9
9
from efibootmgr import Efibootmgr
10
10
11
11
gi .require_version ('Gtk' , '4.0' )
12
- from gi .repository import Gtk , Gio , GObject
12
+ from gi .repository import Gtk , Gio , GObject , GLib
13
13
14
14
15
15
def btn_with_icon (icon ):
@@ -267,14 +267,20 @@ def sort_by_boot_order(self, row1: EfibootRowModel, row2: EfibootRowModel) -> in
267
267
row2_index = self .boot_order .index (row2 .num )
268
268
return row1_index - row2_index
269
269
270
- def change_boot_next (self , widget , checked_row : EfibootRowModel ):
271
- checked_row .next = not checked_row .next
272
- self .boot_next = checked_row .num if checked_row .next else None
273
-
274
- def change_active (self , widget : Gtk .CheckButton , checked_row : EfibootRowModel ):
275
- checked_row .active = widget .get_active ()
276
- num = checked_row .num
277
- if checked_row .active :
270
+ def change_boot_next (self , action : Gio .SimpleAction , num_variant : GLib .Variant ):
271
+ num = num_variant .get_string ()
272
+ if self .boot_next == num :
273
+ action .set_state (GLib .Variant .new_string ("" ))
274
+ self .boot_next = None
275
+ else :
276
+ action .set_state (num_variant )
277
+ self .boot_next = num
278
+ logging .debug ("%s changed to %s" , action .get_name (), action .get_state ())
279
+
280
+ def change_active (self , widget : Gtk .Switch , state : bool , row : EfibootRowModel ):
281
+ row .active = state
282
+ num = row .num
283
+ if row .active :
278
284
if num in self .boot_inactive :
279
285
self .boot_inactive .remove (num )
280
286
else :
@@ -285,7 +291,7 @@ def change_active(self, widget: Gtk.CheckButton, checked_row: EfibootRowModel):
285
291
else :
286
292
self .boot_inactive .add (num )
287
293
288
- logging .debug (checked_row , self .boot_active , self .boot_inactive )
294
+ logging .debug ("%s %s %s" , row , self .boot_active , self .boot_inactive )
289
295
290
296
def add (self , label , path , parameters ):
291
297
new_num = "NEW{:d}" .format (len (self .boot_add ))
@@ -342,6 +348,8 @@ class EfibootsMainWindow(Gtk.ApplicationWindow):
342
348
__gtype_name__ = "EfibootsMainWindow"
343
349
344
350
column_view : Gtk .ColumnView = Gtk .Template .Child ()
351
+ column_next : Gtk .ColumnViewColumn = Gtk .Template .Child ()
352
+ column_active : Gtk .ColumnViewColumn = Gtk .Template .Child ()
345
353
346
354
up : Gtk .Button = Gtk .Template .Child ()
347
355
down : Gtk .Button = Gtk .Template .Child ()
@@ -359,8 +367,71 @@ def __init__(self, app):
359
367
self .column_view .set_model (self .selection_model )
360
368
self .timeout_spin .set_adjustment (Gtk .Adjustment (lower = 0 , step_increment = 1 , upper = 999 ))
361
369
370
+ def on_setup_active (_ : Gtk .ListItemFactory , item : Gtk .ListItem ):
371
+ switch = Gtk .Switch ()
372
+ item .set_child (switch )
373
+
374
+ def on_bind_active (_ : Gtk .ListItemFactory , item : Gtk .ListItem ):
375
+ row : EfibootRowModel = item .get_item ()
376
+ switch : Gtk .Switch = item .get_child ()
377
+ switch .set_active (row .active )
378
+ switch ._binding = switch .connect ("state-set" , self .model .change_active , row )
379
+
380
+ def on_unbind_active (_ : Gtk .ListItemFactory , item : Gtk .ListItem ):
381
+ switch : Gtk .Switch = item .get_child ()
382
+ if switch ._binding :
383
+ switch .disconnect (switch ._binding )
384
+ switch ._binding = None
385
+
386
+ def on_teardown_active (_ : Gtk .ListItemFactory , item : Gtk .ListItem ):
387
+ switch : Gtk .Switch = item .get_child ()
388
+ switch ._binding = None
389
+
390
+ factory_active = Gtk .SignalListItemFactory .new ()
391
+ factory_active .connect ("setup" , on_setup_active )
392
+ factory_active .connect ("bind" , on_bind_active )
393
+ factory_active .connect ("unbind" , on_unbind_active )
394
+ factory_active .connect ("teardown" , on_teardown_active )
395
+ self .column_active .set_factory (factory_active )
396
+
397
+ var = GLib .Variant .new_string ("" )
398
+ action_next = Gio .SimpleAction .new_stateful ("next_boot" , var .get_type (), var )
399
+ action_next .connect ("change-state" , self .model .change_boot_next )
400
+ self .add_action (action_next )
401
+
402
+ def on_setup_next_boot (_ : Gtk .ListItemFactory , item : Gtk .ListItem ):
403
+ num_variant = GLib .Variant .new_string ("0000" ) # set to something not None
404
+ checkbutton = Gtk .CheckButton (action_name = "win.next_boot" , action_target = num_variant )
405
+ item .set_child (checkbutton )
406
+
407
+ def on_bind_next_boot (_ : Gtk .ListItemFactory , item : Gtk .ListItem ):
408
+ row : EfibootRowModel = item .get_item ()
409
+ checkbutton : Gtk .CheckButton = item .get_child ()
410
+ checkbutton ._binding = checkbutton .bind_property ("active" , row , "next" , GObject .BindingFlags .BIDIRECTIONAL )
411
+ checkbutton .set_action_target_value (GLib .Variant .new_string (row .num ))
412
+
413
+ def on_unbind_next_boot (_ : Gtk .ListItemFactory , item : Gtk .ListItem ):
414
+ checkbutton : Gtk .CheckButton = item .get_child ()
415
+ if checkbutton ._binding :
416
+ checkbutton ._binding .unbind ()
417
+ checkbutton ._binding = None
418
+
419
+ def on_teardown_next_boot (_ : Gtk .ListItemFactory , item : Gtk .ListItem ):
420
+ checkbutton : Gtk .CheckButton = item .get_child ()
421
+ checkbutton ._binding = None
422
+
423
+ factory = Gtk .SignalListItemFactory .new ()
424
+ factory .connect ("setup" , on_setup_next_boot )
425
+ factory .connect ("bind" , on_bind_next_boot )
426
+ factory .connect ("unbind" , on_unbind_next_boot )
427
+ factory .connect ("teardown" , on_teardown_next_boot )
428
+ self .column_next .set_factory (factory )
429
+
362
430
self .add_css_class ("devel" )
363
431
432
+ def next_boot_handler (self , action : Gio .SimpleAction , state : str ):
433
+ self .model .boot_next = state
434
+
364
435
def query_system (self , disk , part ):
365
436
if not (disk and part ):
366
437
disk , part = auto_detect_esp ()
0 commit comments