11from json import loads as json_loads
2+ from re import L
23from pyperclip import copy
34import PySimpleGUI as sg
45from decimal import Decimal as d
5- from math import floor as round_down
66
7+ #GUI Theme
78sg .theme ('DarkGrey12' )
89
9- class timer :
10+ class retime : #Class for all timer related functions
1011 def frame_round (time , fps ): # Rounds to the nearest frame
1112 time = d (time )
1213 time = round (time , 3 )
1314 output = d (time - time % (d (1 )/ fps )) #Credit to Slush0Puppy for this 1 Line of Code
1415 return round (output , 3 )
1516
16- def format (time ): # Formats the time to the SRC format
17+ # Formats the time to the SRC format
18+ def format (time ):
1719 time = str (time )
1820 time = time .split ('.' , 1 )
1921 seconds = time [0 ]
@@ -26,9 +28,11 @@ def format(time): # Formats the time to the SRC format
2628 seconds = seconds - (minutes * 60 )
2729 if minutes > 60 : #makes sure that the minutes are less than 60
2830 minutes = minutes - (hours * 60 )
31+ #Converts Integers to Strings
2932 seconds = str (seconds )
3033 minutes = str (minutes )
3134 hours = str (hours )
35+ #Combines the time into a single string
3236 if seconds == '0' :
3337 return (f'0s { milliseconds } ms' )
3438 elif minutes == '0' :
@@ -41,76 +45,82 @@ def format(time): # Formats the time to the SRC format
4145 else :
4246 return (f'{ hours } h { minutes } m { seconds } s { milliseconds } ms' )
4347
44-
45- def load ( dbi_end , dbi_start , fps ):
46- try :
48+ #Calculates the loads
49+ def loads ( dbi_start , dbi_end , fps ):
50+ try : #Turns JSON into a Dictionary and Checks if it is Valid (Start)
4751 dbis_dict = json_loads (dbi_start )
4852 except :
49- sg .popup ('Error (Start)' , 'Debug Info is not valid.' , title = 'Error' )
53+ sg .popup ('Error (Start)' , 'Debug Info is not valid.' , title = 'Error' ) #Error Message
5054 return
51- try :
55+ try : #Turns JSON into a Dictionary and Checks if it is Valid (End)
5256 dbie_dict = json_loads (dbi_end )
5357 except :
54- sg .popup ('Error (End)' , 'Debug Info is not valid.' , title = 'Error' )
58+ sg .popup ('Error (End)' , 'Debug Info is not valid.' , title = 'Error' ) #Error Message
5559 return
56- try :
60+ try : #Gets the CMT from the Dictionary
5761 cmt_end = dbie_dict ['cmt' ]
5862 cmt_start = dbis_dict ['cmt' ]
5963 except :
60- sg .popup ('Error (CMT)' , 'CMT is not Valid.' , title = 'fuck you rekto' )
61- cmt_start = timer .frame_round (d (cmt_start ), fps )
62- cmt_end = timer .frame_round (d (cmt_end ), fps )
63- try :
64- time = (d (cmt_end ) - d (cmt_start )) + d (time )
65- except :
66- sg .popup ('Error (CMT)' , 'CMT is not Valid.' , title = 'fuck you rekto' )
64+ sg .popup ('Error (CMT)' , 'CMT is not Valid.' , title = 'Error' ) #Error Message
65+ #Rounds the CMT to the nearest frame
66+ cmt_start = retime .frame_round (d (cmt_start ), fps )
67+ cmt_end = retime .frame_round (d (cmt_end ), fps )
68+ #Calculates the Loads
69+ loads = (d (cmt_end ) - d (cmt_start ))
70+ if - abs (loads ) == loads : #Checks if the Start is greater than the End
71+ sg .popup ('Error' , 'The start is greater than the end.' , title = 'Error' ) #Error Message
6772 return
68- if - abs (time ) == time :
69- sg .popup ('Error' , 'The start is greater than the end.' , title = 'Error' )
70- return
71- main_window ['dbis_loads' ].update ('' )
72- main_window ['dbie_loads' ].update ('' )
73- sg .popup (f'Loads Added' , title = 'Loads' , font = ('Helvetica' , 16 ))
73+ loads = retime .frame_round (loads , fps ) #Rounds the Loads to the nearest frame just in case the rounding is off
74+ sg .popup (f'Loads Added' , title = 'Loads' , font = ('Helvetica' , 16 )) #Success Message
7475 return loads
7576
77+ #Calculates the Final Time
7678 def final (dbi_start , dbi_end , loads , fps ):
77- try :
79+ try : #Turns JSON into a Dictionary and Checks if it is Valid (Start)
7880 dbis_dict = json_loads (dbi_start )
7981 except :
80- sg .popup ('Error (Start)' , 'Debug Info is not valid.' , title = 'Error' )
82+ sg .popup ('Error (Start)' , 'Debug Info is not valid.' , title = 'Error' ) #Error Message
8183 return
82- try :
84+ try : #Turns JSON into a Dictionary and Checks if it is Valid (End)
8385 dbie_dict = json_loads (dbi_end )
8486 except :
85- sg .popup ('Error (End)' , 'Debug Info is not valid.' , title = 'Error' )
87+ sg .popup ('Error (End)' , 'Debug Info is not valid.' , title = 'Error' ) #Error Message
8688 return
87- try :
89+ try : #Gets the CMT from the Dictionary
8890 cmt_end = dbie_dict ['cmt' ]
8991 cmt_start = dbis_dict ['cmt' ]
9092 except :
91- sg .popup ('Error (CMT)' , 'CMT is not Valid.' , title = 'fuck you rekto' )
92- cmt_start = timer .frame_round (d (cmt_start ), fps )
93- cmt_end = timer .frame_round (d (cmt_end ), fps )
93+ sg .popup ('Error (CMT)' , 'CMT is not Valid.' , title = 'Error' ) #Error Message
94+ #Rounds the CMT to the nearest frame
95+ cmt_start = retime .frame_round (d (cmt_start ), fps )
96+ cmt_end = retime .frame_round (d (cmt_end ), fps )
97+ #Calculates the Final Time
9498 time_loads = (d (cmt_end ) - d (cmt_start ))
95- if - abs (time_loads ) == time_loads :
96- sg .popup ('Error' , 'The start is greater than the end.' , title = 'Error' )
99+ if - abs (time_loads ) == time_loads : #Checks if the Start is greater than the End
100+ sg .popup ('Error' , 'The start is greater than the end.' , title = 'Error' ) #Error Message
101+ return
102+ if loads > time_loads : #Checks if the Loads are greater than the Time
103+ sg .popup ('Error' , 'The Loads is greater than the Time.' , title = 'Error' ) #Error Message
97104 return
98- loads = timer .frame_round (loads , fps )
99- time_noloads = time_loads - loads
100- no_loads = timer .format (time_noloads )
101- with_loads = timer .format (time_loads )
105+ loads = retime .frame_round (loads , fps ) #Rounds Loads for the millionth time
106+ time_noloads = time_loads - loads #Gets the Time without Loads
107+ #Formats the Time
108+ no_loads = retime .format (time_noloads )
109+ with_loads = retime .format (time_loads )
102110 if loads == 0 :
103111 final_confirm = sg .popup_yes_no (f'Without Loads: { no_loads } ' , 'Would you like the Mod Note to be Copied to the Clipboard?' , title = 'Results' )
104112 if final_confirm == 'Yes' :
105- copy (f'Mod Note: Retimed to { no_loads } https://github.com/ConnerConnerConner/PyTime' )
113+ copy (f'Mod Note: Retimed to { no_loads } at { fps } using https://github.com/ConnerConnerConner/PyTime' )
106114 elif final_confirm == 'No' :
107115 return
108116 else :
109117 final_confirm = sg .popup_yes_no (f'Without Loads: { no_loads } , With Loads: { with_loads } ' , 'Mod Note Copied to Clipboard' , title = 'Results' )
110118 if final_confirm == 'Yes' :
111- copy (f'Mod Note: Retimed to { no_loads } using https://github.com/ConnerConnerConner/PyTime' )
119+ copy (f'Mod Note: Retimed to { no_loads } at { fps } using https://github.com/ConnerConnerConner/PyTime' )
112120 elif final_confirm == 'No' :
113121 return
122+
123+ #GUI Layout
114124main_layout = [
115125 [sg .Text ('PyTime' , font = ('Helvetica' , 36 )), sg .Text (' FPS' , font = (' Helvetica' , 30 )), sg .InputText ('60' , size = (5 , 1 ), key = 'fps' , font = ('Helvetica' , 30 ))],
116126 [sg .InputText (key = 'dbis' , font = ('Helvetica' , 16 ), pad = ((5 , 0 ), (0 , 0 )), size = (20 , 1 )), sg .Text (' Debug Info Start' , font = ('Helvetica' , 16 ), justification = 'right' )],
@@ -119,52 +129,61 @@ def final(dbi_start, dbi_end, loads, fps):
119129 [sg .InputText (key = 'dbie_loads' , font = ('Helvetica' , 14 ), pad = ((5 , 0 ), (0 , 0 )), size = (15 , 1 )), sg .Text (' Debug Info End (Loads)' , font = ('Helvetica' , 14 ), justification = 'right' )],
120130 [sg .Button ('Calculate' , font = ('Helvetica' , 16 )), sg .Button ('Add Loads' , font = ('Helvetica' , 16 )), sg .Button ('Remove All Loads' , font = ('Helvetica' , 16 ))]
121131 ]
122- main_window = sg .Window ('PyTime' , main_layout , resizable = False , element_justification = 'left' , size = (447 , 253 ), icon = r'assets\PyTime.ico' )
132+ main_window = sg .Window ('PyTime' , main_layout , resizable = False , element_justification = 'left' , size = (447 , 253 ))
123133
134+ #Main Loop
124135while True :
125- event , values = main_window .read ()
126- if event == sg .WIN_CLOSED :
136+ event , values = main_window .read () #Reads the Window
137+ if event == sg .WIN_CLOSED : #Checks if the Window is Closed
127138 break
128- if event == 'Remove All Loads' :
129- lr_confirm = sg .popup_yes_no ('Are you sure you want to remove all loads?' , title = 'Remove All Loads' , font = ('Helvetica' , 16 ))
139+ if event == 'Remove All Loads' : #Checks if the Remove All Loads Button is Pressed
140+ lr_confirm = sg .popup_yes_no ('Are you sure you want to remove all loads?' , title = 'Remove All Loads' , font = ('Helvetica' , 16 ), icon = r'assets\PyTime.ico' ) #Confirmation Message
130141 if lr_confirm == 'Yes' :
142+ #Clears Loads Input Boxes
131143 main_window ['dbis_loads' ].update ('' )
132144 main_window ['dbie_loads' ].update ('' )
133- loads = 0
145+ loads = 0 #Sets Loads to 0
134146 elif lr_confirm == 'No' :
135147 continue
136- if event == 'Add Loads' :
148+ if event == 'Add Loads' : #Checks if the Add Loads Button is Pressed
149+ #Gets the Values from the Input Boxes
137150 dbis_loads = values ['dbis_loads' ]
138151 dbiel_loads = values ['dbie_loads' ]
139152 fps = values ['fps' ]
140- try :
153+ try : #Checks if the FPS is Valid
141154 fps = d (fps )
142155 except :
143- sg .popup ('Error (FPS)' , 'FPS is not a valid number.' , title = 'Error' )
156+ sg .popup ('Error (FPS)' , 'FPS is not a valid number.' , title = 'Error' ) #Error Message
144157 continue
145- if not 'loads' in globals ():
146- loads = timer . load (dbis_loads , dbiel_loads , fps )
158+ if not 'loads' in globals (): #Checks if Loads exists
159+ loads = retime . loads (dbis_loads , dbiel_loads , fps ) #Calculates Loads
147160 else :
148161 try :
149- loads = timer . load (dbis_loads , dbiel_loads , fps ) + loads
162+ loads = retime . loads (dbis_loads , dbiel_loads , fps ) + loads #Calculates Loads
150163 except :
151164 continue
152165 if event == 'Calculate' :
166+ #Gets the Values from the Input Boxes
153167 dbi_start = values ['dbis' ]
154168 dbi_end = values ['dbie' ]
155169 fps = values ['fps' ]
156- try :
170+ try : #Checks if the FPS is Valid
157171 fps = d (fps )
158172 except :
159173 sg .popup ('Error (FPS)' , 'FPS is not an valid number.' , title = 'Error' )
160174 continue
161- if not 'loads' in globals ():
162- loads = 0
163- main_window ['dbis' ].update ('' )
164- main_window ['dbie' ].update ('' )
165- timer .final (dbi_start , dbi_end , loads , fps )
175+ if fps == 0 :
176+ sg .popup ('Error (FPS)' , 'FPS cannot be 0.' , title = 'Error' )
177+ continue
178+ else :
179+ if not 'loads' in globals (): #Check if the Loads Variables Exists
180+ loads = 0 #Sets Loads to 0
181+ retime .final (dbi_start , dbi_end , loads , fps ) #Runs the Final Function
182+ #Clears Input Boxes
183+ main_window ['dbis' ].update ('' )
184+ main_window ['dbie' ].update ('' )
166185
167- main_window .close ()
186+ main_window .close () #Closes the Window once
168187
169188#Credit to Rekto for Helping Me With Everything
170189#Credit to Slush0Puppy for Frane Rounding
0 commit comments