diff --git a/benchmarks/benchmark_all_examples.py b/benchmarks/benchmark_all_examples.py index 5687ad8a2be4ae02fb2f0b14f2c5873fe89e798e..676bfe16ba94d53682ff6e52d7b714d8fa1c2d8b 100644 --- a/benchmarks/benchmark_all_examples.py +++ b/benchmarks/benchmark_all_examples.py @@ -9,10 +9,6 @@ import pkg_resources from benchmarker import Benchmarker from importlib_resources import path -from flatland.utils import graphics_pil - -graphics_pil.unattended_switch = True - for entry in [entry for entry in importlib_resources.contents('examples') if not pkg_resources.resource_isdir('examples', entry) and entry.endswith(".py") diff --git a/benchmarks/profile_all_examples.py b/benchmarks/profile_all_examples.py index b41f52a8cb9a9d261dcaf656b7aa4a11e8885374..8015e23a04e8096d3302b3b3a717221d0d872773 100644 --- a/benchmarks/profile_all_examples.py +++ b/benchmarks/profile_all_examples.py @@ -8,7 +8,6 @@ import pkg_resources from importlib_resources import path from benchmarks.benchmark_utils import swap_attr -from flatland.utils import graphics_pil def profile(resource, entry): @@ -25,8 +24,6 @@ def profile(resource, entry): cProfile.run('my_func()', sort='time') -graphics_pil.unattended_switch = True - for entry in [entry for entry in importlib_resources.contents('examples') if not pkg_resources.resource_isdir('examples', entry) and entry.endswith(".py") diff --git a/benchmarks/run_all_examples.py b/benchmarks/run_all_examples.py index 972ac68ee862e4e80a342cf4d5133a42b28d3df2..57dd6a930a65e421e4395050d6b82b3383096286 100644 --- a/benchmarks/run_all_examples.py +++ b/benchmarks/run_all_examples.py @@ -7,15 +7,11 @@ import pkg_resources from importlib_resources import path from benchmarks.benchmark_utils import swap_attr -from flatland.utils import graphics_pil - -graphics_pil.unattended_switch = True for entry in [entry for entry in importlib_resources.contents('examples') if not pkg_resources.resource_isdir('examples', entry) and entry.endswith(".py") and '__init__' not in entry - and 'example_basic_elements_test' not in entry and 'demo.py' not in entry ]: with path('examples', entry) as file_in: diff --git a/flatland/utils/graphics_pil.py b/flatland/utils/graphics_pil.py index 5f91b8bc8adc7b2aef2597c62251b7f021b707f5..b5b761a20b8c1cc5cb8d20f9b12d0831e8636685 100644 --- a/flatland/utils/graphics_pil.py +++ b/flatland/utils/graphics_pil.py @@ -33,8 +33,9 @@ from flatland.core.grid.rail_env_grid import RailEnvTransitions # noqa: E402 class PILGL(GraphicsLayer): - # hack: in continuous integration, we run multiple - unattended_switch = False + # tk.Tk() must be a singleton! + # https://stackoverflow.com/questions/26097811/image-pyimage2-doesnt-exist + window = tk.Tk() def __init__(self, width, height, jupyter=False): self.yxBase = (0, 0) @@ -86,7 +87,6 @@ class PILGL(GraphicsLayer): self.ltAgentColors = [self.rgb_s2i(sColor) for sColor in sColors.split("#")] self.nAgentColors = len(self.ltAgentColors) - self.window_root = None self.window_open = False self.firstFrame = True self.old_background_image = (None, None, None) @@ -160,24 +160,14 @@ class PILGL(GraphicsLayer): def open_window(self): assert self.window_open is False, "Window is already open!" - if self.unattended_switch: - # use tk.Toplevel() instead of tk.Tk() since we run all examples from the same python script - # https://stackoverflow.com/questions/26097811/image-pyimage2-doesnt-exist - self.window_root = tk.Toplevel() - else: - self.window_root = tk.Tk() - self.window_root.withdraw() - self.window = tk.Toplevel(self.window_root) - self.window.title("Flatland") - self.window.configure(background='grey') + self.__class__.window.title("Flatland") + self.__class__.window.configure(background='grey') self.window_open = True def close_window(self): self.panel.destroy() - self.window.quit() - self.window.destroy() - self.window_root.destroy() - self.window = None + # quit but not destroy! + self.__class__.window.quit() def text(self, *args, **kwargs): pass @@ -209,7 +199,7 @@ class PILGL(GraphicsLayer): self.panel.configure(image=tkimg) self.panel.image = tkimg - self.window.update() + self.__class__.window.update() self.firstFrame = False def pause(self, seconds=0.00001): diff --git a/flatland/utils/rendertools.py b/flatland/utils/rendertools.py index 7932aacafe5c67e188afa9f52a90ec47f73ff8da..8036294b71e78039f1452ebe0603f148e8bc6772 100644 --- a/flatland/utils/rendertools.py +++ b/flatland/utils/rendertools.py @@ -677,7 +677,7 @@ class RenderTool(object): if self.agentRenderVariant == AgentRenderVariant.BOX_ONLY: self.gl.setCellOccupied(iAgent, *(agent.position)) elif self.agentRenderVariant == AgentRenderVariant.ONE_STEP_BEHIND or \ - self.agentRenderVariant == AgentRenderVariant.ONE_STEP_BEHIND_AND_BOX: + self.agentRenderVariant == AgentRenderVariant.ONE_STEP_BEHIND_AND_BOX: if agent.old_position is not None: position = agent.old_position direction = agent.direction