From 8b9d66f4de08cff76a12261d293620e0b987ac27 Mon Sep 17 00:00:00 2001 From: Sebastian Castro Date: Mon, 14 Oct 2024 12:27:10 -0400 Subject: [PATCH 1/2] Do not flush events in UI draw method --- pyrobosim/pyrobosim/gui/world_canvas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrobosim/pyrobosim/gui/world_canvas.py b/pyrobosim/pyrobosim/gui/world_canvas.py index e1565aef..1d734dbb 100644 --- a/pyrobosim/pyrobosim/gui/world_canvas.py +++ b/pyrobosim/pyrobosim/gui/world_canvas.py @@ -365,7 +365,7 @@ def draw_and_sleep(self): """Redraws the figure and waits a small amount of time.""" with self.draw_lock: self.fig.canvas.draw() - self.fig.canvas.flush_events() + # self.fig.canvas.flush_events() time.sleep(0.005) def show_planner_and_path(self, robot=None, show_graphs=True, path=None): From ccc55686653f70fa880be365d18412f1e695bcca Mon Sep 17 00:00:00 2001 From: Sebastian Castro Date: Mon, 14 Oct 2024 12:52:07 -0400 Subject: [PATCH 2/2] Enable interactive mode in GUI MatPlotLib canvas --- pyrobosim/pyrobosim/gui/world_canvas.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyrobosim/pyrobosim/gui/world_canvas.py b/pyrobosim/pyrobosim/gui/world_canvas.py index 1d734dbb..b4af3715 100644 --- a/pyrobosim/pyrobosim/gui/world_canvas.py +++ b/pyrobosim/pyrobosim/gui/world_canvas.py @@ -5,6 +5,7 @@ import time import threading import warnings +import matplotlib.pyplot as plt from matplotlib.figure import Figure from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg from matplotlib.pyplot import Circle @@ -126,6 +127,7 @@ def __init__( self.fig = Figure(dpi=dpi, tight_layout=True) self.axes = self.fig.add_subplot(111) super(WorldCanvas, self).__init__(self.fig) + plt.ion() self.main_window = main_window self.world = world @@ -365,7 +367,7 @@ def draw_and_sleep(self): """Redraws the figure and waits a small amount of time.""" with self.draw_lock: self.fig.canvas.draw() - # self.fig.canvas.flush_events() + self.fig.canvas.flush_events() time.sleep(0.005) def show_planner_and_path(self, robot=None, show_graphs=True, path=None): @@ -417,14 +419,13 @@ def nav_animation_callback(self): # Check if any robot is currently navigating. nav_status = [robot.is_moving() for robot in world.robots] if any(nav_status): - self.update_robots_plot() - # Show the state of the currently selected robot cur_robot = world.gui.get_current_robot() if cur_robot is not None and cur_robot.is_moving(): self.show_world_state(cur_robot) world.gui.set_buttons_during_action(False) + self.update_robots_plot() self.draw_and_sleep() def update_robots_plot(self):