2016-03-08 16:22:20 +01:00
|
|
|
# ##### 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>
|
|
|
|
|
|
|
|
bl_info = {
|
|
|
|
"name": "Blender Cloud Texture Browser",
|
|
|
|
"author": "Sybren A. Stüvel and Francesco Siddi",
|
2016-03-14 17:23:56 +01:00
|
|
|
"version": (0, 2, 0),
|
2016-03-08 16:22:20 +01:00
|
|
|
"blender": (2, 77, 0),
|
|
|
|
"location": "TO BE DETERMINED",
|
|
|
|
"description": "Allows downloading of textures from the Blender Cloud. Requires "
|
|
|
|
"the Blender ID addon.",
|
|
|
|
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
|
|
|
|
"Scripts/System/BlenderCloud",
|
|
|
|
"category": "System",
|
|
|
|
"support": "TESTING"
|
|
|
|
}
|
|
|
|
|
2016-03-09 14:09:22 +01:00
|
|
|
# Support reloading
|
|
|
|
if 'pillar' in locals():
|
|
|
|
import importlib
|
2016-03-09 17:34:37 +01:00
|
|
|
|
2016-03-09 14:09:22 +01:00
|
|
|
pillar = importlib.reload(pillar)
|
2016-03-11 17:52:12 +01:00
|
|
|
async_loop = importlib.reload(async_loop)
|
2016-03-14 17:23:56 +01:00
|
|
|
gui = importlib.reload(gui)
|
2016-03-18 14:03:25 +01:00
|
|
|
cache = importlib.reload(cache)
|
2016-03-09 14:09:22 +01:00
|
|
|
else:
|
2016-03-18 14:03:25 +01:00
|
|
|
from . import pillar, async_loop, gui, cache
|
2016-03-09 14:09:22 +01:00
|
|
|
|
2016-03-15 13:47:21 +01:00
|
|
|
import logging
|
2016-03-18 14:03:25 +01:00
|
|
|
import os.path
|
2016-03-15 13:47:21 +01:00
|
|
|
|
2016-03-08 16:22:20 +01:00
|
|
|
import bpy
|
2016-03-15 15:44:19 +01:00
|
|
|
from bpy.types import AddonPreferences, Operator, WindowManager, Scene
|
2016-03-14 17:23:56 +01:00
|
|
|
from bpy.props import StringProperty
|
2016-03-08 16:22:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
class BlenderCloudPreferences(AddonPreferences):
|
|
|
|
bl_idname = __name__
|
|
|
|
|
|
|
|
pillar_server = bpy.props.StringProperty(
|
|
|
|
name='Blender Cloud Server',
|
|
|
|
description='URL of the Blender Cloud backend server',
|
|
|
|
default='https://pillar.blender.org:5000/'
|
|
|
|
)
|
|
|
|
|
|
|
|
def draw(self, context):
|
|
|
|
layout = self.layout
|
|
|
|
|
|
|
|
# Carefully try and import the Blender ID addon
|
|
|
|
try:
|
|
|
|
import blender_id.profiles as blender_id_profiles
|
|
|
|
except ImportError:
|
|
|
|
blender_id_profiles = None
|
|
|
|
blender_id_profile = None
|
|
|
|
else:
|
|
|
|
blender_id_profile = blender_id_profiles.get_active_profile()
|
|
|
|
|
|
|
|
if blender_id_profiles is None:
|
|
|
|
blender_id_icon = 'ERROR'
|
|
|
|
blender_id_text = "This add-on requires Blender ID"
|
|
|
|
blender_id_help = "Make sure that the Blender ID add-on is installed and activated"
|
|
|
|
elif not blender_id_profile:
|
|
|
|
blender_id_icon = 'ERROR'
|
|
|
|
blender_id_text = "You are logged out."
|
|
|
|
blender_id_help = "To login, go to the Blender ID add-on preferences."
|
|
|
|
else:
|
|
|
|
blender_id_icon = 'WORLD_DATA'
|
|
|
|
blender_id_text = "You are logged in as %s." % blender_id_profile['username']
|
2016-03-09 14:09:06 +01:00
|
|
|
blender_id_help = "To logout or change profile, " \
|
|
|
|
"go to the Blender ID add-on preferences."
|
2016-03-08 16:22:20 +01:00
|
|
|
|
|
|
|
sub = layout.column()
|
|
|
|
sub.label(text=blender_id_text, icon=blender_id_icon)
|
|
|
|
sub.label(text="* " + blender_id_help)
|
|
|
|
|
2016-03-08 17:56:13 +01:00
|
|
|
# options for Pillar
|
|
|
|
sub = layout.column()
|
|
|
|
sub.enabled = blender_id_icon != 'ERROR'
|
|
|
|
sub.prop(self, "pillar_server")
|
|
|
|
sub.operator("pillar.credentials_update")
|
|
|
|
|
|
|
|
|
|
|
|
class PillarCredentialsUpdate(Operator):
|
|
|
|
"""Updates the Pillar URL and tests the new URL."""
|
|
|
|
bl_idname = "pillar.credentials_update"
|
|
|
|
bl_label = "Update credentials"
|
|
|
|
|
2016-03-09 14:09:06 +01:00
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
# Only allow activation when the user is actually logged in.
|
|
|
|
return cls.is_logged_in(context)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def is_logged_in(cls, context):
|
|
|
|
active_user_id = getattr(context.window_manager, 'blender_id_active_profile', None)
|
|
|
|
return bool(active_user_id)
|
|
|
|
|
2016-03-08 17:56:13 +01:00
|
|
|
def execute(self, context):
|
2016-03-09 14:09:06 +01:00
|
|
|
# Only allow activation when the user is actually logged in.
|
|
|
|
if not self.is_logged_in(context):
|
|
|
|
self.report({'ERROR'}, "No active profile found")
|
2016-03-08 17:56:13 +01:00
|
|
|
return {'CANCELLED'}
|
|
|
|
|
|
|
|
# Test the new URL
|
|
|
|
endpoint = bpy.context.user_preferences.addons[__name__].preferences.pillar_server
|
|
|
|
pillar._pillar_api = None
|
|
|
|
try:
|
|
|
|
pillar.get_project_uuid('textures') # Just any query will do.
|
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
|
|
|
self.report({'ERROR'}, 'Failed connection to %s' % endpoint)
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
self.report({'INFO'}, 'Updated cloud server address to %s' % endpoint)
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
2016-03-08 16:22:20 +01:00
|
|
|
|
|
|
|
def register():
|
2016-03-14 17:23:56 +01:00
|
|
|
bpy.utils.register_class(BlenderCloudPreferences)
|
|
|
|
bpy.utils.register_class(PillarCredentialsUpdate)
|
2016-03-08 16:22:20 +01:00
|
|
|
|
2016-03-09 17:34:37 +01:00
|
|
|
WindowManager.thumbnails_cache = StringProperty(
|
|
|
|
name="Thumbnails cache",
|
|
|
|
subtype='DIR_PATH',
|
2016-03-18 14:03:25 +01:00
|
|
|
default=os.path.join(cache.cache_directory(), 'thumbnails'))
|
2016-03-09 17:34:37 +01:00
|
|
|
|
|
|
|
WindowManager.blender_cloud_project = StringProperty(
|
|
|
|
name="Blender Cloud project UUID",
|
|
|
|
default='5672beecc0261b2005ed1a33') # TODO: don't hard-code this
|
|
|
|
|
|
|
|
WindowManager.blender_cloud_node = StringProperty(
|
|
|
|
name="Blender Cloud node UUID",
|
|
|
|
default='') # empty == top-level of project
|
|
|
|
|
2016-03-15 15:44:19 +01:00
|
|
|
Scene.blender_cloud_dir = StringProperty(
|
|
|
|
name='Blender Cloud texture storage directory',
|
|
|
|
subtype='DIR_PATH',
|
|
|
|
default='//textures')
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG,
|
2016-03-15 13:47:21 +01:00
|
|
|
format='%(asctime)-15s %(levelname)8s %(name)s %(message)s')
|
2016-03-15 14:05:54 +01:00
|
|
|
async_loop.setup_asyncio_executor()
|
2016-03-14 17:23:56 +01:00
|
|
|
gui.register()
|
2016-03-09 17:34:37 +01:00
|
|
|
|
2016-03-08 16:22:20 +01:00
|
|
|
|
|
|
|
def unregister():
|
2016-03-14 17:23:56 +01:00
|
|
|
gui.unregister()
|
|
|
|
|
|
|
|
bpy.utils.unregister_class(PillarCredentialsUpdate)
|
|
|
|
bpy.utils.unregister_class(BlenderCloudPreferences)
|
2016-03-08 16:22:20 +01:00
|
|
|
|
2016-03-09 17:34:37 +01:00
|
|
|
del WindowManager.blender_cloud_project
|
|
|
|
del WindowManager.blender_cloud_node
|
|
|
|
del WindowManager.blender_cloud_thumbnails
|
|
|
|
|
2016-03-08 16:22:20 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
register()
|