-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChronoRef.py
557 lines (436 loc) · 13.1 KB
/
ChronoRef.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
import glob
import pathlib
import os
import time
import math
import random
import tkinter.font as font
from tkinter import filedialog
from tkinter import *
import tkinter.scrolledtext as st
from PIL import ImageTk, Image
from natsort import natsorted
root = Tk()
root.title("ChronoRef")
# Style
bg_color = "#151818"
fg_color = "#839699"
accent_color = "#094E58"
my_font = font.Font(size=11, family="Arial")
my_font2 = font.Font(size=16, family="Helvetica")
timer_paused=False
root["bg"] = bg_color
# Determines whether or not the next image is random is in sequential order
is_random = False
# The resize length of the image. If the image is landscape, this effects the width, otherwise the height is affected.
size_mod = 900
# The starting time of the timer, 30 seconds.
timer_count = 30000
# The index variable for the image list.
image_index = 0
# The variable for the time that's displayed on the countdown timer.
timer_display = timer_count
# Asks for directory on application startup
root.directory = filedialog.askdirectory()
dir_path = root.directory
# Creates a list of images in the selected directory
image_list = natsorted(list(pathlib.Path(dir_path).glob("*.jpg")))
image_name_list = natsorted(list(pathlib.Path(dir_path).name))
file_count = len(os.listdir(dir_path))
# An image file from the selected directory.
image_file = Image.open(image_list[image_index])
selected_thumb=image_list[image_index].name
# Change Directory
def choose_directory():
global dir_path
global image_list
global file_count
global image_file
global image_index
global directory_label
global image_frame
# Selects first image in directory
image_index = 0
root.directory = filedialog.askdirectory()
dir_path = root.directory
image_list = natsorted(list(pathlib.Path(dir_path).glob("*.jpg")))
file_count = len(os.listdir(dir_path))
image_file = Image.open(image_list[image_index])
thumb_generate()
display_reset()
update_time()
def display_reset():
global image_frame
global directory_label
global timer_display
global timer_count
if timer_display > 0: # manual
image_frame.destroy()
directory_label.destroy()
else: # timer
image_frame.grid_forget()
directory_label.grid_forget()
timer_display = timer_count
# Update countdown time length
def update_time():
global timer_display
global timer_count
timer_count = selected_time.get()
display_reset()
image_display()
def resume():
global timer_display
global timer_count
timer_count=timer_display
# Update whether the next image is random or sequential
def updateRandom():
global is_random
global button_shuffle
if is_random == False:
button_shuffle = Button(media_control, text="\U0001F500", command=shuffle, bg=bg_color, fg=fg_color, font=my_font2, border=0)
button_shuffle.grid(row=0, column=3)
else:
button_shuffle = Button(media_control, text="\U0001F500", command=shuffle, bg=bg_color, fg=accent_color, font=my_font2, border=0)
button_shuffle.grid(row=0, column=3)
display_reset()
update_time()
def shuffle():
global is_random
if is_random == False:
is_random = True
else:
is_random = False
updateRandom()
# timer function
def timer():
global timer_display
global my_timer
global timer_paused
if timer_paused==False:
timer_display -= 1000
minute = int(math.floor(timer_display / 1000 / 60))
second = int(timer_display / 1000 % 60)
counter_string = "{:0>2}".format(str(minute)) + ":" + "{:0>2}".format(str(second))
my_timer.config(text=counter_string)
my_timer.after(1000, timer)
def prev_image():
global image_frame
global directory_label
global image_file
global image_index
global image_list
global timer_display
global timer_count
global is_random
# Determines if image selection is random or sequential
if image_index == 0:
image_index = len(image_list) - 1
else:
image_index -= 1
update_time()
display_reset()
image_display()
# Function for loading the next image
def next_image():
global image_frame
global directory_label
global image_file
global image_index
global image_list
global timer_display
global timer_count
global is_random
# Determines if image selection is random or sequential
if is_random:
image_index = random.randint(0, len(image_list) - 1)
else:
if image_index < len(image_list) - 1:
image_index = image_index + 1
else:
image_index = 0
update_time()
display_reset()
image_display()
def pause_timer():
global timer_paused
if timer_paused == False:
timer_paused = True
resume()
else:
timer_paused = False
display_reset()
image_display()
thumb_display = Button()
def image_preview(file):
global thumb_image_file
global thumb_image
global thumb_display
global selected_thumb
global thumb_generate
global scroll_area
selected_thumb=file.name
thumb_generate()
thumb_display.destroy()
thumb_image_file = Image.open(file)
thumb_image_file.thumbnail((200,200))
thumb_image = ImageTk.PhotoImage(thumb_image_file)
thumb_display = Button(
scroll_area,
image=thumb_image,
command=lambda file=file : image_select(file),
bg=bg_color,
fg=fg_color,
font=my_font,
)
thumb_display.grid(row=1, column=0)
def image_select(file):
global image_index
image_index=image_list.index(file)
update_time()
display_reset()
image_display()
# Function for displaying the image
def image_display():
global image_frame
global directory_label
global image_file
global image_index
global image_height
global image_width
global aspect_ratio
global resize_width
global resize_height
global tk_image
global resized
global resized_pic
global image_list
global timer_display
global timer_count
global is_random
global size_mod
global timer_paused
global widthpadding
global heightpadding
image_file = Image.open(image_list[image_index])
tk_image = ImageTk.PhotoImage(image_file)
# Get Image size
image_height = tk_image.height()
image_width = tk_image.width()
# Determine size of the image. If image length is less than the resize length, it doesn't resize the image.
aspect_ratio = image_height / image_width
if aspect_ratio < 1:
if image_width > size_mod:
resize_width = size_mod
resize_height = int(size_mod * aspect_ratio)
else:
resize_width = image_width
resize_height = image_height
heightpadding = 150
else:
if image_height > size_mod:
resize_height = size_mod
resize_width = int(size_mod / aspect_ratio)
else:
resize_width = image_width
resize_height = image_height
heightpadding = 100
root.geometry(str(resize_width + 300) + "x" + str(resize_height + heightpadding))
resized = image_file.resize((resize_width, resize_height), Image.ANTIALIAS)
resized_pic = ImageTk.PhotoImage(resized)
# Displays the image
image_frame = Label(root, image=resized_pic, bg=bg_color, fg=fg_color, font=my_font)
image_frame.grid(row=2, column=2, rowspan=19)
# Selects the next image after a certain time (timer_count) has passed
if timer_paused==False:
image_frame.after(timer_count, next_image)
# Creates a button that displays the current directory. Clicking it prompts the user to select a new one.
directory_label = Button(
text=dir_path, bg=bg_color, fg=fg_color, font=my_font, command=choose_directory
)
directory_label.grid(row=0, column=2)
image_display()
# Adjust the countdown timer length
selected_time = IntVar()
selected_time.set(30000)
r1 = Radiobutton(
root,
text="30 Seconds",
value=30000,
variable=selected_time,
command=update_time,
bg=bg_color,
fg=fg_color,
font=my_font,
selectcolor=accent_color,
indicatoron=0,
)
r2 = Radiobutton(
root,
text="1 Minute",
value=60000,
variable=selected_time,
command=update_time,
bg=bg_color,
fg=fg_color,
font=my_font,
selectcolor=accent_color,
indicatoron=0,
)
r3 = Radiobutton(
root,
text="5 Minutes",
value=300000,
variable=selected_time,
command=update_time,
bg=bg_color,
fg=fg_color,
font=my_font,
selectcolor=accent_color,
indicatoron=0,
)
r4 = Radiobutton(
root,
text="10 Minutes",
value=600000,
variable=selected_time,
command=update_time,
bg=bg_color,
fg=fg_color,
font=my_font,
selectcolor=accent_color,
indicatoron=0,
)
r5 = Radiobutton(
root,
text="15 Minutes",
value=900000,
variable=selected_time,
command=update_time,
bg=bg_color,
fg=fg_color,
font=my_font,
selectcolor=accent_color,
indicatoron=0,
)
r6 = Radiobutton(
root,
text="30 Minutes",
value=1800000,
variable=selected_time,
command=update_time,
bg=bg_color,
fg=fg_color,
font=my_font,
selectcolor=accent_color,
indicatoron=0,
)
r7 = Radiobutton(
root,
text="45 Minutes",
value=2700000,
variable=selected_time,
command=update_time,
bg=bg_color,
fg=fg_color,
font=my_font,
selectcolor=accent_color,
indicatoron=0,
)
r8 = Radiobutton(
root,
text="60 Minutes",
value=3600000,
variable=selected_time,
command=update_time,
bg=bg_color,
fg=fg_color,
font=my_font,
selectcolor=accent_color,
indicatoron=0,
)
r1.grid(row=3, column=0, sticky="nsew")
r2.grid(row=4, column=0, sticky="nsew")
r3.grid(row=5, column=0, sticky="nsew")
r4.grid(row=6, column=0, sticky="nsew")
r5.grid(row=7, column=0, sticky="nsew")
r6.grid(row=8, column=0, sticky="nsew")
r7.grid(row=9, column=0, sticky="nsew")
r8.grid(row=10, column=0, sticky="nsew")
# Adjust whether or not the next image is sequential or random
selected_random = BooleanVar()
# Image List
def thumb_generate():
global selected_thumb
global image_button
global scroll_area
global yviewposition
global positionpad
scroll_area = Frame(root, bg=bg_color)
scroll_area.grid(row=1, column=3, rowspan=20)
image_names= st.ScrolledText(scroll_area, width=16, height=24, bg=bg_color,
fg=fg_color,
font=my_font,)
image_names.pack()
image_names.grid(row=0, column=0)
for x in image_list:
#image_button.destroy()
#image_names.insert(INSERT, x.name+'\n')
if x.name == selected_thumb:
image_button=Button(
image_names,
text=x.name,
command=lambda x=x: image_preview(x),
bg=accent_color,
fg=fg_color,
font=my_font,
height=2
)
positionpad=2/(len(image_list))
yviewposition = (image_list.index(x)/len(image_list))-positionpad
else:
image_button=Button(
image_names,
text=x.name,
command=lambda x=x: image_preview(x),
bg=bg_color,
fg=fg_color,
font=my_font,
height=2
)
image_names.window_create("end", window=image_button)
image_names.insert("end", "\n")
image_names.yview_moveto(yviewposition)
image_names.configure(state='disabled')
thumb_generate()
# Media Control Frame
media_control = Frame(root)
media_control.grid(row=22, column=2)
# Media Control Buttons
button_shuffle = Button(
media_control, text="\U0001F500", command=shuffle, bg=bg_color, fg=fg_color, font=my_font2, border=0
)
button_shuffle.grid(row=0, column=3)
button_right = Button(
media_control, text="\u23ED", command=next_image, bg=bg_color, fg=fg_color, font=my_font2, border=0
)
button_right.grid(row=0, column=2)
button_pause = Button(
media_control, text="\u23EF", command=pause_timer, bg=bg_color, fg=fg_color, font=my_font2, border=0
)
button_pause.grid(row=0, column=1)
button_left = Button(
media_control, text="\u23EE", command=prev_image, bg=bg_color, fg=fg_color, font=my_font2, border=0
)
button_left.grid(row=0, column=0)
# Exit program
button_exit = Button(
root, text="\u2715", command=root.quit, bg=bg_color, fg=fg_color, font=my_font
)
button_exit.grid(row=0, column=3, sticky="e")
# Displays the timer
my_timer = Label(root, text="", bg=bg_color, fg=fg_color, font=my_font2)
my_timer.grid(row=21, column=1, columnspan=2)
# Starts the timer
timer()
root.resizable(False, False)
root.mainloop()