@@ -154,7 +154,7 @@ def __show_break_screen(self, message, image_path, widget, tray_actions):
154154 i = 0
155155
156156 for monitor in monitors :
157- w = BreakScreenWindow (
157+ window = BreakScreenWindow (
158158 self .application ,
159159 message ,
160160 image_path ,
@@ -167,8 +167,6 @@ def __show_break_screen(self, message, image_path, widget, tray_actions):
167167 self .on_skip_clicked ,
168168 )
169169
170- window = w .window
171-
172170 if self .context ["is_wayland" ]:
173171 # Note: in theory, this could also be used on X11
174172 # however, that already has its own implementation below
@@ -179,7 +177,7 @@ def __show_break_screen(self, message, image_path, widget, tray_actions):
179177
180178 window .set_title ("SafeEyes-" + str (i ))
181179
182- self .windows .append (w )
180+ self .windows .append (window )
183181
184182 if self .context ["desktop" ] == "kde" :
185183 # Fix flickering screen in KDE by setting opacity to 1
@@ -298,16 +296,26 @@ def __release_keyboard_x11(self):
298296 def __destroy_all_screens (self ):
299297 """Close all the break screens."""
300298 for win in self .windows :
301- win .window . destroy ()
299+ win .destroy ()
302300 del self .windows [:]
303301
304302
305- class BreakScreenWindow :
303+ @Gtk .Template (filename = BREAK_SCREEN_GLADE )
304+ class BreakScreenWindow (Gtk .Window ):
306305 """This class manages the UI for the break screen window.
307306
308307 Each instance is a single window, covering a single monitor.
309308 """
310309
310+ __gtype_name__ = "BreakScreenWindow"
311+
312+ lbl_message = Gtk .Template .Child ()
313+ lbl_count = Gtk .Template .Child ()
314+ lbl_widget = Gtk .Template .Child ()
315+ img_break = Gtk .Template .Child ()
316+ box_buttons = Gtk .Template .Child ()
317+ toolbar = Gtk .Template .Child ()
318+
311319 def __init__ (
312320 self ,
313321 application ,
@@ -321,21 +329,9 @@ def __init__(
321329 show_skip ,
322330 on_skip ,
323331 ):
324- self . on_close = on_close
332+ super (). __init__ ( application = application )
325333
326- builder = Gtk .Builder ()
327- builder .add_from_file (BREAK_SCREEN_GLADE )
328-
329- self .window = builder .get_object ("window_main" )
330- self .window .set_application (application )
331- self .window .connect ("close-request" , self .on_window_delete )
332-
333- lbl_message = builder .get_object ("lbl_message" )
334- self .lbl_count = builder .get_object ("lbl_count" )
335- lbl_widget = builder .get_object ("lbl_widget" )
336- img_break = builder .get_object ("img_break" )
337- box_buttons = builder .get_object ("box_buttons" )
338- toolbar = builder .get_object ("toolbar" )
334+ self .on_close = on_close
339335
340336 for tray_action in tray_actions :
341337 # TODO: apparently, this would be better served with an icon theme
@@ -350,7 +346,7 @@ def __init__(
350346 tray_action ,
351347 )
352348 toolbar_button .set_tooltip_text (_ (tray_action .name ))
353- toolbar .append (toolbar_button )
349+ self . toolbar .append (toolbar_button )
354350 toolbar_button .show ()
355351
356352 # Add the buttons
@@ -360,21 +356,21 @@ def __init__(
360356 btn_postpone .get_style_context ().add_class ("btn_postpone" )
361357 btn_postpone .connect ("clicked" , on_postpone )
362358 btn_postpone .set_visible (True )
363- box_buttons .append (btn_postpone )
359+ self . box_buttons .append (btn_postpone )
364360
365361 if show_skip :
366362 # Add the skip button
367363 btn_skip = Gtk .Button .new_with_label (_ ("Skip" ))
368364 btn_skip .get_style_context ().add_class ("btn_skip" )
369365 btn_skip .connect ("clicked" , on_skip )
370366 btn_skip .set_visible (True )
371- box_buttons .append (btn_skip )
367+ self . box_buttons .append (btn_skip )
372368
373369 # Set values
374370 if image_path :
375- img_break .set_from_file (image_path )
376- lbl_message .set_label (message )
377- lbl_widget .set_markup (widget )
371+ self . img_break .set_from_file (image_path )
372+ self . lbl_message .set_label (message )
373+ self . lbl_widget .set_markup (widget )
378374
379375 def set_count_down (self , count ):
380376 self .lbl_count .set_text (count )
@@ -389,6 +385,7 @@ def __tray_action(self, button, tray_action: TrayAction):
389385 tray_action .reset ()
390386 tray_action .action ()
391387
388+ @Gtk .Template .Callback ()
392389 def on_window_delete (self , * args ):
393390 """Window close event handler."""
394391 logging .info ("Closing the break screen" )
0 commit comments