forked from azbox-enigma2/keymapconfig
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeymapConfig.py
More file actions
169 lines (133 loc) · 4.83 KB
/
KeymapConfig.py
File metadata and controls
169 lines (133 loc) · 4.83 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
from Screens.Screen import Screen
from Components.ActionMap import ActionMap
from Components.Sources.List import List
from Components.Sources.StaticText import StaticText
from Tools.LoadPixmap import LoadPixmap
from Tools.Directories import resolveFilename, SCOPE_CURRENT_SKIN
from Components.config import config, ConfigSubsection, ConfigText
import keymapparser
import os
config.plugins.keymap = ConfigSubsection()
config.plugins.keymap.selected = ConfigText()
def load_keymap(keymap, keymaplist=[]):
if os.path.isfile(keymap):
keymaplist.append(("/usr/share/enigma2/keymap.xml", None, None))
keymaplist.append(("/usr/lib/enigma2/python/Plugins/Extensions/CutListEditor/keymap.xml", None, None))
keymaplist.append(("/usr/lib/enigma2/python/Plugins/Extensions/setupGlass16/keymap.xml", None, None))
keymaplist = set(k[0] for k in keymaplist)
for k in keymaplist:
if not os.path.isfile(k) or k == keymap:
continue
try:
keymapparser.removeKeymap(k)
except Exception as e:
print("[Keymap Config] RemoveKeymap error: %s" % e)
try:
print("[Keymap Config] Loading '%s'" % keymap)
keymapparser.readKeymap(keymap)
return True
except Exception as e:
print("[Keymap Config] Could not load keymap file '%s'" % keymap)
print("[Keymap Config] This plugin will not work properly")
print("[Keymap Config] Reason: %s" % e)
try:
print("[Keymap Config] Reloading default keymap")
keymapparser.readKeymap("/usr/share/enigma2/keymap.xml")
return True
except Exception as e:
print("[Keymap Config] Something bad happened. Failed to reload default keymap.")
print("[Keymap Config] Reason: %s" % e)
return False
class KeymapConfig(Screen):
skin = """
<screen position="fill" title="Keymap Config" flags="wfNoBorder" >
<panel name="PigTemplate"/>
<!--panel name="ButtonTemplate_2S"/-->
<panel name="ButtonTemplate_RGS"/>
<widget source="config" render="Listbox" position="590,110" size="600,512" scrollbarMode="showOnDemand" enableWrapAround="1" selectionDisabled="1">
<convert type="TemplatedMultiContent">
{"template": [
MultiContentEntryPixmapAlphaBlend(pos = (4, 2), size = (24, 24), png = 3),
MultiContentEntryText(pos = (32, 0), size = (1000, 32), font=0, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 1),
],
"fonts": [gFont("Regular", 20)],
"itemHeight": 32
}
</convert>
</widget>
</screen>"""
def __init__(self, session):
Screen.__init__(self, session)
self["shortcuts"] = ActionMap(["WizardActions", "DirectionActions", "ColorActions"],
{
"ok": self.ok,
"back": self.exit,
"cancel": self.exit,
"red": self.exit,
"green": self.save,
})
self.keymap_paths = [
"/usr/lib/enigma2/python/Plugins/Extensions/KeymapConfig/keymap/",
"/media/hdd/keymap/",
"/media/cf/keymap/",
"/media/mmc1/keymap/",
"/media/usb/keymap/"
]
self.list = []
self["config"] = List(self.list)
self["key_red"] = StaticText(_("Cancel"))
self["key_green"] = StaticText(_("Save"))
self.selected = 0
self.onShow.append(self.on_load)
def on_load(self):
self.update_list()
def exit(self):
self.close()
def ok(self):
self.selected = self["config"].getIndex()
self.set_selected()
def set_selected(self):
for k, item in enumerate(self.list):
item = list(item)
item[3] = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, "icons/lock_off.png"))
self["config"].modifyEntry(k, tuple(item))
item = list(self.list[self.selected])
item[3] = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, "icons/lock_on.png"))
self["config"].modifyEntry(self.selected, tuple(item))
self["config"].setIndex(self.selected)
def save(self):
current = self.list[self.selected]
if load_keymap(current[0], self.list):
config.plugins.keymap.selected.value = current[0]
config.plugins.keymap.save()
self.exit()
def update_list(self):
self.list = []
selected = 0
self.list.append((
"/usr/share/enigma2/keymap.xml",
_("Default"),
"/usr/share/enigma2/keymap.xml",
LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, "icons/lock_off.png")),
))
for path_item in self.keymap_paths:
path = os.path.normpath(path_item)
for root, dirnames, filenames in os.walk(path):
for filename in sorted(filenames):
if filename[0] == ".":
continue
title, ext = os.path.splitext(filename)
ext = ext.strip().lower()
if ext == ".xml":
keymap_path = "%s/%s" % (root, filename)
if keymap_path == config.plugins.keymap.selected.value:
self.selected = len(self.list)
self.list.append((
keymap_path,
title,
keymap_path.replace('/usr/lib/enigma2/python/Plugins/', './'), # description
LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, "icons/lock_off.png")),
))
break
self["config"].setList(self.list)
self.set_selected()