enforcing type better

This commit is contained in:
2022-03-24 22:11:02 -05:00
parent fdccf77367
commit 88db4171cf
8 changed files with 58 additions and 58 deletions

View File

@@ -36,7 +36,7 @@ class Controller(DummyMixin, Controller_Data):
@threaded
def gui_event_observer(self):
def gui_event_observer(self) -> None:
while True:
time.sleep(event_sleep_time)
event = event_system.consume_gui_event()
@@ -48,10 +48,10 @@ class Controller(DummyMixin, Controller_Data):
except Exception as e:
print(repr(e))
def handle_file_from_ipc(self, path):
def handle_file_from_ipc(self, path: str) -> None:
print(f"Path From IPC: {path}")
def on_global_key_release_controller(self, widget, event):
def on_global_key_release_controller(self, widget: type, event: type) -> None:
"""Handler for keyboard events"""
keyname = Gdk.keyval_name(event.keyval).lower()
if keyname.replace("_l", "").replace("_r", "") in ["control", "alt", "shift"]:
@@ -73,13 +73,13 @@ class Controller(DummyMixin, Controller_Data):
def get_clipboard_data(self):
def get_clipboard_data(self) -> str:
proc = subprocess.Popen(['xclip','-selection', 'clipboard', '-o'], stdout=subprocess.PIPE)
retcode = proc.wait()
data = proc.stdout.read()
return data.decode("utf-8").strip()
def set_clipboard_data(self, data):
def set_clipboard_data(self, data: type) -> None:
proc = subprocess.Popen(['xclip','-selection','clipboard'], stdin=subprocess.PIPE)
proc.stdin.write(data)
proc.stdin.close()

View File

@@ -11,7 +11,7 @@ from plugins.plugins import Plugins
class Controller_Data:
''' Controller_Data contains most of the state of the app at ay given time. It also has some support methods. '''
def setup_controller_data(self, _settings):
def setup_controller_data(self, _settings: type) -> None:
self.plugins = Plugins(_settings)
self.settings = _settings
@@ -30,11 +30,11 @@ class Controller_Data:
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, self.tear_down)
def clear_console(self):
def clear_console(self) -> None:
''' Clears the terminal screen. '''
os.system('cls' if os.name == 'nt' else 'clear')
def call_method(self, _method_name, data = None):
def call_method(self, _method_name: str, data: type) -> type:
'''
Calls a method from scope of class.
@@ -51,11 +51,11 @@ class Controller_Data:
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, name):
def has_method(self, obj: type, name: type) -> type:
''' Checks if a given method exists. '''
return callable(getattr(obj, name, None))
def clear_children(self, widget):
def clear_children(self, widget: type) -> None:
''' Clear children of a gtk widget. '''
for child in widget.get_children():
widget.remove(child)

View File

@@ -1,4 +1,4 @@
class DummyMixin:
""" DummyMixin is an example of how mixins are used and structured in a project. """
def print_hello_world(self):
def print_hello_world(self) -> None:
print("Hello, World!")