Newton_Editor/src/core/controller.py

68 lines
2.1 KiB
Python
Raw Normal View History

2023-03-18 04:17:38 +00:00
# Python imports
import os
2023-03-18 04:17:38 +00:00
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GLib
# Application imports
from .controller_data import ControllerData
from .core_widget import CoreWidget
2023-03-18 22:04:31 +00:00
from .mixins.signals_mixins import SignalsMixins
2023-03-18 04:17:38 +00:00
2023-03-18 22:04:31 +00:00
class Controller(SignalsMixins, ControllerData):
2023-03-18 04:17:38 +00:00
def __init__(self, args, unknownargs):
2023-09-10 05:24:47 +00:00
messages = []
for arg in unknownargs + [args.new_tab,]:
2023-09-13 03:14:31 +00:00
# NOTE: If passing line number with file split against :
if os.path.isfile(arg.replace("file://", "").split(":")[0]):
messages.append(f"FILE|{arg.replace('file://', '')}")
2023-09-10 05:24:47 +00:00
if len(messages) > 0:
settings_manager.set_is_starting_with_file(True)
2023-09-10 05:24:47 +00:00
2023-03-18 22:04:31 +00:00
self.setup_controller_data()
2023-03-18 04:17:38 +00:00
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
if args.no_plugins == "false":
self.plugins.launch_plugins()
2023-09-10 05:24:47 +00:00
for message in messages:
event_system.emit("post_file_to_ipc", message)
2023-03-18 04:17:38 +00:00
def _setup_styling(self):
...
def _setup_signals(self):
2023-03-18 22:04:31 +00:00
self.window.connect("focus-out-event", self.unset_keys_and_data)
self.window.connect("key-press-event", self.on_global_key_press_controller)
self.window.connect("key-release-event", self.on_global_key_release_controller)
2023-03-18 04:17:38 +00:00
def _subscribe_to_events(self):
event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
event_system.subscribe("set_active_src_view", self.set_active_src_view)
event_system.subscribe("get_active_src_view", self.get_active_src_view)
2023-03-18 04:17:38 +00:00
def load_glade_file(self):
self.builder = Gtk.Builder()
self.builder.add_from_file(settings_manager.get_glade_file())
2023-03-18 04:17:38 +00:00
self.builder.expose_object("main_window", self.window)
settings_manager.set_builder(self.builder)
2023-03-18 04:17:38 +00:00
self.core_widget = CoreWidget()
settings_manager.register_signals_to_builder([self, self.core_widget])
2023-03-18 04:17:38 +00:00
def get_core_widget(self):
return self.core_widget