Completed rewrite

This commit is contained in:
2022-08-28 18:47:15 -05:00
parent 0c19f61d88
commit c7550c62ec
41 changed files with 567 additions and 1211 deletions

3
src/core/__init__.py Normal file
View File

@@ -0,0 +1,3 @@
"""
Core module
"""

View File

@@ -0,0 +1,21 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from .widgets.defined_keys import Esc_Key, AT_Key, Space_Key, COM_Key
class Bottom_Key_Row(Gtk.Box):
def __init__(self):
super(Bottom_Key_Row, self).__init__()
self.set_property("homogeneous", True)
for key in [Esc_Key(), Space_Key(), AT_Key(), COM_Key()]:
self.add(key)

View File

@@ -0,0 +1,4 @@
from .left_column import Left_Column
from .keys_column import Keys_Column
from .right_column import Right_Column
from .controls_column import Controls_Column

View File

@@ -0,0 +1,102 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from ..widgets.defined_keys import Del_Key, Ctrl_Key, Shift_Key, Alt_Key, PrtSc_Key, Up_Key, Down_Key, Left_Key, Right_Key
class Button_Box(Gtk.ButtonBox):
"""docstring for Button_Box."""
def __init__(self):
super(Button_Box, self).__init__()
for key in [Del_Key(), Ctrl_Key(), Shift_Key(), Alt_Key(), PrtSc_Key()]:
self.add(key)
class List_Box(Gtk.ScrolledWindow):
"""docstring for List_Box."""
def __init__(self):
super(List_Box, self).__init__()
tree, store = self.create_treeview()
self.add(tree)
self.set_size_request(360, 240)
def create_treeview(self):
tree = Gtk.TreeView()
store = Gtk.ListStore(str)
column = Gtk.TreeViewColumn("Commands")
name = Gtk.CellRendererText()
selec = tree.get_selection()
tree.set_model(store)
selec.set_mode(2)
column.pack_start(name, True)
column.add_attribute(name, "text", 0)
column.set_expand(False)
tree.append_column(column)
tree.set_search_column(0)
tree.set_headers_visible(True)
tree.set_enable_tree_lines(False)
tree.columns_autosize()
return tree, store
class Grid_Box(Gtk.Grid):
"""docstring for Grid_Box."""
def __init__(self):
super(Grid_Box, self).__init__()
self.setup_styling()
self.insert_row(0)
self.insert_row(1)
self.insert_row(2)
self.insert_column(0)
self.insert_column(1)
self.insert_column(2)
# NOTE: Widget, left, top, width, height
self.attach(Up_Key(), 1, 0, 1, 1)
self.attach(Down_Key(), 1, 2, 1, 1)
self.attach(Left_Key(), 0, 1, 1, 1)
self.attach(Right_Key(), 2, 1, 1, 1)
def setup_styling(self):
self.set_hexpand(True)
self.set_margin_top(5)
self.set_margin_bottom(5)
self.set_column_homogeneous(True)
class Controls_Column(Gtk.Box):
"""docstring for Controls_Column."""
def __init__(self):
super(Controls_Column, self).__init__()
self. setup_styling()
for key in [Button_Box(), List_Box(), Grid_Box()]:
self.add(key)
self.show_all()
def setup_styling(self):
self.set_orientation(1) # HORIZONTAL = 0, VERTICAL = 1
self.set_vexpand(True)
self.set_margin_start(10)
self.set_margin_end(10)

View File

@@ -0,0 +1,59 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from ..widgets.key import Key
from ..bottom_key_row import Bottom_Key_Row
class KeyboardRowMatchError(Exception):
pass
class Keys_Column(Gtk.Box):
"""docstring for Keys_Column."""
def __init__(self):
super(Keys_Column, self).__init__()
self.setup_styling()
self.setup_key_buttons()
self.show_all()
def setup_styling(self):
self.set_orientation(1) # HORIZONTAL = 0, VERTICAL = 1
self.set_property("homogeneous", True)
self.set_hexpand(True)
def setup_key_buttons(self):
keys = keys_set["keys"]
children = keys.keys()
for child in children:
pKeys = keys[child]["pKeys"]
sKeys = keys[child]["sKeys"]
row_box = self.add_row()
if len(pKeys) == len(sKeys):
for i in range(10):
pkey = pKeys[i]
sKey = sKeys[i]
row_box.add(Key(pkey, sKey))
else:
raise KeyboardRowMatchError("A row in keys_json has missmatched pKeys and sKeys lengths.")
self.add(Bottom_Key_Row())
def add_row(self):
row_box = Gtk.Box()
row_box.set_property("homogeneous", True)
self.add(row_box)
return row_box

View File

@@ -0,0 +1,28 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from ..widgets.defined_keys import Symbols_Key, CAPS_Key
class Left_Column(Gtk.Box):
"""docstring for Left_Column."""
def __init__(self):
super(Left_Column, self).__init__()
self.setup_styling()
for key in [Symbols_Key(), CAPS_Key()]:
self.add(key)
self.show_all()
def setup_styling(self):
self.set_orientation(1) # HORIZONTAL = 0, VERTICAL = 1

View File

@@ -0,0 +1,28 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from ..widgets.defined_keys import Backspace_Key, Enter_Key
class Right_Column(Gtk.Box):
"""docstring for Right_Column."""
def __init__(self):
super(Right_Column, self).__init__()
self.setup_styling()
for key in [Backspace_Key(), Enter_Key()]:
self.add(key)
self.show_all()
def setup_styling(self):
self.set_orientation(1) # HORIZONTAL = 0, VERTICAL = 1

97
src/core/container.py Normal file
View File

@@ -0,0 +1,97 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from .columns import Left_Column, Keys_Column, Right_Column, Controls_Column
class Auto_Type(Gtk.Box):
"""docstring for Auto_Type."""
def __init__(self):
super(Auto_Type, self).__init__()
pad1 = Gtk.Label()
pad2 = Gtk.Label()
self._auto_typer = Gtk.SearchEntry()
self._type_btn = Gtk.Button(label="Type")
self._auto_typer.set_placeholder_text("Autotype Field...")
# self._auto_typer.set_icon_from_icon_name(0, "gtk-go-forward") # PRIMARY = 0, SECONDARY = 1
self._auto_typer.set_icon_from_stock(0, "gtk-go-forward") # PRIMARY = 0, SECONDARY = 1
self._auto_typer.set_can_focus(True)
self._auto_typer.set_hexpand(True)
pad1.set_hexpand(True)
pad2.set_hexpand(True)
self.add(pad1)
self.add(self._auto_typer)
self.add(self._type_btn)
self.add(pad2)
self.setup_styling()
self.setup_signals()
self.show_all()
def setup_styling(self):
self.set_margin_bottom(5)
def setup_signals(self):
self._type_btn.connect("released", self.type_out)
def type_out(self, widget = None, eve = None):
text = self._auto_typer.get_text()
typwriter.type_string(text)
class Main_Container(Gtk.Box):
"""docstring for Main_Container."""
def __init__(self):
super(Main_Container, self).__init__()
self.setup_styling()
self.add_columns()
self.show_all()
def setup_styling(self):
self.set_orientation(0) # HORIZONTAL = 0, VERTICAL = 1
self.set_vexpand(True)
def add_columns(self):
self.add(Left_Column())
self.add(Keys_Column())
self.add(Right_Column())
self.add(Controls_Column())
class Container(Gtk.Box):
"""docstring for Container."""
def __init__(self):
super(Container, self).__init__()
self.setup_styling()
self.add_content()
self.show_all()
def setup_styling(self):
self.set_orientation(1) # HORIZONTAL = 0, VERTICAL = 1
self.set_vexpand(True)
self.set_margin_start(5)
self.set_margin_top(5)
self.set_margin_bottom(5)
def add_content(self):
self.add(Auto_Type())
self.add(Main_Container())

18
src/core/signals_mixin.py Normal file
View File

@@ -0,0 +1,18 @@
# Python imports
# Lib imports
from gi.repository import GObject
# Application imports
from .widgets.key import Key
class SignalsMixin:
"""docstring for SignalsMixin."""
def setup_custom_event_signals(self):
GObject.signal_new('toggle-caps', Key, GObject.SIGNAL_RUN_LAST, GObject.TYPE_PYOBJECT, (GObject.TYPE_PYOBJECT,))
GObject.signal_new('toggle-symbol-keys', Key, GObject.SIGNAL_RUN_LAST, GObject.TYPE_PYOBJECT, (GObject.TYPE_PYOBJECT,))

View File

@@ -0,0 +1,3 @@
"""
Widgets module
"""

View File

@@ -0,0 +1,175 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from .key import Key
############################ 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)
def _clicked(self, widget = None):
key_columns = self.get_parent().get_parent().get_children()[1]
for row in key_columns.get_children():
for key in row:
key.emit("toggle-symbol-keys", ())
class CAPS_Key(Gtk.ToggleButton):
def __init__(self):
super(CAPS_Key, self).__init__("Caps", "Caps")
self.set_vexpand(True)
self.setup_signals()
self.show_all()
def setup_signals(self):
self.connect("clicked", self._clicked)
def _clicked(self, widget = None):
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 ############################
class Backspace_Key(Key):
def __init__(self):
super(Backspace_Key, self).__init__("Backspace", "Backspace")
def setup_signals(self):
self.connect("released", self._clicked)
def _clicked(self, widget = None):
typwriter.press_special_keys(self.get_label())
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())
############################ Bottom_Key_Row Keys ############################
class AT_Key(Key):
def __init__(self):
super(AT_Key, self).__init__("@", "@")
class Space_Key(Key):
def __init__(self):
super(Space_Key, self).__init__("Space", "Space")
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class COM_Key(Key):
def __init__(self):
super(COM_Key, self).__init__(".com", ".com")
############################ Controls_Column Keys ############################
class Esc_Key(Key):
def __init__(self):
super(Esc_Key, self).__init__("Esc", "Esc")
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")
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")
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")
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")
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")
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")
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class Down_Key(Key):
def __init__(self):
super(Down_Key, self).__init__("Down", "Down")
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class Left_Key(Key):
def __init__(self):
super(Left_Key, self).__init__("Left", "Left")
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class Right_Key(Key):
def __init__(self):
super(Right_Key, self).__init__("Right", "Right")
def setup_signals(self):
self.connect("released", self._do_press_special_key)

46
src/core/widgets/key.py Normal file
View File

@@ -0,0 +1,46 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
class Key(Gtk.Button):
def __init__(self, primary = "NULL", secondary = "NULL"):
super(Key, self).__init__()
self._primary_symbol = primary
self._secondary_symbol = secondary
self._is_upper = False
self._is_symbol = False
self.set_label(self._primary_symbol)
self.setup_signals()
def setup_signals(self):
self.connect("released", self._do_type)
self.connect("toggle-caps", self.toggle_caps)
self.connect("toggle-symbol-keys", self.toggle_symbol_keys)
def _do_type(self, widget = None):
key = self.get_label().strip()
typwriter.type(key)
def _do_press_special_key(self, widget = None):
typwriter.press_special_keys(self.get_label())
def toggle_symbol_keys(self, widget = None, eve = None):
self._is_symbol = not self._is_symbol
if self._is_symbol:
self.set_label(self._secondary_symbol)
else:
self.set_label(self._primary_symbol.upper()) if self._is_upper else self.set_label(self._primary_symbol.lower())
def toggle_caps(self, widget = None, eve = None):
self._is_upper = not self._is_upper
if not self._is_symbol:
self.set_label(self._primary_symbol.upper()) if self._is_upper else self.set_label(self._primary_symbol.lower())

73
src/core/window.py Normal file
View File

@@ -0,0 +1,73 @@
# Python imports
import os
# Lib imports
import gi, cairo
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
# Application imports
from .signals_mixin import SignalsMixin
from .container import Container
class Window(SignalsMixin, Gtk.ApplicationWindow):
"""docstring for Window."""
def __init__(self, args, unknownargs):
super(Window, self).__init__()
self._SCRIPT_PTH = os.path.dirname(os.path.realpath(__file__))
self._ICON_FILE = f"{self._SCRIPT_PTH}/../resources/icon.png"
self._CSS_FILE = f"{self._SCRIPT_PTH}/../resources/stylesheet.css"
self.setup_win_settings()
self.setup_styling()
self.setup_signals()
self.setup_custom_event_signals()
self.add(Container())
self.show_all()
def setup_signals(self):
self.connect("delete-event", Gtk.main_quit)
def setup_win_settings(self):
self.set_icon_from_file(self._ICON_FILE)
self.set_title(app_name)
self.set_default_size(800, 200)
self.set_keep_above(True)
self.set_accept_focus(False)
self.set_skip_taskbar_hint(True)
self.set_skip_pager_hint(True)
self.set_type_hint(3) # 3 = TOOLBAR
self.set_gravity(8) # 5 = CENTER, 8 = SOUTH
self.set_position(1) # 1 = CENTER, 4 = CENTER_ALWAYS
self.stick()
def setup_styling(self):
screen = self.get_screen()
visual = screen.get_rgba_visual()
if visual != None and screen.is_composited():
self.set_visual(visual)
self.set_app_paintable(True)
self.connect("draw", self._area_draw)
css_provider = Gtk.CssProvider()
css_provider.load_from_path(self._CSS_FILE)
screen = Gdk.Screen.get_default()
style_context = Gtk.StyleContext()
style_context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
def _area_draw(self, widget, cr):
cr.set_source_rgba(0, 0, 0, 0.54)
cr.set_operator(cairo.OPERATOR_SOURCE)
cr.paint()
cr.set_operator(cairo.OPERATOR_OVER)