[chirp_devel] [PATCH 0 of 3] Settings arrays and UV5R ANI code
When I wrote the RadioSettings stuff, I planned for values to be able to be arrays. A RadioSetting can be composed of one or more RadioSettingValue objects, but there was no example setting with which to demonstrate this situation. The UV5R ANI code actually fits this rather nicely, in that it is actually an array of integers.
This patch fixes a few bugs in the array support, makes the UI properly handle array values by arranging the value widgets in a horizontal row, and makes the UV5R driver expose the ANI code as an array value.
# HG changeset patch # User Dan Smith dsmith@danplanet.com # Date 1338939366 25200 # Node ID c3a4540e9591f1338dc166229fa6183b2fe36a22 # Parent d3f6a4f8fd33c34e3ddb608c8094ed324a467880 Finish making RadioSetting work as an array of values In support of #188
diff -r d3f6a4f8fd33 -r c3a4540e9591 chirp/settings.py --- a/chirp/settings.py Mon Jun 04 07:15:31 2012 -0600 +++ b/chirp/settings.py Tue Jun 05 16:36:06 2012 -0700 @@ -255,8 +255,7 @@ if len(self) == 1: return self._elements[self._element_order[0]] else: - print self._elements - raise InternalError("Setting %s is not a scalar" % self._name) + return self._elements.values() else: return self.__dict__[name]
@@ -279,7 +278,7 @@ def __getitem__(self, name): if not isinstance(name, int): raise IndexError("Index `%s' is not an integer" % name) - return self._elements[name].get_value() + return self._elements[name]
def __setitem__(self, name, value): if not isinstance(name, int):
# HG changeset patch # User Dan Smith dsmith@danplanet.com # Date 1338939375 25200 # Node ID dc35edce4a5c5fd16989a29d4810df0c2d3e71d3 # Parent c3a4540e9591f1338dc166229fa6183b2fe36a22 Make the settings editor UI properly handle array values In support of #188
diff -r c3a4540e9591 -r dc35edce4a5c chirpui/settingsedit.py --- a/chirpui/settingsedit.py Tue Jun 05 16:36:06 2012 -0700 +++ b/chirpui/settingsedit.py Tue Jun 05 16:36:15 2012 -0700 @@ -62,37 +62,37 @@ job.set_desc("Setting radio settings") self._rthread.submit(job)
- def _load_setting(self, element, widget): - if isinstance(element.value, settings.RadioSettingValueInteger): + def _load_setting(self, value, widget): + if isinstance(value, settings.RadioSettingValueInteger): adj = widget.get_adjustment() - adj.configure(element.value.get_value(), - element.value.get_min(), element.value.get_max(), - element.value.get_step(), 1, 0) - elif isinstance(element.value, settings.RadioSettingValueBoolean): - widget.set_active(element.value.get_value()) - elif isinstance(element.value, settings.RadioSettingValueList): + 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 element.value.get_options(): + for option in value.get_options(): widget.append_text(option) - current = element.value.get_value() - index = element.value.get_options().index(current) + current = value.get_value() + index = value.get_options().index(current) widget.set_active(index) - elif isinstance(element.value, settings.RadioSettingValueString): - widget.set_text(str(element.value)) + elif isinstance(value, settings.RadioSettingValueString): + widget.set_text(str(value)) else: print "Unsupported widget type %s for %s" % (value.__class__, element.get_name())
- def _save_setting(self, widget, element): - if isinstance(element.value, settings.RadioSettingValueInteger): - element.value.set_value(widget.get_adjustment().get_value()) - elif isinstance(element.value, settings.RadioSettingValueBoolean): - element.value.set_value(widget.get_active()) - elif isinstance(element.value, settings.RadioSettingValueList): - element.value.set_value(widget.get_active_text()) - elif isinstance(element.value, settings.RadioSettingValueString): - element.value.set_value(widget.get_text()) + def _save_setting(self, widget, 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" % (\ element.value.__class__, @@ -118,26 +118,40 @@ label.show() pack(label, 0)
- if isinstance(element.value, settings.RadioSettingValueInteger): - widget = gtk.SpinButton() - signal = "value-changed" - elif isinstance(element.value, settings.RadioSettingValueBoolean): - widget = gtk.CheckButton(_("Enabled")) - signal = "toggled" - elif isinstance(element.value, settings.RadioSettingValueList): - widget = miscwidgets.make_choice([], editable=False) - signal = "changed" - elif isinstance(element.value, settings.RadioSettingValueString): - widget = gtk.Entry() - signal = "changed" - else: - print "Unsupported widget type: %s" % value.__class__ + hbox = gtk.HBox(3, True) + pack(hbox, 1) + hbox.show()
- self._load_setting(element, widget) - widget.connect(signal, self._save_setting, element) + widgets = [] + for index in element.keys(): + value = element[index] + if isinstance(value, settings.RadioSettingValueInteger): + widget = gtk.SpinButton() + print "Digits: %i" % widget.get_digits() + signal = "value-changed" + elif isinstance(value, settings.RadioSettingValueBoolean): + widget = gtk.CheckButton(_("Enabled")) + signal = "toggled" + elif isinstance(value, settings.RadioSettingValueList): + widget = miscwidgets.make_choice([], editable=False) + signal = "changed" + elif isinstance(value, settings.RadioSettingValueString): + widget = gtk.Entry() + signal = "changed" + else: + print "Unsupported widget type: %s" % value.__class__
- widget.show() - pack(widget, 1) + # Make sure the widget gets left-aligned to match up + # with its label + lalign = gtk.Alignment(0, 0, 0, 0) + lalign.add(widget) + lalign.show() + + hbox.pack_start(lalign, 1, 1, 1) + widget.show() + self._load_setting(value, widget) + widget.connect(signal, self._save_setting, value) + self._index += 1
def _build_tree(self, group, parent):
# HG changeset patch # User Dan Smith dsmith@danplanet.com # Date 1338939395 25200 # Node ID aeba22a01cfd02549f365be764cc61b1a988197e # Parent dc35edce4a5c5fd16989a29d4810df0c2d3e71d3 [uv5r] Expose ANI code as an array of integer settings Fixes #188
diff -r dc35edce4a5c -r aeba22a01cfd chirp/uv5r.py --- a/chirp/uv5r.py Tue Jun 05 16:36:15 2012 -0700 +++ b/chirp/uv5r.py Tue Jun 05 16:36:35 2012 -0700 @@ -38,6 +38,9 @@ unknown5:2; } memory[128];
+#seekto 0x0CB2; +u8 ani[5]; + #seekto 0x0E28; struct { u8 squelch; @@ -468,6 +471,15 @@ COLOR_LIST[_settings.txled])) basic.append(rs)
+ _ani = self._memobj.ani + rs = RadioSetting("_ani", "ANI Code", + RadioSettingValueInteger(0, 9, _ani[0]), + RadioSettingValueInteger(0, 9, _ani[1]), + RadioSettingValueInteger(0, 9, _ani[2]), + RadioSettingValueInteger(0, 9, _ani[3]), + RadioSettingValueInteger(0, 9, _ani[4])) + advanced.append(rs) + return group
def set_settings(self, settings): @@ -477,7 +489,12 @@ self.set_settings(element) continue try: - setattr(_settings, element.get_name(), element.value) + # Elements that start with "_" should be applied to the + # top-level memobj, otherwise to memobj.settings + if element.get_name().startswith("_"): + setattr(self._memobj, element.get_name()[1:], element.value) + else: + setattr(_settings, element.get_name(), element.value) except Exception, e: print element.get_name() raise
participants (1)
-
Dan Smith