[chirp_devel] [PATCH] Add batch memory editing support to the detail editor
Dan Smith
Wed Apr 3 10:39:47 PDT 2013
# HG changeset patch
# User Dan Smith <dsmith at danplanet.com>
# Date 1364948814 25200
# Node ID df16f648b07e079b3495de68fd984dab23e07ac8
# Parent 88968d7b52b4c4128cab71561932f932f4e063af
Add batch memory editing support to the detail editor
Implements #234
diff -r 88968d7b52b4 -r df16f648b07e chirpui/memdetail.py
--- a/chirpui/memdetail.py Tue Apr 02 17:16:20 2013 -0700
+++ b/chirpui/memdetail.py Tue Apr 02 17:26:54 2013 -0700
@@ -34,6 +34,9 @@
def _init(self, data):
"""Type-specific initialization"""
+ def set_sensitive(self, sensitive):
+ self._widget.set_sensitive(sensitive)
+
def get_widget(self):
"""Returns the widget associated with this editor"""
return self._widget
@@ -157,21 +160,24 @@
class MemoryDetailEditor(gtk.Dialog):
"""Detail editor for a memory"""
- def _add(self, tab, row, name, editor, labeltxt):
+ def _add(self, tab, row, name, editor, labeltxt, colindex=0):
label = gtk.Label(labeltxt)
img = gtk.Image()
label.show()
- tab.attach(label, 0, 1, row, row+1)
+ tab.attach(label, colindex, colindex + 1, row, row + 1)
+ colindex += 1
editor.get_widget().show()
- tab.attach(editor.get_widget(), 1, 2, row, row+1)
+ tab.attach(editor.get_widget(), colindex, colindex + 1, row, row + 1)
+ colindex += 1
img.set_size_request(15, -1)
img.show()
- tab.attach(img, 2, 3, row, row+1)
+ tab.attach(img, colindex, colindex + 1, row, row + 1)
self._editors[name] = label, editor, img
+ return label, editor, img
def _set_doc(self, name, doc):
label, editor, _img = self._editors[name]
@@ -229,10 +235,13 @@
row += 1
self._order.append(name)
+ def _title(self):
+ return _("Edit Memory #{num}").format(num=self._memory.number)
+
def __init__(self, features, memory, parent=None):
+ self._memory = memory
gtk.Dialog.__init__(self,
- title=_("Edit Memory"
- "#{num}").format(num=memory.number),
+ title=self._title(),
flags=gtk.DIALOG_MODAL,
parent=parent,
buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
@@ -241,7 +250,6 @@
self._tips = gtk.Tooltips()
self._features = features
- self._memory = memory
self._editors = {}
self._elements = {
@@ -327,3 +335,29 @@
def get_memory(self):
self._memory.empty = False
return self._memory
+
+class MultiMemoryDetailEditor(MemoryDetailEditor):
+ def _title(self):
+ return _("Edit Multiple Memories")
+
+ def __init__(self, features, memory, parent=None):
+ self._selections = dict()
+ super(MultiMemoryDetailEditor, self).__init__(features, memory, parent)
+
+ def _toggle_selector(self, selector, *widgets):
+ for widget in widgets:
+ widget.set_sensitive(selector.get_active())
+
+ def _add(self, tab, row, name, editor, labeltxt):
+ label, editor, img = super(MultiMemoryDetailEditor, self)._add(
+ tab, row, name, editor, labeltxt, 1)
+
+ selector = gtk.CheckButton()
+ tab.attach(selector, 0, 1, row, row + 1)
+ selector.show()
+ self._toggle_selector(selector, label, editor, img)
+ selector.connect("toggled", self._toggle_selector, label, editor, img)
+ self._selections[name] = selector
+
+ def get_fields(self):
+ return [k for k, v in self._selections.items() if v.get_active()]
diff -r 88968d7b52b4 -r df16f648b07e chirpui/memedit.py
--- a/chirpui/memedit.py Tue Apr 02 17:16:20 2013 -0700
+++ b/chirpui/memedit.py Tue Apr 02 17:26:54 2013 -0700
@@ -692,23 +692,57 @@
job.set_desc(_("Getting raw memory {number}").format(number=loc_b))
self.rthread.submit(job)
- def edit_memory(self, memory):
- dlg = memdetail.MemoryDetailEditor(self._features, memory)
+ def _copy_field(self, src_memory, dst_memory, field):
+ if field.startswith("extra_"):
+ field = field.split("_", 1)[1]
+ value = src_memory.extra[field].value.get_value()
+ dst_memory.extra[field].value = value
+ else:
+ setattr(dst_memory, field, getattr(src_memory, field))
+
+ def _apply_multiple(self, src_memory, fields, locations):
+ for location in locations:
+ def apply_and_set(memory):
+ for field in fields:
+ self._copy_field(src_memory, memory, field)
+ cb = (memory.number == locations[-1]
+ and self._set_memory_cb or None)
+ job = common.RadioJob(cb, "set_memory", memory)
+ job.set_desc(_("Writing memory {number}").format(
+ number=memory.number))
+ self.rthread.submit(job)
+ job = common.RadioJob(apply_and_set, "get_memory", location)
+ job.set_desc(_("Getting original memory {number}").format(
+ number=location))
+ self.rthread.submit(job)
+
+ def edit_memory(self, memory, locations):
+ if len(locations) > 1:
+ dlg = memdetail.MultiMemoryDetailEditor(self._features, memory)
+ else:
+ dlg = memdetail.MemoryDetailEditor(self._features, memory)
r = dlg.run()
if r == gtk.RESPONSE_OK:
self.need_refresh = True
mem = dlg.get_memory()
- mem.name = self.rthread.radio.filter_name(mem.name)
- job = common.RadioJob(self._set_memory_cb, "set_memory", mem)
- job.set_desc(_("Writing memory {number}").format(number=mem.number))
- self.rthread.submit(job)
- self.emit("changed")
+ if len(locations) > 1:
+ self._apply_multiple(memory, dlg.get_fields(), locations)
+ else:
+ mem.name = self.rthread.radio.filter_name(mem.name)
+ job = common.RadioJob(self._set_memory_cb, "set_memory", mem)
+ job.set_desc(_("Writing memory {number}").format(
+ number=mem.number))
+ self.rthread.submit(job)
dlg.destroy()
def mh(self, _action, store, paths):
action = _action.get_name()
- iter = store.get_iter(paths[0])
- cur_pos, = store.get(iter, self.col(_("Loc")))
+ selected = []
+ for path in paths:
+ iter = store.get_iter(path)
+ loc, = store.get(iter, self.col(_("Loc")))
+ selected.append(loc)
+ cur_pos = selected[0]
require_contiguous = ["delete_s", "move_up", "move_dn"]
if action in require_contiguous:
@@ -743,6 +777,7 @@
self._diff_raw(paths)
elif action == "edit":
job = common.RadioJob(self.edit_memory, "get_memory", cur_pos)
+ job.set_cb_args(selected)
self.rthread.submit(job)
if changed:
More information about the chirp_devel
mailing list