-
Notifications
You must be signed in to change notification settings - Fork 37
/
Common.py
104 lines (81 loc) · 3.39 KB
/
Common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python
# -*- encoding: UTF-8 -*-
#
# 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/>
import cairo
import Enum
keytypes = Enum.Enum("SIMPLE SPECIAL").vals(illegal=255)
alignments = Enum.Enum("LEFT CENTRE RIGHT").vals(illegal=255)
keysegments = Enum.Enum("ALL ONE TWO THREE FOUR NONE").vals(illegal=255)
keyvaluetype = Enum.Enum("UNICHAR CODEPOINT KEYSYM CONSTANT DEADKEY ANY VOIDSYMBOL NOSYMBOL NOACTION VERBATIM").vals(illegal=255)
keysegmentslist = [keysegments.ONE, keysegments.TWO,
keysegments.THREE, keysegments.FOUR]
keysegmentslistreverse = list(keysegmentslist)
keysegmentslistreverse.reverse()
fontname = "Sans"
fontstyle = cairo.FONT_SLANT_NORMAL
fontweight = cairo.FONT_WEIGHT_NORMAL
fontsize = 12
# You need to have gucharmap installed.
# It might be possible to perform drag n drop from the KDE equivalent,
# though I did not get any confirmation on this yet.
# We now perform a 'os.system()' on the following string.
gucharmappath = "gucharmap"
# The Xkeyboard-Config path
xkcpath = "/usr/share/X11/xkb"
xkcsymbols = xkcpath + "/symbols"
# The program icon
KLEiconfile = "kleiconfile.ico"
# Max levels, currently 4. May go 8 in future.
LEVELMAX = 4
# The application home directory
HOMEDIR = ''
# The application's official full name.
applicationname="Keyboard Layout Editor"
# Holds the current filename.
currentlayoutfile=''
# The directory to the xkeyboard-config base directory.
basedir = '/usr/share/X11/xkb/'
# The directory to the xkeyboard-config symbols directory.
symbolsdir = basedir + 'symbols/'
# A gtk.Statusbar object, shared, so that all can write to.
statusbar = None
# Default dead key.
deadkey = "dead_acute"
# Text that appears when saving a keyboard layout (appears in text file, at start
layout_preamble = """/////////////////////////////////////////////////////////////////////////////////
//
// Generated keyboard layout file with the Keyboard Layout Editor.
// For more about the software, see http://code.google.com/p/keyboardlayouteditor
//
"""
# Sorts a dictionary by value, produces a sorted list of values.
def sortDict(adict, cmp_function = None):
keys = adict.keys()
keys.sort(cmp_function)
return map(adict.get, keys)
def addtostatusbar(message):
statusbar.push(statusbar.console_context, message)
def parseIncludeString(include):
"""
Parses strings of the form 'us(intl)', 'us', and produces
{ 'filename': 'us', 'variant': 'intl' }, { 'filename': 'us', 'variant': 'basic' }
"""
if include.partition('(')[1] == '(':
return { 'filename': include.partition('(')[0], 'variant': include.partition('(')[2].partition(')')[0] }
else:
return { 'filename': include.partition('(')[0], 'variant': '' }
if __name__ == '__main__':
print parseIncludeString('us')
print parseIncludeString('us(level1)')