2022-10-14 01:58:44 +00:00
|
|
|
# Python imports
|
|
|
|
import signal
|
|
|
|
|
|
|
|
# Lib imports
|
|
|
|
import gi
|
|
|
|
import cairo
|
|
|
|
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 core.controller import Controller
|
|
|
|
|
|
|
|
|
2023-02-24 00:48:37 +00:00
|
|
|
class ControllerStartExceptiom(Exception):
|
|
|
|
...
|
|
|
|
|
|
|
|
|
2022-10-14 01:58:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Window(Gtk.ApplicationWindow):
|
2023-03-28 02:25:54 +00:00
|
|
|
""" docstring for Window. """
|
2022-10-14 01:58:44 +00:00
|
|
|
|
|
|
|
def __init__(self, args, unknownargs):
|
|
|
|
super(Window, self).__init__()
|
2023-07-30 05:36:52 +00:00
|
|
|
settings_manager.set_main_window(self)
|
2022-10-14 01:58:44 +00:00
|
|
|
|
2023-02-24 00:48:37 +00:00
|
|
|
self._controller = None
|
|
|
|
|
2022-10-14 01:58:44 +00:00
|
|
|
self._set_window_data()
|
|
|
|
self._setup_styling()
|
|
|
|
self._setup_signals()
|
2023-02-24 00:48:37 +00:00
|
|
|
self._subscribe_to_events()
|
2022-10-14 01:58:44 +00:00
|
|
|
self._load_widgets(args, unknownargs)
|
|
|
|
|
2023-04-29 14:27:21 +00:00
|
|
|
self._set_size_constraints()
|
2023-07-30 05:36:52 +00:00
|
|
|
self.show()
|
2023-04-29 14:27:21 +00:00
|
|
|
|
2022-10-14 01:58:44 +00:00
|
|
|
|
|
|
|
def _setup_styling(self):
|
|
|
|
self.set_title(f"{app_name}")
|
2023-07-30 05:36:52 +00:00
|
|
|
self.set_icon_from_file( settings_manager.get_window_icon() )
|
2022-10-14 01:58:44 +00:00
|
|
|
self.set_gravity(5) # 5 = CENTER
|
|
|
|
self.set_position(1) # 1 = CENTER, 4 = CENTER_ALWAYS
|
|
|
|
|
2023-10-21 23:58:20 +00:00
|
|
|
ctx = self.get_style_context()
|
|
|
|
ctx.add_class("main-window")
|
|
|
|
ctx.add_class(f"mw_transparency_{settings.theming.transparency}")
|
|
|
|
|
2022-10-14 01:58:44 +00:00
|
|
|
def _setup_signals(self):
|
|
|
|
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, self._tear_down)
|
2023-07-30 05:36:52 +00:00
|
|
|
self.connect("delete-event", self._tear_down)
|
2022-10-14 01:58:44 +00:00
|
|
|
|
2023-02-24 00:48:37 +00:00
|
|
|
def _subscribe_to_events(self):
|
|
|
|
event_system.subscribe("tear_down", self._tear_down)
|
2023-10-21 23:58:20 +00:00
|
|
|
event_system.subscribe("load_interactive_debug", self._load_interactive_debug)
|
2023-02-24 00:48:37 +00:00
|
|
|
|
2022-10-14 01:58:44 +00:00
|
|
|
def _load_widgets(self, args, unknownargs):
|
2023-07-30 05:36:52 +00:00
|
|
|
if settings_manager.is_debug():
|
2023-03-07 03:26:48 +00:00
|
|
|
self.set_interactive_debugging(True)
|
|
|
|
|
|
|
|
self._controller = Controller(args, unknownargs)
|
2023-02-24 00:48:37 +00:00
|
|
|
if not self._controller:
|
|
|
|
raise ControllerStartException("Controller exited and doesn't exist...")
|
|
|
|
|
2023-04-23 15:57:12 +00:00
|
|
|
self.add( self._controller.get_base_container() )
|
2022-10-14 01:58:44 +00:00
|
|
|
|
2023-04-29 14:27:21 +00:00
|
|
|
def _set_size_constraints(self):
|
2023-07-30 05:36:52 +00:00
|
|
|
_window_x = settings.config.main_window_x
|
|
|
|
_window_y = settings.config.main_window_y
|
|
|
|
_min_width = settings.config.main_window_min_width
|
|
|
|
_min_height = settings.config.main_window_min_height
|
|
|
|
_width = settings.config.main_window_width
|
|
|
|
_height = settings.config.main_window_height
|
|
|
|
|
|
|
|
self.move(_window_x, _window_y - 28)
|
|
|
|
self.set_size_request(_min_width, _min_height)
|
|
|
|
self.set_default_size(_width, _height)
|
2023-04-29 14:27:21 +00:00
|
|
|
|
2022-10-14 01:58:44 +00:00
|
|
|
def _set_window_data(self) -> None:
|
|
|
|
screen = self.get_screen()
|
|
|
|
visual = screen.get_rgba_visual()
|
|
|
|
|
2023-07-30 05:36:52 +00:00
|
|
|
if visual and screen.is_composited() and settings.config.make_transparent == 0:
|
2022-10-14 01:58:44 +00:00
|
|
|
self.set_visual(visual)
|
|
|
|
self.set_app_paintable(True)
|
|
|
|
self.connect("draw", self._area_draw)
|
|
|
|
|
|
|
|
# bind css file
|
|
|
|
cssProvider = Gtk.CssProvider()
|
2023-07-30 05:36:52 +00:00
|
|
|
cssProvider.load_from_path( settings_manager.get_css_file() )
|
2022-10-14 01:58:44 +00:00
|
|
|
screen = Gdk.Screen.get_default()
|
|
|
|
styleContext = Gtk.StyleContext()
|
|
|
|
styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
|
|
|
|
|
|
|
|
def _area_draw(self, widget: Gtk.ApplicationWindow, cr: cairo.Context) -> None:
|
2023-07-30 05:36:52 +00:00
|
|
|
cr.set_source_rgba( *settings_manager.get_paint_bg_color() )
|
2022-10-14 01:58:44 +00:00
|
|
|
cr.set_operator(cairo.OPERATOR_SOURCE)
|
|
|
|
cr.paint()
|
|
|
|
cr.set_operator(cairo.OPERATOR_OVER)
|
|
|
|
|
2023-10-21 23:58:20 +00:00
|
|
|
def _load_interactive_debug(self):
|
|
|
|
self.set_interactive_debugging(True)
|
|
|
|
|
2022-10-14 01:58:44 +00:00
|
|
|
|
2023-07-30 05:36:52 +00:00
|
|
|
def _tear_down(self, widget = None, eve = None):
|
2023-10-19 00:00:33 +00:00
|
|
|
event_system.emit("shutting_down")
|
|
|
|
|
2023-07-30 05:36:52 +00:00
|
|
|
size = self.get_default_size()
|
|
|
|
pos = self.get_position()
|
|
|
|
|
|
|
|
settings_manager.set_main_window_width(size.width)
|
|
|
|
settings_manager.set_main_window_height(size.height)
|
|
|
|
settings_manager.set_main_window_x(pos.root_x)
|
|
|
|
settings_manager.set_main_window_y(pos.root_y)
|
|
|
|
settings_manager.save_settings()
|
|
|
|
|
|
|
|
settings_manager.clear_pid()
|
2022-10-14 01:58:44 +00:00
|
|
|
Gtk.main_quit()
|