Skip to content

Commit aa50b70

Browse files
committed
gtk template: settings - plugin settings items
1 parent b424091 commit aa50b70

File tree

4 files changed

+34
-25
lines changed

4 files changed

+34
-25
lines changed

safeeyes/glade/item_bool.glade

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
~ You should have received a copy of the GNU General Public License
2020
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
2121
-->
22-
<interface>
22+
<interface domain="safeeyes">
2323
<requires lib="gtk" version="4.0"/>
24-
<object class="GtkBox" id="box">
24+
<template parent="GtkBox" class="BoolItem">
2525
<property name="visible">1</property>
2626
<property name="margin-start">5</property>
2727
<property name="margin-end">5</property>
@@ -46,5 +46,5 @@
4646
<property name="valign">center</property>
4747
</object>
4848
</child>
49-
</object>
49+
</template>
5050
</interface>

safeeyes/glade/item_int.glade

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
~ You should have received a copy of the GNU General Public License
2020
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
2121
-->
22-
<interface>
22+
<interface domain="safeeyes">
2323
<requires lib="gtk" version="4.0"/>
2424
<object class="GtkAdjustment" id="adjustment_value">
2525
<property name="upper">100</property>
2626
<property name="step-increment">1</property>
2727
<property name="page-increment">10</property>
2828
</object>
29-
<object class="GtkBox" id="box">
29+
<template parent="GtkBox" class="IntItem">
3030
<property name="visible">1</property>
3131
<property name="margin-start">5</property>
3232
<property name="margin-end">5</property>
@@ -52,5 +52,5 @@
5252
<property name="adjustment">adjustment_value</property>
5353
</object>
5454
</child>
55-
</object>
55+
</template>
5656
</interface>

safeeyes/glade/item_text.glade

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
~ You should have received a copy of the GNU General Public License
2020
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
2121
-->
22-
<interface>
22+
<interface domain="safeeyes">
2323
<requires lib="gtk" version="4.0"/>
24-
<object class="GtkBox" id="box">
24+
<template parent="GtkBox" class="TextItem">
2525
<property name="visible">1</property>
2626
<property name="margin-start">5</property>
2727
<property name="margin-end">5</property>
@@ -46,5 +46,5 @@
4646
<property name="valign">center</property>
4747
</object>
4848
</child>
49-
</object>
49+
</template>
5050
</interface>

safeeyes/ui/settings_dialog.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -431,44 +431,53 @@ def on_properties_clicked(self, button):
431431
self.on_properties()
432432

433433

434-
class IntItem:
434+
@Gtk.Template(filename=SETTINGS_ITEM_INT_GLADE)
435+
class IntItem(Gtk.Box):
436+
__gtype_name__ = "IntItem"
437+
438+
lbl_name = Gtk.Template.Child()
439+
spin_value = Gtk.Template.Child()
440+
435441
def __init__(self, name, value, min_value, max_value):
436442
super().__init__()
437443

438-
builder = utility.create_gtk_builder(SETTINGS_ITEM_INT_GLADE)
439-
builder.get_object("lbl_name").set_label(_(name))
440-
self.spin_value = builder.get_object("spin_value")
444+
self.lbl_name.set_label(_(name))
441445
self.spin_value.set_range(min_value, max_value)
442446
self.spin_value.set_value(value)
443-
self.box = builder.get_object("box")
444447

445448
def get_value(self):
446449
return self.spin_value.get_value()
447450

448451

449-
class TextItem:
452+
@Gtk.Template(filename=SETTINGS_ITEM_TEXT_GLADE)
453+
class TextItem(Gtk.Box):
454+
__gtype_name__ = "TextItem"
455+
456+
lbl_name = Gtk.Template.Child()
457+
txt_value = Gtk.Template.Child()
458+
450459
def __init__(self, name, value):
451460
super().__init__()
452461

453-
builder = utility.create_gtk_builder(SETTINGS_ITEM_TEXT_GLADE)
454-
builder.get_object("lbl_name").set_label(_(name))
455-
self.txt_value = builder.get_object("txt_value")
462+
self.lbl_name.set_label(_(name))
456463
self.txt_value.set_text(value)
457-
self.box = builder.get_object("box")
458464

459465
def get_value(self):
460466
return self.txt_value.get_text()
461467

462468

463-
class BoolItem:
469+
@Gtk.Template(filename=SETTINGS_ITEM_BOOL_GLADE)
470+
class BoolItem(Gtk.Box):
471+
__gtype_name__ = "BoolItem"
472+
473+
lbl_name = Gtk.Template.Child()
474+
switch_value = Gtk.Template.Child()
475+
464476
def __init__(self, name, value):
465477
super().__init__()
466478

467-
builder = utility.create_gtk_builder(SETTINGS_ITEM_BOOL_GLADE)
468-
builder.get_object("lbl_name").set_label(_(name))
469-
self.switch_value = builder.get_object("switch_value")
479+
self.lbl_name.set_label(_(name))
470480
self.switch_value.set_active(value)
471-
self.box = builder.get_object("box")
472481

473482
def get_value(self):
474483
return self.switch_value.get_active()
@@ -508,7 +517,7 @@ def __init__(self, parent, config):
508517
continue
509518

510519
self.property_controls.append({"key": setting["id"], "box": box})
511-
self.box_settings.append(box.box)
520+
self.box_settings.append(box)
512521

513522
@Gtk.Template.Callback()
514523
def on_window_delete(self, *args):

0 commit comments

Comments
 (0)