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

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Leger <stephen@3dservices.ch>2017-12-07 12:26:51 +0300
committerStephen Leger <stephen@3dservices.ch>2017-12-07 12:27:45 +0300
commitf60ec960dec0274f269748be79b0fb2d833118b1 (patch)
treec77a2aaecb0e53f87069a34cbc2947b5ea7a8431 /archipack
parent75ad0c4177844696747f6e7db5ce2ad1005270a3 (diff)
Move presets to user writeable folder when rendering thumbs
Diffstat (limited to 'archipack')
-rw-r--r--archipack/archipack_preset.py11
-rw-r--r--archipack/archipack_rendering.py79
2 files changed, 68 insertions, 22 deletions
diff --git a/archipack/archipack_preset.py b/archipack/archipack_preset.py
index 3541042c..dcaa7970 100644
--- a/archipack/archipack_preset.py
+++ b/archipack/archipack_preset.py
@@ -34,6 +34,8 @@ from .archipack_gl import (
ThumbHandle, Screen, GlRect,
GlPolyline, GlPolygon, GlText, GlHandle
)
+preset_paths = bpy.utils.script_paths("presets")
+addons_paths = bpy.utils.script_paths("addons")
class CruxHandle(GlHandle):
@@ -164,10 +166,6 @@ class SeekBox(GlText, GlHandle):
return self.pos_3d
-preset_paths = bpy.utils.script_paths("presets")
-addons_paths = bpy.utils.script_paths("addons")
-
-
class PresetMenuItem():
def __init__(self, thumbsize, preset, image=None):
name = bpy.path.display_name_from_filepath(preset)
@@ -246,6 +244,7 @@ class PresetMenu():
def scan_files(self, category):
file_list = []
+ """
# load default presets
dir_path = os.path.dirname(os.path.realpath(__file__))
sub_path = "presets" + os.path.sep + category
@@ -255,6 +254,7 @@ class PresetMenu():
for f in os.listdir(presets_path)
if f.endswith('.py') and
not f.startswith('.')]
+ """
# load user def presets
for path in preset_paths:
presets_path = os.path.join(path, category)
@@ -524,7 +524,6 @@ class ArchipackPreset(AddPresetBase):
os.remove(filepath[:-3] + ".png")
def background_render(self, context, cls, preset):
- print("bg render")
generator = os.path.dirname(os.path.realpath(__file__)) + os.path.sep + "archipack_thumbs.py"
# Run external instance of blender like the original thumbnail generator.
cmd = [
@@ -536,7 +535,7 @@ class ArchipackPreset(AddPresetBase):
"cls:" + cls,
"preset:" + preset
]
- print(repr(cmd))
+ # print(repr(cmd))
subprocess.Popen(cmd)
diff --git a/archipack/archipack_rendering.py b/archipack/archipack_rendering.py
index 05373a75..fced24ac 100644
--- a/archipack/archipack_rendering.py
+++ b/archipack/archipack_rendering.py
@@ -30,6 +30,7 @@
import bpy
# noinspection PyUnresolvedReferences
import bgl
+from shutil import copyfile
from os import path, remove, listdir
from sys import exc_info
import subprocess
@@ -38,14 +39,21 @@ import bpy_extras.image_utils as img_utils
# noinspection PyUnresolvedReferences
from math import ceil
from bpy.types import Operator
+from bl_ui import properties_render
class ARCHIPACK_OT_render_thumbs(Operator):
bl_idname = "archipack.render_thumbs"
- bl_label = "Render preset thumbs"
- bl_description = "Render all presets thumbs"
+ bl_label = "Render presets thumbs"
+ bl_description = "Setup default presets and update thumbs"
bl_options = {'REGISTER', 'INTERNAL'}
+ @classmethod
+ def poll(cls, context):
+ # Ensure CYCLES engine is available
+ return context.scene.archipack_progress < 0 and \
+ 'CYCLES' in properties_render.RENDER_PT_render.COMPAT_ENGINES
+
def background_render(self, context, cls, preset):
generator = path.dirname(path.realpath(__file__)) + path.sep + "archipack_thumbs.py"
addon_name = __name__.split('.')[0]
@@ -63,24 +71,61 @@ class ARCHIPACK_OT_render_thumbs(Operator):
"cls:" + cls,
"preset:" + preset
]
-
popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
for stdout_line in iter(popen.stdout.readline, ""):
yield stdout_line
popen.stdout.close()
popen.wait()
- def scan_files(self, category):
+ def copy_to_user_path(self, category):
+ """
+ Copy factory presets to writeable presets folder
+ Two cases here:
+ 1 there is not presets thumbs found (official version)
+ 2 thumbs allready are there (unofficial)
+ """
file_list = []
# load default presets
dir_path = path.dirname(path.realpath(__file__))
sub_path = "presets" + path.sep + category
- presets_path = path.join(dir_path, sub_path)
- if path.exists(presets_path):
- file_list += [presets_path + path.sep + f[:-3]
- for f in listdir(presets_path)
- if f.endswith('.py') and
- not f.startswith('.')]
+ source_path = path.join(dir_path, sub_path)
+ if path.exists(source_path):
+ file_list.extend([f
+ for f in listdir(source_path)
+ if (f.endswith('.py') or f.endswith('.txt')) and
+ not f.startswith('.')])
+
+ target_path = path.join("presets", category)
+ presets_path = bpy.utils.user_resource('SCRIPTS',
+ target_path,
+ create=True)
+ # files from factory not found in user dosent require a recompute
+ skipfiles = []
+ for f in file_list:
+ # copy python/txt preset
+ if not path.exists(presets_path + path.sep + f):
+ copyfile(source_path + path.sep + f, presets_path + path.sep + f)
+
+ # skip txt files (material presets)
+ if f.endswith(".txt"):
+ skipfiles.append(f)
+
+ # when thumbs allready are in factory folder but not found in user one
+ # simply copy them, and add preset to skip list
+ thumb_filename = f[:-3] + ".png"
+ if path.exists(source_path + path.sep + thumb_filename):
+ if not path.exists(presets_path + path.sep + thumb_filename):
+ copyfile(source_path + path.sep + thumb_filename, presets_path + path.sep + thumb_filename)
+ skipfiles.append(f)
+
+ return skipfiles
+
+ def scan_files(self, category):
+ file_list = []
+
+ # copy from factory to user writeable folder
+ skipfiles = self.copy_to_user_path(category)
+
# load user def presets
preset_paths = bpy.utils.script_paths("presets")
for preset in preset_paths:
@@ -89,7 +134,8 @@ class ARCHIPACK_OT_render_thumbs(Operator):
file_list += [presets_path + path.sep + f[:-3]
for f in listdir(presets_path)
if f.endswith('.py') and
- not f.startswith('.')]
+ not f.startswith('.') and
+ f not in skipfiles]
file_list.sort()
return file_list
@@ -99,7 +145,7 @@ class ARCHIPACK_OT_render_thumbs(Operator):
dir_path = path.dirname(path.realpath(__file__))
sub_path = "presets"
presets_path = path.join(dir_path, sub_path)
- print(presets_path)
+ # print(presets_path)
if path.exists(presets_path):
dirs = listdir(presets_path)
for dir in dirs:
@@ -119,11 +165,12 @@ class ARCHIPACK_OT_render_thumbs(Operator):
# elif not "Fra:1" in l:
# print(l.strip())
- @classmethod
- def poll(cls, context):
- return context.scene.archipack_progress < 0
-
def invoke(self, context, event):
+ addon_name = __name__.split('.')[0]
+ matlib_path = context.user_preferences.addons[addon_name].preferences.matlib_path
+
+ if matlib_path == '':
+ self.report({'WARNING'}, "You should setup a default material library path in addon preferences")
return context.window_manager.invoke_confirm(self, event)
def execute(self, context):