# HG changeset patch # User Kosta A. ve7kcy@gmail.com # Date 1631945611 25200 # Fri Sep 17 23:13:31 2021 -0700 # Branch mem-edit # Node ID 0e72d226d24784ced8aecb55362052551f0c1c06 # Parent 9c47d5fc9f51d9b303f5e6ac539db05767c71880 Prevent spuriour error messages in memory editor while editing memories. Fixes #9381.
The memory editor has historically excluded the Frequency column from validating checks to determine if/when a value has changed for the previously noted reason in the code comment. This change attempts to resolve this by caching all column values prior to finalizing the editing and restores the values in the case validation determines nothing has changed or the new contents have failed radio verification.
diff --git a/chirp/ui/memedit.py b/chirp/ui/memedit.py --- a/chirp/ui/memedit.py +++ b/chirp/ui/memedit.py @@ -44,16 +44,6 @@ def handle_toggle(_, path, store, col): store[path][col] = not store[path][col]
- -def handle_ed(_, iter, new, store, col): - old, = store.get(iter, col) - if old != new: - store.set(iter, col, new) - return True - else: - return False - - class ValueErrorDialog(gtk.MessageDialog): def __init__(self, exception, **args): gtk.MessageDialog.__init__(self, buttons=gtk.BUTTONS_OK, **args) @@ -337,9 +327,13 @@ return
iter = self.store.get_iter(path) - if not self.store.get(iter, self.col("_filled"))[0] and \ - self.store.get(iter, self.col(_("Frequency")))[0] == 0: - LOG.error("Editing new item, taking defaults") + vals = self.store.get(iter, *range(0, len(self.cols))) + prev, = self.store.get(iter, self.col(cap)) + filled, = self.store.get(iter, self.col("_filled")) + freq, = self.store.get(iter, self.col(_("Frequency"))) + + # Take default values, if not yet edited + if not filled and freq == 0: self.insert_new(iter)
colnum = self.col(cap) @@ -357,13 +351,16 @@ _("Cross Mode"): self.ed_tone_field, }
+ # Call the specific editor for the given column if cap in funcs: new = funcs[cap](rend, path, new, colnum)
+ # Sanity check if new is None: LOG.error("Bad value for {col}: {val}".format(col=cap, val=new)) return
+ # Convert type based on column if self.store.get_column_type(colnum) == TYPE_INT: new = int(new) elif self.store.get_column_type(colnum) == TYPE_FLOAT: @@ -374,24 +371,30 @@ if new == "(None)": new = ""
- if not handle_ed(rend, iter, new, self.store, self.col(cap)) and \ - cap != _("Frequency"): - # No change was made - # For frequency, we make an exception, since the handler might - # have altered the duplex. That needs to be fixed. + # Verify a change was made + if new == prev: + # Restore all columns to their orginal values, a given editor + # may modify mutliple columns so we need to restore each of them + # to their previous values in order to restore the orginal state. + self._restore(iter, vals) return
+ # Finally, set the new value + self.store.set(iter, self.col(cap), new) + + # Have the radio validate the memory mem = self._get_memory(iter) - msgs = self.rthread.radio.validate_memory(mem) if msgs: common.show_error(_("Error setting memory") + ": " + "\r\n\r\n".join(msgs)) - self.prefill() + # Restore to orginal values and exit + self._restore(iter, vals) return
mem.empty = False
+ # Kick off job to write memory job = common.RadioJob(self._set_memory_cb, "set_memory", mem) job.set_desc(_("Writing memory {number}").format(number=mem.number)) self.rthread.submit(job) @@ -940,7 +943,6 @@
def cell_editing_stopped(self, *args): self._in_editing = False - print 'Would activate %s' % str(self._edit_path) self.view.grab_focus() self.view.set_cursor(*self._edit_path)
@@ -1050,13 +1052,7 @@ _("Internal Error: Column {name} not found").format( name=caption))
- def prefill(self): - self.store.clear() - self._rows_in_store = 0 - - lo = int(self.lo_limit_adj.get_value()) - hi = int(self.hi_limit_adj.get_value()) - + def _prefill(self, num): def handler(mem, number): if not isinstance(mem, Exception): if not mem.empty or self.show_empty: @@ -1065,18 +1061,28 @@ mem = chirp_common.Memory(number, True, "Error") gobject.idle_add(self.set_memory, mem)
+ job = common.RadioJob(handler, "get_memory", num) + job.set_desc(_("Getting memory {number}").format(number=num)) + job.set_cb_args(num) + self.rthread.submit(job, 2) + + def prefill(self): + self.store.clear() + self._rows_in_store = 0 + + lo = int(self.lo_limit_adj.get_value()) + hi = int(self.hi_limit_adj.get_value()) + for i in range(lo, hi+1): - job = common.RadioJob(handler, "get_memory", i) - job.set_desc(_("Getting memory {number}").format(number=i)) - job.set_cb_args(i) - self.rthread.submit(job, 2) + self._prefill(i)
if self.show_special: for i in self._features.valid_special_chans: - job = common.RadioJob(handler, "get_memory", i) - job.set_desc(_("Getting channel {chan}").format(chan=i)) - job.set_cb_args(i) - self.rthread.submit(job, 2) + self._prefill(i) + + def _restore(self, iter, vals): + for col, val in enumerate(vals): + self.store.set(iter, col, val)
def _set_memory(self, iter, memory): self.store.set(iter, @@ -1692,7 +1698,3 @@ self.col("RPT2CALL"), "", self.col("Digital Code"), 0, ) - - -class ID800MemoryEditor(DstarMemoryEditor): - pass