Skip to content

Commit b379523

Browse files
committed
move stylesheet loading out of breakscreen
1 parent f3e34c3 commit b379523

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

safeeyes/safeeyes.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,11 @@ def do_startup(self):
104104
else:
105105
self.context["session"] = {"plugin": {}}
106106

107+
# Initialize the theme
108+
self._initialize_styles()
109+
107110
self.break_screen = BreakScreen(
108-
self,
109-
self.context,
110-
self.on_skipped,
111-
self.on_postponed,
112-
utility.STYLE_SHEET_PATH,
111+
self, self.context, self.on_skipped, self.on_postponed
113112
)
114113
self.break_screen.initialize(self.config)
115114
self.plugins_manager = PluginManager()
@@ -166,6 +165,11 @@ def do_activate(self):
166165
elif self.cli_args.take_break:
167166
self.take_break()
168167

168+
def _initialize_styles(self):
169+
utility.load_css_file(
170+
utility.STYLE_SHEET_PATH, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
171+
)
172+
169173
def _retry_errored_plugins(self):
170174
if not self.plugins_manager.needs_retry():
171175
return

safeeyes/ui/break_screen.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ class BreakScreen:
4343
interface.
4444
"""
4545

46-
def __init__(
47-
self, application, context, on_skipped, on_postponed, style_sheet_path
48-
):
46+
def __init__(self, application, context, on_skipped, on_postponed):
4947
self.application = application
5048
self.context = context
5149
self.count_labels = []
@@ -64,15 +62,6 @@ def __init__(
6462
if not self.context["is_wayland"]:
6563
self.x11_display = Display()
6664

67-
# Initialize the theme
68-
css_provider = Gtk.CssProvider()
69-
css_provider.load_from_path(style_sheet_path)
70-
71-
display = Gdk.Display.get_default()
72-
Gtk.StyleContext.add_provider_for_display(
73-
display, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
74-
)
75-
7665
def initialize(self, config):
7766
"""Initialize the internal properties from configuration."""
7867
logging.info("Initialize the break screen")

safeeyes/utility.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@
3838
import gi
3939

4040
gi.require_version("Gtk", "4.0")
41+
gi.require_version("Gdk", "4.0")
42+
43+
from gi.repository import Gdk
4144
from gi.repository import Gtk
4245
from gi.repository import GLib
4346
from gi.repository import GdkPixbuf
4447
from packaging.version import parse
4548

46-
gi.require_version("Gdk", "4.0")
47-
4849
BIN_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
4950
HOME_DIRECTORY = os.environ.get("HOME") or os.path.expanduser("~")
5051
CONFIG_DIRECTORY = os.path.join(
@@ -372,6 +373,14 @@ def merge_configs(new_config, old_config):
372373
return new_config
373374

374375

376+
def load_css_file(style_sheet_path, priority):
377+
css_provider = Gtk.CssProvider()
378+
css_provider.load_from_path(style_sheet_path)
379+
380+
display = Gdk.Display.get_default()
381+
Gtk.StyleContext.add_provider_for_display(display, css_provider, priority)
382+
383+
375384
def initialize_safeeyes():
376385
"""Create the config file and style sheet in XDG_CONFIG_HOME(or
377386
~/.config)/safeeyes directory.

0 commit comments

Comments
 (0)