| 
									
										
										
										
											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 | 
					
						
							|  |  |  | import os | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  | from blf import gettext as _ | 
					
						
							|  |  |  | from blf import fake_gettext as N_ | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | KM_HIERARCHY = [ | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |     ( N_('Window'), 'EMPTY', 'WINDOW', []),  # file save, window change, exit | 
					
						
							|  |  |  |     ( N_('Screen'), 'EMPTY', 'WINDOW', [     # full screen, undo, screenshot | 
					
						
							|  |  |  |         ( N_('Screen Editing'), 'EMPTY', 'WINDOW', []),    # resizing, action corners | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         ]), | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |     ( N_('View2D'), 'EMPTY', 'WINDOW', []),    # view 2d navigation (per region) | 
					
						
							|  |  |  |     ( N_('View2D Buttons List'), 'EMPTY', 'WINDOW', []),  # view 2d with buttons navigation | 
					
						
							|  |  |  |     ( N_('Header'), 'EMPTY', 'WINDOW', []),    # header stuff (per region) | 
					
						
							|  |  |  |     ( N_('Grease Pencil'), 'EMPTY', 'WINDOW', []),  # grease pencil stuff (per region) | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |     ( N_('3D View'), 'VIEW_3D', 'WINDOW', [  # view 3d navigation and generic stuff (select, transform) | 
					
						
							|  |  |  |         ( N_('Object Mode'), 'EMPTY', 'WINDOW', []), | 
					
						
							|  |  |  |         ( N_('Mesh'), 'EMPTY', 'WINDOW', []), | 
					
						
							|  |  |  |         ( N_('Curve'), 'EMPTY', 'WINDOW', []), | 
					
						
							|  |  |  |         ( N_('Armature'), 'EMPTY', 'WINDOW', []), | 
					
						
							|  |  |  |         ( N_('Metaball'), 'EMPTY', 'WINDOW', []), | 
					
						
							|  |  |  |         ( N_('Lattice'), 'EMPTY', 'WINDOW', []), | 
					
						
							|  |  |  |         ( N_('Font'), 'EMPTY', 'WINDOW', []), | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |         ( N_('Pose'), 'EMPTY', 'WINDOW', []), | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |         ( N_('Vertex Paint'), 'EMPTY', 'WINDOW', []), | 
					
						
							|  |  |  |         ( N_('Weight Paint'), 'EMPTY', 'WINDOW', []), | 
					
						
							|  |  |  |         ( N_('Face Mask'), 'EMPTY', 'WINDOW', []), | 
					
						
							|  |  |  |         ( N_('Image Paint'), 'EMPTY', 'WINDOW', []),  # image and view3d | 
					
						
							|  |  |  |         ( N_('Sculpt'), 'EMPTY', 'WINDOW', []), | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |         ( N_('Armature Sketch'), 'EMPTY', 'WINDOW', []), | 
					
						
							|  |  |  |         ( N_('Particle'), 'EMPTY', 'WINDOW', []), | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |         ( N_('Object Non-modal'), 'EMPTY', 'WINDOW', []),  # mode change | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |         ( N_('3D View Generic'), 'VIEW_3D', 'WINDOW', [])    # toolbar and properties | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         ]), | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |     ( N_('Frames'), 'EMPTY', 'WINDOW', []),    # frame navigation (per region) | 
					
						
							|  |  |  |     ( N_('Markers'), 'EMPTY', 'WINDOW', []),    # markers (per region) | 
					
						
							|  |  |  |     ( N_('Animation'), 'EMPTY', 'WINDOW', []),    # frame change on click, preview range (per region) | 
					
						
							|  |  |  |     ( N_('Animation Channels'), 'EMPTY', 'WINDOW', []), | 
					
						
							|  |  |  |     ( N_('Graph Editor'), 'GRAPH_EDITOR', 'WINDOW', [ | 
					
						
							|  |  |  |         ( N_('Graph Editor Generic'), 'GRAPH_EDITOR', 'WINDOW', []) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         ]), | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |     ( N_('Dopesheet'), 'DOPESHEET_EDITOR', 'WINDOW', []), | 
					
						
							|  |  |  |     ( N_('NLA Editor'), 'NLA_EDITOR', 'WINDOW', [ | 
					
						
							|  |  |  |         ( N_('NLA Channels'), 'NLA_EDITOR', 'WINDOW', []), | 
					
						
							|  |  |  |         ( N_('NLA Generic'), 'NLA_EDITOR', 'WINDOW', []) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         ]), | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |     ( N_('Image'), 'IMAGE_EDITOR', 'WINDOW', [ | 
					
						
							|  |  |  |         ( N_('UV Editor'), 'EMPTY', 'WINDOW', []),  # image (reverse order, UVEdit before Image | 
					
						
							|  |  |  |         ( N_('Image Paint'), 'EMPTY', 'WINDOW', []),  # image and view3d | 
					
						
							|  |  |  |         ( N_('Image Generic'), 'IMAGE_EDITOR', 'WINDOW', []) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         ]), | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |     ( N_('Timeline'), 'TIMELINE', 'WINDOW', []), | 
					
						
							|  |  |  |     ( N_('Outliner'), 'OUTLINER', 'WINDOW', []), | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |     ( N_('Node Editor'), 'NODE_EDITOR', 'WINDOW', [ | 
					
						
							|  |  |  |         ( N_('Node Generic'), 'NODE_EDITOR', 'WINDOW', []) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         ]), | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |     ( N_('Sequencer'), 'SEQUENCE_EDITOR', 'WINDOW', []), | 
					
						
							|  |  |  |     ( N_('Logic Editor'), 'LOGIC_EDITOR', 'WINDOW', []), | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |     ( N_('File Browser'), 'FILE_BROWSER', 'WINDOW', [ | 
					
						
							|  |  |  |         ( N_('File Browser Main'), 'FILE_BROWSER', 'WINDOW', []), | 
					
						
							|  |  |  |         ( N_('File Browser Buttons'), 'FILE_BROWSER', 'WINDOW', []) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         ]), | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |     ( N_('Property Editor'), 'PROPERTIES', 'WINDOW', []),  # align context menu | 
					
						
							| 
									
										
										
										
											2010-05-03 16:00:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |     ( N_('Script'), 'SCRIPTS_WINDOW', 'WINDOW', []), | 
					
						
							|  |  |  |     ( N_('Text'), 'TEXT_EDITOR', 'WINDOW', []), | 
					
						
							|  |  |  |     ( N_('Console'), 'CONSOLE', 'WINDOW', []), | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |     ( N_('View3D Gesture Circle'), 'EMPTY', 'WINDOW', []), | 
					
						
							|  |  |  |     ( N_('Gesture Border'), 'EMPTY', 'WINDOW', []), | 
					
						
							|  |  |  |     ( N_('Standard Modal Map'), 'EMPTY', 'WINDOW', []), | 
					
						
							|  |  |  |     ( N_('Transform Modal Map'), 'EMPTY', 'WINDOW', []), | 
					
						
							|  |  |  |     ( N_('View3D Fly Modal'), 'EMPTY', 'WINDOW', []), | 
					
						
							|  |  |  |     ( N_('View3D Rotate Modal'), 'EMPTY', 'WINDOW', []), | 
					
						
							|  |  |  |     ( N_('View3D Move Modal'), 'EMPTY', 'WINDOW', []), | 
					
						
							|  |  |  |     ( N_('View3D Zoom Modal'), 'EMPTY', 'WINDOW', []), | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-03 16:00:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | def _km_exists_in(km, export_keymaps): | 
					
						
							|  |  |  |     for km2, kc in export_keymaps: | 
					
						
							|  |  |  |         if km2.name == km.name: | 
					
						
							|  |  |  |             return True | 
					
						
							|  |  |  |     return False | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-03 16:00:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | def _merge_keymaps(kc1, kc2): | 
					
						
							| 
									
										
										
										
											2010-05-03 16:00:42 +00:00
										 |  |  |     """ note: kc1 takes priority over kc2
 | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |     merged_keymaps = [(km, kc1) for km in kc1.keymaps] | 
					
						
							|  |  |  |     if kc1 != kc2: | 
					
						
							| 
									
										
										
										
											2010-09-19 07:07:14 +00:00
										 |  |  |         merged_keymaps.extend((km, kc2) for km in kc2.keymaps if not _km_exists_in(km, merged_keymaps)) | 
					
						
							| 
									
										
										
										
											2010-05-03 16:00:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return merged_keymaps | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 20:29:00 +00:00
										 |  |  | class USERPREF_MT_keyconfigs(bpy.types.Menu): | 
					
						
							| 
									
										
										
										
											2011-06-24 04:22:27 +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-06-20 10:07:46 +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 | 
					
						
							|  |  |  |         bpy.types.Menu.draw_preset(self, context) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 09:52:11 +00:00
										 |  |  | class InputKeyMapPanel: | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |     bl_space_type = 'USER_PREFERENCES' | 
					
						
							| 
									
										
										
										
											2011-06-24 04:22:27 +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-06-20 10:07:46 +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') | 
					
						
							| 
									
										
										
										
											2010-08-18 07:14:10 +00:00
										 |  |  |         if km.is_user_defined: | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |             op = row.operator("wm.keymap_restore", text=_("Restore")) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |             op = row.operator("wm.keymap_edit", text=_("Edit")) | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |                 subrow.label(text="%s (Global)" % km.name) | 
					
						
							|  |  |  |             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() | 
					
						
							| 
									
										
										
										
											2010-08-18 07:14:10 +00:00
										 |  |  |                 subcol.enabled = km.is_user_defined | 
					
						
							| 
									
										
										
										
											2011-06-24 04:22:27 +00:00
										 |  |  |                 op = 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) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-06 06:04:05 +00:00
										 |  |  |     @staticmethod | 
					
						
							|  |  |  |     def draw_kmi_properties(box, properties, title=None): | 
					
						
							|  |  |  |         box.separator() | 
					
						
							|  |  |  |         if title: | 
					
						
							|  |  |  |             box.label(text=title) | 
					
						
							|  |  |  |         flow = box.column_flow(columns=2) | 
					
						
							|  |  |  |         for pname, value in properties.bl_rna.properties.items(): | 
					
						
							|  |  |  |             if pname != "rna_type" and not properties.is_property_hidden(pname): | 
					
						
							|  |  |  |                 if isinstance(value, bpy.types.OperatorProperties): | 
					
						
							|  |  |  |                     __class__.draw_kmi_properties(box, value, title=pname) | 
					
						
							|  |  |  |                 else: | 
					
						
							|  |  |  |                     flow.prop(properties, pname) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |     def draw_kmi(self, display_keymaps, kc, km, kmi, layout, level): | 
					
						
							|  |  |  |         map_type = kmi.map_type | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         col = self.indented_layout(layout, level) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-18 07:14:10 +00:00
										 |  |  |         if km.is_user_defined: | 
					
						
							| 
									
										
										
										
											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-08-18 07:14:10 +00:00
										 |  |  |         row.enabled = km.is_user_defined | 
					
						
							| 
									
										
										
										
											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: | 
					
						
							|  |  |  |             row.label(text=kmi.name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         row = split.row() | 
					
						
							| 
									
										
										
										
											2010-08-18 07:14:10 +00:00
										 |  |  |         row.enabled = km.is_user_defined | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         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) | 
					
						
							|  |  |  |         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() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-06 02:42:59 +00:00
										 |  |  |         if not kmi.is_user_defined: | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |             op = row.operator("wm.keyitem_restore", text="", icon='BACK') | 
					
						
							|  |  |  |             op.item_id = kmi.id | 
					
						
							|  |  |  |         op = row.operator("wm.keyitem_remove", text="", icon='X') | 
					
						
							|  |  |  |         op.item_id = kmi.id | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # 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() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-18 07:14:10 +00:00
										 |  |  |             box.enabled = km.is_user_defined | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-07 13:23:45 +00:00
										 |  |  |             if map_type not in {'TEXTINPUT', 'TIMER'}: | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |                 split = box.split(percentage=0.4) | 
					
						
							|  |  |  |                 sub = split.row() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-18 07:14:10 +00:00
										 |  |  |                 if km.is_modal: | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |                     sub.prop(kmi, "propvalue", text="") | 
					
						
							|  |  |  |                 else: | 
					
						
							| 
									
										
										
										
											2010-09-06 22:43:09 +00:00
										 |  |  |                     # One day... | 
					
						
							|  |  |  |                     # sub.prop_search(kmi, "idname", bpy.context.window_manager, "operators_all", text="") | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |                     sub.prop(kmi, "idname", text="") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 sub = split.column() | 
					
						
							|  |  |  |                 subrow = sub.row(align=True) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if map_type == 'KEYBOARD': | 
					
						
							|  |  |  |                     subrow.prop(kmi, "type", text="", event=True) | 
					
						
							|  |  |  |                     subrow.prop(kmi, "value", text="") | 
					
						
							|  |  |  |                 elif map_type == 'MOUSE': | 
					
						
							|  |  |  |                     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 | 
					
						
							|  |  |  |             props = kmi.properties | 
					
						
							|  |  |  |             if props is not None: | 
					
						
							| 
									
										
										
										
											2010-09-06 06:04:05 +00:00
										 |  |  |                 __class__.draw_kmi_properties(box, props) | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-25 14:29:14 +00:00
										 |  |  |     def draw_filtered(self, display_keymaps, filter_text, layout): | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-25 02:12:44 +00:00
										 |  |  |             filtered_items = [kmi for kmi in km.keymap_items if filter_text in kmi.name.lower()] | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if len(filtered_items) != 0: | 
					
						
							|  |  |  |                 col = layout.column() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 row = col.row() | 
					
						
							|  |  |  |                 row.label(text=km.name, icon="DOT") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 row.label() | 
					
						
							|  |  |  |                 row.label() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-18 07:14:10 +00:00
										 |  |  |                 if km.is_user_defined: | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |                     op = row.operator("wm.keymap_restore", text=_("Restore")) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |                 else: | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |                     op = row.operator("wm.keymap_edit", text=_("Edit")) | 
					
						
							| 
									
										
										
										
											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() | 
					
						
							| 
									
										
										
										
											2010-08-18 07:14:10 +00:00
										 |  |  |                 subcol.enabled = km.is_user_defined | 
					
						
							| 
									
										
										
										
											2011-06-24 04:22:27 +00:00
										 |  |  |                 op = subcol.operator("wm.keyitem_add", text=_("Add New"), icon='ZOOMIN') | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def draw_hierarchy(self, display_keymaps, layout): | 
					
						
							|  |  |  |         for entry in KM_HIERARCHY: | 
					
						
							|  |  |  |             self.draw_entry(display_keymaps, entry, layout) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def draw_keymaps(self, context, layout): | 
					
						
							| 
									
										
										
										
											2010-09-02 04:53:05 +00:00
										 |  |  |         wm = context.window_manager | 
					
						
							| 
									
										
										
										
											2010-08-23 22:16:45 +00:00
										 |  |  |         kc = wm.keyconfigs.active | 
					
						
							|  |  |  |         defkc = wm.keyconfigs.default | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-14 16:45:24 +00:00
										 |  |  |         #row.prop_search(wm.keyconfigs, "active", wm, "keyconfigs", text="Key Config:") | 
					
						
							|  |  |  |         text = bpy.path.display_name(context.window_manager.keyconfigs.active.name) | 
					
						
							|  |  |  |         if not text: | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |             text = _("Blender (default)") | 
					
						
							| 
									
										
										
										
											2010-10-06 20:29:00 +00:00
										 |  |  |         row.menu("USERPREF_MT_keyconfigs", text=text) | 
					
						
							| 
									
										
										
										
											2010-09-14 16:45:24 +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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-14 16:45:24 +00:00
										 |  |  | #        layout.context_pointer_set("keyconfig", wm.keyconfigs.active) | 
					
						
							|  |  |  | #        row.operator("wm.keyconfig_remove", text="", icon='X') | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-17 07:49:53 +00:00
										 |  |  |         row.prop(context.space_data, "filter_text", icon="VIEWZOOM") | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         col.separator() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         display_keymaps = _merge_keymaps(kc, defkc) | 
					
						
							| 
									
										
										
										
											2010-08-17 07:49:53 +00:00
										 |  |  |         if context.space_data.filter_text != "": | 
					
						
							|  |  |  |             filter_text = context.space_data.filter_text.lower() | 
					
						
							| 
									
										
										
										
											2010-08-25 14:29:14 +00:00
										 |  |  |             self.draw_filtered(display_keymaps, filter_text, col) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         else: | 
					
						
							|  |  |  |             self.draw_hierarchy(display_keymaps, col) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-27 15:25:24 +00:00
										 |  |  | from bpy.props import StringProperty, BoolProperty, IntProperty | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-13 18:48:33 +00:00
										 |  |  | def export_properties(prefix, properties, lines=None): | 
					
						
							|  |  |  |     if lines is None: | 
					
						
							|  |  |  |         lines = [] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-01 14:35:14 +00:00
										 |  |  |     for pname in properties.bl_rna.properties.keys(): | 
					
						
							|  |  |  |         if pname != "rna_type" and not properties.is_property_hidden(pname): | 
					
						
							| 
									
										
										
										
											2010-09-14 16:45:24 +00:00
										 |  |  |             value = getattr(properties, pname) | 
					
						
							| 
									
										
										
										
											2010-08-13 18:48:33 +00:00
										 |  |  |             if isinstance(value, bpy.types.OperatorProperties): | 
					
						
							|  |  |  |                 export_properties(prefix + "." + pname, value, lines) | 
					
						
							|  |  |  |             elif properties.is_property_set(pname): | 
					
						
							|  |  |  |                 value = _string_value(value) | 
					
						
							|  |  |  |                 if value != "": | 
					
						
							|  |  |  |                     lines.append("%s.%s = %s\n" % (prefix, pname, value)) | 
					
						
							|  |  |  |     return lines | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | class WM_OT_keyconfig_test(bpy.types.Operator): | 
					
						
							|  |  |  |     "Test keyconfig for conflicts" | 
					
						
							|  |  |  |     bl_idname = "wm.keyconfig_test" | 
					
						
							| 
									
										
										
										
											2011-06-24 04:22:27 +00:00
										 |  |  |     bl_label = _("Test Key Configuration for Conflicts") | 
					
						
							|  |  |  |     __doc__ = _("Test keyconfig for conflicts") | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def testEntry(self, kc, entry, src=None, parent=None): | 
					
						
							|  |  |  |         result = False | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def kmistr(kmi): | 
					
						
							| 
									
										
										
										
											2010-08-18 07:14:10 +00:00
										 |  |  |             if km.is_modal: | 
					
						
							| 
									
										
										
										
											2011-03-25 02:12:44 +00:00
										 |  |  |                 s = ["kmi = km.keymap_items.new_modal(\'%s\', \'%s\', \'%s\'" % (kmi.propvalue, kmi.type, kmi.value)] | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |             else: | 
					
						
							| 
									
										
										
										
											2011-03-25 02:12:44 +00:00
										 |  |  |                 s = ["kmi = km.keymap_items.new(\'%s\', \'%s\', \'%s\'" % (kmi.idname, kmi.type, kmi.value)] | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if kmi.any: | 
					
						
							|  |  |  |                 s.append(", any=True") | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 if kmi.shift: | 
					
						
							|  |  |  |                     s.append(", shift=True") | 
					
						
							|  |  |  |                 if kmi.ctrl: | 
					
						
							|  |  |  |                     s.append(", ctrl=True") | 
					
						
							|  |  |  |                 if kmi.alt: | 
					
						
							|  |  |  |                     s.append(", alt=True") | 
					
						
							|  |  |  |                 if kmi.oskey: | 
					
						
							|  |  |  |                     s.append(", oskey=True") | 
					
						
							|  |  |  |             if kmi.key_modifier and kmi.key_modifier != 'NONE': | 
					
						
							|  |  |  |                 s.append(", key_modifier=\'%s\'" % kmi.key_modifier) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             s.append(")\n") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             props = kmi.properties | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if props is not None: | 
					
						
							| 
									
										
										
										
											2010-08-13 18:48:33 +00:00
										 |  |  |                 export_properties("kmi.properties", props, s) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             return "".join(s).strip() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         idname, spaceid, regionid, children = entry | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 km: | 
					
						
							|  |  |  |             km = km.active() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if src: | 
					
						
							| 
									
										
										
										
											2011-03-25 02:12:44 +00:00
										 |  |  |                 for item in km.keymap_items: | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |                     if src.compare(item): | 
					
						
							|  |  |  |                         print("===========") | 
					
						
							|  |  |  |                         print(parent.name) | 
					
						
							|  |  |  |                         print(kmistr(src)) | 
					
						
							|  |  |  |                         print(km.name) | 
					
						
							|  |  |  |                         print(kmistr(item)) | 
					
						
							|  |  |  |                         result = True | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 for child in children: | 
					
						
							|  |  |  |                     if self.testEntry(kc, child, src, parent): | 
					
						
							|  |  |  |                         result = True | 
					
						
							|  |  |  |             else: | 
					
						
							| 
									
										
										
										
											2011-03-25 02:12:44 +00:00
										 |  |  |                 for i in range(len(km.keymap_items)): | 
					
						
							|  |  |  |                     src = km.keymap_items[i] | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     for child in children: | 
					
						
							|  |  |  |                         if self.testEntry(kc, child, src, km): | 
					
						
							|  |  |  |                             result = True | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-25 02:12:44 +00:00
										 |  |  |                     for j in range(len(km.keymap_items) - i - 1): | 
					
						
							|  |  |  |                         item = km.keymap_items[j + i + 1] | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |                         if src.compare(item): | 
					
						
							|  |  |  |                             print("===========") | 
					
						
							|  |  |  |                             print(km.name) | 
					
						
							|  |  |  |                             print(kmistr(src)) | 
					
						
							|  |  |  |                             print(kmistr(item)) | 
					
						
							|  |  |  |                             result = True | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 for child in children: | 
					
						
							|  |  |  |                     if self.testEntry(kc, child): | 
					
						
							|  |  |  |                         result = True | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return result | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def testConfig(self, kc): | 
					
						
							|  |  |  |         result = False | 
					
						
							|  |  |  |         for entry in KM_HIERARCHY: | 
					
						
							|  |  |  |             if self.testEntry(kc, entry): | 
					
						
							|  |  |  |                 result = True | 
					
						
							|  |  |  |         return result | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def execute(self, context): | 
					
						
							| 
									
										
										
										
											2010-09-02 04:53:05 +00:00
										 |  |  |         wm = context.window_manager | 
					
						
							| 
									
										
										
										
											2010-08-23 22:16:45 +00:00
										 |  |  |         kc = wm.keyconfigs.default | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if self.testConfig(kc): | 
					
						
							|  |  |  |             print("CONFLICT") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return {'FINISHED'} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def _string_value(value): | 
					
						
							|  |  |  |     if isinstance(value, str) or isinstance(value, bool) or isinstance(value, float) or isinstance(value, int): | 
					
						
							|  |  |  |         result = repr(value) | 
					
						
							|  |  |  |     elif getattr(value, '__len__', False): | 
					
						
							| 
									
										
										
										
											2010-09-14 16:45:24 +00:00
										 |  |  |         return repr(list(value)) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |     else: | 
					
						
							|  |  |  |         print("Export key configuration: can't write ", value) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return result | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WM_OT_keyconfig_import(bpy.types.Operator): | 
					
						
							|  |  |  |     "Import key configuration from a python script" | 
					
						
							|  |  |  |     bl_idname = "wm.keyconfig_import" | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |     bl_label = _("Import Key Configuration...") | 
					
						
							|  |  |  |     __doc__ = _("Import key configuration from a python script") | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-24 04:22:27 +00:00
										 |  |  |     filepath = StringProperty(name=_("File Path"), description=_("Filepath to write file to"), default="keymap.py") | 
					
						
							|  |  |  |     filter_folder = BoolProperty(name=_("Filter folders"), description="", default=True, options={'HIDDEN'}) | 
					
						
							|  |  |  |     filter_text = BoolProperty(name=_("Filter text"), description="", default=True, options={'HIDDEN'}) | 
					
						
							|  |  |  |     filter_python = BoolProperty(name=_("Filter python"), description="", default=True, options={'HIDDEN'}) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |     keep_original = BoolProperty(name=_("Keep original"), description=_("Keep original file after copying to configuration folder"), default=True) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def execute(self, context): | 
					
						
							| 
									
										
										
										
											2010-09-14 16:45:24 +00:00
										 |  |  |         from os.path import basename | 
					
						
							| 
									
										
										
										
											2010-08-13 18:48:33 +00:00
										 |  |  |         import shutil | 
					
						
							| 
									
										
										
										
											2010-09-09 18:03:57 +00:00
										 |  |  |         if not self.filepath: | 
					
						
							| 
									
										
										
										
											2010-06-14 03:52:10 +00:00
										 |  |  |             raise Exception("Filepath not set") | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-09 18:03:57 +00:00
										 |  |  |         f = open(self.filepath, "r") | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         if not f: | 
					
						
							|  |  |  |             raise Exception("Could not open file") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-14 16:45:24 +00:00
										 |  |  |         config_name = basename(self.filepath) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-03 08:21:11 +00:00
										 |  |  |         path = bpy.utils.user_resource('SCRIPTS', os.path.join("presets", "keyconfig"), create=True) | 
					
						
							| 
									
										
										
										
											2010-09-14 16:45:24 +00:00
										 |  |  |         path = os.path.join(path, config_name) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-09 18:03:57 +00:00
										 |  |  |         if self.keep_original: | 
					
						
							|  |  |  |             shutil.copy(self.filepath, path) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2010-09-09 18:03:57 +00:00
										 |  |  |             shutil.move(self.filepath, path) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-13 18:48:33 +00:00
										 |  |  |         # sneaky way to check we're actually running the code. | 
					
						
							| 
									
										
										
										
											2010-09-14 16:45:24 +00:00
										 |  |  |         bpy.utils.keyconfig_set(path) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return {'FINISHED'} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def invoke(self, context, event): | 
					
						
							| 
									
										
										
										
											2010-09-02 04:53:05 +00:00
										 |  |  |         wm = context.window_manager | 
					
						
							| 
									
										
										
										
											2010-12-08 11:42:11 +00:00
										 |  |  |         wm.fileselect_add(self) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         return {'RUNNING_MODAL'} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # This operator is also used by interaction presets saving - AddPresetBase | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | class WM_OT_keyconfig_export(bpy.types.Operator): | 
					
						
							|  |  |  |     "Export key configuration to a python script" | 
					
						
							|  |  |  |     bl_idname = "wm.keyconfig_export" | 
					
						
							| 
									
										
										
										
											2011-06-20 10:07:46 +00:00
										 |  |  |     bl_label = _("Export Key Configuration...") | 
					
						
							|  |  |  |     __doc__ = _("Export key configuration to a python script") | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-24 04:22:27 +00:00
										 |  |  |     filepath = StringProperty(name=_("File Path"), description=_("Filepath to write file to"), default="keymap.py") | 
					
						
							|  |  |  |     filter_folder = BoolProperty(name=_("Filter folders"), description="", default=True, options={'HIDDEN'}) | 
					
						
							|  |  |  |     filter_text = BoolProperty(name=_("Filter text"), description="", default=True, options={'HIDDEN'}) | 
					
						
							|  |  |  |     filter_python = BoolProperty(name=_("Filter python"), description="", default=True, options={'HIDDEN'}) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def execute(self, context): | 
					
						
							| 
									
										
										
										
											2010-09-09 18:03:57 +00:00
										 |  |  |         if not self.filepath: | 
					
						
							| 
									
										
										
										
											2010-06-14 03:52:10 +00:00
										 |  |  |             raise Exception("Filepath not set") | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-09 18:03:57 +00:00
										 |  |  |         f = open(self.filepath, "w") | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         if not f: | 
					
						
							|  |  |  |             raise Exception("Could not open file") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-02 04:53:05 +00:00
										 |  |  |         wm = context.window_manager | 
					
						
							| 
									
										
										
										
											2010-08-23 22:16:45 +00:00
										 |  |  |         kc = wm.keyconfigs.active | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-14 16:45:24 +00:00
										 |  |  |         f.write("import bpy\n") | 
					
						
							|  |  |  |         f.write("import os\n\n") | 
					
						
							| 
									
										
										
										
											2010-09-02 04:53:05 +00:00
										 |  |  |         f.write("wm = bpy.context.window_manager\n") | 
					
						
							| 
									
										
										
										
											2011-01-01 07:20:34 +00:00
										 |  |  |         f.write("kc = wm.keyconfigs.new(os.path.splitext(os.path.basename(__file__))[0])\n\n")  # keymap must be created by caller | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # Generate a list of keymaps to export: | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  |         # | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         # First add all user_defined keymaps (found in inputs.edited_keymaps list), | 
					
						
							|  |  |  |         # then add all remaining keymaps from the currently active custom keyconfig. | 
					
						
							|  |  |  |         # | 
					
						
							|  |  |  |         # This will create a final list of keymaps that can be used as a 'diff' against | 
					
						
							|  |  |  |         # the default blender keyconfig, recreating the current setup from a fresh blender | 
					
						
							|  |  |  |         # without needing to export keymaps which haven't been edited. | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         class FakeKeyConfig(): | 
					
						
							|  |  |  |             keymaps = [] | 
					
						
							|  |  |  |         edited_kc = FakeKeyConfig() | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  |         edited_kc.keymaps.extend(context.user_preferences.inputs.edited_keymaps) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         # merge edited keymaps with non-default keyconfig, if it exists | 
					
						
							| 
									
										
										
										
											2010-08-23 22:16:45 +00:00
										 |  |  |         if kc != wm.keyconfigs.default: | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |             export_keymaps = _merge_keymaps(edited_kc, kc) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             export_keymaps = _merge_keymaps(edited_kc, edited_kc) | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         for km, kc_x in export_keymaps: | 
					
						
							| 
									
										
										
										
											2010-04-17 19:05:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |             km = km.active() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             f.write("# Map %s\n" % km.name) | 
					
						
							| 
									
										
										
										
											2010-08-30 13:50:59 +00:00
										 |  |  |             f.write("km = kc.keymaps.new('%s', space_type='%s', region_type='%s', modal=%s)\n\n" % (km.name, km.space_type, km.region_type, km.is_modal)) | 
					
						
							| 
									
										
										
										
											2011-03-25 02:12:44 +00:00
										 |  |  |             for kmi in km.keymap_items: | 
					
						
							| 
									
										
										
										
											2010-08-18 07:14:10 +00:00
										 |  |  |                 if km.is_modal: | 
					
						
							| 
									
										
										
										
											2011-03-25 02:12:44 +00:00
										 |  |  |                     f.write("kmi = km.keymap_items.new_modal('%s', '%s', '%s'" % (kmi.propvalue, kmi.type, kmi.value)) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |                 else: | 
					
						
							| 
									
										
										
										
											2011-03-25 02:12:44 +00:00
										 |  |  |                     f.write("kmi = km.keymap_items.new('%s', '%s', '%s'" % (kmi.idname, kmi.type, kmi.value)) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |                 if kmi.any: | 
					
						
							|  |  |  |                     f.write(", any=True") | 
					
						
							|  |  |  |                 else: | 
					
						
							|  |  |  |                     if kmi.shift: | 
					
						
							|  |  |  |                         f.write(", shift=True") | 
					
						
							|  |  |  |                     if kmi.ctrl: | 
					
						
							|  |  |  |                         f.write(", ctrl=True") | 
					
						
							|  |  |  |                     if kmi.alt: | 
					
						
							|  |  |  |                         f.write(", alt=True") | 
					
						
							|  |  |  |                     if kmi.oskey: | 
					
						
							|  |  |  |                         f.write(", oskey=True") | 
					
						
							|  |  |  |                 if kmi.key_modifier and kmi.key_modifier != 'NONE': | 
					
						
							|  |  |  |                     f.write(", key_modifier='%s'" % kmi.key_modifier) | 
					
						
							|  |  |  |                 f.write(")\n") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 props = kmi.properties | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if props is not None: | 
					
						
							| 
									
										
										
										
											2010-08-13 18:48:33 +00:00
										 |  |  |                     f.write("".join(export_properties("kmi.properties", props))) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             f.write("\n") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         f.close() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return {'FINISHED'} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def invoke(self, context, event): | 
					
						
							| 
									
										
										
										
											2010-09-02 04:53:05 +00:00
										 |  |  |         wm = context.window_manager | 
					
						
							| 
									
										
										
										
											2010-12-08 11:42:11 +00:00
										 |  |  |         wm.fileselect_add(self) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         return {'RUNNING_MODAL'} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WM_OT_keymap_edit(bpy.types.Operator): | 
					
						
							|  |  |  |     "Edit stored key map" | 
					
						
							|  |  |  |     bl_idname = "wm.keymap_edit" | 
					
						
							| 
									
										
										
										
											2011-06-24 04:22:27 +00:00
										 |  |  |     bl_label = _("Edit Key Map") | 
					
						
							|  |  |  |     __doc__ = _("Edit stored key map") | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def execute(self, context): | 
					
						
							|  |  |  |         km = context.keymap | 
					
						
							|  |  |  |         km.copy_to_user() | 
					
						
							|  |  |  |         return {'FINISHED'} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WM_OT_keymap_restore(bpy.types.Operator): | 
					
						
							|  |  |  |     "Restore key map(s)" | 
					
						
							|  |  |  |     bl_idname = "wm.keymap_restore" | 
					
						
							| 
									
										
										
										
											2011-06-24 04:22:27 +00:00
										 |  |  |     bl_label = _("Restore Key Map(s)") | 
					
						
							|  |  |  |     __doc__ = _("Restore key map(s)") | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-10 04:04:48 +00:00
										 |  |  |     all = BoolProperty(name="All Keymaps", description="Restore all keymaps to default") | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def execute(self, context): | 
					
						
							| 
									
										
										
										
											2010-09-02 04:53:05 +00:00
										 |  |  |         wm = context.window_manager | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-09 18:03:57 +00:00
										 |  |  |         if self.all: | 
					
						
							| 
									
										
										
										
											2010-08-23 22:16:45 +00:00
										 |  |  |             for km in wm.keyconfigs.default.keymaps: | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |                 km.restore_to_default() | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             km = context.keymap | 
					
						
							|  |  |  |             km.restore_to_default() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return {'FINISHED'} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WM_OT_keyitem_restore(bpy.types.Operator): | 
					
						
							|  |  |  |     "Restore key map item" | 
					
						
							|  |  |  |     bl_idname = "wm.keyitem_restore" | 
					
						
							| 
									
										
										
										
											2011-06-24 04:22:27 +00:00
										 |  |  |     bl_label = _("Restore Key Map Item") | 
					
						
							|  |  |  |     __doc__ = _("Restore key map item") | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-10 04:04:48 +00:00
										 |  |  |     item_id = IntProperty(name="Item Identifier", description="Identifier of the item to remove") | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-06 02:42:59 +00:00
										 |  |  |     @classmethod | 
					
						
							|  |  |  |     def poll(cls, context): | 
					
						
							| 
									
										
										
										
											2011-03-22 08:21:16 +00:00
										 |  |  |         keymap = getattr(context, "keymap", None) | 
					
						
							|  |  |  |         return keymap and keymap.is_user_defined | 
					
						
							| 
									
										
										
										
											2010-12-06 02:42:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |     def execute(self, context): | 
					
						
							|  |  |  |         km = context.keymap | 
					
						
							| 
									
										
										
										
											2011-03-25 02:12:44 +00:00
										 |  |  |         kmi = km.keymap_items.from_id(self.item_id) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-06 02:42:59 +00:00
										 |  |  |         if not kmi.is_user_defined: | 
					
						
							|  |  |  |             km.restore_item_to_default(kmi) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return {'FINISHED'} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WM_OT_keyitem_add(bpy.types.Operator): | 
					
						
							|  |  |  |     "Add key map item" | 
					
						
							|  |  |  |     bl_idname = "wm.keyitem_add" | 
					
						
							| 
									
										
										
										
											2011-06-24 04:22:27 +00:00
										 |  |  |     bl_label = _("Add Key Map Item") | 
					
						
							|  |  |  |     __doc__ = _("Add key map item") | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def execute(self, context): | 
					
						
							| 
									
										
										
										
											2010-09-02 04:53:05 +00:00
										 |  |  |         wm = context.window_manager | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         km = context.keymap | 
					
						
							| 
									
										
										
										
											2010-08-23 22:16:45 +00:00
										 |  |  |         kc = wm.keyconfigs.default | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-18 07:14:10 +00:00
										 |  |  |         if km.is_modal: | 
					
						
							| 
									
										
										
										
											2011-03-25 02:12:44 +00:00
										 |  |  |             km.keymap_items.new_modal("", 'A', 'PRESS')  # kmi | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2011-03-25 02:12:44 +00:00
										 |  |  |             km.keymap_items.new("none", 'A', 'PRESS')  # kmi | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # clear filter and expand keymap so we can see the newly added item | 
					
						
							| 
									
										
										
										
											2010-08-17 07:49:53 +00:00
										 |  |  |         if context.space_data.filter_text != "": | 
					
						
							|  |  |  |             context.space_data.filter_text = "" | 
					
						
							| 
									
										
										
										
											2010-08-17 17:03:52 +00:00
										 |  |  |             km.show_expanded_items = True | 
					
						
							|  |  |  |             km.show_expanded_children = True | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return {'FINISHED'} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WM_OT_keyitem_remove(bpy.types.Operator): | 
					
						
							|  |  |  |     "Remove key map item" | 
					
						
							|  |  |  |     bl_idname = "wm.keyitem_remove" | 
					
						
							| 
									
										
										
										
											2011-06-24 04:22:27 +00:00
										 |  |  |     bl_label = _("Remove Key Map Item") | 
					
						
							|  |  |  |     __doc__ = _("Remove key map item") | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-24 04:22:27 +00:00
										 |  |  |     item_id = IntProperty(name=_("Item Identifier"), description=_("Identifier of the item to remove")) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-06 02:42:59 +00:00
										 |  |  |     @classmethod | 
					
						
							|  |  |  |     def poll(cls, context): | 
					
						
							| 
									
										
										
										
											2011-03-07 23:53:08 +00:00
										 |  |  |         return hasattr(context, "keymap") and context.keymap.is_user_defined | 
					
						
							| 
									
										
										
										
											2010-12-06 02:42:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |     def execute(self, context): | 
					
						
							|  |  |  |         km = context.keymap | 
					
						
							| 
									
										
										
										
											2011-03-25 02:12:44 +00:00
										 |  |  |         kmi = km.keymap_items.from_id(self.item_id) | 
					
						
							|  |  |  |         km.keymap_items.remove(kmi) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         return {'FINISHED'} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WM_OT_keyconfig_remove(bpy.types.Operator): | 
					
						
							|  |  |  |     "Remove key config" | 
					
						
							|  |  |  |     bl_idname = "wm.keyconfig_remove" | 
					
						
							| 
									
										
										
										
											2011-06-24 04:22:27 +00:00
										 |  |  |     bl_label = _("Remove Key Config") | 
					
						
							|  |  |  |     __doc__ = _("Remove key config") | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-09 01:37:09 +00:00
										 |  |  |     @classmethod | 
					
						
							|  |  |  |     def poll(cls, context): | 
					
						
							| 
									
										
										
										
											2010-09-02 04:53:05 +00:00
										 |  |  |         wm = context.window_manager | 
					
						
							| 
									
										
										
										
											2011-03-22 08:21:16 +00:00
										 |  |  |         keyconf = wm.keyconfigs.active | 
					
						
							|  |  |  |         return keyconf and keyconf.is_user_defined | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def execute(self, context): | 
					
						
							| 
									
										
										
										
											2010-09-02 04:53:05 +00:00
										 |  |  |         wm = context.window_manager | 
					
						
							| 
									
										
										
										
											2010-08-23 22:16:45 +00:00
										 |  |  |         keyconfig = wm.keyconfigs.active | 
					
						
							| 
									
										
										
										
											2010-08-30 13:50:59 +00:00
										 |  |  |         wm.keyconfigs.remove(keyconfig) | 
					
						
							| 
									
										
										
										
											2010-04-14 07:09:01 +00:00
										 |  |  |         return {'FINISHED'} | 
					
						
							| 
									
										
										
										
											2011-04-04 10:13:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | if __name__ == "__main__":  # only for live edit. | 
					
						
							|  |  |  |     bpy.utils.register_module(__name__) |