2016-07-20 16:32:01 +02: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 #####
|
|
|
|
|
2016-03-18 16:53:52 +01:00
|
|
|
"""Blender-specific code.
|
|
|
|
|
|
|
|
Separated from __init__.py so that we can import & run from non-Blender environments.
|
|
|
|
"""
|
2017-03-17 15:08:09 +01:00
|
|
|
import functools
|
2016-04-13 15:37:19 +02:00
|
|
|
import logging
|
2016-07-08 17:00:44 +02:00
|
|
|
import os.path
|
2018-01-02 15:37:38 +01:00
|
|
|
import tempfile
|
2016-04-13 15:37:19 +02:00
|
|
|
|
2016-03-18 16:53:52 +01:00
|
|
|
import bpy
|
2016-06-23 19:00:47 +02:00
|
|
|
from bpy.types import AddonPreferences, Operator, WindowManager, Scene, PropertyGroup
|
2021-02-16 11:21:06 +01:00
|
|
|
from bpy.props import (
|
|
|
|
StringProperty,
|
|
|
|
EnumProperty,
|
|
|
|
PointerProperty,
|
|
|
|
BoolProperty,
|
|
|
|
IntProperty,
|
|
|
|
)
|
2016-07-20 16:54:06 +02:00
|
|
|
import rna_prop_ui
|
2016-03-18 16:53:52 +01:00
|
|
|
|
2019-10-10 10:23:40 +02:00
|
|
|
from . import compatibility, pillar, async_loop, flamenco, project_specific
|
2017-01-13 17:24:37 +01:00
|
|
|
from .utils import pyside_cache, redraw
|
2016-03-18 16:53:52 +01:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
PILLAR_WEB_SERVER_URL = os.environ.get("BCLOUD_SERVER", "https://cloud.blender.org/")
|
|
|
|
PILLAR_SERVER_URL = "%sapi/" % PILLAR_WEB_SERVER_URL
|
2016-05-04 14:30:47 +02:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
ADDON_NAME = "blender_cloud"
|
2016-04-13 15:37:19 +02:00
|
|
|
log = logging.getLogger(__name__)
|
2016-07-08 17:00:44 +02:00
|
|
|
icons = None
|
|
|
|
|
2018-09-04 13:47:44 +02:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
@pyside_cache("version")
|
2016-06-24 12:53:49 +02:00
|
|
|
def blender_syncable_versions(self, context):
|
2016-08-26 17:43:20 +02:00
|
|
|
"""Returns the list of items used by SyncStatusProperties.version EnumProperty."""
|
|
|
|
|
2016-06-24 12:53:49 +02:00
|
|
|
bss = context.window_manager.blender_sync_status
|
|
|
|
versions = bss.available_blender_versions
|
|
|
|
if not versions:
|
2021-02-16 11:21:06 +01:00
|
|
|
return [("", "No settings stored in your Blender Cloud", "")]
|
|
|
|
return [(v, v, "") for v in versions]
|
2016-06-24 12:53:49 +02:00
|
|
|
|
|
|
|
|
2019-10-10 10:23:40 +02:00
|
|
|
@compatibility.convert_properties
|
2016-06-23 19:00:47 +02:00
|
|
|
class SyncStatusProperties(PropertyGroup):
|
|
|
|
status = EnumProperty(
|
|
|
|
items=[
|
2021-02-16 11:21:06 +01:00
|
|
|
("NONE", "NONE", "We have done nothing at all yet."),
|
|
|
|
(
|
|
|
|
"IDLE",
|
|
|
|
"IDLE",
|
|
|
|
"User requested something, which is done, and we are now idle.",
|
|
|
|
),
|
|
|
|
("SYNCING", "SYNCING", "Synchronising with Blender Cloud."),
|
2016-06-23 19:00:47 +02:00
|
|
|
],
|
2021-02-16 11:21:06 +01:00
|
|
|
name="status",
|
|
|
|
description="Current status of Blender Sync",
|
|
|
|
update=redraw,
|
|
|
|
)
|
2016-06-24 12:53:49 +02:00
|
|
|
|
|
|
|
version = EnumProperty(
|
|
|
|
items=blender_syncable_versions,
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Version of Blender from which to pull",
|
|
|
|
description="Version of Blender from which to pull",
|
|
|
|
)
|
2016-06-24 12:53:49 +02:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
message = StringProperty(name="message", update=redraw)
|
2016-06-23 19:00:47 +02:00
|
|
|
level = EnumProperty(
|
|
|
|
items=[
|
2021-02-16 11:21:06 +01:00
|
|
|
("INFO", "INFO", ""),
|
|
|
|
("WARNING", "WARNING", ""),
|
|
|
|
("ERROR", "ERROR", ""),
|
|
|
|
("SUBSCRIBE", "SUBSCRIBE", ""),
|
2016-06-23 19:00:47 +02:00
|
|
|
],
|
2021-02-16 11:21:06 +01:00
|
|
|
name="level",
|
|
|
|
update=redraw,
|
|
|
|
)
|
2016-06-23 19:00:47 +02:00
|
|
|
|
|
|
|
def report(self, level: set, message: str):
|
2021-02-16 11:21:06 +01:00
|
|
|
assert len(level) == 1, "level should be a set of one string, not %r" % level
|
2016-06-23 19:00:47 +02:00
|
|
|
self.level = level.pop()
|
|
|
|
self.message = message
|
2016-06-24 12:53:49 +02:00
|
|
|
|
|
|
|
# Message can also be empty, just to erase it from the GUI.
|
|
|
|
# No need to actually log those.
|
|
|
|
if message:
|
2016-06-24 15:22:12 +02:00
|
|
|
try:
|
|
|
|
loglevel = logging._nameToLevel[self.level]
|
|
|
|
except KeyError:
|
|
|
|
loglevel = logging.WARNING
|
|
|
|
log.log(loglevel, message)
|
2016-06-24 12:53:49 +02:00
|
|
|
|
|
|
|
# List of syncable versions is stored in 'available_blender_versions' ID property,
|
|
|
|
# because I don't know how to store a variable list of strings in a proper RNA property.
|
|
|
|
@property
|
|
|
|
def available_blender_versions(self) -> list:
|
2021-02-16 11:21:06 +01:00
|
|
|
return self.get("available_blender_versions", [])
|
2016-06-24 12:53:49 +02:00
|
|
|
|
|
|
|
@available_blender_versions.setter
|
|
|
|
def available_blender_versions(self, new_versions):
|
2021-02-16 11:21:06 +01:00
|
|
|
self["available_blender_versions"] = new_versions
|
2016-06-23 19:00:47 +02:00
|
|
|
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
@pyside_cache("project")
|
2016-08-26 17:43:20 +02:00
|
|
|
def bcloud_available_projects(self, context):
|
|
|
|
"""Returns the list of items used by BlenderCloudProjectGroup.project EnumProperty."""
|
|
|
|
|
2017-03-17 15:08:09 +01:00
|
|
|
projs = preferences().project.available_projects
|
2016-08-26 17:43:20 +02:00
|
|
|
if not projs:
|
2021-02-16 11:21:06 +01:00
|
|
|
return [("", "No projects available in your Blender Cloud", "")]
|
|
|
|
return [(p["_id"], p["name"], "") for p in projs]
|
2016-08-26 17:43:20 +02:00
|
|
|
|
|
|
|
|
2017-03-17 15:08:09 +01:00
|
|
|
@functools.lru_cache(1)
|
|
|
|
def project_extensions(project_id) -> set:
|
|
|
|
"""Returns the extensions the project is enabled for.
|
|
|
|
|
|
|
|
At the moment of writing these are 'attract' and 'flamenco'.
|
|
|
|
"""
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
log.debug("Finding extensions for project %s", project_id)
|
2017-03-17 15:08:09 +01:00
|
|
|
|
|
|
|
# We can't use our @property, since the preferences may be loaded from a
|
|
|
|
# preferences blend file, in which case it is not constructed from Python code.
|
2021-02-16 11:21:06 +01:00
|
|
|
available_projects = preferences().project.get("available_projects", [])
|
2017-03-17 15:08:09 +01:00
|
|
|
if not available_projects:
|
2021-02-16 11:21:06 +01:00
|
|
|
log.debug("No projects available.")
|
2017-03-17 15:08:09 +01:00
|
|
|
return set()
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
proj = next((p for p in available_projects if p["_id"] == project_id), None)
|
2017-03-17 15:08:09 +01:00
|
|
|
if proj is None:
|
2021-02-16 11:21:06 +01:00
|
|
|
log.debug("Project %s not found in available projects.", project_id)
|
2017-03-17 15:08:09 +01:00
|
|
|
return set()
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
return set(proj.get("enabled_for", ()))
|
2017-03-17 15:08:09 +01:00
|
|
|
|
|
|
|
|
2019-10-10 10:23:40 +02:00
|
|
|
@compatibility.convert_properties
|
2016-08-26 17:43:20 +02:00
|
|
|
class BlenderCloudProjectGroup(PropertyGroup):
|
|
|
|
status = EnumProperty(
|
|
|
|
items=[
|
2021-02-16 11:21:06 +01:00
|
|
|
("NONE", "NONE", "We have done nothing at all yet"),
|
|
|
|
(
|
|
|
|
"IDLE",
|
|
|
|
"IDLE",
|
|
|
|
"User requested something, which is done, and we are now idle",
|
|
|
|
),
|
|
|
|
("FETCHING", "FETCHING", "Fetching available projects from Blender Cloud"),
|
2016-08-26 17:43:20 +02:00
|
|
|
],
|
2021-02-16 11:21:06 +01:00
|
|
|
name="status",
|
|
|
|
update=redraw,
|
|
|
|
)
|
2016-08-26 17:43:20 +02:00
|
|
|
|
|
|
|
project = EnumProperty(
|
|
|
|
items=bcloud_available_projects,
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Cloud project",
|
|
|
|
description="Which Blender Cloud project to work with",
|
|
|
|
update=project_specific.handle_project_update,
|
2017-03-17 15:08:09 +01:00
|
|
|
)
|
2016-08-26 17:43:20 +02:00
|
|
|
|
|
|
|
# List of projects is stored in 'available_projects' ID property,
|
|
|
|
# because I don't know how to store a variable list of strings in a proper RNA property.
|
|
|
|
@property
|
|
|
|
def available_projects(self) -> list:
|
2021-02-16 11:21:06 +01:00
|
|
|
return self.get("available_projects", [])
|
2016-08-26 17:43:20 +02:00
|
|
|
|
|
|
|
@available_projects.setter
|
|
|
|
def available_projects(self, new_projects):
|
2021-02-16 11:21:06 +01:00
|
|
|
self["available_projects"] = new_projects
|
2018-01-02 16:42:37 +01:00
|
|
|
project_specific.handle_project_update()
|
2016-08-26 17:43:20 +02:00
|
|
|
|
|
|
|
|
2019-10-10 10:23:40 +02:00
|
|
|
@compatibility.convert_properties
|
2016-03-18 16:53:52 +01:00
|
|
|
class BlenderCloudPreferences(AddonPreferences):
|
|
|
|
bl_idname = ADDON_NAME
|
|
|
|
|
2018-01-02 16:42:37 +01:00
|
|
|
# The following property is read-only to limit the scope of the
|
2016-04-19 11:37:46 +02:00
|
|
|
# addon and allow for proper testing within this scope.
|
2016-06-23 19:00:47 +02:00
|
|
|
pillar_server = StringProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Blender Cloud Server",
|
|
|
|
description="URL of the Blender Cloud backend server",
|
2016-05-04 14:30:47 +02:00
|
|
|
default=PILLAR_SERVER_URL,
|
2021-02-16 11:21:06 +01:00
|
|
|
get=lambda self: PILLAR_SERVER_URL,
|
2016-03-18 16:53:52 +01:00
|
|
|
)
|
|
|
|
|
2016-03-31 11:54:15 +02:00
|
|
|
local_texture_dir = StringProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Default Blender Cloud Texture Storage Directory",
|
|
|
|
subtype="DIR_PATH",
|
|
|
|
default="//textures",
|
|
|
|
)
|
2016-03-31 11:54:15 +02:00
|
|
|
|
2016-07-07 11:43:01 +02:00
|
|
|
open_browser_after_share = BoolProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Open Browser after Sharing File",
|
|
|
|
description="When enabled, Blender will open a webbrowser",
|
|
|
|
default=True,
|
2016-07-07 11:43:01 +02:00
|
|
|
)
|
|
|
|
|
2017-03-17 15:08:09 +01:00
|
|
|
# TODO: store project-dependent properties with the project, so that people
|
|
|
|
# can switch projects and the Attract and Flamenco properties switch with it.
|
|
|
|
project = PointerProperty(type=BlenderCloudProjectGroup)
|
|
|
|
|
2017-03-21 14:06:45 +01:00
|
|
|
cloud_project_local_path = StringProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Local Project Path",
|
|
|
|
description="Local path of your Attract project, used to search for blend files; "
|
|
|
|
"usually best to set to an absolute path",
|
|
|
|
subtype="DIR_PATH",
|
|
|
|
default="//../",
|
2018-01-02 16:42:37 +01:00
|
|
|
update=project_specific.store,
|
|
|
|
)
|
2016-08-26 17:43:20 +02:00
|
|
|
|
2017-01-13 17:24:37 +01:00
|
|
|
flamenco_manager = PointerProperty(type=flamenco.FlamencoManagerGroup)
|
2017-04-21 18:15:59 +02:00
|
|
|
flamenco_exclude_filter = StringProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="File Exclude Filter",
|
2018-12-07 12:25:48 +01:00
|
|
|
description='Space-separated list of filename filters, like "*.abc *.mkv", to prevent '
|
2021-02-16 11:21:06 +01:00
|
|
|
"matching files from being packed into the output directory",
|
|
|
|
default="",
|
2018-01-02 16:42:37 +01:00
|
|
|
update=project_specific.store,
|
|
|
|
)
|
2017-01-13 17:24:37 +01:00
|
|
|
flamenco_job_file_path = StringProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Job Storage Path",
|
|
|
|
description="Path where to store job files, should be accesible for Workers too",
|
|
|
|
subtype="DIR_PATH",
|
2018-01-02 16:42:37 +01:00
|
|
|
default=tempfile.gettempdir(),
|
|
|
|
update=project_specific.store,
|
|
|
|
)
|
2017-01-18 14:31:25 +01:00
|
|
|
flamenco_job_output_path = StringProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Job Output Path",
|
|
|
|
description="Path where to store output files, should be accessible for Workers",
|
|
|
|
subtype="DIR_PATH",
|
2018-01-02 16:42:37 +01:00
|
|
|
default=tempfile.gettempdir(),
|
|
|
|
update=project_specific.store,
|
|
|
|
)
|
2017-01-18 14:31:25 +01:00
|
|
|
flamenco_job_output_strip_components = IntProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Job Output Path Strip Components",
|
|
|
|
description="The final output path comprises of the job output path, and the blend file "
|
|
|
|
"path relative to the project with this many path components stripped off "
|
|
|
|
"the front",
|
2017-01-18 14:31:25 +01:00
|
|
|
min=0,
|
|
|
|
default=0,
|
|
|
|
soft_max=4,
|
2018-01-02 16:42:37 +01:00
|
|
|
update=project_specific.store,
|
2017-01-18 14:31:25 +01:00
|
|
|
)
|
2018-12-06 15:46:54 +01:00
|
|
|
flamenco_relative_only = BoolProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Relative Paths Only",
|
|
|
|
description="When enabled, only assets that are referred to with a relative path are "
|
|
|
|
"packed, and assets referred to by an absolute path are excluded from the "
|
|
|
|
"BAT pack. When disabled, all assets are packed",
|
2018-12-06 15:46:54 +01:00
|
|
|
default=False,
|
|
|
|
update=project_specific.store,
|
|
|
|
)
|
|
|
|
|
2017-01-24 15:14:43 +01:00
|
|
|
flamenco_open_browser_after_submit = BoolProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Open Browser after Submitting Job",
|
|
|
|
description="When enabled, Blender will open a webbrowser",
|
2018-01-02 16:42:37 +01:00
|
|
|
default=True,
|
2017-01-24 15:14:43 +01:00
|
|
|
)
|
2019-01-31 14:42:50 +01:00
|
|
|
flamenco_show_quit_after_submit_button = BoolProperty(
|
|
|
|
name='Show "Submit & Quit" button',
|
|
|
|
description='When enabled, next to the "Render on Flamenco" button there will be a button '
|
2021-02-16 11:21:06 +01:00
|
|
|
'"Submit & Quit" that silently quits Blender after submitting the render job '
|
|
|
|
"to Flamenco",
|
2019-01-31 14:42:50 +01:00
|
|
|
default=False,
|
|
|
|
)
|
2017-01-18 14:31:25 +01:00
|
|
|
|
2016-03-18 16:53:52 +01:00
|
|
|
def draw(self, context):
|
2016-05-03 18:29:43 +02:00
|
|
|
import textwrap
|
|
|
|
|
2016-03-18 16:53:52 +01:00
|
|
|
layout = self.layout
|
|
|
|
|
|
|
|
# Carefully try and import the Blender ID addon
|
|
|
|
try:
|
2016-04-01 14:11:12 +02:00
|
|
|
import blender_id
|
2016-03-18 16:53:52 +01:00
|
|
|
except ImportError:
|
2016-04-01 14:11:12 +02:00
|
|
|
blender_id = None
|
2016-03-18 16:53:52 +01:00
|
|
|
blender_id_profile = None
|
|
|
|
else:
|
2016-04-01 14:11:12 +02:00
|
|
|
blender_id_profile = blender_id.get_active_profile()
|
|
|
|
if blender_id is None:
|
2017-03-17 15:08:09 +01:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
msg_icon = "ERROR"
|
|
|
|
text = "This add-on requires Blender ID"
|
|
|
|
help_text = (
|
|
|
|
"Make sure that the Blender ID add-on is installed and activated"
|
|
|
|
)
|
2016-03-18 16:53:52 +01:00
|
|
|
elif not blender_id_profile:
|
2021-02-16 11:21:06 +01:00
|
|
|
msg_icon = "ERROR"
|
|
|
|
text = "You are logged out."
|
|
|
|
help_text = "To login, go to the Blender ID add-on preferences."
|
2016-06-24 14:46:13 +02:00
|
|
|
elif bpy.app.debug and pillar.SUBCLIENT_ID not in blender_id_profile.subclients:
|
2021-02-16 11:21:06 +01:00
|
|
|
msg_icon = "QUESTION"
|
|
|
|
text = "No Blender Cloud credentials."
|
|
|
|
help_text = (
|
|
|
|
"You are logged in on Blender ID, but your credentials have not "
|
|
|
|
"been synchronized with Blender Cloud yet. Press the Update "
|
|
|
|
"Credentials button."
|
|
|
|
)
|
2016-03-18 16:53:52 +01:00
|
|
|
else:
|
2021-02-16 11:21:06 +01:00
|
|
|
msg_icon = "WORLD_DATA"
|
|
|
|
text = "You are logged in as %s." % blender_id_profile.username
|
|
|
|
help_text = (
|
|
|
|
"To logout or change profile, "
|
|
|
|
"go to the Blender ID add-on preferences."
|
|
|
|
)
|
2016-03-18 16:53:52 +01:00
|
|
|
|
2016-06-24 12:53:49 +02:00
|
|
|
# Authentication stuff
|
|
|
|
auth_box = layout.box()
|
2016-07-08 17:00:44 +02:00
|
|
|
auth_box.label(text=text, icon=msg_icon)
|
2016-05-03 18:29:43 +02:00
|
|
|
|
|
|
|
help_lines = textwrap.wrap(help_text, 80)
|
|
|
|
for line in help_lines:
|
2016-06-24 12:53:49 +02:00
|
|
|
auth_box.label(text=line)
|
2016-06-24 14:46:13 +02:00
|
|
|
if bpy.app.debug:
|
|
|
|
auth_box.operator("pillar.credentials_update")
|
2016-03-18 16:53:52 +01:00
|
|
|
|
2016-06-24 12:53:49 +02:00
|
|
|
# Texture browser stuff
|
|
|
|
texture_box = layout.box()
|
2021-02-16 11:21:06 +01:00
|
|
|
texture_box.enabled = msg_icon != "ERROR"
|
2016-06-24 12:53:49 +02:00
|
|
|
sub = texture_box.column()
|
2021-02-16 11:21:06 +01:00
|
|
|
sub.label(
|
|
|
|
text="Local directory for downloaded textures", icon_value=icon("CLOUD")
|
|
|
|
)
|
|
|
|
sub.prop(self, "local_texture_dir", text="Default")
|
|
|
|
sub.prop(context.scene, "local_texture_dir", text="Current scene")
|
2016-03-31 11:54:15 +02:00
|
|
|
|
2016-06-24 12:53:49 +02:00
|
|
|
# Blender Sync stuff
|
2016-06-23 19:00:47 +02:00
|
|
|
bss = context.window_manager.blender_sync_status
|
2016-06-24 12:53:49 +02:00
|
|
|
bsync_box = layout.box()
|
2021-02-16 11:21:06 +01:00
|
|
|
bsync_box.enabled = msg_icon != "ERROR"
|
2019-10-10 10:23:40 +02:00
|
|
|
row = bsync_box.row().split(**compatibility.factor(0.33))
|
2021-02-16 11:21:06 +01:00
|
|
|
row.label(text="Blender Sync with Blender Cloud", icon_value=icon("CLOUD"))
|
2016-06-23 19:00:47 +02:00
|
|
|
|
|
|
|
icon_for_level = {
|
2021-02-16 11:21:06 +01:00
|
|
|
"INFO": "NONE",
|
|
|
|
"WARNING": "INFO",
|
|
|
|
"ERROR": "ERROR",
|
|
|
|
"SUBSCRIBE": "ERROR",
|
2016-06-23 19:00:47 +02:00
|
|
|
}
|
2021-02-16 11:21:06 +01:00
|
|
|
msg_icon = icon_for_level[bss.level] if bss.message else "NONE"
|
2016-06-23 19:00:47 +02:00
|
|
|
message_container = row.row()
|
2018-09-04 13:47:44 +02:00
|
|
|
message_container.label(text=bss.message, icon=msg_icon)
|
2016-06-23 19:00:47 +02:00
|
|
|
|
2016-06-24 12:53:49 +02:00
|
|
|
sub = bsync_box.column()
|
2016-06-23 19:00:47 +02:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
if bss.level == "SUBSCRIBE":
|
2016-06-24 15:22:12 +02:00
|
|
|
self.draw_subscribe_button(sub)
|
2016-07-08 12:38:58 +02:00
|
|
|
self.draw_sync_buttons(sub, bss)
|
2016-06-24 15:22:12 +02:00
|
|
|
|
2016-07-07 11:43:01 +02:00
|
|
|
# Image Share stuff
|
|
|
|
share_box = layout.box()
|
2021-02-16 11:21:06 +01:00
|
|
|
share_box.label(text="Image Sharing on Blender Cloud", icon_value=icon("CLOUD"))
|
|
|
|
share_box.prop(self, "open_browser_after_share")
|
2016-07-07 11:43:01 +02:00
|
|
|
|
2017-03-17 15:08:09 +01:00
|
|
|
# Project selector
|
|
|
|
project_box = layout.box()
|
2021-02-16 11:21:06 +01:00
|
|
|
project_box.enabled = self.project.status in {"NONE", "IDLE"}
|
2017-03-17 15:08:09 +01:00
|
|
|
|
|
|
|
self.draw_project_selector(project_box, self.project)
|
|
|
|
extensions = project_extensions(self.project.project)
|
|
|
|
|
2017-01-13 17:24:37 +01:00
|
|
|
# Flamenco stuff
|
2021-02-16 11:21:06 +01:00
|
|
|
if "flamenco" in extensions:
|
2017-03-17 15:08:09 +01:00
|
|
|
flamenco_box = project_box.column()
|
|
|
|
self.draw_flamenco_buttons(flamenco_box, self.flamenco_manager, context)
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2016-06-24 15:22:12 +02:00
|
|
|
def draw_subscribe_button(self, layout):
|
2021-02-16 11:21:06 +01:00
|
|
|
layout.operator("pillar.subscribe", icon="WORLD")
|
2016-06-24 15:22:12 +02:00
|
|
|
|
|
|
|
def draw_sync_buttons(self, layout, bss):
|
2021-02-16 11:21:06 +01:00
|
|
|
layout.enabled = bss.status in {"NONE", "IDLE"}
|
2016-06-24 15:22:12 +02:00
|
|
|
|
|
|
|
buttons = layout.column()
|
2019-10-10 10:23:40 +02:00
|
|
|
row_buttons = buttons.row().split(**compatibility.factor(0.5))
|
2016-06-24 12:53:49 +02:00
|
|
|
row_push = row_buttons.row()
|
2016-06-28 16:55:35 +02:00
|
|
|
row_pull = row_buttons.row(align=True)
|
2016-06-24 12:53:49 +02:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
row_push.operator(
|
|
|
|
"pillar.sync",
|
|
|
|
text="Save %i.%i settings" % bpy.app.version[:2],
|
|
|
|
icon="TRIA_UP",
|
|
|
|
).action = "PUSH"
|
2016-06-24 12:53:49 +02:00
|
|
|
|
|
|
|
versions = bss.available_blender_versions
|
2021-02-16 11:21:06 +01:00
|
|
|
if bss.status in {"NONE", "IDLE"}:
|
2019-03-26 12:35:27 +01:00
|
|
|
if not versions:
|
2021-02-16 11:21:06 +01:00
|
|
|
row_pull.operator(
|
|
|
|
"pillar.sync", text="Find version to load", icon="TRIA_DOWN"
|
|
|
|
).action = "REFRESH"
|
2016-06-24 12:53:49 +02:00
|
|
|
else:
|
2021-02-16 11:21:06 +01:00
|
|
|
props = row_pull.operator(
|
|
|
|
"pillar.sync",
|
|
|
|
text="Load %s settings" % bss.version,
|
|
|
|
icon="TRIA_DOWN",
|
|
|
|
)
|
|
|
|
props.action = "PULL"
|
2019-03-26 12:35:27 +01:00
|
|
|
props.blender_version = bss.version
|
2021-02-16 11:21:06 +01:00
|
|
|
row_pull.operator(
|
|
|
|
"pillar.sync", text="", icon=compatibility.SYNC_SELECT_VERSION_ICON
|
|
|
|
).action = "SELECT"
|
2016-06-24 12:53:49 +02:00
|
|
|
else:
|
2021-02-16 11:21:06 +01:00
|
|
|
row_pull.label(text="Cloud Sync is running.")
|
2016-06-23 19:00:47 +02:00
|
|
|
|
2017-03-17 15:08:09 +01:00
|
|
|
def draw_project_selector(self, project_box, bcp: BlenderCloudProjectGroup):
|
|
|
|
project_row = project_box.row(align=True)
|
2021-02-16 11:21:06 +01:00
|
|
|
project_row.label(text="Project settings", icon_value=icon("CLOUD"))
|
2016-10-11 11:17:24 +02:00
|
|
|
|
2017-03-17 15:08:09 +01:00
|
|
|
row_buttons = project_row.row(align=True)
|
2016-08-26 17:43:20 +02:00
|
|
|
|
|
|
|
projects = bcp.available_projects
|
|
|
|
project = bcp.project
|
2021-02-16 11:21:06 +01:00
|
|
|
if bcp.status in {"NONE", "IDLE"}:
|
2019-02-13 14:29:36 +01:00
|
|
|
if not projects:
|
2021-02-16 11:21:06 +01:00
|
|
|
row_buttons.operator(
|
|
|
|
"pillar.projects", text="Find project to load", icon="FILE_REFRESH"
|
|
|
|
)
|
2016-08-26 17:43:20 +02:00
|
|
|
else:
|
2021-02-16 11:21:06 +01:00
|
|
|
row_buttons.prop(bcp, "project")
|
|
|
|
row_buttons.operator("pillar.projects", text="", icon="FILE_REFRESH")
|
|
|
|
props = row_buttons.operator(
|
|
|
|
"pillar.project_open_in_browser", text="", icon="WORLD"
|
|
|
|
)
|
2018-01-02 16:42:52 +01:00
|
|
|
props.project_id = project
|
2016-08-26 17:43:20 +02:00
|
|
|
else:
|
2021-02-16 11:21:06 +01:00
|
|
|
row_buttons.label(text="Fetching available projects.")
|
2016-08-26 17:43:20 +02:00
|
|
|
|
2017-03-17 15:08:09 +01:00
|
|
|
enabled_for = project_extensions(project)
|
2017-03-21 14:06:45 +01:00
|
|
|
if not project:
|
|
|
|
return
|
|
|
|
|
|
|
|
if not enabled_for:
|
2021-02-16 11:21:06 +01:00
|
|
|
project_box.label(text="This project is not set up for Attract or Flamenco")
|
2017-03-21 14:06:45 +01:00
|
|
|
return
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
project_box.label(
|
|
|
|
text="This project is set up for: %s" % ", ".join(sorted(enabled_for))
|
|
|
|
)
|
2017-03-17 15:08:09 +01:00
|
|
|
|
2017-03-21 14:06:45 +01:00
|
|
|
# This is only needed when the project is set up for either Attract or Flamenco.
|
2021-02-16 11:21:06 +01:00
|
|
|
project_box.prop(self, "cloud_project_local_path", text="Local Project Path")
|
2016-10-11 11:17:24 +02:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
def draw_flamenco_buttons(
|
|
|
|
self, flamenco_box, bcp: flamenco.FlamencoManagerGroup, context
|
|
|
|
):
|
2017-03-17 15:08:09 +01:00
|
|
|
header_row = flamenco_box.row(align=True)
|
2021-02-16 11:21:06 +01:00
|
|
|
header_row.label(text="Flamenco:", icon_value=icon("CLOUD"))
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2019-10-10 10:23:40 +02:00
|
|
|
manager_split = flamenco_box.split(**compatibility.factor(0.32), align=True)
|
2021-02-16 11:21:06 +01:00
|
|
|
manager_split.label(text="Manager:")
|
2017-04-21 18:15:59 +02:00
|
|
|
manager_box = manager_split.row(align=True)
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
if bcp.status in {"NONE", "IDLE"}:
|
2019-03-26 12:35:27 +01:00
|
|
|
if not bcp.available_managers:
|
2021-02-16 11:21:06 +01:00
|
|
|
manager_box.operator(
|
|
|
|
"flamenco.managers",
|
|
|
|
text="Find Flamenco Managers",
|
|
|
|
icon="FILE_REFRESH",
|
|
|
|
)
|
2017-01-13 17:24:37 +01:00
|
|
|
else:
|
2021-02-16 11:21:06 +01:00
|
|
|
manager_box.prop(bcp, "manager", text="")
|
|
|
|
manager_box.operator("flamenco.managers", text="", icon="FILE_REFRESH")
|
2017-01-13 17:24:37 +01:00
|
|
|
else:
|
2021-02-16 11:21:06 +01:00
|
|
|
manager_box.label(text="Fetching available managers.")
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2019-10-10 10:23:40 +02:00
|
|
|
path_split = flamenco_box.split(**compatibility.factor(0.32), align=True)
|
2021-02-16 11:21:06 +01:00
|
|
|
path_split.label(text="Job File Path:")
|
2017-04-21 18:15:59 +02:00
|
|
|
path_box = path_split.row(align=True)
|
2021-02-16 11:21:06 +01:00
|
|
|
path_box.prop(self, "flamenco_job_file_path", text="")
|
|
|
|
props = path_box.operator(
|
|
|
|
"flamenco.explore_file_path", text="", icon="DISK_DRIVE"
|
|
|
|
)
|
2017-01-18 14:31:25 +01:00
|
|
|
props.path = self.flamenco_job_file_path
|
|
|
|
|
|
|
|
job_output_box = flamenco_box.column(align=True)
|
2019-10-10 10:23:40 +02:00
|
|
|
path_split = job_output_box.split(**compatibility.factor(0.32), align=True)
|
2021-02-16 11:21:06 +01:00
|
|
|
path_split.label(text="Job Output Path:")
|
2017-04-21 18:15:59 +02:00
|
|
|
path_box = path_split.row(align=True)
|
2021-02-16 11:21:06 +01:00
|
|
|
path_box.prop(self, "flamenco_job_output_path", text="")
|
|
|
|
props = path_box.operator(
|
|
|
|
"flamenco.explore_file_path", text="", icon="DISK_DRIVE"
|
|
|
|
)
|
2017-01-18 14:31:25 +01:00
|
|
|
props.path = self.flamenco_job_output_path
|
2021-02-16 11:21:06 +01:00
|
|
|
job_output_box.prop(self, "flamenco_exclude_filter")
|
2017-04-21 18:15:59 +02:00
|
|
|
|
2019-10-10 10:23:40 +02:00
|
|
|
prop_split = job_output_box.split(**compatibility.factor(0.32), align=True)
|
2021-02-16 11:21:06 +01:00
|
|
|
prop_split.label(text="Strip Components:")
|
|
|
|
prop_split.prop(self, "flamenco_job_output_strip_components", text="")
|
2017-01-18 14:31:25 +01:00
|
|
|
|
|
|
|
from .flamenco import render_output_path
|
|
|
|
|
|
|
|
path_box = job_output_box.row(align=True)
|
|
|
|
output_path = render_output_path(context)
|
2017-02-01 14:00:46 +01:00
|
|
|
if output_path:
|
2018-09-04 13:47:44 +02:00
|
|
|
path_box.label(text=str(output_path))
|
2021-02-16 11:21:06 +01:00
|
|
|
props = path_box.operator(
|
|
|
|
"flamenco.explore_file_path", text="", icon="DISK_DRIVE"
|
|
|
|
)
|
2017-02-01 14:00:46 +01:00
|
|
|
props.path = str(output_path.parent)
|
|
|
|
else:
|
2021-02-16 11:21:06 +01:00
|
|
|
path_box.label(
|
|
|
|
text="Blend file is not in your project path, "
|
|
|
|
"unable to give output path example."
|
|
|
|
)
|
2017-01-17 16:03:46 +01:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
flamenco_box.prop(self, "flamenco_relative_only")
|
|
|
|
flamenco_box.prop(self, "flamenco_open_browser_after_submit")
|
|
|
|
flamenco_box.prop(self, "flamenco_show_quit_after_submit_button")
|
2017-01-24 15:14:43 +01:00
|
|
|
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
class PillarCredentialsUpdate(pillar.PillarOperatorMixin, Operator):
|
2016-03-18 16:53:52 +01:00
|
|
|
"""Updates the Pillar URL and tests the new URL."""
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
bl_idname = "pillar.credentials_update"
|
|
|
|
bl_label = "Update credentials"
|
|
|
|
bl_description = "Resynchronises your Blender ID login with Blender Cloud"
|
|
|
|
|
|
|
|
log = logging.getLogger("bpy.ops.%s" % bl_idname)
|
2016-07-14 11:47:50 +02:00
|
|
|
|
2016-03-18 16:53:52 +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):
|
2016-04-01 17:16:29 +02:00
|
|
|
try:
|
|
|
|
import blender_id
|
|
|
|
except ImportError:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return blender_id.is_logged_in()
|
2016-03-18 16:53:52 +01:00
|
|
|
|
|
|
|
def execute(self, context):
|
2016-04-12 16:59:34 +02:00
|
|
|
import blender_id
|
|
|
|
import asyncio
|
|
|
|
|
2016-03-18 16:53:52 +01:00
|
|
|
# Only allow activation when the user is actually logged in.
|
|
|
|
if not self.is_logged_in(context):
|
2021-02-16 11:21:06 +01:00
|
|
|
self.report({"ERROR"}, "No active profile found")
|
|
|
|
return {"CANCELLED"}
|
2016-04-12 16:59:34 +02:00
|
|
|
|
|
|
|
try:
|
2016-05-04 14:30:47 +02:00
|
|
|
loop = asyncio.get_event_loop()
|
2016-06-24 15:22:12 +02:00
|
|
|
loop.run_until_complete(self.check_credentials(context, set()))
|
2016-04-12 16:59:34 +02:00
|
|
|
except blender_id.BlenderIdCommError as ex:
|
2021-02-16 11:21:06 +01:00
|
|
|
log.exception("Error sending subclient-specific token to Blender ID")
|
|
|
|
self.report({"ERROR"}, "Failed to sync Blender ID to Blender Cloud")
|
|
|
|
return {"CANCELLED"}
|
2016-04-12 16:59:34 +02:00
|
|
|
except Exception as ex:
|
2021-02-16 11:21:06 +01:00
|
|
|
log.exception("Error in test call to Pillar")
|
|
|
|
self.report({"ERROR"}, "Failed test connection to Blender Cloud")
|
|
|
|
return {"CANCELLED"}
|
2016-03-18 16:53:52 +01:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
self.report({"INFO"}, "Blender Cloud credentials & endpoint URL updated.")
|
|
|
|
return {"FINISHED"}
|
2016-03-18 16:53:52 +01:00
|
|
|
|
|
|
|
|
2016-06-24 15:22:12 +02:00
|
|
|
class PILLAR_OT_subscribe(Operator):
|
|
|
|
"""Opens a browser to subscribe the user to the Cloud."""
|
2021-02-16 11:21:06 +01:00
|
|
|
|
|
|
|
bl_idname = "pillar.subscribe"
|
|
|
|
bl_label = "Subscribe to the Cloud"
|
2016-10-03 19:29:41 +02:00
|
|
|
bl_description = "Opens a page in a web browser to subscribe to the Blender Cloud"
|
2016-06-24 15:22:12 +02:00
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
import webbrowser
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
webbrowser.open_new_tab("https://cloud.blender.org/join")
|
|
|
|
self.report({"INFO"}, "We just started a browser for you.")
|
2016-06-24 15:22:12 +02:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
return {"FINISHED"}
|
2016-06-24 15:22:12 +02:00
|
|
|
|
|
|
|
|
2019-10-10 10:23:40 +02:00
|
|
|
@compatibility.convert_properties
|
2018-01-02 16:42:52 +01:00
|
|
|
class PILLAR_OT_project_open_in_browser(Operator):
|
2021-02-16 11:21:06 +01:00
|
|
|
bl_idname = "pillar.project_open_in_browser"
|
|
|
|
bl_label = "Open in Browser"
|
|
|
|
bl_description = "Opens a webbrowser to show the project"
|
2018-01-02 16:42:52 +01:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
project_id = StringProperty(name="Project ID")
|
2018-01-02 16:42:52 +01:00
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
if not self.project_id:
|
2021-02-16 11:21:06 +01:00
|
|
|
return {"CANCELLED"}
|
2018-01-02 16:42:52 +01:00
|
|
|
|
|
|
|
import webbrowser
|
|
|
|
import urllib.parse
|
|
|
|
|
|
|
|
import pillarsdk
|
|
|
|
from .pillar import sync_call
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
project = sync_call(
|
|
|
|
pillarsdk.Project.find, self.project_id, {"projection": {"url": True}}
|
|
|
|
)
|
2018-01-02 16:42:52 +01:00
|
|
|
|
|
|
|
if log.isEnabledFor(logging.DEBUG):
|
|
|
|
import pprint
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
log.debug("found project: %s", pprint.pformat(project.to_dict()))
|
|
|
|
|
|
|
|
url = urllib.parse.urljoin(PILLAR_WEB_SERVER_URL, "p/" + project.url)
|
2018-01-02 16:42:52 +01:00
|
|
|
webbrowser.open_new_tab(url)
|
2021-02-16 11:21:06 +01:00
|
|
|
self.report({"INFO"}, "Opened a browser at %s" % url)
|
2018-01-02 16:42:52 +01:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
return {"FINISHED"}
|
2018-01-02 16:42:52 +01:00
|
|
|
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
class PILLAR_OT_projects(
|
|
|
|
async_loop.AsyncModalOperatorMixin,
|
|
|
|
pillar.AuthenticatedPillarOperatorMixin,
|
|
|
|
Operator,
|
|
|
|
):
|
2016-10-18 12:23:36 +02:00
|
|
|
"""Fetches the projects available to the user"""
|
2021-02-16 11:21:06 +01:00
|
|
|
|
|
|
|
bl_idname = "pillar.projects"
|
|
|
|
bl_label = "Fetch available projects"
|
2016-08-26 17:43:20 +02:00
|
|
|
|
|
|
|
stop_upon_exception = True
|
2021-02-16 11:21:06 +01:00
|
|
|
_log = logging.getLogger("bpy.ops.%s" % bl_idname)
|
2016-08-26 17:43:20 +02:00
|
|
|
|
|
|
|
async def async_execute(self, context):
|
2017-01-13 17:24:37 +01:00
|
|
|
if not await self.authenticate(context):
|
|
|
|
return
|
|
|
|
|
2016-08-26 17:43:20 +02:00
|
|
|
import pillarsdk
|
|
|
|
from .pillar import pillar_call
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
self.log.info("Going to fetch projects for user %s", self.user_id)
|
2016-08-26 17:43:20 +02:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
preferences().project.status = "FETCHING"
|
2016-08-26 17:43:20 +02:00
|
|
|
|
|
|
|
# Get all projects, except the home project.
|
|
|
|
projects_user = await pillar_call(
|
|
|
|
pillarsdk.Project.all,
|
2021-02-16 11:21:06 +01:00
|
|
|
{
|
|
|
|
"where": {"user": self.user_id, "category": {"$ne": "home"}},
|
|
|
|
"sort": "-name",
|
|
|
|
"projection": {"_id": True, "name": True, "extension_props": True},
|
|
|
|
},
|
|
|
|
)
|
2016-08-26 17:43:20 +02:00
|
|
|
|
|
|
|
projects_shared = await pillar_call(
|
|
|
|
pillarsdk.Project.all,
|
2021-02-16 11:21:06 +01:00
|
|
|
{
|
|
|
|
"where": {
|
|
|
|
"user": {"$ne": self.user_id},
|
|
|
|
"permissions.groups.group": {"$in": self.db_user.groups},
|
|
|
|
},
|
|
|
|
"sort": "-name",
|
|
|
|
"projection": {"_id": True, "name": True, "extension_props": True},
|
|
|
|
},
|
|
|
|
)
|
2016-08-26 17:43:20 +02:00
|
|
|
|
|
|
|
# We need to convert to regular dicts before storing in ID properties.
|
|
|
|
# Also don't store more properties than we need.
|
2017-03-17 15:08:09 +01:00
|
|
|
def reduce_properties(project_list):
|
|
|
|
for p in project_list:
|
|
|
|
p = p.to_dict()
|
2021-02-16 11:21:06 +01:00
|
|
|
extension_props = p.get("extension_props", {})
|
2017-03-17 15:08:09 +01:00
|
|
|
enabled_for = list(extension_props.keys())
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
self._log.debug("Project %r is enabled for %s", p["name"], enabled_for)
|
2017-03-17 15:08:09 +01:00
|
|
|
yield {
|
2021-02-16 11:21:06 +01:00
|
|
|
"_id": p["_id"],
|
|
|
|
"name": p["name"],
|
|
|
|
"enabled_for": enabled_for,
|
2017-03-17 15:08:09 +01:00
|
|
|
}
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
projects = list(reduce_properties(projects_user["_items"])) + list(
|
|
|
|
reduce_properties(projects_shared["_items"])
|
|
|
|
)
|
2016-08-26 17:43:20 +02:00
|
|
|
|
2017-10-06 12:35:25 +02:00
|
|
|
def proj_sort_key(project):
|
2021-02-16 11:21:06 +01:00
|
|
|
return project.get("name")
|
2017-10-06 12:35:25 +02:00
|
|
|
|
|
|
|
preferences().project.available_projects = sorted(projects, key=proj_sort_key)
|
2016-08-26 17:43:20 +02:00
|
|
|
|
|
|
|
self.quit()
|
|
|
|
|
|
|
|
def quit(self):
|
2021-02-16 11:21:06 +01:00
|
|
|
preferences().project.status = "IDLE"
|
2016-08-26 17:43:20 +02:00
|
|
|
super().quit()
|
|
|
|
|
|
|
|
|
2016-07-20 16:54:06 +02:00
|
|
|
class PILLAR_PT_image_custom_properties(rna_prop_ui.PropertyPanel, bpy.types.Panel):
|
|
|
|
"""Shows custom properties in the image editor."""
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
bl_space_type = "IMAGE_EDITOR"
|
|
|
|
bl_region_type = "UI"
|
|
|
|
bl_label = "Custom Properties"
|
2016-07-20 16:54:06 +02:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
_context_path = "edit_image"
|
2016-07-20 16:54:06 +02:00
|
|
|
_property_type = bpy.types.Image
|
|
|
|
|
|
|
|
|
2018-12-28 12:31:33 +01:00
|
|
|
def ctx_preferences():
|
|
|
|
"""Returns bpy.context.preferences in a 2.79-compatible way."""
|
|
|
|
try:
|
|
|
|
return bpy.context.preferences
|
|
|
|
except AttributeError:
|
|
|
|
return bpy.context.user_preferences
|
|
|
|
|
|
|
|
|
2016-03-18 16:53:52 +01:00
|
|
|
def preferences() -> BlenderCloudPreferences:
|
2018-12-28 12:31:33 +01:00
|
|
|
return ctx_preferences().addons[ADDON_NAME].preferences
|
2016-03-18 16:53:52 +01:00
|
|
|
|
|
|
|
|
2016-07-08 17:00:44 +02:00
|
|
|
def load_custom_icons():
|
|
|
|
global icons
|
|
|
|
|
|
|
|
if icons is not None:
|
|
|
|
# Already loaded
|
|
|
|
return
|
|
|
|
|
|
|
|
import bpy.utils.previews
|
2021-02-16 11:21:06 +01:00
|
|
|
|
2016-07-08 17:00:44 +02:00
|
|
|
icons = bpy.utils.previews.new()
|
2021-02-16 11:21:06 +01:00
|
|
|
my_icons_dir = os.path.join(os.path.dirname(__file__), "icons")
|
|
|
|
icons.load("CLOUD", os.path.join(my_icons_dir, "icon-cloud.png"), "IMAGE")
|
2016-07-08 17:00:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
def unload_custom_icons():
|
|
|
|
global icons
|
|
|
|
|
|
|
|
if icons is None:
|
|
|
|
# Already unloaded
|
|
|
|
return
|
|
|
|
|
|
|
|
bpy.utils.previews.remove(icons)
|
|
|
|
icons = None
|
|
|
|
|
|
|
|
|
|
|
|
def icon(icon_name: str) -> int:
|
|
|
|
"""Returns the icon ID for the named icon.
|
|
|
|
|
|
|
|
Use with layout.operator('pillar.image_share', icon_value=icon('CLOUD'))
|
|
|
|
"""
|
|
|
|
|
|
|
|
return icons[icon_name].icon_id
|
|
|
|
|
|
|
|
|
2016-03-18 16:53:52 +01:00
|
|
|
def register():
|
2016-08-30 10:39:09 +02:00
|
|
|
bpy.utils.register_class(BlenderCloudProjectGroup)
|
2016-03-18 16:53:52 +01:00
|
|
|
bpy.utils.register_class(BlenderCloudPreferences)
|
|
|
|
bpy.utils.register_class(PillarCredentialsUpdate)
|
2016-06-23 19:00:47 +02:00
|
|
|
bpy.utils.register_class(SyncStatusProperties)
|
2016-06-24 15:22:12 +02:00
|
|
|
bpy.utils.register_class(PILLAR_OT_subscribe)
|
2016-08-26 17:43:20 +02:00
|
|
|
bpy.utils.register_class(PILLAR_OT_projects)
|
2018-01-02 16:42:52 +01:00
|
|
|
bpy.utils.register_class(PILLAR_OT_project_open_in_browser)
|
2016-07-20 16:54:06 +02:00
|
|
|
bpy.utils.register_class(PILLAR_PT_image_custom_properties)
|
2016-03-18 16:53:52 +01:00
|
|
|
|
2016-05-17 17:30:38 +02:00
|
|
|
addon_prefs = preferences()
|
|
|
|
|
2016-05-18 11:56:46 +02:00
|
|
|
WindowManager.last_blender_cloud_location = StringProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Last Blender Cloud browser location", default="/"
|
|
|
|
)
|
2016-03-31 11:54:15 +02:00
|
|
|
|
|
|
|
def default_if_empty(scene, context):
|
|
|
|
"""The scene's local_texture_dir, if empty, reverts to the addon prefs."""
|
|
|
|
|
|
|
|
if not scene.local_texture_dir:
|
|
|
|
scene.local_texture_dir = addon_prefs.local_texture_dir
|
|
|
|
|
|
|
|
Scene.local_texture_dir = StringProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Blender Cloud texture storage directory for current scene",
|
|
|
|
subtype="DIR_PATH",
|
2016-03-31 11:54:15 +02:00
|
|
|
default=addon_prefs.local_texture_dir,
|
2021-02-16 11:21:06 +01:00
|
|
|
update=default_if_empty,
|
|
|
|
)
|
2016-03-18 16:53:52 +01:00
|
|
|
|
2016-06-23 19:00:47 +02:00
|
|
|
WindowManager.blender_sync_status = PointerProperty(type=SyncStatusProperties)
|
|
|
|
|
2016-07-08 17:00:44 +02:00
|
|
|
load_custom_icons()
|
|
|
|
|
2016-03-18 16:53:52 +01:00
|
|
|
|
|
|
|
def unregister():
|
2016-07-08 17:00:44 +02:00
|
|
|
unload_custom_icons()
|
|
|
|
|
2016-08-30 10:39:09 +02:00
|
|
|
bpy.utils.unregister_class(BlenderCloudProjectGroup)
|
2016-03-18 16:53:52 +01:00
|
|
|
bpy.utils.unregister_class(PillarCredentialsUpdate)
|
|
|
|
bpy.utils.unregister_class(BlenderCloudPreferences)
|
2016-06-23 19:00:47 +02:00
|
|
|
bpy.utils.unregister_class(SyncStatusProperties)
|
2016-06-24 15:22:12 +02:00
|
|
|
bpy.utils.unregister_class(PILLAR_OT_subscribe)
|
2016-08-26 17:43:20 +02:00
|
|
|
bpy.utils.unregister_class(PILLAR_OT_projects)
|
2018-01-02 16:42:52 +01:00
|
|
|
bpy.utils.unregister_class(PILLAR_OT_project_open_in_browser)
|
2016-07-20 16:54:06 +02:00
|
|
|
bpy.utils.unregister_class(PILLAR_PT_image_custom_properties)
|
2016-03-18 16:53:52 +01:00
|
|
|
|
2016-06-23 19:00:47 +02:00
|
|
|
del WindowManager.last_blender_cloud_location
|
|
|
|
del WindowManager.blender_sync_status
|