-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import bpy | ||
import time | ||
import os | ||
import subprocess | ||
|
||
try: | ||
from . import pasteboard_py37 as pasteboard | ||
except ImportError: | ||
from . import pasteboard_py39 as pasteboard | ||
|
||
|
||
# Check if clipboard doesn't contain any file paths | ||
def no_furls(): | ||
script = [ | ||
"osascript", | ||
"-e", | ||
'((clipboard info) as string does not contain "«class furl»") as string', | ||
] | ||
popen = subprocess.Popen(script, stdout=subprocess.PIPE) | ||
return popen.communicate()[0].decode("utf-8").strip() == "true" | ||
|
||
|
||
# Save image data directly from clipboard | ||
def save_clipboard(fullpath): | ||
commands = [ | ||
f'set pastedImage to (open for access POSIX file "{fullpath}" with write permission)', | ||
"try", | ||
" write (the clipboard as «class PNGf») to pastedImage", | ||
"end try", | ||
"close access pastedImage", | ||
] | ||
script = ["osascript"] | ||
for command in commands: | ||
script += ["-e", command] | ||
subprocess.Popen(script).wait() | ||
|
||
|
||
def GrabImage(): | ||
|
||
timestamp = time.strftime("%y%m%d-%H%M%S") | ||
img_name = f"PastedImage{timestamp}.png" | ||
|
||
bpy_addon_prefs = bpy.context.preferences.addons[ | ||
__package__.split(".")[0] | ||
].preferences | ||
|
||
if bpy.data.filepath and bpy_addon_prefs.force_default_dir is False: | ||
Directory = os.path.join(os.path.split(bpy.data.filepath)[0], "ImagePaste") | ||
|
||
if os.path.isdir(Directory) is False: | ||
os.mkdir(Directory) | ||
|
||
else: | ||
Directory = bpy_addon_prefs.default_img_dir | ||
|
||
img_dir = os.path.join(Directory, img_name) | ||
|
||
pb = pasteboard.Pasteboard() | ||
urls = pb.get_file_urls() | ||
contents = pb.get_contents() | ||
|
||
if urls is not None: | ||
urls = list(urls) | ||
img_dir = urls | ||
img_name = [os.path.basename(current) for current in img_dir] | ||
return img_dir, img_name | ||
elif contents == "": | ||
return 0 | ||
else: | ||
if no_furls(): | ||
save_clipboard(img_dir) | ||
return [img_dir], [img_name] | ||
|
||
return 1 | ||
|
||
|
||
# Function to copy image from given path to clipboard | ||
def CopyImage(img_path): | ||
script = [ | ||
"osascript", | ||
"-e", | ||
f'set the clipboard to (read file POSIX file "{img_path}" as «class PNGf»)', | ||
] | ||
subprocess.Popen(script).wait() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Pasteboard - Python interface for reading from NSPasteboard (macOS clipboard) | ||
# Copyright (C) 2017-2021 Toby Fleming | ||
# This Source Code Form is subject to the terms of the Mozilla Public License, | ||
# v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
# obtain one at https://mozilla.org/MPL/2.0/. | ||
import sys as _sys | ||
|
||
assert _sys.platform == "darwin", "pasteboard only works on macOS" | ||
|
||
from ._native import * | ||
|
||
|
||
class PasteboardType: | ||
"""Make type hints not fail on import - don't use this class""" | ||
|
||
pass |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Pasteboard - Python interface for reading from NSPasteboard (macOS clipboard) | ||
# Copyright (C) 2017-2021 Toby Fleming | ||
# This Source Code Form is subject to the terms of the Mozilla Public License, | ||
# v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
# obtain one at https://mozilla.org/MPL/2.0/. | ||
import sys as _sys | ||
|
||
assert _sys.platform == "darwin", "pasteboard only works on macOS" | ||
|
||
from ._native import * | ||
|
||
|
||
class PasteboardType: | ||
"""Make type hints not fail on import - don't use this class""" | ||
|
||
pass |
Binary file not shown.