Clean up timer widget code and create state widgets more intelligently
This commit corresponds to the most recent update of warpy and removes the need for state handlers in order to determine the string value of the open worlds state. This also further abstracts the code for the asynchronous state_widget function by taking the function and timer widget instead of specifying these explicitly in code. This removes the need to have three near identical timer state setting functions due to a small difference in function calls despite ingesting the same target information, just with different strings and values.
This commit is contained in:
@@ -44,6 +44,7 @@ else:
|
|||||||
# Assume fullscreen
|
# Assume fullscreen
|
||||||
x_pos, y_pos, width, height, fullscreen = 0, 0, win32api.GetSystemMetrics(0), win32api.GetSystemMetrics(1), True
|
x_pos, y_pos, width, height, fullscreen = 0, 0, win32api.GetSystemMetrics(0), win32api.GetSystemMetrics(1), True
|
||||||
|
|
||||||
|
|
||||||
if fullscreen:
|
if fullscreen:
|
||||||
# root.wm_attributes("-fullscreen", True)
|
# root.wm_attributes("-fullscreen", True)
|
||||||
print("Fullscreen is not supported") # Currently unable to display above fullscreen apps
|
print("Fullscreen is not supported") # Currently unable to display above fullscreen apps
|
||||||
@@ -68,11 +69,12 @@ tk.Label(timers, text="Cetus", fg="#FFFFFF").grid(row=0, column=0)
|
|||||||
tk.Label(timers, text="Deimos", fg="#FFFFFF").grid(row=0, column=3)
|
tk.Label(timers, text="Deimos", fg="#FFFFFF").grid(row=0, column=3)
|
||||||
tk.Label(timers, text="Vallis", fg="#FFFFFF").grid(row=0, column=6)
|
tk.Label(timers, text="Vallis", fg="#FFFFFF").grid(row=0, column=6)
|
||||||
|
|
||||||
# String state indicators
|
# Create new timer objects
|
||||||
cetus_timer = Timer(tk.StringVar(timers), tk.StringVar(timers), root, loop)
|
cetus_timer = Timer(tk.StringVar(timers), tk.StringVar(timers), root, loop)
|
||||||
vallis_timer = Timer(tk.StringVar(timers), tk.StringVar(timers), root, loop)
|
vallis_timer = Timer(tk.StringVar(timers), tk.StringVar(timers), root, loop)
|
||||||
cambion_timer = Timer(tk.StringVar(timers), tk.StringVar(timers), root, loop)
|
cambion_timer = Timer(tk.StringVar(timers), tk.StringVar(timers), root, loop)
|
||||||
|
|
||||||
|
# State Labels
|
||||||
cetus_state_label = tk.Label(timers, textvariable=cetus_timer.state)
|
cetus_state_label = tk.Label(timers, textvariable=cetus_timer.state)
|
||||||
vallis_state_label = tk.Label(timers, textvariable=vallis_timer.state)
|
vallis_state_label = tk.Label(timers, textvariable=vallis_timer.state)
|
||||||
cambion_state_label = tk.Label(timers, textvariable=cambion_timer.state)
|
cambion_state_label = tk.Label(timers, textvariable=cambion_timer.state)
|
||||||
@@ -81,6 +83,7 @@ cetus_state_label.grid(row=0, column=1)
|
|||||||
cambion_state_label.grid(row=0, column=4)
|
cambion_state_label.grid(row=0, column=4)
|
||||||
vallis_state_label.grid(row=0, column=7)
|
vallis_state_label.grid(row=0, column=7)
|
||||||
|
|
||||||
|
# Timer Labels
|
||||||
cetus_timer_label = tk.Label(timers, textvariable=cetus_timer.timer)
|
cetus_timer_label = tk.Label(timers, textvariable=cetus_timer.timer)
|
||||||
vallis_timer_label = tk.Label(timers, textvariable=vallis_timer.timer)
|
vallis_timer_label = tk.Label(timers, textvariable=vallis_timer.timer)
|
||||||
cambion_timer_label = tk.Label(timers, textvariable=cambion_timer.timer)
|
cambion_timer_label = tk.Label(timers, textvariable=cambion_timer.timer)
|
||||||
@@ -91,28 +94,15 @@ vallis_timer_label.grid(row=0, column=8)
|
|||||||
|
|
||||||
|
|
||||||
# Asynchronous functions
|
# Asynchronous functions
|
||||||
async def cetus_state_widget():
|
async def state_widget(f, _timer_widget):
|
||||||
json = await warframe.cetus_status()
|
json = await f()
|
||||||
next_attempt, remaining_time = cetus_timer.set_state(json, cetus_timer.cetus_handler)
|
next_attempt, remaining_time = _timer_widget.set_state(json)
|
||||||
cetus_timer.update_timer(remaining_time)
|
_timer_widget.update_timer(remaining_time)
|
||||||
root.after(next_attempt, lambda: loop.run_until_complete(cetus_state_widget()))
|
root.after(next_attempt, lambda: loop.run_until_complete(state_widget(f, _timer_widget)))
|
||||||
|
root.after(next_attempt, lambda: enable_clickthrough(root))
|
||||||
|
|
||||||
|
loop.run_until_complete(state_widget(warframe.cetus_status, cetus_timer))
|
||||||
async def vallis_state_widget():
|
loop.run_until_complete(state_widget(warframe.vallis_status, vallis_timer))
|
||||||
json = await warframe.vallis_status()
|
loop.run_until_complete(state_widget(warframe.cambion_status, cambion_timer))
|
||||||
next_attempt, remaining_time = vallis_timer.set_state(json, vallis_timer.vallis_handler)
|
|
||||||
vallis_timer.update_timer(remaining_time)
|
|
||||||
root.after(next_attempt, lambda: loop.run_until_complete(vallis_state_widget()))
|
|
||||||
|
|
||||||
|
|
||||||
async def cambion_state_widget():
|
|
||||||
json = await warframe.cambion_status()
|
|
||||||
next_attempt, remaining_time = cambion_timer.set_state(json, cambion_timer.cambion_handler)
|
|
||||||
cambion_timer.update_timer(remaining_time)
|
|
||||||
root.after(next_attempt, lambda: loop.run_until_complete(cambion_state_widget()))
|
|
||||||
|
|
||||||
loop.run_until_complete(cetus_state_widget())
|
|
||||||
loop.run_until_complete(vallis_state_widget())
|
|
||||||
loop.run_until_complete(cambion_state_widget())
|
|
||||||
|
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class Timer:
|
|||||||
self._root = root
|
self._root = root
|
||||||
self._loop = loop
|
self._loop = loop
|
||||||
|
|
||||||
def set_state(self, json, state_handler):
|
def set_state(self, json):
|
||||||
expiration, remaining_time, remaining_seconds = _create_timer_values(json)
|
expiration, remaining_time, remaining_seconds = _create_timer_values(json)
|
||||||
if remaining_seconds < 0:
|
if remaining_seconds < 0:
|
||||||
self.timer.set(str('00:00:00'))
|
self.timer.set(str('00:00:00'))
|
||||||
@@ -25,22 +25,8 @@ class Timer:
|
|||||||
else:
|
else:
|
||||||
self.timer.set(str(remaining_time))
|
self.timer.set(str(remaining_time))
|
||||||
retry = remaining_seconds * 1000.0 + 120000
|
retry = remaining_seconds * 1000.0 + 120000
|
||||||
state_handler(json)
|
|
||||||
return round(retry), remaining_time
|
|
||||||
|
|
||||||
# Do these belong here?
|
|
||||||
def cetus_handler(self, json):
|
|
||||||
self.state.set(json['state'].capitalize())
|
self.state.set(json['state'].capitalize())
|
||||||
|
return round(retry), remaining_time
|
||||||
def vallis_handler(self, json):
|
|
||||||
if json["isWarm"]:
|
|
||||||
self.state.set("Warm")
|
|
||||||
else:
|
|
||||||
self.state.set("Cold")
|
|
||||||
|
|
||||||
def cambion_handler(self, json):
|
|
||||||
self.state.set(json['active'].capitalize())
|
|
||||||
# End ?
|
|
||||||
|
|
||||||
def update_timer(self, remaining_time):
|
def update_timer(self, remaining_time):
|
||||||
remaining_time -= timedelta(seconds=1)
|
remaining_time -= timedelta(seconds=1)
|
||||||
|
|||||||
Reference in New Issue
Block a user