added settings, cleaned up keybindings formatting

This commit is contained in:
itdominator 2023-03-18 14:53:16 -05:00
parent 628bd296c2
commit 4b62747e02
4 changed files with 21 additions and 20 deletions

View File

@ -83,7 +83,7 @@ class Window(Gtk.ApplicationWindow):
styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER) styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
def _area_draw(self, widget: Gtk.ApplicationWindow, cr: cairo.Context) -> None: def _area_draw(self, widget: Gtk.ApplicationWindow, cr: cairo.Context) -> None:
cr.set_source_rgba(0, 0, 0, 0.54) cr.set_source_rgba( *settings.get_paint_bg_color() )
cr.set_operator(cairo.OPERATOR_SOURCE) cr.set_operator(cairo.OPERATOR_SOURCE)
cr.paint() cr.paint()
cr.set_operator(cairo.OPERATOR_OVER) cr.set_operator(cairo.OPERATOR_OVER)

View File

@ -12,16 +12,15 @@ from gi.repository import Gdk
def err(log = ""): def err(log = ""):
"""Print an error message"""
print(log) print(log)
class KeymapError(Exception): class KeymapError(Exception):
"""Custom exception for errors in keybinding configurations""" """ Custom exception for errors in keybinding configurations """
MODIFIER = re.compile('<([^<]+)>') MODIFIER = re.compile('<([^<]+)>')
class Keybindings: class Keybindings:
"""Class to handle loading and lookup of Terminator keybindings""" """ Class to handle loading and lookup of Terminator keybindings """
modifiers = { modifiers = {
'ctrl': Gdk.ModifierType.CONTROL_MASK, 'ctrl': Gdk.ModifierType.CONTROL_MASK,
@ -44,12 +43,12 @@ class Keybindings:
self.configure({}) self.configure({})
def configure(self, bindings): def configure(self, bindings):
"""Accept new bindings and reconfigure with them""" """ Accept new bindings and reconfigure with them """
self.keys = bindings self.keys = bindings
self.reload() self.reload()
def reload(self): def reload(self):
"""Parse bindings and mangle into an appropriate form""" """ Parse bindings and mangle into an appropriate form """
self._lookup = {} self._lookup = {}
self._masks = 0 self._masks = 0
@ -66,10 +65,10 @@ class Keybindings:
try: try:
keyval, mask = self._parsebinding(binding) keyval, mask = self._parsebinding(binding)
# Does much the same, but with poorer error handling. # Does much the same, but with worse error handling.
#keyval, mask = Gtk.accelerator_parse(binding) # keyval, mask = Gtk.accelerator_parse(binding)
except KeymapError as e: except KeymapError as e:
err ("keybinding reload failed to parse binding '%s': %s" % (binding, e)) err(f"Keybinding reload failed to parse binding '{binding}': {e}")
else: else:
if mask & Gdk.ModifierType.SHIFT_MASK: if mask & Gdk.ModifierType.SHIFT_MASK:
if keyval == Gdk.KEY_Tab: if keyval == Gdk.KEY_Tab:
@ -88,7 +87,7 @@ class Keybindings:
self._masks |= mask self._masks |= mask
def _parsebinding(self, binding): def _parsebinding(self, binding):
"""Parse an individual binding using Gtk's binding function""" """ Parse an individual binding using Gtk's binding function """
mask = 0 mask = 0
modifiers = re.findall(MODIFIER, binding) modifiers = re.findall(MODIFIER, binding)
@ -103,25 +102,25 @@ class Keybindings:
keyval = Gdk.keyval_from_name(key) keyval = Gdk.keyval_from_name(key)
if keyval == 0: if keyval == 0:
raise KeymapError("Key '%s' is unrecognised..." % key) raise KeymapError(f"Key '{key}' is unrecognised...")
return (keyval, mask) return (keyval, mask)
def _lookup_modifier(self, modifier): def _lookup_modifier(self, modifier):
"""Map modifier names to gtk values""" """ Map modifier names to gtk values """
try: try:
return self.modifiers[modifier.lower()] return self.modifiers[modifier.lower()]
except KeyError: except KeyError:
raise KeymapError("Unhandled modifier '<%s>'" % modifier) raise KeymapError(f"Unhandled modifier '<{modifier}>'")
def lookup(self, event): def lookup(self, event):
"""Translate a keyboard event into a mapped key""" """ Translate a keyboard event into a mapped key """
try: try:
_found, keyval, _egp, _lvl, consumed = self.keymap.translate_keyboard_state( _found, keyval, _egp, _lvl, consumed = self.keymap.translate_keyboard_state(
event.hardware_keycode, event.hardware_keycode,
Gdk.ModifierType(event.get_state() & ~Gdk.ModifierType.LOCK_MASK), Gdk.ModifierType(event.get_state() & ~Gdk.ModifierType.LOCK_MASK),
event.group) event.group)
except TypeError: except TypeError:
err ("Keybinding lookup failed to translate keyboard event: %s" % dir(event)) err(f"Keybinding lookup failed to translate keyboard event: {dir(event)}")
return None return None
mask = (event.get_state() & ~consumed) & self._masks mask = (event.get_state() & ~consumed) & self._masks

View File

@ -29,7 +29,7 @@ class Settings(StartCheckMixin):
self._CSS_FILE = f"{self._HOME_CONFIG_PATH}/stylesheet.css" self._CSS_FILE = f"{self._HOME_CONFIG_PATH}/stylesheet.css"
self._KEY_BINDINGS_FILE = f"{self._HOME_CONFIG_PATH}/key-bindings.json" self._KEY_BINDINGS_FILE = f"{self._HOME_CONFIG_PATH}/key-bindings.json"
self._PID_FILE = f"{self._HOME_CONFIG_PATH}/{app_name.lower()}.pid" self._PID_FILE = f"{self._HOME_CONFIG_PATH}/{app_name.lower()}.pid"
self._WINDOW_ICON = f"{self._DEFAULT_ICONS}/icons/{app_name.lower()}.png" self._WINDOW_ICON = f"{self._DEFAULT_ICONS}/{app_name.lower()}.png"
if not os.path.exists(self._HOME_CONFIG_PATH): if not os.path.exists(self._HOME_CONFIG_PATH):
os.mkdir(self._HOME_CONFIG_PATH) os.mkdir(self._HOME_CONFIG_PATH)
@ -73,6 +73,7 @@ class Settings(StartCheckMixin):
self._main_window_w = 800 self._main_window_w = 800
self._main_window_h = 600 self._main_window_h = 600
self._builder = None self._builder = None
self.PAINT_BG_COLOR = (0, 0, 0, 0.54)
self._trace_debug = False self._trace_debug = False
self._debug = False self._debug = False
@ -108,9 +109,10 @@ class Settings(StartCheckMixin):
return monitors return monitors
def get_main_window(self) -> any: return self._main_window def get_main_window(self) -> any: return self._main_window
def get_main_window_width(self) -> Gtk.ApplicationWindow: return self._main_window_w def get_main_window_width(self) -> any: return self._main_window_w
def get_main_window_height(self) -> Gtk.ApplicationWindow: return self._main_window_h def get_main_window_height(self) -> any: return self._main_window_h
def get_builder(self) -> any: return self._builder def get_builder(self) -> any: return self._builder
def get_paint_bg_color(self) -> any: return self.PAINT_BG_COLOR
def get_glade_file(self) -> str: return self._GLADE_FILE def get_glade_file(self) -> str: return self._GLADE_FILE
def get_plugins_path(self) -> str: return self._PLUGINS_PATH def get_plugins_path(self) -> str: return self._PLUGINS_PATH

View File

@ -5,7 +5,7 @@
"open_terminal" : "F4", "open_terminal" : "F4",
"refresh_tab" : ["F5", "<Control>r"], "refresh_tab" : ["F5", "<Control>r"],
"delete_files" : "Delete", "delete_files" : "Delete",
"tggl_top_main_menubar" : "<Alt>", "tggl_top_main_menubar" : "Alt",
"trash_files" : "<Shift><Control>t", "trash_files" : "<Shift><Control>t",
"tear_down" : "<Control>q", "tear_down" : "<Control>q",
"go_up" : "<Control>Up", "go_up" : "<Control>Up",