[Bf-extensions-cvs] [ce5538ec] master: matlibvx: addons prefs custom file path by stephen-l

meta-androcto noreply at git.blender.org
Wed Jul 5 03:18:58 CEST 2017


Commit: ce5538eca22a69ddaa6e1efd342a32749651623e
Author: meta-androcto
Date:   Wed Jul 5 11:18:23 2017 +1000
Branches: master
https://developer.blender.org/rBAce5538eca22a69ddaa6e1efd342a32749651623e

matlibvx: addons prefs custom file path by stephen-l

===================================================================

M	materials_library_vx/__init__.py

===================================================================

diff --git a/materials_library_vx/__init__.py b/materials_library_vx/__init__.py
index 01dac494..fe456e6d 100644
--- a/materials_library_vx/__init__.py
+++ b/materials_library_vx/__init__.py
@@ -1,3 +1,5 @@
+# -*- coding:utf-8 -*-
+
 # #####BEGIN GPL LICENSE BLOCK #####
 #
 #  This program is free software; you can redistribute it and/or
@@ -17,1170 +19,1238 @@
 # #####END GPL LICENSE BLOCK #####
 
 bl_info = {
-	"name": "Material Library",
-	"author": "Mackraken (mackraken2023 at hotmail.com)",
-	"version": (0, 5, 7),
-	"blender": (2, 7, 8),
-	"api": 60995,
-	"location": "Properties > Material",
-	"description": "Material Library VX",
-	"warning": "",
-	"wiki_url": "https://sites.google.com/site/aleonserra/home/scripts/matlib-vx",
-	"tracker_url": "",
-	"category": "Material"}
-
-
-import bpy, os, json
-from bpy.props import *
+  "name": "Material Library",
+  "author": "Mackraken (mackraken2023 at hotmail.com)",
+  "version": (0, 5, 7),
+  "blender": (2, 7, 8),
+  "api": 60995,
+  "location": "Properties > Material",
+  "description": "Material Library VX",
+  "warning": "",
+  "wiki_url": "https://sites.google.com/site/aleonserra/home/scripts/matlib-vx",
+  "tracker_url": "",
+  "category": "Material"}
+
+
+import bpy
+import os
+import json
+from bpy.app.handlers import persistent
+from bpy.props import (
+    StringProperty, IntProperty, BoolProperty,
+    PointerProperty, CollectionProperty
+)
+from bpy.types import (
+    Panel, Menu, AddonPreferences, Operator,
+    PropertyGroup,
+    Scene
+)
+
 
 dev = False
 
 matlib_path = os.path.dirname(__file__)
 
 if dev:
-	print (30*"-")
-	matlib_path = r"D:\Blender Foundation\Blender\2.72\scripts\addons\matlib"
+  print (30*"-")
+  matlib_path = r"D:\Blender Foundation\Blender\2.72\scripts\addons\matlib"
 
 ##debug print variables
 def dd(*args, dodir=False):
-	if dev:
-		if dodir:
-			print(dir(*args))
-		print(*args)
+  if dev:
+    if dodir:
+      print(dir(*args))
+    print(*args)
 
 #Regular Functions
 def winpath(path):
-	return path.replace("\\", "\\\\")
-		
+  return path.replace("\\", "\\\\")
+
 def update_search_index(self, context):
-	search = self.search
-	for i, it in enumerate(self.materials):
-		if it.name==search:
-			self.mat_index = i
-			break
-		
+  search = self.search
+  for i, it in enumerate(self.materials):
+    if it.name==search:
+      self.mat_index = i
+      break
+
 def check_path(path):
-	#isabs sometimes returns true on relpaths
-	if path and os.path.exists(path) and os.path.isfile(path) and os.path.isabs(path):
-		try:
-			if bpy.data.filepath and bpy.path.relpath(bpy.data.filepath) == bpy.path.relpath(path):
-				return False
-		except:
-			pass
-			#paths are on different drives. No problem then
-		return True
-	return False
+  #isabs sometimes returns true on relpaths
+  if path and os.path.exists(path) and os.path.isfile(path) and os.path.isabs(path):
+    try:
+      if bpy.data.filepath and bpy.path.relpath(bpy.data.filepath) == bpy.path.relpath(path):
+        return False
+    except:
+      pass
+      #paths are on different drives. No problem then
+    return True
+  return False
 
 def update_lib_index(self, context):
-	self.load_library()
+  self.load_library()
 
 def update_cat_index(self, context):
-	dd("cat index:", self.current_category, self.filter)
+  dd("cat index:", self.current_category, self.filter)
+
+  if self.filter:
+    self.filter = True
 
-	if self.filter:
-		self.filter = True
 
-				
 def update_filter(self, context):
-	
-	dd("filter:", self.filter, self.cat_index, self.current_category)
-#	index = self.cat_index
-#	
-#	if self.filter:
-#		cat = self.current_category
-#	else:
-#		cat = ""
-#		
-#	self.current_library.filter = cat
-	self.update_list()
-			
+
+  dd("filter:", self.filter, self.cat_index, self.current_category)
+#  index = self.cat_index
+#
+#  if self.filter:
+#    cat = self.current_category
+#  else:
+#    cat = ""
+#
+#  self.current_library.filter = cat
+  self.update_list()
+
 def check_index(collection, index):
-	count = len(collection)
-	return count>0 and index<count and index>=0
+  count = len(collection)
+  return count>0 and index<count and index>=0
 
 def send_command(cmd, output="sendmat.py"):
-		bin = winpath(bpy.app.binary_path)
-		scriptpath = winpath(os.path.join(matlib_path, output))
-		
-		with open(scriptpath, "w") as f:
-			f.write(cmd)
-		
-		import subprocess
-
-		if output == "createlib.py":
-			code = subprocess.call([bin, "-b", "-P", scriptpath])
-		else:
-			libpath = winpath(bpy.context.scene.matlib.current_library.path)
-			code = subprocess.call([bin, "-b", libpath, "-P", scriptpath])
-			
-		#code returns 0 if ok, 1 if not
-		return abs(code-1)
-	
+    bin = winpath(bpy.app.binary_path)
+    scriptpath = winpath(os.path.join(matlib_path, output))
+
+    with open(scriptpath, "w") as f:
+      f.write(cmd)
+
+    import subprocess
+
+    if output == "createlib.py":
+      code = subprocess.call([bin, "-b", "-P", scriptpath])
+    else:
+      libpath = winpath(bpy.context.scene.matlib.current_library.path)
+      code = subprocess.call([bin, "-b", libpath, "-P", scriptpath])
+
+    #code returns 0 if ok, 1 if not
+    return abs(code-1)
+
 def list_materials(path, sort=False):
-	list = []
-	with bpy.data.libraries.load(path) as (data_from, data_to):
-		for mat in data_from.materials:
-			list.append(mat)
-			
-	if sort: list = sorted(list)
-	return list
+  list = []
+  with bpy.data.libraries.load(path) as (data_from, data_to):
+    for mat in data_from.materials:
+      list.append(mat)
+
+  if sort: list = sorted(list)
+  return list
 
 #category properties (none atm)
-class EmptyGroup(bpy.types.PropertyGroup):
-	pass
-bpy.utils.register_class(EmptyGroup)
+class EmptyGroup(PropertyGroup):
+  pass
+# bpy.utils.register_class(EmptyGroup)
 
-class matlibMaterials(bpy.types.PropertyGroup):
-	category = StringProperty()
-bpy.utils.register_class(matlibMaterials)
+class matlibMaterials(PropertyGroup):
+  category = StringProperty()
+# bpy.utils.register_class(matlibMaterials)
 
 #bpy.types.Scene.matlib_categories = CollectionProperty(type=EmptyGroup)
 
 ### CATEGORIES
 class Categories():
-	
-	#cats = bpy.context.scene.matlib.categories
-	
-	def __init__(self, cats):
-		self.cats = cats
-		
-	def save(self):
-		scn = bpy.context.scene
-		cats = set([cat.name for cat in self.cats])
-		libpath = bpy.context.scene.matlib.current_library.path
-		
-		cmd = """
+
+  #cats = bpy.context.scene.matlib.categories
+
+  def __init__(self, cats):
+    self.cats = cats
+
+  def save(self):
+    scn = bpy.context.scene
+    cats = set([cat.name for cat in self.cats])
+    libpath = bpy.context.scene.matlib.current_library.path
+
+    cmd = """
 print(30*"+")
 import bpy
 if not hasattr(bpy.context.scene, "matlib_categories"):
-	class EmptyProps(bpy.types.PropertyGroup):
-		pass
-	bpy.utils.register_class(EmptyProps)
-	bpy.types.Scene.matlib_categories = bpy.props.CollectionProperty(type=EmptyProps)
+  class EmptyProps(bpy.types.PropertyGroup):
+    pass
+  bpy.utils.register_class(EmptyProps)
+  bpy.types.Scene.matlib_categories = bpy.props.CollectionProperty(type=EmptyProps)
 cats = bpy.context.scene.matlib_categories
 for cat in cats:
-	cats.remove(0)
+  cats.remove(0)
 """
-		for cat in cats:
-			cmd += """
+    for cat in cats:
+      cmd += """
 cat = cats.add()
 cat.name = "%s" """ % cat.capitalize()
-		cmd +='''
+    cmd +='''
 bpy.ops.wm.save_mainfile(filepath="%s", check_existing=False, compress=True)''' % winpath(libpath)
 
-		return send_command(cmd, "save_categories.py")
+    return send_command(cmd, "save_categories.py")
 
-	def read(self, pull=True):
-		#mandar a imprimir el listado
-		catfile = winpath(os.path.join(matlib_path, "categories.txt"))
-		cmd = """
+  def read(self, pull=True):
+    #mandar a imprimir el listado
+    catfile = winpath(os.path.join(matlib_path, "categories.txt"))
+    cmd = """
 import bpy, json
 class EmptyProps(bpy.types.PropertyGroup):
-	pass
+  pass
 bpy.utils.register_class(EmptyProps)
 bpy.types.Scene.matlib_categories = bpy.props.CollectionProperty(type=EmptyProps)
 cats = []
 for cat in bpy.context.scene.matlib_categories:
-	materials = []
-	for mat in bpy.data.materials:
-		if "category" in mat.keys() and mat['category'] == cat.name:
-			materials.append(mat.name)
-	cats.append([cat.name, materials])
-with open("%s", "w") as f: 
-	f.write(json.dumps(cats, sort_keys=True, indent=4))
+  materials = []
+  for mat in bpy.data.materials:
+    if "category" in mat.keys() and mat['category'] == cat.name:
+      materials.append(mat.name)
+  cats.append([cat.name, materials])
+with open("%s", "w") as f:
+  f.write(json.dumps(cats, sort_keys=True, indent=4))
 """ % catfile
-		if pull: send_command(cmd)
-		
-		#leer el fichero
-		with open(catfile, "r") as f:
-			cats = json.loads(f.read())
-
-		dd(cats)
-		
-#		#refrescar categorias
-#		for cat in self.cats:
-#			self.cats.remove(0)
-#		
-#		for cat in cats:
-#			item = self.cats.add()
-#			item.name = cat
-#			
-		return cats
-	
-	def view(self):
-		for cat in self.cats:
-			dd(cat.name)
-			
-	def add(self, name):
-		if name and name not in [item.name for item in self.cats]:
-			name = name.strip().capitalize()
-			item = self.cats.add()
-			item.name = name
-			if self.save():
-				dd(name, "added")
-				return True
-		else:
-			dd("duplicated?")
-			
-	def remove(self, index):
-		self.cats.remove(index)
-		self.save()
+    if pull: send_command(cmd)
+
+    #leer el fichero
+    with open(catfile, "r") as f:
+      cats = json.loads(f.read())
+
+    dd(cats)
+
+#    #refrescar categorias
+#    for cat in self.cats:
+#      self.cats.remove(0)
+#
+#    for cat in cats:
+#      item = self.cats.add()
+#      item.name = cat
+#
+    return cats
+
+  def view(self):
+    for cat in self.cats:
+      dd(cat.name)
+
+  def add(self, name):
+    if name and name not in [item.name for item in self.cats]:
+      name = name.strip().capitalize()
+      item = self.cats.add()
+      item.name = name
+      if self.save():
+        dd(name, "added")
+        return True
+    else:
+      dd("duplicated?")
+
+  def remove(self, index):
+    self.cats.remove(index)
+    self.save()
 
 class Library():
-	
-	def __init__(self

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list