Cleanup: quiet strict name warnings for addons a..h.
[blender-addons.git] / development_iskeyfree.py
blob0408a648ecfe4ab5a2d800552b428a5253760177
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 # PEP8 compliant (https://www.python.org/dev/peps/pep-0008)
21 bl_info = {
22 "name": "Is key Free",
23 "author": "Antonio Vazquez (antonioya)",
24 "version": (1, 0, 2),
25 "blender": (2, 6, 9),
26 "location": "Text Editor > Props Shelf (Ctrl/t > IsKeyFree Tools",
27 "description": "Find free shortcuts and inform of used keys",
28 "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6"
29 "/Py/Scripts/Development/IsKeyFree",
30 "category": "Development"}
32 import bpy
33 from bpy.props import (
34 StringProperty,
35 BoolProperty,
36 EnumProperty,
37 PointerProperty,
39 from bpy.types import (
40 Operator,
41 Panel,
42 PropertyGroup,
46 # ------------------------------------------------------
47 # Class to find keymaps
48 # ------------------------------------------------------
51 class MyChecker():
52 lastfind = None
53 lastkey = None
54 mylist = []
56 # Init
57 def __init__(self):
58 self.var = 5
60 # Verify if the key is used
61 @classmethod
62 def check(cls, findkey, ctrl, alt, shift, oskey):
63 if len(findkey) > 0:
64 cmd = ""
65 if ctrl is True:
66 cmd += "Ctrl+"
67 if alt is True:
68 cmd += "Alt+"
69 if shift is True:
70 cmd += "Shift+"
71 if oskey is True:
72 cmd += "OsKey+"
73 cls.lastfind = cmd + findkey.upper()
74 cls.lastkey = findkey.upper()
75 else:
76 cls.lastfind = None
77 cls.lastkey = None
79 wm = bpy.context.window_manager
80 mykeys = []
82 for context, keyboardmap in wm.keyconfigs.user.keymaps.items():
83 for myitem in keyboardmap.keymap_items:
84 if myitem.active is True and myitem.type == findkey:
85 if ctrl is True and myitem.ctrl is not True:
86 continue
87 if alt is True and myitem.alt is not True:
88 continue
89 if shift is True and myitem.shift is not True:
90 continue
91 if oskey is True and myitem.oskey is not True:
92 continue
93 t = (context,
94 myitem.type,
95 "Ctrl" if myitem.ctrl is True else "",
96 "Alt" if myitem.alt is True else "",
97 "Shift" if myitem.shift is True else "",
98 "OsKey" if myitem.oskey is True else "",
99 myitem.name)
101 mykeys.append(t)
103 sortkeys = sorted(mykeys, key=lambda key: (key[0], key[1], key[2], key[3], key[4], key[5]))
105 cls.mylist.clear()
106 for e in sortkeys:
107 cmd = ""
108 if e[2] is not "":
109 cmd += e[2] + "+"
110 if e[3] is not "":
111 cmd += e[3] + "+"
112 if e[4] is not "":
113 cmd += e[4] + "+"
114 if e[5] is not "":
115 cmd += e[5] + "+"
117 cmd += e[1]
119 if e[6] is not "":
120 cmd += " " + e[6]
121 cls.mylist.append([e[0], cmd])
123 # return context
124 @classmethod
125 def getcontext(cls):
126 return str(bpy.context.screen.name)
128 # return last search
129 @classmethod
130 def getlast(cls):
131 return cls.lastfind
133 # return last key
134 @classmethod
135 def getlastkey(cls):
136 return cls.lastkey
138 # return result of last search
139 @classmethod
140 def getlist(cls):
141 return cls.mylist
143 # verify if key is valid
144 @classmethod
145 def isvalidkey(cls, txt):
146 allkeys = [
147 "LEFTMOUSE", "MIDDLEMOUSE", "RIGHTMOUSE", "BUTTON4MOUSE", "BUTTON5MOUSE", "BUTTON6MOUSE",
148 "BUTTON7MOUSE",
149 "ACTIONMOUSE", "SELECTMOUSE", "MOUSEMOVE", "INBETWEEN_MOUSEMOVE", "TRACKPADPAN", "TRACKPADZOOM",
150 "MOUSEROTATE", "WHEELUPMOUSE", "WHEELDOWNMOUSE", "WHEELINMOUSE", "WHEELOUTMOUSE", "EVT_TWEAK_L",
151 "EVT_TWEAK_M", "EVT_TWEAK_R", "EVT_TWEAK_A", "EVT_TWEAK_S", "A", "B", "C", "D", "E", "F", "G", "H",
152 "I", "J",
153 "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "ZERO", "ONE", "TWO",
154 "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "LEFT_CTRL", "LEFT_ALT", "LEFT_SHIFT",
155 "RIGHT_ALT",
156 "RIGHT_CTRL", "RIGHT_SHIFT", "OSKEY", "GRLESS", "ESC", "TAB", "RET", "SPACE", "LINE_FEED",
157 "BACK_SPACE",
158 "DEL", "SEMI_COLON", "PERIOD", "COMMA", "QUOTE", "ACCENT_GRAVE", "MINUS", "SLASH", "BACK_SLASH",
159 "EQUAL",
160 "LEFT_BRACKET", "RIGHT_BRACKET", "LEFT_ARROW", "DOWN_ARROW", "RIGHT_ARROW", "UP_ARROW", "NUMPAD_2",
161 "NUMPAD_4", "NUMPAD_6", "NUMPAD_8", "NUMPAD_1", "NUMPAD_3", "NUMPAD_5", "NUMPAD_7", "NUMPAD_9",
162 "NUMPAD_PERIOD", "NUMPAD_SLASH", "NUMPAD_ASTERIX", "NUMPAD_0", "NUMPAD_MINUS", "NUMPAD_ENTER",
163 "NUMPAD_PLUS",
164 "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15",
165 "F16", "F17",
166 "F18", "F19", "PAUSE", "INSERT", "HOME", "PAGE_UP", "PAGE_DOWN", "END", "MEDIA_PLAY", "MEDIA_STOP",
167 "MEDIA_FIRST", "MEDIA_LAST", "TEXTINPUT", "WINDOW_DEACTIVATE", "TIMER", "TIMER0", "TIMER1", "TIMER2",
168 "TIMER_JOBS", "TIMER_AUTOSAVE", "TIMER_REPORT", "TIMERREGION", "NDOF_MOTION", "NDOF_BUTTON_MENU",
169 "NDOF_BUTTON_FIT", "NDOF_BUTTON_TOP", "NDOF_BUTTON_BOTTOM", "NDOF_BUTTON_LEFT", "NDOF_BUTTON_RIGHT",
170 "NDOF_BUTTON_FRONT", "NDOF_BUTTON_BACK", "NDOF_BUTTON_ISO1", "NDOF_BUTTON_ISO2",
171 "NDOF_BUTTON_ROLL_CW",
172 "NDOF_BUTTON_ROLL_CCW", "NDOF_BUTTON_SPIN_CW", "NDOF_BUTTON_SPIN_CCW", "NDOF_BUTTON_TILT_CW",
173 "NDOF_BUTTON_TILT_CCW", "NDOF_BUTTON_ROTATE", "NDOF_BUTTON_PANZOOM", "NDOF_BUTTON_DOMINANT",
174 "NDOF_BUTTON_PLUS", "NDOF_BUTTON_MINUS", "NDOF_BUTTON_ESC", "NDOF_BUTTON_ALT", "NDOF_BUTTON_SHIFT",
175 "NDOF_BUTTON_CTRL", "NDOF_BUTTON_1", "NDOF_BUTTON_2", "NDOF_BUTTON_3", "NDOF_BUTTON_4",
176 "NDOF_BUTTON_5",
177 "NDOF_BUTTON_6", "NDOF_BUTTON_7", "NDOF_BUTTON_8", "NDOF_BUTTON_9", "NDOF_BUTTON_10",
178 "NDOF_BUTTON_A",
179 "NDOF_BUTTON_B", "NDOF_BUTTON_C"
181 try:
182 allkeys.index(txt)
183 return True
184 except ValueError:
185 return False
188 mychecker = MyChecker() # Global class handler
191 # ------------------------------------------------------
192 # Button: Class for search button
193 # ------------------------------------------------------
196 class RunActionCheck(Operator):
197 bl_idname = "iskeyfree.action_check"
198 bl_label = ""
199 bl_description = "Verify if the selected shortcut is free"
201 # ------------------------------
202 # Execute
203 # ------------------------------
204 # noinspection PyUnusedLocal
205 def execute(self, context):
206 scene = context.scene.is_keyfree
207 txt = scene.data.upper()
208 global mychecker
209 mychecker.check(txt, scene.use_crtl, scene.use_alt, scene.use_shift,
210 scene.use_oskey)
212 return {'FINISHED'}
215 # ------------------------------------------------------
216 # Defines UI panel
217 # ------------------------------------------------------
218 class UIControlPanel(Panel):
219 bl_idname = "DEVISKEYFREE_PT_ui"
220 bl_space_type = "TEXT_EDITOR"
221 bl_region_type = "UI"
222 bl_label = "Is Key Free"
224 # noinspection PyUnusedLocal
225 def draw(self, context):
226 layout = self.layout
227 scene = context.scene.is_keyfree
229 row = layout.row(align=True)
230 row.prop(scene, "data")
231 row.operator("iskeyfree.action_check", icon="VIEWZOOM")
233 row = layout.row(align=True)
234 row.prop(scene, "use_crtl", toggle=True)
235 row.prop(scene, "use_alt", toggle=True)
236 row.prop(scene, "use_shift", toggle=True)
237 row.prop(scene, "use_oskey", toggle=True)
239 row = layout.row()
240 row.prop(scene, "numpad")
242 global mychecker
243 mylist = mychecker.getlist()
244 oldcontext = None
246 box = None
247 if len(mylist) > 0:
248 cmd = mychecker.getlast()
249 if cmd is not None:
250 row = layout.row()
251 row.label("Current uses of " + str(cmd), icon="PARTICLE_DATA")
252 for e in mylist:
253 if oldcontext != e[0]:
254 box = layout.box()
255 box.label(e[0], icon="UNPINNED")
256 oldcontext = e[0]
258 row = box.row(align=True)
259 row.label(e[1])
260 else:
261 cmd = mychecker.getlast()
262 if cmd is not None:
263 box = layout.box()
264 if mychecker.isvalidkey(mychecker.getlastkey()) is False:
265 box.label(str(mychecker.getlastkey()) + " looks not valid key", icon="ERROR")
266 else:
267 box.label(str(cmd) + " is free", icon="FILE_TICK")
270 # ------------------------------------------------------
271 # Update key (special values) event handler
272 # ------------------------------------------------------
275 # noinspection PyUnusedLocal
276 def update_data(self, context):
277 scene = context.scene.is_keyfree
278 if scene.numpad != "NONE":
279 scene.data = scene.numpad
282 class IskeyFreeProperties(PropertyGroup):
283 data = StringProperty(
284 name="Key", maxlen=32,
285 description="Shortcut to verify"
287 use_crtl = BoolProperty(
288 name="Ctrl",
289 description="Ctrl key used in shortcut",
290 default=False
292 use_alt = BoolProperty(
293 name="Alt",
294 description="Alt key used in shortcut",
295 default=False
297 use_shift = BoolProperty(
298 name="Shift",
299 description="Shift key used in shortcut",
300 default=False
302 use_oskey = BoolProperty(
303 name="OsKey",
304 description="Operating system key used in shortcut",
305 default=False
307 numpad = EnumProperty(
308 items=(('NONE', "Select key", ""),
309 ("LEFTMOUSE", "LEFTMOUSE", ""),
310 ("MIDDLEMOUSE", "MIDDLEMOUSE", ""),
311 ("RIGHTMOUSE", "RIGHTMOUSE", ""),
312 ("BUTTON4MOUSE", "BUTTON4MOUSE", ""),
313 ("BUTTON5MOUSE", "BUTTON5MOUSE", ""),
314 ("BUTTON6MOUSE", "BUTTON6MOUSE", ""),
315 ("BUTTON7MOUSE", "BUTTON7MOUSE", ""),
316 ("ACTIONMOUSE", "ACTIONMOUSE", ""),
317 ("SELECTMOUSE", "SELECTMOUSE", ""),
318 ("MOUSEMOVE", "MOUSEMOVE", ""),
319 ("INBETWEEN_MOUSEMOVE", "INBETWEEN_MOUSEMOVE", ""),
320 ("TRACKPADPAN", "TRACKPADPAN", ""),
321 ("TRACKPADZOOM", "TRACKPADZOOM", ""),
322 ("MOUSEROTATE", "MOUSEROTATE", ""),
323 ("WHEELUPMOUSE", "WHEELUPMOUSE", ""),
324 ("WHEELDOWNMOUSE", "WHEELDOWNMOUSE", ""),
325 ("WHEELINMOUSE", "WHEELINMOUSE", ""),
326 ("WHEELOUTMOUSE", "WHEELOUTMOUSE", ""),
327 ("EVT_TWEAK_L", "EVT_TWEAK_L", ""),
328 ("EVT_TWEAK_M", "EVT_TWEAK_M", ""),
329 ("EVT_TWEAK_R", "EVT_TWEAK_R", ""),
330 ("EVT_TWEAK_A", "EVT_TWEAK_A", ""),
331 ("EVT_TWEAK_S", "EVT_TWEAK_S", ""),
332 ("A", "A", ""),
333 ("B", "B", ""),
334 ("C", "C", ""),
335 ("D", "D", ""),
336 ("E", "E", ""),
337 ("F", "F", ""),
338 ("G", "G", ""),
339 ("H", "H", ""),
340 ("I", "I", ""),
341 ("J", "J", ""),
342 ("K", "K", ""),
343 ("L", "L", ""),
344 ("M", "M", ""),
345 ("N", "N", ""),
346 ("O", "O", ""),
347 ("P", "P", ""),
348 ("Q", "Q", ""),
349 ("R", "R", ""),
350 ("S", "S", ""),
351 ("T", "T", ""),
352 ("U", "U", ""),
353 ("V", "V", ""),
354 ("W", "W", ""),
355 ("X", "X", ""),
356 ("Y", "Y", ""),
357 ("Z", "Z", ""),
358 ("ZERO", "ZERO", ""),
359 ("ONE", "ONE", ""),
360 ("TWO", "TWO", ""),
361 ("THREE", "THREE", ""),
362 ("FOUR", "FOUR", ""),
363 ("FIVE", "FIVE", ""),
364 ("SIX", "SIX", ""),
365 ("SEVEN", "SEVEN", ""),
366 ("EIGHT", "EIGHT", ""),
367 ("NINE", "NINE", ""),
368 ("LEFT_CTRL", "LEFT_CTRL", ""),
369 ("LEFT_ALT", "LEFT_ALT", ""),
370 ("LEFT_SHIFT", "LEFT_SHIFT", ""),
371 ("RIGHT_ALT", "RIGHT_ALT", ""),
372 ("RIGHT_CTRL", "RIGHT_CTRL", ""),
373 ("RIGHT_SHIFT", "RIGHT_SHIFT", ""),
374 ("OSKEY", "OSKEY", ""),
375 ("GRLESS", "GRLESS", ""),
376 ("ESC", "ESC", ""),
377 ("TAB", "TAB", ""),
378 ("RET", "RET", ""),
379 ("SPACE", "SPACE", ""),
380 ("LINE_FEED", "LINE_FEED", ""),
381 ("BACK_SPACE", "BACK_SPACE", ""),
382 ("DEL", "DEL", ""),
383 ("SEMI_COLON", "SEMI_COLON", ""),
384 ("PERIOD", "PERIOD", ""),
385 ("COMMA", "COMMA", ""),
386 ("QUOTE", "QUOTE", ""),
387 ("ACCENT_GRAVE", "ACCENT_GRAVE", ""),
388 ("MINUS", "MINUS", ""),
389 ("SLASH", "SLASH", ""),
390 ("BACK_SLASH", "BACK_SLASH", ""),
391 ("EQUAL", "EQUAL", ""),
392 ("LEFT_BRACKET", "LEFT_BRACKET", ""),
393 ("RIGHT_BRACKET", "RIGHT_BRACKET", ""),
394 ("LEFT_ARROW", "LEFT_ARROW", ""),
395 ("DOWN_ARROW", "DOWN_ARROW", ""),
396 ("RIGHT_ARROW", "RIGHT_ARROW", ""),
397 ("UP_ARROW", "UP_ARROW", ""),
398 ("NUMPAD_1", "NUMPAD_1", ""),
399 ("NUMPAD_2", "NUMPAD_2", ""),
400 ("NUMPAD_3", "NUMPAD_3", ""),
401 ("NUMPAD_4", "NUMPAD_4", ""),
402 ("NUMPAD_5", "NUMPAD_5", ""),
403 ("NUMPAD_6", "NUMPAD_6", ""),
404 ("NUMPAD_7", "NUMPAD_7", ""),
405 ("NUMPAD_8", "NUMPAD_8", ""),
406 ("NUMPAD_9", "NUMPAD_9", ""),
407 ("NUMPAD_0", "NUMPAD_0", ""),
408 ("NUMPAD_PERIOD", "NUMPAD_PERIOD", ""),
409 ("NUMPAD_SLASH", "NUMPAD_SLASH", ""),
410 ("NUMPAD_ASTERIX", "NUMPAD_ASTERIX", ""),
411 ("NUMPAD_MINUS", "NUMPAD_MINUS", ""),
412 ("NUMPAD_ENTER", "NUMPAD_ENTER", ""),
413 ("NUMPAD_PLUS", "NUMPAD_PLUS", ""),
414 ("F1", "F1", ""),
415 ("F2", "F2", ""),
416 ("F3", "F3", ""),
417 ("F4", "F4", ""),
418 ("F5", "F5", ""),
419 ("F6", "F6", ""),
420 ("F7", "F7", ""),
421 ("F8", "F8", ""),
422 ("F9", "F9", ""),
423 ("F10", "F10", ""),
424 ("F11", "F11", ""),
425 ("F12", "F12", ""),
426 ("F13", "F13", ""),
427 ("F14", "F14", ""),
428 ("F15", "F15", ""),
429 ("F16", "F16", ""),
430 ("F17", "F17", ""),
431 ("F18", "F18", ""),
432 ("F19", "F19", ""),
433 ("PAUSE", "PAUSE", ""),
434 ("INSERT", "INSERT", ""),
435 ("HOME", "HOME", ""),
436 ("PAGE_UP", "PAGE_UP", ""),
437 ("PAGE_DOWN", "PAGE_DOWN", ""),
438 ("END", "END", ""),
439 ("MEDIA_PLAY", "MEDIA_PLAY", ""),
440 ("MEDIA_STOP", "MEDIA_STOP", ""),
441 ("MEDIA_FIRST", "MEDIA_FIRST", ""),
442 ("MEDIA_LAST", "MEDIA_LAST", ""),
443 ("TEXTINPUT", "TEXTINPUT", ""),
444 ("WINDOW_DEACTIVATE", "WINDOW_DEACTIVATE", ""),
445 ("TIMER", "TIMER", ""),
446 ("TIMER0", "TIMER0", ""),
447 ("TIMER1", "TIMER1", ""),
448 ("TIMER2", "TIMER2", ""),
449 ("TIMER_JOBS", "TIMER_JOBS", ""),
450 ("TIMER_AUTOSAVE", "TIMER_AUTOSAVE", ""),
451 ("TIMER_REPORT", "TIMER_REPORT", ""),
452 ("TIMERREGION", "TIMERREGION", ""),
453 ("NDOF_MOTION", "NDOF_MOTION", ""),
454 ("NDOF_BUTTON_MENU", "NDOF_BUTTON_MENU", ""),
455 ("NDOF_BUTTON_FIT", "NDOF_BUTTON_FIT", ""),
456 ("NDOF_BUTTON_TOP", "NDOF_BUTTON_TOP", ""),
457 ("NDOF_BUTTON_BOTTOM", "NDOF_BUTTON_BOTTOM", ""),
458 ("NDOF_BUTTON_LEFT", "NDOF_BUTTON_LEFT", ""),
459 ("NDOF_BUTTON_RIGHT", "NDOF_BUTTON_RIGHT", ""),
460 ("NDOF_BUTTON_FRONT", "NDOF_BUTTON_FRONT", ""),
461 ("NDOF_BUTTON_BACK", "NDOF_BUTTON_BACK", ""),
462 ("NDOF_BUTTON_ISO1", "NDOF_BUTTON_ISO1", ""),
463 ("NDOF_BUTTON_ISO2", "NDOF_BUTTON_ISO2", ""),
464 ("NDOF_BUTTON_ROLL_CW", "NDOF_BUTTON_ROLL_CW", ""),
465 ("NDOF_BUTTON_ROLL_CCW", "NDOF_BUTTON_ROLL_CCW", ""),
466 ("NDOF_BUTTON_SPIN_CW", "NDOF_BUTTON_SPIN_CW", ""),
467 ("NDOF_BUTTON_SPIN_CCW", "NDOF_BUTTON_SPIN_CCW", ""),
468 ("NDOF_BUTTON_TILT_CW", "NDOF_BUTTON_TILT_CW", ""),
469 ("NDOF_BUTTON_TILT_CCW", "NDOF_BUTTON_TILT_CCW", ""),
470 ("NDOF_BUTTON_ROTATE", "NDOF_BUTTON_ROTATE", ""),
471 ("NDOF_BUTTON_PANZOOM", "NDOF_BUTTON_PANZOOM", ""),
472 ("NDOF_BUTTON_DOMINANT", "NDOF_BUTTON_DOMINANT", ""),
473 ("NDOF_BUTTON_PLUS", "NDOF_BUTTON_PLUS", ""),
474 ("NDOF_BUTTON_MINUS", "NDOF_BUTTON_MINUS", ""),
475 ("NDOF_BUTTON_ESC", "NDOF_BUTTON_ESC", ""),
476 ("NDOF_BUTTON_ALT", "NDOF_BUTTON_ALT", ""),
477 ("NDOF_BUTTON_SHIFT", "NDOF_BUTTON_SHIFT", ""),
478 ("NDOF_BUTTON_CTRL", "NDOF_BUTTON_CTRL", ""),
479 ("NDOF_BUTTON_1", "NDOF_BUTTON_1", ""),
480 ("NDOF_BUTTON_2", "NDOF_BUTTON_2", ""),
481 ("NDOF_BUTTON_3", "NDOF_BUTTON_3", ""),
482 ("NDOF_BUTTON_4", "NDOF_BUTTON_4", ""),
483 ("NDOF_BUTTON_5", "NDOF_BUTTON_5", ""),
484 ("NDOF_BUTTON_6", "NDOF_BUTTON_6", ""),
485 ("NDOF_BUTTON_7", "NDOF_BUTTON_7", ""),
486 ("NDOF_BUTTON_8", "NDOF_BUTTON_8", ""),
487 ("NDOF_BUTTON_9", "NDOF_BUTTON_9", ""),
488 ("NDOF_BUTTON_10", "NDOF_BUTTON_10", ""),
489 ("NDOF_BUTTON_A", "NDOF_BUTTON_A", ""),
490 ("NDOF_BUTTON_B", "NDOF_BUTTON_B", ""),
491 ("NDOF_BUTTON_C", "NDOF_BUTTON_C", "")
493 name="Quick Type",
494 description="Enter key code in find text",
495 update=update_data
499 # -----------------------------------------------------
500 # Registration
501 # ------------------------------------------------------
503 def register():
504 bpy.utils.register_module(__name__)
505 bpy.types.Scene.is_keyfree = PointerProperty(type=IskeyFreeProperties)
508 def unregister():
509 bpy.utils.unregister_module(__name__)
510 del bpy.types.Scene.is_keyfree