[chirp_devel] [PATCH] Add support for settingvalue objects to be immutable

Dan Smith
Sat May 4 14:02:31 PDT 2013


# HG changeset patch
# User Dan Smith <dsmith at danplanet.com>
# Date 1367701349 25200
# Node ID e924129f98b9d6b65ca12ca52d57ece8d2a95c12
# Parent  28d01422eb4585d7f3e35ca98afdd01675783fa1
Add support for settingvalue objects to be immutable

Use like this:

val = RadioSettingValueString(0, 7, _filter(_msg.line1))
val.set_mutable(False)
rs = RadioSetting("sixpoweron_msg.line1", "6+Power-On Message 1", val)

diff -r 28d01422eb45 -r e924129f98b9 chirp/settings.py
--- a/chirp/settings.py	Sat May 04 12:12:18 2013 -0400
+++ b/chirp/settings.py	Sat May 04 14:02:29 2013 -0700
@@ -29,6 +29,13 @@
         self._current = None
         self._has_changed = False
         self._validate_callback = lambda x: x
+        self._mutable = True
+
+    def set_mutable(self, mutable):
+        self._mutable = mutable
+
+    def get_mutable(self):
+        return self._mutable
 
     def changed(self):
         """Returns True if the setting has been changed since init"""
@@ -39,6 +46,9 @@
 
     def set_value(self, value):
         """Sets the current value, triggers changed"""
+        if not self.get_mutable():
+            raise InvalidValueError("This value is not mutable")
+
         if self._current != None and value != self._current:
             self._has_changed = True
         self._current = self._validate_callback(value)
diff -r 28d01422eb45 -r e924129f98b9 chirpui/settingsedit.py
--- a/chirpui/settingsedit.py	Sat May 04 12:12:18 2013 -0400
+++ b/chirpui/settingsedit.py	Sat May 04 14:02:29 2013 -0700
@@ -178,6 +178,8 @@
                 lalign.add(widget)
                 lalign.show()
 
+                widget.set_sensitive(value.get_mutable())
+
                 arraybox.pack_start(lalign, 1, 1, 1)
                 widget.show()
                 self._load_setting(value, widget)



More information about the chirp_devel mailing list