Added screenshot functionality
This commit is contained in:
parent
65faeba7b0
commit
acd62b4917
@ -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
|
||||||
@ -50,8 +51,9 @@ 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='DATABLOCK')
|
||||||
@ -59,6 +61,11 @@ class PILLAR_OT_image_share(pillar.PillarOperatorMixin,
|
|||||||
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_full = bpy.props.BoolProperty(
|
||||||
|
name='screenshot_full',
|
||||||
|
description='Full Screen, Capture the whole window (otherwise only capture the active area)',
|
||||||
|
default=True)
|
||||||
|
|
||||||
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.
|
||||||
@ -141,6 +148,8 @@ class PILLAR_OT_image_share(pillar.PillarOperatorMixin,
|
|||||||
self.report({'INFO'}, "Uploading %s '%s'" % (self.target.lower(), self.name))
|
self.report({'INFO'}, "Uploading %s '%s'" % (self.target.lower(), self.name))
|
||||||
if self.target == 'FILE':
|
if self.target == 'FILE':
|
||||||
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:
|
||||||
node = await self.upload_datablock(context)
|
node = await self.upload_datablock(context)
|
||||||
|
|
||||||
@ -245,6 +254,17 @@ 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."""
|
||||||
|
|
||||||
|
filename_on_cloud = datetime.datetime.now().strftime('Screenshot-%Y-%m-%d-%H:%M:%S.png')
|
||||||
|
|
||||||
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
|
filepath = os.path.join(tmpdir, filename_on_cloud)
|
||||||
|
self.log.debug('Saving screenshot to %s', filepath)
|
||||||
|
bpy.ops.screen.screenshot(filepath=filepath, 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
|
||||||
|
Reference in New Issue
Block a user