-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathczeditorpygame.py
2316 lines (2027 loc) · 95.2 KB
/
czeditorpygame.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
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
from tkinter import *
import tkinter.font as tkfont
from PIL import ImageTk, Image, ImageDraw, ImageChops, ImageFilter
import time
from generate import *
from pydub import AudioSegment
from pydub.playback import _play_with_simpleaudio
import functools
import concurrent.futures
import os
from base64 import *
from tkinter.filedialog import *
import pygame
# import inspect
import wavfile
# import pprint
# import palanteer
import copy
import numpy as np
from scipy.spatial.transform import Rotation as R
import sys
import traceback
from math import pi
globalcache = {}
framecache = {}
keyframecache = {}
filledframes = {}
openedimages = {}
generated = {"xp": {}, "ubuntu": {}, "95": {}, "macwindow": {}, "7": {}, "custom": {}}
emptyimg = Image.new("RGBA", (100, 100), (255, 0, 255))
def win7bezierapprox(x):
return 1.08334 * x ** 0.817775 - 0.0822632 * x ** 1.48583
def win7bezierapproxclose(x):
return 0.922396 * x ** 1.234158 + 0.0768603 * x ** 11.3377
def linear(x):
return x
def cubiceaseout(x):
return 1 - (1 - x) ** 3
def smooth(x):
return 3 * x ** 2 - 2 * x ** 3
def easeout(x):
return -x * (x - 2)
def openimage(s):
if s in openedimages:
return openedimages[s]
openedimages[s] = Image.open(s)
return openedimages[s]
def find_coeffs(pa, pb):
matrix = []
for p1, p2 in zip(pa, pb):
matrix.append([p1[0], p1[1], 1, 0, 0, 0, -p2[0] * p1[0], -p2[0] * p1[1]])
matrix.append([0, 0, 0, p1[0], p1[1], 1, -p2[1] * p1[0], -p2[1] * p1[1]])
A = np.matrix(matrix, dtype=np.float)
B = np.array(pb).reshape(8)
res = np.dot(np.linalg.inv(A.T * A) * A.T, B)
return np.array(res).reshape(8)
def rotate(vec, angles):
angle = np.array(angles / 180 * pi)
# print(angles)
rot = R.from_rotvec(angle)
# print(vec)
return rot.apply(vec)
def translaterotateproject(width, height, position, rotation, origin, corner, perspective=250):
vec = np.array((width * corner[0] - (width * origin[0]) / 2, height * corner[1] - (height * origin[1]) / 2, 0))
rotated = rotate(vec, rotation)
z = 1 + rotated[2] / perspective + position[2]
projected = [(rotated[0] - width * (0.5 - origin[0] / 2)) / z + width / 2 + position[0], (rotated[1] - height * (0.5 - origin[1] / 2)) / z + height / 2 + position[1]]
return projected
def CreateCustomWindowAnimation(image, time=1, startpos=(0, 0, 0), startrotation=(0, 0, 0), origin=(0.5, 0.5, 0)):
# print("theimage,",image)
t = min(1, max(0, time))
startrotation = np.array(startrotation)
startpos = np.array(startpos)
NW = translaterotateproject(w(image), h(image), startpos * (1 - t), startrotation * (1 - t), origin, (0, 0, 0))
NE = translaterotateproject(w(image), h(image), startpos * (1 - t), startrotation * (1 - t), origin, (1, 0, 0))
SW = translaterotateproject(w(image), h(image), startpos * (1 - t), startrotation * (1 - t), origin, (0, 1, 0))
SE = translaterotateproject(w(image), h(image), startpos * (1 - t), startrotation * (1 - t), origin, (1, 1, 0))
coeffs = find_coeffs([NW, NE, SE, SW], [[0, 0], [w(image), 0], [w(image), h(image)], [0, h(image)]])
return coeffs
def ExecuteCustomWindowAnimation(image, coeffs, time, wallpaper=None, pos=None, align=None):
t = min(1, max(0, time))
image = image.transform(image.size, Image.PERSPECTIVE, coeffs, Image.LINEAR);
no = image.copy()
no.putalpha(0)
image = ImageChops.blend(no, image, t)
if wallpaper:
image = put(wallpaper.copy(), image.copy(), pos[0], pos[1], align)
return image
def Composite7(img, GlassMask, time, startpos, startrotation, origin, wallpaper, pos, align):
wallpaper = wallpaper.copy()
GlassImg = openimage("7/Glass.png")
WithBorder = put(Image.new("RGBA", (800, 602), (0, 0, 0, 0)), GlassImg.resize(wallpaper.size, 0), int(-pos[0] + w(img) / 16 - wallpaper.size[0] / 16 + pos[0] / 8), -pos[1])
GlassMask = put(Image.new("RGBA", img.size, (255, 255, 255, 0)), GlassMask, 14, 14)
WithBorder = ImageChops.multiply(WithBorder, GlassMask)
IMAGE = put(WithBorder, img, 0, 0)
coeffs = CreateCustomWindowAnimation(IMAGE, time, startpos, startrotation, origin)
IMAGE = ExecuteCustomWindowAnimation(IMAGE, coeffs, time)
GlassMask = ExecuteCustomWindowAnimation(GlassMask, coeffs, time)
Blur = wallpaper.filter(ImageFilter.GaussianBlur(radius=12))
masked = ImageChops.multiply(put(Image.new("RGBA", wallpaper.size, (0, 0, 0, 0)), GlassMask, pos[0] - 14, pos[1] - 14, align), Blur)
masked = put(masked, IMAGE, pos[0] - 14, pos[1] - 14, align)
wallpaper.alpha_composite(masked)
return wallpaper
composites = {
"xp": (lambda img, mask, time, startpos, startrotation, origin, wallpaper, pos, align: ExecuteCustomWindowAnimation(
img, CreateCustomWindowAnimation(img, time, startpos, startrotation, origin), time, wallpaper, pos, align
)),
"7": (lambda img, mask, time, startpos, startrotation, origin, wallpaper, pos, align: Composite7(img, mask, time, startpos, startrotation, origin, wallpaper, pos, align)),
"custom": (lambda img, mask, time, startpos, startrotation, origin, wallpaper, pos, align: ExecuteCustomWindowAnimation(
img, CreateCustomWindowAnimation(img, time, startpos, startrotation, origin), time, wallpaper, pos, align
))
}
def CompositeWindow(img, mask, os, time, startpos, startrotation, origin, wallpaper, pos, align, close, closetime, endpos, endrotation, endorigin, closetimingfunction, timingfunction):
global composites
if close:
time = 1 - closetimingfunction(closetime)
return composites[os](img, mask, time, endpos, endrotation, endorigin, wallpaper, pos, align)
else:
time = timingfunction(time)
return composites[os](img, mask, time, startpos, startrotation, origin, wallpaper, pos, align)
class Window():
def __getimage(self, composite=False, pos=(0, 0), time=1, align="", close=False, generated=None):
mask = None
if generated is None:
if self.os == "xp":
new = CreateXPWindow(
0, 0,
captiontext=self.title,
active=self.active,
erroriconpath=self.icons["xp"][self.icon],
errortext=self.text,
button1=self.buttons[0],
button2=self.buttons[1],
button3=self.buttons[2],
button1style=self.buttonstyles[0],
button2style=self.buttonstyles[1],
button3style=self.buttonstyles[2]
)
elif self.os == "macwindoid":
new = CreateMacWindoid(icon=self.icons["macwindoid"][self.icon], text=self.text, collapsed=self.collapsed)
elif self.os == "ubuntu":
new = CreateUbuntuWindow(icon=self.icons["ubuntu"][self.icon], bigtext=self.text, text=self.subtext, title=self.title, buttons=self.buttons, active=self.active)
elif self.os == "95":
new = Create95Window(icon=self.icons["95"][self.icon], text=self.text, title=self.title, buttons=self.buttons, active=self.active, closebutton=self.closebutton)
elif self.os == "macwindow":
new = CreateMacWindow(
0, 0,
title=self.title,
icon=self.icons["macwindow"][self.icon],
errortext=self.text,
button1=self.buttons[0],
button2=self.buttons[1],
button3=self.buttons[2],
button1style=self.buttonstyles[0],
button2style=self.buttonstyles[1],
button3style=self.buttonstyles[2],
button1default=self.buttondefaults[0],
button2default=self.buttondefaults[1],
button3default=self.buttondefaults[2]
)
elif self.os == "7":
temp = []
for i in range(len(self.buttons)):
if self.buttons[i] != "":
temp.append([self.buttons[i], self.buttonstyles[i]])
new, mask = Create7Window(icon=self.icons["7"][self.icon], text=self.text, title=self.title, buttons=temp, active=self.active)
elif self.os == "custom":
new = self.img
else:
new = generated[0].copy()
mask = generated[1].copy()
# print("Animate",self.animate)
# print("new",new)
if mask is None:
mask = new.split()[-1]
# print("timingfucntion:")
# print(self.closetimingfunction)
if composite:
new = CompositeWindow(
new, mask, self.os, time=min(1, max(0, (time + 0.016666666) / max(0.01, self.animationlength))), startpos=self.startpos, startrotation=self.startrotation, origin=self.origin,
wallpaper=composite, pos=pos, align=align, close=close, closetime=min(1, max(0, (time + 0.01666666) / max(0.01, self.animationcloselength))), endpos=self.endpos,
endrotation=self.endrotation, endorigin=self.endorigin, closetimingfunction=self.closetimingfunction, timingfunction=self.timingfunction
)
# new = CreateCustomWindowAnimation(new,time/self.animationlength,self.startpos,self.startrotation,self.origin,wallpaper=composite,pos=pos,align=align,close=close)
return new, mask
def __init__(
self, os="xp", text="", subtext="", icon=0, title="", buttons=["", "", ""], buttonstyles=[0, 0, 0], buttondefaults=[False, False, False], bar=True, closebutton=True, active=True,
collapsed=False, img="", startpos=(0, 0, 0), animate=True, startrotation=(0, 0, 0), animationlength=0.016666666, origin=(0, 0, 0), animationcloselength=0.0166666666,
timingfunction=win7bezierapprox, endpos=(0, 0, 0), endrotation=(0, 0, 0), endorigin=(0, 0, 0), closetimingfunction=win7bezierapproxclose
):
global emptyimg
self.os = os
self.active = active
self.text = text
self.subtext = subtext
self.title = title
self.icon = icon
self.buttons = buttons
self.buttonstyles = buttonstyles
self.buttondefaults = buttondefaults
self.bar = bar
self.closebutton = closebutton
self.collapsed = collapsed
self.icons = {
"xp": [
"xp/Critical Error.png",
"xp/Exclamation.png",
"xp/Information.png",
"xp/Question.png"],
"macwindoid": ["",
"mac/Speech Bubble"],
"ubuntu": ["ubuntu/Error.png",
"ubuntu/Exclamation.png",
"ubuntu/Attention.png",
"ubuntu/Information.png",
"ubuntu/Question Mark.png"],
"95": ["95/Critical Error.png",
"95/Exclamation.png.png",
"95/Information.png",
"95/Question.png"],
"macwindow": ["mac/hand.png",
"mac/Exclamation.png",
"mac/Speech Bubble.png"],
"7": ["7/Critical Error.png",
"7/Exclamation.png",
"7/Information.png",
"7/Question Mark.png"]
}
self.cancomposite = self.os in ["7", "custom"]
self.imgstr = img
if self.imgstr:
self.img = openimage(self.imgstr)
else:
self.img = emptyimg.copy()
self.startpos = startpos
self.animate = animate
self.startrotation = startrotation
self.animationlength = animationlength
self.animationcloselength = animationcloselength
self.origin = origin
self.hashstring = self.os + "," + str(self.active) + "," + self.text + "," + self.subtext + "," + str(self.icon) + "," + self.title + "," + str(self.buttons) + "," + str(
self.buttonstyles
) + "," + str(self.buttondefaults) + "," + str(self.bar) + "," + str(self.closebutton) + "," + str(self.collapsed) + "," + str(self.imgstr)
self.timingfunction = timingfunction
self.endpos = endpos
self.endrotation = endrotation
self.endorigin = endorigin
self.closetimingfunction = closetimingfunction
def image(self, composite=None, pos=None, time=1, align="00", close=False):
global generated
self.hashstring = self.os + "," + str(self.active) + "," + self.text + "," + self.subtext + "," + str(self.icon) + "," + self.title + "," + str(self.buttons) + "," + str(
self.buttonstyles
) + "," + str(self.buttondefaults) + "," + str(self.bar) + "," + str(self.closebutton) + "," + str(self.collapsed) + "," + str(self.imgstr)
if self.hashstring not in generated[self.os]:
generated[self.os][self.hashstring] = self.__getimage()
if composite:
return self.__getimage(composite, pos, time, align, close, generated[self.os][self.hashstring])[0]
return generated[self.os][self.hashstring][0]
def copy(self):
return Window(
self.os, self.text, self.subtext, self.icon, self.title, self.buttons, self.buttonstyles, self.buttondefaults, self.bar, self.closebutton, self.active, self.collapsed,
img=self.imgstr, startpos=self.startpos, animate=self.animate, startrotation=self.startrotation, animationlength=self.animationlength, origin=self.origin,
animationcloselength=self.animationcloselength, timingfunction=self.timingfunction, endpos=self.endpos, endrotation=self.endrotation, endorigin=self.endorigin,
closetimingfunction=self.closetimingfunction
)
def __str__(self):
return self.hashstring
def savestr(self):
return b64encode(self.os.encode("ascii")).decode("ascii") + "," + \
b64encode(str(self.active).encode("ascii")).decode("ascii") + "," + \
b64encode(self.text.encode("ascii")).decode("ascii") + "," + \
b64encode(self.subtext.encode("ascii")).decode("ascii") + "," + \
b64encode(str(self.icon).encode("ascii")).decode("ascii") + "," + \
b64encode(self.title.encode("ascii")).decode("ascii") + "," + \
b64encode(str(self.buttons).encode("ascii")).decode("ascii") + "," + \
b64encode(str(self.buttonstyles).encode("ascii")).decode("ascii") + "," + \
b64encode(str(self.buttondefaults).encode("ascii")).decode("ascii") + "," + \
b64encode(str(self.bar).encode("ascii")).decode("ascii") + "," + \
b64encode(str(self.closebutton).encode("ascii")).decode("ascii") + "," + \
b64encode(str(self.collapsed).encode("ascii")).decode("ascii") + "," + \
b64encode(self.imgstr.encode("ascii")).decode("ascii") + "," + \
b64encode(str(self.startpos).encode("ascii")).decode("ascii") + "," + \
b64encode(str(self.animate).encode("ascii")).decode("ascii") + "," + \
b64encode(str(self.startrotation).encode("ascii")).decode("ascii") + "," + \
b64encode(str(self.animationlength).encode("ascii")).decode("ascii") + "," + \
b64encode(str(self.origin).encode("ascii")).decode("ascii") + "," + \
b64encode(str(self.endpos).encode("ascii")).decode("ascii") + "," + \
b64encode(str(self.endrotation).encode("ascii")).decode("ascii") + "," + \
b64encode(str(self.endorigin).encode("ascii")).decode("ascii") + "," + \
b64encode(str(self.animationcloselength).encode("ascii")).decode("ascii") + "," + \
b64encode(dictindex(timingfunctions, presets[currentpreset].timingfunction).encode("ascii")).decode("ascii") + "," + \
b64encode(dictindex(timingfunctions, presets[currentpreset].closetimingfunction).encode("ascii")).decode("ascii")
def getkeyframeswhosedatais(param, value):
global keyframes
returnids = []
i = 0
for keyframe in keyframes:
if param in keyframe.data:
if keyframe.data[param] == value:
returnids.append(i)
i += 1
return returnids
def getkeyframeswhoseprivatedatais(param, value):
global keyframes
returnids = []
i = 0
for keyframe in keyframes:
if param in keyframe.privatedata:
if keyframe.privatedata[param] == value:
returnids.append(i)
i += 1
return returnids
def getkeyframeswhosedatacontains(param, value):
global keyframes
returnids = []
i = 0
for keyframe in keyframes:
if param in keyframe.data:
if value in keyframe.data[param]:
returnids.append(i)
i += 1
return returnids
class Keyframe():
def __init__(self, frame, x, y, window, align, keyframetype="error", data={}, privatedata={}):
global currentdirection
global keyframeview
global keyframes
self.window = window.copy()
self.type = keyframetype
self.data = data.copy()
if self.type == "remove":
if "remove" not in data:
self.data["remove"] = [keyframes[i].frame for i in keyframeview.selected]
# print(keyframeview.selected)
removedframes = keyframeview.selected
else:
removedframes = getkeyframeswhoseframesare(self.data["remove"])
self.window.animationlength = 0.01666666
for i in removedframes:
self.window.animationlength = max(self.window.animationlength, keyframes[i].window.animationcloselength)
keyframes[i].privatedata["getclosedby"] = frame
self.windowinactive = window.copy()
self.windowinactive.active = False
self.frame = frame
self.start = frame / 60
self.x = x
self.y = y
self.align = align
self.close = False
self.closeframe = 0
self.privatedata = privatedata.copy()
if "getclosedby" not in privatedata:
self.privatedata["getclosedby"] = None
def __str__(self):
global keyframeview
return str(self.window) + "," + str(self.x) + "," + str(self.y) + "," + self.align + "," + str(self.frame) + "," + str(self.close) + "," + str(self.closeframe) + "," + str(
self.type
) + "," + str(self.data)
def strframe(self, frame):
return str(self.window) + "," + str(self.x) + "," + str(self.y) + "," + self.align + (
"," + str(max(0, min(int(self.window.animationlength * 60), frame - self.frame))) if self.window.cancomposite else "") + "," + str(self.close) + "," + (
str(max(0, min(int(self.window.animationcloselength * 60), frame - self.closeframe))) if self.window.cancomposite else "") + "," + str(self.type) + "," + str(self.data)
def frametosavestr(frame):
return frame.window.savestr() + "|" + str(frame.frame) + "|" + str(frame.x) + "|" + str(frame.y) + "|" + frame.align + "|" + str(frame.type) + "|" + str(list(frame.data.items()))
def stringtobool(s):
return True if s == "True" else False
def stringtolist(s):
# print("enter string:",s)
s = s.strip()
s = s[1:-1]
# print("clipped string:",s)
s = s.split(",")
# print("s",s)
finallist = []
k = 0
while k < len(s):
i = s[k]
# print(i)
i = i.strip()
if not i:
k += 1
continue
if i[0] == "[":
innerlist = ""
while True:
innerlist += s[k]
# print("innerlist",innerlist)
if s[k][-1] == "]":
break
innerlist += ","
k += 1
# print("innerlist",innerlist)
finallist.append(stringtolist(innerlist))
elif i[0] == "(":
innerlist = ""
while True:
innerlist += s[k]
if s[k][-1] == ")":
break
innerlist += ","
k += 1
# print("innerlist",innerlist)
finallist.append(stringtolist(innerlist))
elif i[0] == "'":
if i == "''":
finallist.append("")
else:
finallist.append(i[1:-1])
elif i == "True" or i == "False":
finallist.append(stringtobool(i))
elif "." in i:
finallist.append(float(i))
else:
finallist.append(int(i))
k += 1
return finallist
def savestrtowindow(savestr):
array = savestr.split(",")
notcustom = Window(
os=b64decode(array[0].encode("ascii")).decode("ascii"),
text=b64decode(array[2].encode("ascii")).decode("ascii"),
subtext=b64decode(array[3].encode("ascii")).decode("ascii"),
icon=int(b64decode(array[4].encode("ascii")).decode("ascii")),
title=b64decode(array[5].encode("ascii")).decode("ascii"),
buttons=stringtolist(b64decode(array[6].encode("ascii")).decode("ascii")),
buttonstyles=stringtolist(b64decode(array[7].encode("ascii")).decode("ascii")),
buttondefaults=stringtolist(b64decode(array[8].encode("ascii")).decode("ascii")),
bar=stringtobool(b64decode(array[9].encode("ascii")).decode("ascii")),
closebutton=stringtobool(b64decode(array[10].encode("ascii")).decode("ascii")),
collapsed=stringtobool(b64decode(array[11].encode("ascii")).decode("ascii"))
)
notcustom.imgstr = b64decode(array[12].encode("ascii")).decode("ascii")
if notcustom.imgstr:
notcustom.img = Image.open(notcustom.imgstr)
if len(array) == 18:
if notcustom.os == "custom":
notcustom.startpos = tuple(stringtolist(b64decode(array[13].encode("ascii")).decode("ascii")))
notcustom.animate = stringtobool(b64decode(array[14].encode("ascii")).decode("ascii"))
notcustom.startrotation = tuple(stringtolist(b64decode(array[15].encode("ascii")).decode("ascii")))
notcustom.animationlength = float(b64decode(array[16].encode("ascii")).decode("ascii"))
notcustom.origin = tuple(stringtolist(b64decode(array[17].encode("ascii")).decode("ascii")))
elif notcustom.os == "7":
notcustom.startpos = (0, -0.017, 0.1)
notcustom.animate = True
notcustom.startrotation = (5, 0, 0)
notcustom.origin = (0, 1, 0)
notcustom.animationlength = 0.25
else:
notcustom.startpos = tuple(stringtolist(b64decode(array[13].encode("ascii")).decode("ascii")))
notcustom.animate = stringtobool(b64decode(array[14].encode("ascii")).decode("ascii"))
notcustom.startrotation = tuple(stringtolist(b64decode(array[15].encode("ascii")).decode("ascii")))
notcustom.animationlength = float(b64decode(array[16].encode("ascii")).decode("ascii"))
notcustom.origin = tuple(stringtolist(b64decode(array[17].encode("ascii")).decode("ascii")))
notcustom.endpos = tuple(stringtolist(b64decode(array[18].encode("ascii")).decode("ascii")))
notcustom.endrotation = tuple(stringtolist(b64decode(array[19].encode("ascii")).decode("ascii")))
notcustom.endorigin = tuple(stringtolist(b64decode(array[20].encode("ascii")).decode("ascii")))
notcustom.animationcloselength = float(b64decode(array[21].encode("ascii")).decode("ascii"))
notcustom.timingfunction = timingfunctions[b64decode(array[22].encode("ascii")).decode("ascii")]
notcustom.closetimingfunction = timingfunctions[b64decode(array[23].encode("ascii")).decode("ascii")]
return notcustom
# print(stringtolist(str([["hi",2,True],True,5,"hello"])))
def savestrtoframe(savestr):
array = savestr.split("|")
# frame,x,y,window,align,keyframetype="error",data={}
if len(array) == 7:
thedata = stringtolist(array[6])
return Keyframe(int(array[1]), int(array[2]), int(array[3]), savestrtowindow(array[0]), array[4], array[5], {i: j for i, j in thedata})
return Keyframe(int(array[1]), int(array[2]), int(array[3]), savestrtowindow(array[0]), array[4])
def savekeyframes(path):
global keyframes
global audiopath
global wallpaperpath
savestr = b64encode(audiopath.encode("ascii")).decode("ascii") + "," + b64encode(wallpaperpath.encode("ascii")).decode("ascii")
keyframeslen = len(keyframes)
for frame in keyframes:
savestr += "\n" + frametosavestr(frame)
with open(path, "w") as file:
file.write(savestr)
def loadkeyframes(path):
global keyframes
global keyframecache
global closed
global executor
global executor2
global workersamount
global audiopath
global wallpaperpath
global filledframes
keyframes = []
with open(path, "r") as file:
savestr = file.read()
savestr = savestr.split("\n")
metadata = savestr[0].split(',')
audiopath = b64decode(metadata[0].encode("ascii")).decode("ascii")
wallpaperpath = b64decode(metadata[1].encode("ascii")).decode("ascii")
savestr.pop(0)
for i in savestr:
keyframes.append(savestrtoframe(i))
keyframecache = {}
filledframes = {}
# closed = True
# executor.shutdown()
# closed = False
# executor = concurrent.futures.ThreadPoolExecutor(max_workers=2)
# executor.submit(cacheframesmanager)
# executor.submit(cachevisualizationjob)
# cachestart([i.frame for i in keyframes])
updatesound()
updatewallpaper()
updatekeyframeview()
markerfont = ImageFont.truetype("tahoma.ttf", 8)
class Keyframeview():
def __init__(self):
self.min = 0
self.max = 10
self.cursor = 2
self.cursorimg = Image.open("Cursor.png").convert("RGBA")
self.keyframeimg = Image.open("Keyframe.png").convert("RGBA")
self.keyframeghostimg = Image.open("KeyframeGhost.png").convert("RGBA")
self.keyframeActiveimg = Image.open("KeyframeActive.png").convert("RGBA")
self.keyframeSelectedimg = Image.open("KeyframeSelected.png").convert("RGBA")
self.grid = Image.open("grid.png").convert("RGBA")
self.minorgrid = Image.open("minorgrid.png").convert("RGBA")
self.width = 800
self.lastclickpos = 0
self.zoom = self.max - self.min
self.m1pressed = False
self.keyframeimage = None
self.holdingframe = None
self.movedpos = None
self.active = None
self.selected = []
self.blank = Image.new("RGBA", (self.width, 50), (255, 192, 192))
self.currentimg = self.blank.copy()
self.gridimg = self.blank.copy()
def getcoord(self, x):
return floor(((x - self.min) / (self.zoom)) * self.width)
def gettime(self, x):
return (x / self.width) * (self.max - self.min) + self.min
def image(self):
global keyframes
global temposnap
global playing
if temposnap:
keyview = self.gridimg.copy()
else:
keyview = self.blank.copy()
keyview.alpha_composite(self.cursorimg, (self.getcoord(self.cursor), 0))
# print(self.active,self.selected)
j = 0
for i in keyframes:
if i.start > self.min and i.start < self.max:
keyview.alpha_composite(self.keyframeActiveimg if j == self.active else (self.keyframeSelectedimg if j in self.selected else self.keyframeimg), (self.getcoord(i.start) - 4, 19))
j += 1
self.currentimg = keyview.copy()
return keyview
def changecursorpos(self, event):
global keyframepanel
global starttime
global tempovalue
global temposnap
global holdingshift
if self.holdingframe is not None and self.movingcursor:
movekeyframes(self.selected, round(self.movedpos - self.starthold))
self.active = None
self.selected = []
clickpos = self.gettime(event.x)
# print(event)
self.cursor = clickpos
if temposnap.get() == 1:
self.cursor = round(clickpos * int(tempovalue.get()) / 60 * 4) / int(tempovalue.get()) * 60 / 4
self.cursor = round(self.cursor * 60) / 60
# print(self.cursor)
# keyframepanel.image = self.image()
nearframes = []
if (self.lastclickpos == clickpos):
nextkeyframe = getnextkeyframe(int(self.cursor * 60))
if not checkcache(nextkeyframe)[4]:
cachestart(nextkeyframe)
if not holdingshift:
self.active = None
for i in keyframes:
if i.start > self.min and i.start < self.max:
if abs(self.getcoord(i.start) - event.x) < 60:
nearframes.append(i.start)
if nearframes:
closestdistance = 9999
closest = 999
for i in nearframes:
if abs(self.getcoord(i) - event.x) < closestdistance:
closestdistance = abs(self.getcoord(i) - event.x)
closest = i
self.cursor = closest
starttime = time.time() - keyframeview.cursor
self.lastclickpos = clickpos
self.keyframeimage = self.image()
self.m1pressed = False
self.holdingframe = None
self.movingcursor = False
if (self.getkeyframeundercursor(event) is None and not holdingshift):
self.selected = [self.active]
updatekeyframeview()
updatescreen()
playaudiofromtimestamp(self.cursor)
def updategrid(self):
global tempovalue
global temposnap
global playing
global markers
global hertz
global markerfont
keyview = Image.new("RGBA", (self.width, 50), (255, 192, 192))
keypix = ImageDraw.Draw(keyview)
if temposnap.get() == 1 and not playing:
# print(int((self.max-self.min)/60*int(tempovalue.get())*4))
value = 0
i = 0
mult = 60 / int(tempovalue.get()) / 4
while value < self.width:
value = i * mult
getcord = self.getcoord(value)
# keyview.paste(self.grid if i&3 == 0 else self.minorgrid,(self.getcoord(value),0))
keypix.line([getcord, 0, getcord, 49], fill=(245, 165, 165) if i & 3 == 0 else (250, 180, 180))
i += 1
if markers:
i = 0
drawn = 0
for marker in markers:
i += 1
if marker["position"] / hertz < self.min - self.zoom / 6:
continue
if marker["position"] / hertz > self.max:
break
if drawn > 200:
break
getcord = self.getcoord(marker["position"] / hertz)
keypix.line([getcord, 0, getcord, 49], fill=(192, 192, 96))
labeltext = marker["label"].decode("ascii")
bbox = keypix.multiline_textbbox([getcord, 40], labeltext, font=markerfont)
bbox = (bbox[0], bbox[1], bbox[2], min(bbox[3], 49))
lightness = (i * 111) % 255
keypix.rectangle(bbox, fill=(255, lightness, lightness), outline=(255, 64, 64))
keypix.text([getcord, 40], labeltext, font=markerfont, fill=(0, 0, 0, 255))
drawn += 1
self.gridimg = keyview
def changezoom(self, event):
self.zoom = max(0.5, self.zoom - event.delta / 240)
self.min, self.max = [self.cursor - (self.max - self.min) / 2, self.cursor + (self.max - self.min) / 2]
self.min = max(0, self.cursor - self.zoom / 2)
self.max = self.zoom + self.min
self.updategrid()
updatekeyframeview()
# def update(self):
# global czepanel
# global keyframes
# currentframe = geterrors(self.cursor)
# fsf = ImageTk.PhotoImage(currentframe)
# czepanel.configure(image=fsf)
# czepanel.image = fsf
def moveby(self, value):
global tempovalue
global temposnap
if temposnap.get() == 1:
mult = 15 / int(tempovalue.get())
curbeat = round(self.cursor / mult) + value
# print(curbeat)
self.cursor = round(curbeat * mult * 60) / 60
else:
self.cursor = round(60 * self.cursor + value) / 60
def motion(self, event):
global tempovalue
global temposnap
if self.m1pressed and self.holdingframe is not None:
clickpos = round(self.gettime(event.x) * 60) / 60
self.movingcursor = True
if temposnap.get() == 1:
self.movedpos = round(clickpos * int(tempovalue.get()) / 15) / int(tempovalue.get()) * 15 * 60
else:
self.movedpos = clickpos * 60
temp = self.keyframeimage.copy()
temp.alpha_composite(self.keyframeghostimg, (self.getcoord(self.movedpos / 60) - 4, 19))
keyframeimage = ImageTk.PhotoImage(temp)
keyframepanel.configure(image=keyframeimage)
keyframepanel.image = keyframeimage
def button1pressed(self, event):
global keyframes
self.movingcursor = False
self.m1pressed = True
# frame = round(self.gettime(event.x)*60)
i = self.getkeyframeundercursor(event)
if i is not None:
self.starthold = keyframes[i].frame
self.holdingframe = i
self.active = i
if holdingshift:
if i not in self.selected:
self.selected.append(i)
else:
self.selected = [i]
def getkeyframeundercursor(self, pos):
global keyframes
if abs(pos.y - 25) < 5:
for i in range(len(keyframes)):
if abs(self.getcoord(keyframes[i].frame / 60) - pos.x) < 5:
# print(i)
return i
def getnextkeyframe(startframe):
global keyframes
lastgood = 0
for i in keyframes:
lastgood = i.frame
if i.frame > startframe:
break
return lastgood
errors = []
currentframeimg = Image.new("RGBA", (1280, 720), (8, 8, 8, 255))
currentwallpaper = Image.new("RGBA", (1280, 720), (8, 8, 8, 255))
def geterrors(time):
global keyframes
global currentframeimg
global currentwallpaper
global keyframecache
i = 0
frames, cachestr, notimportant, last, success, cacheimg = checkcache(round(time * 60))
if success:
currentframeimg = notimportant[0]
return cacheimg[0]
fillcache(notimportant, frames, cachestr, round(time * 60))
returnimg = keyframecache[cachestr][0]
currentframeimg = keyframecache[cachestr][1]
# print(returnimg)
return returnimg
playing = False
framestart = time.time()
currentframe = time.time() - framestart
framenumber = 0
starttime = time.time()
curtime = time.time() - starttime
lastframe = 0
stats = None
pygame.init()
windowgame = pygame.display.set_mode((1280, 720))
clockgame = pygame.time.Clock()
chosewindow = None
def getalignedpos(pos, align, size):
return (int(pos[0]) - (size[0] * int(align[0]) // 2), int(pos[1]) - (size[1] * int(align[1]) // 2))
def playback():
global playing
global keyframeview
global keyframepanel
global currentframe
global framestart
global framenumber
global curtime
global starttime
global timestampvar
global stats
global closed
global windowgame
global clockgame
global currentframeimg
global chosewindow
global snap
global currentdirection
global currentpreset
try:
pygame.fastevent.init()
starttime = time.time() - keyframeview.cursor
curtime = time.time() - starttime
pygameSurface = None
chosenwindowimageSurface = None
lastpos = None
while not closed:
clockgame.tick(60)
prevcurtime = curtime
if playing:
curtime = time.time() - starttime
keyframeview.cursor = round(curtime * 60) / 60
pygameSurface = geterrors(curtime)
else:
starttime = time.time() - keyframeview.cursor
curtime = time.time() - starttime
if curtime != prevcurtime:
pygameSurface = geterrors(curtime)
if not pygameSurface:
pygameSurface = geterrors(curtime)
windowgame.blit(pygameSurface, (0, 0))
for event in pygame.fastevent.get():
if event.type == pygame.QUIT:
closed = True
elif event.type == 1024 and not playing: # MouseMotion
chosenwindow = presets[currentpreset]
if chosenwindow != chosewindow:
chosenwindowimage = chosenwindow.image()
chosenwindowimageSurface = pygame.image.fromstring(chosenwindowimage.tobytes(), chosenwindowimage.size, "RGBA").convert_alpha()
lastpos = getalignedpos((round(event.pos[0] / snap) * snap, round(event.pos[1] / snap) * snap), currentdirection, chosenwindowimage.size)
elif event.type == 1025 and pygame.mouse.get_pressed(num_buttons=3)[0]: # MouseDown
createkeyframe(event.pos[0], event.pos[1])
updatekeyframeview()
elif event.type == 32785 and pygame.mouse.get_pressed(num_buttons=5)[0]: # FocusGained, basically MouseDown
createkeyframe(pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1])
updatekeyframeview()
elif event.type == 1027: # scroll
cascade(event.y)
elif event.type == 768: # keyboard
keyboard(event.scancode)
if chosenwindowimageSurface and not playing:
windowgame.blit(chosenwindowimageSurface, lastpos)
pygame.display.update()
# print("douing")
except Exception:
print("PYGAME ERROR:", sys.exc_info()[0](traceback.format_exc()))
print("end pygame")
def updatekeyframeviewduringplayback():
global playing
if playing:
updatekeyframeview()
timelineroot.after(30, updatekeyframeviewduringplayback)
holdingshift = True
def keyboard(event):
global playing
global keyframeview
global holdingshift
if event == 44: # space
play()
# print(playing)
elif event == 80:
keyframeview.moveby(-1)
updatescreen()
updatekeyframeview()
elif event == 79:
keyframeview.moveby(1)
updatescreen()
updatekeyframeview()
def keyboardtk(event):
global holdingshift
# print(event.keycode)
if event.keycode == 16:
holdingshift = True
elif event.keycode == 46: # delete
deletekeyframesparam(keyframeview.selected)
updatescreen()
updatekeyframeview()
elif event.keycode == 32: # space
play()
elif event.keycode == 37:
keyframeview.moveby(-1)
updatescreen()
updatekeyframeview()
elif event.keycode == 39:
keyframeview.moveby(1)
updatescreen()
updatekeyframeview()
def keyboardrelease(event):
global holdingshift
if event.keycode == 16:
holdingshift = False
def createkeyframeparam(frame, x, y, window, align, keyframetype, data, privatedata):
global keyframeview
global keyframes
global selected
global presets
global lastframe
# frame = round(keyframeview.cursor*60)
lastgoodi = -1
# chosenwindow = presets[int(selected.get().split(":")[0])]
if keyframes:
for i in range(len(keyframes)):
if keyframes[i].frame <= frame:
lastgoodi = i
else:
break
if (keyframes[lastgoodi].frame != frame):
lastgoodi += 1
keyframes.insert(lastgoodi, Keyframe(frame, x, y, window, align, keyframetype, data, privatedata))
else:
keyframes[lastgoodi] = Keyframe(frame, x, y, window, align, keyframetype, data, privatedata)
return lastgoodi
else:
keyframes.append(Keyframe(frame, x, y, window, align, keyframetype, data, privatedata))
return len(keyframes) - 1
# cachestart(frame)
# print([i.frame for i in keyframes])
def deletekeyframeparam(frame):
global keyframeview
global keyframes
# frame = round(keyframeview.cursor*60)
for i in range(len(keyframes)):
if keyframes[i].frame == frame:
keyframes.pop(i)
cachestart(frame)