From 9a55ff4ca5964bc4cef915da66e9cf85831ec0c2 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Wed, 27 Nov 2019 11:41:54 -0800 Subject: [PATCH] display mobility player on session start, change buttons and progress bar on session events --- coretk/coretk/coreclient.py | 30 +++++++++++-------- coretk/coretk/dialogs/mobilityplayer.py | 40 ++++++++++++++----------- coretk/coretk/menubar.py | 2 +- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/coretk/coretk/coreclient.py b/coretk/coretk/coreclient.py index 04d9df06..e6dfb77e 100644 --- a/coretk/coretk/coreclient.py +++ b/coretk/coretk/coreclient.py @@ -128,19 +128,18 @@ class CoreClient: if session_event.event <= core_pb2.SessionState.SHUTDOWN: self.state = event.session_event.event # mobility start - elif session_event.event == 7: + elif session_event.event in {7, 8, 9}: node_id = session_event.node_id - if node_id not in self.mobility_players: - canvas_node = self.canvas_nodes[node_id] - dialog = MobilityPlayerDialog(self.app, self.app, canvas_node) - dialog.show() - self.mobility_players[node_id] = dialog - # mobility stop - elif session_event.event == 8: - pass - # mobility pause - elif session_event.event == 9: - pass + dialog = self.mobility_players.get(node_id) + if dialog: + if session_event.event == 7: + dialog.set_play() + elif session_event.event == 8: + dialog.set_stop() + else: + dialog.set_pause() + else: + logging.warning("unknown session event: %s", session_event) elif event.HasField("node_event"): node_event = event.node_event node_id = node_event.node.id @@ -359,6 +358,13 @@ class CoreClient: logging.debug("start session(%s), result: %s", self.session_id, response.result) self.app.statusbar.start_session_callback(process_time) + # display mobility players + for node_id, config in self.mobility_configs.items(): + canvas_node = self.canvas_nodes[node_id] + dialog = MobilityPlayerDialog(self.app, self.app, canvas_node, config) + dialog.show() + self.mobility_players[node_id] = dialog + def stop_session(self, session_id=None): if not session_id: session_id = self.session_id diff --git a/coretk/coretk/dialogs/mobilityplayer.py b/coretk/coretk/dialogs/mobilityplayer.py index 30053498..65b16058 100644 --- a/coretk/coretk/dialogs/mobilityplayer.py +++ b/coretk/coretk/dialogs/mobilityplayer.py @@ -10,13 +10,13 @@ ICON_SIZE = 16 class MobilityPlayerDialog(Dialog): - def __init__(self, master, app, canvas_node): + def __init__(self, master, app, canvas_node, config): super().__init__( master, app, f"{canvas_node.core_node.name} Mobility Player", modal=False ) self.canvas_node = canvas_node self.node = canvas_node.core_node - self.config = self.app.core.mobility_configs[canvas_node.core_node.id] + self.config = config self.play_button = None self.pause_button = None self.stop_button = None @@ -30,14 +30,8 @@ class MobilityPlayerDialog(Dialog): label = ttk.Label(self.top, text=file_name) label.grid(sticky="ew", pady=PAD) - frame = ttk.Frame(self.top) - frame.grid(sticky="ew", pady=PAD) - frame.columnconfigure(0, weight=1) - self.progressbar = ttk.Progressbar(frame, mode="indeterminate") - self.progressbar.grid(row=0, column=0, sticky="ew", padx=PAD) - self.progressbar.start() - label = ttk.Label(frame, text="time") - label.grid(row=0, column=1) + self.progressbar = ttk.Progressbar(self.top, mode="indeterminate") + self.progressbar.grid(sticky="ew", pady=PAD) frame = ttk.Frame(self.top) frame.grid(sticky="ew", pady=PAD) @@ -58,6 +52,7 @@ class MobilityPlayerDialog(Dialog): self.stop_button = ttk.Button(frame, image=image, command=self.click_stop) self.stop_button.image = image self.stop_button.grid(row=0, column=2, sticky="ew", padx=PAD) + self.stop_button.state(["pressed"]) loop = tk.IntVar(value=int(self.config["loop"].value == "1")) checkbutton = ttk.Checkbutton( @@ -74,29 +69,38 @@ class MobilityPlayerDialog(Dialog): self.pause_button.state(["!pressed"]) self.stop_button.state(["!pressed"]) - def click_play(self): + def set_play(self): self.clear_buttons() self.play_button.state(["pressed"]) + self.progressbar.start() + + def set_pause(self): + self.clear_buttons() + self.pause_button.state(["pressed"]) + self.progressbar.stop() + + def set_stop(self): + self.clear_buttons() + self.stop_button.state(["pressed"]) + self.progressbar.stop() + + def click_play(self): + self.set_play() session_id = self.app.core.session_id self.app.core.client.mobility_action( session_id, self.node.id, core_pb2.MobilityAction.START ) - self.progressbar.start() def click_pause(self): - self.clear_buttons() - self.pause_button.state(["pressed"]) + self.set_pause() session_id = self.app.core.session_id self.app.core.client.mobility_action( session_id, self.node.id, core_pb2.MobilityAction.PAUSE ) - self.progressbar.stop() def click_stop(self): - self.clear_buttons() - self.stop_button.state(["pressed"]) + self.set_stop() session_id = self.app.core.session_id self.app.core.client.mobility_action( session_id, self.node.id, core_pb2.MobilityAction.STOP ) - self.progressbar.stop() diff --git a/coretk/coretk/menubar.py b/coretk/coretk/menubar.py index d9508681..e56c55ec 100644 --- a/coretk/coretk/menubar.py +++ b/coretk/coretk/menubar.py @@ -51,10 +51,10 @@ class Menubar(tk.Menu): label="Open...", command=self.menuaction.file_open_xml, accelerator="Ctrl+O" ) self.app.bind_all("", self.menuaction.file_open_xml) - menu.add_command(label="Reload", underline=0, state=tk.DISABLED) menu.add_command( label="Save", accelerator="Ctrl+S", command=self.menuaction.file_save_as_xml ) + menu.add_command(label="Reload", underline=0, state=tk.DISABLED) self.app.bind_all("", self.menuaction.file_save_as_xml) menu.add_separator() menu.add_command(label="Export Python script...", state=tk.DISABLED)