44
self.vk = virtkey.virtkey()
47
#List of keys which have been latched.
47
def __init__(self, vk):
50
#List of keys which have been latched.
48
51
#ie. pressed until next non sticky button is pressed.
51
54
self.panes = [] # All panes except the basePane
52
55
self.tabKeys.append(BaseTabKey(self, config.SIDEBARWIDTH))
56
58
def set_basePane(self, basePane):
57
59
self.basePane = basePane #Pane which is always visible
59
61
def add_pane(self, pane):
60
62
self.panes.append(pane)
61
63
self.tabKeys.append(TabKey(self, config.SIDEBARWIDTH, pane))
63
65
def utf8_to_unicode(self,utf8Char):
64
66
return ord(utf8Char.decode('utf-8'))
66
68
def scan_tick(self): #at intervals scans across keys in the row and then down columns.
67
69
if self.scanningActive:
68
70
self.scanningActive.beingScanned = False
70
72
if self.activePane:
71
73
pane = self.activePane
73
75
pane = self.basePane
75
77
if not self.scanning_y == None:
76
78
self.scanning_y = (self.scanning_y + 1) % len(pane.columns[self.scanning_x])
78
80
self.scanning_x = (self.scanning_x + 1) % len(pane.columns)
80
82
if self.scanning_y == None:
83
85
y = self.scanning_y
85
87
self.scanningActive = pane.columns[self.scanning_x][y]
87
89
self.scanningActive.beingScanned = True
92
94
def is_key_pressed(self,key, widget, event):
93
95
if(key.pointWithinKey(widget, event.x, event.y)):
94
96
self.press_key(key)
96
98
def _on_mods_changed(self):
97
99
raise NotImplementedException()
99
101
def press_key(self, key):
102
107
self.altLocked = True
105
110
if key.sticky == True:
106
111
self.stuck.append(key)
109
114
self.active = key #Since only one non-sticky key can be pressed at once.
114
119
if key.action_type == KeyCommon.CHAR_ACTION:
115
120
self.vk.press_unicode(self.utf8_to_unicode(key.action))
117
122
elif key.action_type == KeyCommon.KEYSYM_ACTION:
118
123
self.vk.press_keysym(key.action)
119
124
elif key.action_type == KeyCommon.KEYPRESS_NAME_ACTION:
120
125
self.vk.press_keysym(get_keysym_from_name(key.action))
121
126
elif key.action_type == KeyCommon.MODIFIER_ACTION:
124
129
if not mod == 8: #Hack since alt puts metacity into move mode and prevents clicks reaching widget.
125
130
self.vk.lock_mod(mod)
126
131
self.mods[mod] += 1
127
132
elif key.action_type == KeyCommon.MACRO_ACTION:
129
134
mString = unicode(config.snippets[string.atoi(key.action)])
130
# If mstring exists do the below, otherwise the code in finally should always
135
# If mstring exists do the below, otherwise the code in finally should always
133
138
for c in mString:
134
139
self.vk.press_unicode(ord(c))
135
140
self.vk.release_unicode(ord(c))
138
143
except IndexError:
141
146
if not config.xid_mode: # block dialog in xembed mode
143
dialog = gtk.Dialog("No snippet", self.parent, 0,
144
("_Save snippet", gtk.RESPONSE_OK,
148
dialog = gtk.Dialog("No snippet", self.parent, 0,
149
("_Save snippet", gtk.RESPONSE_OK,
145
150
"_Cancel", gtk.RESPONSE_CANCEL))
146
151
dialog.vbox.add(gtk.Label(
147
152
"No snippet for this button,\nType new snippet"))
149
macroEntry = gtk.Entry()
154
macroEntry = gtk.Entry()
151
156
dialog.connect("response", self.cb_dialog_response,string.atoi(key.action), macroEntry)
153
158
macroEntry.connect("activate", self.cb_macroEntry_activate,string.atoi(key.action), dialog)
154
159
dialog.vbox.pack_end(macroEntry)
178
183
self.release_key(key)
180
185
self.queue_draw()
183
188
def cb_dialog_response(self, widget, response, macroNo,macroEntry):
184
189
self.set_new_macro(macroNo, response, macroEntry, widget)
186
191
def cb_macroEntry_activate(self,widget,macroNo,dialog):
187
192
self.set_new_macro(macroNo, gtk.RESPONSE_OK, widget, dialog)
189
194
def set_new_macro(self,macroNo,response,macroEntry,dialog):
190
if response == gtk.RESPONSE_OK:
195
if response == gtk.RESPONSE_OK:
191
196
config.set_snippet(macroNo, macroEntry.get_text())
195
200
def release_key(self,key):
196
204
if key.action_type == KeyCommon.CHAR_ACTION:
197
205
self.vk.release_unicode(self.utf8_to_unicode(key.action))
198
206
elif key.action_type == KeyCommon.KEYSYM_ACTION: