Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Librem5
squeekboard
Commits
16d81f3f
Commit
16d81f3f
authored
Mar 11, 2011
by
Daiki Ueno
Browse files
Generate inscript keyboard on-the-fly.
parent
42a0ea14
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
bindings/python/eekboard/__init__.py
View file @
16d81f3f
...
...
@@ -25,6 +25,7 @@ Section = Eek.Section
Key
=
Eek
.
Key
Symbol
=
Eek
.
Symbol
Keysym
=
Eek
.
Keysym
SymbolMatrix
=
Eek
.
SymbolMatrix
MODIFIER_BEHAVIOR_NONE
,
\
MODIFIER_BEHAVIOR_LOCK
,
\
...
...
configure.ac
View file @
16d81f3f
...
...
@@ -245,7 +245,9 @@ data/icons/32x32/Makefile
data/icons/48x48/Makefile
data/icons/scalable/Makefile
data/themes/Makefile
data/keyboards/Makefile
examples/Makefile
examples/eekboard-inscript/Makefile
eek/eek-${EEK_API_VERSION}.pc
eek/eek-clutter-${EEK_API_VERSION}.pc
eek/eek-gtk-${EEK_API_VERSION}.pc
...
...
data/Makefile.am
View file @
16d81f3f
SUBDIRS
=
icons themes
SUBDIRS
=
icons themes
keyboards
data/keyboards/Makefile.am
0 → 100644
View file @
16d81f3f
keyboarddir
=
$(pkgdatadir)
/keyboards
dist_keyboard_DATA
=
us-qwerty.xml
data/keyboards/us-qwerty.xml
0 → 100644
View file @
16d81f3f
This diff is collapsed.
Click to expand it.
examples/Makefile.am
View file @
16d81f3f
bin_SCRIPTS
=
eekboard-inscript
keyboarddir
=
$(pkgdatadir)
/keyboards
dist_keyboard_DATA
=
inscript2.xml
EXTRA_DIST
=
gen-inscript-keyboard.py
eekboard-inscript
:
eekboard-inscript.in
$(AM_V_GEN)
sed
's!@EEKBOARD_INSCRIPT_PATH@!'
$(pkgdatadir)
/keyboards/inscript2.xml
'!'
<
$<
>
$@
SUBDIRS
=
eekboard-inscript
examples/eekboard-inscript/Makefile.am
0 → 100644
View file @
16d81f3f
bin_SCRIPTS
=
eekboard-inscript
keyboarddir
=
$(pkgdatadir)
/keyboards
eekboard_inscript_datadir
=
$(datarootdir)
/eekboard-inscript
eekboard_inscript_data_DATA
=
inscript.py main.py
eekboard-inscript
:
eekboard-inscript.in
$(AM_V_GEN)
sed
-e
's!@''PYTHON@!'
$(PYTHON)
'!'
\
-e
's!@EEKBOARD_KEYBOARDDIR@!'
$(keyboarddir)
'!'
\
-e
's!@M17N_DIR@!'
$(datadir)
/m17n
'!'
\
-e
's!@EEKBOARD_INSCRIPT_DATADIR@!'
$(eekboard_inscript_datadir)
'!'
<
$<
>
$@
CLEANFILES
=
eekboard-inscript
examples/eekboard-inscript/eekboard-inscript.in
0 → 100644
View file @
16d81f3f
#!/bin/sh
# 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
export
EEKBOARD_KEYBOARDDIR
=
@EEKBOARD_KEYBOARDDIR@
export
M17N_DIR
=
@M17N_DIR@
exec
@PYTHON@ @EEKBOARD_INSCRIPT_DATADIR@/main.py
$@
examples/eekboard-inscript
.
in
→
examples/eekboard-inscript
/
in
script.py
View file @
16d81f3f
...
...
@@ -19,35 +19,67 @@
# 02110-1301 USA
import
gtk
,
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
)
import
sys
,
os
.
path
,
re
KEYCODE_TABLE
=
{
'1'
:
10
,
'2'
:
11
,
'3'
:
12
,
'4'
:
13
,
'5'
:
14
,
'6'
:
15
,
'7'
:
16
,
'8'
:
17
,
'9'
:
18
,
'0'
:
19
,
'-'
:
20
,
'='
:
21
,
'q'
:
24
,
'w'
:
25
,
'e'
:
26
,
'r'
:
27
,
't'
:
28
,
'y'
:
29
,
'u'
:
30
,
'i'
:
31
,
'o'
:
32
,
'p'
:
33
,
'['
:
34
,
']'
:
35
,
'a'
:
38
,
's'
:
39
,
'd'
:
40
,
'f'
:
41
,
'g'
:
42
,
'h'
:
43
,
'j'
:
44
,
'k'
:
45
,
'l'
:
46
,
';'
:
47
,
'
\'
'
:
48
,
'`'
:
49
,
'
\\
'
:
51
,
'z'
:
52
,
'x'
:
53
,
'c'
:
54
,
'v'
:
55
,
'b'
:
56
,
'n'
:
57
,
'm'
:
58
,
','
:
59
,
'.'
:
60
,
'/'
:
61
}
MARK_UPPER
=
'~!@#$%^&*()_+{}|:"<>?'
MARK_LOWER
=
'`1234567890-=[]
\\
;
\'
,./'
class
MapFile
(
object
):
MAPENTRY_PATTERN
=
re
.
compile
(
r
'\A\s*\((?:\((.*?)\)|"(.*?)")\s*"(.*?)"\)'
)
def
__init__
(
self
,
path
):
self
.
__dict
=
dict
()
with
open
(
path
,
'r'
)
as
fp
:
for
line
in
fp
:
match
=
re
.
match
(
self
.
MAPENTRY_PATTERN
,
line
)
if
match
:
insert
=
match
.
group
(
3
).
decode
(
'UTF-8'
)
if
match
.
group
(
1
):
keyseq
=
re
.
sub
(
r
'\\(.)'
,
r
'\1'
,
match
.
group
(
1
))
self
.
__add_symbol_entry
(
keyseq
,
insert
)
else
:
keyseq
=
re
.
sub
(
r
'\\(.)'
,
r
'\1'
,
match
.
group
(
2
))
self
.
__add_text_entry
(
keyseq
,
insert
)
def
get_entry_for_keycode
(
self
,
keycode
):
return
self
.
__dict
.
get
(
keycode
)
def
__add_entry
(
self
,
letter
,
level
,
insert
):
if
letter
.
isupper
():
level
|=
1
letter
=
letter
.
lower
()
elif
letter
in
MARK_UPPER
:
level
|=
1
letter
=
MARK_LOWER
[
MARK_UPPER
.
index
(
letter
)]
keycode
=
KEYCODE_TABLE
[
letter
]
if
keycode
not
in
self
.
__dict
:
self
.
__dict
[
keycode
]
=
list
([
None
,
None
,
None
,
None
])
self
.
__dict
[
keycode
][
level
]
=
insert
def
__add_symbol_entry
(
self
,
symbol
,
insert
):
level
=
0
if
symbol
.
startswith
(
'G-'
):
level
|=
2
symbol
=
symbol
[
2
:]
if
not
symbol
.
startswith
(
'KP_'
):
self
.
__add_entry
(
symbol
,
level
,
insert
)
def
__add_text_entry
(
self
,
text
,
insert
):
self
.
__add_entry
(
text
,
0
,
insert
)
class
Keyboard
(
object
):
def
__init__
(
self
,
client_name
,
map_path
,
kbd_path
):
self
.
__keyboard
=
self
.
__create_keyboard
(
map_path
,
kbd_path
)
self
.
__eekboard
=
eekboard
.
Eekboard
()
self
.
__context
=
self
.
__eekboard
.
create_context
(
client_name
)
keyboard_id
=
self
.
__context
.
add_keyboard
(
self
.
__keyboard
)
...
...
@@ -58,6 +90,50 @@ class InscriptKeyboard(object):
self
.
__english
=
False
self
.
__eekboard
.
connect
(
'destroyed'
,
self
.
__destroyed_cb
)
def
__create_keyboard
(
self
,
map_path
,
kbd_path
):
def
__each_key
(
element
,
data
):
keycode
=
element
.
get_keycode
()
# keycode 37 is used to toggle English/Inscript
if
keycode
==
37
:
matrix
=
eekboard
.
SymbolMatrix
.
new
(
2
,
1
)
keysym
=
eekboard
.
Keysym
.
new
(
65507
)
keysym
.
set_label
(
"Ind"
)
matrix
.
set_symbol
(
0
,
0
,
keysym
)
keysym
=
eekboard
.
Keysym
.
new
(
65507
)
keysym
.
set_label
(
"Eng"
)
matrix
.
set_symbol
(
1
,
0
,
keysym
)
element
.
set_symbol_matrix
(
matrix
)
return
# group(0) is us keyboard
matrix
=
eekboard
.
SymbolMatrix
.
new
(
2
,
4
)
for
l
in
xrange
(
4
):
keysym
=
element
.
get_symbol_at_index
(
0
,
l
,
0
,
0
)
matrix
.
set_symbol
(
0
,
l
,
keysym
)
# group(1) is inscript keyboard
entry
=
data
.
get_entry_for_keycode
(
keycode
)
for
l
in
xrange
(
4
):
keysym
=
None
if
entry
and
entry
[
l
]:
try
:
keyval
=
gtk
.
gdk
.
unicode_to_keyval
(
ord
(
entry
[
l
]))
keysym
=
eekboard
.
Keysym
.
new
(
keyval
)
except
:
print
>>
sys
.
stderr
,
"can't convert %s to keyval"
%
entry
[
l
]
if
not
keysym
:
keysym
=
element
.
get_symbol_at_index
(
1
,
l
,
0
,
0
)
matrix
.
set_symbol
(
1
,
l
,
keysym
)
element
.
set_symbol_matrix
(
matrix
)
def
__each_section
(
element
,
data
):
element
.
foreach_child
(
__each_key
,
data
)
mapfile
=
MapFile
(
map_path
)
keyboard
=
eekboard
.
XmlKeyboard
(
kbd_path
,
eekboard
.
MODIFIER_BEHAVIOR_LATCH
)
keyboard
.
foreach_child
(
__each_section
,
mapfile
)
return
keyboard
def
__destroyed_cb
(
self
,
eekboard
):
gtk
.
main_quit
()
...
...
@@ -98,29 +174,3 @@ class InscriptKeyboard(object):
if
isinstance
(
symbol
,
eekboard
.
Keysym
):
xkeysym
=
symbol
.
get_xkeysym
()
self
.
__virtkey
.
release_keysym
(
xkeysym
)
if
__name__
==
"__main__"
:
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
()
examples/eekboard-inscript/main.py
0 → 100644
View file @
16d81f3f
# 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
inscript
import
gtk
from
optparse
import
OptionParser
import
sys
,
os
parser
=
OptionParser
()
parser
.
add_option
(
"-n"
,
"--name=LANGCODE"
,
dest
=
"langcode"
,
help
=
"Specify language code to LANGCODE"
,
metavar
=
"LANGCODE"
)
(
options
,
args
)
=
parser
.
parse_args
()
if
options
.
langcode
is
None
:
print
>>
sys
.
stderr
,
"Specify language code with -n"
exit
(
1
)
map_path
=
os
.
path
.
join
(
os
.
getenv
(
"M17N_DIR"
),
options
.
langcode
+
".mim"
)
if
not
os
.
path
.
exists
(
map_path
):
print
>>
sys
.
stderr
,
"%s not found"
%
map_path
exit
(
1
)
kbd_path
=
os
.
path
.
join
(
os
.
getenv
(
"EEKBOARD_KEYBOARDDIR"
),
"us-qwerty.xml"
)
if
not
os
.
path
.
exists
(
kbd_path
):
print
>>
sys
.
stderr
,
"%s not found"
%
kbd_path
exit
(
1
)
keyboard
=
inscript
.
Keyboard
(
"eekboard-inscript"
,
map_path
,
kbd_path
)
keyboard
.
set_group
(
1
)
keyboard
.
enable
()
keyboard
.
show
()
gtk
.
main
()
examples/gen-inscript-keyboard.py
deleted
100644 → 0
View file @
42a0ea14
#!/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
sys
,
os
.
path
import
sys
import
re
import
gtk
,
gtk
.
gdk
import
eekboard
from
gi.repository
import
Eek
,
GLib
if
len
(
sys
.
argv
)
<
3
:
print
>>
sys
.
stderr
,
"Usage: %s KEYBOARD M17N-MAP..."
%
sys
.
argv
[
0
]
sys
.
exit
(
-
1
)
MAPENTRY_PATTERN
=
re
.
compile
(
r
'\A\s*\((?:\((.*?)\)|"(.*?)")\s*"(.*?)"\)'
)
KEYCODE_TABLE
=
{
'1'
:
10
,
'2'
:
11
,
'3'
:
12
,
'4'
:
13
,
'5'
:
14
,
'6'
:
15
,
'7'
:
16
,
'8'
:
17
,
'9'
:
18
,
'0'
:
19
,
'-'
:
20
,
'='
:
21
,
'q'
:
24
,
'w'
:
25
,
'e'
:
26
,
'r'
:
27
,
't'
:
28
,
'y'
:
29
,
'u'
:
30
,
'i'
:
31
,
'o'
:
32
,
'p'
:
33
,
'['
:
34
,
']'
:
35
,
'a'
:
38
,
's'
:
39
,
'd'
:
40
,
'f'
:
41
,
'g'
:
42
,
'h'
:
43
,
'j'
:
44
,
'k'
:
45
,
'l'
:
46
,
';'
:
47
,
'
\'
'
:
48
,
'`'
:
49
,
'
\\
'
:
51
,
'z'
:
52
,
'x'
:
53
,
'c'
:
54
,
'v'
:
55
,
'b'
:
56
,
'n'
:
57
,
'm'
:
58
,
','
:
59
,
'.'
:
60
,
'/'
:
61
}
MARK_UPPER
=
'~!@#$%^&*()_+{}|:"<>?'
MARK_LOWER
=
'`1234567890-=[]
\\
;
\'
,./'
class
MapFile
(
object
):
def
__init__
(
self
,
path
):
self
.
__dict
=
dict
()
with
open
(
path
,
'r'
)
as
fp
:
for
line
in
fp
:
match
=
re
.
match
(
MAPENTRY_PATTERN
,
line
)
if
match
:
insert
=
match
.
group
(
3
).
decode
(
'UTF-8'
)
if
match
.
group
(
1
):
keyseq
=
re
.
sub
(
r
'\\(.)'
,
r
'\1'
,
match
.
group
(
1
))
self
.
__add_symbol_entry
(
keyseq
,
insert
)
else
:
keyseq
=
re
.
sub
(
r
'\\(.)'
,
r
'\1'
,
match
.
group
(
2
))
self
.
__add_text_entry
(
keyseq
,
insert
)
def
get_entry_for_keycode
(
self
,
keycode
):
return
self
.
__dict
.
get
(
keycode
,
list
([
None
,
None
,
None
,
None
]))
def
__add_entry
(
self
,
letter
,
level
,
insert
):
if
letter
.
isupper
():
level
|=
1
letter
=
letter
.
lower
()
elif
letter
in
MARK_UPPER
:
level
|=
1
letter
=
MARK_LOWER
[
MARK_UPPER
.
index
(
letter
)]
keycode
=
KEYCODE_TABLE
[
letter
]
if
keycode
not
in
self
.
__dict
:
self
.
__dict
[
keycode
]
=
list
([
None
,
None
,
None
,
None
])
self
.
__dict
[
keycode
][
level
]
=
insert
def
__add_symbol_entry
(
self
,
symbol
,
insert
):
level
=
0
if
symbol
.
startswith
(
'G-'
):
level
|=
2
symbol
=
symbol
[
2
:]
if
not
symbol
.
startswith
(
'KP_'
):
self
.
__add_entry
(
symbol
,
level
,
insert
)
def
__add_text_entry
(
self
,
text
,
insert
):
self
.
__add_entry
(
text
,
0
,
insert
)
files
=
list
()
for
path
in
sys
.
argv
[
2
:]:
files
.
append
(
MapFile
(
path
))
keyboard
=
eekboard
.
XmlKeyboard
(
os
.
path
.
abspath
(
sys
.
argv
[
1
]))
def
each_key
(
element
,
data
):
keycode
=
element
.
get_keycode
()
matrix
=
Eek
.
SymbolMatrix
.
new
(
len
(
files
)
+
1
,
4
)
for
l
in
xrange
(
4
):
keysym
=
element
.
get_symbol_at_index
(
0
,
l
,
0
,
0
)
matrix
.
set_symbol
(
0
,
l
,
keysym
)
for
g
,
f
in
enumerate
(
files
):
entry
=
f
.
get_entry_for_keycode
(
keycode
)
for
l
in
xrange
(
4
):
keysym
=
None
if
entry
[
l
]:
try
:
keyval
=
gtk
.
gdk
.
unicode_to_keyval
(
ord
(
entry
[
l
]))
keysym
=
Eek
.
Keysym
.
new
(
keyval
)
except
:
pass
if
not
keysym
:
keysym
=
element
.
get_symbol_at_index
(
g
+
1
,
l
,
0
,
0
)
matrix
.
set_symbol
(
g
+
1
,
l
,
keysym
)
element
.
set_symbol_matrix
(
matrix
)
def
each_section
(
element
,
data
):
element
.
foreach_child
(
each_key
,
None
)
keyboard
.
foreach_child
(
each_section
,
None
)
output
=
GLib
.
string_sized_new
(
4096
)
keyboard
.
output
(
output
,
0
)
print
output
.
str
examples/inscript2.xml
deleted
100644 → 0
View file @
42a0ea14
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment