Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-08-10 18:26:37 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-08-10 18:45:16 +0300
commit8d37aaeca1f9dc74224da378cecd392fd1cf361b (patch)
tree29729f23ebaa74f607ad6ec4e260112fee924b27 /release/scripts/startup
parent8f837e0ac586fb010c7c6133ddbdc09546f7f851 (diff)
Data previews: add utils to generate/clear previews.
Not much to add, you can now clear previews from current .blend file, or a set of non-opened files. Likewise, you can generate previews (for mat/tex, objects, groups, scenes, ...).
Diffstat (limited to 'release/scripts/startup')
-rw-r--r--release/scripts/startup/bl_operators/__init__.py1
-rw-r--r--release/scripts/startup/bl_operators/file.py243
-rw-r--r--release/scripts/startup/bl_ui/space_info.py6
3 files changed, 250 insertions, 0 deletions
diff --git a/release/scripts/startup/bl_operators/__init__.py b/release/scripts/startup/bl_operators/__init__.py
index 4047505652f..35c7a55b6da 100644
--- a/release/scripts/startup/bl_operators/__init__.py
+++ b/release/scripts/startup/bl_operators/__init__.py
@@ -28,6 +28,7 @@ _modules = [
"anim",
"clip",
"console",
+ "file",
"image",
"mask",
"mesh",
diff --git a/release/scripts/startup/bl_operators/file.py b/release/scripts/startup/bl_operators/file.py
new file mode 100644
index 00000000000..a6a6982e746
--- /dev/null
+++ b/release/scripts/startup/bl_operators/file.py
@@ -0,0 +1,243 @@
+# ##### 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
+from bpy.types import Operator
+from bpy.props import (
+ StringProperty,
+ BoolProperty,
+ CollectionProperty,
+ )
+
+# ########## Datablock previews... ##########
+
+class WM_OT_previews_batch_generate(Operator):
+ """Generate selected .blend file's previews"""
+ bl_idname = "wm.previews_batch_generate"
+ bl_label = "Batch-Generate Previews"
+ bl_options = {'REGISTER'}
+
+ # -----------
+ # File props.
+ files = CollectionProperty(
+ type=bpy.types.OperatorFileListElement,
+ options={'HIDDEN', 'SKIP_SAVE'},
+ )
+
+ directory = StringProperty(
+ maxlen=1024,
+ subtype='FILE_PATH',
+ options={'HIDDEN', 'SKIP_SAVE'},
+ )
+
+ # Show only images/videos, and directories!
+ filter_blender = BoolProperty(
+ default=True,
+ options={'HIDDEN', 'SKIP_SAVE'},
+ )
+ filter_folder = BoolProperty(
+ default=True,
+ options={'HIDDEN', 'SKIP_SAVE'},
+ )
+
+ # -----------
+ # Own props.
+ use_scenes = BoolProperty(
+ default=True,
+ name="Scenes",
+ description="Generate scenes' previews",
+ )
+ use_groups = BoolProperty(
+ default=True,
+ name="Groups",
+ description="Generate groups' previews",
+ )
+ use_objects = BoolProperty(
+ default=True,
+ name="Objects",
+ description="Generate objects' previews",
+ )
+ use_intern_data = BoolProperty(
+ default=True,
+ name="Mat/Tex/...",
+ description="Generate 'internal' previews (materials, textures, images, etc.)",
+ )
+
+ use_trusted = BoolProperty(
+ default=False,
+ name="Trusted Blend Files",
+ description="Enable python evaluation for selected files",
+ )
+
+ def invoke(self, context, event):
+ context.window_manager.fileselect_add(self)
+ return {'RUNNING_MODAL'}
+
+ def execute(self, context):
+ if "subprocess" in locals():
+ import imp
+ imp.reload(preview_render)
+ else:
+ import os
+ import subprocess
+ from bl_previews_utils import bl_previews_render as preview_render
+
+ context.window_manager.progress_begin(0, len(self.files))
+ context.window_manager.progress_update(0)
+ for i, fn in enumerate(self.files):
+ blen_path = os.path.join(self.directory, fn.name)
+ cmd = [
+ bpy.app.binary_path,
+ "--background",
+ "--factory-startup",
+ "-noaudio",
+ ]
+ if self.use_trusted:
+ cmd.append("--enable-autoexec")
+ cmd.extend([
+ blen_path,
+ "--python",
+ os.path.join(os.path.dirname(preview_render.__file__), "bl_previews_render.py"),
+ "--",
+ ])
+ if not self.use_scenes:
+ cmd.append('--no_scenes')
+ if not self.use_groups:
+ cmd.append('--no_groups')
+ if not self.use_objects:
+ cmd.append('--no_objects')
+ if not self.use_intern_data:
+ cmd.append('--no_data_intern')
+ if subprocess.call(cmd):
+ self.report({'ERROR'}, "Previews generation process failed for file '%s'!" % blen_path)
+ context.window_manager.progress_end()
+ return {'CANCELLED'}
+ context.window_manager.progress_update(i + 1)
+ context.window_manager.progress_end()
+
+ return {'FINISHED'}
+
+
+class WM_OT_previews_batch_clear(Operator):
+ """Clear selected .blend file's previews"""
+ bl_idname = "wm.previews_batch_clear"
+ bl_label = "Batch-Clear Previews"
+ bl_options = {'REGISTER'}
+
+ # -----------
+ # File props.
+ files = CollectionProperty(
+ type=bpy.types.OperatorFileListElement,
+ options={'HIDDEN', 'SKIP_SAVE'},
+ )
+
+ directory = StringProperty(
+ maxlen=1024,
+ subtype='FILE_PATH',
+ options={'HIDDEN', 'SKIP_SAVE'},
+ )
+
+ # Show only images/videos, and directories!
+ filter_blender = BoolProperty(
+ default=True,
+ options={'HIDDEN', 'SKIP_SAVE'},
+ )
+ filter_folder = BoolProperty(
+ default=True,
+ options={'HIDDEN', 'SKIP_SAVE'},
+ )
+
+ # -----------
+ # Own props.
+ use_scenes = BoolProperty(
+ default=True,
+ name="Scenes",
+ description="Clear scenes' previews",
+ )
+ use_groups = BoolProperty(default=True,
+ name="Groups",
+ description="Clear groups' previews",
+ )
+ use_objects = BoolProperty(
+ default=True,
+ name="Objects",
+ description="Clear objects' previews",
+ )
+ use_intern_data = BoolProperty(
+ default=True,
+ name="Mat/Tex/...",
+ description="Clear 'internal' previews (materials, textures, images, etc.)",
+ )
+
+ use_trusted = BoolProperty(
+ default=False,
+ name="Trusted Blend Files",
+ description="Enable python evaluation for selected files",
+ )
+
+ def invoke(self, context, event):
+ context.window_manager.fileselect_add(self)
+ return {'RUNNING_MODAL'}
+
+ def execute(self, context):
+ if "subprocess" in locals():
+ import imp
+ imp.reload(preview_render)
+ else:
+ import os
+ import subprocess
+ from bl_previews_utils import bl_previews_render as preview_render
+
+ context.window_manager.progress_begin(0, len(self.files))
+ context.window_manager.progress_update(0)
+ for i, fn in enumerate(self.files):
+ blen_path = os.path.join(self.directory, fn.name)
+ cmd = [
+ bpy.app.binary_path,
+ "--background",
+ "--factory-startup",
+ "-noaudio",
+ ]
+ if self.use_trusted:
+ cmd.append("--enable-autoexec")
+ cmd.extend([
+ blen_path,
+ "--python",
+ os.path.join(os.path.dirname(preview_render.__file__), "bl_previews_render.py"),
+ "--",
+ "--clear",
+ ])
+ if not self.use_scenes:
+ cmd.append('--no_scenes')
+ if not self.use_groups:
+ cmd.append('--no_groups')
+ if not self.use_objects:
+ cmd.append('--no_objects')
+ if not self.use_intern_data:
+ cmd.append('--no_data_intern')
+ if subprocess.call(cmd):
+ self.report({'ERROR'}, "Previews clear process failed for file '%s'!" % blen_path)
+ context.window_manager.progress_end()
+ return {'CANCELLED'}
+ context.window_manager.progress_update(i + 1)
+ context.window_manager.progress_end()
+
+ return {'FINISHED'}
+
diff --git a/release/scripts/startup/bl_ui/space_info.py b/release/scripts/startup/bl_ui/space_info.py
index 48a1b28289e..d295cc19fb7 100644
--- a/release/scripts/startup/bl_ui/space_info.py
+++ b/release/scripts/startup/bl_ui/space_info.py
@@ -203,6 +203,12 @@ class INFO_MT_file_previews(Menu):
layout = self.layout
layout.operator("wm.previews_ensure")
+ layout.operator("wm.previews_batch_generate")
+
+ layout.separator()
+
+ layout.operator("wm.previews_clear")
+ layout.operator("wm.previews_batch_clear")
class INFO_MT_game(Menu):