diff options
| author | Iain R. Learmonth <irl@fsfe.org> | 2015-05-03 18:15:26 +0100 |
|---|---|---|
| committer | Iain R. Learmonth <irl@fsfe.org> | 2015-05-03 18:15:26 +0100 |
| commit | c86187dcdf158df59977baee6c8d6385f964b69b (patch) | |
| tree | 9b4f956c3bbfd9bbb48cf60aa75a32051e496d2c /chirpui/memedit.py | |
| parent | 717fcf5fd76d3c672c609f336c80a675a548c4c6 (diff) | |
Imported Upstream version 0.4.0upstream/0.4.0
Diffstat (limited to 'chirpui/memedit.py')
| -rw-r--r-- | chirpui/memedit.py | 212 |
1 files changed, 161 insertions, 51 deletions
diff --git a/chirpui/memedit.py b/chirpui/memedit.py index 5764ee0..b0c3ab9 100644 --- a/chirpui/memedit.py +++ b/chirpui/memedit.py @@ -33,6 +33,7 @@ import pickle import os from chirpui import common, shiftdialog, miscwidgets, config, memdetail +from chirpui import bandplans from chirp import chirp_common, errors, directory, import_logic def handle_toggle(_, path, store, col): @@ -104,10 +105,8 @@ class MemoryEditor(common.Editor): choices = { _("Tone") : chirp_common.TONES, _("ToneSql") : chirp_common.TONES, - _("DTCS Code") : sorted(chirp_common.DTCS_CODES + - chirp_common.DTCS_EXTRA_CODES), - _("DTCS Rx Code") : sorted(chirp_common.DTCS_CODES + - chirp_common.DTCS_EXTRA_CODES), + _("DTCS Code") : chirp_common.ALL_DTCS_CODES, + _("DTCS Rx Code") : chirp_common.ALL_DTCS_CODES, _("DTCS Pol") : ["NN", "NR", "RN", "RR"], _("Mode") : chirp_common.MODES, _("Power") : [], @@ -121,13 +120,14 @@ class MemoryEditor(common.Editor): return self.rthread.radio.filter_name(new) def ed_offset(self, _, path, new, __): - return chirp_common.parse_freq(new) + new = chirp_common.parse_freq(new) + return abs(new) def ed_freq(self, _foo, path, new, colnum): iter = self.store.get_iter(path) - prev, = self.store.get(iter, colnum) + was_filled, prev = self.store.get(iter, self.col("_filled"), colnum) - def set_offset(path, offset): + def set_offset(offset): if offset > 0: dup = "+" elif offset == 0: @@ -136,17 +136,37 @@ class MemoryEditor(common.Editor): dup = "-" offset *= -1 + if not dup in self.choices[_("Duplex")]: + print "Duplex %s not supported by this radio" % dup + return + if offset: self.store.set(iter, self.col(_("Offset")), offset) self.store.set(iter, self.col(_("Duplex")), dup) def set_ts(ts): - self.store.set(iter, self.col(_("Tune Step")), ts) + if ts in self.choices[_("Tune Step")]: + self.store.set(iter, self.col(_("Tune Step")), ts) + else: + print "Tune step %s not supported by this radio" % ts def get_ts(path): return self.store.get(iter, self.col(_("Tune Step")))[0] + def set_mode(mode): + if mode in self.choices[_("Mode")]: + self.store.set(iter, self.col(_("Mode")), mode) + else: + print "Mode %s not supported by this radio (%s)" % ( + mode, self.choices[_("Mode")]) + + def set_tone(tone): + if tone in self.choices[_("Tone")]: + self.store.set(iter, self.col(_("Tone")), tone) + else: + print "Tone %s not supported by this radio" % tone + try: new = chirp_common.parse_freq(new) except ValueError, e: @@ -156,16 +176,16 @@ class MemoryEditor(common.Editor): if not self._features.has_nostep_tuning: set_ts(chirp_common.required_step(new)) - if new and self._config.get_bool("autorpt") and new != prev: - try: - band = chirp_common.freq_to_band(new) - set_offset(path, 0) - for lo, hi, offset in chirp_common.STD_OFFSETS[band]: - if new > lo and new < hi: - set_offset(path, offset) - break - except Exception, e: - pass + is_changed = new != prev if was_filled else True + if new is not None and is_changed: + defaults = self.bandplans.get_defaults_for_frequency(new) + set_offset(defaults.offset or 0) + if defaults.step_khz: + set_ts(defaults.step_khz) + if defaults.mode: + set_mode(defaults.mode) + if defaults.tones: + set_tone(defaults.tones[0]) return new @@ -192,15 +212,58 @@ class MemoryEditor(common.Editor): # RX frequency as the default TX frequency self.store.set(iter, self.col("Offset"), freq) else: - band = int(freq / 100000000) - if chirp_common.STD_OFFSETS.has_key(band): - offset = chirp_common.STD_OFFSETS[band][0][2] - else: - offset = 0 + defaults = self.bandplans.get_defaults_for_frequency(freq) + offset = defaults.offset or 0 self.store.set(iter, self.col(_("Offset")), abs(offset)) return new + def ed_tone_field(self, _foo, path, new, col): + if self._config.get_bool("no_smart_tmode"): + return new + + iter = self.store.get_iter(path) + + # Python scoping hurts us here, so store this as a list + # that we can modify, instead of helpful variables :( + modes = list(self.store.get(iter, + self.col(_("Tone Mode")), + self.col(_("Cross Mode")))) + + def _tm(*tmodes): + if modes[0] not in tmodes: + modes[0] = tmodes[0] + self.store.set(iter, self.col(_("Tone Mode")), modes[0]) + def _cm(*cmodes): + if modes[0] == "Cross" and modes[1] not in cmodes: + modes[1] = cmodes[0] + self.store.set(iter, self.col(_("Cross Mode")), modes[1]) + + if col == self.col(_("DTCS Code")): + _tm("DTCS", "Cross") + _cm(*tuple([x for x in chirp_common.CROSS_MODES + if x.startswith("DTCS->")])) + elif col == self.col(_("DTCS Rx Code")): + _tm("Cross") + _cm(*tuple([x for x in chirp_common.CROSS_MODES + if x.endswith("->DTCS")])) + elif col == self.col(_("DTCS Pol")): + _tm("DTCS", "Cross") + _cm(*tuple([x for x in chirp_common.CROSS_MODES + if "DTCS" in x])) + elif col == self.col(_("Tone")): + _tm("Tone", "Cross") + _cm(*tuple([x for x in chirp_common.CROSS_MODES + if x.startswith("Tone->")])) + elif col == self.col(_("ToneSql")): + _tm("TSQL", "Cross") + _cm(*tuple([x for x in chirp_common.CROSS_MODES + if x.endswith("->Tone")])) + elif col == self.col(_("Cross Mode")): + _tm("Cross") + + return new + def _get_cols_to_hide(self, iter): tmode, duplex, cmode = self.store.get(iter, self.col(_("Tone Mode")), @@ -248,7 +311,7 @@ class MemoryEditor(common.Editor): if "DTCS" not in cmode: hide += [self.col(_("DTCS Pol"))] - if duplex == "" or duplex == "(None)": + if duplex == "" or duplex == "(None)" or duplex == "off": hide += [self.col(_("Offset"))] @@ -276,6 +339,12 @@ class MemoryEditor(common.Editor): _("Frequency") : self.ed_freq, _("Duplex") : self.ed_duplex, _("Offset") : self.ed_offset, + _("Tone") : self.ed_tone_field, + _("ToneSql"): self.ed_tone_field, + _("DTCS Code"): self.ed_tone_field, + _("DTCS Rx Code"): self.ed_tone_field, + _("DTCS Pol"): self.ed_tone_field, + _("Cross Mode"): self.ed_tone_field, } if funcs.has_key(cap): @@ -306,7 +375,7 @@ class MemoryEditor(common.Editor): msgs = self.rthread.radio.validate_memory(mem) if msgs: - common.show_error(_("Error setting memory") + \ + common.show_error(_("Error setting memory") + ": " + \ "\r\n\r\n".join(msgs)) self.prefill() return @@ -397,7 +466,7 @@ class MemoryEditor(common.Editor): else: iter = store.iter_next(_iter) - pos, = store.get(iter, self.col("Loc")) + pos, = store.get(iter, self.col(_("Loc"))) sd = shiftdialog.ShiftDialog(self.rthread) @@ -455,12 +524,12 @@ class MemoryEditor(common.Editor): return True # We changed memories - def _delete_rows_and_shift(self, paths): + def _delete_rows_and_shift(self, paths, all=False): iter = self.store.get_iter(paths[0]) starting_loc, = self.store.get(iter, self.col(_("Loc"))) for i in range(0, len(paths)): sd = shiftdialog.ShiftDialog(self.rthread) - sd.delete(starting_loc, quiet=True) + sd.delete(starting_loc, quiet=True, all=all) sd.destroy() self.prefill() @@ -640,23 +709,57 @@ class MemoryEditor(common.Editor): 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: @@ -677,6 +780,8 @@ class MemoryEditor(common.Editor): changed = self._delete_rows(paths) elif action == "delete_s": changed = self._delete_rows_and_shift(paths) + elif action == "delete_sall": + changed = self._delete_rows_and_shift(paths, all=True) elif action in ["move_up", "move_dn"]: changed = self._move_up_down(paths, action) elif action == "exchange": @@ -691,6 +796,7 @@ class MemoryEditor(common.Editor): 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: @@ -724,8 +830,11 @@ class MemoryEditor(common.Editor): <menuitem action="edit"/> <menuitem action="insert_prev"/> <menuitem action="insert_next"/> - <menuitem action="delete"/> - <menuitem action="delete_s"/> + <menu action="deletes"> + <menuitem action="delete"/> + <menuitem action="delete_s"/> + <menuitem action="delete_sall"/> + </menu> <menuitem action="move_up"/> <menuitem action="move_dn"/> <menuitem action="exchange"/> @@ -747,8 +856,10 @@ class MemoryEditor(common.Editor): ("edit", _("Edit")), ("insert_prev", _("Insert row above")), ("insert_next", _("Insert row below")), - ("delete", issingle and _("Delete") or _("Delete all")), - ("delete_s", _("Delete (and shift up)")), + ("deletes", _("Delete")), + ("delete", issingle and _("this memory") or _("these memories")), + ("delete_s", _("...and shift block up")), + ("delete_sall", _("...and shift all memories up")), ("move_up", _("Move up")), ("move_dn", _("Move down")), ("exchange", _("Exchange memories")), @@ -1022,7 +1133,7 @@ class MemoryEditor(common.Editor): def _limit_key(self, which): if which not in ["lo", "hi"]: - raise Exception(_("Internal Error: Invalid limit {number").format(number=which)) + raise Exception(_("Internal Error: Invalid limit {number}").format(number=which)) return "%s_%s" % (directory.radio_class_id(self.rthread.radio.__class__), which) @@ -1110,12 +1221,6 @@ class MemoryEditor(common.Editor): self.prefill() self._config.set_bool("hide_empty", not show) - def set_read_only(self, read_only): - self.read_only = read_only - - def get_read_only(self): - return self.read_only - def set_hide_unused(self, hide_unused): self.hide_unused = hide_unused self.prefill() @@ -1175,13 +1280,14 @@ class MemoryEditor(common.Editor): return user_visible def __init__(self, rthread): - common.Editor.__init__(self) - self.rthread = rthread + super(MemoryEditor, self).__init__(rthread) self.defaults = dict(self.defaults) self._config = config.get("memedit") + self.bandplans = bandplans.BandPlans(config.get()) + self.allowed_bands = [144, 440] self.count = 100 self.show_special = self._config.get_bool("show_special") @@ -1208,6 +1314,8 @@ class MemoryEditor(common.Editor): self.choices[_("Power")] = [str(x) for x in self._features["valid_power_levels"]] self.choices[_("DTCS Pol")] = self._features["valid_dtcs_pols"] + self.choices[_("DTCS Code")] = self._features["valid_dtcs_codes"] + self.choices[_("DTCS Rx Code")] = self._features["valid_dtcs_codes"] if self._features["valid_power_levels"]: self.defaults[_("Power")] = self._features["valid_power_levels"][0] @@ -1371,7 +1479,9 @@ class MemoryEditor(common.Editor): cols = self.view.get_columns() self._config.set("column_order_%s" % self.__class__.__name__, ",".join([x.get_title() for x in cols])) - + + def other_editor_changed(self, target_editor): + self.need_refresh = True class DstarMemoryEditor(MemoryEditor): def _get_cols_to_hide(self, iter): |
