1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 '''This plugin listens for certain keystrokes and binds them to actions. Other
22 keystrokes are silently passed onto the StyledTextControl for handling. This
23 is the simplest way to implement keybindings, as the StyledTextControl
24 takes care of a lot of the work. However, it is not the most extensible, as
25 modifying keybindings requires editing the plugin, and we end up with a mix
26 of StyledTextControl keybindings and Pallavi handled keybindings. A more
27 extensible solution was used in Pallavi 0.1 with the keystroke_conversion plugin,
28 but because it was incomplete, this restricted a lot of the functionality.
29
30 Luckily, any number of keybinding plugins can be written (though perhaps they
31 should not all be used at once!) So in the future, a more extensible system may
32 be devised or some enterprising plugin developer. Ideally, I would like to see
33 a modal plugin (like vim interaction) and a fully customizable plugin with a keybinding
34 interface that lists all known user actions and allows them to be bound. And also
35 a simple one for people that want sleek and elegant.
36
37 This Plugin queues the following event:
38 KeyStroke
39 When a key has been pressed
40
41 This plugins listens for the following events:
42 TextViewAdded
43 Sets up a keystroke listener on a textview when it has been added to the view.
44 '''
45 from pallavi import EventActionManager
46 import wx
47
55
56 -def TextViewAdded(eventName, textview):
57 textview.Bind(wx.EVT_KEY_DOWN, KeyDown)
58
60 key = ""
61 if event.AltDown():
62 key = key + "ALT+"
63 if event.ControlDown():
64 key = key + "CTRL+"
65 if event.ShiftDown():
66 key = key + "SHIFT+"
67 if event.GetKeyCode() < 255:
68 key = key + chr(event.GetKeyCode())
69 else:
70
71
72
73
74
75
76
77
78 for special_keyvariable in filter(lambda x: x.startswith("WXK_"), dir(wx)):
79 exec("special_keycode = wx." + special_keyvariable)
80 if event.GetKeyCode() == special_keycode:
81 key = key + special_keyvariable[4:]
82
83 eventBus.QueueEvent("KeyStroke", event.GetKeyCode())
84
85 if config.simplekeybindings.has_key(key):
86 action = config.simplekeybindings[key]
87 if type(action) == tuple:
88 actions.Invoke(*action)
89 else:
90 actions.Invoke(action)
91 else:
92 event.Skip()
93