Launcher: launch without delay on URI without choice (#4279)
This commit is contained in:
parent
17b3ee6eaf
commit
ecc3094c70
58
Launcher.py
58
Launcher.py
|
@ -126,12 +126,13 @@ def handle_uri(path: str, launch_args: Tuple[str, ...]) -> None:
|
||||||
elif component.display_name == "Text Client":
|
elif component.display_name == "Text Client":
|
||||||
text_client_component = component
|
text_client_component = component
|
||||||
|
|
||||||
from kvui import App, Button, BoxLayout, Label, Clock, Window
|
if client_component is None:
|
||||||
|
run_component(text_client_component, *launch_args)
|
||||||
|
return
|
||||||
|
|
||||||
|
from kvui import App, Button, BoxLayout, Label, Window
|
||||||
|
|
||||||
class Popup(App):
|
class Popup(App):
|
||||||
timer_label: Label
|
|
||||||
remaining_time: Optional[int]
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.title = "Connect to Multiworld"
|
self.title = "Connect to Multiworld"
|
||||||
self.icon = r"data/icon.png"
|
self.icon = r"data/icon.png"
|
||||||
|
@ -139,48 +140,25 @@ def handle_uri(path: str, launch_args: Tuple[str, ...]) -> None:
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
layout = BoxLayout(orientation="vertical")
|
layout = BoxLayout(orientation="vertical")
|
||||||
|
layout.add_widget(Label(text="Select client to open and connect with."))
|
||||||
|
button_row = BoxLayout(orientation="horizontal", size_hint=(1, 0.4))
|
||||||
|
|
||||||
if client_component is None:
|
text_client_button = Button(
|
||||||
self.remaining_time = 7
|
text=text_client_component.display_name,
|
||||||
label_text = (f"A game client able to parse URIs was not detected for {game}.\n"
|
on_release=lambda *args: run_component(text_client_component, *launch_args)
|
||||||
f"Launching Text Client in 7 seconds...")
|
)
|
||||||
self.timer_label = Label(text=label_text)
|
button_row.add_widget(text_client_button)
|
||||||
layout.add_widget(self.timer_label)
|
|
||||||
Clock.schedule_interval(self.update_label, 1)
|
|
||||||
else:
|
|
||||||
layout.add_widget(Label(text="Select client to open and connect with."))
|
|
||||||
button_row = BoxLayout(orientation="horizontal", size_hint=(1, 0.4))
|
|
||||||
|
|
||||||
text_client_button = Button(
|
game_client_button = Button(
|
||||||
text=text_client_component.display_name,
|
text=client_component.display_name,
|
||||||
on_release=lambda *args: run_component(text_client_component, *launch_args)
|
on_release=lambda *args: run_component(client_component, *launch_args)
|
||||||
)
|
)
|
||||||
button_row.add_widget(text_client_button)
|
button_row.add_widget(game_client_button)
|
||||||
|
|
||||||
game_client_button = Button(
|
layout.add_widget(button_row)
|
||||||
text=client_component.display_name,
|
|
||||||
on_release=lambda *args: run_component(client_component, *launch_args)
|
|
||||||
)
|
|
||||||
button_row.add_widget(game_client_button)
|
|
||||||
|
|
||||||
layout.add_widget(button_row)
|
|
||||||
|
|
||||||
return layout
|
return layout
|
||||||
|
|
||||||
def update_label(self, dt):
|
|
||||||
if self.remaining_time > 1:
|
|
||||||
# countdown the timer and string replace the number
|
|
||||||
self.remaining_time -= 1
|
|
||||||
self.timer_label.text = self.timer_label.text.replace(
|
|
||||||
str(self.remaining_time + 1), str(self.remaining_time)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
# our timer is finished so launch text client and close down
|
|
||||||
run_component(text_client_component, *launch_args)
|
|
||||||
Clock.unschedule(self.update_label)
|
|
||||||
App.get_running_app().stop()
|
|
||||||
Window.close()
|
|
||||||
|
|
||||||
def _stop(self, *largs):
|
def _stop(self, *largs):
|
||||||
# see run_gui Launcher _stop comment for details
|
# see run_gui Launcher _stop comment for details
|
||||||
self.root_window.close()
|
self.root_window.close()
|
||||||
|
|
Loading…
Reference in New Issue