Compare commits

..

4 Commits

Author SHA1 Message Date
53ab2fc6df Bumped version to 1.3.1 2016-07-14 11:50:19 +02:00
1e2c74e82d Made screenshot the default target for image sharing.
This way the spacebar-menu takes a screenshot of the current area and
shares it. The other targets need a 'name' property set, so those won't
work from the spacebar-menu anyway.

I also added some extra options for the screenshotting, to mirror the
bpy.ops.screen.screenshot() operator options.

The full-window screenshot operator is now also placed in the Window menu.
2016-07-14 11:49:30 +02:00
ecb8f8575f Added missing logger 2016-07-14 11:47:50 +02:00
acd62b4917 Added screenshot functionality 2016-07-14 11:13:09 +02:00
4 changed files with 58 additions and 7 deletions

View File

@@ -21,7 +21,7 @@
bl_info = { bl_info = {
'name': 'Blender Cloud', 'name': 'Blender Cloud',
'author': 'Sybren A. Stüvel and Francesco Siddi', 'author': 'Sybren A. Stüvel and Francesco Siddi',
'version': (1, 3, 0), 'version': (1, 3, 1),
'blender': (2, 77, 0), 'blender': (2, 77, 0),
'location': 'Addon Preferences panel, and Ctrl+Shift+Alt+A anywhere for texture browser', 'location': 'Addon Preferences panel, and Ctrl+Shift+Alt+A anywhere for texture browser',
'description': 'Texture library browser and Blender Sync. Requires the Blender ID addon ' 'description': 'Texture library browser and Blender Sync. Requires the Blender ID addon '

View File

@@ -230,6 +230,8 @@ class PillarCredentialsUpdate(pillar.PillarOperatorMixin,
bl_idname = 'pillar.credentials_update' bl_idname = 'pillar.credentials_update'
bl_label = 'Update credentials' bl_label = 'Update credentials'
log = logging.getLogger('bpy.ops.%s' % bl_idname)
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
# Only allow activation when the user is actually logged in. # Only allow activation when the user is actually logged in.

View File

@@ -1,6 +1,7 @@
import logging import logging
import os.path import os.path
import tempfile import tempfile
import datetime
import bpy import bpy
import pillarsdk import pillarsdk
@@ -38,7 +39,7 @@ class PILLAR_OT_image_share(pillar.PillarOperatorMixin,
async_loop.AsyncModalOperatorMixin, async_loop.AsyncModalOperatorMixin,
bpy.types.Operator): bpy.types.Operator):
bl_idname = 'pillar.image_share' 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' bl_description = 'Uploads an image for sharing via Blender Cloud'
log = logging.getLogger('bpy.ops.%s' % bl_idname) log = logging.getLogger('bpy.ops.%s' % bl_idname)
@@ -50,19 +51,39 @@ class PILLAR_OT_image_share(pillar.PillarOperatorMixin,
target = bpy.props.EnumProperty( target = bpy.props.EnumProperty(
items=[ items=[
('FILE', 'File', 'Upload an image file'), ('FILE', 'File', 'Share an image file'),
('DATABLOCK', 'Datablock', 'Upload an image datablock'), ('DATABLOCK', 'Datablock', 'Share an image datablock'),
('SCREENSHOT', 'Screenshot', 'Share a screenshot'),
], ],
name='target', name='target',
default='DATABLOCK') default='SCREENSHOT')
name = bpy.props.StringProperty(name='name', name = bpy.props.StringProperty(name='name',
description='File or datablock name to sync') 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): def invoke(self, context, event):
# Do a quick test on datablock dirtyness. If it's not packed and dirty, # Do a quick test on datablock dirtyness. If it's not packed and dirty,
# the user should save it first. # the user should save it first.
if self.target == 'DATABLOCK': 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] datablock = bpy.data.images[self.name]
if datablock.type == 'IMAGE' and datablock.is_dirty and not datablock.packed_file: if datablock.type == 'IMAGE' and datablock.is_dirty and not datablock.packed_file:
self.report({'ERROR'}, 'Datablock is dirty, save it first.') 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): async def share_image(self, context):
"""Sends files to the Pillar server.""" """Sends files to the Pillar server."""
self.report({'INFO'}, "Uploading %s '%s'" % (self.target.lower(), self.name))
if self.target == 'FILE': if self.target == 'FILE':
self.report({'INFO'}, "Uploading %s '%s'" % (self.target.lower(), self.name))
node = await self.upload_file(self.name) node = await self.upload_file(self.name)
elif self.target == 'SCREENSHOT':
node = await self.upload_screenshot(context)
else: else:
self.report({'INFO'}, "Uploading %s '%s'" % (self.target.lower(), self.name))
node = await self.upload_datablock(context) node = await self.upload_datablock(context)
self.report({'INFO'}, 'Upload complete, creating link to share.') 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) self.log.info('Uploading packed file directly from memory to %r.', filename)
return await self.upload_file(filename, fileobj=fileobj) 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): def image_editor_menu(self, context):
image = context.space_data.image image = context.space_data.image
@@ -262,13 +301,23 @@ def image_editor_menu(self, context):
props.name = image.name 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(): def register():
bpy.utils.register_class(PILLAR_OT_image_share) bpy.utils.register_class(PILLAR_OT_image_share)
bpy.types.IMAGE_HT_header.append(image_editor_menu) bpy.types.IMAGE_HT_header.append(image_editor_menu)
bpy.types.INFO_MT_window.append(window_menu)
def unregister(): def unregister():
bpy.utils.unregister_class(PILLAR_OT_image_share) bpy.utils.unregister_class(PILLAR_OT_image_share)
bpy.types.IMAGE_HT_header.remove(image_editor_menu) bpy.types.IMAGE_HT_header.remove(image_editor_menu)
bpy.types.INFO_MT_window.remove(window_menu)

View File

@@ -179,7 +179,7 @@ setup(
'wheels': BuildWheels}, 'wheels': BuildWheels},
name='blender_cloud', name='blender_cloud',
description='The Blender Cloud addon allows browsing the Blender Cloud from Blender.', description='The Blender Cloud addon allows browsing the Blender Cloud from Blender.',
version='1.3.0', version='1.3.1',
author='Sybren A. Stüvel', author='Sybren A. Stüvel',
author_email='sybren@stuvel.eu', author_email='sybren@stuvel.eu',
packages=find_packages('.'), packages=find_packages('.'),