-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathHPSolver.py
More file actions
1544 lines (1357 loc) · 63.2 KB
/
HPSolver.py
File metadata and controls
1544 lines (1357 loc) · 63.2 KB
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
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Version = "1.8"
InfoText = """\
Any app's window must be in focus
for settings to function.
Order Playback enables click-through
functionality for the order window
For Puzzle #2 you can input numbers right away.
For Puzzle #3 you can seperate the number and
the base (the other number in ()) with a space
or a t, so, for example, "100110 (2)" (in game)
will be "100110 2" or "100110t2" in your input.
For Puzzle #4 you don't need to use spaces at all.
Also, some questions are labeled as "evil" by the
creator of the puzzle, so you can input their
answers right away.
Made by ozo (Discord @m6ga)
Contributed by ltrc125 (@cat.0400)
DM any bugs or suggestions, a forum post for the
app can be found on the EUT's discord server.\
"""
Evil_Solutions = """\
"Asap" question's answer is 1
"33 + 77" is 100
The not not not not question is 1
The bottom blue hint is the number in the end + 1
The bottom red hint is the number in the end - 1
The "1 + 1" is 11
Answers can be input right away, but solving is
also implemented
Puzzle #4 syntax shortcuts
c = math.ceil
f = math.floor
r = math.round
p = π (math.pi)
"""
import customtkinter as ctk
import tkinter as tk
import sys, os
from ctypes import windll
from PIL import Image
import pywinstyles as pws
import math
import sympy as sp
from re import sub
import json
import webbrowser
# required for proper images compiling
def resource_path(relative_path):
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath("."), relative_path)
# Save config to a JSON file
def save_settings():
try:
settings["main_window_location"] = f"+{app.winfo_x()}+{app.winfo_y()}"
settings["main_window_size"] = f"{app.winfo_width()}x{app.winfo_height()}"
data = {
"hatch_puzzle": settings[hatch_puzzle],
"clear_entries": settings[clear_entries],
"order_playback": settings[order_playback],
"order_cooldown": settings["order_cooldown"],
"main_window_location": settings["main_window_location"],
"main_window_size": settings["main_window_size"],
"settings_window_location": settings["settings_window_location"],
"info_window_location": settings["info_window_location"],
"evil_solutions_window_location": settings["evil_solutions_window_location"],
"order_window_location": settings["order_window_location"],
"order_window_size": settings["order_window_size"],
"puzzle4_window_location": settings["puzzle4_window_location"],
"console_window_location": settings["console_window_location"],
}
with open("settings.json", "w") as f:
json.dump(data, f, indent=4)
print("Config saved.")
except Exception as e:
print(f"Error saving config: {e}")
def load_settings():
if not os.path.exists("settings.json"):
app.bind_all(f"<{settings[hatch_puzzle]}>", hatch_puzzle)
app.bind_all(f"<{settings[clear_entries]}>", clear_entries)
app.bind_all(f"<{settings[order_playback]}>", order_playback)
return
try:
with open("settings.json", "r") as f:
data = json.load(f)
# Keybinds
# Solve
old_solve = settings[hatch_puzzle]
new_solve = data.get("hatch_puzzle", old_solve)
if new_solve != old_solve and new_solve != '??':
settings[hatch_puzzle] = new_solve
app.bind_all(f"<{new_solve}>", hatch_puzzle)
# Clear
old_clear = settings[clear_entries]
new_clear = data.get("clear_entries", old_clear)
if new_clear != old_clear and new_clear != '??':
settings[clear_entries] = new_clear
app.bind_all(f"<{new_clear}>", clear_entries)
# Order playback
old_playback = settings[order_playback]
new_playback = data.get("order_playback", old_playback)
if new_playback != old_playback and new_playback != '??':
settings[order_playback] = new_playback
app.bind_all(f"<{new_playback}>", order_playback)
# Other
# Order cooldown
old_cooldown = settings["order_cooldown"]
new_cooldown = data.get("order_cooldown", old_cooldown)
if new_cooldown != old_cooldown:
settings["order_cooldown"] = int(new_cooldown)
# Window Stuff
# Main
old_main_window_location = settings["main_window_location"]
new_main_window_location = data.get("main_window_location", old_main_window_location)
if new_main_window_location != old_main_window_location:
settings["main_window_location"] = new_main_window_location
old_main_window_size = settings["main_window_size"]
new_main_window_size = data.get("main_window_size", old_main_window_size)
if new_main_window_size != old_main_window_size:
settings["main_window_size"] = new_main_window_size
# Settings
old_settings_window_location = settings["settings_window_location"]
new_settings_window_location = data.get("settings_window_location", old_settings_window_location)
if new_settings_window_location != old_settings_window_location:
settings["settings_window_location"] = new_settings_window_location
# Info
old_info_window_location = settings["info_window_location"]
new_info_window_location = data.get("info_window_location", old_info_window_location)
if new_info_window_location != old_info_window_location:
settings["info_window_location"] = new_info_window_location
# Evil Solutions
old_evil_solutions_window_location = settings["evil_solutions_window_location"]
new_evil_solutions_window_location = data.get("evil_solutions_window_location", old_evil_solutions_window_location)
if new_evil_solutions_window_location != old_evil_solutions_window_location:
settings["evil_solutions_window_location"] = new_evil_solutions_window_location
# Order
old_order_window_location = settings["order_window_location"]
new_order_window_location = data.get("order_window_location", old_order_window_location)
if new_order_window_location != old_order_window_location:
settings["order_window_location"] = new_order_window_location
old_order_window_size = settings["order_window_size"]
new_order_window_size = data.get("order_window_size", old_order_window_size)
if new_order_window_size != old_order_window_size:
settings["order_window_size"] = new_order_window_size
# Puzzle 4 Answers
old_puzzle4_window_location = settings["puzzle4_window_location"]
new_puzzle4_window_location = data.get("puzzle4_window_location", old_puzzle4_window_location)
if new_puzzle4_window_location != old_puzzle4_window_location:
settings["puzzle4_window_location"] = new_puzzle4_window_location
# Console
old_console_window_location = settings["console_window_location"]
new_console_window_location = data.get("console_window_location", old_console_window_location)
if new_console_window_location != old_console_window_location:
settings["console_window_location"] = new_console_window_location
except Exception as e:
print(f"Error loading settings: {e}")
# top window pinning utility
def pin_window(window, button):
try:
current_topmost = window.attributes('-topmost')
window.attributes('-topmost', not current_topmost)
button.configure(text="Unpin" if not current_topmost else "Pin")
except Exception as e:
print(f"Error processing pin_window: {e}")
# allows for darkening any colour, mainly applied to widgets upon hovering as feedback
def darken(widget, factor=0.8, bool=True):
if bool:
def on_enter(event):
widget.configure(fg_color=f"#{darken_color}")
def on_leave(event):
widget.configure(fg_color=f"#{initial_color}")
initial_color = widget.cget("fg_color").lstrip('#')
rgb = tuple(int(initial_color[i:i + 2], 16) for i in (0, 2, 4))
darken_rgb = tuple(max(0, min(255, int(c * factor))) for c in rgb)
darken_color = '{:02x}{:02x}{:02x}'.format(*darken_rgb)
widget.bind("<Enter>", on_enter)
widget.bind("<Leave>", on_leave)
return darken_color
# custom titlebar for subwindows
def titlebarify(widget, window, location_key):
try:
initial_color = widget.cget("fg_color")
darken_color = darken(widget)
def start_move(event):
window._offset_x = event.x_root - window.winfo_rootx()
window._offset_y = event.y_root - window.winfo_rooty()
widget.configure(fg_color=f"#{darken_color}")
def do_move(event):
new_x = event.x_root - window._offset_x
new_y = event.y_root - window._offset_y
window.geometry(f"+{new_x}+{new_y}")
def stop_move(event):
widget.configure(fg_color=initial_color)
settings[location_key] = f"+{int(window.winfo_x())} +{int(window.winfo_y())}"
widget.bind("<Button-1>", start_move)
widget.bind("<B1-Motion>", do_move)
widget.bind("<ButtonRelease-1>", stop_move)
except Exception as e:
print(f"Error processing titlebarify: {e}\n")
# subwindow template
def create_subwindow(location_key):
try:
window = ctk.CTkToplevel(app)
window.attributes("-toolwindow", True)
window.attributes('-topmost', True)
window.overrideredirect(True)
window.wm_attributes("-transparentcolor", "#1a1a1a")
window.after(10, lambda: window.focus_force())
window.geometry(settings[location_key])
mainframe = ctk.CTkFrame(window, corner_radius=10)
mainframe.pack()
titlebar = ctk.CTkFrame(mainframe,
height=25,
fg_color='#1f6aa5',
corner_radius=5)
titlebar.pack_propagate(False)
titlebar.pack(fill='x', pady=(5, 0), padx=5)
titlebarify(titlebar, window, location_key)
close = ctk.CTkButton(titlebar,
height=20,
width=15,
corner_radius=5,
fg_color='#002037',
text='Close',
font=("", 10),
command=window.withdraw)
close.pack(side='right', padx=2)
return window, mainframe, titlebar
except Exception as e:
print(f"Error processing create_subwindow: {e}\n")
settings_window = None
OrderSizeValue = None
def open_settings():
try:
global settings_window, settings
def hatch_bind(button, function):
blacklist = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '.', ',', '/', 'm', 'a', 't', 'h', 'r', 'o', 'u', 'n', 'd', 'c', 'e', 'i', 'l', 'f', 's', 'p', "Tab", "Escape"]
button.configure(text="Press a Key", fg_color='#144870')
def on_key_press(event):
if not event.keysym.isascii():
print("Invalid keybind: Non-ASCII key detected.")
return
key = event.keysym
# Normalizing
key = key.upper() if key.lower() in [f'f{i}' for i in range(1, 13)] else key
if key in blacklist:
print(f"Invalid keybind: {key}.\nFollowing keys are reserved:\n{blacklist}.")
return
button.configure(text=key, fg_color='#1f6aa5')
old_key = settings.get(function)
if old_key:
try:
app.unbind_all(f"<{old_key}>")
except Exception as e:
print(f"Error unbinding old key {old_key}: {e}")
# Update settings and bind new key
settings[function] = key
app.bind_all(f"<{key}>", function)
print(f"{function.__name__} keybind changed to:", key)
settings_window.unbind("<Any-KeyPress>")
settings_window.bind("<Any-KeyPress>", on_key_press)
settings_window.focus_force()
def update_cooldown(event):
try:
new_value = event.widget.get().strip()
if int(new_value) == int(settings['order_cooldown']):
pass
elif new_value.isdigit() and int(new_value) > 0:
settings["order_cooldown"] = int(new_value)
print(f"Cooldown updated to: {settings['order_cooldown']}ms")
else:
print("Invalid cooldown: Must be a positive integer.")
event.widget.delete(0, "end")
event.widget.insert(0, str(settings["order_cooldown"]))
focus_out(event)
except Exception as e:
print(f"Error updating cooldown: {e}")
event.widget.delete(0, "end")
event.widget.insert(0, str(settings["order_cooldown"]))
def update_order_window_size(event):
try:
global screen_h
new_value = event.widget.get().strip()
if int(new_value) == int(settings["order_window_size"]):
pass
elif new_value.isdigit() and int(new_value) >= 200 and int(new_value) <= int(screen_h * 0.9):
new_w = int(new_value)
settings["order_window_size"] = new_w
new_h = new_w + 90
order_window.geometry(f"{new_w}x{new_h}")
cell_size = (new_w - 20) // 5
for row in labels:
for label in row:
label.configure(width=cell_size,
height=cell_size,
font=("", max(12, cell_size // 4), "bold"))
print(f"Order window size set to: {new_w}")
else:
print(f"Invalid window size: Must be an integet >= 200 and <= {int(screen_h * 0.9)}")
event.widget.delete(0, "end")
event.widget.insert(0, settings["order_window_size"])
focus_out(event)
except Exception as e:
print(f"Error updating order window size: {e}")
event.widget.delete(0, "end")
event.widget.insert(0, settings["order_window_size"])
def reset_defaults(event=None):
try:
global settings
for fn in (hatch_puzzle, clear_entries, order_playback):
old = settings.get(fn)
if old:
app.unbind_all(f"<{old}>")
settings = DEFAULT_SETTINGS.copy()
app.bind_all(f"<{settings[hatch_puzzle]}>", hatch_puzzle)
app.bind_all(f"<{settings[clear_entries]}>", clear_entries)
app.bind_all(f"<{settings[order_playback]}>", order_playback)
SolveBind.configure(text=settings[hatch_puzzle])
ClearBind.configure(text=settings[clear_entries])
PlaybackBind.configure(text=settings[order_playback])
CooldownValue.delete(0, "end")
CooldownValue.insert(0, str(settings["order_cooldown"]))
OrderSizeValue.delete(0, "end")
OrderSizeValue.insert(0, str(settings["order_window_size"]))
if order_window and order_window.winfo_exists():
new_w = settings["order_window_size"]
new_h = new_w + 90
order_window.geometry(f"{new_w}x{new_h}")
app.geometry(settings["main_window_size"] + settings["main_window_location"])
save_settings()
print("Settings reset to defaults.")
except Exception as e:
print(f"Error resetting defaults: {e}")
if settings_window is not None and settings_window.winfo_exists():
settings_window.lift()
settings_window.focus_force()
return
window, mainframe, titlebar = create_subwindow("settings_window_location")
grid = ctk.CTkFrame(mainframe, corner_radius=5)
grid.pack(pady=5, padx=5)
grid.columnconfigure(1, weight=1)
SettingsLabel = ctk.CTkLabel(grid,
text="Settings",
font=("", 20, "bold"))
SettingsLabel.grid(row=0, columnspan=2)
TabLabel = ctk.CTkLabel(grid,
text="Focus Next Entry = <Tab>\nPrevious Entry = <Shift> + <Tab>",
font=("", 15))
TabLabel.grid(row=1, column=0, columnspan=2, pady=5, padx=5)
SolveLabel = ctk.CTkLabel(grid,
text="Solve:",
font=("", 15))
SolveLabel.grid(row=2, column=0, pady=5, padx=5, sticky="w")
SolveBind = ctk.CTkButton(grid,
width=90,
height=30,
border_width=1,
corner_radius=2,
text=settings[hatch_puzzle],
font=("", 15, 'bold'), command=lambda: hatch_bind(SolveBind, hatch_puzzle))
SolveBind.grid(row=2, column=1, pady=5, padx=5)
ClearLabel = ctk.CTkLabel(grid,
text="Clear:",
font=("", 15))
ClearLabel.grid(row=3, column=0, pady=5, padx=5, sticky="w")
ClearBind = ctk.CTkButton(grid,
width=90,
height=30,
border_width=1,
corner_radius=2,
text=settings[clear_entries],
font=("", 15, 'bold'),
command=lambda: hatch_bind(ClearBind, clear_entries))
ClearBind.grid(row=3, column=1, pady=5, padx=5)
PlaybackLabel = ctk.CTkLabel(grid,
text="Order Playback:",
font=("", 15))
PlaybackLabel.grid(row=4, column=0, pady=5, padx=5, sticky="w")
PlaybackBind = ctk.CTkButton(grid,
width=90,
height=30,
border_width=1,
corner_radius=2,
text=settings[order_playback],
font=("", 15, 'bold'),
command=lambda: hatch_bind(PlaybackBind, order_playback))
PlaybackBind.grid(row=4, column=1, pady=5, padx=5)
CooldownLabel = ctk.CTkLabel(grid,
text="Cooldown (ms):",
font=("", 15))
CooldownLabel.grid(row=5, column=0, pady=5, padx=5, sticky="w")
CooldownValue = ctk.CTkEntry(grid,
justify="center",
width=90,
height=30,
border_width=1,
border_color="#acacac",
corner_radius=2,
font=("", 15, 'bold'))
CooldownValue.insert(0, str(settings["order_cooldown"]))
CooldownValue.grid(row=5, column=1, pady=5, padx=5)
CooldownValue.bind("<FocusIn>", focus_in)
CooldownValue.bind("<FocusOut>", update_cooldown)
OrderSizeLabel = ctk.CTkLabel(grid,
text="Order Window Size:",
font=("", 15))
OrderSizeLabel.grid(row=6, column=0, pady=5, padx=5, sticky="w")
global OrderSizeValue
OrderSizeValue = ctk.CTkEntry(grid,
justify="center",
width=90,
height=30,
border_width=1,
border_color="#acacac",
corner_radius=2,
font=("", 15, "bold"))
OrderSizeValue.insert(0, str(settings["order_window_size"]))
OrderSizeValue.grid(row=6, column=1, pady=5, padx=5)
OrderSizeValue.bind("<FocusIn>", focus_in)
OrderSizeValue.bind("<FocusOut>", update_order_window_size)
ResetDefaults = ctk.CTkButton(grid,
width=230,
height=30,
border_width=1,
corner_radius=2,
text="Reset To Defaults",
font=("", 15, 'bold'),
command=reset_defaults)
ResetDefaults.grid(row=7, column=0, columnspan=2, pady=5, padx=5)
window.withdraw()
settings_window = window
except Exception as e:
print(f"Error processing open_settings: {e}\n")
info_window = None
def open_info():
try:
global info_window
if info_window is not None and info_window.winfo_exists():
info_window.lift()
info_window.focus_force()
return
window, mainframe, titlebar = create_subwindow("info_window_location")
versionlabel = ctk.CTkLabel(mainframe,
anchor="center",
width=280,
text=f"Version {Version}",
font=("", 20, 'bold'))
versionlabel.pack()
label = ctk.CTkLabel(mainframe,
text=InfoText,
font=("", 15),
justify="left")
label.pack(padx=5)
DiscordLabel = ctk.CTkLabel(mainframe,
text="Everything Upgrade Tree Discord",
font=("", 18, "bold"),
anchor="center",
text_color="#48a7ff",
cursor="hand2")
DiscordLabel.pack(padx=5, pady=(0, 2))
DiscordLabel.bind("<Enter>", lambda e: DiscordLabel.configure(font=("", 18, "underline")))
DiscordLabel.bind("<Leave>", lambda e: DiscordLabel.configure(font=("", 18, "bold")))
DiscordLabel.bind("<Button-1>", lambda e: (webbrowser.open("https://discord.gg/eut"), app.iconify()))
ForumPostLabel = ctk.CTkLabel(mainframe,
text="Forum Post Link",
font=("", 18, "bold"),
anchor="center",
text_color="#6ab7ff",
cursor="hand2")
ForumPostLabel.pack(padx=5, pady=(0, 2))
ForumPostLabel.bind("<Enter>", lambda e: ForumPostLabel.configure(font=("", 18, "underline")))
ForumPostLabel.bind("<Leave>", lambda e: ForumPostLabel.configure(font=("", 18, "bold")))
ForumPostLabel.bind("<Button-1>", lambda e: (webbrowser.open("https://discord.com/channels/1300785642954817589/1349881040201842688"), app.iconify()))
window.withdraw()
info_window = window
except Exception as e:
print(f"Error processing open_info: {e}\n")
evil_solutions_window = None
def open_evil_solutions():
try:
global evil_solutions_window
if evil_solutions_window is not None and evil_solutions_window.winfo_exists():
evil_solutions_window.lift()
evil_solutions_window.focus_force()
return
window, mainframe, titlebar = create_subwindow("evil_solutions_window_location")
evillabel = ctk.CTkLabel(mainframe,
width=100,
text="Evil Solutions",
text_color="#ff0000",
font=("", 20))
evillabel.pack()
label = ctk.CTkLabel(mainframe,
text=Evil_Solutions,
font=("", 15),
justify="left",
width=280)
label.pack(padx=5)
window.withdraw()
evil_solutions_window = window
except Exception as e:
print(f"Error processing open_evil_solutions: {e}\n")
# Class is used as I couldn't find a class-less solution for properly redirecting console output to the app
class ConsoleWindow:
def __init__(self, master):
self.master = master
self.window = None
self.console_text = None
self.master.after(200, self.setup)
def setup(self):
self.setup_ui()
self.setup_redirection()
self.write_console("Console initialized.\n")
def setup_ui(self):
try:
if self.window is not None and self.window.winfo_exists():
self.window.lift()
self.window.focus_force()
return
self.window = ctk.CTkToplevel(self.master)
self.window.attributes("-toolwindow", True)
self.window.attributes('-topmost', True)
self.window.overrideredirect(True)
self.window.geometry(settings["console_window_location"])
mainframe = ctk.CTkFrame(self.window,
corner_radius=10,
fg_color="#1a1a1a",
width=550,
height=300)
mainframe.pack_propagate(False)
mainframe.pack(fill='both')
freedom_dive = ctk.CTkImage(light_image=Image.open(resource_path("images/KuranteEUT.png")),
size=(550, 300))
freedom_image = ctk.CTkLabel(mainframe,
text="",
image=freedom_dive)
freedom_image.place(relx=0, rely=0, relwidth=1, relheight=1)
titlebar = ctk.CTkFrame(mainframe,
height=25,
fg_color='#1f6aa5',
corner_radius=5,
background_corner_colors=('#97aabf', '#0d1121', '#465b2f', '#64975f'))
titlebar.pack_propagate(False)
titlebar.pack(fill='x', pady=5, padx=5)
titlebarify(titlebar, self.window, "console_window_location")
titlebar.grid_columnconfigure(1, weight=1)
clear = ctk.CTkButton(titlebar,
height=20,
width=30,
corner_radius=5,
fg_color='#002037',
text='Clear',
font=("", 10),
command=self.clear_console)
clear.grid(column=0, row=0, padx=2, pady=2, sticky='w')
copy_button = ctk.CTkButton(titlebar,
height=20,
width=30,
corner_radius=5,
fg_color='#002037',
text='Copy',
font=("", 10),
command=self.copy_console)
copy_button.grid(column=1, row=0)
close = ctk.CTkButton(titlebar,
height=20,
width=15,
corner_radius=5,
fg_color='#002037',
text='Close',
font=("", 10),
command=self.window.withdraw)
close.grid(column=2, row=0, padx=2, sticky='e')
text_frame = ctk.CTkFrame(mainframe,
fg_color="#1a1a1a")
pws.set_opacity(text_frame, value=0.9)
text_frame.pack(pady=(0, 5), padx=5, fill='both', expand=True)
# tk.text is used for errors colormapping as ctk one doesn't support it if I am not dumb
self.console_text = tk.Text(text_frame,
wrap="word",
height=15,
width=60,
bg="#000000",
fg="#ffffff",
insertbackground="#ffffff",
font=("Courier", 10, ""),
bd=0,
relief="flat")
self.console_text.pack(fill='both', expand=True)
# error text
self.console_text.tag_configure("error", foreground="#ff5959")
self.console_text.config(state='disabled')
self.window.withdraw()
except Exception as e:
with open("console_error.log", "a") as f:
f.write(f"Error setting up console UI: {e}\n")
class NullOutput:
def write(self, text):
pass
def flush(self):
pass
def setup_redirection(self):
try:
if sys.stdout is None:
sys.stdout = self.NullOutput()
if sys.stderr is None:
sys.stderr = self.NullOutput()
sys.stdout.write = self.write_console
sys.stderr.write = self.write_console
except Exception as e:
with open("console_error.log", "a") as f:
f.write(f"Error setting up redirection: {e}\n")
def write_console(self, text):
try:
if self.console_text is not None:
self.console_text.config(state='normal')
# Apply red color to error messages
tag = "error" if "Error" in text else None
self.console_text.insert("end", text, tag)
self.console_text.see("end")
self.console_text.config(state='disabled')
self.console_text.update()
with open("output.log", "a") as f:
f.write(f"{text}")
except Exception as e:
with open("console_error.log", "a") as f:
f.write(f"Error in write_console: {e}\n")
def clear_console(self):
try:
if self.console_text is not None:
self.console_text.config(state='normal')
self.console_text.delete("1.0", "end")
self.console_text.config(state='disabled')
except Exception as e:
self.write_console(f"Error processing clear_console: {e}\n")
def copy_console(self):
try:
if self.console_text is not None:
text = self.console_text.get("1.0", "end-1c")
app.clipboard_clear()
app.clipboard_append(text)
except Exception as e:
self.write_console(f"Error processing copy_console: {e}\n")
def toggle(self):
if self.window is not None and self.window.winfo_exists():
if self.window.state() == 'withdrawn':
self.window.deiconify()
self.window.lift()
else:
self.window.withdraw()
# controlling window transparency
def change_transparency(value, window):
try:
window.attributes("-alpha", float(value))
except Exception as e:
print(f"Error processing change_transparency: {e}")
clickthroughlabel = None
playback_live = False
def order_playback(event=None, cooldown=None):
global clickthroughlabel, playback_live, hwnd
after_id = None
try:
if order_window is None or not order_window.winfo_exists() or order_window.state() == 'withdrawn':
print("Order window is not open. Open the Order window to enable playback.")
return
if order is None or not order:
print("No order available. Solve a puzzle first.")
return
if not playback_live:
playback_live = True
order_window.lift()
order_window.focus_force()
order_window.update_idletasks()
if cooldown is None:
cooldown = settings["order_cooldown"]
# Enable clickthrough
hwnd = windll.user32.GetForegroundWindow() # declare only once here!!!!!
style = windll.user32.GetWindowLongW(hwnd, -20) # GWL_EXSTYLE = -20
windll.user32.SetWindowLongW(hwnd, -20, style | 0x00000020) # WS_EX_TRANSPARENT
clickthroughlabel.configure(text="Clickthrough Enabled", text_color="#50ff6d")
label_order = []
for i in range(5):
for j in range(5):
text = labels[i][j].cget("text")
if text and text.isdigit() and int(text) in order.values():
label_order.append((int(text), labels[i][j]))
label_order.sort(key=lambda x: x[0])
def highlight_sequence(idx):
global playback_live
nonlocal after_id, label_order, cooldown
if not playback_live:
return
if idx >= len(label_order):
style = windll.user32.GetWindowLongW(hwnd, -20)
windll.user32.SetWindowLongW(hwnd, -20, style & ~0x00000020) # Remove WS_EX_TRANSPARENT
clickthroughlabel.configure(text="Clickthrough Disabled", text_color='#ffa8a8')
windll.user32.UpdateWindow(hwnd)
playback_live = False
after_id = None
print("Playback completed.")
return
order_num, label = label_order[idx]
original_color = label.cget("fg_color")
label.configure(fg_color="#cc00ff")
def unhighlight_and_next():
nonlocal after_id
label.configure(fg_color=original_color)
highlight_sequence(idx + 1)
after_id = app.after(cooldown, unhighlight_and_next)
highlight_sequence(0)
print(f"Playback started for {len(label_order)} labels with cooldown of {cooldown}ms")
else:
playback_live = False
if after_id is not None:
app.after_cancel(after_id)
after_id = None
for i in range(5):
for j in range(5):
labels[i][j].configure(fg_color="#025c9d")
style = windll.user32.GetWindowLongW(hwnd, -20)
windll.user32.SetWindowLongW(hwnd, -20, style & ~0x00000020) # Remove WS_EX_TRANSPARENT
clickthroughlabel.configure(text="Clickthrough Disabled", text_color='#ffa8a8')
windll.user32.UpdateWindow(hwnd)
print("Playback stopped.")
except Exception as e:
print(f"Error processing order_playback: {e}")
labels = []
order_window = None
def open_order():
try:
global order_window, clickthroughlabel, labels
if order_window is not None and order_window.winfo_exists():
order_window.lift()
order_window.focus_force()
return
window, mainframe, titlebar = create_subwindow("order_window_location")
frame = ctk.CTkFrame(mainframe, fg_color='transparent')
frame.pack(padx=5, pady=5)
grid = ctk.CTkFrame(frame)
grid.pack()
labels = []
for i in range(5):
row_labels = []
for j in range(5):
label = ctk.CTkLabel(grid,
justify="center",
text="",
fg_color="#025c9d",
font=("", 16, "bold"))
label.grid(row=i, column=j, padx=1, pady=1, sticky='nsew')
row_labels.append(label)
labels.append(row_labels)
cell_size = (settings["order_window_size"] - 20) // 5
for row in labels:
for label in row:
label.configure(width=cell_size,
height=cell_size,
font=("", max(12, cell_size // 4), "bold"))
transparency_slider = ctk.CTkSlider(mainframe,
width=200,
height=5,
from_=0.1,
to=1,
number_of_steps=10,
command=lambda value: change_transparency(value, window))
window.attributes("-alpha", 0.73)
transparency_slider.set(0.7)
transparency_slider.pack(pady=(10, 5))
clickthroughlabel = ctk.CTkLabel(mainframe, text="Clickthrough disabled", text_color='#ffa8a8')
clickthroughlabel.pack(pady=(0, 10))
resize_button = ctk.CTkButton(mainframe,
width=20,
height=20,
text="➘",
font=("", 12, "bold"),
fg_color="#006ec9",
hover_color="#0080ff",
text_color="#ffffff",
corner_radius=2,
cursor="size_nw_se")
resize_button.place(relx=1.0, rely=1.0, anchor='se', x=-5, y=-5)
resize_start_x = None
resize_start_y = None
resize_start_w = None
def on_resize_press(event):
nonlocal resize_start_x, resize_start_y, resize_start_w
resize_start_x = event.x_root
resize_start_y = event.y_root
resize_start_w = window.winfo_width()
def on_resize_drag(event):
nonlocal resize_start_x, resize_start_y, resize_start_w
if resize_start_x is None:
return
delta_x = event.x_root - resize_start_x
new_width = max(200, resize_start_w + delta_x)
max_allowed = int(screen_h * 0.9)
new_width = min(new_width, max_allowed)
new_height = new_width + 90
window.geometry(f"{new_width}x{new_height}")
cell_size = (new_width - 20) // 5
for row in labels:
for label in row:
label.configure(width=cell_size,
height=cell_size,
font=("", max(12, cell_size // 4), "bold"))
try:
if OrderSizeValue is not None and OrderSizeValue.winfo_exists():
OrderSizeValue.delete(0, "end")
OrderSizeValue.insert(0, str(new_width))
except:
pass
settings["order_window_size"] = new_width
def on_resize_release(event):
nonlocal resize_start_x, resize_start_y
resize_start_x = None
resize_start_y = None
resize_button.bind("<Button-1>", on_resize_press)
resize_button.bind("<B1-Motion>", on_resize_drag)
resize_button.bind("<ButtonRelease-1>", on_resize_release)
def on_window_configure(event):
if event.widget != window:
return
current_w = event.width
current_h = event.height
if abs(current_w - settings["order_window_size"]) < 5:
return
clamped_w = max(200, min(current_w, int(screen_h * 0.9)))
if clamped_w != current_w:
new_h = clamped_w + 90
window.geometry(f"{clamped_w}x{new_h}")
return
settings["order_window_size"] = clamped_w
try:
if OrderSizeValue is not None and OrderSizeValue.winfo_exists():
OrderSizeValue.delete(0, "end")
OrderSizeValue.insert(0, str(clamped_w))
except:
pass
cell_size = (clamped_w - 20) // 5
for row in labels:
for label in row:
label.configure(width=cell_size,
height=cell_size,
font=("", max(12, cell_size // 4), "bold"))
window.bind("<Configure>", on_window_configure)
window.withdraw()
order_window = window
except Exception as e:
print(f"Error processing open_order: {e}\n")
puzzle4_labels = []
puzzle4_window = None
def open_puzzle4():
try:
global puzzle4_window, puzzle4_labels
if puzzle4_window is not None and puzzle4_window.winfo_exists():
puzzle4_window.lift()
puzzle4_window.focus_force()
return
window, mainframe, titlebar = create_subwindow("puzzle4_window_location")
frame = ctk.CTkFrame(mainframe, fg_color='transparent')
frame.pack()
grid = ctk.CTkFrame(frame)
grid.pack(padx=5, pady=5)
for i in range(5):
puzzle4_row_labels = []
for j in range(5):
label = ctk.CTkLabel(grid,
width=100,
height=30,
justify="center",
text="",
fg_color="#025c9d",
font=("", 16, "bold"),
cursor="hand2")