5252SETTINGS_ITEM_BOOL_GLADE = os .path .join (utility .BIN_DIRECTORY , "glade/item_bool.glade" )
5353
5454
55- class SettingsDialog :
55+ @Gtk .Template (filename = SETTINGS_DIALOG_GLADE )
56+ class SettingsDialog (Gtk .ApplicationWindow ):
5657 """Create and initialize SettingsDialog instance."""
5758
59+ __gtype_name__ = "SettingsDialog"
60+
61+ box_short_breaks = Gtk .Template .Child ()
62+ box_long_breaks = Gtk .Template .Child ()
63+ box_plugins = Gtk .Template .Child ()
64+ popover = Gtk .Template .Child ()
65+
66+ spin_short_break_duration = Gtk .Template .Child ()
67+ spin_long_break_duration = Gtk .Template .Child ()
68+ spin_short_break_interval = Gtk .Template .Child ()
69+ spin_long_break_interval = Gtk .Template .Child ()
70+ spin_time_to_prepare = Gtk .Template .Child ()
71+ spin_postpone_duration = Gtk .Template .Child ()
72+ dropdown_postpone_unit = Gtk .Template .Child ()
73+ spin_disable_keyboard_shortcut = Gtk .Template .Child ()
74+ switch_strict_break = Gtk .Template .Child ()
75+ switch_random_order = Gtk .Template .Child ()
76+ switch_postpone = Gtk .Template .Child ()
77+ switch_persist = Gtk .Template .Child ()
78+ info_bar_long_break = Gtk .Template .Child ()
79+
5880 def __init__ (self , application , config , on_save_settings ):
59- self .application = application
81+ super ().__init__ (application = application )
82+
6083 self .config = config
6184 self .on_save_settings = on_save_settings
6285 self .plugin_items = {}
@@ -65,53 +88,11 @@ def __init__(self, application, config, on_save_settings):
6588 self .initializing = True
6689 self .infobar_long_break_shown = False
6790
68- builder = utility .create_gtk_builder (SETTINGS_DIALOG_GLADE )
69-
70- self .window = builder .get_object ("window_settings" )
71- self .window .set_application (application )
72- self .box_short_breaks = builder .get_object ("box_short_breaks" )
73- self .box_long_breaks = builder .get_object ("box_long_breaks" )
74- self .box_plugins = builder .get_object ("box_plugins" )
75- self .popover = builder .get_object ("popover" )
76-
77- self .spin_short_break_duration = builder .get_object ("spin_short_break_duration" )
78- self .spin_long_break_duration = builder .get_object ("spin_long_break_duration" )
79- self .spin_short_break_interval = builder .get_object ("spin_short_break_interval" )
80- self .spin_long_break_interval = builder .get_object ("spin_long_break_interval" )
81- self .spin_time_to_prepare = builder .get_object ("spin_time_to_prepare" )
82- self .spin_postpone_duration = builder .get_object ("spin_postpone_duration" )
83- self .dropdown_postpone_unit = builder .get_object ("dropdown_postpone_unit" )
84- self .spin_disable_keyboard_shortcut = builder .get_object (
85- "spin_disable_keyboard_shortcut"
86- )
87- self .switch_strict_break = builder .get_object ("switch_strict_break" )
88- self .switch_random_order = builder .get_object ("switch_random_order" )
89- self .switch_postpone = builder .get_object ("switch_postpone" )
90- self .switch_persist = builder .get_object ("switch_persist" )
91- self .info_bar_long_break = builder .get_object ("info_bar_long_break" )
9291 self .info_bar_long_break .hide ()
9392
94- self .window .connect ("close-request" , self .on_window_delete )
95- builder .get_object ("reset_menu" ).connect ("clicked" , self .on_reset_menu_clicked )
96- self .spin_short_break_interval .connect (
97- "value-changed" , self .on_spin_short_break_interval_change
98- )
99- self .info_bar_long_break .connect ("close" , self .on_info_bar_long_break_close )
100- self .info_bar_long_break .connect ("response" , self .on_info_bar_long_break_close )
101- self .spin_long_break_interval .connect (
102- "value-changed" , self .on_spin_long_break_interval_change
103- )
104- builder .get_object ("btn_add_break" ).connect ("clicked" , self .add_break )
105-
10693 # Set the current values of input fields
10794 self .__initialize (config )
10895
109- # Add event listener to postpone switch
110- self .switch_postpone .connect ("state-set" , self .on_switch_postpone_activate )
111- self .on_switch_postpone_activate (
112- self .switch_postpone , self .switch_postpone .get_active ()
113- )
114-
11596 self .initializing = False
11697
11798 def __initialize (self , config ):
@@ -175,6 +156,7 @@ def __create_break_item(self, break_config, is_short):
175156 gbox .set_visible (True )
176157 parent_box .append (gbox )
177158
159+ @Gtk .Template .Callback ()
178160 def on_reset_menu_clicked (self , button ):
179161 self .popover .hide ()
180162
@@ -201,7 +183,7 @@ def __confirmation_dialog_response(dialog, result) -> None:
201183 messagedialog .set_cancel_button (0 )
202184 messagedialog .set_default_button (0 )
203185
204- messagedialog .choose (self . window , None , __confirmation_dialog_response )
186+ messagedialog .choose (self , None , __confirmation_dialog_response )
205187
206188 def __clear_children (self , widget ):
207189 while widget .get_last_child () is not None :
@@ -228,7 +210,7 @@ def __confirmation_dialog_response(dialog, result):
228210 messagedialog .set_cancel_button (0 )
229211 messagedialog .set_default_button (0 )
230212
231- messagedialog .choose (self . window , None , __confirmation_dialog_response )
213+ messagedialog .choose (self , None , __confirmation_dialog_response )
232214
233215 def __create_plugin_item (self , plugin_config ):
234216 """Create an entry for plugin to be listed in the plugin tab."""
@@ -249,15 +231,15 @@ def __create_plugin_item(self, plugin_config):
249231
250232 def __show_plugins_properties_dialog (self , plugin_config ):
251233 """Show the PluginProperties dialog."""
252- dialog = PluginSettingsDialog (self . window , plugin_config )
234+ dialog = PluginSettingsDialog (self , plugin_config )
253235 dialog .show ()
254236
255237 def __show_break_properties_dialog (
256238 self , break_config , is_short , parent , on_close , on_add , on_remove
257239 ):
258240 """Show the BreakProperties dialog."""
259241 dialog = BreakSettingsDialog (
260- self . window ,
242+ self ,
261243 break_config ,
262244 is_short ,
263245 parent ,
@@ -270,8 +252,9 @@ def __show_break_properties_dialog(
270252
271253 def show (self ):
272254 """Show the SettingsDialog."""
273- self . window . present ()
255+ super (). show ()
274256
257+ @Gtk .Template .Callback ()
275258 def on_switch_postpone_activate (self , switch , state ):
276259 """Event handler to the state change of the postpone switch.
277260
@@ -281,6 +264,7 @@ def on_switch_postpone_activate(self, switch, state):
281264 self .spin_postpone_duration .set_sensitive (self .switch_postpone .get_active ())
282265 self .dropdown_postpone_unit .set_sensitive (self .switch_postpone .get_active ())
283266
267+ @Gtk .Template .Callback ()
284268 def on_spin_short_break_interval_change (self , spin_button , * value ):
285269 """Event handler for value change of short break interval."""
286270 short_break_interval = self .spin_short_break_interval .get_value_as_int ()
@@ -298,27 +282,31 @@ def on_spin_short_break_interval_change(self, spin_button, *value):
298282 self .infobar_long_break_shown = True
299283 self .info_bar_long_break .show ()
300284
285+ @Gtk .Template .Callback ()
301286 def on_spin_long_break_interval_change (self , spin_button , * value ):
302287 """Event handler for value change of long break interval."""
303288 if not self .initializing and not self .infobar_long_break_shown :
304289 self .infobar_long_break_shown = True
305290 self .info_bar_long_break .show ()
306291
292+ @Gtk .Template .Callback ()
307293 def on_info_bar_long_break_close (self , infobar , * user_data ):
308294 """Event handler for info bar close action."""
309295 self .info_bar_long_break .hide ()
310296
297+ @Gtk .Template .Callback ()
311298 def add_break (self , button ) -> None :
312299 """Event handler for add break button."""
313300 dialog = NewBreakDialog (
314- self . window ,
301+ self ,
315302 self .config ,
316303 lambda is_short , break_config : self .__create_break_item (
317304 break_config , is_short
318305 ),
319306 )
320307 dialog .show ()
321308
309+ @Gtk .Template .Callback ()
322310 def on_window_delete (self , * args ):
323311 """Event handler for Settings dialog close action."""
324312 self .config .set (
@@ -356,7 +344,7 @@ def on_window_delete(self, *args):
356344 plugin ["enabled" ] = self .plugin_items [plugin ["id" ]].is_enabled ()
357345
358346 self .on_save_settings (self .config ) # Call the provided save method
359- self .window . destroy ()
347+ self .destroy ()
360348
361349
362350class BreakItem :
0 commit comments