[chirp_devel] [PATCH 1 of 3] Add basic RadioMod object

Dan Smith
Wed Apr 6 09:19:54 PDT 2011


# HG changeset patch
# User Dan Smith <dsmith at danplanet.com>
# Date 1302106344 25200
# Node ID 3d3a44d2309b969e24571e436eb5b7b706095500
# Parent  99e058729af64f4836e2d9ac6009e9a116f8b0f5
Add basic RadioMod object

diff -r 99e058729af6 -r 3d3a44d2309b chirp/chirp_common.py
--- a/chirp/chirp_common.py	Tue Apr 05 12:36:16 2011 -0700
+++ b/chirp/chirp_common.py	Wed Apr 06 09:12:24 2011 -0700
@@ -492,6 +492,7 @@
         "has_name"            : BOOLEAN,
         "has_ctone"           : BOOLEAN,
         "has_cross"           : BOOLEAN,
+        "has_mods"            : BOOLEAN,
 
         # Attributes
         "valid_modes"         : [],
@@ -542,6 +543,7 @@
         self.has_tuning_step = True
         self.has_ctone = True
         self.has_cross = False
+        self.has_mods = False
 
         self.valid_modes = list(MODES)
         self.valid_tmodes = []
@@ -840,3 +842,66 @@
         if ret != 1:
             ctypes.pythonapi.PyThreadState_SetAsyncExc(self.__tid(), 0)
             raise Exception("Failed to signal thread!")
+
+class RadioMod:
+    def __init__(self, name, current):
+        self._name = name
+        self._current = current
+        self._new = current
+        self._doc = None
+
+    def get_name(self):
+        return self._name
+
+    def get_current_value(self):
+        return self._current
+
+    def get_new_value(self):
+        return self._new
+
+    def set_new_value(self, value):
+        pass
+
+    def set_doc(self, doc):
+        self._doc = doc
+
+    def get_doc(self):
+        return self._doc
+
+    def is_changed(self):
+        return self._current == self._new
+
+class RadioModInt(RadioMod):
+    _format = "%i"
+
+    def set_range(self, low, high):
+        self._low = low
+        self._high = high
+
+    def set_new_value(self, value):
+        value = int(value)
+
+        if value <= self._high and value >= self._low:
+            self._new = value
+        else:
+            raise ValueError("Invalid value")
+
+    def set_display_format(self, format):
+        self._format = format
+
+    def get_display_format(self):
+        return self._format
+
+class RadioModOpt(RadioMod):
+    def set_options(self, options):
+        self._options = options
+
+    def get_options(self):
+        return self._options
+
+    def set_new_value(self, value):
+        if value in self._options:
+            self._new = value
+        else:
+            raise ValueError("Invalid value")
+



More information about the chirp_devel mailing list