[Bf-extensions-cvs] [e86311ec] master: matlibvx ui part2: toggle icon/button style
meta-androcto
noreply at git.blender.org
Sun Apr 23 10:45:24 CEST 2017
Commit: e86311ec9729dad041e4aa176139ce4013b6d52c
Author: meta-androcto
Date: Sun Apr 23 18:45:00 2017 +1000
Branches: master
https://developer.blender.org/rBACe86311ec9729dad041e4aa176139ce4013b6d52c
matlibvx ui part2: toggle icon/button style
===================================================================
M materials_library_vx/__init__.py
===================================================================
diff --git a/materials_library_vx/__init__.py b/materials_library_vx/__init__.py
index 92748ddc..39bb55d2 100644
--- a/materials_library_vx/__init__.py
+++ b/materials_library_vx/__init__.py
@@ -1,4 +1,4 @@
-# #####BEGIN GPL LICENSE BLOCK #####
+# ##### 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
@@ -14,7 +14,7 @@
# 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 #####
+# ##### END GPL LICENSE BLOCK #####
# contributed to by meta-androcto
bl_info = {
@@ -29,131 +29,178 @@ bl_info = {
"tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
"category": "Material"}
-import zipfile, urllib.request, os, sys, re
-import csv, codecs
+# TODO: translate comments, cleanup imports, remove dead code, fix xml set fiter crash
+
+import bpy
+import json
+import zipfile
+import urllib.request
+import os
+import sys
+import re
+import csv
+import codecs
import collections
import subprocess
import webbrowser
-import bpy, json
-from bpy.props import *
+from bpy.types import (
+ Operator,
+ Menu,
+ Panel,
+ PropertyGroup,
+ AddonPreferences,
+ )
+from bpy.props import (
+ BoolProperty,
+ CollectionProperty,
+ EnumProperty,
+ IntProperty,
+ StringProperty,
+ PointerProperty,
+ )
-print (30*"-")
dev = False
-
matlib_path = os.path.dirname(__file__)
if dev:
matlib_path = r"D:\Blender Foundation\Blender\2.72\scripts\addons\matlib"
-##debug print variables
+
+# debug print variables
def dd(*args, dodir=False):
if dev:
if dodir:
print(dir(*args))
print(*args)
-#Regular Functions
+
+# add-on settings
+def addon_settings():
+ # separate function just for more convience
+ addon = bpy.context.user_preferences.addons[__name__]
+ compact = addon.preferences.use_brushes_menu_type
+
+ return compact
+
+
+# Regular Functions
def winpath(path):
return path.replace("\\", "\\\\")
-
+
+
def update_search_index(self, context):
search = self.search
for i, it in enumerate(self.materials):
- if it.name==search:
+ if it.name == search:
self.mat_index = i
break
-
+
+
def check_path(path):
-# isabs sometimes returns true on relpaths
+ # 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
+ # paths are on different drives. No problem then
return True
return False
+
def update_lib_index(self, context):
self.load_library()
+
def update_cat_index(self, context):
- dd("cat index:", self.current_category, self.filter)
+ dd("cat index:", self.current_category, self.filters)
+
+ if self.filters:
+ self.filters = 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
+
+ dd("filter:", self.filters, self.cat_index, self.current_category)
+ """
+ index = self.cat_index
+
+ if self.filters:
+ cat = self.current_category
+ else:
+ cat = ""
+
+ self.current_library.filters = cat
+ """
self.update_list()
-
+
+
def check_index(collection, index):
count = len(collection)
- return count>0 and index<count and index>=0
+ 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)
+
+ 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)
+
+ if sort:
+ list = sorted(list)
return list
+
# category properties (none atm)
-class EmptyGroup(bpy.types.PropertyGroup):
+class EmptyGroup(PropertyGroup):
pass
+
+
bpy.utils.register_class(EmptyGroup)
-class matlibMaterials(bpy.types.PropertyGroup):
+
+class matlibMaterials(PropertyGroup):
category = StringProperty()
+
+
bpy.utils.register_class(matlibMaterials)
-#bpy.types.Scene.matlib_categories = CollectionProperty(type=EmptyGroup)
-### CATEGORIES
+# bpy.types.Scene.matlib_categories = CollectionProperty(type=EmptyGroup)
+
+
+# CATEGORIES
class Categories():
-
- #cats = bpy.context.scene.matlib.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 = """
print(30*"+")
import bpy
@@ -170,13 +217,13 @@ 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")
def read(self, pull=True):
- #mandar a imprimir el listado
+ # mandar a imprimir el listado
catfile = winpath(os.path.join(matlib_path, "categories.txt"))
cmd = """
import bpy, json
@@ -191,31 +238,32 @@ for cat in bpy.context.scene.matlib_categories:
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:
+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
+ 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
-#
+ """
+ # 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()
@@ -226,130 +274,178 @@ with open("%s", "w") as f:
return True
else:
dd("duplicated?")
-
+
def remove(self, index):
self.cats.remove(index)
self.save()
+
class Library():
-
+
def __init__(self, name):
self.name = name
self.path = os.path.join(matlib_path, name)
-# @property
-# def default(self):
-# return self.name == default_library
-
+ """
+ @property
+ def default(self):
+ return self.name == default_library
+ """
@property
def shortname(self):
-# if self.default:
-# return "Default Library"
+ # if self.default:
+ # return "Default Library"
return bpy.path.display_name(self.name).title()
-
-
+
def __repr__(self):
return str(type(self).__name__) + "('" + self.name + "')"
-
-#bpy.utils.register_class(Library)
+
+
+# bpy.utils.register_class(Library)
def get_libraries():
libs = [Library(f) for f in os.listdir(matlib_path) if f[-5::] == "blend"]
return sorted(libs, key=lambda x: bpy.path.display_name(x.name))
+
libraries = get_libraries()
-### MATLIB CLASS
-class matlibProperties(bpy.types.PropertyGroup):
-
-# MATLIB PROPERTIES
-
-# libraries are read from the xml
- lib_index = IntProperty(min = -1, default = -1, update=update_lib_index)
- all_materials = CollectionProperty(type = matlibMaterials)
- materials = CollectionProperty(type = matlibMaterials)
- mat_index = IntProperty(min = -1, default = -1)
- categories = CollectionProperty(type = EmptyGroup)
- cat_index = IntProperty(min = -1, default = -1, update=update_cat_index)
- search = StringProperty(name="Search", description="Find By Name", update=update_search_index)
-
-# MATLIB OPTIONS
-# link: import material linked
-# force import:
-# if disable it wont import a material if its present in the scene,(avoid duplicates)
-# instead it will apply the scene material rathe
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list