3 # ##### BEGIN GPL LICENSE BLOCK #####
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software Foundation,
17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110- 1301, USA.
19 # ##### END GPL LICENSE BLOCK #####
23 # ----------------------------------------------------------
24 # Author: Stephen Leger (s-leger)
26 # ----------------------------------------------------------
31 Expose user defined keymaps as event
32 so in modal operator we are able to
34 if (event == keymap.undo.event):
36 and in feedback panels:
40 def __init__(self
, context
):
42 Init keymaps properties
46 self
.undo
= self
.get_event(context
, 'Screen', 'ed.undo')
49 self
.delete
= self
.get_event(context
, 'Object Mode', 'object.delete')
52 # provide abstration between user and addon
53 # with different select mouse side
54 mouse_right = context.window_manager.keyconfigs.active.preferences.select_mouse
55 if mouse_right == 'LEFT':
57 mouse_right_side = 'Left'
58 mouse_left_side = 'Right'
61 mouse_right_side = 'Right'
62 mouse_left_side = 'Left'
64 self.leftmouse = mouse_left + 'MOUSE'
65 self.rightmouse = mouse_right + 'MOUSE'
68 def check(self
, event
, against
):
70 signature
= (event
.alt
, event
.ctrl
, event
.shift
, event
.type, event
.value
)
72 # print ("check %s == %s" % (signature, ev))
73 if ev
['event'] == signature
:
79 def get_event(self
, context
, keyconfig
, keymap_item
):
81 Return simple keymaps event signature as array of dict
83 this won't work for complex keymaps such as select_all
84 using properties to call operator in different manner
85 type: keyboard main type
86 name: event name as defined in user preferences
87 event: simple event signature to compare like :
88 if keymap.check(event, keymap.undo):
90 evs
= [ev
for k
, ev
in context
.window_manager
.keyconfigs
[0].keymaps
[keyconfig
].keymap_items
.items()
92 # ev = context.window_manager.keyconfigs[0].keymaps[keyconfig].keymap_items[keymap_item]
102 res
.append({'type': key
, 'name': ev
.name
, 'event': (ev
.alt
, ev
.ctrl
, ev
.shift
, ev
.type, ev
.value
)})
105 def dump_keys(self
, context
, filename
="/tmp/keymap.txt"):
107 Utility for developers :
108 Dump all keymaps to a file
109 filename : string a file path to dump keymaps
112 kms
= context
.window_manager
.keyconfigs
113 for name
, km
in kms
.items():
114 for key
in km
.keymaps
.keys():
115 str += "\n\n#--------------------------------\n{} - {}:\n#--------------------------------\n\n".format(name
, key
)
116 for sub
in km
[key
].keymap_items
.keys():
117 k
= km
[key
].keymap_items
[sub
]
118 str += "alt:{} ctrl:{} shift:{} type:{} value:{} idname:{} name:{}\n".format(
119 k
.alt
, k
.ctrl
, k
.shift
, k
.type, k
.value
, sub
, k
.name
)
120 file = open(filename
, "w")