diff options
author | Eitan Isaacson <eitan@monotonous.org> | 2011-05-28 13:13:10 -0700 |
---|---|---|
committer | Eitan Isaacson <eitan@monotonous.org> | 2011-05-28 13:14:43 -0700 |
commit | 09f4e8eaecafe477007540416da88de0069df5aa (patch) | |
tree | 2c2811c1f4bfce61b93e16f91f9a3e3ec1ee81a0 | |
parent | 62936ea71642189a6f9694aa4a248d24321852e6 (diff) | |
download | caribou-09f4e8eaecafe477007540416da88de0069df5aa.tar.gz |
Add scanning support in antler.
-rw-r--r-- | caribou/antler/keyboard_view.py | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/caribou/antler/keyboard_view.py b/caribou/antler/keyboard_view.py index e7c0fd8..1192300 100644 --- a/caribou/antler/keyboard_view.py +++ b/caribou/antler/keyboard_view.py @@ -42,6 +42,25 @@ class AntlerKey(Gtk.Button): if key.get_extended_keys (): self._sublevel = AntlerSubLevel(self) + self._key_pressed_handler = key.connect( + 'key-pressed', + lambda x: self.set_state_flags(Gtk.StateFlags.ACTIVE, False)) + self._key_released_handler = key.connect( + 'key-released', + lambda x: self.unset_state_flags(Gtk.StateFlags.ACTIVE)) + + def set_dwell_scan(self, dwell): + if dwell: + self.set_state_flags(Gtk.StateFlags.SELECTED, False) + else: + self.unset_state_flags(Gtk.StateFlags.SELECTED) + + def set_group_scan_active(self, active): + if active: + self.set_state_flags(Gtk.StateFlags.INCONSISTENT, False) + else: + self.unset_state_flags(Gtk.StateFlags.INCONSISTENT) + def _on_prefs_clicked(self, key): p = PreferencesDialog(AntlerSettings()) p.populate_settings(CaribouSettings()) @@ -63,10 +82,14 @@ class AntlerKey(Gtk.Button): return "<b>%s</b>" % glib.markup_escape_text(label.encode('utf-8')) def _on_pressed(self, button): + self.caribou_key.handler_block(self._key_pressed_handler) self.caribou_key.press() + self.caribou_key.handler_unblock(self._key_pressed_handler) def _on_released(self, button): + self.caribou_key.handler_block(self._key_released_handler) self.caribou_key.release() + self.caribou_key.handler_unblock(self._key_released_handler) def do_get_preferred_width_for_height(self, w): return (w, w) @@ -120,6 +143,9 @@ class AntlerLayout(Gtk.HBox): if level: self.load_rows(level.get_rows ()) + level.connect("selected-item-changed", self._on_active_group_changed) + level.connect("step-item-changed", self._on_dwelling_group_changed) + level.connect("scan-cleared", self._on_scan_cleared) def add_column (self): col = Gtk.Grid() @@ -131,6 +157,40 @@ class AntlerLayout(Gtk.HBox): self._columns.append(col) return col + def _on_scan_cleared (self, level): + for key in self._active_scan_group: + self._keys_map[key].set_group_scan_active(False) + + self._active_scan_group = [] + + for key in self._dwelling_scan_group: + self._keys_map[key].set_dwell_scan(False) + + self._dwelling_scan_group = [] + + def _on_active_group_changed(self, level, active_item): + for key in self._active_scan_group: + self._keys_map[key].set_group_scan_active(False) + + if isinstance(active_item, Caribou.KeyModel): + self._active_scan_group = [active_item] + else: + self._active_scan_group = active_item.get_keys() + + for key in self._active_scan_group: + self._keys_map[key].set_group_scan_active(True) + + def _on_dwelling_group_changed(self, level, dwell_item): + for key in self._dwelling_scan_group: + self._keys_map[key].set_dwell_scan(False) + + if isinstance(dwell_item, Caribou.KeyModel): + self._dwelling_scan_group = [dwell_item] + else: + self._dwelling_scan_group = dwell_item.get_keys() + + for key in self._dwelling_scan_group: + self._keys_map[key].set_dwell_scan(True) def add_row(self, row, row_num=0): x = 0 @@ -151,16 +211,26 @@ class AntlerLayout(Gtk.HBox): int(self.KEY_SPAN * key.props.width), self.KEY_SPAN) x += int((key.props.width + key.props.margin_left ) * self.KEY_SPAN) - + def load_rows(self, rows): for row_num, row in enumerate(rows): self.add_row([c.get_keys() for c in row.get_columns()], row_num) + def _on_scan_state_changed(self, row, prop, antler_keys): + if prop.name == "scan-dwelling": + for key in antler_keys: + key.set_dwell_scan(row.props.scan_dwelling) + elif prop.name == "scan-active": + for key in antler_keys: + key.set_group_scan_active(row.props.scan_active) + class AntlerKeyboardView(Gtk.Notebook): def __init__(self): gobject.GObject.__init__(self) self.set_show_tabs(False) self.keyboard_model = Caribou.KeyboardModel() + self.scanner = Caribou.Scanner() + self.scanner.set_keyboard(self.keyboard_model) self.keyboard_model.connect("notify::active-group", self._on_group_changed) self.layers = {} |