Skip to content

Commit

Permalink
2.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
TeaM-TL committed Oct 30, 2019
1 parent 01e7bc7 commit 3d1692e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
12 changes: 12 additions & 0 deletions src/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
import mswindows


def humansize(nbytes):
""" convert size in Byte into human readable: kB, MB, GB
https://stackoverflow.com/questions/14996453/python-libraries-to-calculate-human-readable-filesize-from-bytes """
suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
i = 0
while nbytes >= 1024 and i < len(suffixes)-1:
nbytes /= 1024.
i += 1
f = ('%.2f' % nbytes).rstrip('0').rstrip('.')
return '%s %s' % (f, suffixes[i])


def check_command():
"""
What is available: ImageMagick, Graphick Magick or none
Expand Down
1 change: 0 additions & 1 deletion src/entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def parse_color(entry, default):
result = entry
else:
result = default
print(entry, default, result)
return result

# EOF
28 changes: 16 additions & 12 deletions src/fotokilof.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

###################
# CONSTANTS
VERSION = "2.9.1"
VERSION = "2.9.2"
if mswindows.windows() == 1:
PREVIEW_ORIG = 400 # preview original
PREVIEW_NEW = 400 # preview result
Expand Down Expand Up @@ -100,7 +100,9 @@ def preview_new(file_out, dir_temp):
try:
pi_preview_new.configure(file=preview_picture['filename'])
l_preview_new.configure(text=preview_picture['width'] + "x" \
+ preview_picture['height'])
+ preview_picture['height'] \
+ " - " \
+ preview_picture['size'])
except:
print("! Error in preview_new: Nie można wczytać podglądu")

Expand Down Expand Up @@ -245,25 +247,24 @@ def apply_all_button():
if result == "OK":
preview_new(out_file, TEMP_DIR)
else:
pwd = os.getcwd()
os.chdir(os.path.dirname(file_in_path.get()))
dirname = os.path.dirname(file_in_path.get())
i = 0
files_list = glob.glob("*.[j|J][p|P][g|G]")
files_list = glob.glob(os.path.join(dirname, "*.[j|J][p|P][g|G]"))
file_list_len = len(files_list)
pb['maximum'] = file_list_len
pb['mode'] = "determinate"
for files in glob.glob("*.[j|J][p|P][g|G]"):
out_file = magick.pre_magick(files, work_dir.get())
result = apply_all_convert(os.path.realpath(out_file), 0)
for file in files_list: # glob.glob("*.[j|J][p|P][g|G]"):
out_file = magick.pre_magick(os.path.realpath(file), work_dir.get())
result = apply_all_convert(out_file, 0)
i = i + 1
progress_files.set(str(i) + " " + _("of") + " " \
+ str(file_list_len) + " : " + files)
+ str(file_list_len) + " : " \
+ os.path.basename(file))
progress_var.set(i)
root.update_idletasks()
preview_orig()
if result == "OK":
preview_new(out_file, TEMP_DIR)
os.chdir(pwd)

progress_var.set(0)
progress_files.set(_("done"))
Expand Down Expand Up @@ -940,8 +941,10 @@ def preview_orig():
print("! Error in preview_orig: Cannot load preview")

try:
l_preview_orig.configure(text=preview_picture['width'] + "x"\
+ preview_picture['height'])
l_preview_orig.configure(text=preview_picture['width'] + "x" \
+ preview_picture['height'] \
+ " - " \
+ preview_picture['size'])
except:
print("! Error in preview_orig: Cannot load image size")

Expand Down Expand Up @@ -1819,6 +1822,7 @@ def tools_set():
b_text_color.configure(state=DISABLED)
b_text_box_color.configure(state=DISABLED)
b_border_color.configure(state=DISABLED)

else:
root.withdraw()
messagebox.showerror(title=_("Error"),
Expand Down
11 changes: 8 additions & 3 deletions src/magick.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ def magick_command(command):
"""
make [Graphics|Image]Magick independent
command: it depends:
convert, mogrify, composite - ImageMagick
gm convert, gm mogrify, gm composite - GraphicsMagick
- ImageMagick:
- Unix: convert, mogrify, composite
- Windows: magick.exe convert, magick.exe mogrify, magick.exe composite
- GraphicsMagick:
- Unix: gm convert, gm mogrify, gm composite
- Windows: gm.exe convert, gm.exe mogrify, gm.exe composite
"""
if mswindows.windows() == 1:
suffix = ".exe "
Expand All @@ -96,7 +100,8 @@ def magick_command(command):
tool = command.split()
tool.insert(1, suffix)
tool.extend(' ')
return "".join(tool)
result = "".join(tool)
return result


def fonts_list_get(temp_dir, gm_or_im):
Expand Down
9 changes: 6 additions & 3 deletions src/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,25 @@ def preview_convert(file, dir_temp, command, size, gm_or_im):
img = Image.open(file)
width = str(img.size[0])
height = str(img.size[1])
filesize = common.humansize(os.path.getsize(file))

file_preview = common.spacja(os.path.join(dir_temp, "preview.ppm"))
command = magick.magick_command(gm_or_im + "convert") \
+ common.spacja(file) \
+ " -resize " + str(size) + "x" + str(size) \
+ command + file_preview
# print("!", command)
try:
os.system(command)
except:
print("! Error in preview_convert: " + command)

try:
return {'filename': file_preview, 'width': width, 'height': height}
result = {'filename': file_preview, 'size': filesize, \
'width': width, 'height': height}
except:
print("! Error in preview_convert: return")
return None
result = None

return result

# EOF

0 comments on commit 3d1692e

Please sign in to comment.