[chirp_devel] [PATCH 2 of 2] Make EditorSet handle multiple MemoryMapping objects
Dan Smith
Mon Apr 1 17:16:13 PDT 2013
# HG changeset patch
# User Dan Smith <dsmith at danplanet.com>
# Date 1364861757 25200
# Node ID b6bca3fba0e99bbef63392bfe046f6765b21f110
# Parent d04801a1c0302d80d0dbfbc617b707da7ebcc389
Make EditorSet handle multiple MemoryMapping objects
This makes EditorSet create a generic membership and names (if appropriate)
editor for each MemoryMapping object exported by the radio.
Related to #741
diff -r d04801a1c030 -r b6bca3fba0e9 chirpui/bankedit.py
--- a/chirpui/bankedit.py Mon Apr 01 17:15:56 2013 -0700
+++ b/chirpui/bankedit.py Mon Apr 01 17:15:57 2013 -0700
@@ -38,8 +38,6 @@
gobject.idle_add(self.cb, *self.cb_args)
class MappingNameEditor(common.Editor):
- TYPE = _("Mapping")
-
def refresh(self):
def got_mappings():
self._keys = []
@@ -52,7 +50,7 @@
self.listw.connect("item-set", self.mapping_changed)
job = MappingNamesJob(self._model, self, got_mappings)
- job.set_desc(_("Retrieving %s information") % self.TYPE)
+ job.set_desc(_("Retrieving %s information") % self._type)
self.rthread.submit(job)
def get_mapping_list(self):
@@ -75,7 +73,7 @@
job = common.RadioJob(trigger_changed, "set_name", name)
job.set_target(mapping)
- job.set_desc(_("Setting name on %s") % self.TYPE.lower())
+ job.set_desc(_("Setting name on %s") % self._type.lower())
self.rthread.submit(job)
return True
@@ -83,9 +81,10 @@
def __init__(self, rthread, model):
super(MappingNameEditor, self).__init__(rthread)
self._model = model
+ self._type = common.unpluralize(model.get_name())
types = [(gobject.TYPE_STRING, "key"),
- (gobject.TYPE_STRING, self.TYPE),
+ (gobject.TYPE_STRING, self._type),
(gobject.TYPE_STRING, _("Name"))]
self.listw = miscwidgets.KeyedListWidget(types)
@@ -110,13 +109,6 @@
self.refresh()
self._loaded = True
-class BankNameEditor(MappingNameEditor):
- TYPE = _("Bank")
-
- def __init__(self, rthread):
- model = rthread.radio.get_bank_model()
- super(BankNameEditor, self).__init__(rthread, model)
-
class MemoryMappingsJob(common.RadioJob):
def __init__(self, model, cb, number):
common.RadioJob.__init__(self, cb, None)
@@ -138,8 +130,6 @@
self.cb(mem, mappings, indexes, *self.cb_args)
class MappingMembershipEditor(common.Editor):
- TYPE = _("Mapping")
-
def _number_to_path(self, number):
return (number - self._rf.memory_bounds[0],)
@@ -215,7 +205,7 @@
"set_memory_index", memory, mapping, index)
job.set_target(self._model)
job.set_desc(_("Updating {type} index "
- "for memory {num}").format(type=self.TYPE,
+ "for memory {num}").format(type=self._type,
num=memory.number))
self.rthread.submit(job)
@@ -255,7 +245,7 @@
job.set_cb_args(memory)
job.set_target(self._model)
job.set_desc(_("Getting {type} for "
- "memory {num}").format(type=self.TYPE,
+ "memory {num}").format(type=self._type,
num=memory.number))
self.rthread.submit(job)
@@ -270,6 +260,7 @@
self.editorset = editorset
self._rf = rthread.radio.get_features()
self._model = model
+ self._type = common.unpluralize(model.get_name())
self._view_cols = [
(_("Loc"), TYPE_INT, gtk.CellRendererText, ),
@@ -294,7 +285,7 @@
self._index_cache = []
for i in range(0, self._model.get_num_mappings()):
- label = "%s %i" % (self.TYPE, (i+1))
+ label = "%s %i" % (self._type, (i+1))
cols.append((label, TYPE_BOOLEAN, gtk.CellRendererToggle))
self._store = gtk.ListStore(*tuple([y for x,y,z in cols]))
@@ -364,12 +355,12 @@
self._store.set(iter, *tuple(row))
if memory.number == self._rf.memory_bounds[1] - 1:
- print "Got all %s info in %s" % (self.TYPE,
+ print "Got all %s info in %s" % (self._type,
(time.time() - self._start))
job = MemoryMappingsJob(self._model, got_mem, number)
job.set_desc(_("Getting {type} information "
- "for memory {num}").format(type=self.TYPE, num=number))
+ "for memory {num}").format(type=self._type, num=number))
self.rthread.submit(job)
def refresh_all_memories(self):
@@ -390,7 +381,7 @@
self.refresh_all_memories()
job = MappingNamesJob(self._model, self, got_mappings)
- job.set_desc(_("Getting %s information") % self.TYPE)
+ job.set_desc(_("Getting %s information") % self._type)
self.rthread.submit(job)
def focus(self):
@@ -410,13 +401,3 @@
def mappings_changed(self):
self.refresh_mappings()
-
-class BankMembershipEditor(MappingMembershipEditor):
- TYPE = _("Bank")
-
- def __init__(self, rthread, editorset):
- model = rthread.radio.get_bank_model()
- super(BankMembershipEditor, self).__init__(rthread, editorset, model)
-
- def banks_changed(self):
- self.mappings_changed()
diff -r d04801a1c030 -r b6bca3fba0e9 chirpui/common.py
--- a/chirpui/common.py Mon Apr 01 17:15:56 2013 -0700
+++ b/chirpui/common.py Mon Apr 01 17:15:57 2013 -0700
@@ -410,3 +410,8 @@
d.run()
d.destroy()
+def unpluralize(string):
+ if string.endswith("s"):
+ return string[:-1]
+ else:
+ return string
diff -r d04801a1c030 -r b6bca3fba0e9 chirpui/editorset.py
--- a/chirpui/editorset.py Mon Apr 01 17:15:56 2013 -0700
+++ b/chirpui/editorset.py Mon Apr 01 17:15:57 2013 -0700
@@ -35,16 +35,47 @@
(gobject.TYPE_STRING,)),
}
+ def _make_device_mapping_editors(self, device, devrthread, index):
+ sub_index = 0
+ memory_editor = self.editors["memedit%i" % index]
+ mappings = device.get_mapping_models()
+ for mapping_model in mappings:
+ members = bankedit.MappingMembershipEditor(devrthread, self,
+ mapping_model)
+ label = mapping_model.get_name()
+ if self.rf.has_sub_devices:
+ label += "(%s)" % device.VARIANT
+ lab = gtk.Label(label)
+ self.tabs.append_page(members.root, lab)
+ self.editors["mapping_members%i%i" % (index, sub_index)] = members
+
+ basename = common.unpluralize(mapping_model.get_name())
+ names = bankedit.MappingNameEditor(devrthread, mapping_model)
+ label = "%s Names" % basename
+ if self.rf.has_sub_devices:
+ label += " (%s)" % device.VARIANT
+ lab = gtk.Label(label)
+ self.tabs.append_page(names.root, lab)
+ self.editors["mapping_members%i%i" % (index, sub_index)] = members
+
+ members.root.show()
+ memory_editor.connect("changed",
+ lambda x: members.memories_changed())
+ if hasattr(mapping_model.get_mappings()[0], "set_name"):
+ names.root.show()
+ members.connect("changed", lambda x: names.mappings_changed())
+ names.connect("changed", lambda x: members.mappings_changed())
+ memory_editor.connect("changed",
+ lambda x: names.memories_changed())
+
def _make_device_editors(self, device, devrthread, index):
- key = "memedit%i" % index
if isinstance(device, chirp_common.IcomDstarSupport):
- self.editors[key] = memedit.DstarMemoryEditor(devrthread)
+ memories = memedit.DstarMemoryEditor(devrthread)
else:
- self.editors[key] = memedit.MemoryEditor(devrthread)
+ memories = memedit.MemoryEditor(devrthread)
- self.editors[key].connect("usermsg",
- lambda e, m: self.emit("usermsg", m))
- self.editors[key].connect("changed", self.editor_changed)
+ memories.connect("usermsg", lambda e, m: self.emit("usermsg", m))
+ memories.connect("changed", self.editor_changed)
if self.rf.has_sub_devices:
label = (_("Memories (%(variant)s)") %
@@ -54,33 +85,11 @@
label = _("Memories")
rf = self.rf
lab = gtk.Label(label)
- memedit_tab = self.tabs.append_page(self.editors[key].root, lab)
- self.editors[key].root.show()
+ self.tabs.append_page(memories.root, lab)
+ memories.root.show()
+ self.editors["memedit%i" % index] = memories
- if rf.has_bank:
- key = "bank_members%i" % index
- self.editors[key] = bankedit.BankMembershipEditor(devrthread, self)
- if self.rf.has_sub_devices:
- label = _("Banks (%(variant)s)") % dict(variant=device.VARIANT)
- else:
- label = _("Banks")
- lab = gtk.Label(label)
- self.tabs.append_page(self.editors[key].root, lab)
- self.editors[key].root.show()
- self.editors[key].connect("changed", self.banks_changed)
-
- if rf.has_bank_names:
- key = "bank_names%i" % index
- self.editors[key] = bankedit.BankNameEditor(devrthread)
- if self.rf.has_sub_devices:
- label = (_("Bank Names (%(variant)s)") %
- dict(variant=device.VARIANT))
- else:
- label = _("Bank Names")
- lab = gtk.Label(label)
- self.tabs.append_page(self.editors[key].root, lab)
- self.editors[key].root.show()
- self.editors[key].connect("changed", self.banks_changed)
+ self._make_device_mapping_editors(device, devrthread, index)
def __init__(self, source, parent_window=None, filename=None, tempname=None):
gtk.VBox.__init__(self, True, 0)
More information about the chirp_devel
mailing list