121 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			121 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
#!/usr/bin/env python
 | 
						|
 | 
						|
# Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
 | 
						|
# Copyright (C) 2011 Red Hat, Inc.
 | 
						|
 | 
						|
# This library 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 of
 | 
						|
# the License, or (at your option) any later version.
 | 
						|
 | 
						|
# This library 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 library; if not, write to the Free Software
 | 
						|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 | 
						|
# 02110-1301 USA
 | 
						|
 | 
						|
import eekboard, virtkey
 | 
						|
 | 
						|
GROUPS = (
 | 
						|
    "as-inscript2",
 | 
						|
    "bn-inscript2",
 | 
						|
    "brx-inscript2-deva",
 | 
						|
    "doi-inscript2-deva",
 | 
						|
    "gu-inscript2",
 | 
						|
    "hi-inscript2",
 | 
						|
    "kn-inscript2",
 | 
						|
    "kok-inscript2-deva",
 | 
						|
    "mai-inscript2",
 | 
						|
    "ml-inscript2",
 | 
						|
    "mni-inscript2-beng",
 | 
						|
    "mni-inscript2-mtei",
 | 
						|
    "mr-inscript2",
 | 
						|
    "ne-inscript2-deva",
 | 
						|
    "or-inscript2",
 | 
						|
    "pa-inscript2-guru",
 | 
						|
    "sa-inscript2",
 | 
						|
    "sat-inscript2-deva",
 | 
						|
    "sat-inscript2-olck",
 | 
						|
    "sd-inscript2-deva",
 | 
						|
    "ta-inscript2",
 | 
						|
    "te-inscript2")
 | 
						|
 | 
						|
class InscriptKeyboard(object):
 | 
						|
    def __init__(self, client_name, path):
 | 
						|
        self.__keyboard = eekboard.XmlKeyboard(path,
 | 
						|
                                               eekboard.MODIFIER_BEHAVIOR_LATCH)
 | 
						|
        self.__eekboard = eekboard.Eekboard()
 | 
						|
        self.__context = self.__eekboard.create_context(client_name)
 | 
						|
        keyboard_id = self.__context.add_keyboard(self.__keyboard)
 | 
						|
        self.__context.set_keyboard(keyboard_id)
 | 
						|
        self.__keyboard.connect('key-pressed', self.__key_pressed_cb)
 | 
						|
        self.__keyboard.connect('key-released', self.__key_released_cb)
 | 
						|
        self.__virtkey = virtkey.virtkey()
 | 
						|
        self.__english = False
 | 
						|
 | 
						|
    def enable(self):
 | 
						|
        self.__eekboard.push_context(self.__context)
 | 
						|
 | 
						|
    def disable(self):
 | 
						|
        self.__eekboard.pop_context(self.__context)
 | 
						|
 | 
						|
    def show(self):
 | 
						|
        self.__context.show_keyboard()
 | 
						|
 | 
						|
    def set_group(self, group):
 | 
						|
        self.__group = group
 | 
						|
        self.__context.set_group(self.__group)
 | 
						|
 | 
						|
    def __key_pressed_cb(self, keyboard, key):
 | 
						|
        if key.get_keycode() == 37:
 | 
						|
            return
 | 
						|
        symbol = key.get_symbol()
 | 
						|
        if isinstance(symbol, eekboard.Keysym):
 | 
						|
            xkeysym = symbol.get_xkeysym()
 | 
						|
            self.__virtkey.press_keysym(xkeysym)
 | 
						|
 | 
						|
    def __key_released_cb(self, keyboard, key):
 | 
						|
        if key.get_keycode() == 37:
 | 
						|
            if self.__english:
 | 
						|
                self.__context.set_group(self.__group)
 | 
						|
                self.__english = False
 | 
						|
            else:
 | 
						|
                self.__context.set_group(0)
 | 
						|
                self.__english = True
 | 
						|
            return
 | 
						|
        symbol = key.get_symbol()
 | 
						|
        if isinstance(symbol, eekboard.Keysym):
 | 
						|
            xkeysym = symbol.get_xkeysym()
 | 
						|
            self.__virtkey.release_keysym(xkeysym)
 | 
						|
 | 
						|
if __name__ == "__main__":
 | 
						|
    import gtk
 | 
						|
    from optparse import OptionParser
 | 
						|
    import sys
 | 
						|
 | 
						|
    parser = OptionParser()
 | 
						|
    parser.add_option("-n", "--name=LANGCODE", dest="langcode",
 | 
						|
                      help="Specify language code to LANGCODE",
 | 
						|
                      metavar="LANGCODE")
 | 
						|
    (options, args) = parser.parse_args()
 | 
						|
    group = 1
 | 
						|
    if options.langcode:
 | 
						|
        group = None
 | 
						|
        for index, langcode in enumerate(GROUPS):
 | 
						|
            if langcode.startswith(options.langcode):
 | 
						|
                group = index + 1
 | 
						|
                break
 | 
						|
        if group is None:
 | 
						|
            print >> sys.stderr, "Unknown langcode %s" % options.langcode
 | 
						|
            exit(1)
 | 
						|
 | 
						|
    inscript = InscriptKeyboard("eekboard-inscript", "@EEKBOARD_INSCRIPT_PATH@")
 | 
						|
    inscript.set_group(group)
 | 
						|
    inscript.enable()
 | 
						|
    inscript.show()
 | 
						|
    gtk.main()
 |