[chirp_devel] [PATCH 1 of 7] Bank Rebase: basic support

Dan Smith
Tue Feb 7 20:08:27 PST 2012


# HG changeset patch
# User Dan Smith <dsmith at danplanet.com>
# Date 1328671740 28800
# Node ID fa6b1f430f74f991f945a62dfb59e56d3ac6e4e7
# Parent  3db9dc931cbc2d39111c4173c4d51eeac3a362bc
Bank Rebase: basic support

This change introduces a BankModel object, as well as refined Bank and
NamedBank objects. A radio driver should implement BankModel and return
it from Radio.get_banks(). This encapsulates all bank-related transactions.
Radios with user-nameable banks should also implement NamedBank and plumb
name changes accordingly.

diff -r 3db9dc931cbc -r fa6b1f430f74 chirp/chirp_common.py
--- a/chirp/chirp_common.py	Tue Feb 07 15:26:23 2012 -0800
+++ b/chirp/chirp_common.py	Tue Feb 07 19:29:00 2012 -0800
@@ -527,18 +527,83 @@
             self.dv_code = 0
 
 class Bank:
-    def __init__(self, name):
-        self.__dict__["name"] = name
+    def __init__(self, model, index, name):
+        self._model = model
+        self._index = index
+        self._name = name
 
     def __str__(self):
-        return self.name
+        return self._name
 
-class ImmutableBank(Bank):
-    def __setattr__(self, name, val):
-        if not hasattr(self, name):
-            raise ValueError("No such attribute `%s'" % name)
-        else:
-            raise ValueError("Property is immutable")    
+    def get_name(self):
+        """Returns the static or user-adjustable bank name"""
+        return self._name
+
+    def get_index(self):
+        """Returns the immutable bank index (string or int)"""
+        return self._index
+
+    def __eq__(self, other):
+        return self.get_index() == other.get_index()
+
+class NamedBank(Bank):
+    def set_name(self, name):
+        """Changes the user-adjustable bank name"""
+        self._name = name
+
+class BankModel:
+    """A bank model where one memory is in zero or one banks at any point"""
+    def __init__(self, radio):
+        self._radio = radio
+
+    def get_num_banks(self):
+        """Returns the number of banks (should be callable without
+        consulting the radio"""
+        raise Exception("Not implemented")
+
+    def get_banks(self):
+        """Return a list of banks"""
+        raise Exception("Not implemented")
+
+    def add_memory_to_bank(self, memory, bank):
+        """Add @memory to @bank."""
+        raise Exception("Not implemented")
+
+    def remove_memory_from_bank(self, memory, bank):
+        """Remove @memory from @bank.
+        Shall raise exception if @memory is not in @bank."""
+        raise Exception("Not implemented")
+
+    def get_bank_memories(self, bank):
+        """Return a list of memories in @bank"""
+        raise Exception("Not implemented")
+
+    def get_memory_banks(self, memory):
+        """Returns a list of the banks that @memory is in"""
+        raise Exception("Not implemented")
+
+class BankIndexInterface:
+    def get_index_bounds(self):
+        """Returns a tuple (lo,hi) of the minimum and maximum bank indices"""
+        raise Exception("Not implemented")
+
+    def get_memory_index(self, memory, bank):
+        """Returns the index of @memory in @bank"""
+        raise Exception("Not implemented")
+
+    def set_memory_index(self, memory, bank, index):
+        """Sets the index of @memory in @bank to @index"""
+        raise Exception("Not implemented")
+
+    def get_next_bank_index(self, bank):
+        """Returns the next available bank index in @bank, or raises
+        Exception if full"""
+        raise Exception("Not implemented")
+
+
+class MTOBankModel(BankModel):
+    """A bank model where one memory can be in multiple banks at once """
+    pass
 
 def console_status(status):
     import sys
@@ -562,6 +627,7 @@
         "has_offset"          : BOOLEAN,
         "has_name"            : BOOLEAN,
         "has_bank"            : BOOLEAN,
+        "has_bank_names"      : BOOLEAN,
         "has_tuning_step"     : BOOLEAN,
         "has_name"            : BOOLEAN,
         "has_ctone"           : BOOLEAN,
@@ -645,6 +711,8 @@
                   "Indicates that an alphanumeric memory name is supported")
         self.init("has_bank", True,
                   "Indicates that memories may be placed into banks")
+        self.init("has_bank_names", False,
+                  "Indicates that banks may be named")
         self.init("has_tuning_step", True,
                   "Indicates that memories store their tuning step")
         self.init("has_ctone", True,
@@ -758,11 +826,9 @@
     def set_memories(self, memories):
         pass
 
-    def get_banks(self):
-        return []
-
-    def set_banks(self, banks):
-        raise errors.InvalidDataError("This model does not support bank naming")
+    def get_bank_model(self):
+        """Returns either a BankModel or None if not supported"""
+        return None
 
     def get_raw_memory(self, number):
         pass



More information about the chirp_devel mailing list