Skip to content

Commit 85ab055

Browse files
committedJun 24, 2023
New implementation for next boot and activate
1 parent 217fab7 commit 85ab055

File tree

3 files changed

+82
-61
lines changed

3 files changed

+82
-61
lines changed
 

‎efibootmgr.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def parse_line(line: str) -> tuple[str, object]:
157157
num, active, name, path, params = match.groups()
158158
parsed_entry = ParsedEfibootmgrEntry(num=num, active=active is not None, name=name,
159159
path=path if path else '', parameters=params)
160-
parser_logger.debug("Entry: %s", parsed_entry)
160+
parser_logger.debug("%s", parsed_entry)
161161
return 'entry', parsed_entry
162162
if line.startswith("BootOrder"):
163163
parsed = line.split(':')[1].strip().split(',')

‎efiboots.py

+81-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from efibootmgr import Efibootmgr
1010

1111
gi.require_version('Gtk', '4.0')
12-
from gi.repository import Gtk, Gio, GObject
12+
from gi.repository import Gtk, Gio, GObject, GLib
1313

1414

1515
def btn_with_icon(icon):
@@ -267,14 +267,20 @@ def sort_by_boot_order(self, row1: EfibootRowModel, row2: EfibootRowModel) -> in
267267
row2_index = self.boot_order.index(row2.num)
268268
return row1_index - row2_index
269269

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:
278284
if num in self.boot_inactive:
279285
self.boot_inactive.remove(num)
280286
else:
@@ -285,7 +291,7 @@ def change_active(self, widget: Gtk.CheckButton, checked_row: EfibootRowModel):
285291
else:
286292
self.boot_inactive.add(num)
287293

288-
logging.debug(checked_row, self.boot_active, self.boot_inactive)
294+
logging.debug("%s %s %s", row, self.boot_active, self.boot_inactive)
289295

290296
def add(self, label, path, parameters):
291297
new_num = "NEW{:d}".format(len(self.boot_add))
@@ -342,6 +348,8 @@ class EfibootsMainWindow(Gtk.ApplicationWindow):
342348
__gtype_name__ = "EfibootsMainWindow"
343349

344350
column_view: Gtk.ColumnView = Gtk.Template.Child()
351+
column_next: Gtk.ColumnViewColumn = Gtk.Template.Child()
352+
column_active: Gtk.ColumnViewColumn = Gtk.Template.Child()
345353

346354
up: Gtk.Button = Gtk.Template.Child()
347355
down: Gtk.Button = Gtk.Template.Child()
@@ -359,8 +367,71 @@ def __init__(self, app):
359367
self.column_view.set_model(self.selection_model)
360368
self.timeout_spin.set_adjustment(Gtk.Adjustment(lower=0, step_increment=1, upper=999))
361369

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+
362430
self.add_css_class("devel")
363431

432+
def next_boot_handler(self, action: Gio.SimpleAction, state: str):
433+
self.model.boot_next = state
434+
364435
def query_system(self, disk, part):
365436
if not (disk and part):
366437
disk, part = auto_detect_esp()

‎ui/main.ui

-50
Original file line numberDiff line numberDiff line change
@@ -171,57 +171,12 @@
171171
<object class="GtkColumnViewColumn" id="column_active">
172172
<property name="resizable">True</property>
173173
<property name="title">Active</property>
174-
<property name="factory">
175-
<object class="GtkBuilderListItemFactory">
176-
<property name="bytes">
177-
<![CDATA[
178-
<?xml version="1.0" encoding="UTF-8"?>
179-
<interface>
180-
<template class="GtkListItem">
181-
<property name="child">
182-
<object class="GtkSwitch">
183-
<property name="sensitive">False</property>
184-
<binding name="active">
185-
<lookup name="active" type="EfibootRowModel">
186-
<lookup name="item">GtkListItem</lookup>
187-
</lookup>
188-
</binding>
189-
</object>
190-
</property>
191-
</template>
192-
</interface>
193-
]]>
194-
</property>
195-
</object>
196-
</property>
197174
</object>
198175
</child>
199176
<child>
200177
<object class="GtkColumnViewColumn" id="column_next">
201178
<property name="resizable">True</property>
202179
<property name="title">Boot Next</property>
203-
<property name="factory">
204-
<object class="GtkBuilderListItemFactory">
205-
<property name="bytes">
206-
<![CDATA[
207-
<?xml version="1.0" encoding="UTF-8"?>
208-
<interface>
209-
<template class="GtkListItem">
210-
<property name="child">
211-
<object class="GtkCheckButton">
212-
<binding name="active">
213-
<lookup name="next" type="EfibootRowModel">
214-
<lookup name="item">GtkListItem</lookup>
215-
</lookup>
216-
</binding>
217-
</object>
218-
</property>
219-
</template>
220-
</interface>
221-
]]>
222-
</property>
223-
</object>
224-
</property>
225180
</object>
226181
</child>
227182
</object>
@@ -285,11 +240,6 @@
285240
</child>
286241
</object>
287242
</child>
288-
<child>
289-
<object class="GtkLabel">
290-
<property name="label">WARNING: The active and boot next columns are a work in progress and are currently not usable. GTK is hard!</property>
291-
</object>
292-
</child>
293243
</object>
294244
</child>
295245
<child type="titlebar">

0 commit comments

Comments
 (0)
Please sign in to comment.