2023-11-25 00:55:01 +00:00
|
|
|
#!/usr/bin/env python3
|
2024-02-05 07:18:40 +00:00
|
|
|
import logging
|
2023-12-26 17:02:43 +00:00
|
|
|
from pathlib import Path
|
2023-12-16 12:03:10 +00:00
|
|
|
|
2023-11-25 00:55:01 +00:00
|
|
|
import gi
|
2023-12-16 12:03:10 +00:00
|
|
|
|
2024-01-17 12:11:49 +00:00
|
|
|
gi.require_version("Gtk", "4.0")
|
|
|
|
gi.require_version("Adw", "1")
|
2024-01-02 04:54:19 +00:00
|
|
|
|
2024-01-17 12:11:49 +00:00
|
|
|
from gi.repository import Adw, Gdk, Gio, Gtk
|
2023-12-16 12:03:10 +00:00
|
|
|
|
2024-01-20 09:11:52 +00:00
|
|
|
from clan_vm_manager.models.interfaces import ClanConfig
|
|
|
|
from clan_vm_manager.models.use_vms import VMS
|
2023-12-26 17:02:43 +00:00
|
|
|
|
2024-01-20 09:11:52 +00:00
|
|
|
from .constants import constants
|
|
|
|
from .windows.main_window import MainWindow
|
2023-12-16 11:52:10 +00:00
|
|
|
|
2024-02-05 07:18:40 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2023-11-28 17:19:01 +00:00
|
|
|
|
2024-01-20 09:11:52 +00:00
|
|
|
class MainApplication(Adw.Application):
|
2024-01-17 12:11:49 +00:00
|
|
|
def __init__(self, config: ClanConfig) -> None:
|
|
|
|
super().__init__(
|
|
|
|
application_id=constants["APPID"], flags=Gio.ApplicationFlags.FLAGS_NONE
|
2023-12-30 10:14:45 +00:00
|
|
|
)
|
2024-01-17 12:11:49 +00:00
|
|
|
self.config = config
|
|
|
|
self.connect("shutdown", self.on_shutdown)
|
2023-12-30 10:14:45 +00:00
|
|
|
|
2024-01-17 12:11:49 +00:00
|
|
|
def on_shutdown(self, app: Gtk.Application) -> None:
|
2024-02-05 07:18:40 +00:00
|
|
|
log.debug("Shutting down")
|
2024-01-17 12:11:49 +00:00
|
|
|
VMS.use().kill_all()
|
2023-11-28 17:19:01 +00:00
|
|
|
|
2023-11-30 12:42:15 +00:00
|
|
|
def do_activate(self) -> None:
|
2024-01-17 12:11:49 +00:00
|
|
|
self.init_style()
|
|
|
|
window = MainWindow(config=self.config)
|
|
|
|
window.set_application(self)
|
|
|
|
window.present()
|
2023-11-28 17:19:01 +00:00
|
|
|
|
|
|
|
# TODO: For css styling
|
2023-11-30 12:42:15 +00:00
|
|
|
def init_style(self) -> None:
|
2024-01-17 12:11:49 +00:00
|
|
|
resource_path = Path(__file__).parent / "style.css"
|
|
|
|
css_provider = Gtk.CssProvider()
|
|
|
|
css_provider.load_from_path(str(resource_path))
|
|
|
|
Gtk.StyleContext.add_provider_for_display(
|
|
|
|
Gdk.Display.get_default(),
|
|
|
|
css_provider,
|
|
|
|
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION,
|
|
|
|
)
|