[#21807] Import Key Configuration problems
[blender.git] / release / scripts / ui / space_userpref.py
index 42b6b1d1a5484468ee95aec895ebeeb42281e93b..4ee1f119f53626336e0b0305a0c69f4d0c085787 100644 (file)
 #
 #  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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 #
 # ##### END GPL LICENSE BLOCK #####
 
 # <pep8 compliant>
 import bpy
-import os, re, shutil
+import os
+import re
+import shutil
+
 
-# General UI Theme Settings (User Interface)
 def ui_items_general(col, context):
+    """ General UI Theme Settings (User Interface)
+    """
     row = col.row()
     sub = row.column()
     sub.prop(context, "outline")
@@ -38,9 +42,10 @@ def ui_items_general(col, context):
     subsub.active = context.shaded
     subsub.prop(context, "shadetop")
     subsub.prop(context, "shadedown")
-    
+
     col.separator()
-    
+
+
 def opengl_lamp_buttons(column, lamp):
     split = column.split(percentage=0.1)
 
@@ -166,6 +171,10 @@ class USERPREF_HT_header(bpy.types.Header):
             op.path = "keymap.py"
             op = layout.operator("wm.keyconfig_import", "Import Key Configuration...")
             op.path = "keymap.py"
+        elif userpref.active_section == 'ADDONS':
+            layout.operator_context = 'INVOKE_DEFAULT'
+            op = layout.operator("wm.addon_install", "Install Add-On...")
+            op.path = "*.py"
 
 
 class USERPREF_PT_tabs(bpy.types.Panel):
@@ -236,14 +245,14 @@ class USERPREF_PT_interface(bpy.types.Panel):
         col.prop(view, "auto_perspective")
         col.prop(view, "smooth_view")
         col.prop(view, "rotation_angle")
-        
+
         col.separator()
         col.separator()
-        
+
         col.label(text="2D Viewports:")
         col.prop(view, "view2d_grid_minimum_spacing", text="Minimum Grid Spacing")
         col.prop(view, "timecode_style")
-        
+
         row.separator()
         row.separator()
 
@@ -271,6 +280,10 @@ class USERPREF_PT_interface(bpy.types.Panel):
         col.prop(view, "open_toplevel_delay", text="Top Level")
         col.prop(view, "open_sublevel_delay", text="Sub Level")
 
+        col.separator()
+
+        col.prop(view, "show_splash")
+
 
 class USERPREF_PT_edit(bpy.types.Panel):
     bl_space_type = 'USER_PREFERENCES'
@@ -329,6 +342,11 @@ class USERPREF_PT_edit(bpy.types.Panel):
         #col.prop(edit, "grease_pencil_simplify_stroke", text="Simplify Stroke")
         col.prop(edit, "grease_pencil_eraser_radius", text="Eraser Radius")
         col.prop(edit, "grease_pencil_smooth_stroke", text="Smooth Stroke")
+        col.separator()
+        col.separator()
+        col.separator()
+        col.label(text="Playback:")
+        col.prop(edit, "use_negative_frames")
 
         row.separator()
         row.separator()
@@ -340,20 +358,20 @@ class USERPREF_PT_edit(bpy.types.Panel):
 
         col.separator()
 
-        col.label(text="New F-Curve Defaults:")
-        col.prop(edit, "new_interpolation_type", text="Interpolation")
-        col.prop(edit, "insertkey_xyz_to_rgb", text="XYZ to RGB")
-
-        col.separator()
-
-        col.prop(edit, "auto_keying_enable", text="Auto Keyframing:")
+        col.prop(edit, "use_auto_keying", text="Auto Keyframing:")
 
         sub = col.column()
 
-        sub.active = edit.auto_keying_enable
+        # sub.active = edit.use_auto_keying # incorrect, timeline can enable
         sub.prop(edit, "auto_keyframe_insert_keyingset", text="Only Insert for Keying Set")
         sub.prop(edit, "auto_keyframe_insert_available", text="Only Insert Available")
 
+        col.separator()
+
+        col.label(text="New F-Curve Defaults:")
+        col.prop(edit, "new_interpolation_type", text="Interpolation")
+        col.prop(edit, "insertkey_xyz_to_rgb", text="XYZ to RGB")
+
         col.separator()
         col.separator()
         col.separator()
@@ -408,7 +426,8 @@ class USERPREF_PT_system(bpy.types.Panel):
         col.prop(system, "dpi")
         col.prop(system, "frame_server_port")
         col.prop(system, "scrollback", text="Console Scrollback")
-        col.prop(system, "auto_run_python_scripts")
+        col.prop(system, "auto_execute_scripts")
+        col.prop(system, "tabs_as_spaces")
 
         col.separator()
         col.separator()
@@ -427,10 +446,10 @@ class USERPREF_PT_system(bpy.types.Panel):
         col.separator()
         col.separator()
         col.separator()
-        
+
         col.label(text="Screencast:")
         col.prop(system, "screencast_fps")
-        col.prop(system, "screencast_wait_time")     
+        col.prop(system, "screencast_wait_time")
         col.separator()
         col.separator()
         col.separator()
@@ -448,7 +467,7 @@ class USERPREF_PT_system(bpy.types.Panel):
         #col.separator()
 
         #col.prop(system, "use_textured_fonts")
-        
+
 
         # 2. Column
         column = split.column()
@@ -462,7 +481,7 @@ class USERPREF_PT_system(bpy.types.Panel):
         #Anti-aliasing is disabled as it breaks broder/lasso select
         #col.prop(system, "use_antialiasing")
         col.label(text="Window Draw Method:")
-        col.row().prop(system, "window_draw_method", expand=True)
+        col.prop(system, "window_draw_method", text="")
         col.label(text="Textures:")
         col.prop(system, "gl_texture_limit", text="Limit Size")
         col.prop(system, "texture_time_out", text="Time Out")
@@ -475,7 +494,7 @@ class USERPREF_PT_system(bpy.types.Panel):
         col.label(text="Sequencer:")
         col.prop(system, "prefetch_frames")
         col.prop(system, "memory_cache_limit")
-        
+
 
         # 3. Column
         column = split.column()
@@ -486,27 +505,27 @@ class USERPREF_PT_system(bpy.types.Panel):
         split.label()
         split.label(text="Colors:")
         split.label(text="Direction:")
-        
+
         lamp = system.solid_lights[0]
         opengl_lamp_buttons(column, lamp)
-        
+
         lamp = system.solid_lights[1]
         opengl_lamp_buttons(column, lamp)
-        
+
         lamp = system.solid_lights[2]
         opengl_lamp_buttons(column, lamp)
 
         column.separator()
         column.separator()
         column.separator()
-        
+
         column.label(text="Color Picker Type:")
         column.row().prop(system, "color_picker_type", text="")
-        
+
         column.separator()
         column.separator()
         column.separator()
-        
+
         column.prop(system, "use_weight_color_range", text="Custom Weight Paint Range")
         sub = column.column()
         sub.active = system.use_weight_color_range
@@ -532,7 +551,7 @@ class USERPREF_PT_theme(bpy.types.Panel):
         split_themes.prop(theme, "theme_area", expand=True)
 
         split = split_themes.split()
-        
+
         if theme.theme_area == 'USER_INTERFACE':
             col = split.column()
 
@@ -643,13 +662,28 @@ class USERPREF_PT_theme(bpy.types.Panel):
             col.prop(v3d, "object_grouped")
             col.prop(v3d, "object_grouped_active")
             col.prop(v3d, "transform")
+            col.prop(v3d, "nurb_uline")
+            col.prop(v3d, "nurb_vline")
+            col.prop(v3d, "nurb_sel_uline")
+            col.prop(v3d, "nurb_sel_vline")
+            col.prop(v3d, "handle_free")
+            col.prop(v3d, "handle_auto")
+            col.prop(v3d, "handle_vect")
+            col.prop(v3d, "handle_align")
+            col.prop(v3d, "handle_sel_free")
+            col.prop(v3d, "handle_sel_auto")
+            col.prop(v3d, "handle_sel_vect")
+            col.prop(v3d, "handle_sel_align")
+            col.prop(v3d, "act_spline")
 
             col = split.column()
             col.prop(v3d, "vertex")
             col.prop(v3d, "face", slider=True)
             col.prop(v3d, "normal")
+            col.prop(v3d, "vertex_normal")
             col.prop(v3d, "bone_solid")
             col.prop(v3d, "bone_pose")
+            col.prop(v3d, "edge_seam")
             #col.prop(v3d, "edge") Doesn't seem to work
 
         elif theme.theme_area == 'GRAPH_EDITOR':
@@ -939,19 +973,20 @@ class USERPREF_PT_theme(bpy.types.Panel):
 
             col = split.column()
             col.prop(prefs, "header_text")
-            
+
         elif theme.theme_area == 'CONSOLE':
             prefs = theme.console
-             
+
             col = split.column()
+            col.prop(prefs, "back")
             col.prop(prefs, "header")
-            
+
             col = split.column()
             col.prop(prefs, "line_output")
             col.prop(prefs, "line_input")
             col.prop(prefs, "line_info")
             col.prop(prefs, "line_error")
-            
+            col.prop(prefs, "cursor")
 
 
 class USERPREF_PT_file(bpy.types.Panel):
@@ -987,6 +1022,7 @@ class USERPREF_PT_file(bpy.types.Panel):
         sub.label(text="Scripts:")
         sub.label(text="Sounds:")
         sub.label(text="Temp:")
+        sub.label(text="Image Editor:")
         sub.label(text="Animation Player:")
 
         sub = col1.column()
@@ -998,6 +1034,7 @@ class USERPREF_PT_file(bpy.types.Panel):
         sub.prop(paths, "python_scripts_directory", text="")
         sub.prop(paths, "sounds_directory", text="")
         sub.prop(paths, "temporary_directory", text="")
+        sub.prop(paths, "image_editor", text="")
         subsplit = sub.split(percentage=0.3)
         subsplit.prop(paths, "animation_player_preset", text="")
         subsplit.prop(paths, "animation_player", text="")
@@ -1062,7 +1099,7 @@ class USERPREF_PT_input(bpy.types.Panel):
         row = col.row()
         row.prop(km, "children_expanded", text="", no_bg=True)
         row.label(text=km.name)
-        
+
         row.label()
         row.label()
 
@@ -1092,7 +1129,7 @@ class USERPREF_PT_input(bpy.types.Panel):
                 # "Add New" at end of keymap item list
                 col = self.indented_layout(col, level + 1)
                 subcol = col.split(percentage=0.2).column()
-                subcol.active = km.user_defined
+                subcol.enabled = km.user_defined
                 op = subcol.operator("wm.keyitem_add", text="Add New", icon='ZOOMIN')
 
             col.separator()
@@ -1156,7 +1193,7 @@ class USERPREF_PT_input(bpy.types.Panel):
         # Expanded, additional event settings
         if kmi.expanded:
             box = col.box()
-            
+
             box.enabled = km.user_defined
 
             if map_type not in ('TEXTINPUT', 'TIMER'):
@@ -1186,8 +1223,8 @@ class USERPREF_PT_input(bpy.types.Panel):
                 subrow.prop(kmi, "alt")
                 subrow.prop(kmi, "oskey", text="Cmd")
                 subrow.prop(kmi, "key_modifier", text="", event=True)
-                
-            def display_properties(properties, title = None):
+
+            def display_properties(properties, title=None):
                 box.separator()
                 if title:
                     box.label(text=title)
@@ -1196,7 +1233,7 @@ class USERPREF_PT_input(bpy.types.Panel):
                     if not properties.is_property_hidden(pname):
                         value = eval("properties." + pname)
                         if isinstance(value, bpy.types.OperatorProperties):
-                            display_properties(value, title = pname)
+                            display_properties(value, title=pname)
                         else:
                             flow.prop(properties, pname)
 
@@ -1268,6 +1305,7 @@ class USERPREF_PT_input(bpy.types.Panel):
 
         for km in kc.keymaps:
             km = km.active()
+            layout.set_context_pointer("keymap", km)
 
             filtered_items = [kmi for kmi in km.items if filter in kmi.name.lower()]
 
@@ -1282,10 +1320,8 @@ class USERPREF_PT_input(bpy.types.Panel):
 
                 if km.user_defined:
                     op = row.operator("wm.keymap_restore", text="Restore")
-                    op.keymap = km
                 else:
                     op = row.operator("wm.keymap_edit", text="Edit")
-                    op.keymap = km
 
                 for kmi in filtered_items:
                     self.draw_kmi(kc, km, kmi, col, 1)
@@ -1293,9 +1329,8 @@ class USERPREF_PT_input(bpy.types.Panel):
                 # "Add New" at end of keymap item list
                 col = self.indented_layout(layout, 1)
                 subcol = col.split(percentage=0.2).column()
-                subcol.active = km.user_defined
+                subcol.enabled = km.user_defined
                 op = subcol.operator("wm.keyitem_add", text="Add New", icon='ZOOMIN')
-                op.keymap = km
 
     def draw_hierarchy(self, defkc, layout):
         for entry in KM_HIERARCHY:
@@ -1303,9 +1338,9 @@ class USERPREF_PT_input(bpy.types.Panel):
 
     def draw(self, context):
         layout = self.layout
-        
+
         #import time
-        
+
         #start = time.time()
 
         userpref = context.user_preferences
@@ -1330,7 +1365,7 @@ class USERPREF_PT_input(bpy.types.Panel):
         row = subcol.row()
         row.prop_object(wm, "active_keyconfig", wm, "keyconfigs", text="Configuration:")
 
-        layout.set_context_pointer("keyconfig", wm.active_keyconfig) 
+        layout.set_context_pointer("keyconfig", wm.active_keyconfig)
         row.operator("wm.keyconfig_remove", text="", icon='X')
 
         row.prop(kc, "filter", icon="VIEWZOOM")
@@ -1341,23 +1376,320 @@ class USERPREF_PT_input(bpy.types.Panel):
             self.draw_filtered(kc, col)
         else:
             self.draw_hierarchy(kc, col)
-            
+
         #print("runtime", time.time() - start)
 
-bpy.types.register(USERPREF_HT_header)
-bpy.types.register(USERPREF_PT_tabs)
-bpy.types.register(USERPREF_PT_interface)
-bpy.types.register(USERPREF_PT_theme)
-bpy.types.register(USERPREF_PT_edit)
-bpy.types.register(USERPREF_PT_system)
-bpy.types.register(USERPREF_PT_file)
-bpy.types.register(USERPREF_PT_input)
+
+class USERPREF_PT_addons(bpy.types.Panel):
+    bl_space_type = 'USER_PREFERENCES'
+    bl_label = "Addons"
+    bl_region_type = 'WINDOW'
+    bl_show_header = False
+
+    def poll(self, context):
+        userpref = context.user_preferences
+        return (userpref.active_section == 'ADDONS')
+
+    def _addon_list(self):
+        import sys
+        modules = []
+        loaded_modules = set()
+        paths = bpy.utils.script_paths("addons")
+        # sys.path.insert(0, None)
+        for path in paths:
+            # sys.path[0] = path
+            modules.extend(bpy.utils.modules_from_path(path, loaded_modules))
+
+        # del sys.path[0]
+        return modules
+
+    def draw(self, context):
+        layout = self.layout
+
+        userpref = context.user_preferences
+        used_ext = {ext.module for ext in userpref.addons}
+
+        # collect the categories that can be filtered on
+        addons = [(mod, addon_info_get(mod)) for mod in self._addon_list()]
+
+        cats = {info["category"] for mod, info in addons}
+        cats.discard("")
+
+        cats = ['All', 'Disabled', 'Enabled'] + sorted(cats)
+
+        bpy.types.Scene.EnumProperty(items=[(cats[i], cats[i], str(i)) for i in range(len(cats))],
+            name="Category", attr="addon_filter", description="Filter add-ons by category")
+        bpy.types.Scene.StringProperty(name="Search", attr="addon_search",
+            description="Search within the selected filter")
+
+        row = layout.row()
+        row.prop(context.scene, "addon_filter", text="Filter")
+        row.prop(context.scene, "addon_search", text="Search", icon='VIEWZOOM')
+        layout.separator()
+
+        filter = context.scene.addon_filter
+        search = context.scene.addon_search.lower()
+
+        for mod, info in addons:
+            module_name = mod.__name__
+
+            # check if add-on should be visible with current filters
+            if filter != "All" and \
+                    filter != info["category"] and \
+                    not (module_name not in used_ext and filter == "Disabled"):
+
+                continue
+
+            if search and search not in info["name"].lower():
+                if info["author"]:
+                    if search not in info["author"].lower():
+                        continue
+                else:
+                    continue
+
+            # Addon UI Code
+            box = layout.column().box()
+            column = box.column()
+            row = column.row()
+
+            # Arrow #
+            # If there are Infos or UI is expanded
+            if info["expanded"]:
+                row.operator("wm.addon_expand", icon="TRIA_DOWN").module = module_name
+            elif info["author"] or info["version"] or info["url"] or info["location"]:
+                row.operator("wm.addon_expand", icon="TRIA_RIGHT").module = module_name
+            else:
+                # Else, block UI
+                arrow = row.column()
+                arrow.enabled = False
+                arrow.operator("wm.addon_expand", icon="TRIA_RIGHT").module = module_name
+
+            row.label(text=info["name"])
+            row.operator("wm.addon_disable" if module_name in used_ext else "wm.addon_enable").module = module_name
+
+            # Expanded UI (only if additional infos are available)
+            if info["expanded"]:
+                if info["author"]:
+                    split = column.row().split(percentage=0.15)
+                    split.label(text='Author:')
+                    split.label(text=info["author"])
+                if info["version"]:
+                    split = column.row().split(percentage=0.15)
+                    split.label(text='Version:')
+                    split.label(text=info["version"])
+                if info["location"]:
+                    split = column.row().split(percentage=0.15)
+                    split.label(text='Location:')
+                    split.label(text=info["location"])
+                if info["url"]:
+                    split = column.row().split(percentage=0.15)
+                    split.label(text="Internet:")
+                    split.operator("wm.addon_links", text="Link to the Wiki").link = info["url"]
+                    split.separator()
+                    split.separator()
+
+        # Append missing scripts
+        # First collect scripts that are used but have no script file.
+        module_names = {mod.__name__ for mod, info in addons}
+        missing_modules = {ext for ext in used_ext if ext not in module_names}
+
+        if missing_modules and filter in ("All", "Enabled"):
+            layout.column().separator()
+            layout.column().label(text="Missing script files")
+
+            module_names = {mod.__name__ for mod, info in addons}
+            for ext in sorted(missing_modules):
+                # Addon UI Code
+                box = layout.column().box()
+                column = box.column()
+                row = column.row()
+
+                row.label(text=ext, icon="ERROR")
+                row.operator("wm.addon_disable").module = ext
 
 from bpy.props import *
 
 
+def addon_info_get(mod, info_basis={"name": "", "author": "", "version": "", "blender": "", "location": "", "url": "", "category": "", "expanded": False}):
+    addon_info = getattr(mod, "bl_addon_info", {})
+
+    # avoid re-initializing
+    if "_init" in addon_info:
+        return addon_info
+
+    if not addon_info:
+        mod.bl_addon_info = addon_info
+
+    for key, value in info_basis.items():
+        addon_info.setdefault(key, value)
+
+    if not addon_info["name"]:
+        addon_info["name"] = mod.__name__
+
+    addon_info["_init"] = None
+    return addon_info
+
+
+class WM_OT_addon_enable(bpy.types.Operator):
+    "Enable an addon"
+    bl_idname = "wm.addon_enable"
+    bl_label = "Enable Add-On"
+
+    module = StringProperty(name="Module", description="Module name of the addon to enable")
+
+    def execute(self, context):
+        module_name = self.properties.module
+
+        try:
+            mod = __import__(module_name)
+            mod.register()
+        except:
+            import traceback
+            traceback.print_exc()
+            return {'CANCELLED'}
+
+        ext = context.user_preferences.addons.new()
+        ext.module = module_name
+
+        # check if add-on is written for current blender version, or raise a warning
+        info = addon_info_get(mod)
+
+        if info.get("blender", (0, 0, 0)) > bpy.app.version:
+            self.report("WARNING','This script was written for a newer version of Blender and might not function (correctly).\nThe script is enabled though.")
+
+        return {'FINISHED'}
+
+
+class WM_OT_addon_disable(bpy.types.Operator):
+    "Disable an addon"
+    bl_idname = "wm.addon_disable"
+    bl_label = "Disable Add-On"
+
+    module = StringProperty(name="Module", description="Module name of the addon to disable")
+
+    def execute(self, context):
+        import traceback
+        module_name = self.properties.module
+
+        try:
+            mod = __import__(module_name)
+            mod.unregister()
+        except:
+            traceback.print_exc()
+
+        addons = context.user_preferences.addons
+        ok = True
+        while ok: # incase its in more then once.
+            ok = False
+            for ext in addons:
+                if ext.module == module_name:
+                    addons.remove(ext)
+                    ok = True
+                    break
+
+        return {'FINISHED'}
+
+
+class WM_OT_addon_install(bpy.types.Operator):
+    "Install an addon"
+    bl_idname = "wm.addon_install"
+    bl_label = "Install Add-On"
+
+    module = StringProperty(name="Module", description="Module name of the addon to disable")
+
+    path = StringProperty(name="File Path", description="File path to write file to")
+    filename = StringProperty(name="File Name", description="Name of the file")
+    directory = StringProperty(name="Directory", description="Directory of the file")
+    filter_folder = BoolProperty(name="Filter folders", description="", default=True, options={'HIDDEN'})
+    filter_python = BoolProperty(name="Filter python", description="", default=True, options={'HIDDEN'})
+
+    def execute(self, context):
+        import traceback
+        import zipfile
+        pyfile = self.properties.path
+
+        path_addons = bpy.utils.script_paths("addons")[-1]
+
+        #check to see if the file is in compressed format (.zip)
+        if zipfile.is_zipfile(pyfile):
+            try:
+                file_to_extract = zipfile.ZipFile(pyfile, 'r')
+
+                #extract the file to "addons"
+                file_to_extract.extractall(path_addons)
+
+            except:
+                traceback.print_exc()
+                return {'CANCELLED'}
+
+        else:
+            path_dest = os.path.join(path_addons, os.path.basename(pyfile))
+
+            if os.path.exists(path_dest):
+                self.report({'WARNING'}, "File already installed to '%s'\n" % path_dest)
+                return {'CANCELLED'}
+
+            #if not compressed file just copy into the addon path
+            try:
+                shutil.copyfile(pyfile, path_dest)
+
+            except:
+                traceback.print_exc()
+                return {'CANCELLED'}
+
+        # TODO, should not be a warning.
+        # self.report({'WARNING'}, "File installed to '%s'\n" % path_dest)
+        return {'FINISHED'}
+
+    def invoke(self, context, event):
+        paths = bpy.utils.script_paths("addons")
+        if not paths:
+            self.report({'ERROR'}, "No 'addons' path could be found in " + str(bpy.utils.script_paths()))
+            return {'CANCELLED'}
+
+        wm = context.manager
+        wm.add_fileselect(self)
+        return {'RUNNING_MODAL'}
+
+
+class WM_OT_addon_expand(bpy.types.Operator):
+    "Display more information on this add-on"
+    bl_idname = "wm.addon_expand"
+    bl_label = ""
+
+    module = StringProperty(name="Module", description="Module name of the addon to expand")
+
+    def execute(self, context):
+        module_name = self.properties.module
+
+        # unlikely to fail, module should have alredy been imported
+        try:
+            mod = __import__(module_name)
+        except:
+            import traceback
+            traceback.print_exc()
+            return {'CANCELLED'}
+
+        info = addon_info_get(mod)
+        info["expanded"] = not info["expanded"]
+        return {'FINISHED'}
+
+
+class WM_OT_addon_links(bpy.types.Operator):
+    "Open the Blender Wiki in the Webbrowser"
+    bl_idname = "wm.addon_links"
+    bl_label = ""
+
+    link = StringProperty(name="Link", description="Link to open")
+
+    def execute(self, context):
+        import webbrowser
+        webbrowser.open(self.properties.link)
+        return {'FINISHED'}
+
+
 class WM_OT_keyconfig_test(bpy.types.Operator):
-    "Test keyconfig for conflicts."
+    "Test keyconfig for conflicts"
     bl_idname = "wm.keyconfig_test"
     bl_label = "Test Key Configuration for Conflicts"
 
@@ -1385,7 +1717,7 @@ class WM_OT_keyconfig_test(bpy.types.Operator):
                 s.append(", key_modifier=\'%s\'" % kmi.key_modifier)
 
             s.append(")\n")
-            
+
             def export_properties(prefix, properties):
                 for pname in dir(properties):
                     if not properties.is_property_hidden(pname):
@@ -1465,81 +1797,65 @@ class WM_OT_keyconfig_test(bpy.types.Operator):
 
 
 def _string_value(value):
-    result = ""
-    if isinstance(value, str):
-        if value != "":
-            result = "\'%s\'" % value
-    elif isinstance(value, bool):
-        if value:
-            result = "True"
-        else:
-            result = "False"
-    elif isinstance(value, float):
-        result = "%.10f" % value
-    elif isinstance(value, int):
-        result = "%d" % 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):
-        if len(value):
-            result = "["
-            for i in range(0, len(value)):
-                result += _string_value(value[i])
-                if i != len(value)-1:
-                    result += ", "
-            result += "]"
+        repr(list(value))
     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."
+    "Import key configuration from a python script"
     bl_idname = "wm.keyconfig_import"
     bl_label = "Import Key Configuration..."
 
-    path = bpy.props.StringProperty(name="File Path", description="File path to write file to.")
-    filename = bpy.props.StringProperty(name="File Name", description="Name of the file.")
-    directory = bpy.props.StringProperty(name="Directory", description="Directory of the file.")
-    filter_folder = bpy.props.BoolProperty(name="Filter folders", description="", default=True, hidden=True)
-    filter_text = bpy.props.BoolProperty(name="Filter text", description="", default=True, hidden=True)
-    filter_python = bpy.props.BoolProperty(name="Filter python", description="", default=True, hidden=True)
+    path = StringProperty(name="File Path", description="File path to write file to")
+    filename = StringProperty(name="File Name", description="Name of the file")
+    directory = StringProperty(name="Directory", description="Directory of the file")
+    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'})
 
-    keep_original = bpy.props.BoolProperty(name="Keep original", description="Keep original file after copying to configuration folder", default=True)
+    keep_original = BoolProperty(name="Keep original", description="Keep original file after copying to configuration folder", default=True)
 
     def execute(self, context):
         if not self.properties.path:
-            raise Exception("File path not set.")
+            raise Exception("File path not set")
 
         f = open(self.properties.path, "r")
         if not f:
-            raise Exception("Could not open file.")
+            raise Exception("Could not open file")
 
         name_pattern = re.compile("^kc = wm.add_keyconfig\('(.*)'\)$")
 
         for line in f.readlines():
             match = name_pattern.match(line)
-            
+
             if match:
                 config_name = match.groups()[0]
-        
+
         f.close()
-        
+
         path = os.path.split(os.path.split(__file__)[0])[0] # remove ui/space_userpref.py
         path = os.path.join(path, "cfg")
-        
+
         # create config folder if needed
         if not os.path.exists(path):
-            os.mkdir(path)        
-        
+            os.mkdir(path)
+
         path = os.path.join(path, config_name + ".py")
-            
+
         if self.properties.keep_original:
             shutil.copy(self.properties.path, path)
         else:
             shutil.move(self.properties.path, path)
-        
-        __import__(config_name) 
-        
-        wm = bpy.data.window_managers[0]
+
+        exec("import " + config_name)
+
+        wm = bpy.context.manager
         wm.active_keyconfig = wm.keyconfigs[config_name]
 
         return {'FINISHED'}
@@ -1548,26 +1864,27 @@ class WM_OT_keyconfig_import(bpy.types.Operator):
         wm = context.manager
         wm.add_fileselect(self)
         return {'RUNNING_MODAL'}
-    
+
+
 class WM_OT_keyconfig_export(bpy.types.Operator):
-    "Export key configuration to a python script."
+    "Export key configuration to a python script"
     bl_idname = "wm.keyconfig_export"
     bl_label = "Export Key Configuration..."
 
-    path = bpy.props.StringProperty(name="File Path", description="File path to write file to.")
-    filename = bpy.props.StringProperty(name="File Name", description="Name of the file.")
-    directory = bpy.props.StringProperty(name="Directory", description="Directory of the file.")
-    filter_folder = bpy.props.BoolProperty(name="Filter folders", description="", default=True, hidden=True)
-    filter_text = bpy.props.BoolProperty(name="Filter text", description="", default=True, hidden=True)
-    filter_python = bpy.props.BoolProperty(name="Filter python", description="", default=True, hidden=True)
+    path = StringProperty(name="File Path", description="File path to write file to")
+    filename = StringProperty(name="File Name", description="Name of the file")
+    directory = StringProperty(name="Directory", description="Directory of the file")
+    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'})
 
     def execute(self, context):
         if not self.properties.path:
-            raise Exception("File path not set.")
+            raise Exception("File path not set")
 
         f = open(self.properties.path, "w")
         if not f:
-            raise Exception("Could not open file.")
+            raise Exception("Could not open file")
 
         wm = context.manager
         kc = wm.active_keyconfig
@@ -1580,7 +1897,7 @@ class WM_OT_keyconfig_export(bpy.types.Operator):
         f.write("# Configuration %s\n" % name)
 
         f.write("import bpy\n\n")
-        f.write("wm = bpy.data.window_managers[0]\n")
+        f.write("wm = bpy.context.manager\n")
         f.write("kc = wm.add_keyconfig('%s')\n\n" % name)
 
         for km in kc.keymaps:
@@ -1617,9 +1934,9 @@ class WM_OT_keyconfig_export(bpy.types.Operator):
                                 value = _string_value(value)
                                 if value != "":
                                     f.write(prefix + ".%s = %s\n" % (pname, value))
-    
+
                 props = kmi.properties
-    
+
                 if props is not None:
                     export_properties("kmi.properties", props)
 
@@ -1636,7 +1953,7 @@ class WM_OT_keyconfig_export(bpy.types.Operator):
 
 
 class WM_OT_keymap_edit(bpy.types.Operator):
-    "Edit key map."
+    "Edit key map"
     bl_idname = "wm.keymap_edit"
     bl_label = "Edit Key Map"
 
@@ -1648,11 +1965,11 @@ class WM_OT_keymap_edit(bpy.types.Operator):
 
 
 class WM_OT_keymap_restore(bpy.types.Operator):
-    "Restore key map(s)."
+    "Restore key map(s)"
     bl_idname = "wm.keymap_restore"
     bl_label = "Restore Key Map(s)"
 
-    all = BoolProperty(attr="all", name="All Keymaps", description="Restore all keymaps to default.")
+    all = BoolProperty(attr="all", name="All Keymaps", description="Restore all keymaps to default")
 
     def execute(self, context):
         wm = context.manager
@@ -1668,11 +1985,11 @@ class WM_OT_keymap_restore(bpy.types.Operator):
 
 
 class WM_OT_keyitem_restore(bpy.types.Operator):
-    "Restore key map item."
+    "Restore key map item"
     bl_idname = "wm.keyitem_restore"
     bl_label = "Restore Key Map Item"
 
-    item_id = IntProperty(attr="item_id", name="Item Identifier",  description="Identifier of the item to remove")
+    item_id = IntProperty(attr="item_id", name="Item Identifier", description="Identifier of the item to remove")
 
     def execute(self, context):
         wm = context.manager
@@ -1685,7 +2002,7 @@ class WM_OT_keyitem_restore(bpy.types.Operator):
 
 
 class WM_OT_keyitem_add(bpy.types.Operator):
-    "Add key map item."
+    "Add key map item"
     bl_idname = "wm.keyitem_add"
     bl_label = "Add Key Map Item"
 
@@ -1709,12 +2026,12 @@ class WM_OT_keyitem_add(bpy.types.Operator):
 
 
 class WM_OT_keyitem_remove(bpy.types.Operator):
-    "Remove key map item."
+    "Remove key map item"
     bl_idname = "wm.keyitem_remove"
     bl_label = "Remove Key Map Item"
 
-    item_id = IntProperty(attr="item_id", name="Item Identifier",  description="Identifier of the item to remove")
-    
+    item_id = IntProperty(attr="item_id", name="Item Identifier", description="Identifier of the item to remove")
+
     def execute(self, context):
         wm = context.manager
         km = context.keymap
@@ -1722,8 +2039,9 @@ class WM_OT_keyitem_remove(bpy.types.Operator):
         km.remove_item(kmi)
         return {'FINISHED'}
 
+
 class WM_OT_keyconfig_remove(bpy.types.Operator):
-    "Remove key config."
+    "Remove key config"
     bl_idname = "wm.keyconfig_remove"
     bl_label = "Remove Key Config"
 
@@ -1733,27 +2051,60 @@ class WM_OT_keyconfig_remove(bpy.types.Operator):
 
     def execute(self, context):
         wm = context.manager
-        
+
         keyconfig = wm.active_keyconfig
-        
+
         module = __import__(keyconfig.name)
-        
+
         os.remove(module.__file__)
 
         compiled_path = module.__file__ + "c" # for .pyc
-        
+
         if os.path.exists(compiled_path):
             os.remove(compiled_path)
-        
+
         wm.remove_keyconfig(keyconfig)
         return {'FINISHED'}
 
-bpy.types.register(WM_OT_keyconfig_export)
-bpy.types.register(WM_OT_keyconfig_import)
-bpy.types.register(WM_OT_keyconfig_test)
-bpy.types.register(WM_OT_keyconfig_remove)
-bpy.types.register(WM_OT_keymap_edit)
-bpy.types.register(WM_OT_keymap_restore)
-bpy.types.register(WM_OT_keyitem_add)
-bpy.types.register(WM_OT_keyitem_remove)
-bpy.types.register(WM_OT_keyitem_restore)
+
+classes = [
+    USERPREF_HT_header,
+    USERPREF_PT_tabs,
+    USERPREF_PT_interface,
+    USERPREF_PT_theme,
+    USERPREF_PT_edit,
+    USERPREF_PT_system,
+    USERPREF_PT_file,
+    USERPREF_PT_input,
+    USERPREF_PT_addons,
+
+    WM_OT_addon_enable,
+    WM_OT_addon_disable,
+    WM_OT_addon_install,
+    WM_OT_addon_expand,
+    WM_OT_addon_links,
+
+    WM_OT_keyconfig_export,
+    WM_OT_keyconfig_import,
+    WM_OT_keyconfig_test,
+    WM_OT_keyconfig_remove,
+    WM_OT_keymap_edit,
+    WM_OT_keymap_restore,
+    WM_OT_keyitem_add,
+    WM_OT_keyitem_remove,
+    WM_OT_keyitem_restore]
+
+
+def register():
+    register = bpy.types.register
+    for cls in classes:
+        register(cls)
+
+
+def unregister():
+    unregister = bpy.types.unregister
+    for cls in classes:
+        unregister(cls)
+
+if __name__ == "__main__":
+    register()