From b02e7afd98d26f456520f8ca2130f20a2eeb0b10 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Sat, 31 Aug 2024 08:32:25 -0700 Subject: [PATCH] Fix pasting memories past end of range The memory editor will fail with a 'KeyError: N' error if the user attempts to paste more memories than will fit. This makes us not choke, stop when we get to the end, and report to the user (unless the memories that don't fit are empty). Fixes #11510 --- chirp/wxui/memedit.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/chirp/wxui/memedit.py b/chirp/wxui/memedit.py index 46266b1c..9744a073 100644 --- a/chirp/wxui/memedit.py +++ b/chirp/wxui/memedit.py @@ -1984,7 +1984,12 @@ def _cb_paste_memories(self, payload, row=None): overwrite = [] for i in range(len(mems)): - mem = self._memory_cache[row + i] + try: + mem = self._memory_cache[row + i] + except KeyError: + # No more memories in the target. This will be handled/reported + # in the actual paste loop below. + break if not mem.empty: overwrite.append(mem.extd_number or mem.number) @@ -2015,7 +2020,20 @@ def _cb_paste_memories(self, payload, row=None): errormsgs = [] modified = False for mem in mems: - existing = self._memory_cache[row] + try: + existing = self._memory_cache[row] + except KeyError: + if not mem.empty: + LOG.debug('Not pasting to row %i beyond end of memory', + row) + errormsgs.append( + (mem, _('No more space available; ' + 'some memories were not applied'))) + break + else: + # Don't complain about empty memories past the end of the + # current radio's memory upper bound. + continue number = self.row2mem(row) # We need to disable immutable checking while we reassign these # numbers. This might be a flag that we should be copying things