summaryrefslogtreecommitdiff
path: root/caribou/ui/keyboard.py
diff options
context:
space:
mode:
authorDavid Pellicer <davidpellicermartin@gmail.com>2010-12-07 09:19:56 -0800
committerEitan Isaacson <eitan@monotonous.org>2010-12-07 09:20:23 -0800
commitc35d19ab7d43328c33e9b1916f8508df944c2fc3 (patch)
treef364c59fe88ee4b3a8c3c9e66831daf992d968ef /caribou/ui/keyboard.py
parent8d0fc8934626783e05f55a5c4235924faed9d1df (diff)
downloadcaribou-c35d19ab7d43328c33e9b1916f8508df944c2fc3.tar.gz
Added scanning support.
Diffstat (limited to 'caribou/ui/keyboard.py')
-rw-r--r--caribou/ui/keyboard.py241
1 files changed, 240 insertions, 1 deletions
diff --git a/caribou/ui/keyboard.py b/caribou/ui/keyboard.py
index ace93b0..e395af8 100644
--- a/caribou/ui/keyboard.py
+++ b/caribou/ui/keyboard.py
@@ -23,6 +23,7 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import caribou.common.const as const
+import caribou.ui.scan as scan
import gconf
import gobject
import gtk
@@ -31,6 +32,7 @@ import sys
import virtkey
import os
import traceback
+from caribou.ui.i18n import _
try:
import json
except ImportError:
@@ -119,6 +121,150 @@ class KeyboardPreferences:
self._on_default_font_toggled,
client, key_font_button)
+ reverse_scanning_checkbox = builder.get_object(
+ "reverse_scanning_checkbox")
+
+ reverse_scanning = client.get_bool(const.CARIBOU_GCONF +
+ "/reverse_scanning")
+ if reverse_scanning is None:
+ reverse_scanning is False
+ reverse_scanning_checkbox.set_active(reverse_scanning)
+ reverse_scanning_checkbox.connect('toggled',
+ self._on_reverse_scanning_toggled,
+ client)
+
+ block_scanning_color_button = builder.get_object("block_scanning_color_button")
+ block_scanning_color_string = client.get_string(const.CARIBOU_GCONF +
+ "/block_scanning_color") or "purple"
+ block_scanning_color = gtk.gdk.Color(block_scanning_color_string)
+ block_scanning_color_button.set_color(block_scanning_color)
+ block_scanning_color_button.connect("color-set",
+ self._on_block_scanning_color_set,
+ client)
+
+ row_scanning_color_button = builder.get_object("row_scanning_color_button")
+ row_scanning_color_string = client.get_string(const.CARIBOU_GCONF +
+ "/row_scanning_color") or "blue"
+ row_scanning_color = gtk.gdk.Color(row_scanning_color_string)
+ row_scanning_color_button.set_color(row_scanning_color)
+ row_scanning_color_button.connect("color-set",
+ self._on_row_scanning_color_set,
+ client)
+
+ button_scanning_color_button = builder.get_object("button_scanning_color_button")
+ button_scanning_color_string = client.get_string(const.CARIBOU_GCONF +
+ "/button_scanning_color") or "green"
+ button_scanning_color = gtk.gdk.Color(button_scanning_color_string)
+ button_scanning_color_button.set_color(button_scanning_color)
+ button_scanning_color_button.connect("color-set",
+ self._on_button_scanning_color_set,
+ client)
+
+ cancel_scanning_color_button = builder.get_object(
+ "cancel_scanning_color_button")
+ cancel_scanning_color_string = client.get_string(const.CARIBOU_GCONF +
+ "/cancel_scanning_color") or "red"
+ cancel_scanning_color = gtk.gdk.Color(cancel_scanning_color_string)
+ cancel_scanning_color_button.set_color(cancel_scanning_color)
+ cancel_scanning_color_button.connect("color-set",
+ self._on_cancel_scanning_color_set,
+ client)
+ scanning_type_combo = builder.get_object("scanning_type_combo")
+ scanning_type_combo.connect("changed",
+ self._on_scanning_type_combo_changed,
+ client)
+ types = [_("block"), _("row")]
+ for type in types:
+ scanning_type_combo.append_text(type)
+ type = client.get_string(const.CARIBOU_GCONF + "/scanning_type")
+ try:
+ scanning_type_combo.set_active(int(type))
+ except:
+ scanning_type_combo.set_active(0)
+
+
+ mouse_button_combo = builder.get_object("mouse_button_combo")
+ mouse_button_combo.connect("changed",
+ self._on_mouse_button_combo_changed,
+ client)
+ mouse_buttons = [_("Left"), _("Center"), _("Right")]
+ for button in mouse_buttons:
+ mouse_button_combo.append_text(button)
+ button = client.get_string(const.CARIBOU_GCONF + "/mouse_button")
+ try:
+ mouse_button_combo.set_active(int(button)-1)
+ except:
+ mouse_button_combo.set_active(0)
+
+
+ keyboard_key_combo = builder.get_object("keyboard_key_combo")
+ keyboard_keys = const.KEYBOARD_KEY_LIST.keys()
+ keyboard_values = const.KEYBOARD_KEY_LIST.values()
+ for key in keyboard_keys:
+ keyboard_key_combo.append_text(key)
+ key = client.get_string(const.CARIBOU_GCONF + "/keyboard_key")
+ try:
+ keyboard_key_combo.set_active(keyboard_values.index(key))
+ except:
+ keyboard_key_combo.set_active(0)
+
+ keyboard_key_combo.connect("changed",
+ self._on_keyboard_key_combo_changed,
+ client)
+
+ mouse_switch_radio = builder.get_object("mouse_switch_radio")
+ keyboard_switch_radio = builder.get_object("keyboard_switch_radio")
+ mouse_switch_radio.connect("toggled", self._on_switch_radio_toggled,
+ client, mouse_button_combo,
+ keyboard_key_combo)
+
+ switch_type = client.get_string(const.CARIBOU_GCONF + "/switch_type")
+ if switch_type == const.KEYBOARD_SWITCH_TYPE:
+ keyboard_switch_radio.set_active(True)
+ else:
+ mouse_switch_radio.set_active(True)
+
+ step_time_spin = builder.get_object("step_time_spin")
+ step_time_spin.set_value(client.get_int(const.CARIBOU_GCONF +
+ "/step_time"))
+ step_time_spin.connect("value_changed",
+ self._on_step_time_spin_changed, client)
+
+ scan_enabled_checkbox = builder.get_object("scan_enabled_checkbox")
+ scan_enabled = client.get_bool(const.CARIBOU_GCONF + "/scan_enabled")
+ if scan_enabled is None:
+ scan_enabled is False
+
+ scan_enabled_checkbox.set_active(scan_enabled)
+
+ self._on_scan_enabled_toggled(scan_enabled_checkbox,
+ client, reverse_scanning_checkbox,
+ row_scanning_color_button,
+ button_scanning_color_button,
+ block_scanning_color_button,
+ cancel_scanning_color_button,
+ mouse_switch_radio,
+ keyboard_switch_radio,
+ mouse_button_combo,
+ keyboard_key_combo,
+ scanning_type_combo,
+ step_time_spin)
+
+ scan_enabled_checkbox.connect('toggled',
+ self._on_scan_enabled_toggled, client,
+ reverse_scanning_checkbox,
+ row_scanning_color_button,
+ block_scanning_color_button,
+ button_scanning_color_button,
+ cancel_scanning_color_button,
+ mouse_switch_radio,
+ keyboard_switch_radio,
+ mouse_button_combo,
+ keyboard_key_combo,
+ scanning_type_combo,
+ step_time_spin)
+
+
kbds = self._fetch_keyboards()
for kbddef in kbds:
layout_combo.append_text(kbddef)
@@ -149,6 +295,36 @@ class KeyboardPreferences:
normal_color_button.set_sensitive(not use_defaults)
mouse_over_color_button.set_sensitive(not use_defaults)
+ def _on_scan_enabled_toggled(self, scan_enabled_checkbox,
+ gconf_client, *args):
+ scan_enabled = scan_enabled_checkbox.get_active()
+ gconf_client.set_bool(const.CARIBOU_GCONF + "/scan_enabled", scan_enabled)
+ for arg in args:
+ arg.set_sensitive(scan_enabled)
+
+ def _on_reverse_scanning_toggled(self, reverse_scanning_checkbox,
+ gconf_client):
+ reverse_scanning = reverse_scanning_checkbox.get_active()
+ gconf_client.set_bool(const.CARIBOU_GCONF + "/reverse_scanning",
+ reverse_scanning)
+ def _on_switch_radio_toggled(self, mouse_switch_radio,
+ gconf_client, mouse_button_combo,
+ keyboard_key_combo):
+ mouse_switch = mouse_switch_radio.get_active()
+ if mouse_switch:
+ gconf_client.set_string(const.CARIBOU_GCONF + "/switch_type",
+ const.MOUSE_SWITCH_TYPE)
+ else:
+ gconf_client.set_string(const.CARIBOU_GCONF + "/switch_type",
+ const.KEYBOARD_SWITCH_TYPE)
+ mouse_button_combo.set_sensitive(mouse_switch)
+ keyboard_key_combo.set_sensitive(not mouse_switch)
+
+ def _on_step_time_spin_changed(self, step_time_spin, gconf_client):
+ gconf_client.set_int(const.CARIBOU_GCONF + "/step_time",
+ step_time_spin.get_value_as_int())
+
+
def destroy(self, widget, data = None):
self.window.destroy()
@@ -167,13 +343,46 @@ class KeyboardPreferences:
def _on_layout_changed(self, combobox, client):
kbdname = combobox.get_active_text()
- if kbdname:
+ actual_layout = client.get_string("/apps/caribou/osk/layout")
+ if kbdname and kbdname != actual_layout:
client.set_string("/apps/caribou/osk/layout", kbdname)
+ def _on_scanning_type_combo_changed(self, scanning_type_combo, gconf_client):
+ value = str(scanning_type_combo.get_active())
+ if value:
+ gconf_client.set_string(const.CARIBOU_GCONF + "/scanning_type", value)
+
+ def _on_mouse_button_combo_changed(self, mouse_button_combo, client):
+ value = mouse_button_combo.get_active() + 1
+ if value:
+ client.set_string(const.CARIBOU_GCONF + "/mouse_button", str(value))
+
+ def _on_keyboard_key_combo_changed(self, keyboard_key_combo, client):
+ value = keyboard_key_combo.get_active_text()
+ if value:
+ client.set_string(const.CARIBOU_GCONF + "/keyboard_key",
+ const.KEYBOARD_KEY_LIST[value])
+
def _on_normal_state_color_set(self, colorbutton, client):
color = colorbutton.get_color().to_string()
client.set_string(const.CARIBOU_GCONF + "/normal_color", color)
+ def _on_block_scanning_color_set(self, colorbutton, client):
+ color = colorbutton.get_color().to_string()
+ client.set_string(const.CARIBOU_GCONF + "/block_scanning_color", color)
+
+ def _on_row_scanning_color_set(self, colorbutton, client):
+ color = colorbutton.get_color().to_string()
+ client.set_string(const.CARIBOU_GCONF + "/row_scanning_color", color)
+
+ def _on_button_scanning_color_set(self, colorbutton, client):
+ color = colorbutton.get_color().to_string()
+ client.set_string(const.CARIBOU_GCONF + "/button_scanning_color", color)
+
+ def _on_cancel_scanning_color_set(self, colorbutton, client):
+ color = colorbutton.get_color().to_string()
+ client.set_string(const.CARIBOU_GCONF + "/cancel_scanning_color", color)
+
def _on_mouse_over_color_set(self, colorbutton, client):
color = colorbutton.get_color().to_string()
client.set_string(const.CARIBOU_GCONF + "/mouse_over_color", color)
@@ -433,10 +642,14 @@ class CaribouKeyboard(gtk.Notebook):
self._gconf_connections.append(self.client.notify_add(
const.CARIBOU_GCONF + "/key_font",
self._key_font_changed))
+ self._gconf_connections.append(self.client.notify_add(
+ const.CARIBOU_GCONF + "/scan_enabled",
+ self._scan_enabled))
self.connect('size-allocate', self._on_size_allocate)
self.row_height = -1
+ self.scan_enabled = False
self.keyboard_preferences = KeyboardPreferences()
def reset_row_height(self):
@@ -466,6 +679,7 @@ class CaribouKeyboard(gtk.Notebook):
layouts = kb_deserializer.deserialize(kb_location)
self._set_layouts(layouts)
self._update_key_style()
+ self._enable_scanning()
def _set_layouts(self, layout_list):
self._clear()
@@ -486,6 +700,9 @@ class CaribouKeyboard(gtk.Notebook):
key.connect('clicked',
self._pressed_normal_key)
+ def _scan_enabled(self, client, connection_id, entry, args):
+ self._enable_scanning()
+
def _colors_changed(self, client, connection_id, entry, args):
self._update_key_style()
@@ -543,6 +760,8 @@ class CaribouKeyboard(gtk.Notebook):
def show_all(self):
self.set_current_page(self.current_page)
gtk.Notebook.show_all(self)
+ if self.scan_enabled:
+ self.scan_service.start()
def is_preferences_open(self):
if self.keyboard_preferences.window.window and \
@@ -554,7 +773,24 @@ class CaribouKeyboard(gtk.Notebook):
def _pressed_preferences_key(self, key):
self.keyboard_preferences.window.show_all()
+ def _enable_scanning(self):
+ enable = self.client.get_bool(const.CARIBOU_GCONF + '/scan_enabled')
+ if enable:
+ current_layout = self.get_nth_page(self.current_page)
+ if current_layout and not self.scan_enabled:
+ self.scan_service = scan.Scan_service(current_layout.rows,
+ self.get_parent().get_parent())
+ self.scan_enabled = True
+ elif self.scan_enabled:
+ self.scan_service.destroy()
+ self.scan_service = None
+ self.scan_enabled = False
+ else:
+ self.scan_enabled = False
+
def destroy(self):
+ if self.scan_enabled:
+ self.scan_service.destroy()
for id in self._gconf_connections:
self.client.notify_remove(id)
super(gtk.Notebook, self).destroy()
@@ -565,4 +801,7 @@ class CaribouKeyboard(gtk.Notebook):
if self.get_nth_page(i).layout_name == name:
self.set_current_page(i)
self.current_page = i
+ if self.scan_enabled:
+ self.scan_service.change_keyboard(
+ self.get_nth_page(i).rows)
break