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:
Sybren A. Stüvel 2016-07-07 11:43:01 +02:00
parent 4762f0292d
commit 3c9e4e2873
2 changed files with 33 additions and 5 deletions

View File

@ -7,7 +7,7 @@ import logging
import bpy
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
@ -101,6 +101,12 @@ class BlenderCloudPreferences(AddonPreferences):
subtype='DIR_PATH',
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):
import textwrap
@ -177,6 +183,12 @@ class BlenderCloudPreferences(AddonPreferences):
else:
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):
layout.operator('pillar.subscribe', icon='WORLD')

View File

@ -7,7 +7,7 @@ import pillarsdk
from pillarsdk import exceptions as sdk_exceptions
from .pillar import pillar_call
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'}
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)
home_project_id = None
home_project_url = 'home'
share_group_id = None # top-level share group node ID
user_id = None
@ -101,7 +102,9 @@ class PILLAR_OT_image_share(pillar.PillarOperatorMixin,
# Find the home project.
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:
self.log.exception('Forbidden 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'
return
self.home_project_id = home_proj['_id']
self.home_project_url = home_proj['url']
try:
gid = await find_image_sharing_group_id(self.home_project_id,
self.user_id)
@ -152,12 +158,22 @@ class PILLAR_OT_image_share(pillar.PillarOperatorMixin,
always_create_new_node=True,
fileobj=fileobj,
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!')
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 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)
webbrowser.open_new_tab(url)