keyboard: improvements and fixes

modify layout to make keyboard bigger in the same space
create shift for a more traditional aproach
fix highlighting fixes #1004
This commit is contained in:
alfrix 2023-06-09 12:06:31 -03:00
parent 72c1b1d5f2
commit f0a33bd360
2 changed files with 89 additions and 45 deletions

View File

@ -12,6 +12,8 @@ class Keyboard(Gtk.Box):
def __init__(self, screen, close_cb, entry=None):
super().__init__(orientation=Gtk.Orientation.VERTICAL)
self.shift = []
self.shift_active = False
self.close_cb = close_cb
self.keyboard = Gtk.Grid()
self.keyboard.set_direction(Gtk.TextDirection.LTR)
@ -24,70 +26,82 @@ class Keyboard(Gtk.Box):
if language == "de":
self.keys = [
[
["q", "w", "e", "r", "t", "z", "u", "i", "o", "p", "ü", ""],
["q", "w", "e", "r", "t", "z", "u", "i", "o", "p", "ü"],
["a", "s", "d", "f", "g", "h", "j", "k", "l", "ö", "ä"],
["ABC", "123", "#+=", "y", "x", "c", "v", "b", "n", "m"],
["", "y", "x", "c", "v", "b", "n", "m", "", "#+=", ""],
["123", " ", ""],
],
[
["Q", "W", "E", "R", "T", "Z", "U", "I", "O", "P", "Ü", ""],
["Q", "W", "E", "R", "T", "Z", "U", "I", "O", "P", "Ü"],
["A", "S", "D", "F", "G", "H", "J", "K", "L", "Ö", "Ä"],
["abc", "123", "#+=", "Y", "X", "C", "V", "B", "N", "M"],
["", "Y", "X", "C", "V", "B", "N", "M", "ß", "#+=", ""],
["123", " ", ""],
],
[
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "ß", ""],
["-", "/", ":", ";", "(", ")", "$", "&", "@", "\"", ""],
["ABC", "abc", "#+=", ".", ",", "?", "!", "'"],
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"],
["@", "#", "$", "_", "&", "-", "+", "(", ")", "/"],
["", "*", '"', "'", ":", ";", "!", "?", "#+=", ""],
["abc", " ", ""],
],
[
["[", "]", "{", "}", "#", "%", "^", "*", "+", "=", ""],
["[", "]", "{", "}", "#", "%", "^", "*", "+", "="],
["_", "\\", "|", "~", "<", ">", "", "£", "¥", ""],
["ABC", "abc", "123", ".", ",", "?", "!", "'"],
["", ".", ",", "?", "!", "'", "º", "¨", "123", ""],
["ABC", " ", ""],
]
]
elif language == "fr":
self.keys = [
[
["a", "z", "e", "r", "t", "y", "u", "i", "o", "p", ""],
["a", "z", "e", "r", "t", "y", "u", "i", "o", "p"],
["q", "s", "d", "f", "g", "h", "j", "k", "l", "m"],
["ABC", "123", "#+=", "w", "x", "c", "v", "b", "n"],
["", "w", "x", "c", "v", "b", "n", "ç", "#+=", ""],
["123", " ", ""],
],
[
["A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P", ""],
["A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P"],
["Q", "S", "D", "F", "G", "H", "J", "K", "L", "M"],
["abc", "123", "#+=", "W", "X", "C", "V", "B", "N"],
["", "W", "X", "C", "V", "B", "N", "Ç", "#+=", ""],
["123", " ", ""],
],
[
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", ""],
["-", "/", ":", ";", "(", ")", "$", "&", "@", "\""],
["ABC", "abc", "#+=", ".", ",", "?", "!", "'"],
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"],
["@", "#", "$", "_", "&", "-", "+", "(", ")", "/"],
["", "*", '"', "'", ":", ";", "!", "?", "ABC", ""],
["abc", " ", ""],
],
[
["[", "]", "{", "}", "#", "%", "^", "*", "+", "=", ""],
["[", "]", "{", "}", "#", "%", "^", "*", "+", "="],
["_", "\\", "|", "~", "<", ">", "", "£", "¥", ""],
["ABC", "abc", "123", ".", ",", "?", "!", "'"],
["", ".", ",", "?", "!", "'", "º", "Æ", "æ", ""],
["ABC", " ", ""],
]
]
else:
self.keys = [
[
["q", "w", "e", "r", "t", "y", "u", "i", "o", "p", ""],
["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"],
["a", "s", "d", "f", "g", "h", "j", "k", "l"],
["ABC", "123", "#+=", "z", "x", "c", "v", "b", "n", "m"],
["", "z", "x", "c", "v", "b", "n", "m", "#+=", ""],
["123", " ", ""],
],
[
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", ""],
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
["A", "S", "D", "F", "G", "H", "J", "K", "L"],
["abc", "123", "#+=", "Z", "X", "C", "V", "B", "N", "M"],
["", "Z", "X", "C", "V", "B", "N", "M", "#+=", ""],
["123", " ", ""],
],
[
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", ""],
["-", "/", ":", ";", "(", ")", "$", "&", "@", "\""],
["ABC", "abc", "#+=", ".", ",", "?", "!", "'"],
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"],
["@", "#", "$", "_", "&", "-", "+", "(", ")", "/"],
["", "*", '"', "'", ":", ";", "!", "?", "Ç", ""],
["abc", " ", ""],
],
[
["[", "]", "{", "}", "#", "%", "^", "*", "+", "=", ""],
["[", "]", "{", "}", "#", "%", "^", "*", "+", "="],
["_", "\\", "|", "~", "<", ">", "", "£", "¥", ""],
["ABC", "abc", "123", ".", ",", "?", "!", "'"],
["", ".", ",", "?", "!", "'", "º", "ç", "abc", ""],
["ABC", " ", ""],
]
]
@ -95,19 +109,17 @@ class Keyboard(Gtk.Box):
self.keys[0][1].append("ñ")
self.keys[1][1].append("Ñ")
for pallet in self.keys:
pallet.append(["", " ", ""])
self.buttons = self.keys.copy()
for p, pallet in enumerate(self.keys):
for r, row in enumerate(pallet):
for k, key in enumerate(row):
if key == "":
self.buttons[p][r][k] = screen.gtk.Button("backspace", scale=.6)
elif key == "":
self.buttons[p][r][k] = screen.gtk.Button("cancel", scale=.6)
elif key == "":
self.buttons[p][r][k] = screen.gtk.Button("complete", scale=.6)
elif key == "":
self.buttons[p][r][k] = screen.gtk.Button("arrow-up", scale=.6)
self.shift.append(self.buttons[p][r][k])
elif key == "":
self.buttons[p][r][k] = screen.gtk.Button("arrow-down", scale=.6)
else:
self.buttons[p][r][k] = screen.gtk.Button(label=key, lines=1)
self.buttons[p][r][k].set_hexpand(True)
@ -134,17 +146,21 @@ class Keyboard(Gtk.Box):
for _ in range(len(self.keys[self.pallet_nr]) + 1):
self.keyboard.remove_row(0)
self.pallet_nr = p
columns = 0
for r, row in enumerate(self.keys[p][:-1]):
for k, key in enumerate(row):
x = k * 2 + 1 if r == 1 else k * 2
self.keyboard.attach(self.buttons[p][r][k], x, r, 2, 1)
self.keyboard.attach(self.buttons[p][3][0], 0, 4, 3, 1) # ✕
self.keyboard.attach(self.buttons[p][3][1], 3, 4, 16, 1) # Space
self.keyboard.attach(self.buttons[p][3][2], 19, 4, 3, 1) # ✔
if x > columns:
columns = x
self.keyboard.attach(self.buttons[p][3][0], 0, 4, 3, 1) # 123
self.keyboard.attach(self.buttons[p][3][1], 3, 4, -4 + columns, 1) # Space
self.keyboard.attach(self.buttons[p][3][2], -1 + columns, 4, 3, 1) # ↓
self.show_all()
def repeat(self, widget, event, key):
# Button-press
widget.get_style_context().add_class("active")
self.update_entry(widget, key)
if self.timeout is None and key == "":
# Hold for repeat, hold longer to clear the field
@ -152,7 +168,6 @@ class Keyboard(Gtk.Box):
# This can be used to repeat all the keys,
# but I don't find it useful on the console
self.timeout = GLib.timeout_add(400, self.repeat, widget, None, key)
widget.get_style_context().add_class("active")
return True
def release(self, widget, event):
@ -163,7 +178,8 @@ class Keyboard(Gtk.Box):
if self.clear_timeout is not None:
GLib.source_remove(self.clear_timeout)
self.clear_timeout = None
widget.get_style_context().remove_class("active")
if widget not in self.shift:
widget.get_style_context().remove_class("active")
def clear(self, widget=None):
self.entry.set_text("")
@ -174,20 +190,48 @@ class Keyboard(Gtk.Box):
def update_entry(self, widget, key):
if key == "":
Gtk.Entry.do_backspace(self.entry)
elif key == "":
elif key == "":
self.close_cb()
return
elif key == "":
self.clear()
self.close_cb()
elif key == "":
self.toggle_shift()
if self.pallet_nr == 0:
self.set_pallet(1)
elif self.pallet_nr == 1:
self.set_pallet(0)
elif self.pallet_nr == 2:
self.set_pallet(3)
elif self.pallet_nr == 3:
self.set_pallet(2)
return
elif key == "abc":
if self.shift_active:
self.toggle_shift()
widget.get_style_context().remove_class("active")
self.set_pallet(0)
elif key == "ABC":
if not self.shift_active:
self.toggle_shift()
widget.get_style_context().remove_class("active")
self.set_pallet(1)
elif key == "123":
if self.shift_active:
self.toggle_shift()
widget.get_style_context().remove_class("active")
self.set_pallet(2)
elif key == "#+=":
if not self.shift_active:
self.toggle_shift()
widget.get_style_context().remove_class("active")
self.set_pallet(3)
else:
Gtk.Entry.do_insert_at_cursor(self.entry, key)
def toggle_shift(self):
self.shift_active = not self.shift_active
if self.shift_active:
for widget in self.shift:
widget.get_style_context().add_class("active")
else:
for widget in self.shift:
widget.get_style_context().remove_class("active")

View File

@ -122,7 +122,7 @@ entry {
font-size: 1em;
background-color: #20292F;
border: .2em solid #13181C;
padding: .25em;
padding: .2em;
}
label {
@ -303,7 +303,7 @@ trough {
}
.keyboard_box {
margin-top: 35px;
margin-top: 38px;
}
.keyboard_matchbox {