[chirp_devel] [PATCH 2 of 3] Add basic UI elements for modifications
Dan Smith
Wed Apr 6 09:19:55 PDT 2011
# HG changeset patch
# User Dan Smith <dsmith at danplanet.com>
# Date 1302106729 25200
# Node ID f51cc15cd52dfce7a958af5b1708178e7c73adcb
# Parent 3d3a44d2309b969e24571e436eb5b7b706095500
Add basic UI elements for modifications
diff -r 3d3a44d2309b -r f51cc15cd52d chirpui/editorset.py
--- a/chirpui/editorset.py Wed Apr 06 09:12:24 2011 -0700
+++ b/chirpui/editorset.py Wed Apr 06 09:18:49 2011 -0700
@@ -21,7 +21,7 @@
from chirp import chirp_common, directory, csv, xml
from chirpui import memedit, dstaredit, bankedit, common, importdialog
-from chirpui import inputdialog
+from chirpui import inputdialog, modedit
class EditorSet(gtk.VBox):
__gsignals__ = {
@@ -69,6 +69,11 @@
else:
self.banked = None
+ if self.radio.get_features().has_mods:
+ self.moded = modedit.ModEditor(self.rthread)
+ else:
+ self.moded = None
+
lab = gtk.Label("Memories")
self.tabs.append_page(self.memedit.root, lab)
self.memedit.root.show()
@@ -85,6 +90,12 @@
self.banked.root.show()
self.banked.connect("changed", self.banks_changed)
+ if self.moded:
+ lab = gtk.Label("Mods")
+ self.tabs.append_page(self.moded.root, lab)
+ self.moded.root.show()
+ #self.moded.connect("changed", self.mods_changed)
+
self.pack_start(self.tabs)
self.tabs.show()
@@ -275,8 +286,9 @@
def tab_selected(self, notebook, foo, pagenum):
# Quick hack for D-STAR editor
- if pagenum == 1:
- self.dstared.focus()
+ #if pagenum == 1:
+ # self.dstared.focus()
+ pass
def set_read_only(self, read_only=True):
self.memedit.set_read_only(read_only)
diff -r 3d3a44d2309b -r f51cc15cd52d chirpui/modedit.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/chirpui/modedit.py Wed Apr 06 09:18:49 2011 -0700
@@ -0,0 +1,115 @@
+#!/usr/bin/python
+#
+# Copyright 2010 Dan Smith <dsmith at danplanet.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import gtk
+import gobject
+
+from chirp import chirp_common
+from chirpui import common, miscwidgets
+
+def enforce_format(entry, new, length, pos, format):
+ formats = {
+ "X" : "0123456789ABCDEF",
+ "i" : "0123456789",
+ }
+
+ for i in new:
+ if i.upper() not in formats[format]:
+ entry.stop_emission("insert-text")
+
+class ModificationEditor:
+ def __init__(self, radio, mod):
+ self._radio = radio
+ self._mod = mod
+
+ def build_ui(self):
+ pass
+
+ def _build_label(self):
+ l = gtk.Label(self._mod.get_name())
+ l.show()
+ return l
+
+ def _set_mod(self, button):
+ self._mod.set_new_value(self._get_value())
+ self._radio.set_mod(self._mod)
+
+ def _build_set(self):
+ b = gtk.Button("Set")
+ b.connect("clicked", self._set_mod)
+ b.show()
+ return b
+
+class OptionModificationEditor(ModificationEditor):
+ def _get_value(self):
+ return self.__c.get_active_text()
+
+ def build_ui(self):
+ self.__c = miscwidgets.make_choice(self._mod.get_options(),
+ False, self._mod.get_current_value())
+ self.__c.show()
+
+ return self._build_label(), self.__c, self._build_set()
+
+class IntegerModificationEditor(ModificationEditor):
+ def _get_value(self):
+ base = {
+ "X" : 16,
+ "i" : 10,
+ }
+
+ return int(self.__n.get_text(),
+ base[self._mod.get_display_format()[-1]])
+
+ def build_ui(self):
+ self.__n = gtk.Entry()
+ self.__n.connect("insert-text", enforce_format,
+ self._mod.get_display_format()[-1])
+ v = self._mod.get_display_format() % self._mod.get_current_value()
+ self.__n.set_text(v)
+ self.__n.show()
+
+ return self._build_label(), self.__n, self._build_set()
+
+class ModEditor(common.Editor):
+ def __init__(self, rthread):
+ common.Editor.__init__(self)
+ self.rthread = rthread
+
+ self.root = gtk.Table(5, 3)
+
+ xopts = gtk.FILL
+ yopts = 0
+
+ row = 0
+ for mod in rthread.radio.get_mods():
+ if isinstance(mod, chirp_common.RadioModOpt):
+ e = OptionModificationEditor(self.rthread.radio, mod)
+ elif isinstance(mod, chirp_common.RadioModInt):
+ e = IntegerModificationEditor(self.rthread.radio, mod)
+ else:
+ continue
+
+ col = 0
+ for widget in e.build_ui():
+ self.root.attach(widget, col, col+1, row, row+1,
+ xopts, yopts, 3, 1)
+ col += 1
+ row += 1
+
+ def focus(self):
+ pass
More information about the chirp_devel
mailing list