-
Notifications
You must be signed in to change notification settings - Fork 0
/
saf_view.py
148 lines (107 loc) · 2.86 KB
/
saf_view.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import os
from tkinter import messagebox
from tkinter import filedialog
from tkinter import *
from PIL import Image, ImageTk
import sys
fTypes = [".jpg", ".jpeg", ".png", ".gif"] #".jpg", ".jpeg", ".png", ".gif"
img = []
cf = ""
cwd = os.getcwd()
if (not os.path.exists(os.getcwd()+"/junk")):
try:
print("Attempting to creat dir [" + (cwd + "/junk/") + "]")
os.mkdir((cwd + "/junk/"))
except OSError as err:
print("OS error: {0}! Exiting Can't Continue!".format(err))
exit()
def loadDir():
global img
global cwd
img = []
for fT in fTypes:
for file in os.listdir(cwd + "/"):
if file.endswith(fT):
img.append(file)
loadDir()
def nextPic(fn):
imname = (cwd + "/" + fn)
image = Image.open(imname)
root.title("PPC's SAF Image Viewer! - " + imname)
wh = root.winfo_height()-30
if (image.size[1] < wh):
baseheight = image.size[1]
else:
baseheight = wh
# this is the resizeing stuff
hpercent = (baseheight / float(image.size[1]))
wsize = int((float(image.size[0]) * float(hpercent)))
image = image.resize((wsize, baseheight), Image.ANTIALIAS)
#
photo = ImageTk.PhotoImage(image)
label.configure(image = photo)
label.image = photo
def showHelp(self):
messagebox.showinfo('Help', "[SPACEBAR] = next picture\n[Z] = move picture to junk folder\n[D] = load new folder\n[H] = This help\n[Q] = quit\n\nBy The Pascal Pirate."
)
def handelKeys(event):
global cf
global img
global cwd
if event.char == 'z':
print(cwd + "/" + cf, " moved to " + cwd + "/junk/" + cf)
os.rename(cwd + "/" + cf, cwd + "/junk/" + cf)
try:
fn = img.pop()
except:
print("End of images asking for new directory...")
tmp = filedialog.askdirectory()
if tmp:
cwd = tmp
loadDir()
cf = fn
nextPic(fn)
elif event.char == 'q':
print("Quit!")
root.destroy()
elif event.char == '?' or event.char == "h":
showHelp(False)
elif event.char == ' ':
try:
fn = img.pop()
cf = fn
print("Next! " + cwd + "/" + fn)
nextPic(fn)
except:
print("End of images asking for new directory...")
tmp = filedialog.askdirectory()
if tmp:
cwd = tmp
loadDir()
elif event.char == "d":
tmp = filedialog.askdirectory()
if tmp:
cwd = tmp
loadDir()
root = Tk()
# get screen width and height
ws = root.winfo_screenwidth()-380 # width of the screen
hs = root.winfo_screenheight()-300 # height of the screen
root.title("PPC's SAF Image Viewer!")
root.geometry('%dx%d+170+120' % (ws, hs))
photo = PhotoImage(file="saf_view_splash.png")
if not photo:
cf = img.pop()
photo = PhotoImage(file=cf)
label = Label(root, image=photo)
label.pack()
ent = Entry(root)
ent.bind_all('<Key>', handelKeys)
ent.focus_set()
wl = ws-20
instructions = Label(root, text=u"\u2699", fg="grey", wraplength=ws)
instructions.config(font=("Times", 16))
instructions.place(x=1, y=1)
instructions.bind("<Button-1>", showHelp)
showHelp(False)
root.mainloop()