[Bf-blender-cvs] [9ec944bbab7] master: Cleanup: split user preferences out of wm.py
Campbell Barton
noreply at git.blender.org
Mon Feb 11 13:24:34 CET 2019
Commit: 9ec944bbab7a5ba75a526387f8eab52af7f6405e
Author: Campbell Barton
Date: Mon Feb 11 23:17:05 2019 +1100
Branches: master
https://developer.blender.org/rB9ec944bbab7a5ba75a526387f8eab52af7f6405e
Cleanup: split user preferences out of wm.py
These operations are for handling preference related tasks so move into
into a preferences file.
Operators still need to be renamed.
===================================================================
M release/scripts/startup/bl_operators/__init__.py
A release/scripts/startup/bl_operators/userpref.py
M release/scripts/startup/bl_operators/wm.py
===================================================================
diff --git a/release/scripts/startup/bl_operators/__init__.py b/release/scripts/startup/bl_operators/__init__.py
index 4d9038684d1..bb92e070d00 100644
--- a/release/scripts/startup/bl_operators/__init__.py
+++ b/release/scripts/startup/bl_operators/__init__.py
@@ -35,14 +35,15 @@ _modules = [
"mask",
"mesh",
"node",
- "object_align",
"object",
- "object_randomize_transform",
+ "object_align",
"object_quick_effects",
+ "object_randomize_transform",
"presets",
"rigidbody",
"screen_play_rendered_anim",
"sequencer",
+ "userpref",
"uvcalc_follow_active",
"uvcalc_lightmap",
"uvcalc_smart_project",
diff --git a/release/scripts/startup/bl_operators/userpref.py b/release/scripts/startup/bl_operators/userpref.py
new file mode 100644
index 00000000000..072899320e4
--- /dev/null
+++ b/release/scripts/startup/bl_operators/userpref.py
@@ -0,0 +1,1090 @@
+# ##### 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>
+
+# TODO, use PREFERENCES_OT_* prefix for operators.
+
+import bpy
+from bpy.types import (
+ Operator,
+ OperatorFileListElement
+)
+from bpy.props import (
+ BoolProperty,
+ EnumProperty,
+ IntProperty,
+ StringProperty,
+ CollectionProperty,
+)
+
+from bpy.app.translations import pgettext_tip as tip_
+
+
+class WM_OT_keyconfig_activate(Operator):
+ bl_idname = "wm.keyconfig_activate"
+ bl_label = "Activate Keyconfig"
+
+ filepath: StringProperty(
+ subtype='FILE_PATH',
+ )
+
+ def execute(self, context):
+ if bpy.utils.keyconfig_set(self.filepath, report=self.report):
+ return {'FINISHED'}
+ else:
+ return {'CANCELLED'}
+
+
+class WM_OT_copy_prev_settings(Operator):
+ """Copy settings from previous version"""
+ bl_idname = "wm.copy_prev_settings"
+ bl_label = "Copy Previous Settings"
+
+ @staticmethod
+ def previous_version():
+ ver = bpy.app.version
+ ver_old = ((ver[0] * 100) + ver[1]) - 1
+ return ver_old // 100, ver_old % 100
+
+ @staticmethod
+ def _old_path():
+ ver = bpy.app.version
+ ver_old = ((ver[0] * 100) + ver[1]) - 1
+ return bpy.utils.resource_path('USER', ver_old // 100, ver_old % 100)
+
+ @staticmethod
+ def _new_path():
+ return bpy.utils.resource_path('USER')
+
+ @classmethod
+ def poll(cls, context):
+ import os
+
+ old = cls._old_path()
+ new = cls._new_path()
+
+ # Disable operator in case config path is overriden with environment
+ # variable. That case has no automatic per-version configuration.
+ userconfig_path = os.path.normpath(bpy.utils.user_resource('CONFIG'))
+ new_userconfig_path = os.path.normpath(os.path.join(new, "config"))
+ if userconfig_path != new_userconfig_path:
+ return False
+
+ # Enable operator if new config path does not exist yet.
+ if os.path.isdir(old) and not os.path.isdir(new):
+ return True
+
+ # Enable operator also if there are no new user preference yet.
+ old_userpref = os.path.join(old, "config", "userpref.blend")
+ new_userpref = os.path.join(new, "config", "userpref.blend")
+ return os.path.isfile(old_userpref) and not os.path.isfile(new_userpref)
+
+ def execute(self, context):
+ import shutil
+
+ shutil.copytree(self._old_path(), self._new_path(), symlinks=True)
+
+ # reload recent-files.txt
+ bpy.ops.wm.read_history()
+
+ # don't loose users work if they open the splash later.
+ if bpy.data.is_saved is bpy.data.is_dirty is False:
+ bpy.ops.wm.read_homefile()
+ else:
+ self.report({'INFO'}, "Reload Start-Up file to restore settings")
+
+ return {'FINISHED'}
+
+
+class WM_OT_keyconfig_test(Operator):
+ """Test key-config for conflicts"""
+ bl_idname = "wm.keyconfig_test"
+ bl_label = "Test Key Configuration for Conflicts"
+
+ def execute(self, context):
+ from bpy_extras import keyconfig_utils
+
+ wm = context.window_manager
+ kc = wm.keyconfigs.default
+
+ if keyconfig_utils.keyconfig_test(kc):
+ print("CONFLICT")
+
+ return {'FINISHED'}
+
+
+class WM_OT_keyconfig_import(Operator):
+ """Import key configuration from a python script"""
+ bl_idname = "wm.keyconfig_import"
+ bl_label = "Import Key Configuration..."
+
+ filepath: StringProperty(
+ subtype='FILE_PATH',
+ default="keymap.py",
+ )
+ filter_folder: BoolProperty(
+ name="Filter folders",
+ default=True,
+ options={'HIDDEN'},
+ )
+ filter_text: BoolProperty(
+ name="Filter text",
+ default=True,
+ options={'HIDDEN'},
+ )
+ filter_python: BoolProperty(
+ name="Filter python",
+ default=True,
+ options={'HIDDEN'},
+ )
+ keep_original: BoolProperty(
+ name="Keep original",
+ description="Keep original file after copying to configuration folder",
+ default=True,
+ )
+
+ def execute(self, context):
+ import os
+ from os.path import basename
+ import shutil
+
+ if not self.filepath:
+ self.report({'ERROR'}, "Filepath not set")
+ return {'CANCELLED'}
+
+ config_name = basename(self.filepath)
+
+ path = bpy.utils.user_resource('SCRIPTS', os.path.join("presets", "keyconfig"), create=True)
+ path = os.path.join(path, config_name)
+
+ try:
+ if self.keep_original:
+ shutil.copy(self.filepath, path)
+ else:
+ shutil.move(self.filepath, path)
+ except Exception as ex:
+ self.report({'ERROR'}, "Installing keymap failed: %s" % ex)
+ return {'CANCELLED'}
+
+ # sneaky way to check we're actually running the code.
+ if bpy.utils.keyconfig_set(path, report=self.report):
+ return {'FINISHED'}
+ else:
+ return {'CANCELLED'}
+
+ def invoke(self, context, event):
+ wm = context.window_manager
+ wm.fileselect_add(self)
+ return {'RUNNING_MODAL'}
+
+# This operator is also used by interaction presets saving - AddPresetBase
+
+
+class WM_OT_keyconfig_export(Operator):
+ """Export key configuration to a python script"""
+ bl_idname = "wm.keyconfig_export"
+ bl_label = "Export Key Configuration..."
+
+ all: BoolProperty(
+ name="All Keymaps",
+ default=False,
+ description="Write all keymaps (not just user modified)",
+ )
+ filepath: StringProperty(
+ subtype='FILE_PATH',
+ default="keymap.py",
+ )
+ filter_folder: BoolProperty(
+ name="Filter folders",
+ default=True,
+ options={'HIDDEN'},
+ )
+ filter_text: BoolProperty(
+ name="Filter text",
+ default=True,
+ options={'HIDDEN'},
+ )
+ filter_python: BoolProperty(
+ name="Filter python",
+ default=True,
+ options={'HIDDEN'},
+ )
+
+ def execute(self, context):
+ from bl_keymap_utils.io import keyconfig_export_as_data
+
+ if not self.filepath:
+ raise Exception("Filepath not set")
+
+ if not self.filepath.endswith(".py"):
+ self.filepath += ".py"
+
+ wm = context.window_manager
+
+ keyconfig_export_as_data(
+ wm,
+ wm.keyconfigs.active,
+ self.filepath,
+ all_keymaps=self.all,
+ )
+
+ return {'FINISHED'}
+
+ def invoke(self, context, event):
+ wm = context.window_manager
+ wm.fileselect_add(self)
+ return {'RUNNING_MODAL'}
+
+
+class WM_OT_keymap_restore(Operator):
+ """Restore key map(s)"""
+ bl_idname = "wm.keymap_restore"
+ bl_label = "Restore Key Map(s)"
+
+ all: BoolProperty(
+ name="All Keymaps",
+ description="Restore all keymaps to default",
+ )
+
+ def execute(self, context):
+ wm = context.window_manager
+
+ if self.all:
+ for km in wm.keyconfigs.user.keymaps:
+ km.restore_to_default()
+ else:
+ km = context.keymap
+ km.restore_to_default()
+
+ return {'FINISHED'}
+
+
+class WM_OT_keyitem_restore(Operator):
+ """Restore key map item"""
+ bl_idname = "wm.keyitem_restore"
+ bl_label = "Restore Key Map Item"
+
+ item_id: IntProperty(
+ name="Item Identifier",
+ description="Identifier of the item to remove",
+ )
+
+ @classmethod
+ def poll(cls, context):
+ keymap = getattr(context, "keymap", None)
+ return keymap
+
+ def execute(self, context):
+ km = context.keymap
+ kmi = km.keymap_items.from_id(self.item_id)
+
+ if (not kmi.is_user_defined) and kmi.is_user_modified:
+ km.restore_item_to_default(kmi)
+
+ return {'FINISHED'}
+
+
+class WM_OT_keyitem_add(Operator):
+ """Add key map item"""
+ bl_idname = "wm.keyitem_add"
+ bl_label = "Add Key Map Item"
+
+ def execute(self, context):
+ km = context.keymap
+
+ if km.is_modal:
+ km.keymap_items.new_modal("", 'A', 'PRESS')
+ else:
+ km.keymap_items.new("none", 'A', 'PRESS')
+
+ # clear filter and expand keymap so we can see the newly added item
+ if context.space_data.filter_text != "":
+ context.space_d
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list