Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Commit

Permalink
v1.0 & Small fixes
Browse files Browse the repository at this point in the history
Changed a few labels
fixed a bug in the rename method that would delete folders
Added an icon
  • Loading branch information
natecraddock committed Sep 24, 2018
1 parent e01431c commit bc049f5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
Binary file added icon.ico
Binary file not shown.
34 changes: 24 additions & 10 deletions page_zipper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# PageZipper v0.3
# Elder Nathan Craddock 2018
# PageZipper v1.0
# Nathan Craddock 2018

import tkinter as tk
from tkinter import ttk
Expand All @@ -10,6 +10,7 @@
from PIL import Image

import io
import sys
import os
import shutil
import itertools
Expand Down Expand Up @@ -95,8 +96,8 @@ def __init__(self, parent):
self.browser = DirectoryBrowser(self, "Rename files in folder:")
self.browser.grid(row=0, column=0, sticky='nesw', padx=5, columnspan=2)

tk.Label(self, text="Starting Number:").grid(column=0, row=1, sticky='nsw')
tk.Entry(self, textvariable=self.number).grid(column=1, row=1, sticky='nsew', padx=5, pady=5)
self.label = tk.Label(self, text="Starting Number:").grid(column=0, row=1, sticky='nswe')
self.entry = tk.Entry(self, textvariable=self.number).grid(column=1, row=1, sticky='nsew', padx=5, pady=5)

self.rename_button = tk.Button(self, text='Rename Files', command=self.rename)
self.rename_button.grid(row=2, column=0, columnspan=2, sticky='nesw', padx=5)
Expand Down Expand Up @@ -151,17 +152,17 @@ def rename_files(self, path, n):

count += 1
else:
end = os.path.splitext(f)[1]
origin = os.path.join(p, f)
dest = os.path.join(temporary_directory, f)
shutil.copytree(origin, dest)
progress.next()
progress.log_message("Did not modify {0}".format(origin))

# Replace old directory with temporary directory
try:
print(p)
os.rmdir(p)
#shutil.rmtree(p)
#os.rmdir(p)
shutil.rmtree(p)
except:
print("No dir to remove")

Expand All @@ -179,7 +180,7 @@ class HelpFrame(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)

tk.Label(parent, text="Page Zipper v0.3", font=("tkdefaultfont", 18)).grid(row=0, pady=10)
tk.Label(parent, text="Page Zipper v1.0", font=("tkdefaultfont", 18)).grid(row=0, pady=10)

text = "Page Zipper is a tool to aid in the document capture process. It is designed to merge (zip) right and left captured pages of books."
tk.Message(parent, text=text, width=600).grid(row=1, pady=10)
Expand Down Expand Up @@ -209,7 +210,7 @@ def __init__(self, parent):
tk.Frame.__init__(self, parent)

self.prefix = tk.StringVar()
self.prefix.set('page_')
self.prefix.set('img_')

tk.Label(self, text="File Prefix:").grid(column=0, row=0, sticky='nse')
tk.Entry(self, textvariable=self.prefix).grid(column=1, row=0, sticky='nsew', padx=5)
Expand Down Expand Up @@ -364,7 +365,7 @@ def __init__(self, root, *args, **kwargs):
class PageZipper:
def __init__(self, root):
self.root = root
root.title("Page Zipper v0.3")
root.title("Page Zipper v1.0")
#root.tk.call('wm', 'iconphoto', root._w, tk.PhotoImage(file="icon.png"))

# Create dictionary variables for the three UI areas
Expand Down Expand Up @@ -418,6 +419,7 @@ def create_gui(self):
# Fill Utilities Frame
self.utils['renamer'] = RenameFrame(self.utils['frame'])
self.utils['renamer'].grid(row=0, column=0, sticky='nesw')
self.utils['renamer'].columnconfigure(0, weight=1)

# Fill Output Frame
self.output['viewer'] = ThumbnailViewer(self.output['frame'])
Expand All @@ -440,6 +442,7 @@ def create_gui(self):
self.input_tab.columnconfigure(0, weight=1)
self.output_tab.columnconfigure(0, weight=1)
self.help_tab.columnconfigure(0, weight=1)
self.utils_tab.columnconfigure(0, weight=1)

# Set callbacks to load images that are called when path is valid
self.left['browser'].callback = lambda area=self.left : self.on_input(area)
Expand Down Expand Up @@ -535,4 +538,15 @@ def clear_dir(self, path):
root.update()
root.minsize(root.winfo_reqwidth(), root.winfo_reqheight())
root.resizable(width=True, height=True)

# Ensure the icon works both from the python file, and the pyinstaller executable
icon_file = "icon.ico"
if not hasattr(sys, "frozen"):
icon_file = os.path.join(os.path.dirname(__file__), icon_file)
else:
icon_file = os.path.join(sys._MEIPASS, icon_file)
try:
root.iconbitmap(default=icon_file)
except:
print("Icon failed")
root.mainloop()

0 comments on commit bc049f5

Please sign in to comment.