Refactoring, settings cleanup, glade load fixes
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
# Python imports
|
||||
import subprocess
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
@@ -26,6 +25,8 @@ class Controller(DummyMixin, ControllerData):
|
||||
self.setup_controller_data()
|
||||
self.print_hello_world() # A mixin method from the DummyMixin file
|
||||
|
||||
logger.info(f"Made it past {self.__class__} loading...")
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
...
|
||||
@@ -43,6 +44,8 @@ class Controller(DummyMixin, ControllerData):
|
||||
def load_glade_file(self):
|
||||
self.builder = Gtk.Builder()
|
||||
self.builder.add_from_file(settings.get_glade_file())
|
||||
self.builder.expose_object("main_window", self.window)
|
||||
|
||||
settings.set_builder(self.builder)
|
||||
self.core_widget = CoreWidget()
|
||||
|
||||
@@ -71,16 +74,3 @@ class Controller(DummyMixin, ControllerData):
|
||||
else:
|
||||
print(f"on_global_key_release_controller > key > {keyname}")
|
||||
print(f"Add logic or remove this from: {self.__class__}")
|
||||
|
||||
|
||||
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: type) -> None:
|
||||
proc = subprocess.Popen(['xclip','-selection','clipboard'], stdin=subprocess.PIPE)
|
||||
proc.stdin.write(data.encode("utf-8"))
|
||||
proc.stdin.close()
|
||||
retcode = proc.wait()
|
||||
|
@@ -1,5 +1,6 @@
|
||||
# Python imports
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
# Lib imports
|
||||
|
||||
@@ -13,7 +14,7 @@ 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:
|
||||
self.logger = settings.get_logger()
|
||||
self.window = settings.get_main_window()
|
||||
self.builder = None
|
||||
self.core_widget = None
|
||||
|
||||
@@ -50,3 +51,15 @@ class ControllerData:
|
||||
''' Clear children of a gtk widget. '''
|
||||
for child in widget.get_children():
|
||||
widget.remove(child)
|
||||
|
||||
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: type) -> None:
|
||||
proc = subprocess.Popen(['xclip','-selection','clipboard'], stdin=subprocess.PIPE)
|
||||
proc.stdin.write(data.encode("utf-8"))
|
||||
proc.stdin.close()
|
||||
retcode = proc.wait()
|
||||
|
@@ -14,6 +14,8 @@ class CoreWidget(Gtk.Box):
|
||||
def __init__(self):
|
||||
super(CoreWidget, self).__init__()
|
||||
|
||||
self._builder = settings.get_builder()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._load_widgets()
|
||||
@@ -28,10 +30,15 @@ class CoreWidget(Gtk.Box):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
button = Gtk.Button(label="Click Me!")
|
||||
glade_box = self._builder.get_object("glade_box")
|
||||
button = Gtk.Button(label="Click Me!")
|
||||
|
||||
button.connect("clicked", self._hello_world)
|
||||
|
||||
self.add(button)
|
||||
self.add(glade_box)
|
||||
|
||||
|
||||
|
||||
def _hello_world(self, widget=None, eve=None):
|
||||
print("Hello, World!")
|
||||
|
@@ -15,6 +15,10 @@ from gi.repository import GLib
|
||||
from core.controller import Controller
|
||||
|
||||
|
||||
class ControllerStartExceptiom(Exception):
|
||||
...
|
||||
|
||||
|
||||
|
||||
|
||||
class Window(Gtk.ApplicationWindow):
|
||||
@@ -23,12 +27,17 @@ class Window(Gtk.ApplicationWindow):
|
||||
def __init__(self, args, unknownargs):
|
||||
super(Window, self).__init__()
|
||||
|
||||
self._controller = None
|
||||
|
||||
self._set_window_data()
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
|
||||
settings.set_main_window(self)
|
||||
self._load_widgets(args, unknownargs)
|
||||
|
||||
self.show_all()
|
||||
self.show()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
@@ -42,9 +51,16 @@ class Window(Gtk.ApplicationWindow):
|
||||
self.connect("delete-event", self._tear_down)
|
||||
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, self._tear_down)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("tear_down", self._tear_down)
|
||||
|
||||
def _load_widgets(self, args, unknownargs):
|
||||
controller = Controller(args, unknownargs)
|
||||
self.add( controller.get_core_widget() )
|
||||
self._controller = Controller(args, unknownargs)
|
||||
|
||||
if not self._controller:
|
||||
raise ControllerStartException("Controller exited and doesn't exist...")
|
||||
|
||||
self.add( self._controller.get_core_widget() )
|
||||
|
||||
def _set_window_data(self) -> None:
|
||||
screen = self.get_screen()
|
||||
|
Reference in New Issue
Block a user