Hey all,
I’m modifying the keyboard example “Special Characters.py” to include all Unicode characters. I did this by scraping the Unicode code point range and category name from Wikipedia. It has a navigation view with all the categories in a scroll view, and then presents all the Unicode characters of that category.
Anyhow, the problem is that I get spotty printability, but since the character is a valid Unicode character I can’t prevent it from displaying as 🠂. I don’t understand the problem since sys.maxunicode (1114111) suggests this shouldn’t be a problem...
Is it due to the possibility that the iOS system font doesn’t have a rendering of these glyphs? How can I install Google Noto and access these glyphs (if that’s the issue).
Code:
#! python3
import keyboard
import ui
with open('uni_blocks.txt', 'r') as block_file:
blocks = block_file.readlines()
class BlocksView (ui.View):
def __init__(self, *args, **kwargs):
ui.View.__init__(self, *args, **kwargs)
self.glyph_sv = None
self.cat_sv = ui.ScrollView(
flex='WH',
frame=self.bounds
)
self.buttons = []
for block in blocks:
cells = block.split(' ')
start = cells[0]
end = cells[1]
name = ' '.join(cells[2:])
btn = self.create_button(name)
btn.action = self.cat_selected
btn.start = start
btn.end = end
self.cat_sv.add_subview(btn)
self.buttons.append(btn)
self.add_subview(self.cat_sv)
def layout(self):
if self.cat_sv.on_screen:
bw = ui.get_screen_size()[0]
x, y = 2, 2
for button in self.buttons:
button.frame = (x, y, bw, 20)
y += 24
self.cat_sv.content_size = (0, (len(self.buttons) + 1) * 24 + 40)
def cat_selected(self, sender):
# present another scroll view of unicode titled buttons
self.glyph_sv = ui.ScrollView(
name=sender.title,
frame=self.bounds,
flex='WH'
)
w = ui.get_screen_size()[0]
x = y = 2
rows = 1
for i in range(int(sender.start, 16), int(sender.end, 16)):
char = chr(i)
if char.isprintable() and not char.isspace():
btn = self.create_button(chr(i))
btn.action = self.insert_char
btn.number = i
btn.frame = (x, y, 35, 35)
x += 39
if x > w - 39:
x = 2
y += 39
rows += 1
self.glyph_sv.add_subview(btn)
self.glyph_sv.content_size = (w, (rows + 1) * 39 + 40)
self.navigation_view.push_view(self.glyph_sv, False)
def create_button(self, name):
btn = ui.Button(title=name)
btn.font = ('<System>', 18)
btn.background_color = (1, 1, 1, 0.1)
btn.tint_color = 'white'
btn.corner_radius = 4
btn.size_to_fit()
return btn
def insert_char(self, sender):
if keyboard.is_keyboard():
keyboard.insert_text(sender.title)
else:
print(sender.title, sender.number)
def main():
w = ui.get_screen_size()[0]
v = BlocksView(
frame=(0, 0, w, 133),
name='Categories',
flex='WH'
)
nav_view = ui.NavigationView(v)
nav_view.title_color = 'white'
if keyboard.is_keyboard():
keyboard.set_view(nav_view, 'expanded')
else:
# For debugging in the main app:
nav_view.bg_color = 'black'
nav_view.bar_tint_color='black'
nav_view.present('fullscreen', hide_title_bar=True)
if __name__ == '__main__':
main()
Source .txt:
https://pastebin.com/raw/Y9Fsuykq
Thanks!