[chirp_devel] [PATCH] Add batch memory editing support to the detail editor
# HG changeset patch # User Dan Smith dsmith@danplanet.com # Date 1364945209 25200 # Node ID 3e8c20f0cc978ba54bbef5a135b0a3099502625f # Parent 4f0521cefe56eef2dd0567e6402763be0f40cd56 Add batch memory editing support to the detail editor
Implements #234
diff -r 4f0521cefe56 -r 3e8c20f0cc97 chirpui/memdetail.py --- a/chirpui/memdetail.py Mon Apr 01 21:32:51 2013 -0700 +++ b/chirpui/memdetail.py Tue Apr 02 16:26:49 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] @@ -225,10 +231,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, @@ -236,7 +245,6 @@ self._tips = gtk.Tooltips()
self._features = features - self._memory = memory
self._editors = {} self._elements = { @@ -322,3 +330,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 4f0521cefe56 -r 3e8c20f0cc97 chirpui/memedit.py --- a/chirpui/memedit.py Mon Apr 01 21:32:51 2013 -0700 +++ b/chirpui/memedit.py Tue Apr 02 16:26:49 2013 -0700 @@ -692,23 +692,56 @@ 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) + job = common.RadioJob(None, "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) + 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) self.emit("changed") 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 +776,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:
participants (1)
-
Dan Smith