Unified toggle keys, fixed ctrl, shit, alt logic
This commit is contained in:
parent
b04840b458
commit
0a2e258766
|
@ -13,6 +13,6 @@ function main() {
|
|||
echo "Working Dir: " $(pwd)
|
||||
|
||||
source '/home/abaddon/Portable_Apps/py-venvs/gtk-apps-venv/venv/bin/activate'
|
||||
python -m pudb $(pwd)/__main__.py; bash
|
||||
python -m pudb $(pwd)/src/__main__.py; bash
|
||||
}
|
||||
main "$@";
|
|
@ -8,6 +8,7 @@ from utils.pyautogui_control import ControlMixin
|
|||
|
||||
|
||||
|
||||
|
||||
# NOTE: Threads WILL NOT die with parent's destruction.
|
||||
def threaded_wrapper(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
|
@ -37,9 +38,13 @@ class EndpointRegistry():
|
|||
def get_endpoints(self):
|
||||
return self._endpoints
|
||||
|
||||
|
||||
class Pyautogui_Controller(ControlMixin):
|
||||
def __init__(self):
|
||||
pass
|
||||
self.isCtrlOn = False
|
||||
self.isShiftOn = False
|
||||
self.isAltOn = False
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -66,6 +71,7 @@ keys_json = {
|
|||
|
||||
|
||||
|
||||
|
||||
# NOTE: Just reminding myself we can add to builtins two different ways...
|
||||
# __builtins__.update({"event_system": Builtins()})
|
||||
builtins.app_name = "Mouse Keyboard"
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -15,8 +15,15 @@ pyautogui.PAUSE = 0
|
|||
class ControlMixin:
|
||||
|
||||
def type(self, key):
|
||||
if self.isCtrlOn or self.isShiftOn or self.isAltOn:
|
||||
self.set_hotkeys()
|
||||
|
||||
pyautogui.typewrite(key)
|
||||
|
||||
if self.isCtrlOn or self.isShiftOn or self.isAltOn:
|
||||
self.unset_hotkeys()
|
||||
|
||||
|
||||
def enter(self, widget = None, data = None):
|
||||
pyautogui.press("enter")
|
||||
|
||||
|
@ -28,6 +35,16 @@ class ControlMixin:
|
|||
pyautogui.press(key.lower())
|
||||
return True
|
||||
|
||||
if key in ["Ctrl", "Shift", "Alt"]:
|
||||
if key == "Ctrl":
|
||||
self.isCtrlOn = not self.isCtrlOn
|
||||
if key == "Shift":
|
||||
self.isShiftOn = not self.isShiftOn
|
||||
if key == "Alt":
|
||||
self.isAltOn = not self.isAltOn
|
||||
|
||||
return True
|
||||
|
||||
for i in range(1, 13):
|
||||
fkey = 'F' + str(i)
|
||||
if key == fkey:
|
||||
|
@ -41,84 +58,18 @@ class ControlMixin:
|
|||
pyautogui.typewrite(char)
|
||||
|
||||
|
||||
def set_hotkeys(self):
|
||||
if self.isCtrlOn:
|
||||
pyautogui.keyDown('ctrl')
|
||||
if self.isShiftOn:
|
||||
pyautogui.keyDown('shiftleft')
|
||||
pyautogui.keyDown('shiftright')
|
||||
if self.isAltOn:
|
||||
pyautogui.keyDown('alt')
|
||||
|
||||
|
||||
|
||||
# def typeString(self, widget = None, data = None):
|
||||
# text = self.autoTypeField.get_text()
|
||||
# for char in text:
|
||||
# self.do_insert(char)
|
||||
#
|
||||
# def insert(self, widget = None, data = None, key = None):
|
||||
# if not key:
|
||||
# key = widget.get_label().strip()
|
||||
#
|
||||
# if self.is_keypress_type(key):
|
||||
# return
|
||||
#
|
||||
# if self.isCapsLockOn:
|
||||
# key = key.upper()
|
||||
#
|
||||
# self.do_insert(key)
|
||||
#
|
||||
#
|
||||
# def do_insert(self, key):
|
||||
# if self.isCtrlOn or self.isShiftOn or self.isAltOn:
|
||||
# self.set_hotkeys()
|
||||
#
|
||||
# pyautogui.typewrite(key)
|
||||
#
|
||||
# if self.isCtrlOn or self.isShiftOn or self.isAltOn:
|
||||
# self.unset_hotkeys()
|
||||
#
|
||||
#
|
||||
# def is_keypress_type(self, key):
|
||||
# if key in ["Esc", "Tab", "Space", "Del", "Up", "Down", "Left", "Right", "PrtSc"]:
|
||||
# pyautogui.press(key.lower())
|
||||
# return True
|
||||
#
|
||||
# for i in range(1, 13):
|
||||
# fkey = 'F' + str(i)
|
||||
# if key == fkey:
|
||||
# pyautogui.press(key.lower())
|
||||
# return True
|
||||
#
|
||||
# return False
|
||||
#
|
||||
#
|
||||
# def set_hotkeys(self):
|
||||
# if self.isCtrlOn:
|
||||
# pyautogui.keyDown('ctrl')
|
||||
# if self.isShiftOn:
|
||||
# pyautogui.keyDown('shiftleft')
|
||||
# pyautogui.keyDown('shiftright')
|
||||
# if self.isAltOn:
|
||||
# pyautogui.keyDown('alt')
|
||||
#
|
||||
#
|
||||
# def unset_hotkeys(self):
|
||||
# pyautogui.keyUp('ctrl')
|
||||
# pyautogui.keyUp('shiftleft')
|
||||
# pyautogui.keyUp('shiftright')
|
||||
# pyautogui.keyUp('alt')
|
||||
#
|
||||
#
|
||||
# def toggleCaps(self, widget, data=None):
|
||||
# self.isCapsLockOn = False if self.isCapsLockOn else True
|
||||
#
|
||||
# def tgglCtrl(self, widget, data=None):
|
||||
# self.isCtrlOn = False if self.isCtrlOn else True
|
||||
#
|
||||
# def tgglShift(self, widget, data=None):
|
||||
# self.isShiftOn = False if self.isShiftOn else True
|
||||
#
|
||||
# def tgglAlt(self, widget, data=None):
|
||||
# self.isAltOn = False if self.isAltOn else True
|
||||
#
|
||||
#
|
||||
# def enter(self, widget, data=None):
|
||||
# pyautogui.press("enter")
|
||||
#
|
||||
#
|
||||
# def backspace(self, widget, data=None):
|
||||
# pyautogui.press("backspace")
|
||||
def unset_hotkeys(self):
|
||||
pyautogui.keyUp('ctrl')
|
||||
pyautogui.keyUp('shiftleft')
|
||||
pyautogui.keyUp('shiftright')
|
||||
pyautogui.keyUp('alt')
|
||||
|
|
|
@ -6,3 +6,7 @@
|
|||
#popoutkeyboard {
|
||||
background-color: rgba(0, 65, 125, 1);
|
||||
} */
|
||||
|
||||
.toggled_bttn {
|
||||
background-color: rgba(0, 65, 125, 1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue