mirror of
https://github.com/blender/blender-addons.git
synced 2025-08-20 13:22:58 +00:00
Is key Free: Use property group for Scene props
Bumped version to 1.0.2 Move the scene properties into a separate group The props can be accessed through bpy.context.scene.is_keyfree
This commit is contained in:
@ -19,16 +19,26 @@
|
||||
# PEP8 compliant (https://www.python.org/dev/peps/pep-0008)
|
||||
|
||||
bl_info = {
|
||||
'name': 'Is key Free',
|
||||
'author': 'Antonio Vazquez (antonioya)',
|
||||
'version': (1, 0, 1),
|
||||
"name": "Is key Free",
|
||||
"author": "Antonio Vazquez (antonioya)",
|
||||
"version": (1, 0, 2),
|
||||
"blender": (2, 6, 9),
|
||||
'location': 'Properties pane > IsKeyFree Tools',
|
||||
'description': 'Find free shortcuts and inform of used keys',
|
||||
'category': 'Development'}
|
||||
"location": "Properties pane > IsKeyFree Tools",
|
||||
"description": "Find free shortcuts and inform of used keys",
|
||||
"category": "Development"}
|
||||
|
||||
import bpy
|
||||
from bpy.props import StringProperty, BoolProperty, EnumProperty
|
||||
from bpy.props import (
|
||||
StringProperty,
|
||||
BoolProperty,
|
||||
EnumProperty,
|
||||
PointerProperty,
|
||||
)
|
||||
from bpy.types import (
|
||||
Operator,
|
||||
Panel,
|
||||
PropertyGroup,
|
||||
)
|
||||
|
||||
|
||||
# ------------------------------------------------------
|
||||
@ -66,6 +76,7 @@ class MyChecker():
|
||||
|
||||
wm = bpy.context.window_manager
|
||||
mykeys = []
|
||||
|
||||
for context, keyboardmap in wm.keyconfigs.user.keymaps.items():
|
||||
for myitem in keyboardmap.keymap_items:
|
||||
if myitem.active is True and myitem.type == findkey:
|
||||
@ -77,7 +88,6 @@ class MyChecker():
|
||||
continue
|
||||
if oskey is True and myitem.oskey is not True:
|
||||
continue
|
||||
|
||||
t = (context,
|
||||
myitem.type,
|
||||
"Ctrl" if myitem.ctrl is True else "",
|
||||
@ -131,7 +141,8 @@ class MyChecker():
|
||||
# verify if key is valid
|
||||
@classmethod
|
||||
def isvalidkey(cls, txt):
|
||||
allkeys = ["LEFTMOUSE", "MIDDLEMOUSE", "RIGHTMOUSE", "BUTTON4MOUSE", "BUTTON5MOUSE", "BUTTON6MOUSE",
|
||||
allkeys = [
|
||||
"LEFTMOUSE", "MIDDLEMOUSE", "RIGHTMOUSE", "BUTTON4MOUSE", "BUTTON5MOUSE", "BUTTON6MOUSE",
|
||||
"BUTTON7MOUSE",
|
||||
"ACTIONMOUSE", "SELECTMOUSE", "MOUSEMOVE", "INBETWEEN_MOUSEMOVE", "TRACKPADPAN", "TRACKPADZOOM",
|
||||
"MOUSEROTATE", "WHEELUPMOUSE", "WHEELDOWNMOUSE", "WHEELINMOUSE", "WHEELOUTMOUSE", "EVT_TWEAK_L",
|
||||
@ -163,13 +174,15 @@ class MyChecker():
|
||||
"NDOF_BUTTON_5",
|
||||
"NDOF_BUTTON_6", "NDOF_BUTTON_7", "NDOF_BUTTON_8", "NDOF_BUTTON_9", "NDOF_BUTTON_10",
|
||||
"NDOF_BUTTON_A",
|
||||
"NDOF_BUTTON_B", "NDOF_BUTTON_C"]
|
||||
"NDOF_BUTTON_B", "NDOF_BUTTON_C"
|
||||
]
|
||||
try:
|
||||
allkeys.index(txt)
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
|
||||
mychecker = MyChecker() # Global class handler
|
||||
|
||||
|
||||
@ -178,7 +191,7 @@ mychecker = MyChecker() # Global class handler
|
||||
# ------------------------------------------------------
|
||||
|
||||
|
||||
class RunActionCheck(bpy.types.Operator):
|
||||
class RunActionCheck(Operator):
|
||||
bl_idname = "iskeyfree.action_check"
|
||||
bl_label = ""
|
||||
bl_description = "Verify if the selected shortcut is free"
|
||||
@ -188,11 +201,11 @@ class RunActionCheck(bpy.types.Operator):
|
||||
# ------------------------------
|
||||
# noinspection PyUnusedLocal
|
||||
def execute(self, context):
|
||||
scene = context.scene
|
||||
txt = scene.iskeyfree_data.upper()
|
||||
scene = context.scene.is_keyfree
|
||||
txt = scene.data.upper()
|
||||
global mychecker
|
||||
mychecker.check(txt, scene.iskeyfree_use_crtl, scene.iskeyfree_use_alt, scene.iskeyfree_use_shift,
|
||||
scene.iskeyfree_use_oskey)
|
||||
mychecker.check(txt, scene.use_crtl, scene.use_alt, scene.use_shift,
|
||||
scene.use_oskey)
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
@ -200,7 +213,7 @@ class RunActionCheck(bpy.types.Operator):
|
||||
# ------------------------------------------------------
|
||||
# Defines UI panel
|
||||
# ------------------------------------------------------
|
||||
class UIControlPanel(bpy.types.Panel):
|
||||
class UIControlPanel(Panel):
|
||||
bl_space_type = "TEXT_EDITOR"
|
||||
bl_region_type = "UI"
|
||||
bl_label = "Is Key Free"
|
||||
@ -208,20 +221,20 @@ class UIControlPanel(bpy.types.Panel):
|
||||
# noinspection PyUnusedLocal
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
scene = context.scene
|
||||
scene = context.scene.is_keyfree
|
||||
|
||||
row = layout.row(align=True)
|
||||
row.prop(scene, "iskeyfree_data")
|
||||
row.prop(scene, "data")
|
||||
row.operator("iskeyfree.action_check", icon="VIEWZOOM")
|
||||
|
||||
row = layout.row(align=True)
|
||||
row.prop(scene, "iskeyfree_use_crtl", toggle=True)
|
||||
row.prop(scene, "iskeyfree_use_alt", toggle=True)
|
||||
row.prop(scene, "iskeyfree_use_shift", toggle=True)
|
||||
row.prop(scene, "iskeyfree_use_oskey", toggle=True)
|
||||
row.prop(scene, "use_crtl", toggle=True)
|
||||
row.prop(scene, "use_alt", toggle=True)
|
||||
row.prop(scene, "use_shift", toggle=True)
|
||||
row.prop(scene, "use_oskey", toggle=True)
|
||||
|
||||
row = layout.row()
|
||||
row.prop(scene, "iskeyfree_numpad")
|
||||
row.prop(scene, "numpad")
|
||||
|
||||
global mychecker
|
||||
mylist = mychecker.getlist()
|
||||
@ -258,34 +271,38 @@ class UIControlPanel(bpy.types.Panel):
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
def update_data(self, context):
|
||||
scene = context.scene
|
||||
if scene.iskeyfree_numpad != "NONE":
|
||||
scene.iskeyfree_data = scene.iskeyfree_numpad
|
||||
scene = context.scene.is_keyfree
|
||||
if scene.numpad != "NONE":
|
||||
scene.data = scene.numpad
|
||||
|
||||
|
||||
# ------------------------------------------------------
|
||||
# Registration
|
||||
# ------------------------------------------------------
|
||||
|
||||
|
||||
def register():
|
||||
bpy.utils.register_module(__name__)
|
||||
|
||||
bpy.types.Scene.iskeyfree_data = StringProperty(name="Key", maxlen=32,
|
||||
description="Shortcut to verify")
|
||||
bpy.types.Scene.iskeyfree_use_crtl = BoolProperty(name="Ctrl",
|
||||
class IskeyFreeProperties(PropertyGroup):
|
||||
data = StringProperty(
|
||||
name="Key", maxlen=32,
|
||||
description="Shortcut to verify"
|
||||
)
|
||||
use_crtl = BoolProperty(
|
||||
name="Ctrl",
|
||||
description="Ctrl key used in shortcut",
|
||||
default=False)
|
||||
bpy.types.Scene.iskeyfree_use_alt = BoolProperty(name="Alt",
|
||||
default=False
|
||||
)
|
||||
use_alt = BoolProperty(
|
||||
name="Alt",
|
||||
description="Alt key used in shortcut",
|
||||
default=False)
|
||||
bpy.types.Scene.iskeyfree_use_shift = BoolProperty(name="Shift",
|
||||
default=False
|
||||
)
|
||||
use_shift = BoolProperty(
|
||||
name="Shift",
|
||||
description="Shift key used in shortcut",
|
||||
default=False)
|
||||
bpy.types.Scene.iskeyfree_use_oskey = BoolProperty(name="OsKey",
|
||||
default=False
|
||||
)
|
||||
use_oskey = BoolProperty(
|
||||
name="OsKey",
|
||||
description="Operating system key used in shortcut",
|
||||
default=False)
|
||||
bpy.types.Scene.iskeyfree_numpad = EnumProperty(items=(('NONE', "Select key", ""),
|
||||
default=False
|
||||
)
|
||||
numpad = EnumProperty(
|
||||
items=(('NONE', "Select key", ""),
|
||||
("LEFTMOUSE", "LEFTMOUSE", ""),
|
||||
("MIDDLEMOUSE", "MIDDLEMOUSE", ""),
|
||||
("RIGHTMOUSE", "RIGHTMOUSE", ""),
|
||||
@ -442,24 +459,14 @@ def register():
|
||||
("NDOF_BUTTON_ISO1", "NDOF_BUTTON_ISO1", ""),
|
||||
("NDOF_BUTTON_ISO2", "NDOF_BUTTON_ISO2", ""),
|
||||
("NDOF_BUTTON_ROLL_CW", "NDOF_BUTTON_ROLL_CW", ""),
|
||||
("NDOF_BUTTON_ROLL_CCW", "NDOF_BUTTON_ROLL_CCW",
|
||||
""),
|
||||
(
|
||||
"NDOF_BUTTON_SPIN_CW", "NDOF_BUTTON_SPIN_CW",
|
||||
""),
|
||||
("NDOF_BUTTON_SPIN_CCW", "NDOF_BUTTON_SPIN_CCW",
|
||||
""),
|
||||
(
|
||||
"NDOF_BUTTON_TILT_CW", "NDOF_BUTTON_TILT_CW",
|
||||
""),
|
||||
("NDOF_BUTTON_TILT_CCW", "NDOF_BUTTON_TILT_CCW",
|
||||
""),
|
||||
("NDOF_BUTTON_ROLL_CCW", "NDOF_BUTTON_ROLL_CCW", ""),
|
||||
("NDOF_BUTTON_SPIN_CW", "NDOF_BUTTON_SPIN_CW", ""),
|
||||
("NDOF_BUTTON_SPIN_CCW", "NDOF_BUTTON_SPIN_CCW", ""),
|
||||
("NDOF_BUTTON_TILT_CW", "NDOF_BUTTON_TILT_CW", ""),
|
||||
("NDOF_BUTTON_TILT_CCW", "NDOF_BUTTON_TILT_CCW", ""),
|
||||
("NDOF_BUTTON_ROTATE", "NDOF_BUTTON_ROTATE", ""),
|
||||
(
|
||||
"NDOF_BUTTON_PANZOOM", "NDOF_BUTTON_PANZOOM",
|
||||
""),
|
||||
("NDOF_BUTTON_DOMINANT", "NDOF_BUTTON_DOMINANT",
|
||||
""),
|
||||
("NDOF_BUTTON_PANZOOM", "NDOF_BUTTON_PANZOOM", ""),
|
||||
("NDOF_BUTTON_DOMINANT", "NDOF_BUTTON_DOMINANT", ""),
|
||||
("NDOF_BUTTON_PLUS", "NDOF_BUTTON_PLUS", ""),
|
||||
("NDOF_BUTTON_MINUS", "NDOF_BUTTON_MINUS", ""),
|
||||
("NDOF_BUTTON_ESC", "NDOF_BUTTON_ESC", ""),
|
||||
@ -478,18 +485,23 @@ def register():
|
||||
("NDOF_BUTTON_10", "NDOF_BUTTON_10", ""),
|
||||
("NDOF_BUTTON_A", "NDOF_BUTTON_A", ""),
|
||||
("NDOF_BUTTON_B", "NDOF_BUTTON_B", ""),
|
||||
("NDOF_BUTTON_C", "NDOF_BUTTON_C", "")),
|
||||
("NDOF_BUTTON_C", "NDOF_BUTTON_C", "")
|
||||
),
|
||||
name="Quick Type",
|
||||
description="Enter key code in find text",
|
||||
update=update_data)
|
||||
update=update_data
|
||||
)
|
||||
|
||||
|
||||
# -----------------------------------------------------
|
||||
# Registration
|
||||
# ------------------------------------------------------
|
||||
|
||||
def register():
|
||||
bpy.utils.register_module(__name__)
|
||||
bpy.types.Scene.is_keyfree = PointerProperty(type=IskeyFreeProperties)
|
||||
|
||||
|
||||
def unregister():
|
||||
bpy.utils.unregister_module(__name__)
|
||||
|
||||
del bpy.types.Scene.iskeyfree_use_crtl
|
||||
del bpy.types.Scene.iskeyfree_use_alt
|
||||
del bpy.types.Scene.iskeyfree_use_shift
|
||||
del bpy.types.Scene.iskeyfree_use_oskey
|
||||
del bpy.types.Scene.iskeyfree_numpad
|
||||
del bpy.types.Scene.iskeyfree_data
|
||||
del bpy.types.Scene.is_keyfree
|
||||
|
Reference in New Issue
Block a user