From fc670c763366c755dfaa030f6aba023c49df9240 Mon Sep 17 00:00:00 2001 From: TLu Date: Tue, 1 Oct 2024 23:35:36 +0200 Subject: [PATCH] space --- fotokilof/common.py | 21 +++++++-------------- fotokilof/gui.py | 7 +++++-- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/fotokilof/common.py b/fotokilof/common.py index b566696..5acd289 100644 --- a/fotokilof/common.py +++ b/fotokilof/common.py @@ -33,7 +33,9 @@ """ import fnmatch +from pathlib import PurePosixPath, PureWindowsPath import os +import os.path import re @@ -113,22 +115,13 @@ def mouse_crop_calculation(x_orig, y_orig, size): def spacja(file_path, operating_system): """escaping space and special char in pathname""" - if len(file_path) == 0: - result = file_path - else: - file_path = os.path.normpath(file_path) + if len(file_path): if operating_system == 'Windows': - czy_spacja = re.search(" ", file_path) - if czy_spacja is not None: - file_path = '"' + file_path + '"' + result = PureWindowsPath(os.path.normpath(file_path)) else: - path = os.path.splitext(file_path) - path_splitted = path[0].split("/") - path_escaped = [] - for i in path_splitted: - path_escaped.append(re.escape(i)) - file_path = "/".join(path_escaped) + path[1] - result = file_path + result = PurePosixPath(os.path.normpath(file_path)) + else: + result = None return result diff --git a/fotokilof/gui.py b/fotokilof/gui.py index 0b97b90..ff298fa 100644 --- a/fotokilof/gui.py +++ b/fotokilof/gui.py @@ -32,11 +32,14 @@ import re from PIL import Image +import common + if platform.system() == 'Windows': import win32clipboard elif platform.system() == 'Darwin': import subprocess + module_logger = logging.getLogger(__name__) @@ -48,7 +51,7 @@ def copy_to_clipboard(file_in, operating_system): https://stackoverflow.com/questions/54008175/copy-an-image-to-macos-clipboard-using-python?rq=4 debug needed! """ - image = Image.open(file_in) + image = Image.open(common.spacja(file_in, operating_system)) # Create an in-memory file-like object image_buffer = BytesIO() if operating_system == 'Windows': @@ -67,7 +70,7 @@ def copy_to_clipboard(file_in, operating_system): "osascript", "-e", 'set the clipboard to (read (POSIX file "' - + file_in + + common.spacja(file_in, operating_system) + '") as JPEG picture)', ] )