[chirp_devel] [PATCH] [RFC] Offset calculator
Dan Smith
Wed May 23 11:40:27 PDT 2012
# HG changeset patch
# User Dan Smith <dsmith at danplanet.com>
# Date 1337798425 25200
# Node ID de06d87191f171bd87cdd9d04693e0fdcd960728
# Parent 51a0d9490ced8d3b24ec13a0ed572233185c3560
[RFC] Offset calculator
This allows users of radios with only an offset field to calculate the
required offset from a given TX frequency. This is accessed by right-
clicking on the memory and choosing "Calculate Offset...". Probably need
some better verbiage, but this shows the functionality enough for
comments.
diff -r 51a0d9490ced -r de06d87191f1 chirpui/memedit.py
--- a/chirpui/memedit.py Tue May 22 16:41:27 2012 -0700
+++ b/chirpui/memedit.py Wed May 23 11:40:25 2012 -0700
@@ -58,6 +58,34 @@
return None
return store.get_iter((row - 1,))
+def prompt_for_tx_frequency(txfreq):
+ d = gtk.Dialog(title=_("Offset"),
+ buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
+ gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
+
+ l = gtk.Label(_("Desired TX frequency:"))
+ l.show()
+ d.vbox.pack_start(l, 0, 0, 0)
+
+ f = gtk.Entry()
+ f.set_text(chirp_common.format_freq(txfreq))
+ f.show()
+ d.vbox.pack_start(f, 0, 0, 0)
+
+ freq = None
+ while True:
+ r = d.run()
+ if r != gtk.RESPONSE_OK:
+ break
+ try:
+ freq = chirp_common.parse_freq(f.get_text())
+ break
+ except ValueError:
+ pass
+
+ d.destroy()
+ return freq
+
class MemoryEditor(common.Editor):
cols = [
(_("Loc") , TYPE_INT, gtk.CellRendererText, ),
@@ -624,6 +652,28 @@
self.emit("changed")
dlg.destroy()
+ def _calc_offset(self, iter):
+ mem = self._get_memory(iter)
+ rxfreq = mem.freq
+ if mem.duplex:
+ txfreq = mem.freq + (int("%s1" % mem.duplex) * mem.offset)
+ else:
+ txfreq = mem.freq
+ txfreq = prompt_for_tx_frequency(txfreq)
+ if txfreq is None:
+ return
+
+ if rxfreq == txfreq:
+ mem.duplex = ""
+ mem.offset = 0
+ else:
+ mem.duplex = txfreq < rxfreq and "-" or "+"
+ mem.offset = abs(txfreq - rxfreq)
+
+ self._set_memory(iter, mem)
+ job = common.RadioJob(None, "set_memory", mem)
+ self.rthread.submit(job)
+
def mh(self, _action, store, paths):
action = _action.get_name()
iter = store.get_iter(paths[0])
@@ -663,7 +713,8 @@
elif action == "edit":
job = common.RadioJob(self.edit_memory, "get_memory", cur_pos)
self.rthread.submit(job)
-
+ elif action == "calcoffset":
+ self._calc_offset(iter)
if changed:
self.emit("changed")
@@ -688,6 +739,7 @@
<ui>
<popup name="Menu">
<menuitem action="edit"/>
+ <menuitem action="calcoffset"/>
<menuitem action="insert_prev"/>
<menuitem action="insert_next"/>
<menuitem action="delete"/>
@@ -711,6 +763,7 @@
actions = [
("edit", _("Edit")),
+ ("calcoffset", _("Calculate offset for TX frequency")),
("insert_prev", _("Insert row above")),
("insert_next", _("Insert row below")),
("delete", issingle and _("Delete") or _("Delete all")),
More information about the chirp_devel
mailing list