2022-10-14 01:58:44 +00:00
|
|
|
# Python imports
|
|
|
|
import os
|
2023-02-24 00:48:37 +00:00
|
|
|
import subprocess
|
2022-10-14 01:58:44 +00:00
|
|
|
|
|
|
|
# Lib imports
|
|
|
|
|
|
|
|
# Application imports
|
|
|
|
from plugins.plugins_controller import PluginsController
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-01-29 06:06:52 +00:00
|
|
|
|
2022-10-14 01:58:44 +00:00
|
|
|
class ControllerData:
|
|
|
|
''' ControllerData contains most of the state of the app at ay given time. It also has some support methods. '''
|
|
|
|
|
|
|
|
def setup_controller_data(self) -> None:
|
2023-03-18 20:30:29 +00:00
|
|
|
self.window = settings.get_main_window()
|
|
|
|
self.builder = None
|
|
|
|
self.core_widget = None
|
2023-03-19 20:37:43 +00:00
|
|
|
self.was_midified_key = False
|
2023-03-18 20:30:29 +00:00
|
|
|
self.ctrl_down = False
|
|
|
|
self.shift_down = False
|
|
|
|
self.alt_down = False
|
2022-10-14 01:58:44 +00:00
|
|
|
|
|
|
|
self.load_glade_file()
|
2023-03-18 20:30:29 +00:00
|
|
|
self.plugins = PluginsController()
|
2022-10-14 01:58:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
def clear_console(self) -> None:
|
|
|
|
''' Clears the terminal screen. '''
|
|
|
|
os.system('cls' if os.name == 'nt' else 'clear')
|
|
|
|
|
|
|
|
def call_method(self, _method_name: str, data: type) -> type:
|
|
|
|
'''
|
|
|
|
Calls a method from scope of class.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
a (obj): self
|
|
|
|
b (str): method name to be called
|
|
|
|
c (*): Data (if any) to be passed to the method.
|
|
|
|
Note: It must be structured according to the given methods requirements.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Return data is that which the calling method gives.
|
|
|
|
'''
|
|
|
|
method_name = str(_method_name)
|
|
|
|
method = getattr(self, method_name, lambda data: f"No valid key passed...\nkey={method_name}\nargs={data}")
|
|
|
|
return method(*data) if data else method()
|
|
|
|
|
|
|
|
def has_method(self, obj: type, method: type) -> type:
|
|
|
|
''' Checks if a given method exists. '''
|
|
|
|
return callable(getattr(obj, method, None))
|
|
|
|
|
|
|
|
def clear_children(self, widget: type) -> None:
|
|
|
|
''' Clear children of a gtk widget. '''
|
|
|
|
for child in widget.get_children():
|
|
|
|
widget.remove(child)
|
2023-02-24 00:48:37 +00:00
|
|
|
|
2023-03-04 03:20:53 +00:00
|
|
|
def get_clipboard_data(self, encoding="utf-8") -> str:
|
2023-02-24 00:48:37 +00:00
|
|
|
proc = subprocess.Popen(['xclip','-selection', 'clipboard', '-o'], stdout=subprocess.PIPE)
|
|
|
|
retcode = proc.wait()
|
|
|
|
data = proc.stdout.read()
|
2023-03-04 03:20:53 +00:00
|
|
|
return data.decode(encoding).strip()
|
2023-02-24 00:48:37 +00:00
|
|
|
|
2023-03-04 03:20:53 +00:00
|
|
|
def set_clipboard_data(self, data: type, encoding="utf-8") -> None:
|
2023-02-24 00:48:37 +00:00
|
|
|
proc = subprocess.Popen(['xclip','-selection','clipboard'], stdin=subprocess.PIPE)
|
2023-03-04 03:20:53 +00:00
|
|
|
proc.stdin.write(data.encode(encoding))
|
2023-02-24 00:48:37 +00:00
|
|
|
proc.stdin.close()
|
|
|
|
retcode = proc.wait()
|