44from gi .repository import GtkSource
55
66from meld .conf import _
7- from meld .ui .listselector import FilteredListSelector , with_template_file
7+ from meld .ui ._gtktemplate import Template
8+ from meld .ui .listselector import FilteredListSelector
89
10+ # TODO: Current pygobject support for templates excludes subclassing of
11+ # templated classes, which is why we have two near-identical UI files
12+ # here, and why we can't subclass Gtk.Grid directly in
13+ # FilteredListSelector.
914
10- @with_template_file ('encoding-selector.ui' )
15+ # The subclassing here is weird; the Selector must directly subclass
16+ # Gtk.Grid; we can't do this on the FilteredListSelector. Likewise, the
17+ # Template.Child attributes must be per-class, because of how they're
18+ # registered by the templating engine.
19+
20+
21+ @Template (resource_path = '/org/gnome/meld/ui/encoding-selector.ui' )
1122class EncodingSelector (FilteredListSelector , Gtk .Grid ):
1223 # The subclassing here is weird; the Selector must directly
1324 # subclass Gtk.Grid, or the template building explodes.
@@ -24,6 +35,9 @@ class EncodingSelector(FilteredListSelector, Gtk.Grid):
2435 value_accessor = 'get_charset'
2536 change_signal_name = 'encoding-selected'
2637
38+ entry = Template .Child ('entry' )
39+ treeview = Template .Child ('treeview' )
40+
2741 def populate_model (self ):
2842 for enc in GtkSource .Encoding .get_all ():
2943 self .liststore .append ((self .get_value_label (enc ), enc ))
@@ -40,14 +54,8 @@ def get_value_label(self, enc):
4054# Copyright (C) 2015, 2017 Kai Willadsen <kai.willadsen@gmail.com>
4155
4256
43- # TODO: When there's proper pygobject support for widget templates,
44- # make both selectors here use a generic UI file. We can't do this
45- # currently due to subclassing issues.
46-
47- @with_template_file ('language-selector.ui' )
57+ @Template (resource_path = '/org/gnome/meld/ui/language-selector.ui' )
4858class SourceLangSelector (FilteredListSelector , Gtk .Grid ):
49- # The subclassing here is weird; the Selector must directly
50- # subclass Gtk.Grid, or the template building explodes.
5159
5260 __gtype_name__ = "SourceLangSelector"
5361
@@ -61,6 +69,9 @@ class SourceLangSelector(FilteredListSelector, Gtk.Grid):
6169 value_accessor = 'get_id'
6270 change_signal_name = 'language-selected'
6371
72+ entry = Template .Child ('entry' )
73+ treeview = Template .Child ('treeview' )
74+
6475 def populate_model (self ):
6576 self .liststore .append ((_ ("Plain Text" ), None ))
6677 manager = GtkSource .LanguageManager .get_default ()
0 commit comments