mirror of
https://github.com/aclist/dztui.git
synced 2026-10-30 14:42:54 +01:00
chore: restructure as Gtk.Application and drop Gtk.main loop
This commit is contained in:
1 parent
2e2d3484c4
commit
ea2ca684d6
1 file changed
+22
-11
+22
-11
@@ -2,9 +2,14 @@ import logging
|
|||||||
import signal
|
import signal
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, Literal
|
from typing import TYPE_CHECKING, Literal, Self
|
||||||
|
|
||||||
from dzgui.const.constants import APP_NAME, APP_NAME_LOWER, STEAM_ICON
|
from dzgui.const.constants import (
|
||||||
|
APP_NAME,
|
||||||
|
APP_NAME_LOWER,
|
||||||
|
GTK_APP_ID,
|
||||||
|
STEAM_ICON,
|
||||||
|
)
|
||||||
from dzgui.const.enum import NotebookPage
|
from dzgui.const.enum import NotebookPage
|
||||||
from dzgui.controllers.emitter import Emitter
|
from dzgui.controllers.emitter import Emitter
|
||||||
from dzgui.controllers.mc import Controller
|
from dzgui.controllers.mc import Controller
|
||||||
@@ -14,6 +19,7 @@ from dzgui.views.components.connect_panel import ConnectPanel
|
|||||||
from dzgui.views.components.crumbs import Breadcrumbs
|
from dzgui.views.components.crumbs import Breadcrumbs
|
||||||
from dzgui.views.components.right_panel import RightPanel
|
from dzgui.views.components.right_panel import RightPanel
|
||||||
from dzgui.views.components.statusbar import Statusbar
|
from dzgui.views.components.statusbar import Statusbar
|
||||||
|
from dzgui.views.mixins.colorscheme import ColorAwareApp
|
||||||
from dzgui.views.mixins.scrollable_mixin import ScrollableMixin
|
from dzgui.views.mixins.scrollable_mixin import ScrollableMixin
|
||||||
|
|
||||||
# TODO: import notebook only and add components there?
|
# TODO: import notebook only and add components there?
|
||||||
@@ -34,7 +40,7 @@ import gi
|
|||||||
|
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
gi.require_version("GLibUnix", "2.0")
|
gi.require_version("GLibUnix", "2.0")
|
||||||
from gi.repository import Gtk, GLib, GLibUnix, Gdk # type: ignore # noqa E402
|
from gi.repository import Gtk, GLib, GLibUnix, Gdk # noqa E402
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from dzgui.config.userprefs import UserPrefs
|
from dzgui.config.userprefs import UserPrefs
|
||||||
@@ -46,9 +52,11 @@ logger = logging.getLogger(APP_NAME)
|
|||||||
warnings.filterwarnings("ignore", ".*g_value_get_int", Warning)
|
warnings.filterwarnings("ignore", ".*g_value_get_int", Warning)
|
||||||
|
|
||||||
|
|
||||||
class OuterWindow(Gtk.Window):
|
class OuterWindow(Gtk.ApplicationWindow):
|
||||||
def __init__(self) -> None:
|
def __init__(self, app: Gtk.Application) -> None:
|
||||||
super().__init__(title=APP_NAME, border_width=10, icon_name=APP_NAME_LOWER)
|
super().__init__(
|
||||||
|
application=app, title=APP_NAME, border_width=10, icon_name=APP_NAME_LOWER
|
||||||
|
)
|
||||||
|
|
||||||
self.hb = AppHeaderBar()
|
self.hb = AppHeaderBar()
|
||||||
MainController.register_widget("window", self)
|
MainController.register_widget("window", self)
|
||||||
@@ -279,13 +287,18 @@ class Grid(Gtk.Grid):
|
|||||||
self.right_panel.refresh_button.set_visible(state)
|
self.right_panel.refresh_button.set_visible(state)
|
||||||
|
|
||||||
|
|
||||||
class App(Gtk.Application):
|
class App(ColorAwareApp, Gtk.Application): # type: ignore
|
||||||
def __init__(self, prefs: "UserPrefs") -> None:
|
def __init__(self, prefs: "UserPrefs") -> None:
|
||||||
|
super().__init__(application_id=GTK_APP_ID)
|
||||||
|
|
||||||
GLib.set_prgname(APP_NAME)
|
GLib.set_prgname(APP_NAME)
|
||||||
MainController.set_prefs(prefs)
|
MainController.set_prefs(prefs)
|
||||||
|
|
||||||
self.win = OuterWindow()
|
self._setup_signals()
|
||||||
|
self.connect("activate", self._on_activate)
|
||||||
|
|
||||||
|
def _on_activate(self, app: Self) -> None:
|
||||||
|
self.win = OuterWindow(app)
|
||||||
|
|
||||||
accel = Gtk.AccelGroup()
|
accel = Gtk.AccelGroup()
|
||||||
accel.connect(
|
accel.connect(
|
||||||
@@ -296,9 +309,6 @@ class App(Gtk.Application):
|
|||||||
)
|
)
|
||||||
self.win.add_accel_group(accel)
|
self.win.add_accel_group(accel)
|
||||||
|
|
||||||
self._setup_signals()
|
|
||||||
Gtk.main()
|
|
||||||
|
|
||||||
def _setup_signals(self) -> None:
|
def _setup_signals(self) -> None:
|
||||||
SIGNAL_ADD = "signal_add"
|
SIGNAL_ADD = "signal_add"
|
||||||
SIGNAL_ADD_FULL = "signal_add_full"
|
SIGNAL_ADD_FULL = "signal_add_full"
|
||||||
@@ -330,6 +340,7 @@ class App(Gtk.Application):
|
|||||||
|
|
||||||
MainController = Controller()
|
MainController = Controller()
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
theme = Gtk.IconTheme.get_default()
|
theme = Gtk.IconTheme.get_default()
|
||||||
icons = theme.list_icons(None)
|
icons = theme.list_icons(None)
|
||||||
|
|||||||
Reference in new issue
Block a user