Post #2873: : post_02874, post_03369
๐ท๏ธ Tags
hotkeys configuration advanced solved
โ๏ธ Related PME Features
- Hotkey Configuration
- Python Scripting
๐ฌ Content
Flattiefolks:
Is there any way to call the workspaces dropdown menu from your script within any blender view window by keyboard shortcut? So far this only worked for a โRun Scriptโ shortcut within the text editor area only.
Yes, use Screen Editing keymap which allows to override all existing keyboard shortcuts in all areas.
Eg (ctrl+shift+Space shortcut):
import bpy
class WORKSPACE_OT_select(bpy.types.Operator):
bl_idname = "workspace.select"
bl_label = "Select Workspace"
bl_description = "Select workspace"
bl_property = "workspace"
enum_items = None
def get_items(self, context):
if WORKSPACE_OT_select.enum_items is None:
enum_items = []
for w in bpy.data.workspaces:
identifier, name, description = \
w.name, w.name, w.name
if context.workspace.name == identifier:
name += "|Active"
enum_items.append((
identifier,
name,
description))
WORKSPACE_OT_select.enum_items = enum_items
return WORKSPACE_OT_select.enum_items
workspace = bpy.props.EnumProperty(items=get_items)
def execute(self, context):
if not self.workspace or self.workspace not in bpy.data.workspaces:
return {'CANCELLED'}
context.window.workspace = bpy.data.workspaces[self.workspace]
return {'FINISHED'}
def invoke(self, context, event):
WORKSPACE_OT_select.enum_items = None
context.window_manager.invoke_search_popup(self)
return {'FINISHED'}
addon_keymaps = []
def register():
bpy.utils.register_class(WORKSPACE_OT_select)
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(
name='Screen Editing')
kmi = km.keymap_items.new(
WORKSPACE_OT_select.bl_idname, 'SPACE', 'PRESS',
ctrl=True, shift=True)
addon_keymaps.append((km, kmi))
def unregister():
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()
bpy.utils.unregister_class(WORKSPACE_OT_select)
if __name__ == "__main__":
register()
โค๏ธ 4 likes