Mercurial > code > home > repos > light9
changeset 379:546e01adad37
keyboardcomposer: better bumping, save row, bug fixen
redo pickle format to save row (WARNING: you'll need to delete saved levels file)
bumping: force lights to be off
set slider levels on start up
author | David McClosky <dmcc@bigasterisk.com> |
---|---|
date | Fri, 15 Jun 2007 21:23:53 +0000 |
parents | a4c294b8c9c2 |
children | a13f2caf6f25 |
files | bin/keyboardcomposer |
diffstat | 1 files changed, 18 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/bin/keyboardcomposer Fri Jun 15 21:07:04 2007 +0000 +++ b/bin/keyboardcomposer Fri Jun 15 21:23:53 2007 +0000 @@ -74,11 +74,12 @@ self.submasters = submasters self.name_to_subtk = {} self.current_sub_levels = {} + self.current_row = 0 if current_sub_levels is not None: self.current_sub_levels = current_sub_levels else: try: - self.current_sub_levels = \ + self.current_sub_levels, self.current_row = \ pickle.load(file('.keyboardcomposer.savedlevels')) except IOError: pass @@ -92,11 +93,10 @@ self.slider_vars = {} # this holds subname:sub Tk vars self.slider_table = {} # this holds coords:sub Tk vars self.name_to_subtk.clear() # subname : SubmasterTk instance - self.current_row = 0 self.make_key_hints() self.draw_sliders() - self.highlight_row(self.current_row) + self.change_row(self.current_row) self.rows[self.current_row].focus() self.buttonframe = Frame(self, bg='black') @@ -160,14 +160,16 @@ # Page up, C-p, and ' do up for key in '<Prior> <Next> <Control-n> <Control-p> ' \ '<Key-bracketright> <Key-apostrophe>'.split(): - tkobject.bind(key, self.change_row) + tkobject.bind(key, self.change_row_cb) - def change_row(self, event): + def change_row_cb(self, event): diff = 1 if event.keysym in ('Prior', 'p', 'bracketright'): diff = -1 + self.change_row(self.current_row + diff) + def change_row(self, row): old_row = self.current_row - self.current_row += diff + self.current_row = row self.current_row = max(0, self.current_row) self.current_row = min(len(self.rows) - 1, self.current_row) self.unhighlight_row(old_row) @@ -296,7 +298,7 @@ sub.save() def save(self): - pickle.dump(self.get_levels(), + pickle.dump((self.get_levels(), self.current_row), file('.keyboardcomposer.savedlevels', 'w')) def send_frequent_updates(self): """called when we get a fade -- send events as quickly as possible""" @@ -307,13 +309,15 @@ def refresh(self): self.save() self.submasters = Submasters() - self.current_sub_levels = \ + self.current_sub_levels, self.current_row = \ pickle.load(file('.keyboardcomposer.savedlevels')) for r in self.rows: r.destroy() self.keyhints.destroy() self.buttonframe.destroy() self.draw_ui() + # possibly paranoia (but possibly not) + self.change_row(self.current_row) def alltozero(self): for name, subtk in self.name_to_subtk.items(): @@ -343,7 +347,12 @@ kc.hw_slider_moved(int(name[6:]) - 1, value / 127) elif name.startswith("button-lower"): col = int(name[12:]) - 1 - tkslider = kc.slider_table[(kc.current_row, col)] + self.valueOut(name, 0) + try: + tkslider = kc.slider_table[(kc.current_row, col)] + except KeyError: + return + slider_var = tkslider.slider_var if slider_var.get() == 1: slider_var.set(0)