Skip to content

Commit

Permalink
5.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
TeaM-TL committed Sep 30, 2024
1 parent 963471e commit 3109521
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 110 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 2024

5.0.5 remove redundand ask about platform - use constant, fix default font

5.0.4 fix load default font

5.0.3 compose and text conversion works with Pillow
Expand Down
58 changes: 33 additions & 25 deletions fotokilof/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
import ini_read
import ini_save
import magick
import mswindows
import version

# logger = logging.getLogger(__name__)
Expand All @@ -115,10 +114,18 @@
logging.info("Start: %s", start_time)
logging.info(IMAGEMAGICK_WAND_VERSION)

if mswindows.windows() or mswindows.macos():
if platform.system() == "Windows":
OS = "Windows"
elif platform.system() == "Darwin":
OS = "MACOS"
else:
OS = "UNIX"


if OS != "UNIX":
from PIL import ImageGrab
# set locale and clipboard for Windows
if mswindows.windows():
if OS == "Windows":
import locale

if os.getenv("LANG") is None:
Expand All @@ -135,7 +142,7 @@

###################
# CONSTANTS
if mswindows.windows() == 1:
if OS == "Windows":
PREVIEW_ORIG = 400 # preview original
PREVIEW_NEW = 400 # preview result
PREVIEW_COMPOSE = 400 # preview compose
Expand Down Expand Up @@ -228,7 +235,7 @@ def preview_new(file_out):
preview_new_clear()
else:
preview_picture = convert_common.preview(
file_out, int(co_preview_selector_new.get()), PILLOW
file_out, int(co_preview_selector_new.get()), PILLOW, OS
)
try:
pi_preview_new.configure(file=preview_picture["filename"])
Expand All @@ -249,7 +256,7 @@ def preview_new(file_out):
except:
logging.error("preview_new: Cannot read preview")

gui.copy_to_clipboard(file_out)
gui.copy_to_clipboard(file_out, OS)


def preview_orig_button():
Expand Down Expand Up @@ -321,7 +328,7 @@ def apply_all_button():
files_list = [file_in_path.get()]
else:
dirname = os.path.dirname(file_in_path.get())
files_list_short = common.list_of_images(dirname)
files_list_short = common.list_of_images(dirname, OS)
files_list = []
for filename_short in files_list_short:
files_list.append(os.path.join(dirname, filename_short))
Expand Down Expand Up @@ -478,7 +485,7 @@ def convert_custom_button():
file_in_path.get(), work_dir.get(), co_apply_type.get()
)
cmd = t_custom.get("1.0", "end-1c")
result = magick.magick(cmd, file_in_path.get(), out_file, "convert")
result = magick.magick(cmd, file_in_path.get(), out_file, "convert", OS)
if result == "OK":
preview_new(out_file)
progress_files.set(_("done"))
Expand Down Expand Up @@ -753,7 +760,7 @@ def convert_text_button():

def fonts():
"""preparing font names for ImageMagick or Pillow and load into listbox"""
result = convert_common.fonts_list(PILLOW)
result = convert_common.fonts_list(PILLOW, OS)
co_text_font["values"] = result
return result

Expand Down Expand Up @@ -864,7 +871,7 @@ def open_file_common(cwd, filename):

def open_file_dialog(dir_initial, title):
"""open file dialog function for image and logo"""
if mswindows.windows() == 1:
if OS == "Windows":
filetypes = (
(_("All graphics files"), ".JPG .JPEG .PNG .TIF .TIFF"),
(_("JPG files"), ".JPG .JPEG"),
Expand Down Expand Up @@ -901,7 +908,7 @@ def open_file_last():
if file_in_path.get():
if os.path.isfile(file_in_path.get()):
dir_name = os.path.dirname(file_in_path.get())
file_list = common.list_of_images(dir_name)
file_list = common.list_of_images(dir_name, OS)
current_file = os.path.basename(file_in_path.get())
filename = common.file_from_list_of_images(file_list, current_file, "last")
open_file_common(dir_name, filename)
Expand All @@ -917,7 +924,7 @@ def open_file_next():
if file_in_path.get():
if os.path.isfile(file_in_path.get()):
dir_name = os.path.dirname(file_in_path.get())
file_list = common.list_of_images(dir_name)
file_list = common.list_of_images(dir_name, OS)
current_file = os.path.basename(file_in_path.get())
filename = common.file_from_list_of_images(file_list, current_file, "next")
open_file_common(dir_name, filename)
Expand All @@ -933,7 +940,7 @@ def open_file_first():
if file_in_path.get():
if os.path.isfile(file_in_path.get()):
dir_name = os.path.dirname(file_in_path.get())
file_list = common.list_of_images(dir_name)
file_list = common.list_of_images(dir_name, OS)
current_file = os.path.basename(file_in_path.get())
filename = common.file_from_list_of_images(file_list, current_file, "first")
open_file_common(dir_name, filename)
Expand All @@ -949,7 +956,7 @@ def open_file_prev():
if file_in_path.get():
if os.path.isfile(file_in_path.get()):
dir_name = os.path.dirname(file_in_path.get())
file_list = common.list_of_images(dir_name)
file_list = common.list_of_images(dir_name, OS)
current_file = os.path.basename(file_in_path.get())
filename = common.file_from_list_of_images(
file_list, current_file, "previous"
Expand All @@ -971,18 +978,18 @@ def open_screenshot():
filename = now.strftime("%F_%H-%M-%S_%f") + ".png"
out_file = os.path.normpath(os.path.join(today_dir, filename))
do_it = 1
if mswindows.windows() or mswindows.macos():
screenshot = ImageGrab.grabclipboard()
if OS == "UNIX":
try:
screenshot.save(out_file, "PNG")
magick.magick(" ", "-quiet", out_file, "import", OS)
except:
logging.error("open_screenshot(), error save from clipboards")
logging.error("open_screenshot(), error in make screeshot ")
do_it = 0
else:
screenshot = ImageGrab.grabclipboard()
try:
magick.magick(" ", "-quiet", out_file, "import")
screenshot.save(out_file, "PNG")
except:
logging.error("open_screenshot(), error in make screeshot ")
logging.error("open_screenshot(), error save from clipboards")
do_it = 0
if do_it:
open_file_common(today_dir, filename)
Expand Down Expand Up @@ -1082,7 +1089,7 @@ def ini_read_wraper():
e2_resize.delete(0, "end")
e2_resize.insert(0, ini_entries["resize_size_percent"])
# text
ini_entries = ini_read.text(FILE_INI, img_text_font_dict)
ini_entries = ini_read.text(FILE_INI, img_text_font_dict, OS)
img_text_on.set(ini_entries["img_text_on"])
img_text_inout.set(ini_entries["img_text_inout"])
img_text_font.set(ini_entries["text_font"])
Expand Down Expand Up @@ -1517,6 +1524,7 @@ def preview_orig():
file_in_path.get(),
int(co_preview_selector_orig.get()),
PILLOW,
OS,
crop_rectangle,
)

Expand Down Expand Up @@ -1551,7 +1559,7 @@ def preview_logo():
if os.path.isfile(file_logo_path.get()):
l_logo_filename.configure(text=os.path.basename(file_logo_path.get()))
preview_picture = convert_common.preview(
file_logo_path.get(), PREVIEW_LOGO, PILLOW
file_logo_path.get(), PREVIEW_LOGO, PILLOW, OS
)

try:
Expand All @@ -1578,7 +1586,7 @@ def preview_compose():
if os.path.isfile(img_compose_file.get()):
# l_compose_preview.configure(text=os.path.basename(img_compose_file.get()))
preview_picture = convert_common.preview(
img_compose_file.get(), int(co_compose_preview_selector.get()), PILLOW
img_compose_file.get(), int(co_compose_preview_selector.get()), PILLOW, OS
)

try:
Expand Down Expand Up @@ -1982,7 +1990,7 @@ def text_tool_hide_show():
b_file_select_screenshot = ttk.Button(
frame_file_select, text=_("Screenshot"), command=open_screenshot, bootstyle="info"
)
if mswindows.windows() or mswindows.macos():
if OS != "UNIX":
b_file_select_screenshot.configure(text=_("Clipboard"))

b_file_select_first = ttk.Button(
Expand Down Expand Up @@ -3131,7 +3139,7 @@ def text_tool_hide_show():
co_compose_preview_selector.bind("<<ComboboxSelected>>", preview_compose_refresh)
co_text_font.bind("<<ComboboxSelected>>", font_selected)
c_preview_orig_pi.bind("<Button-1>", mouse_crop_nw)
if mswindows.macos():
if OS == "MACOS":
c_preview_orig_pi.bind("<Button-2>", mouse_crop_se)
else:
c_preview_orig_pi.bind("<Button-3>", mouse_crop_se)
Expand Down
10 changes: 4 additions & 6 deletions fotokilof/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import os
import re

import mswindows


def resize_subdir(resize_vatiant, pixel_x, pixel_y, percent):
"""prepare name for subdir and command for resize"""
Expand Down Expand Up @@ -113,13 +111,13 @@ def mouse_crop_calculation(x_orig, y_orig, size):
return dict_return


def spacja(file_path):
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 mswindows.windows():
if operating_system == 'Windows':
czy_spacja = re.search(" ", file_path)
if czy_spacja is not None:
file_path = '"' + file_path + '"'
Expand Down Expand Up @@ -198,7 +196,7 @@ def crop_gravity(coordinates, x_max, y_max):
return (x0, y0, x1, y1)


def list_of_images(cwd):
def list_of_images(cwd, operating_system):
"""
jpg, png and tiff images in cwd
return sorted list
Expand All @@ -207,7 +205,7 @@ def list_of_images(cwd):
list_of_files = os.listdir(cwd)
file_list = []
patterns = ("*.JPG", "*.JPEG", "*.PNG", "*.TIF", "*.TIFF")
if not mswindows.windows():
if operating_system != 'Windows':
patterns = patterns + ("*.jpg", "*.jpeg", "*.png", "*.tif", "*.tiff")

for pattern in patterns:
Expand Down
10 changes: 5 additions & 5 deletions fotokilof/convert_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@
module_logger.info(WAND_TEXT)


def fonts_list(set_pillow):
def fonts_list(set_pillow, operating_system):
"""list of available fonts"""
start_time = time.time()
if set_pillow:
result = convert_pillow.fonts_list()
result = convert_pillow.fonts_list(operating_system)
else:
result = convert_wand.fonts_list()
module_logger.info("Get fonts list: %ss", str(time.time() - start_time))
Expand Down Expand Up @@ -109,13 +109,13 @@ def get_image_size(file_in, set_pillow):
return size


def preview(file_logo, size, set_pillow, coord=""):
def preview(file_logo, size, set_pillow, operating_system, coord=""):
"""preview"""
start_time = time.time()
if set_pillow:
result = convert_pillow.preview(file_logo, size, coord)
result = convert_pillow.preview(file_logo, size, operating_system, coord)
else:
result = convert_wand.preview(file_logo, size, coord)
result = convert_wand.preview(file_logo, size, operating_system, coord)
module_logger.info("preview: %s s", str(time.time() - start_time))
return result

Expand Down
13 changes: 7 additions & 6 deletions fotokilof/convert_pillow.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
import tempfile
import os
import os.path
import platform
from PIL import Image, ImageDraw, ImageOps, ImageFont

# my modules
import common
import mswindows

if not mswindows.windows():
if platform.system() != "Windows":
from fclist import fclist

module_logger = logging.getLogger(__name__)
Expand All @@ -65,10 +65,10 @@ def version():
return Image.__version__


def fonts_list():
def fonts_list(operating_system):
"""list of available fonts"""
result = []
if mswindows.windows():
if operating_system == 'Windows':
paths = [
os.path.join(os.environ["WINDIR"], "fonts"),
os.path.join(os.path.expanduser("~"))
Expand Down Expand Up @@ -588,11 +588,12 @@ def compose(clone, compose_file, right, autoresize, color, gravity):


# ------------------------------------ Preview
def preview(file_in, max_size, coord=""):
def preview(file_in, max_size, operating_system, coord=""):
"""
preview generation by Pillow
file_in - fullname image file
max_size - required size of image
operating_system - operating system: Windows, MACOS, UNIX
coord - coordinates for crop
--
return:
Expand Down Expand Up @@ -642,7 +643,7 @@ def preview(file_in, max_size, coord=""):
file_preview = os.path.join(tempfile.gettempdir(), "fotokilof_preview.ppm")
save_close_clone(clone, file_preview)
result = {
"filename": common.spacja(file_preview),
"filename": common.spacja(file_preview, operating_system),
"size": filesize,
"width": str(width),
"height": str(height),
Expand Down
5 changes: 3 additions & 2 deletions fotokilof/convert_wand.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,12 @@ def compose(clone, compose_file, right, autoresize, color, gravity):


# ------------------------------------ Preview
def preview(file_in, size, coord=""):
def preview(file_in, size, operating_system, coord=""):
"""
preview generation by Wand
file_in - fullname image file
size - required size of image
os - operating system: Windows, MACOS, UNIX
coord - coordinates for crop
--
return:
Expand Down Expand Up @@ -534,7 +535,7 @@ def preview(file_in, size, coord=""):
file_preview = os.path.join(tempfile.gettempdir(), "fotokilof_preview.ppm")
save_close_clone(clone, file_preview)
result = {
"filename": common.spacja(file_preview),
"filename": common.spacja(file_preview, operating_system),
"size": filesize,
"width": str(width),
"height": str(height),
Expand Down
Loading

0 comments on commit 3109521

Please sign in to comment.