[chirp_devel] [PATCH 1 of 3] Add import logic helper to convert odd split to offset. #185
# HG changeset patch # User Tom Hayward tom@tomh.us # Date 1360126719 28800 # Node ID 257d98b3f5717671face8ae70680a50d83c81a1c # Parent 9fea9e34a71ba4b63a3d89e79a072e98d21539f5 Add import logic helper to convert odd split to offset. #185
diff -r 9fea9e34a71b -r 257d98b3f571 chirp/import_logic.py --- a/chirp/import_logic.py Tue Feb 05 19:42:27 2013 -0800 +++ b/chirp/import_logic.py Tue Feb 05 20:58:39 2013 -0800 @@ -144,6 +144,34 @@ if mem.mode == "Auto" and mem.mode not in dstrf.valid_modes: mem.mode = _guess_mode_by_frequency(mem.freq)
+def _make_offset_with_split(rxfreq, txfreq): + offset = txfreq - rxfreq + + if offset == 0: + return "", offset + elif offset > 0: + return "+", offset + elif offset < 0: + return "-", offset * -1 + +def _import_duplex(dst_radio, srcrf, mem): + dstrf = dst_radio.get_features() + + # If a radio does not support odd split, we can use an equivalent offset + if mem.duplex == "split" and mem.duplex not in dstrf.valid_duplexes: + mem.duplex, mem.offset = _make_offset_with_split(mem.freq, mem.offset) + + # Enforce maximum offset + ranges = [ + ( 0, 500000000, 7000000), + (500000000, 3000000000, 50000000), + ] + for lo, hi, limit in ranges: + if mem.freq > lo and mem.freq <= hi: + if mem.offset > limit or mem.offset * -1 > limit: + raise DestNotCompatible("Unable to create import memory: " + "offset is abnormally large.") + def import_mem(dst_radio, src_features, src_mem, overrides={}): """Perform import logic to create a destination memory from src_mem that will be compatible with @dst_radio""" @@ -165,6 +193,7 @@ _import_tone, _import_dtcs, _import_mode, + _import_duplex, ]
for helper in helpers:
# HG changeset patch # User Tom Hayward tom@tomh.us # Date 1360126791 28800 # Node ID 8acf7f0440e42453cd920cb4397bec207da1db97 # Parent 257d98b3f5717671face8ae70680a50d83c81a1c Refactor paste so import logic is performed before validation. #185
diff -r 257d98b3f571 -r 8acf7f0440e4 chirpui/memedit.py --- a/chirpui/memedit.py Tue Feb 05 20:58:39 2013 -0800 +++ b/chirpui/memedit.py Tue Feb 05 20:59:51 2013 -0800 @@ -1307,27 +1307,29 @@
src_number = mem.number mem.number = loc - msgs = self.rthread.radio.validate_memory(mem) - errs = [x for x in msgs if isinstance(x, - chirp_common.ValidationError)] - if errs: - d = miscwidgets.YesNoDialog(title=_("Incompatible Memory"), - buttons=(gtk.STOCK_OK, 1, - gtk.STOCK_CANCEL, 2)) - d.set_text(_("Pasted memory {number} is not compatible with " - "this radio because:").format(number=src_number) +\ - os.linesep + os.linesep.join(msgs)) - r = d.run() - d.destroy() - if r == 2: - break - else: - iter = store.iter_next(iter) - continue - - mem = import_logic.import_mem(self.rthread.radio, - src_features, - mem) + + try: + mem = import_logic.import_mem(self.rthread.radio, + src_features, + mem) + except import_logic.DestNotCompatible: + msgs = self.rthread.radio.validate_memory(mem) + errs = [x for x in msgs if isinstance(x, + chirp_common.ValidationError)] + if errs: + d = miscwidgets.YesNoDialog(title=_("Incompatible Memory"), + buttons=(gtk.STOCK_OK, 1, + gtk.STOCK_CANCEL, 2)) + d.set_text(_("Pasted memory {number} is not compatible with " + "this radio because:").format(number=src_number) +\ + os.linesep + os.linesep.join(msgs)) + r = d.run() + d.destroy() + if r == 2: + break + else: + iter = store.iter_next(iter) + continue
self._set_memory(iter, mem) iter = store.iter_next(iter)
# HG changeset patch # User Tom Hayward tom@tomh.us # Date 1360128738 28800 # Node ID 161d031e2eb610e34ae1824251d04c259d0e52b9 # Parent 8acf7f0440e42453cd920cb4397bec207da1db97 Refactor import so import logic is performed before validation. #185
diff -r 8acf7f0440e4 -r 161d031e2eb6 chirpui/importdialog.py --- a/chirpui/importdialog.py Tue Feb 05 20:59:51 2013 -0800 +++ b/chirpui/importdialog.py Tue Feb 05 21:32:18 2013 -0800 @@ -541,7 +541,13 @@ continue
self.ww.set(float(i) / end) - msgs = self.dst_radio.validate_memory(mem) + try: + msgs = self.dst_radio.validate_memory( + import_logic.import_mem(self.dst_radio, + self.src_radio.get_features(), + mem)) + except import_logic.DestNotCompatible: + msgs = self.dst_radio.validate_memory(mem) errs = [x for x in msgs if isinstance(x, chirp_common.ValidationError)] if errs: msg = _("Cannot be imported because") + ":\r\n"
participants (1)
-
Tom Hayward