2010-04-14 07:09:01 +00:00
|
|
|
# ##### BEGIN GPL LICENSE BLOCK #####
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
# ##### END GPL LICENSE BLOCK #####
|
|
|
|
|
|
|
|
# <pep8 compliant>
|
|
|
|
import bpy
|
2012-04-08 13:11:25 +00:00
|
|
|
from bpy.types import Menu
|
2013-02-10 10:29:38 +00:00
|
|
|
from bpy.app.translations import pgettext_iface as iface_
|
2013-02-10 09:09:26 +00:00
|
|
|
|
2010-04-14 07:09:01 +00:00
|
|
|
|
2011-08-12 06:57:00 +00:00
|
|
|
class USERPREF_MT_keyconfigs(Menu):
|
2011-09-15 13:20:18 +00:00
|
|
|
bl_label = "KeyPresets"
|
2010-09-14 16:45:24 +00:00
|
|
|
preset_subdir = "keyconfig"
|
|
|
|
preset_operator = "wm.keyconfig_activate"
|
2011-01-01 07:20:34 +00:00
|
|
|
|
2010-09-14 16:45:24 +00:00
|
|
|
def draw(self, context):
|
2011-09-21 15:18:38 +00:00
|
|
|
props = self.layout.operator("wm.context_set_value", text="Blender (default)")
|
2010-09-14 16:45:24 +00:00
|
|
|
props.data_path = "window_manager.keyconfigs.active"
|
|
|
|
props.value = "context.window_manager.keyconfigs.default"
|
|
|
|
|
|
|
|
# now draw the presets
|
2011-08-12 06:57:00 +00:00
|
|
|
Menu.draw_preset(self, context)
|
2010-09-14 16:45:24 +00:00
|
|
|
|
|
|
|
|
2011-05-19 09:52:11 +00:00
|
|
|
class InputKeyMapPanel:
|
2010-04-14 07:09:01 +00:00
|
|
|
bl_space_type = 'USER_PREFERENCES'
|
2011-09-15 13:20:18 +00:00
|
|
|
bl_label = "Input"
|
2010-04-14 07:09:01 +00:00
|
|
|
bl_region_type = 'WINDOW'
|
2010-08-26 01:05:37 +00:00
|
|
|
bl_options = {'HIDE_HEADER'}
|
2010-04-17 19:05:53 +00:00
|
|
|
|
2010-04-14 07:09:01 +00:00
|
|
|
def draw_entry(self, display_keymaps, entry, col, level=0):
|
|
|
|
idname, spaceid, regionid, children = entry
|
|
|
|
|
|
|
|
for km, kc in display_keymaps:
|
|
|
|
if km.name == idname and km.space_type == spaceid and km.region_type == regionid:
|
|
|
|
self.draw_km(display_keymaps, kc, km, children, col, level)
|
2010-04-17 19:05:53 +00:00
|
|
|
|
2010-04-14 07:09:01 +00:00
|
|
|
'''
|
2010-08-30 13:50:59 +00:00
|
|
|
km = kc.keymaps.find(idname, space_type=spaceid, region_type=regionid)
|
2010-04-14 07:09:01 +00:00
|
|
|
if not km:
|
|
|
|
kc = defkc
|
2010-08-30 13:50:59 +00:00
|
|
|
km = kc.keymaps.find(idname, space_type=spaceid, region_type=regionid)
|
2010-04-17 19:05:53 +00:00
|
|
|
|
2010-04-14 07:09:01 +00:00
|
|
|
if km:
|
|
|
|
self.draw_km(kc, km, children, col, level)
|
|
|
|
'''
|
|
|
|
|
|
|
|
def indented_layout(self, layout, level):
|
|
|
|
indentpx = 16
|
|
|
|
if level == 0:
|
|
|
|
level = 0.0001 # Tweak so that a percentage of 0 won't split by half
|
2010-08-20 10:02:21 +00:00
|
|
|
indent = level * indentpx / bpy.context.region.width
|
2010-04-14 07:09:01 +00:00
|
|
|
|
|
|
|
split = layout.split(percentage=indent)
|
|
|
|
col = split.column()
|
|
|
|
col = split.column()
|
|
|
|
return col
|
|
|
|
|
|
|
|
def draw_km(self, display_keymaps, kc, km, children, layout, level):
|
|
|
|
km = km.active()
|
|
|
|
|
2010-09-03 07:25:37 +00:00
|
|
|
layout.context_pointer_set("keymap", km)
|
2010-04-14 07:09:01 +00:00
|
|
|
|
|
|
|
col = self.indented_layout(layout, level)
|
|
|
|
|
|
|
|
row = col.row()
|
2010-08-17 17:03:52 +00:00
|
|
|
row.prop(km, "show_expanded_children", text="", emboss=False)
|
2011-09-21 15:18:38 +00:00
|
|
|
row.label(text=km.name)
|
2010-04-14 07:09:01 +00:00
|
|
|
|
|
|
|
row.label()
|
|
|
|
row.label()
|
|
|
|
|
2010-08-18 07:14:10 +00:00
|
|
|
if km.is_modal:
|
2010-04-14 07:09:01 +00:00
|
|
|
row.label(text="", icon='LINKED')
|
KEYMAP REFACTORING
Diff Keymaps
User edited keymaps now no longer override the builtin keymaps entirely, but
rather save only the difference and reapply those changes. This means they can
stay better in sync when the builtin keymaps change. The diff/patch algorithm
is not perfect, but better for the common case where only a few items are changed
rather than entire keymaps The main weakness is that if a builtin keymap item
changes, user modification of that item may need to be redone in some cases.
Keymap Editor
The most noticeable change here is that there is no longer an "Edit" button for
keymaps, all are editable immediately, but a "Restore" buttons shows for keymaps
and items that have been edited. Shortcuts for addons can also be edited in the
keymap editor.
Addons
Addons now should only modify the new addon keyconfiguration, the keymap items
there will be added to the builtin ones for handling events, and not get lost
when starting new files. Example code of register/unregister:
km = wm.keyconfigs.addon.keymaps.new("3D View", space_type="VIEW_3D")
km.keymap_items.new('my.operator', 'ESC', 'PRESS')
km = wm.keyconfigs.addon.keymaps["3D View"]
km.keymap_items.remove(km.keymap_items["my.operator"])
Compatibility
The changes made are not forward compatible, i.e. if you save user preferences
with newer versions, older versions will not have key configuration changes that
were made.
2011-08-05 20:45:26 +00:00
|
|
|
if km.is_user_modified:
|
2011-09-21 15:18:38 +00:00
|
|
|
row.operator("wm.keymap_restore", text="Restore")
|
2010-04-14 07:09:01 +00:00
|
|
|
else:
|
KEYMAP REFACTORING
Diff Keymaps
User edited keymaps now no longer override the builtin keymaps entirely, but
rather save only the difference and reapply those changes. This means they can
stay better in sync when the builtin keymaps change. The diff/patch algorithm
is not perfect, but better for the common case where only a few items are changed
rather than entire keymaps The main weakness is that if a builtin keymap item
changes, user modification of that item may need to be redone in some cases.
Keymap Editor
The most noticeable change here is that there is no longer an "Edit" button for
keymaps, all are editable immediately, but a "Restore" buttons shows for keymaps
and items that have been edited. Shortcuts for addons can also be edited in the
keymap editor.
Addons
Addons now should only modify the new addon keyconfiguration, the keymap items
there will be added to the builtin ones for handling events, and not get lost
when starting new files. Example code of register/unregister:
km = wm.keyconfigs.addon.keymaps.new("3D View", space_type="VIEW_3D")
km.keymap_items.new('my.operator', 'ESC', 'PRESS')
km = wm.keyconfigs.addon.keymaps["3D View"]
km.keymap_items.remove(km.keymap_items["my.operator"])
Compatibility
The changes made are not forward compatible, i.e. if you save user preferences
with newer versions, older versions will not have key configuration changes that
were made.
2011-08-05 20:45:26 +00:00
|
|
|
row.label()
|
2010-04-14 07:09:01 +00:00
|
|
|
|
2010-08-17 17:03:52 +00:00
|
|
|
if km.show_expanded_children:
|
2010-04-14 07:09:01 +00:00
|
|
|
if children:
|
|
|
|
# Put the Parent key map's entries in a 'global' sub-category
|
|
|
|
# equal in hierarchy to the other children categories
|
|
|
|
subcol = self.indented_layout(col, level + 1)
|
|
|
|
subrow = subcol.row()
|
2010-08-17 17:03:52 +00:00
|
|
|
subrow.prop(km, "show_expanded_items", text="", emboss=False)
|
2013-02-10 10:29:38 +00:00
|
|
|
subrow.label(text=iface_("%s (Global)") % km.name, translate=False)
|
2010-04-14 07:09:01 +00:00
|
|
|
else:
|
2010-08-17 17:03:52 +00:00
|
|
|
km.show_expanded_items = True
|
2010-04-14 07:09:01 +00:00
|
|
|
|
|
|
|
# Key Map items
|
2010-08-17 17:03:52 +00:00
|
|
|
if km.show_expanded_items:
|
2011-03-25 02:12:44 +00:00
|
|
|
for kmi in km.keymap_items:
|
2010-04-14 07:09:01 +00:00
|
|
|
self.draw_kmi(display_keymaps, kc, km, kmi, col, level + 1)
|
|
|
|
|
|
|
|
# "Add New" at end of keymap item list
|
|
|
|
col = self.indented_layout(col, level + 1)
|
|
|
|
subcol = col.split(percentage=0.2).column()
|
2011-09-21 15:18:38 +00:00
|
|
|
subcol.operator("wm.keyitem_add", text="Add New", icon='ZOOMIN')
|
2010-04-14 07:09:01 +00:00
|
|
|
|
|
|
|
col.separator()
|
|
|
|
|
|
|
|
# Child key maps
|
|
|
|
if children:
|
|
|
|
subcol = col.column()
|
|
|
|
row = subcol.row()
|
|
|
|
|
|
|
|
for entry in children:
|
|
|
|
self.draw_entry(display_keymaps, entry, col, level + 1)
|
|
|
|
|
|
|
|
def draw_kmi(self, display_keymaps, kc, km, kmi, layout, level):
|
|
|
|
map_type = kmi.map_type
|
|
|
|
|
|
|
|
col = self.indented_layout(layout, level)
|
|
|
|
|
KEYMAP REFACTORING
Diff Keymaps
User edited keymaps now no longer override the builtin keymaps entirely, but
rather save only the difference and reapply those changes. This means they can
stay better in sync when the builtin keymaps change. The diff/patch algorithm
is not perfect, but better for the common case where only a few items are changed
rather than entire keymaps The main weakness is that if a builtin keymap item
changes, user modification of that item may need to be redone in some cases.
Keymap Editor
The most noticeable change here is that there is no longer an "Edit" button for
keymaps, all are editable immediately, but a "Restore" buttons shows for keymaps
and items that have been edited. Shortcuts for addons can also be edited in the
keymap editor.
Addons
Addons now should only modify the new addon keyconfiguration, the keymap items
there will be added to the builtin ones for handling events, and not get lost
when starting new files. Example code of register/unregister:
km = wm.keyconfigs.addon.keymaps.new("3D View", space_type="VIEW_3D")
km.keymap_items.new('my.operator', 'ESC', 'PRESS')
km = wm.keyconfigs.addon.keymaps["3D View"]
km.keymap_items.remove(km.keymap_items["my.operator"])
Compatibility
The changes made are not forward compatible, i.e. if you save user preferences
with newer versions, older versions will not have key configuration changes that
were made.
2011-08-05 20:45:26 +00:00
|
|
|
if kmi.show_expanded:
|
2010-04-14 07:09:01 +00:00
|
|
|
col = col.column(align=True)
|
|
|
|
box = col.box()
|
|
|
|
else:
|
|
|
|
box = col.column()
|
|
|
|
|
|
|
|
split = box.split(percentage=0.05)
|
|
|
|
|
|
|
|
# header bar
|
|
|
|
row = split.row()
|
2010-08-17 17:03:52 +00:00
|
|
|
row.prop(kmi, "show_expanded", text="", emboss=False)
|
2010-04-14 07:09:01 +00:00
|
|
|
|
|
|
|
row = split.row()
|
2010-06-26 20:00:45 +00:00
|
|
|
row.prop(kmi, "active", text="", emboss=False)
|
2010-04-14 07:09:01 +00:00
|
|
|
|
2010-08-18 07:14:10 +00:00
|
|
|
if km.is_modal:
|
2010-04-14 07:09:01 +00:00
|
|
|
row.prop(kmi, "propvalue", text="")
|
|
|
|
else:
|
2011-09-21 15:18:38 +00:00
|
|
|
row.label(text=kmi.name)
|
2010-04-14 07:09:01 +00:00
|
|
|
|
|
|
|
row = split.row()
|
|
|
|
row.prop(kmi, "map_type", text="")
|
|
|
|
if map_type == 'KEYBOARD':
|
|
|
|
row.prop(kmi, "type", text="", full_event=True)
|
|
|
|
elif map_type == 'MOUSE':
|
|
|
|
row.prop(kmi, "type", text="", full_event=True)
|
2011-08-02 07:08:22 +00:00
|
|
|
elif map_type == 'NDOF':
|
2011-07-21 21:43:42 +00:00
|
|
|
row.prop(kmi, "type", text="", full_event=True)
|
2010-04-14 07:09:01 +00:00
|
|
|
elif map_type == 'TWEAK':
|
|
|
|
subrow = row.row()
|
|
|
|
subrow.prop(kmi, "type", text="")
|
|
|
|
subrow.prop(kmi, "value", text="")
|
|
|
|
elif map_type == 'TIMER':
|
|
|
|
row.prop(kmi, "type", text="")
|
|
|
|
else:
|
|
|
|
row.label()
|
|
|
|
|
KEYMAP REFACTORING
Diff Keymaps
User edited keymaps now no longer override the builtin keymaps entirely, but
rather save only the difference and reapply those changes. This means they can
stay better in sync when the builtin keymaps change. The diff/patch algorithm
is not perfect, but better for the common case where only a few items are changed
rather than entire keymaps The main weakness is that if a builtin keymap item
changes, user modification of that item may need to be redone in some cases.
Keymap Editor
The most noticeable change here is that there is no longer an "Edit" button for
keymaps, all are editable immediately, but a "Restore" buttons shows for keymaps
and items that have been edited. Shortcuts for addons can also be edited in the
keymap editor.
Addons
Addons now should only modify the new addon keyconfiguration, the keymap items
there will be added to the builtin ones for handling events, and not get lost
when starting new files. Example code of register/unregister:
km = wm.keyconfigs.addon.keymaps.new("3D View", space_type="VIEW_3D")
km.keymap_items.new('my.operator', 'ESC', 'PRESS')
km = wm.keyconfigs.addon.keymaps["3D View"]
km.keymap_items.remove(km.keymap_items["my.operator"])
Compatibility
The changes made are not forward compatible, i.e. if you save user preferences
with newer versions, older versions will not have key configuration changes that
were made.
2011-08-05 20:45:26 +00:00
|
|
|
if (not kmi.is_user_defined) and kmi.is_user_modified:
|
2011-10-23 00:53:50 +00:00
|
|
|
row.operator("wm.keyitem_restore", text="", icon='BACK').item_id = kmi.id
|
KEYMAP REFACTORING
Diff Keymaps
User edited keymaps now no longer override the builtin keymaps entirely, but
rather save only the difference and reapply those changes. This means they can
stay better in sync when the builtin keymaps change. The diff/patch algorithm
is not perfect, but better for the common case where only a few items are changed
rather than entire keymaps The main weakness is that if a builtin keymap item
changes, user modification of that item may need to be redone in some cases.
Keymap Editor
The most noticeable change here is that there is no longer an "Edit" button for
keymaps, all are editable immediately, but a "Restore" buttons shows for keymaps
and items that have been edited. Shortcuts for addons can also be edited in the
keymap editor.
Addons
Addons now should only modify the new addon keyconfiguration, the keymap items
there will be added to the builtin ones for handling events, and not get lost
when starting new files. Example code of register/unregister:
km = wm.keyconfigs.addon.keymaps.new("3D View", space_type="VIEW_3D")
km.keymap_items.new('my.operator', 'ESC', 'PRESS')
km = wm.keyconfigs.addon.keymaps["3D View"]
km.keymap_items.remove(km.keymap_items["my.operator"])
Compatibility
The changes made are not forward compatible, i.e. if you save user preferences
with newer versions, older versions will not have key configuration changes that
were made.
2011-08-05 20:45:26 +00:00
|
|
|
else:
|
2011-10-23 00:53:50 +00:00
|
|
|
row.operator("wm.keyitem_remove", text="", icon='X').item_id = kmi.id
|
2010-04-14 07:09:01 +00:00
|
|
|
|
|
|
|
# Expanded, additional event settings
|
2010-08-17 17:03:52 +00:00
|
|
|
if kmi.show_expanded:
|
2010-04-14 07:09:01 +00:00
|
|
|
box = col.box()
|
|
|
|
|
2013-01-29 17:30:30 +00:00
|
|
|
split = box.split(percentage=0.4)
|
|
|
|
sub = split.row()
|
2010-04-14 07:09:01 +00:00
|
|
|
|
2013-01-29 17:30:30 +00:00
|
|
|
if km.is_modal:
|
|
|
|
sub.prop(kmi, "propvalue", text="")
|
|
|
|
else:
|
|
|
|
# One day...
|
|
|
|
#~ sub.prop_search(kmi, "idname", bpy.context.window_manager, "operators_all", text="")
|
|
|
|
sub.prop(kmi, "idname", text="")
|
2010-04-14 07:09:01 +00:00
|
|
|
|
2013-01-29 17:30:30 +00:00
|
|
|
if map_type not in {'TEXTINPUT', 'TIMER'}:
|
2010-04-14 07:09:01 +00:00
|
|
|
sub = split.column()
|
|
|
|
subrow = sub.row(align=True)
|
|
|
|
|
2012-10-31 11:31:25 +00:00
|
|
|
if map_type == 'KEYBOARD':
|
2010-04-14 07:09:01 +00:00
|
|
|
subrow.prop(kmi, "type", text="", event=True)
|
|
|
|
subrow.prop(kmi, "value", text="")
|
2012-10-31 11:31:25 +00:00
|
|
|
elif map_type in {'MOUSE', 'NDOF'}:
|
2010-04-14 07:09:01 +00:00
|
|
|
subrow.prop(kmi, "type", text="")
|
|
|
|
subrow.prop(kmi, "value", text="")
|
|
|
|
|
|
|
|
subrow = sub.row()
|
|
|
|
subrow.scale_x = 0.75
|
|
|
|
subrow.prop(kmi, "any")
|
|
|
|
subrow.prop(kmi, "shift")
|
|
|
|
subrow.prop(kmi, "ctrl")
|
|
|
|
subrow.prop(kmi, "alt")
|
|
|
|
subrow.prop(kmi, "oskey", text="Cmd")
|
|
|
|
subrow.prop(kmi, "key_modifier", text="", event=True)
|
|
|
|
|
|
|
|
# Operator properties
|
2011-10-04 13:24:48 +00:00
|
|
|
box.template_keymap_item_properties(kmi)
|
2010-04-14 07:09:01 +00:00
|
|
|
|
|
|
|
# Modal key maps attached to this operator
|
2010-08-18 07:14:10 +00:00
|
|
|
if not km.is_modal:
|
2010-08-30 13:50:59 +00:00
|
|
|
kmm = kc.keymaps.find_modal(kmi.idname)
|
2010-04-14 07:09:01 +00:00
|
|
|
if kmm:
|
|
|
|
self.draw_km(display_keymaps, kc, kmm, None, layout, level + 1)
|
2010-09-03 07:25:37 +00:00
|
|
|
layout.context_pointer_set("keymap", km)
|
2010-04-17 19:05:53 +00:00
|
|
|
|
2013-03-01 06:17:59 +00:00
|
|
|
_EVENT_TYPES = set()
|
|
|
|
_EVENT_TYPE_MAP = {}
|
2013-03-11 02:19:58 +00:00
|
|
|
|
2013-03-01 06:17:59 +00:00
|
|
|
def draw_filtered(self, display_keymaps, filter_type, filter_text, layout):
|
|
|
|
|
|
|
|
if filter_type == 'NAME':
|
|
|
|
def filter_func(kmi):
|
|
|
|
return (filter_text in kmi.idname.lower() or
|
|
|
|
filter_text in kmi.name.lower())
|
|
|
|
else:
|
|
|
|
if not self._EVENT_TYPES:
|
|
|
|
enum = bpy.types.Event.bl_rna.properties["type"].enum_items
|
|
|
|
self._EVENT_TYPES.update(enum.keys())
|
|
|
|
self._EVENT_TYPE_MAP.update({item.name.replace(" ", "_").upper(): key for key, item in enum.items()})
|
|
|
|
|
|
|
|
del enum
|
|
|
|
self._EVENT_TYPE_MAP.update({
|
2013-03-10 07:18:43 +00:00
|
|
|
"`": 'ACCENT_GRAVE',
|
2013-03-01 06:17:59 +00:00
|
|
|
"*": 'NUMPAD_ASTERIX',
|
|
|
|
"/": 'NUMPAD_SLASH',
|
|
|
|
"RMB": 'RIGHTMOUSE',
|
|
|
|
"LMB": 'LEFTMOUSE',
|
|
|
|
"MMB": 'MIDDLEMOUSE',
|
|
|
|
})
|
2013-03-10 07:18:43 +00:00
|
|
|
self._EVENT_TYPE_MAP.update({
|
|
|
|
"%d" % i: "NUMPAD_%d" % i for i in range(9)
|
|
|
|
})
|
2013-03-01 06:17:59 +00:00
|
|
|
# done with once off init
|
|
|
|
|
|
|
|
filter_text_split = filter_text.strip()
|
|
|
|
filter_text_split = filter_text.split()
|
|
|
|
|
|
|
|
# Modifier {kmi.attribute: name} mapping
|
|
|
|
key_mod = {
|
|
|
|
"ctrl": "ctrl",
|
|
|
|
"alt": "alt",
|
|
|
|
"shift": "shift",
|
|
|
|
"cmd": "oskey",
|
|
|
|
"oskey": "oskey",
|
|
|
|
"any": "any",
|
|
|
|
}
|
|
|
|
# KeyMapItem like dict, use for comparing against
|
|
|
|
# attr: state
|
|
|
|
kmi_test_dict = {}
|
|
|
|
|
|
|
|
# initialize? - so if a if a kmi has a MOD assigned it wont show up.
|
|
|
|
#~ for kv in key_mod.values():
|
|
|
|
#~ kmi_test_dict[kv] = False
|
|
|
|
|
|
|
|
# altname: attr
|
|
|
|
for kk, kv in key_mod.items():
|
|
|
|
if kk in filter_text_split:
|
|
|
|
filter_text_split.remove(kk)
|
|
|
|
kmi_test_dict[kv] = True
|
|
|
|
# whats left should be the event type
|
|
|
|
if len(filter_text_split) > 1:
|
|
|
|
return False
|
|
|
|
elif filter_text_split:
|
|
|
|
kmi_type = filter_text_split[0].upper()
|
2013-03-11 02:19:58 +00:00
|
|
|
|
2013-03-01 06:17:59 +00:00
|
|
|
if kmi_type not in self._EVENT_TYPES:
|
|
|
|
# replacement table
|
|
|
|
kmi_type_test = self._EVENT_TYPE_MAP.get(kmi_type)
|
|
|
|
if kmi_type_test is None:
|
|
|
|
# print("Unknown Type:", kmi_type)
|
2013-03-11 02:19:58 +00:00
|
|
|
|
2013-03-01 06:17:59 +00:00
|
|
|
# Partial match
|
|
|
|
for k, v in self._EVENT_TYPE_MAP.items():
|
|
|
|
if kmi_type in k:
|
|
|
|
kmi_type_test = v
|
|
|
|
break
|
|
|
|
if kmi_type in v:
|
|
|
|
kmi_type_test = v
|
|
|
|
break
|
|
|
|
|
|
|
|
if kmi_type_test is None:
|
|
|
|
return False
|
|
|
|
|
|
|
|
kmi_type = kmi_type_test
|
|
|
|
del kmi_type_test
|
2013-03-11 02:19:58 +00:00
|
|
|
|
2013-03-01 06:17:59 +00:00
|
|
|
kmi_test_dict["type"] = kmi_type
|
|
|
|
|
|
|
|
# main filter func, runs many times
|
|
|
|
def filter_func(kmi):
|
|
|
|
for kk, ki in kmi_test_dict.items():
|
|
|
|
if getattr(kmi, kk) != ki:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2010-04-14 07:09:01 +00:00
|
|
|
for km, kc in display_keymaps:
|
|
|
|
km = km.active()
|
2010-09-03 07:25:37 +00:00
|
|
|
layout.context_pointer_set("keymap", km)
|
2010-04-14 07:09:01 +00:00
|
|
|
|
2013-03-01 06:17:59 +00:00
|
|
|
filtered_items = [kmi for kmi in km.keymap_items if filter_func(kmi)]
|
2010-04-14 07:09:01 +00:00
|
|
|
|
2012-01-02 16:18:39 +00:00
|
|
|
if filtered_items:
|
2010-04-14 07:09:01 +00:00
|
|
|
col = layout.column()
|
|
|
|
|
|
|
|
row = col.row()
|
2011-11-08 01:32:34 +00:00
|
|
|
row.label(text=km.name, icon='DOT')
|
2010-04-14 07:09:01 +00:00
|
|
|
|
|
|
|
row.label()
|
|
|
|
row.label()
|
|
|
|
|
KEYMAP REFACTORING
Diff Keymaps
User edited keymaps now no longer override the builtin keymaps entirely, but
rather save only the difference and reapply those changes. This means they can
stay better in sync when the builtin keymaps change. The diff/patch algorithm
is not perfect, but better for the common case where only a few items are changed
rather than entire keymaps The main weakness is that if a builtin keymap item
changes, user modification of that item may need to be redone in some cases.
Keymap Editor
The most noticeable change here is that there is no longer an "Edit" button for
keymaps, all are editable immediately, but a "Restore" buttons shows for keymaps
and items that have been edited. Shortcuts for addons can also be edited in the
keymap editor.
Addons
Addons now should only modify the new addon keyconfiguration, the keymap items
there will be added to the builtin ones for handling events, and not get lost
when starting new files. Example code of register/unregister:
km = wm.keyconfigs.addon.keymaps.new("3D View", space_type="VIEW_3D")
km.keymap_items.new('my.operator', 'ESC', 'PRESS')
km = wm.keyconfigs.addon.keymaps["3D View"]
km.keymap_items.remove(km.keymap_items["my.operator"])
Compatibility
The changes made are not forward compatible, i.e. if you save user preferences
with newer versions, older versions will not have key configuration changes that
were made.
2011-08-05 20:45:26 +00:00
|
|
|
if km.is_user_modified:
|
2011-09-21 15:18:38 +00:00
|
|
|
row.operator("wm.keymap_restore", text="Restore")
|
2010-04-14 07:09:01 +00:00
|
|
|
else:
|
KEYMAP REFACTORING
Diff Keymaps
User edited keymaps now no longer override the builtin keymaps entirely, but
rather save only the difference and reapply those changes. This means they can
stay better in sync when the builtin keymaps change. The diff/patch algorithm
is not perfect, but better for the common case where only a few items are changed
rather than entire keymaps The main weakness is that if a builtin keymap item
changes, user modification of that item may need to be redone in some cases.
Keymap Editor
The most noticeable change here is that there is no longer an "Edit" button for
keymaps, all are editable immediately, but a "Restore" buttons shows for keymaps
and items that have been edited. Shortcuts for addons can also be edited in the
keymap editor.
Addons
Addons now should only modify the new addon keyconfiguration, the keymap items
there will be added to the builtin ones for handling events, and not get lost
when starting new files. Example code of register/unregister:
km = wm.keyconfigs.addon.keymaps.new("3D View", space_type="VIEW_3D")
km.keymap_items.new('my.operator', 'ESC', 'PRESS')
km = wm.keyconfigs.addon.keymaps["3D View"]
km.keymap_items.remove(km.keymap_items["my.operator"])
Compatibility
The changes made are not forward compatible, i.e. if you save user preferences
with newer versions, older versions will not have key configuration changes that
were made.
2011-08-05 20:45:26 +00:00
|
|
|
row.label()
|
2010-04-14 07:09:01 +00:00
|
|
|
|
|
|
|
for kmi in filtered_items:
|
|
|
|
self.draw_kmi(display_keymaps, kc, km, kmi, col, 1)
|
|
|
|
|
|
|
|
# "Add New" at end of keymap item list
|
|
|
|
col = self.indented_layout(layout, 1)
|
|
|
|
subcol = col.split(percentage=0.2).column()
|
2011-09-21 15:18:38 +00:00
|
|
|
subcol.operator("wm.keyitem_add", text="Add New", icon='ZOOMIN')
|
2013-03-01 06:17:59 +00:00
|
|
|
return True
|
2010-04-14 07:09:01 +00:00
|
|
|
|
|
|
|
def draw_hierarchy(self, display_keymaps, layout):
|
2011-09-26 11:22:07 +00:00
|
|
|
from bpy_extras import keyconfig_utils
|
|
|
|
for entry in keyconfig_utils.KM_HIERARCHY:
|
2010-04-14 07:09:01 +00:00
|
|
|
self.draw_entry(display_keymaps, entry, layout)
|
|
|
|
|
|
|
|
def draw_keymaps(self, context, layout):
|
2011-09-26 11:22:07 +00:00
|
|
|
from bpy_extras import keyconfig_utils
|
|
|
|
|
2010-09-02 04:53:05 +00:00
|
|
|
wm = context.window_manager
|
KEYMAP REFACTORING
Diff Keymaps
User edited keymaps now no longer override the builtin keymaps entirely, but
rather save only the difference and reapply those changes. This means they can
stay better in sync when the builtin keymaps change. The diff/patch algorithm
is not perfect, but better for the common case where only a few items are changed
rather than entire keymaps The main weakness is that if a builtin keymap item
changes, user modification of that item may need to be redone in some cases.
Keymap Editor
The most noticeable change here is that there is no longer an "Edit" button for
keymaps, all are editable immediately, but a "Restore" buttons shows for keymaps
and items that have been edited. Shortcuts for addons can also be edited in the
keymap editor.
Addons
Addons now should only modify the new addon keyconfiguration, the keymap items
there will be added to the builtin ones for handling events, and not get lost
when starting new files. Example code of register/unregister:
km = wm.keyconfigs.addon.keymaps.new("3D View", space_type="VIEW_3D")
km.keymap_items.new('my.operator', 'ESC', 'PRESS')
km = wm.keyconfigs.addon.keymaps["3D View"]
km.keymap_items.remove(km.keymap_items["my.operator"])
Compatibility
The changes made are not forward compatible, i.e. if you save user preferences
with newer versions, older versions will not have key configuration changes that
were made.
2011-08-05 20:45:26 +00:00
|
|
|
kc = wm.keyconfigs.user
|
2013-03-01 06:17:59 +00:00
|
|
|
spref = context.space_data
|
2010-04-17 19:05:53 +00:00
|
|
|
|
|
|
|
col = layout.column()
|
2010-04-14 07:09:01 +00:00
|
|
|
sub = col.column()
|
|
|
|
|
|
|
|
subsplit = sub.split()
|
|
|
|
subcol = subsplit.column()
|
2010-04-17 19:05:53 +00:00
|
|
|
|
2010-09-14 16:45:24 +00:00
|
|
|
row = subcol.row(align=True)
|
2011-01-01 07:20:34 +00:00
|
|
|
|
2011-10-17 06:58:07 +00:00
|
|
|
#~ row.prop_search(wm.keyconfigs, "active", wm, "keyconfigs", text="Key Config:")
|
2013-03-01 06:17:59 +00:00
|
|
|
text = bpy.path.display_name(wm.keyconfigs.active.name)
|
2010-09-14 16:45:24 +00:00
|
|
|
if not text:
|
2011-09-21 15:18:38 +00:00
|
|
|
text = "Blender (default)"
|
2010-10-06 20:29:00 +00:00
|
|
|
row.menu("USERPREF_MT_keyconfigs", text=text)
|
2011-11-08 01:32:34 +00:00
|
|
|
row.operator("wm.keyconfig_preset_add", text="", icon='ZOOMIN')
|
|
|
|
row.operator("wm.keyconfig_preset_add", text="", icon='ZOOMOUT').remove_active = True
|
2011-01-01 07:20:34 +00:00
|
|
|
|
2011-10-17 06:58:07 +00:00
|
|
|
#~ layout.context_pointer_set("keyconfig", wm.keyconfigs.active)
|
|
|
|
#~ row.operator("wm.keyconfig_remove", text="", icon='X')
|
2013-03-01 06:17:59 +00:00
|
|
|
row.separator()
|
|
|
|
rowsub = row.split(align=True, percentage=0.33)
|
|
|
|
# postpone drawing into rowsub, so we can set alert!
|
2010-04-14 07:09:01 +00:00
|
|
|
|
|
|
|
col.separator()
|
2011-09-26 11:22:07 +00:00
|
|
|
display_keymaps = keyconfig_utils.keyconfig_merge(kc, kc)
|
2013-03-01 06:17:59 +00:00
|
|
|
filter_type = spref.filter_type
|
2013-03-10 07:18:43 +00:00
|
|
|
filter_text = spref.filter_text.strip()
|
|
|
|
if filter_text:
|
2013-03-01 06:17:59 +00:00
|
|
|
filter_text = filter_text.lower()
|
|
|
|
ok = self.draw_filtered(display_keymaps, filter_type, filter_text, col)
|
2010-04-14 07:09:01 +00:00
|
|
|
else:
|
|
|
|
self.draw_hierarchy(display_keymaps, col)
|
2013-03-01 06:17:59 +00:00
|
|
|
ok = True
|
|
|
|
|
|
|
|
# go back and fill in rowsub
|
|
|
|
rowsub.prop(spref, "filter_type", text="")
|
|
|
|
rowsubsub = rowsub.row(align=True)
|
|
|
|
if not ok:
|
2013-03-10 07:18:43 +00:00
|
|
|
rowsubsub.alert = True
|
2013-03-01 06:17:59 +00:00
|
|
|
rowsubsub.prop(spref, "filter_text", text="", icon='VIEWZOOM')
|
2010-04-14 07:09:01 +00:00
|
|
|
|
|
|
|
|
2011-04-04 10:13:04 +00:00
|
|
|
if __name__ == "__main__": # only for live edit.
|
|
|
|
bpy.utils.register_module(__name__)
|