Added delete of command; added initial special key handling in commands

This commit is contained in:
itdominator 2024-02-29 19:42:40 -06:00
parent 82fc45373d
commit c3c85a3040
3 changed files with 68 additions and 20 deletions

View File

@ -6,6 +6,8 @@ import threading
# Lib imports
# Application imports
from libs.logger import Logger
from libs.pyautogui_control import ControlMixin
from libs.endpoint_registry import EndpointRegistry
from libs.event_system import EventSystem
@ -73,24 +75,25 @@ builtins.debug = False
builtins.app_settings = None
builtins.get_clipboard = ['xclip','-selection', 'clipboard', '-o']
builtins.set_clipboard = ['xclip','-selection','clipboard']
builtins.endpoint_registry = EndpointRegistry()
builtins.event_system = EventSystem()
builtins.typwriter = Pyautogui_Controller()
builtins.FKEYS = [ f"F{i}" for i in range(1, 13) ]
builtins.LSIDE_KEYS = ["<Ctrl>", "<Shift>", "<Alt>"]
builtins.RSIDE_KEYS = ["</Ctrl>", "</Shift>", "</Alt>"]
_USER_HOME = os.path.expanduser('~')
_USR_PATH = f"/usr/share/{app_name.lower()}"
_CONFIG_PATH = f"{_USER_HOME}/.config/{app_name.lower()}"
_ICON_FILE = f"{_CONFIG_PATH}/icons/{app_name.lower()}.png"
_CSS_FILE = f"{_CONFIG_PATH}/stylesheet.css"
_EMOJI_FILE = f"{_CONFIG_PATH}/emoji.json"
_USER_HOME = os.path.expanduser('~')
_USR_PATH = f"/usr/share/{app_name.lower()}"
_CONFIG_PATH = f"{_USER_HOME}/.config/{app_name.lower()}"
_ICON_FILE = f"{_CONFIG_PATH}/icons/{app_name.lower()}.png"
_CSS_FILE = f"{_CONFIG_PATH}/stylesheet.css"
_EMOJI_FILE = f"{_CONFIG_PATH}/emoji.json"
_LOG_FILE = f"{_CONFIG_PATH}/application.log"
ch_log_lvl: int = 10
fh_log_lvl: int = 20
if not os.path.exists(_ICON_FILE):
_ICON_FILE = f"{_USR_PATH}/icons/{app_name.lower()}.png"
if not os.path.exists(_ICON_FILE):
print(_ICON_FILE)
raise MissingConfigError("Unable to find the application icon.")
if not os.path.exists(_CSS_FILE):
@ -104,8 +107,13 @@ if not os.path.exists(_EMOJI_FILE):
raise MissingConfigError("Unable to find the stylesheet.")
builtins.CONFIG_PATH = _CONFIG_PATH
builtins.ICON_FILE = _ICON_FILE
builtins.CSS_FILE = _CSS_FILE
builtins.EMOJI_FILE = _EMOJI_FILE
builtins.logger = Logger(_LOG_FILE, ch_log_lvl, fh_log_lvl).get_logger()
builtins.endpoint_registry = EndpointRegistry()
builtins.event_system = EventSystem()
builtins.typwriter = Pyautogui_Controller()

View File

@ -52,9 +52,9 @@ class List_Box(Gtk.ScrolledWindow):
event_system.subscribe("del_command", self.del_command)
def add_widgets(self):
tree, self.store = self.create_treeview()
self.tree, self.store = self.create_treeview()
self.add(tree)
self.add(self.tree)
self.set_size_request(360, 240)
def create_treeview(self):
@ -108,9 +108,19 @@ class List_Box(Gtk.ScrolledWindow):
f.write( commands.strip() )
def _row_activated(self, tree_view, path, column):
itr = self.store.get_iter(path)
command = self.store.get_value(itr, 0)
typwriter.type(command)
itr = self.store.get_iter(path)
command = self.store.get_value(itr, 0)
use_special = False
for arg in LSIDE_KEYS + RSIDE_KEYS + FKEYS:
if arg in command:
use_special = True
break
if use_special:
self.handle_as_special(command)
else:
typwriter.type(command)
def run_command(self):
...
@ -119,7 +129,32 @@ class List_Box(Gtk.ScrolledWindow):
self.store.append([command])
def del_command(self):
...
path, column = self.tree.get_cursor()
if not path or not column: return
model = self.tree.get_model()
itr = model.get_iter(path)
if not itr: return
self.store.remove(itr)
def handle_as_special(self, command):
lside_count = []
rside_count = []
for arg in LSIDE_KEYS:
lside_count.append( command.count(arg) )
for arg in RSIDE_KEYS:
rside_count.append( command.count(arg) )
if not lside_count == rside_count:
logger.info("Special keys don't match in open/close count...")
return
typwriter.press_special_keys(command)
class CommandEntry(Gtk.Box):

View File

@ -1,10 +1,15 @@
# Python imports
import os, logging
import os
import logging
# Lib imports
# Application imports
from .singleton import Singleton
class Logger:
class Logger(Singleton):
"""
Create a new logging object and return it.
:note: