|
|
|
@@ -1,6 +1,7 @@
|
|
|
|
|
import logging
|
|
|
|
|
import os.path
|
|
|
|
|
import tempfile
|
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
|
|
import bpy
|
|
|
|
|
import pillarsdk
|
|
|
|
@@ -38,7 +39,7 @@ class PILLAR_OT_image_share(pillar.PillarOperatorMixin,
|
|
|
|
|
async_loop.AsyncModalOperatorMixin,
|
|
|
|
|
bpy.types.Operator):
|
|
|
|
|
bl_idname = 'pillar.image_share'
|
|
|
|
|
bl_label = 'Share an image via Blender Cloud'
|
|
|
|
|
bl_label = 'Share an image/screenshot via Blender Cloud'
|
|
|
|
|
bl_description = 'Uploads an image for sharing via Blender Cloud'
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger('bpy.ops.%s' % bl_idname)
|
|
|
|
@@ -50,19 +51,39 @@ class PILLAR_OT_image_share(pillar.PillarOperatorMixin,
|
|
|
|
|
|
|
|
|
|
target = bpy.props.EnumProperty(
|
|
|
|
|
items=[
|
|
|
|
|
('FILE', 'File', 'Upload an image file'),
|
|
|
|
|
('DATABLOCK', 'Datablock', 'Upload an image datablock'),
|
|
|
|
|
('FILE', 'File', 'Share an image file'),
|
|
|
|
|
('DATABLOCK', 'Datablock', 'Share an image datablock'),
|
|
|
|
|
('SCREENSHOT', 'Screenshot', 'Share a screenshot'),
|
|
|
|
|
],
|
|
|
|
|
name='target',
|
|
|
|
|
default='DATABLOCK')
|
|
|
|
|
default='SCREENSHOT')
|
|
|
|
|
|
|
|
|
|
name = bpy.props.StringProperty(name='name',
|
|
|
|
|
description='File or datablock name to sync')
|
|
|
|
|
|
|
|
|
|
screenshot_show_multiview = bpy.props.BoolProperty(
|
|
|
|
|
name='screenshot_show_multiview',
|
|
|
|
|
description='Enable Multi-View',
|
|
|
|
|
default=False)
|
|
|
|
|
|
|
|
|
|
screenshot_use_multiview = bpy.props.BoolProperty(
|
|
|
|
|
name='screenshot_use_multiview',
|
|
|
|
|
description='Use Multi-View',
|
|
|
|
|
default=False)
|
|
|
|
|
|
|
|
|
|
screenshot_full = bpy.props.BoolProperty(
|
|
|
|
|
name='screenshot_full',
|
|
|
|
|
description='Full Screen, Capture the whole window (otherwise only capture the active area)',
|
|
|
|
|
default=False)
|
|
|
|
|
|
|
|
|
|
def invoke(self, context, event):
|
|
|
|
|
# Do a quick test on datablock dirtyness. If it's not packed and dirty,
|
|
|
|
|
# the user should save it first.
|
|
|
|
|
if self.target == 'DATABLOCK':
|
|
|
|
|
if not self.name:
|
|
|
|
|
self.report({'ERROR'}, 'No name given of the datablock to share.')
|
|
|
|
|
return {'CANCELLED'}
|
|
|
|
|
|
|
|
|
|
datablock = bpy.data.images[self.name]
|
|
|
|
|
if datablock.type == 'IMAGE' and datablock.is_dirty and not datablock.packed_file:
|
|
|
|
|
self.report({'ERROR'}, 'Datablock is dirty, save it first.')
|
|
|
|
@@ -138,10 +159,13 @@ class PILLAR_OT_image_share(pillar.PillarOperatorMixin,
|
|
|
|
|
async def share_image(self, context):
|
|
|
|
|
"""Sends files to the Pillar server."""
|
|
|
|
|
|
|
|
|
|
self.report({'INFO'}, "Uploading %s '%s'" % (self.target.lower(), self.name))
|
|
|
|
|
if self.target == 'FILE':
|
|
|
|
|
self.report({'INFO'}, "Uploading %s '%s'" % (self.target.lower(), self.name))
|
|
|
|
|
node = await self.upload_file(self.name)
|
|
|
|
|
elif self.target == 'SCREENSHOT':
|
|
|
|
|
node = await self.upload_screenshot(context)
|
|
|
|
|
else:
|
|
|
|
|
self.report({'INFO'}, "Uploading %s '%s'" % (self.target.lower(), self.name))
|
|
|
|
|
node = await self.upload_datablock(context)
|
|
|
|
|
|
|
|
|
|
self.report({'INFO'}, 'Upload complete, creating link to share.')
|
|
|
|
@@ -245,6 +269,21 @@ class PILLAR_OT_image_share(pillar.PillarOperatorMixin,
|
|
|
|
|
self.log.info('Uploading packed file directly from memory to %r.', filename)
|
|
|
|
|
return await self.upload_file(filename, fileobj=fileobj)
|
|
|
|
|
|
|
|
|
|
async def upload_screenshot(self, context) -> pillarsdk.Node:
|
|
|
|
|
"""Takes a screenshot, saves it to a temp file, and uploads it."""
|
|
|
|
|
|
|
|
|
|
self.name = datetime.datetime.now().strftime('Screenshot-%Y-%m-%d-%H:%M:%S.png')
|
|
|
|
|
self.report({'INFO'}, "Uploading %s '%s'" % (self.target.lower(), self.name))
|
|
|
|
|
|
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
|
|
|
filepath = os.path.join(tmpdir, self.name)
|
|
|
|
|
self.log.debug('Saving screenshot to %s', filepath)
|
|
|
|
|
bpy.ops.screen.screenshot(filepath=filepath,
|
|
|
|
|
show_multiview=self.screenshot_show_multiview,
|
|
|
|
|
use_multiview=self.screenshot_use_multiview,
|
|
|
|
|
full=self.screenshot_full)
|
|
|
|
|
return await self.upload_file(filepath)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def image_editor_menu(self, context):
|
|
|
|
|
image = context.space_data.image
|
|
|
|
@@ -262,13 +301,23 @@ def image_editor_menu(self, context):
|
|
|
|
|
props.name = image.name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def window_menu(self, context):
|
|
|
|
|
props = self.layout.operator(PILLAR_OT_image_share.bl_idname,
|
|
|
|
|
text='Share screenshot via Blender Cloud',
|
|
|
|
|
icon_value=blender.icon('CLOUD'))
|
|
|
|
|
props.target = 'SCREENSHOT'
|
|
|
|
|
props.screenshot_full = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def register():
|
|
|
|
|
bpy.utils.register_class(PILLAR_OT_image_share)
|
|
|
|
|
|
|
|
|
|
bpy.types.IMAGE_HT_header.append(image_editor_menu)
|
|
|
|
|
bpy.types.IMAGE_MT_image.append(image_editor_menu)
|
|
|
|
|
bpy.types.INFO_MT_window.append(window_menu)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def unregister():
|
|
|
|
|
bpy.utils.unregister_class(PILLAR_OT_image_share)
|
|
|
|
|
|
|
|
|
|
bpy.types.IMAGE_HT_header.remove(image_editor_menu)
|
|
|
|
|
bpy.types.IMAGE_MT_image.remove(image_editor_menu)
|
|
|
|
|
bpy.types.INFO_MT_window.remove(window_menu)
|
|
|
|
|