change blender python interface for classes not to ise __idname__ rather bl_idname...
[blender-staging.git] / release / scripts / ui / space_userpref.py
1  
2 import bpy
3
4 class USERPREF_HT_header(bpy.types.Header):
5         bl_space_type = 'USER_PREFERENCES'
6
7         def draw(self, context):
8                 layout = self.layout
9                 layout.template_header(menus=False)
10                 
11                 userpref = context.user_preferences
12         
13                 layout.operator_context = "EXEC_AREA"
14                 layout.itemO("wm.save_homefile", text="Save As Default")
15
16                 if userpref.active_section == 'INPUT':
17                         layout.operator_context = "INVOKE_DEFAULT"
18                         layout.itemO("wm.keyconfig_export", "Export Key Configuration...")
19                         
20 class USERPREF_MT_view(bpy.types.Menu):
21         bl_label = "View"
22
23         def draw(self, context):
24                 layout = self.layout
25
26 class USERPREF_PT_tabs(bpy.types.Panel):
27         bl_space_type = 'USER_PREFERENCES'
28         bl_show_header = False
29
30         def draw(self, context):
31                 layout = self.layout
32                 
33                 userpref = context.user_preferences
34
35                 layout.itemR(userpref, "active_section", expand=True)
36
37 class USERPREF_PT_interface(bpy.types.Panel):
38         bl_space_type = 'USER_PREFERENCES'
39         bl_label = "Interface"
40         bl_show_header = False
41
42         def poll(self, context):
43                 userpref = context.user_preferences
44                 return (userpref.active_section == 'INTERFACE')
45
46         def draw(self, context):
47                 layout = self.layout
48                 
49                 userpref = context.user_preferences
50                 view = userpref.view
51
52                 split = layout.split()
53                 
54                 col = split.column()
55                 sub = col.split(percentage=0.85)
56                 
57                 sub1 = sub.column()
58                 sub1.itemL(text="Display:")
59                 sub1.itemR(view, "tooltips")
60                 sub1.itemR(view, "display_object_info", text="Object Info")
61                 sub1.itemR(view, "use_large_cursors")
62                 sub1.itemR(view, "show_view_name", text="View Name")
63                 sub1.itemR(view, "show_playback_fps", text="Playback FPS")
64                 sub1.itemR(view, "global_scene")
65                 sub1.itemR(view, "pin_floating_panels")
66                 sub1.itemR(view, "object_center_size")
67                 sub1.itemS()
68                 sub1.itemS()
69                 sub1.itemS()
70                 sub1.itemR(view, "show_mini_axis", text="Display Mini Axis")
71                 sub2 = sub1.column()
72                 sub2.enabled = view.show_mini_axis
73                 sub2.itemR(view, "mini_axis_size", text="Size")
74                 sub2.itemR(view, "mini_axis_brightness", text="Brightness")
75                 
76                 col = split.column()
77                 sub = col.split(percentage=0.85)
78                 
79                 sub1 = sub.column()
80                 sub1.itemL(text="View Manipulation:")
81                 sub1.itemR(view, "auto_depth")
82                 sub1.itemR(view, "global_pivot")
83                 sub1.itemR(view, "zoom_to_mouse")
84                 sub1.itemR(view, "rotate_around_selection")
85                 sub1.itemS()
86                 
87                 
88                 sub1.itemR(view, "auto_perspective")
89                 sub1.itemR(view, "smooth_view")
90                 sub1.itemR(view, "rotation_angle")
91
92                 col = split.column()
93                 sub = col.split(percentage=0.85)
94                 sub1 = sub.column()
95                 
96 #Toolbox doesn't exist yet
97 #               sub1.itemL(text="Toolbox:")
98 #               sub1.itemR(view, "use_column_layout")
99 #               sub1.itemL(text="Open Toolbox Delay:")
100 #               sub1.itemR(view, "open_left_mouse_delay", text="Hold LMB")
101 #               sub1.itemR(view, "open_right_mouse_delay", text="Hold RMB")
102                 
103                 #manipulator
104                 sub1.itemR(view, "use_manipulator")
105                 sub2 = sub1.column()
106                 sub2.enabled = view.use_manipulator
107                 sub2.itemR(view, "manipulator_size", text="Size")
108                 sub2.itemR(view, "manipulator_handle_size", text="Handle Size")
109                 sub2.itemR(view, "manipulator_hotspot", text="Hotspot") 
110                 
111                 sub1.itemS()
112                 sub1.itemS()
113                 sub1.itemS()
114                 
115                 sub1.itemL(text="Menus:")
116                 sub1.itemR(view, "open_mouse_over")
117                 sub1.itemL(text="Menu Open Delay:")
118                 sub1.itemR(view, "open_toplevel_delay", text="Top Level")
119                 sub1.itemR(view, "open_sublevel_delay", text="Sub Level")
120
121 class USERPREF_PT_edit(bpy.types.Panel):
122         bl_space_type = 'USER_PREFERENCES'
123         bl_label = "Edit"
124         bl_show_header = False
125
126         def poll(self, context):
127                 userpref = context.user_preferences
128                 return (userpref.active_section == 'EDITING')
129
130         def draw(self, context):
131                 layout = self.layout
132                 
133                 userpref = context.user_preferences
134                 edit = userpref.edit
135                 
136                 split = layout.split()
137                 
138                 col = split.column()
139                 sub = col.split(percentage=0.85)
140                 
141                 sub1 = sub.column()
142                 sub1.itemL(text="Link Materials To:")
143                 sub1.row().itemR(edit, "material_link", expand=True)
144                 sub1.itemS()
145                 sub1.itemS()
146                 sub1.itemS()
147                 sub1.itemL(text="New Objects:")
148                 sub1.itemR(edit, "enter_edit_mode")
149                 sub1.itemL(text="Align To:")
150                 sub1.row().itemR(edit, "object_align", expand=True)
151                 sub1.itemS()
152                 sub1.itemS()
153                 sub1.itemS()
154                 
155                 sub1.itemL(text="Undo:")
156                 sub1.itemR(edit, "global_undo")
157                 sub1.itemR(edit, "undo_steps", text="Steps")
158                 sub1.itemR(edit, "undo_memory_limit", text="Memory Limit")
159                 
160                 col = split.column()
161                 sub = col.split(percentage=0.85)
162                 
163                 sub1 = sub.column()
164                 sub1.itemL(text="Snap:")
165                 sub1.itemR(edit, "snap_translate", text="Translate")
166                 sub1.itemR(edit, "snap_rotate", text="Rotate")
167                 sub1.itemR(edit, "snap_scale", text="Scale")
168                 sub1.itemS()
169                 sub1.itemS()
170                 sub1.itemS()
171                 sub1.itemL(text="Grease Pencil:")
172                 sub1.itemR(edit, "grease_pencil_manhattan_distance", text="Manhattan Distance")
173                 sub1.itemR(edit, "grease_pencil_euclidean_distance", text="Euclidean Distance")
174                 # sub1.itemR(edit, "grease_pencil_simplify_stroke", text="Simplify Stroke")
175                 sub1.itemR(edit, "grease_pencil_eraser_radius", text="Eraser Radius")
176                 sub1.itemR(edit, "grease_pencil_smooth_stroke", text="Smooth Stroke")
177                 
178                 col = split.column()
179                 sub = col.split(percentage=0.85)
180                 
181                 sub1 = sub.column()
182                 sub1.itemL(text="Keyframing:")
183                 sub1.itemR(edit, "use_visual_keying")
184                 sub1.itemR(edit, "keyframe_insert_needed", text="Only Insert Needed")
185                 sub1.itemS()
186                 sub1.itemL(text="New F-Curve Defaults:")
187                 sub1.itemR(edit, "new_interpolation_type", text="Interpolation")
188                 sub1.itemS()
189                 sub1.itemR(edit, "auto_keying_enable", text="Auto Keyframing:")
190                 sub2 = sub1.column()
191                 sub2.active = edit.auto_keying_enable
192                 sub2.itemR(edit, "auto_keyframe_insert_keyingset", text="Only Insert for Keying Set")
193                 sub2.itemR(edit, "auto_keyframe_insert_available", text="Only Insert Available")
194                 
195                 sub1.itemS()
196                 sub1.itemS()
197                 sub1.itemS()
198                 
199                 sub1.itemL(text="Transform:")
200                 sub1.itemR(edit, "drag_immediately")
201                 
202                 sub1.itemS()
203                 sub1.itemS()
204                 sub1.itemS()
205
206                 col = split.column()
207                 sub = col.split(percentage=0.85)
208                 
209                 sub1 = sub.column()
210                 sub1.itemL(text="Duplicate Data:")
211                 sub1.itemR(edit, "duplicate_mesh", text="Mesh")
212                 sub1.itemR(edit, "duplicate_surface", text="Surface")
213                 sub1.itemR(edit, "duplicate_curve", text="Curve")
214                 sub1.itemR(edit, "duplicate_text", text="Text")
215                 sub1.itemR(edit, "duplicate_metaball", text="Metaball")
216                 sub1.itemR(edit, "duplicate_armature", text="Armature")
217                 sub1.itemR(edit, "duplicate_lamp", text="Lamp")
218                 sub1.itemR(edit, "duplicate_material", text="Material")
219                 sub1.itemR(edit, "duplicate_texture", text="Texture")
220                 sub1.itemR(edit, "duplicate_ipo", text="F-Curve")
221                 sub1.itemR(edit, "duplicate_action", text="Action")
222                 sub1.itemR(edit, "duplicate_particle", text="Particle")
223                 
224 class USERPREF_PT_system(bpy.types.Panel):
225         bl_space_type = 'USER_PREFERENCES'
226         bl_label = "System"
227         bl_show_header = False
228
229         def poll(self, context):
230                 userpref = context.user_preferences
231                 return (userpref.active_section == 'SYSTEM')
232
233         def draw(self, context):
234                 layout = self.layout
235                 
236                 userpref = context.user_preferences
237                 system = userpref.system
238                 
239                 split = layout.split()
240                 
241                 col = split.column()
242                 sub = col.split(percentage=0.9)
243                 
244                 sub1 = sub.column()
245                 sub1.itemL(text="General:")
246                 sub1.itemR(system, "dpi")
247                 sub1.itemR(system, "frame_server_port")
248                 sub1.itemR(system, "scrollback", text="Console Scrollback")
249                 sub1.itemR(system, "emulate_numpad")
250                 sub1.itemR(system, "auto_run_python_scripts")
251                 
252                 sub1.itemS()
253                 sub1.itemS()
254                 sub1.itemS()
255                 
256                 sub1.itemL(text="Sound:")
257                 sub1.row().itemR(system, "audio_device", expand=True)
258                 sub2 = sub1.column()
259                 sub2.active = system.audio_device != 'NONE'
260                 sub2.itemR(system, "enable_all_codecs")
261                 sub2.itemR(system, "game_sound")
262                 sub2.itemR(system, "audio_channels", text="Channels")
263                 sub2.itemR(system, "audio_mixing_buffer", text="Mixing Buffer")
264                 sub2.itemR(system, "audio_sample_rate", text="Sample Rate")
265                 sub2.itemR(system, "audio_sample_format", text="Sample Format")
266                 
267                 col = split.column()    
268                 sub = col.split(percentage=0.9)
269                 
270                 sub1 = sub .column()
271                 sub1.itemL(text="Weight Colors:")
272                 sub1.itemR(system, "use_weight_color_range", text="Use Custom Range")
273                 sub2 = sub1.column()
274                 sub2.active = system.use_weight_color_range
275                 sub2.template_color_ramp(system, "weight_color_range", expand=True)
276                 
277                 sub1.itemS()
278                 sub1.itemS()
279                 sub1.itemS()
280                 
281                 sub1.itemR(system, "language")
282                 sub1.itemL(text="Translate:")
283                 sub1.itemR(system, "translate_tooltips", text="Tooltips")
284                 sub1.itemR(system, "translate_buttons", text="Labels")
285                 sub1.itemR(system, "translate_toolbox", text="Toolbox")
286                 
287                 sub1.itemS()
288                 
289                 sub1.itemR(system, "use_textured_fonts")
290                 
291                 col = split.column()
292                 sub = col.split(percentage=0.9)
293                 
294                 sub1 = sub.column()
295
296                 sub1.itemL(text="OpenGL:")
297                 sub1.itemR(system, "clip_alpha", slider=True)
298                 sub1.itemR(system, "use_mipmaps")
299                 sub1.itemR(system, "use_vbos")
300                 sub1.itemL(text="Window Draw Method:")
301                 sub1.row().itemR(system, "window_draw_method", expand=True)
302                 sub1.itemL(text="Textures:")
303                 sub1.itemR(system, "gl_texture_limit", text="Limit Size")
304                 sub1.itemR(system, "texture_time_out", text="Time Out")
305                 sub1.itemR(system, "texture_collection_rate", text="Collection Rate")
306                 
307                 sub1.itemS()
308                 sub1.itemS()
309                 sub1.itemS()
310                 
311                 sub1.itemL(text="Sequencer:")
312                 sub1.itemR(system, "prefetch_frames")
313                 sub1.itemR(system, "memory_cache_limit")
314                 
315 class USERPREF_PT_file(bpy.types.Panel):
316         bl_space_type = 'USER_PREFERENCES'
317         bl_label = "Files"
318         bl_show_header = False
319
320         def poll(self, context):
321                 userpref = context.user_preferences
322                 return (userpref.active_section == 'FILES')
323
324         def draw(self, context):
325                 layout = self.layout
326                 
327                 userpref = context.user_preferences
328                 paths = userpref.filepaths
329                 
330                 split = layout.split(percentage=0.6)
331                 
332                 col = split.column()
333                 col.itemL(text="File Paths:")
334                 sub = col.split(percentage=0.3)
335                 
336                 sub.itemL(text="Fonts:")
337                 sub.itemR(paths, "fonts_directory", text="")
338                 sub = col.split(percentage=0.3)
339                 sub.itemL(text="Textures:")
340                 sub.itemR(paths, "textures_directory", text="")
341                 sub = col.split(percentage=0.3)
342                 sub.itemL(text="Texture Plugins:")
343                 sub.itemR(paths, "texture_plugin_directory", text="")
344                 sub = col.split(percentage=0.3)
345                 sub.itemL(text="Sequence Plugins:")
346                 sub.itemR(paths, "sequence_plugin_directory", text="")
347                 sub = col.split(percentage=0.3)
348                 sub.itemL(text="Render Output:")
349                 sub.itemR(paths, "render_output_directory", text="")
350                 sub = col.split(percentage=0.3)
351                 sub.itemL(text="Scripts:")
352                 sub.itemR(paths, "python_scripts_directory", text="")
353                 sub = col.split(percentage=0.3)
354                 sub.itemL(text="Sounds:")
355                 sub.itemR(paths, "sounds_directory", text="")
356                 sub = col.split(percentage=0.3)
357                 sub.itemL(text="Temp:")
358                 sub.itemR(paths, "temporary_directory", text="")
359                 
360                 col = split.column()
361                 sub = col.split(percentage=0.2)
362                 sub1 = sub.column()
363                 sub2 = sub.column()
364                 sub2.itemL(text="Save & Load:")
365                 sub2.itemR(paths, "use_relative_paths")
366                 sub2.itemR(paths, "compress_file")
367                 sub2.itemR(paths, "load_ui")
368                 sub2.itemR(paths, "filter_file_extensions")
369                 sub2.itemR(paths, "hide_dot_files_datablocks")
370                 sub2.itemS()
371                 sub2.itemS()
372                 sub2.itemL(text="Auto Save:")
373                 sub2.itemR(paths, "save_version")
374                 sub2.itemR(paths, "recent_files")
375                 sub2.itemR(paths, "save_preview_images")
376                 sub2.itemR(paths, "auto_save_temporary_files")
377                 sub3 = sub2.column()
378                 sub3.enabled = paths.auto_save_temporary_files
379                 sub3.itemR(paths, "auto_save_time", text="Timer (mins)")
380
381 class USERPREF_PT_input(bpy.types.Panel):
382         bl_space_type = 'USER_PREFERENCES'
383         bl_label = "Input"
384         bl_show_header = False
385
386         def poll(self, context):
387                 userpref = context.user_preferences
388                 return (userpref.active_section == 'INPUT')
389
390         def draw(self, context):
391                 layout = self.layout
392                 
393                 userpref = context.user_preferences
394                 wm = context.manager
395                 #input = userpref.input
396                 input = userpref
397                 inputs = userpref.inputs
398
399                 split = layout.split(percentage=0.25)
400
401                 # General settings
402                 row = split.row()
403                 col = row.column()
404
405                 sub = col.column()
406                 sub.itemL(text="Configuration:")
407                 sub.item_pointerR(wm, "active_keyconfig", wm, "keyconfigs", text="")
408
409                 col.itemS()
410
411                 sub = col.column()
412                 sub.itemL(text="Mouse:")
413                 sub1 = sub.column()
414                 sub1.enabled = (inputs.select_mouse == 'RIGHT')
415                 sub1.itemR(inputs, "emulate_3_button_mouse")
416                 sub.itemR(inputs, "continuous_mouse")
417
418                 sub.itemL(text="Select With:")
419                 sub.row().itemR(inputs, "select_mouse", expand=True)
420                 sub.itemL(text="Middle Mouse:")
421                 sub.row().itemR(inputs, "middle_mouse", expand=True)
422                 
423                 sub.itemS()
424                 sub.itemS()
425                 sub.itemS()
426                 
427                 sub.itemL(text="Orbit Style:")
428                 sub.row().itemR(inputs, "view_rotation", expand=True)
429                 
430                 sub.itemL(text="Zoom Style:")
431                 sub.row().itemR(inputs, "viewport_zoom_style", expand=True)
432                 
433                 #sub.itemR(inputs, "use_middle_mouse_paste")
434
435                 #col.itemS()
436
437                 #sub = col.column()
438                 #sub.itemL(text="Mouse Wheel:")
439                 #sub.itemR(view, "wheel_invert_zoom", text="Invert Zoom")
440                 #sub.itemR(view, "wheel_scroll_lines", text="Scroll Lines")
441
442                 col.itemS()
443
444                 sub = col.column()
445                 sub.itemL(text="NDOF Device:")
446                 sub.itemR(inputs, "ndof_pan_speed", text="Pan Speed")
447                 sub.itemR(inputs, "ndof_rotate_speed", text="Orbit Speed")
448
449                 row.itemS()
450
451                 # Keymap Settings
452                 col = split.column()
453
454                 kc = wm.active_keyconfig
455                 defkc = wm.default_keyconfig
456                 km = wm.active_keymap
457
458                 subsplit = col.split()
459                 subsplit.item_pointerR(wm, "active_keymap", defkc, "keymaps", text="Map:")
460                 if km.user_defined:
461                         row = subsplit.row()
462                         row.itemO("WM_OT_keymap_restore", text="Restore")
463                         row.item_booleanO("WM_OT_keymap_restore", "all", True, text="Restore All")
464                 else:
465                         row = subsplit.row()
466                         row.itemO("WM_OT_keymap_edit", text="Edit")
467                         row.itemL()
468
469                 col.itemS()
470                 
471                 for kmi in km.items:
472                         subcol = col.column()
473                         subcol.set_context_pointer("keyitem", kmi)
474
475                         row = subcol.row()
476
477                         if kmi.expanded:
478                                 row.itemR(kmi, "expanded", text="", icon="ICON_TRIA_RIGHT")
479                         else:
480                                 row.itemR(kmi, "expanded", text="", icon="ICON_TRIA_RIGHT")
481
482                         itemrow = row.row()
483                         itemrow.enabled = km.user_defined
484                         itemrow.itemR(kmi, "active", text="", icon="ICON_CHECKBOX_DEHLT")
485
486                         itemcol = itemrow.column()
487                         itemcol.active = kmi.active
488                         row = itemcol.row()
489                         row.itemR(kmi, "idname", text="")
490
491                         sub = row.row()
492                         sub.scale_x = 0.6
493                         sub.itemR(kmi, "map_type", text="")
494
495                         sub = row.row(align=True)
496                         if kmi.map_type == 'KEYBOARD':
497                                 sub.itemR(kmi, "type", text="", full_event=True)
498                         elif kmi.map_type == 'MOUSE':
499                                 sub.itemR(kmi, "type", text="", full_event=True)
500                         elif kmi.map_type == 'TWEAK':
501                                 sub.scale_x = 0.5
502                                 sub.itemR(kmi, "type", text="")
503                                 sub.itemR(kmi, "value", text="")
504                         elif kmi.map_type == 'TIMER':
505                                 sub.itemR(kmi, "type", text="")
506                         else:
507                                 sub.itemL()
508
509                         if kmi.expanded:
510                                 if kmi.map_type not in ('TEXTINPUT', 'TIMER'):
511                                         sub = itemcol.row(align=True)
512
513                                         if kmi.map_type == 'KEYBOARD':
514                                                 sub.itemR(kmi, "type", text="", event=True)
515                                                 sub.itemR(kmi, "value", text="")
516                                         elif kmi.map_type == 'MOUSE':
517                                                 sub.itemR(kmi, "type", text="")
518                                                 sub.itemR(kmi, "value", text="")
519                                         else:
520                                                 sub.itemL()
521                                                 sub.itemL()
522
523                                         subrow = sub.row()
524                                         subrow.scale_x = 0.75
525                                         subrow.itemR(kmi, "shift")
526                                         subrow.itemR(kmi, "ctrl")
527                                         subrow.itemR(kmi, "alt")
528                                         subrow.itemR(kmi, "oskey", text="Cmd")
529                                         sub.itemR(kmi, "key_modifier", text="", event=True)
530
531                                 flow = itemcol.column_flow(columns=2)
532                                 props = kmi.properties
533
534                                 if props != None:
535                                         for pname in dir(props):
536                                                 if not props.is_property_hidden(pname):
537                                                         flow.itemR(props, pname)
538
539                                 itemcol.itemS()
540
541                         itemrow.itemO("wm.keyitem_remove", text="", icon="ICON_ZOOMOUT")
542
543                 itemrow = col.row()
544                 itemrow.itemL()
545                 itemrow.itemO("wm.keyitem_add", text="", icon="ICON_ZOOMIN")
546                 itemrow.enabled = km.user_defined
547
548 bpy.types.register(USERPREF_HT_header)
549 bpy.types.register(USERPREF_MT_view)
550 bpy.types.register(USERPREF_PT_tabs)
551 bpy.types.register(USERPREF_PT_interface)
552 bpy.types.register(USERPREF_PT_edit)
553 bpy.types.register(USERPREF_PT_system)
554 bpy.types.register(USERPREF_PT_file)
555 bpy.types.register(USERPREF_PT_input)
556
557 class WM_OT_keyconfig_export(bpy.types.Operator):
558         "Export key configuration to a python script."
559         bl_idname = "wm.keyconfig_export"
560         bl_label = "Export Key Configuration..."
561         bl_props = [
562                 bpy.props.StringProperty(attr="path", name="File Path", description="File path to write file to.")]
563
564         def _string_value(self, value):
565                 result = ""
566                 if isinstance(value, str):
567                         if value != "":
568                                 result = "\'%s\'" % value
569                 elif isinstance(value, bool):
570                         if value:
571                                 result = "True"
572                         else:
573                                 result = "False"
574                 elif isinstance(value, float):
575                         result = "%.10f" % value
576                 elif isinstance(value, int):
577                         result = "%d" % value
578                 elif getattr(value, '__len__', False):
579                         if len(value):
580                                 result = "["
581                                 for i in range(0, len(value)):
582                                         result += self._string_value(value[i])
583                                         if i != len(value)-1:
584                                                 result += ", "
585                                 result += "]"
586                 else:
587                         print("Export key configuration: can't write ", value)
588
589                 return result
590
591         def execute(self, context):
592                 if not self.path:
593                         raise Exception("File path not set.")
594
595                 f = open(self.path, "w")
596                 if not f:
597                         raise Exception("Could not open file.")
598
599                 wm = context.manager
600                 kc = wm.active_keyconfig
601
602                 f.write('# Configuration %s\n' % kc.name)
603
604                 f.write("wm = bpy.data.windowmanagers[0]\n");
605                 f.write("kc = wm.add_keyconfig(\'%s\')\n\n" % kc.name)
606
607                 for km in kc.keymaps:
608                         f.write("# Map %s\n" % km.name)
609                         f.write("km = kc.add_keymap(\'%s\', space_type=\'%s\', region_type=\'%s\')\n\n" % (km.name, km.space_type, km.region_type))
610                         for kmi in km.items:
611                                 f.write("kmi = km.add_item(\'%s\', \'%s\', \'%s\'" % (kmi.idname, kmi.type, kmi.value))
612                                 if kmi.shift:
613                                         f.write(", shift=True")
614                                 if kmi.ctrl:
615                                         f.write(", ctrl=True")
616                                 if kmi.alt:
617                                         f.write(", alt=True")
618                                 if kmi.oskey:
619                                         f.write(", oskey=True")
620                                 if kmi.key_modifier and kmi.key_modifier != 'NONE':
621                                         f.write(", key_modifier=\'%s\'" % kmi.key_modifier)
622                                 f.write(")\n")
623
624                                 props = kmi.properties
625
626                                 if props != None:
627                                         for pname in dir(props):
628                                                 if props.is_property_set(pname) and not props.is_property_hidden(pname):
629                                                         value = eval("props.%s" % pname)
630                                                         value = self._string_value(value)
631                                                         if value != "":
632                                                                 f.write("kmi.properties.%s = %s\n" % (pname, value))
633
634                         f.write("\n")
635
636                 f.close()
637
638                 return ('FINISHED',)
639
640         def invoke(self, context, event):       
641                 wm = context.manager
642                 wm.add_fileselect(self.__operator__)
643                 return ('RUNNING_MODAL',)
644
645 class WM_OT_keymap_edit(bpy.types.Operator):
646         "Edit key map."
647         bl_idname = "wm.keymap_edit"
648         bl_label = "Edit Key Map"
649
650         def execute(self, context):
651                 wm = context.manager
652                 km = wm.active_keymap
653                 km.copy_to_user()
654                 return ('FINISHED',)
655
656 class WM_OT_keymap_restore(bpy.types.Operator):
657         "Restore key map"
658         bl_idname = "wm.keymap_restore"
659         bl_label = "Restore Key Map"
660         bl_props = [bpy.props.BoolProperty(attr="all", name="All Keymaps", description="Restore all keymaps to default.")]
661
662         def execute(self, context):
663                 wm = context.manager
664
665                 if self.all:
666                         for km in wm.default_keyconfig.keymaps:
667                                 km.restore_to_default()
668                 else:
669                         km = wm.active_keymap
670                         km.restore_to_default()
671
672                 return ('FINISHED',)
673         
674 class WM_OT_keyitem_add(bpy.types.Operator):
675         "Add key map item."
676         bl_idname = "wm.keyitem_add"
677         bl_label = "Add Key Map Item"
678
679         def execute(self, context):
680                 wm = context.manager
681                 km = wm.active_keymap
682                 kmi = km.add_item("", "A", "PRESS")
683                 return ('FINISHED',)
684         
685 class WM_OT_keyitem_remove(bpy.types.Operator):
686         "Remove key map item."
687         bl_idname = "wm.keyitem_remove"
688         bl_label = "Remove Key Map Item"
689
690         def execute(self, context):
691                 wm = context.manager
692                 kmi = context.keyitem
693                 km = wm.active_keymap
694                 km.remove_item(kmi)
695                 return ('FINISHED',)
696
697 bpy.ops.add(WM_OT_keyconfig_export)
698 bpy.ops.add(WM_OT_keymap_edit)
699 bpy.ops.add(WM_OT_keymap_restore)
700 bpy.ops.add(WM_OT_keyitem_add)
701 bpy.ops.add(WM_OT_keyitem_remove)
702