Give users the option to open a webbrowser after sharing an image.
The addon now also uses the home project URL from the project itself, rather than hard-coding it.
This commit is contained in:
parent
4762f0292d
commit
3c9e4e2873
@ -7,7 +7,7 @@ import logging
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
from bpy.types import AddonPreferences, Operator, WindowManager, Scene, PropertyGroup
|
from bpy.types import AddonPreferences, Operator, WindowManager, Scene, PropertyGroup
|
||||||
from bpy.props import StringProperty, EnumProperty, PointerProperty
|
from bpy.props import StringProperty, EnumProperty, PointerProperty, BoolProperty
|
||||||
|
|
||||||
from . import pillar, gui
|
from . import pillar, gui
|
||||||
|
|
||||||
@ -101,6 +101,12 @@ class BlenderCloudPreferences(AddonPreferences):
|
|||||||
subtype='DIR_PATH',
|
subtype='DIR_PATH',
|
||||||
default='//textures')
|
default='//textures')
|
||||||
|
|
||||||
|
open_browser_after_share = BoolProperty(
|
||||||
|
name='Open browser after sharing file',
|
||||||
|
description='When enabled, Blender will open a webbrowser',
|
||||||
|
default=True
|
||||||
|
)
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
@ -177,6 +183,12 @@ class BlenderCloudPreferences(AddonPreferences):
|
|||||||
else:
|
else:
|
||||||
self.draw_sync_buttons(sub, bss)
|
self.draw_sync_buttons(sub, bss)
|
||||||
|
|
||||||
|
# Image Share stuff
|
||||||
|
share_box = layout.box()
|
||||||
|
share_box.label('Image Sharing on Blender Cloud')
|
||||||
|
texture_box.enabled = icon != 'ERROR'
|
||||||
|
share_box.prop(self, 'open_browser_after_share')
|
||||||
|
|
||||||
def draw_subscribe_button(self, layout):
|
def draw_subscribe_button(self, layout):
|
||||||
layout.operator('pillar.subscribe', icon='WORLD')
|
layout.operator('pillar.subscribe', icon='WORLD')
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import pillarsdk
|
|||||||
from pillarsdk import exceptions as sdk_exceptions
|
from pillarsdk import exceptions as sdk_exceptions
|
||||||
from .pillar import pillar_call
|
from .pillar import pillar_call
|
||||||
from . import async_loop, pillar, home_project
|
from . import async_loop, pillar, home_project
|
||||||
from .blender import PILLAR_WEB_SERVER_URL
|
from .blender import PILLAR_WEB_SERVER_URL, preferences
|
||||||
|
|
||||||
REQUIRES_ROLES_FOR_IMAGE_SHARING = {'subscriber', 'demo'}
|
REQUIRES_ROLES_FOR_IMAGE_SHARING = {'subscriber', 'demo'}
|
||||||
IMAGE_SHARING_GROUP_NODE_NAME = 'Image sharing'
|
IMAGE_SHARING_GROUP_NODE_NAME = 'Image sharing'
|
||||||
@ -45,6 +45,7 @@ class PILLAR_OT_image_share(pillar.PillarOperatorMixin,
|
|||||||
log = logging.getLogger('bpy.ops.%s' % bl_idname)
|
log = logging.getLogger('bpy.ops.%s' % bl_idname)
|
||||||
|
|
||||||
home_project_id = None
|
home_project_id = None
|
||||||
|
home_project_url = 'home'
|
||||||
share_group_id = None # top-level share group node ID
|
share_group_id = None # top-level share group node ID
|
||||||
user_id = None
|
user_id = None
|
||||||
|
|
||||||
@ -101,7 +102,9 @@ class PILLAR_OT_image_share(pillar.PillarOperatorMixin,
|
|||||||
|
|
||||||
# Find the home project.
|
# Find the home project.
|
||||||
try:
|
try:
|
||||||
self.home_project_id = await home_project.get_home_project_id()
|
home_proj = await home_project.get_home_project({
|
||||||
|
'projection': {'_id': 1, 'url': 1}
|
||||||
|
})
|
||||||
except sdk_exceptions.ForbiddenAccess:
|
except sdk_exceptions.ForbiddenAccess:
|
||||||
self.log.exception('Forbidden access to home project.')
|
self.log.exception('Forbidden access to home project.')
|
||||||
self.report({'ERROR'}, 'Did not get access to home project.')
|
self.report({'ERROR'}, 'Did not get access to home project.')
|
||||||
@ -112,6 +115,9 @@ class PILLAR_OT_image_share(pillar.PillarOperatorMixin,
|
|||||||
self._state = 'QUIT'
|
self._state = 'QUIT'
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.home_project_id = home_proj['_id']
|
||||||
|
self.home_project_url = home_proj['url']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
gid = await find_image_sharing_group_id(self.home_project_id,
|
gid = await find_image_sharing_group_id(self.home_project_id,
|
||||||
self.user_id)
|
self.user_id)
|
||||||
@ -152,12 +158,22 @@ class PILLAR_OT_image_share(pillar.PillarOperatorMixin,
|
|||||||
always_create_new_node=True,
|
always_create_new_node=True,
|
||||||
fileobj=fileobj,
|
fileobj=fileobj,
|
||||||
caching=False)
|
caching=False)
|
||||||
self.log.info('Created node %s', node['_id'])
|
node_id = node['_id']
|
||||||
|
self.log.info('Created node %s', node_id)
|
||||||
self.report({'INFO'}, 'File succesfully uploaded to the cloud!')
|
self.report({'INFO'}, 'File succesfully uploaded to the cloud!')
|
||||||
|
|
||||||
|
await self.maybe_open_browser(node_id)
|
||||||
|
|
||||||
|
async def maybe_open_browser(self, node_id):
|
||||||
|
prefs = preferences()
|
||||||
|
if not prefs.open_browser_after_share:
|
||||||
|
return
|
||||||
|
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
url = urllib.parse.urljoin(PILLAR_WEB_SERVER_URL, '/p/p-home/%s' % node['_id'])
|
|
||||||
|
url = urllib.parse.urljoin(PILLAR_WEB_SERVER_URL,
|
||||||
|
'/p/%s/%s' % (self.home_project_url, node_id))
|
||||||
self.log.info('Opening browser at %s', url)
|
self.log.info('Opening browser at %s', url)
|
||||||
webbrowser.open_new_tab(url)
|
webbrowser.open_new_tab(url)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user