[meld/deprecation-cleanup: 48/48] preferences: Move to template and resource loading



commit a5c117ecd87548e9232208e796d23dda1dc073a6
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Dec 2 12:38:37 2018 +1000

    preferences: Move to template and resource loading

 meld/meldapp.py                            |  6 ++--
 meld/preferences.py                        | 53 ++++++++++++++++++++++--------
 {data => meld/resources}/ui/preferences.ui |  6 ++--
 3 files changed, 47 insertions(+), 18 deletions(-)
---
diff --git a/meld/meldapp.py b/meld/meldapp.py
index 451615f0..2b5cfad0 100644
--- a/meld/meldapp.py
+++ b/meld/meldapp.py
@@ -25,10 +25,10 @@ from gi.repository import GLib
 from gi.repository import Gtk
 
 import meld.conf
-import meld.preferences
 from meld.conf import _
 from meld.filediff import FileDiff
 from meld.meldwindow import MeldWindow
+from meld.preferences import PreferencesDialog
 
 log = logging.getLogger(__name__)
 
@@ -98,7 +98,9 @@ class MeldApp(Gtk.Application):
     #     return False
 
     def preferences_callback(self, action, parameter):
-        meld.preferences.PreferencesDialog(self.get_active_window())
+        parent = self.get_active_window()
+        dialog = PreferencesDialog(transient_for=parent)
+        dialog.present()
 
     def help_callback(self, action, parameter):
         if meld.conf.DATADIR_IS_UNINSTALLED:
diff --git a/meld/preferences.py b/meld/preferences.py
index d0f0dc4a..5c3d7214 100644
--- a/meld/preferences.py
+++ b/meld/preferences.py
@@ -24,7 +24,6 @@ from meld.conf import _
 from meld.filters import FilterEntry
 from meld.settings import settings
 from meld.ui._gtktemplate import Template
-from meld.ui.gnomeglade import Component
 from meld.ui.listwidget import EditableListWidget
 
 
@@ -255,17 +254,42 @@ class GSettingsStringComboBox(GSettingsComboBox):
     gsettings_value = GObject.Property(type=str, default="")
 
 
-class PreferencesDialog(Component):
+@Template(resource_path='/org/gnome/meld/ui/preferences.ui')
+class PreferencesDialog(Gtk.Dialog):
+
+    __gtype_name__ = "PreferencesDialog"
+
+    checkbutton_break_commit_lines = Template.Child("checkbutton_break_commit_lines")  # noqa: E501
+    checkbutton_default_font = Template.Child("checkbutton_default_font")
+    checkbutton_folder_filter_text = Template.Child("checkbutton_folder_filter_text")  # noqa: E501
+    checkbutton_highlight_current_line = Template.Child("checkbutton_highlight_current_line")  # noqa: E501
+    checkbutton_ignore_blank_lines = Template.Child("checkbutton_ignore_blank_lines")  # noqa: E501
+    checkbutton_ignore_symlinks = Template.Child("checkbutton_ignore_symlinks")
+    checkbutton_shallow_compare = Template.Child("checkbutton_shallow_compare")
+    checkbutton_show_commit_margin = Template.Child("checkbutton_show_commit_margin")  # noqa: E501
+    checkbutton_show_line_numbers = Template.Child("checkbutton_show_line_numbers")  # noqa: E501
+    checkbutton_show_whitespace = Template.Child("checkbutton_show_whitespace")
+    checkbutton_spaces_instead_of_tabs = Template.Child("checkbutton_spaces_instead_of_tabs")  # noqa: E501
+    checkbutton_use_syntax_highlighting = Template.Child("checkbutton_use_syntax_highlighting")  # noqa: E501
+    checkbutton_wrap_text = Template.Child("checkbutton_wrap_text")
+    checkbutton_wrap_word = Template.Child("checkbutton_wrap_word")
+    column_list_vbox = Template.Child("column_list_vbox")
+    combo_file_order = Template.Child("combo_file_order")
+    combo_merge_order = Template.Child("combo_merge_order")
+    combo_timestamp = Template.Child("combo_timestamp")
+    combobox_style_scheme = Template.Child("combobox_style_scheme")
+    custom_edit_command_entry = Template.Child("custom_edit_command_entry")
+    file_filters_vbox = Template.Child("file_filters_vbox")
+    fontpicker = Template.Child("fontpicker")
+    spinbutton_commit_margin = Template.Child("spinbutton_commit_margin")
+    spinbutton_tabsize = Template.Child("spinbutton_tabsize")
+    syntaxschemestore = Template.Child("syntaxschemestore")
+    system_editor_checkbutton = Template.Child("system_editor_checkbutton")
+    text_filters_vbox = Template.Child("text_filters_vbox")
 
-    def __init__(self, parent):
-        super().__init__(
-            "preferences.ui", "preferencesdialog", [
-                "adjustment1", "adjustment2", "fileorderstore",
-                "sizegroup_editor", "timestampstore", "mergeorderstore",
-                "sizegroup_file_order_labels", "sizegroup_file_order_combos",
-                "syntaxschemestore"
-            ])
-        self.widget.set_transient_for(parent)
+    def __init__(self, **kwargs):
+        super().__init__(**kwargs)
+        self.init_template()
 
         bindings = [
             ('use-system-font', self.checkbutton_default_font, 'active'),
@@ -340,8 +364,9 @@ class PreferencesDialog(Component):
             self.syntaxschemestore.append([scheme_id, scheme.get_name()])
         self.combobox_style_scheme.bind_to('style-scheme')
 
-        self.widget.show()
+        self.show()
 
+    @Template.Callback()
     def on_checkbutton_wrap_text_toggled(self, button):
         if not self.checkbutton_wrap_text.get_active():
             wrap_mode = Gtk.WrapMode.NONE
@@ -351,9 +376,11 @@ class PreferencesDialog(Component):
             wrap_mode = Gtk.WrapMode.CHAR
         settings.set_enum('wrap-mode', wrap_mode)
 
+    @Template.Callback()
     def on_checkbutton_show_whitespace_toggled(self, widget):
         value = GtkSource.DrawSpacesFlags.ALL if widget.get_active() else 0
         settings.set_flags('draw-spaces', value)
 
+    @Template.Callback()
     def on_response(self, dialog, response_id):
-        self.widget.destroy()
+        self.destroy()
diff --git a/data/ui/preferences.ui b/meld/resources/ui/preferences.ui
similarity index 99%
rename from data/ui/preferences.ui
rename to meld/resources/ui/preferences.ui
index 5d2d1ffe..9f352efe 100644
--- a/data/ui/preferences.ui
+++ b/meld/resources/ui/preferences.ui
@@ -16,10 +16,10 @@
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
-  <object class="GtkDialog" id="preferencesdialog">
+  <template class="PreferencesDialog" parent="GtkDialog">
     <property name="can_focus">False</property>
     <property name="border_width">0</property>
-    <property name="title" translatable="yes">Meld Preferences</property>
+    <property name="title" translatable="yes">Preferences</property>
     <property name="resizable">False</property>
     <property name="modal">True</property>
     <property name="type_hint">dialog</property>
@@ -1514,7 +1514,7 @@
         </child>
       </object>
     </child>
-  </object>
+  </template>
   <object class="GtkSizeGroup" id="sizegroup_editor">
     <widgets>
       <widget name="label_fontpicker"/>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]