diff options
author | Ben Konrath <ben@bagu.org> | 2009-12-16 16:49:24 -0500 |
---|---|---|
committer | Ben Konrath <ben@bagu.org> | 2009-12-16 16:51:48 -0500 |
commit | 9bf5db88303a247a8978cf4822bd3c47da80f6f1 (patch) | |
tree | b31eb7cc5b7b2823fbc0897f9400f541f7fe3734 | |
parent | 63bbc06229d61c6603730d21f61edfa6034acf6a (diff) | |
download | caribou-9bf5db88303a247a8978cf4822bd3c47da80f6f1.tar.gz |
Dynamically load keyboard definition files
-rw-r--r-- | src/caribou/keyboard.py | 10 | ||||
-rw-r--r-- | src/caribou/keyboards/__init__.py | 32 | ||||
-rw-r--r-- | src/caribou/window.py | 8 |
3 files changed, 46 insertions, 4 deletions
diff --git a/src/caribou/keyboard.py b/src/caribou/keyboard.py index 936b6f1..d1aafd5 100644 --- a/src/caribou/keyboard.py +++ b/src/caribou/keyboard.py @@ -22,7 +22,6 @@ import gtk import virtkey -from keyboards import qwerty class CaribouPredicitionArea(gtk.HBox): pass @@ -131,7 +130,14 @@ class CaribouKeyboard(gtk.Frame): if __name__ == "__main__": - ckbd = CaribouKeyboard(qwerty) + # dynamically import keyboard file + import keyboards, sys + name = "keyboards." + keyboards.kbds[0] + __import__(name) + kbddef = sys.modules[name] + + # create test window with keyboard + ckbd = CaribouKeyboard(kbddef) window = gtk.Window(gtk.WINDOW_POPUP) window.add(ckbd) window.show_all() diff --git a/src/caribou/keyboards/__init__.py b/src/caribou/keyboards/__init__.py index e69de29..7a83f59 100644 --- a/src/caribou/keyboards/__init__.py +++ b/src/caribou/keyboards/__init__.py @@ -0,0 +1,32 @@ +# +# Caribou - text entry and UI navigation application +# +# Copyright (C) 2009 Adaptive Technology Resource Centre +# * Contributor: Ben Konrath <ben@bagu.org> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by the +# Free Software Foundation; either version 2.1 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 Lesser General Public License +# for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +import os + +# TODO: will need to be changed when build / install logic is sorted out +files = os.listdir('caribou/keyboards') + +kbds = [] +for f in files: + if f != "keysyms.py" and f != "__init__.py" and f.endswith('.py'): + module = f.rsplit('.', 1)[0] + # TODO: verify keyboard before adding it to the list + kbds.append(module) +del os, files, f, module
\ No newline at end of file diff --git a/src/caribou/window.py b/src/caribou/window.py index d321034..a3171fd 100644 --- a/src/caribou/window.py +++ b/src/caribou/window.py @@ -22,10 +22,11 @@ import gtk import gtk.gdk as gdk import glib import keyboard -from keyboards import qwerty +import keyboards import gconf import animation import opacity +import sys class CaribouWindow(gtk.Window): __gtype_name__ = "CaribouWindow" @@ -38,7 +39,10 @@ class CaribouWindow(gtk.Window): self._vbox = gtk.VBox() self.add(self._vbox) - self._vbox.pack_start(keyboard.CaribouKeyboard(qwerty)) + name = "caribou.keyboards.qwerty" + __import__(name) + kbddef = sys.modules[name] + self._vbox.pack_start(keyboard.CaribouKeyboard(kbddef)) self.connect("size-allocate", lambda w, a: self._update_position()) self._gconf_client = gconf.client_get_default() |