Reworked logic - in progress
This commit is contained in:
3
1.0.2/core/__init__.py
Normal file
3
1.0.2/core/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Core module
|
||||
"""
|
||||
3
1.0.2/core/columns/__init__.py
Normal file
3
1.0.2/core/columns/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .left_column import Left_Column
|
||||
from .keys_column import Keys_Column
|
||||
from .right_column import Right_Column
|
||||
64
1.0.2/core/columns/keys_column.py
Normal file
64
1.0.2/core/columns/keys_column.py
Normal file
@@ -0,0 +1,64 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from ..widgets.key import Key
|
||||
|
||||
|
||||
|
||||
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_signals()
|
||||
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_signals(self):
|
||||
pass
|
||||
|
||||
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(9):
|
||||
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.")
|
||||
|
||||
row_box = self.add_row()
|
||||
for key in ['Symbols', 'Space', 'Backspace']:
|
||||
row_box.add(Key(key, key))
|
||||
|
||||
def add_row(self):
|
||||
row_box = Gtk.Box()
|
||||
row_box.set_property("homogeneous", True)
|
||||
self.add(row_box)
|
||||
|
||||
return row_box
|
||||
37
1.0.2/core/columns/left_column.py
Normal file
37
1.0.2/core/columns/left_column.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
|
||||
class Left_Column(Gtk.Button):
|
||||
"""docstring for Left_Column."""
|
||||
|
||||
def __init__(self):
|
||||
super(Left_Column, self).__init__()
|
||||
|
||||
self.setup_styling()
|
||||
self.setup_signals()
|
||||
self.show_all()
|
||||
|
||||
|
||||
def setup_styling(self):
|
||||
self.set_label("Caps")
|
||||
|
||||
def setup_signals(self):
|
||||
self.connect("released", self._clicked)
|
||||
|
||||
def _clicked(self, widget = None):
|
||||
key_columns = self.get_parent().get_children()[1]
|
||||
limit = len(key_columns.get_children()) - 1
|
||||
|
||||
for i, row in enumerate(key_columns.get_children()):
|
||||
if not i == limit:
|
||||
for key in row:
|
||||
key.emit("toggle-caps", ())
|
||||
31
1.0.2/core/columns/right_column.py
Normal file
31
1.0.2/core/columns/right_column.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
|
||||
class Right_Column(Gtk.Button):
|
||||
"""docstring for Right_Column."""
|
||||
|
||||
def __init__(self):
|
||||
super(Right_Column, self).__init__()
|
||||
|
||||
self.setup_styling()
|
||||
self.setup_signals()
|
||||
self.show_all()
|
||||
|
||||
|
||||
def setup_styling(self):
|
||||
self.set_label("Enter")
|
||||
|
||||
def setup_signals(self):
|
||||
self.connect("released", self._clicked)
|
||||
|
||||
def _clicked(self, widget = None):
|
||||
typwriter.enter()
|
||||
37
1.0.2/core/container.py
Normal file
37
1.0.2/core/container.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# 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
|
||||
from .signals_mixin import SignalsMixin
|
||||
|
||||
|
||||
|
||||
class Container(SignalsMixin, Gtk.Box):
|
||||
"""docstring for Container."""
|
||||
|
||||
def __init__(self):
|
||||
super(Container, self).__init__()
|
||||
|
||||
self.setup_custom_event_signals()
|
||||
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 setup_signals(self):
|
||||
pass
|
||||
|
||||
def add_columns(self):
|
||||
self.add(Left_Column())
|
||||
self.add(Keys_Column())
|
||||
self.add(Right_Column())
|
||||
17
1.0.2/core/signals_mixin.py
Normal file
17
1.0.2/core/signals_mixin.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# 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,))
|
||||
3
1.0.2/core/widgets/__init__.py
Normal file
3
1.0.2/core/widgets/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Widgets module
|
||||
"""
|
||||
34
1.0.2/core/widgets/key.py
Normal file
34
1.0.2/core/widgets/key.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# 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.set_label(self._primary_symbol)
|
||||
|
||||
self.setup_signals()
|
||||
|
||||
|
||||
def toggle_caps(self, widget = None, eve = None):
|
||||
self._is_upper = not self._is_upper
|
||||
self.set_label(self._primary_symbol.upper()) if self._is_upper else self.set_label(self._primary_symbol.lower())
|
||||
|
||||
def setup_signals(self):
|
||||
self.connect("released", self._clicked)
|
||||
self.connect("toggle-caps", self.toggle_caps)
|
||||
|
||||
def _clicked(self, widget = None):
|
||||
key = self.get_label().strip()
|
||||
typwriter.type(key)
|
||||
36
1.0.2/core/window.py
Normal file
36
1.0.2/core/window.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from .container import Container
|
||||
|
||||
|
||||
|
||||
class Window(Gtk.ApplicationWindow):
|
||||
"""docstring for Window."""
|
||||
|
||||
def __init__(self, args, unknownargs):
|
||||
super(Window, self).__init__()
|
||||
|
||||
self.setup_styling()
|
||||
self.setup_signals()
|
||||
self.add(Container())
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def setup_styling(self):
|
||||
# self.set_icon_from_file("/usr/share/bulkr/bulkr.png")
|
||||
self.set_title(app_name)
|
||||
self.set_default_size(800, 200)
|
||||
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_signals(self):
|
||||
self.connect("delete-event", Gtk.main_quit)
|
||||
Reference in New Issue
Block a user