diff options
author | Daniel Narvaez <dwnarvaez@gmail.com> | 2012-12-10 16:46:18 (GMT) |
---|---|---|
committer | Simon Schampijer <simon@laptop.org> | 2013-01-22 09:29:36 (GMT) |
commit | 891b21f66caf24d3f2bda75893f0e6fb4577249b (patch) | |
tree | ec8b0bdd4f8a06b5450de1ef45693f408a1463e6 | |
parent | 0e45f9d52d216830f3d09cfbb278a38a1050c54a (diff) |
Split keyboard setup out of main.py
main.py is big and messy and the setup method is complex enough
to be worth it's own module.
Acked-by: Simon Schampijer <simon@laptop.org>
-rwxr-xr-x | src/jarabe/main.py | 68 | ||||
-rw-r--r-- | src/jarabe/model/Makefile.am | 1 | ||||
-rwxr-xr-x | src/jarabe/model/keyboard.py | 85 |
3 files changed, 88 insertions, 66 deletions
diff --git a/src/jarabe/main.py b/src/jarabe/main.py index 77b8841..55d0496 100755 --- a/src/jarabe/main.py +++ b/src/jarabe/main.py @@ -38,19 +38,11 @@ from gi.repository import GLib from gi.repository import GConf from gi.repository import Gtk from gi.repository import Gdk -from gi.repository import GdkX11 from gi.repository import GObject from gi.repository import Gst import dbus.glib from gi.repository import Wnck -_USE_XKL = False -try: - from gi.repository import Xkl - _USE_XKL = True -except ImportError: - logging.debug('Could not load xklavier for keyboard configuration') - GLib.threads_init() Gdk.threads_init() dbus.glib.threads_init() @@ -116,62 +108,6 @@ def setup_file_transfer_cb(): from jarabe.model import filetransfer filetransfer.init() -def setup_keyboard_cb(): - logging.debug('STARTUP: setup_keyboard_cb') - - gconf_client = GConf.Client.get_default() - have_config = False - - try: - display = GdkX11.x11_get_default_xdisplay() - if display is not None: - engine = Xkl.Engine.get_instance(display) - else: - logging.debug('setup_keyboard_cb: Could not get default display.') - return - - configrec = Xkl.ConfigRec() - configrec.get_from_server(engine) - - # FIXME, gconf_client_get_list not introspectable #681433 - layouts_from_gconf = gconf_client.get( - '/desktop/sugar/peripherals/keyboard/layouts') - layouts_list = [] - variants_list = [] - if layouts_from_gconf: - for gval in layouts_from_gconf.get_list(): - layout = gval.get_string() - layouts_list.append(layout.split('(')[0]) - variants_list.append(layout.split('(')[1][:-1]) - - if layouts_list and variants_list: - have_config = True - configrec.set_layouts(layouts_list) - configrec.set_variants(variants_list) - - model = gconf_client.get_string(\ - '/desktop/sugar/peripherals/keyboard/model') - if model: - have_config = True - configrec.set_model(model) - - options = [] - # FIXME, gconf_client_get_list not introspectable #681433 - options_from_gconf = gconf_client.get(\ - '/desktop/sugar/peripherals/keyboard/options') - if options_from_gconf: - for gval in options_from_gconf.get_list(): - option = gval.get_string() - options.append(option) - if options: - have_config = True - configrec.set_options(options) - - if have_config: - configrec.activate(engine) - except Exception: - logging.exception('Error during keyboard configuration') - def setup_window_manager(): logging.debug('STARTUP: window_manager') @@ -201,8 +137,8 @@ def bootstrap(): GObject.idle_add(setup_file_transfer_cb) GObject.idle_add(show_software_updates_cb) - if _USE_XKL: - GObject.idle_add(setup_keyboard_cb) + from jarabe.model import keyboard + keyboard.setup() def set_fonts(): client = GConf.Client.get_default() diff --git a/src/jarabe/model/Makefile.am b/src/jarabe/model/Makefile.am index 2fc6b1c..8e2da6a 100644 --- a/src/jarabe/model/Makefile.am +++ b/src/jarabe/model/Makefile.am @@ -7,6 +7,7 @@ sugar_PYTHON = \ filetransfer.py \ friends.py \ invites.py \ + keyboard.py \ olpcmesh.py \ mimeregistry.py \ neighborhood.py \ diff --git a/src/jarabe/model/keyboard.py b/src/jarabe/model/keyboard.py new file mode 100755 index 0000000..43b16c2 --- /dev/null +++ b/src/jarabe/model/keyboard.py @@ -0,0 +1,85 @@ +# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2009, One Laptop Per Child Association Inc +# +# 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 2 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, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import logging + +from gi.repository import GConf +from gi.repository import GdkX11 + +_USE_XKL = False +try: + from gi.repository import Xkl + _USE_XKL = True +except ImportError: + logging.debug('Could not load xklavier for keyboard configuration') + +def setup(): + if not _USE_XKL: + return + + gconf_client = GConf.Client.get_default() + have_config = False + + try: + display = GdkX11.x11_get_default_xdisplay() + if display is not None: + engine = Xkl.Engine.get_instance(display) + else: + logging.debug('setup_keyboard_cb: Could not get default display.') + return + + configrec = Xkl.ConfigRec() + configrec.get_from_server(engine) + + # FIXME, gconf_client_get_list not introspectable #681433 + layouts_from_gconf = gconf_client.get( + '/desktop/sugar/peripherals/keyboard/layouts') + layouts_list = [] + variants_list = [] + if layouts_from_gconf: + for gval in layouts_from_gconf.get_list(): + layout = gval.get_string() + layouts_list.append(layout.split('(')[0]) + variants_list.append(layout.split('(')[1][:-1]) + + if layouts_list and variants_list: + have_config = True + configrec.set_layouts(layouts_list) + configrec.set_variants(variants_list) + + model = gconf_client.get_string(\ + '/desktop/sugar/peripherals/keyboard/model') + if model: + have_config = True + configrec.set_model(model) + + options = [] + # FIXME, gconf_client_get_list not introspectable #681433 + options_from_gconf = gconf_client.get(\ + '/desktop/sugar/peripherals/keyboard/options') + if options_from_gconf: + for gval in options_from_gconf.get_list(): + option = gval.get_string() + options.append(option) + if options: + have_config = True + configrec.set_options(options) + + if have_config: + configrec.activate(engine) + except Exception: + logging.exception('Error during keyboard configuration') |