Add Python binding.
This commit is contained in:
@ -16,8 +16,12 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
# 02110-1301 USA
|
||||
|
||||
if ENABLE_VALA
|
||||
SUBDIRS = vala
|
||||
else
|
||||
SUBDIRS =
|
||||
|
||||
if ENABLE_PYTHON
|
||||
SUBDIRS += python
|
||||
endif
|
||||
|
||||
if ENABLE_VALA
|
||||
SUBDIRS += vala
|
||||
endif
|
||||
|
||||
18
bindings/python/Makefile.am
Normal file
18
bindings/python/Makefile.am
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
|
||||
# Copyright (C) 2011 Red Hat, 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 3 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, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
SUBDIRS = eekboard
|
||||
21
bindings/python/eekboard/Makefile.am
Normal file
21
bindings/python/eekboard/Makefile.am
Normal file
@ -0,0 +1,21 @@
|
||||
# Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
|
||||
# Copyright (C) 2011 Red Hat, 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 3 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, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
pkgpython_PYTHON = \
|
||||
__init__.py \
|
||||
eekboard.py \
|
||||
context.py
|
||||
63
bindings/python/eekboard/__init__.py
Normal file
63
bindings/python/eekboard/__init__.py
Normal file
@ -0,0 +1,63 @@
|
||||
# Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
|
||||
# Copyright (C) 2011 Red Hat, 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 3 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, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
from gi.repository import Eek, EekXkl, Gio
|
||||
|
||||
from eekboard import Eekboard
|
||||
from context import Context
|
||||
|
||||
Keyboard = Eek.Keyboard
|
||||
Section = Eek.Section
|
||||
Key = Eek.Key
|
||||
Symbol = Eek.Symbol
|
||||
Keysym = Eek.Keysym
|
||||
|
||||
MODIFIER_BEHAVIOR_NONE, \
|
||||
MODIFIER_BEHAVIOR_LOCK, \
|
||||
MODIFIER_BEHAVIOR_LATCH = \
|
||||
(Eek.ModifierBehavior.NONE,
|
||||
Eek.ModifierBehavior.LOCK,
|
||||
Eek.ModifierBehavior.LATCH)
|
||||
|
||||
CSW = 640
|
||||
CSH = 480
|
||||
|
||||
def XmlKeyboard(path, modifier_behavior=MODIFIER_BEHAVIOR_NONE):
|
||||
_file = Gio.file_new_for_path(path)
|
||||
layout = Eek.XmlLayout.new(_file.read())
|
||||
keyboard = Eek.Keyboard.new(layout, CSW, CSH)
|
||||
keyboard.set_modifier_behavior(modifier_behavior)
|
||||
return keyboard
|
||||
|
||||
def XklKeyboard(modifier_behavior=MODIFIER_BEHAVIOR_NONE):
|
||||
layout = EekXkl.Layout.new()
|
||||
keyboard = Eek.Keyboard.new(layout, CSW, CSH)
|
||||
keyboard.set_modifier_behavior(modifier_behavior)
|
||||
return keyboard
|
||||
|
||||
__all__ = ['Eekboard',
|
||||
'Context',
|
||||
'Keyboard',
|
||||
'Section',
|
||||
'Key',
|
||||
'Symbol',
|
||||
'Keysym',
|
||||
'MODIFIER_BEHAVIOR_NONE',
|
||||
'MODIFIER_BEHAVIOR_LOCK',
|
||||
'MODIFIER_BEHAVIOR_LATCH',
|
||||
'XmlKeyboard',
|
||||
'XklKeyboard']
|
||||
73
bindings/python/eekboard/context.py
Normal file
73
bindings/python/eekboard/context.py
Normal file
@ -0,0 +1,73 @@
|
||||
# Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
|
||||
# Copyright (C) 2011 Red Hat, 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 3 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, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
from gi.repository import Eekboard
|
||||
import gobject
|
||||
|
||||
class Context(gobject.GObject):
|
||||
__gtype_name__ = "PYEekboardContext"
|
||||
__gsignals__ = {
|
||||
'enabled': (
|
||||
gobject.SIGNAL_RUN_LAST,
|
||||
gobject.TYPE_NONE,
|
||||
()),
|
||||
'disabled': (
|
||||
gobject.SIGNAL_RUN_LAST,
|
||||
gobject.TYPE_NONE,
|
||||
()),
|
||||
'key-pressed': (
|
||||
gobject.SIGNAL_RUN_LAST,
|
||||
gobject.TYPE_NONE,
|
||||
(gobject.TYPE_UINT,)),
|
||||
'key-released': (
|
||||
gobject.SIGNAL_RUN_LAST,
|
||||
gobject.TYPE_NONE,
|
||||
(gobject.TYPE_UINT,))
|
||||
}
|
||||
|
||||
def __init__(self, giobject):
|
||||
super(Context, self).__init__()
|
||||
import sys
|
||||
self.__giobject = giobject
|
||||
self.__giobject.connect('enabled', lambda *args: self.emit('enabled'))
|
||||
self.__giobject.connect('disabled', lambda *args: self.emit('disabled'))
|
||||
self.__giobject.connect('key-pressed', lambda *args: self.emit('key-pressed', args[1]))
|
||||
self.__giobject.connect('key-released', lambda *args: self.emit('key-released', args[1]))
|
||||
|
||||
def get_giobject(self):
|
||||
return self.__giobject
|
||||
|
||||
def set_keyboard(self, keyboard):
|
||||
self.__giobject.set_keyboard(keyboard, None)
|
||||
|
||||
def show_keyboard(self):
|
||||
self.__giobject.show_keyboard(None)
|
||||
|
||||
def hide_keyboard(self):
|
||||
self.__giobject.show_keyboard(None)
|
||||
|
||||
def set_group(self, group):
|
||||
self.__giobject.set_group(group, None)
|
||||
|
||||
def press_key(self, keycode):
|
||||
self.__giobject.press_key(keycode, None)
|
||||
|
||||
def release_key(self, keycode):
|
||||
self.__giobject.release_key(keycode, None)
|
||||
|
||||
def is_enabled(self):
|
||||
return self.__giobject.is_enabled()
|
||||
42
bindings/python/eekboard/eekboard.py
Normal file
42
bindings/python/eekboard/eekboard.py
Normal file
@ -0,0 +1,42 @@
|
||||
# Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
|
||||
# Copyright (C) 2011 Red Hat, 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 3 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, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
from gi.repository import Gio
|
||||
import gi.repository
|
||||
import gobject
|
||||
from context import Context
|
||||
|
||||
class Eekboard(gobject.GObject):
|
||||
__gtype_name__ = "PYEekboardEekboard"
|
||||
|
||||
def __init__(self):
|
||||
super(Eekboard, self).__init__()
|
||||
self.__connection = Gio.bus_get_sync(Gio.BusType.SESSION, None)
|
||||
self.__eekboard = gi.repository.Eekboard.Eekboard.new(self.__connection, None);
|
||||
|
||||
def create_context(self, client_name):
|
||||
context = self.__eekboard.create_context(client_name, None)
|
||||
return Context(context)
|
||||
|
||||
def push_context(self, context):
|
||||
self.__eekboard.push_context(context.get_giobject(), None)
|
||||
|
||||
def pop_context(self):
|
||||
self.__eekboard.pop_context(None)
|
||||
|
||||
def destroy_context(self, context):
|
||||
self.__eekboard.destroy_context(context.get_giobject(), None)
|
||||
33
configure.ac
33
configure.ac
@ -132,6 +132,37 @@ fi
|
||||
AC_MSG_RESULT($enable_cspi)
|
||||
AM_CONDITIONAL(ENABLE_CSPI, [test x$enable_cspi = xyes])
|
||||
|
||||
dnl Python language binding
|
||||
AC_MSG_CHECKING([whether you enable Python language support])
|
||||
AC_ARG_ENABLE(python,
|
||||
AS_HELP_STRING([--enable-python=no/yes],
|
||||
[Enable Python language binding default=yes]),,
|
||||
enable_python=yes)
|
||||
AC_MSG_RESULT($enable_python)
|
||||
AM_CONDITIONAL(ENABLE_PYTHON, [test x$enable_python = xyes])
|
||||
|
||||
if test x"$enable_python" = x"yes"; then
|
||||
# check python
|
||||
AM_PATH_PYTHON([2.5])
|
||||
AC_PATH_PROG(PYTHON_CONFIG, python$PYTHON_VERSION-config)
|
||||
if test x"$PYTHON_CONFIG" = x""; then
|
||||
AC_PATH_PROG(PYTHON_CONFIG, python-config)
|
||||
fi
|
||||
if test x"$PYTHON_CONFIG" != x""; then
|
||||
PYTHON_CFLAGS=`$PYTHON_CONFIG --includes`
|
||||
PYTHON_LIBS=`$PYTHON_CONFIG --libs`
|
||||
else
|
||||
PYTHON_CFLAGS=`$PYTHON $srcdir/python-config.py --includes`
|
||||
PYTHON_LIBS=`$PYTHON $srcdir/python-config.py --libs`
|
||||
fi
|
||||
PYTHON_INCLUDES="$PYTHON_CFLAGS"
|
||||
AC_SUBST(PYTHON_CFLAGS)
|
||||
AC_SUBST(PYTHON_INCLUDES)
|
||||
AC_SUBST(PYTHON_LIBS)
|
||||
else
|
||||
enable_python="no (disabled, use --enable-python to enable)"
|
||||
fi
|
||||
|
||||
dnl Vala langauge binding
|
||||
AC_MSG_CHECKING([whether you enable Vala language support])
|
||||
AC_ARG_ENABLE(vala,
|
||||
@ -195,6 +226,8 @@ eekboard/Makefile
|
||||
src/Makefile
|
||||
tests/Makefile
|
||||
bindings/Makefile
|
||||
bindings/python/Makefile
|
||||
bindings/python/eekboard/Makefile
|
||||
bindings/vala/Makefile
|
||||
docs/Makefile
|
||||
docs/reference/Makefile
|
||||
|
||||
Reference in New Issue
Block a user