Closed
Description
On my path of creating a touch keyboard for the TFT Featherwing after laying out the keyboard saw there's no .contains param like there are for widgets and buttons. Requesting contains add to grid layout or some advice on completing this with touch capability.
forkawesome_font = bitmap_font.load_font("/fonts/forkawesome-12.pcf")
# Quick Colors for Labels
TEXT_BLACK = 0x000000
TEXT_BLUE = 0x0000FF
TEXT_CYAN = 0x00FFFF
TEXT_GRAY = 0x8B8B8B
TEXT_GREEN = 0x00FF00
TEXT_LIGHTBLUE = 0x90C7FF
TEXT_MAGENTA = 0xFF00FF
TEXT_ORANGE = 0xFFA500
TEXT_PURPLE = 0x800080
TEXT_RED = 0xFF0000
TEXT_WHITE = 0xFFFFFF
TEXT_YELLOW = 0xFFFF00
def make_my_label(font, anchor_point, anchored_position, scale, color):
func_label = label.Label(font)
func_label.anchor_point = anchor_point
func_label.anchored_position = anchored_position
func_label.scale = scale
func_label.color = color
return func_label
hello_label_change_wifi = make_my_label(
terminalio.FONT, (0.5, 1.0), (DISPLAY_WIDTH / 2, 15), 1, TEXT_WHITE)
input_change_wifi = make_my_label(
terminalio.FONT, (0.0, 0.0), (5, 50), 1, TEXT_WHITE)
input_new_cred = make_my_label(
terminalio.FONT, (0.0, 0.0), (100, 50), 1, TEXT_WHITE)
# Grid Layout Labels. Cell invisible with no text label
_labels = []
keyboard_input =[]
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="`"))
layout.add_content(_labels[0], grid_position=(0, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="1"))
layout.add_content(_labels[1], grid_position=(1, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="2"))
layout.add_content(_labels[2], grid_position=(2, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="3"))
layout.add_content(_labels[3], grid_position=(3, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="4"))
layout.add_content(_labels[4], grid_position=(4, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="5"))
layout.add_content(_labels[5], grid_position=(5, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="6"))
layout.add_content(_labels[6], grid_position=(6, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="7"))
layout.add_content(_labels[7], grid_position=(7, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="8"))
layout.add_content(_labels[8], grid_position=(8, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="9"))
layout.add_content(_labels[9], grid_position=(9, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="0"))
layout.add_content(_labels[10], grid_position=(10, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="-"))
layout.add_content(_labels[11], grid_position=(11, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="="))
layout.add_content(_labels[12], grid_position=(12, 0), cell_size=(1, 1))
_labels.append(label.Label(forkawesome_font, scale=1, x=0, y=0, text="\uf0e2"))
layout.add_content(_labels[13], grid_position=(13, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="Q"))
layout.add_content(_labels[14], grid_position=(0, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="W"))
layout.add_content(_labels[15], grid_position=(1, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="E"))
layout.add_content(_labels[16], grid_position=(2, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="R"))
layout.add_content(_labels[17], grid_position=(3, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="T"))
layout.add_content(_labels[18], grid_position=(4, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="Y"))
layout.add_content(_labels[19], grid_position=(5, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="U"))
layout.add_content(_labels[20], grid_position=(6, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="I"))
layout.add_content(_labels[21], grid_position=(7, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="O"))
layout.add_content(_labels[22], grid_position=(8, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="P"))
layout.add_content(_labels[23], grid_position=(9, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="["))
layout.add_content(_labels[24], grid_position=(10, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="]"))
layout.add_content(_labels[25], grid_position=(11, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="\\"))
layout.add_content(_labels[26], grid_position=(12, 1), cell_size=(2, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="A"))
layout.add_content(_labels[27], grid_position=(0, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="S"))
layout.add_content(_labels[28], grid_position=(1, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="D"))
layout.add_content(_labels[29], grid_position=(2, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="F"))
layout.add_content(_labels[30], grid_position=(3, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="G"))
layout.add_content(_labels[31], grid_position=(4, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="H"))
layout.add_content(_labels[32], grid_position=(5, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="J"))
layout.add_content(_labels[33], grid_position=(6, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="K"))
layout.add_content(_labels[34], grid_position=(7, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="L"))
layout.add_content(_labels[35], grid_position=(8, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text=";"))
layout.add_content(_labels[36], grid_position=(9, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="'"))
layout.add_content(_labels[37], grid_position=(10, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="ENTER"))
layout.add_content(_labels[38], grid_position=(11, 2), cell_size=(3, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="Z"))
layout.add_content(_labels[39], grid_position=(0, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="X"))
layout.add_content(_labels[40], grid_position=(1, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="C"))
layout.add_content(_labels[41], grid_position=(2, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="V"))
layout.add_content(_labels[42], grid_position=(3, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="B"))
layout.add_content(_labels[43], grid_position=(4, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="N"))
layout.add_content(_labels[44], grid_position=(5, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="M"))
layout.add_content(_labels[45], grid_position=(6, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text=","))
layout.add_content(_labels[46], grid_position=(7, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text=","))
layout.add_content(_labels[47], grid_position=(8, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="."))
layout.add_content(_labels[48], grid_position=(9, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="/"))
layout.add_content(_labels[49], grid_position=(10, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="SHIFT"))
layout.add_content(_labels[50], grid_position=(11, 3), cell_size=(3, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="CTRL"))
layout.add_content(_labels[51], grid_position=(0, 4), cell_size=(2, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="ALT"))
layout.add_content(_labels[52], grid_position=(2, 4), cell_size=(2, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="SPACE"))
layout.add_content(_labels[53], grid_position=(4, 4), cell_size=(6, 1))
_labels.append(label.Label(forkawesome_font, scale=1, x=0, y=0, text="\uf060"))
layout.add_content(_labels[54], grid_position=(10, 4), cell_size=(1, 1))
_labels.append(label.Label(forkawesome_font, scale=1, x=0, y=0, text="\uf061"))
layout.add_content(_labels[55], grid_position=(11, 4), cell_size=(1, 1))
_labels.append(label.Label(forkawesome_font, scale=1, x=0, y=0, text="\uf062"))
layout.add_content(_labels[56], grid_position=(12, 4), cell_size=(1, 1))
_labels.append(label.Label(forkawesome_font, scale=1, x=0, y=0, text="\uf063"))
layout.add_content(_labels[57], grid_position=(13, 4), cell_size=(1, 1))
# bunch of stuff and while True:
while display.root_group is wifi_change_group:
label_list1 = []
New_Label_list =[]
hello_label_change_wifi.text = "Wifi Change Credentials"
input_change_wifi.text = "New Password: "
for label in _labels:
label_list1.append(label)
for label in label_list1:
sorted_labels = {'text':label.text}
New_Label_list.append([sorted_labels])
jsonLabelList = json.dumps(New_Label_list)
jsonlabel_list = json.loads(jsonLabelList)
while (time.monotonic() - last) <= sleep_time and display.root_group is wifi_change_group:
p = touchscreen.touch_point
if p:
print(f"Touch Point: {p}")
print(f"Get Grid Cell H: {layout.get_cell((5,2)).text}")
print(f"Get Grid Cell E: {layout.get_cell((2,1)).text}")
print(f"Get Grid Cell L: {layout.get_cell((8,2)).text}")
print(f"Get Grid Cell L: {layout.get_cell((8,2)).text}")
print(f"Get Grid Cell O: {layout.get_cell((8,1)).text}")
print("Key Pressed")
label_list = json.dumps(_labels)
#print(f"Label List: {label_list}")
#print(f"jsonList: {jsonlabel_list}")
print(f"Labels: {jsonlabel_list[0]}")
print(f"Object Type: {type(_labels)}")
input_new_cred.text = f"{jsonlabel_list[0][0]['text']}"
menu_switching(wifi_change_group, main_group2, main_group, preferences_group, wifi_settings_group, rssi_group, sys_info_group, wifi_change_group)
else:
# Default state always running
group_cleanup()
last = time.monotonic()
Key Pressed
Labels: [{'text': '`'}]
Object Type: <class 'list'>
Touch Point: (461, 194, 71)
Get Grid Cell: H
Get Grid Cell: E
Get Grid Cell: L
Get Grid Cell: L
Get Grid Cell: O
Key Pressed
Labels: [{'text': '`'}]
Object Type: <class 'list'>
I have it drilled down to being able to work with the individual cells to print out the keyboard letters needed with hardcoded statements but not touch yet.
That's the gist of it. Full code can be viewed on my Github which I've been working on daily.
Having grid layout the capability for touch contains would have made this much easier. I'm all ears for ideas if there's a better way.
Metadata
Metadata
Assignees
Labels
No labels