Unified toggle keys, fixed ctrl, shit, alt logic

This commit is contained in:
2022-08-30 17:17:35 -05:00
parent b04840b458
commit 0a2e258766
6 changed files with 62 additions and 105 deletions

View File

@@ -11,13 +11,12 @@ from .key import Key
############################ Left_Column Keys ############################
############################## Left_Column Keys ##############################
class Symbols_Key(Key):
def __init__(self):
super(Symbols_Key, self).__init__("Symbols", "Symbols")
def setup_signals(self):
self.connect("released", self._clicked)
@@ -28,28 +27,30 @@ class Symbols_Key(Key):
for key in row:
key.emit("toggle-symbol-keys", ())
class CAPS_Key(Gtk.ToggleButton):
class CAPS_Key(Key):
def __init__(self):
super(CAPS_Key, self).__init__("Caps", "Caps")
self.set_vexpand(True)
self.setup_signals()
self.setup_styling()
self.show_all()
def setup_styling(self):
self.set_vexpand(True)
def setup_signals(self):
self.connect("clicked", self._clicked)
self.connect("released", self._clicked)
def _clicked(self, widget = None):
key_columns = self.get_parent().get_parent().get_children()[1]
ctx = widget.get_style_context()
ctx.remove_class("toggled_bttn") if ctx.has_class("toggled_bttn") else ctx.add_class("toggled_bttn")
key_columns = self.get_parent().get_parent().get_children()[1]
for row in key_columns.get_children():
for key in row:
key.emit("toggle-caps", ())
############################ Right_Column Keys ############################
############################## Right_Column Keys ##############################
class Backspace_Key(Key):
def __init__(self):
@@ -64,20 +65,16 @@ class Backspace_Key(Key):
class Enter_Key(Key):
def __init__(self):
super(Enter_Key, self).__init__("Enter", "Enter")
self.setup_styling()
def setup_styling(self):
self.set_vexpand(True)
def setup_signals(self):
self.connect("released", self._clicked)
def _clicked(self, widget = None):
typwriter.press_special_keys(self.get_label())
self.connect("released", self._do_press_special_key)
############################ Bottom_Key_Row Keys ############################
############################# Bottom_Key_Row Keys #############################
class AT_Key(Key):
def __init__(self):
@@ -96,7 +93,7 @@ class COM_Key(Key):
super(COM_Key, self).__init__(".com", ".com")
############################ Controls_Column Keys ############################
############################ Controls_Column Keys ############################
class Esc_Key(Key):
def __init__(self):
@@ -105,7 +102,6 @@ class Esc_Key(Key):
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class Del_Key(Key):
def __init__(self):
super(Del_Key, self).__init__("Del", "Del")
@@ -113,7 +109,6 @@ class Del_Key(Key):
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class Ctrl_Key(Key):
def __init__(self):
super(Ctrl_Key, self).__init__("Ctrl", "Ctrl")
@@ -121,7 +116,6 @@ class Ctrl_Key(Key):
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class Shift_Key(Key):
def __init__(self):
super(Shift_Key, self).__init__("Shift", "Shift")
@@ -129,7 +123,6 @@ class Shift_Key(Key):
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class Alt_Key(Key):
def __init__(self):
super(Alt_Key, self).__init__("Alt", "Alt")
@@ -137,7 +130,6 @@ class Alt_Key(Key):
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class PrtSc_Key(Key):
def __init__(self):
super(PrtSc_Key, self).__init__("PrtSc", "PrtSc")
@@ -145,7 +137,6 @@ class PrtSc_Key(Key):
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class Up_Key(Key):
def __init__(self):
super(Up_Key, self).__init__("Up", "Up")

View File

@@ -8,7 +8,7 @@ from gi.repository import Gtk
# Application imports
class Key(Gtk.Button):
class Key(Gtk.Button or Gtk.ToggleButton):
def __init__(self, primary = "NULL", secondary = "NULL"):
super(Key, self).__init__()
@@ -31,7 +31,12 @@ class Key(Gtk.Button):
typwriter.type(key)
def _do_press_special_key(self, widget = None):
typwriter.press_special_keys(self.get_label())
key = self.get_label()
if key in ["Ctrl", "Shift", "Alt"]:
ctx = widget.get_style_context()
ctx.remove_class("toggled_bttn") if ctx.has_class("toggled_bttn") else ctx.add_class("toggled_bttn")
typwriter.press_special_keys(key)
def toggle_symbol_keys(self, widget = None, eve = None):
self._is_symbol = not self._is_symbol