[chirp_devel] [PATCH 3 of 3] Settings UI

Dan Smith
Fri Apr 6 12:12:51 PDT 2012


# HG changeset patch
# User Dan Smith <dsmith at danplanet.com>
# Date 1333739557 25200
# Node ID 8fc20ff7fa28b3e563185fb18396c6d15977cbec
# Parent  0dd1b82210090092fd77336db3f65f406c4c5b0e
Settings UI
#00

diff -r 0dd1b8221009 -r 8fc20ff7fa28 chirpui/editorset.py
--- a/chirpui/editorset.py	Fri Apr 06 12:12:37 2012 -0700
+++ b/chirpui/editorset.py	Fri Apr 06 12:12:37 2012 -0700
@@ -19,7 +19,7 @@
 
 from chirp import chirp_common, directory, generic_csv, xml
 from chirpui import memedit, dstaredit, bankedit, common, importdialog
-from chirpui import inputdialog, reporting
+from chirpui import inputdialog, reporting, settingsedit
 
 class EditorSet(gtk.VBox):
     __gsignals__ = {
@@ -64,6 +64,7 @@
             "dstar"        : None,
             "bank_names"   : None,
             "bank_members" : None,
+            "settings"     : None,
             }
 
         if isinstance(self.radio, chirp_common.IcomDstarSupport):
@@ -106,6 +107,11 @@
             self.editors["bank_members"].root.show()
             self.editors["bank_members"].connect("changed", self.banks_changed)
 
+        self.editors["settings"] = settingsedit.SettingsEditor(self.rthread)
+        lab = gtk.Label(_("Settings"))
+        self.tabs.append_page(self.editors["settings"].root, lab)
+        self.editors["settings"].root.show()
+
         self.pack_start(self.tabs)
         self.tabs.show()
 
diff -r 0dd1b8221009 -r 8fc20ff7fa28 chirpui/settingsedit.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/chirpui/settingsedit.py	Fri Apr 06 12:12:37 2012 -0700
@@ -0,0 +1,131 @@
+# Copyright 2012 Dan Smith <dsmith at danplanet.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import gtk
+import gobject
+
+from chirp import chirp_common, settings
+from chirpui import common, miscwidgets
+
+class RadioSettingProxy(settings.RadioSetting):
+    def __init__(self, setting, editor):
+        self._setting = setting
+        self._editor = editor
+
+class SettingsEditor(common.Editor):
+    def __init__(self, rthread):
+        common.Editor.__init__(self)
+        self._rthread = rthread
+
+        self.root = gtk.Table(20, 3)
+        self.root.set_col_spacings(10)
+        self._index = 0
+
+        self._top_setting_group = None
+
+        job = common.RadioJob(self._build_ui, "get_settings")
+        job.set_desc("Getting radio settings")
+        self._rthread.submit(job)
+
+    def _save_settings(self):
+        if self._top_setting_group is None:
+            return
+
+        job = common.RadioJob(None, "set_settings", self._top_setting_group)
+        job.set_desc("Setting radio settings")
+        self._rthread.submit(job)
+
+    def _load_setting(self, element, widget):
+        value = element.get_value()
+        if isinstance(value, settings.RadioSettingValueInteger):
+            adj = widget.get_adjustment()
+            adj.configure(value.get_value(),
+                          value.get_min(), value.get_max(),
+                          value.get_step(), 1, 0)
+        elif isinstance(value, settings.RadioSettingValueBoolean):
+            widget.set_active(value.get_value())
+        elif isinstance(value, settings.RadioSettingValueList):
+            model = widget.get_model()
+            model.clear()
+            for option in value.get_options():
+                widget.append_text(option)
+            widget.set_active(value.get_options().index(value.get_value()))
+        elif isinstance(value, settings.RadioSettingValueString):
+            widget.set_text(value.get_value())
+        else:
+            print "Unsupported widget type %s for %s" % (value.__class__,
+                                                         element.get_name())
+            
+    def _save_setting(self, widget, element):
+        value = element.get_value()
+        if isinstance(value, settings.RadioSettingValueInteger):
+            value.set_value(widget.get_adjustment().get_value())
+        elif isinstance(value, settings.RadioSettingValueBoolean):
+            value.set_value(widget.get_active())
+        elif isinstance(value, settings.RadioSettingValueList):
+            value.set_value(widget.get_active_text())
+        elif isinstance(value, settings.RadioSettingValueString):
+            value.set_value(widget.get_text())
+        else:
+            print "Unsupported widget type %s for %s" % (value.__class__,
+                                                         element.get_name())
+
+        self._save_settings()
+
+    def _build_ui_real(self, group):
+        if not isinstance(group, settings.RadioSettingGroup):
+            print "Toplevel is not a group"
+            return
+
+        self._top_setting_group = group
+
+        def pack(widget, pos):
+            self.root.attach(widget, pos, pos+1, self._index, self._index+1,
+                             xoptions=gtk.FILL, yoptions=0)
+
+        for element in group.get_elements():
+            label = gtk.Label(element.get_shortname())
+            label.set_alignment(1.0, 0.5)
+            label.show()
+            pack(label, 0)
+
+            value = element.get_value()
+            if isinstance(value, settings.RadioSettingValueInteger):
+                widget = gtk.SpinButton()
+                widget.connect("value-changed",
+                               self._save_setting, element)
+            elif isinstance(value, settings.RadioSettingValueBoolean):
+                widget = gtk.CheckButton(_("Enabled"))
+                widget.connect("toggled",
+                               self._save_setting, element)
+            elif isinstance(value, settings.RadioSettingValueList):
+                widget = miscwidgets.make_choice([], editable=False)
+                widget.connect("changed",
+                               self._save_setting, element)
+            elif isinstance(value, settings.RadioSettingValueString):
+                widget = gtk.Entry()
+                widget.connect("changed",
+                               self._save_setting, element)
+            else:
+                print "Unsupported widget type: %s" % value.__class__
+
+            self._load_setting(element, widget)
+
+            widget.show()
+            pack(widget, 1)
+            self._index += 1
+
+    def _build_ui(self, group):
+        gobject.idle_add(self._build_ui_real, group)



More information about the chirp_devel mailing list