[chirp_devel] [PATCH 0 of 2] Bank Editor tweaks (rev 2)
Per Tom's review on IRC, these two patches are tweaked as noted in their commit messages.
# HG changeset patch # User Dan Smith dsmith@danplanet.com # Date 1331685303 25200 # Node ID 5309412de3ac8705008bd3ea0ed01dc426382c37 # Parent 755a2706e13c23d3923e31896e766d4f24399aa0 Fix bank UI to make empty memories insensitive. This improves the visual nature, but also prevents the UI from asking the driver to add blank memories to a bank if the user accidentally clicks in one of the boxes.
Rev 2: Ignore clicks on insensitive checkboxes
diff -r 755a2706e13c -r 5309412de3ac chirpui/bankedit.py --- a/chirpui/bankedit.py Tue Mar 13 16:23:40 2012 -0700 +++ b/chirpui/bankedit.py Tue Mar 13 17:35:03 2012 -0700 @@ -137,9 +137,9 @@ ncols = len(self._cols) + len(self.banks) while iter: vals = self._store.get(iter, *tuple([n for n in range(0, ncols)])) - loc = vals[0] - index = vals[3] - banks = vals[4:] + loc = vals[self.C_LOC] + index = vals[self.C_INDEX] + banks = vals[self.C_BANKS:] if True in banks and banks.index(True) == bank: indexes.append(index) iter = self._store.iter_next(iter) @@ -154,9 +154,12 @@ return 0 # If the bank is full, just wrap around!
def _toggled_cb(self, rend, path, colnum): + if not rend.get_sensitive(): + return + # The bank index is the column number, minus the 3 label columns bank, name = self.banks[colnum - len(self._cols)] - loc, = self._store.get(self._store.get_iter(path), 0) + loc, = self._store.get(self._store.get_iter(path), self.C_LOC)
if rend.get_active(): # Changing from True to False @@ -201,7 +204,7 @@ self.rthread.submit(job)
def _index_edited_cb(self, rend, path, new): - loc, = self._store.get(self._store.get_iter(path), 0) + loc, = self._store.get(self._store.get_iter(path), self.C_LOC)
def refresh_memory(*args): self.refresh_memory(loc) @@ -234,12 +237,23 @@ self.rthread = rthread self._rf = rthread.radio.get_features()
- self._cols = [ + self._view_cols = [ (_("Loc"), TYPE_INT, gtk.CellRendererText, ), (_("Frequency"), TYPE_STRING, gtk.CellRendererText, ), (_("Name"), TYPE_STRING, gtk.CellRendererText, ), (_("Index"), TYPE_INT, gtk.CellRendererText, ), ] + + self._cols = [ + ("_filled", TYPE_BOOLEAN, None, ), + ] + self._view_cols + + self.C_FILLED = 0 + self.C_LOC = 1 + self.C_FREQ = 2 + self.C_NAME = 3 + self.C_INDEX = 4 + self.C_BANKS = 5 # and beyond
cols = list(self._cols)
@@ -254,13 +268,18 @@
colnum = 0 for label, dtype, rtype in cols: + if not rtype: + colnum += 1 + continue rend = rtype() if dtype == TYPE_BOOLEAN: rend.set_property("activatable", True) rend.connect("toggled", self._toggled_cb, colnum) - col = gtk.TreeViewColumn(label, rend, active=colnum) + col = gtk.TreeViewColumn(label, rend, active=colnum, + sensitive=self.C_FILLED) else: - col = gtk.TreeViewColumn(label, rend, text=colnum) + col = gtk.TreeViewColumn(label, rend, text=colnum, + sensitive=self.C_FILLED)
self._view.append_column(col) if colnum == 2: @@ -278,7 +297,12 @@
for i in range(*self._rf.memory_bounds): iter = self._store.append() - self._store.set(iter, 0, i, 1, 0, 2, "", 3, 0) + self._store.set(iter, + self.C_FILLED, False, + self.C_LOC, i, + self.C_FREQ, 0, + self.C_NAME, "", + self.C_INDEX, 0)
self.root = sw self._loaded = False @@ -286,11 +310,12 @@ def refresh_memory(self, number): def got_mem(memory, banks, indexes): iter = self._store.get_iter(self._number_to_path(memory.number)) - row = [0, memory.number, - 1, chirp_common.format_freq(memory.freq), - 2, memory.name, + row = [self.C_FILLED, not memory.empty, + self.C_LOC, memory.number, + self.C_FREQ, chirp_common.format_freq(memory.freq), + self.C_NAME, memory.name, # Hack for only one index right now - 3, indexes and indexes[0] or 0, + self.C_INDEX, indexes and indexes[0] or 0, ] for i in range(0, len(self.banks)): row.append(i + len(self._cols)) @@ -309,8 +334,9 @@
def refresh_banks(self, and_memories=False): def got_banks(): - for i in range(0, len(self.banks)): - col = self._view.get_column(i + len(self._cols)) + for i in range(len(self._cols) - len(self._view_cols), + len(self.banks)): + col = self._view.get_column(i + len(self._view_cols)) bank, name = self.banks[i] if name: col.set_title(name)
# HG changeset patch # User Dan Smith dsmith@danplanet.com # Date 1331685304 25200 # Node ID 4df6f2246d71dac29ff00e7f92a080002e0d9394 # Parent 5309412de3ac8705008bd3ea0ed01dc426382c37 Report failure to add a memory to a bank to the user
Rev 2: Make the error dialog transient for the owning window so that it's modal
diff -r 5309412de3ac -r 4df6f2246d71 chirpui/bankedit.py --- a/chirpui/bankedit.py Tue Mar 13 17:35:03 2012 -0700 +++ b/chirpui/bankedit.py Tue Mar 13 17:35:04 2012 -0700 @@ -177,7 +177,13 @@ # Step 2: Update our notion of the memory's bank information self.refresh_memory(loc)
- def do_bank_index(_null, memory): + def do_bank_index(result, memory): + if isinstance(result, Exception): + common.show_error("Failed to add {mem} to bank: {err}" + .format(mem=memory.number, + err=str(result)), + parent=self.editorset.parent_window) + return # Step 3: Set the memory's bank index (maybe) if not self._rf.has_bank_index or index is None: return do_refresh_memory() @@ -232,9 +238,10 @@ job.set_desc(_("Getting memory {num}").format(num=loc)) self.rthread.submit(job)
- def __init__(self, rthread): + def __init__(self, rthread, editorset): common.Editor.__init__(self) self.rthread = rthread + self.editorset = editorset self._rf = rthread.radio.get_features()
self._view_cols = [ diff -r 5309412de3ac -r 4df6f2246d71 chirpui/editorset.py --- a/chirpui/editorset.py Tue Mar 13 17:35:03 2012 -0700 +++ b/chirpui/editorset.py Tue Mar 13 17:35:04 2012 -0700 @@ -79,7 +79,7 @@
if rf.has_bank: self.editors["bank_members"] = \ - bankedit.BankMembershipEditor(self.rthread) + bankedit.BankMembershipEditor(self.rthread, self)
if rf.has_bank_names: self.editors["bank_names"] = bankedit.BankNameEditor(self.rthread)
participants (1)
-
Dan Smith