From 9a4a1f0b6bbb7454ccce62ac63207854697a3e57 Mon Sep 17 00:00:00 2001 From: "Egli Adrian (IT-SCI-API-PFI)" <adrian.egli@sbb.ch> Date: Mon, 17 Jun 2019 16:32:35 +0200 Subject: [PATCH] editor bug fix : interaction with mouse --- README.rst | 2 +- flatland/utils/editor.py | 31 ++++++++++++++ flatland/utils/graphics_pil.py | 10 ++--- notebooks/Scene_Editor.ipynb | 2 +- notebooks/Simple_Rendering_Demo.ipynb | 59 ++++++++++++++++++++++----- 5 files changed, 86 insertions(+), 18 deletions(-) diff --git a/README.rst b/README.rst index 5d769f4e..a626dcb8 100644 --- a/README.rst +++ b/README.rst @@ -110,7 +110,7 @@ Once you have a copy of the source, you can install it with :: Jupyter Canvas Widget --------------------- If you work with jupyter notebook you need to install the Jupyer Canvas Widget. To install the Jupyter Canvas Widget read also -https://github.com/Who8MyLunch/Jupyter_Canvas_Widget#installation +https://github.com/Who8MyLunch/Jupyter_Canvas_Widget#installation Usage ===== diff --git a/flatland/utils/editor.py b/flatland/utils/editor.py index 6973c94e..4dcd4ef2 100644 --- a/flatland/utils/editor.py +++ b/flatland/utils/editor.py @@ -249,6 +249,9 @@ class Controller(object): self.debug("click in cell", rcCell) self.model.debug_cell(rcCell) + if self.model.iSelectedAgent is not None: + self.lrcStroke = [] + def setDebug(self, dEvent): self.model.setDebug(dEvent["new"]) @@ -276,6 +279,33 @@ class Controller(object): # The intention was to avoid too many redraws. if event["buttons"] > 0: qEvents.append((time.time(), x, y)) + bShift = event["shiftKey"] + bCtrl = event["ctrlKey"] + bAlt = event["altKey"] + if bShift: + self.lrcStroke = [] + while len(qEvents) > 0: + t, x, y = qEvents.popleft() + return + if bCtrl: + self.lrcStroke = [] + while len(qEvents) > 0: + t, x, y = qEvents.popleft() + return + if bAlt: + self.lrcStroke = [] + while len(qEvents) > 0: + t, x, y = qEvents.popleft() + return + else: + self.lrcStroke = [] + + + if self.model.iSelectedAgent is not None: + self.lrcStroke = [] + while len(qEvents) > 0: + t, x, y = qEvents.popleft() + return # Process the events in our queue: # Draw a black square to indicate a trail @@ -298,6 +328,7 @@ class Controller(object): else: self.model.mod_path(not event["shiftKey"]) + def refresh(self, event): self.debug("refresh") self.view.redraw() diff --git a/flatland/utils/graphics_pil.py b/flatland/utils/graphics_pil.py index 6c687667..e3e32125 100644 --- a/flatland/utils/graphics_pil.py +++ b/flatland/utils/graphics_pil.py @@ -433,13 +433,13 @@ class PILSVG(PILGL): if (col + row) % 10 > 7: pilTrack = self.dScenery[0] else: - if (col + row + col * row) % 2 == 0: + if (col + row + col * row) % 3 == 0: a = (a + (col + row + col * row)) % len(self.dBuildings) pilTrack = self.dBuildings[a] - elif (self.background_grid[col][row] > 5) or ((col ** 3 + row ** 2 + col * row) % 10 == 0): - a = int(self.background_grid[col][row]) - 5 - a = a % len(self.dScenery) - if (col + row + col * row) % 10 > 2: + elif (self.background_grid[col][row] > 4) or ((col ** 3 + row ** 2 + col * row) % 10 == 0): + a = int(self.background_grid[col][row]) - 4 + a = (a + (col + row + col * row + col ** 3 + row ** 4)) % len(self.dScenery) + if (col + row + col * row ) % 10 > 2: a = 0 pilTrack = self.dScenery[a] diff --git a/notebooks/Scene_Editor.ipynb b/notebooks/Scene_Editor.ipynb index 728debb3..444c1ebf 100644 --- a/notebooks/Scene_Editor.ipynb +++ b/notebooks/Scene_Editor.ipynb @@ -100,7 +100,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "04f9a225dac149dca9990b271ab3b459", + "model_id": "140f16d2c9a643e39d68c6421e50b9bd", "version_major": 2, "version_minor": 0 }, diff --git a/notebooks/Simple_Rendering_Demo.ipynb b/notebooks/Simple_Rendering_Demo.ipynb index b05b791f..8b13d860 100644 --- a/notebooks/Simple_Rendering_Demo.ipynb +++ b/notebooks/Simple_Rendering_Demo.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -19,7 +19,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -31,7 +31,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -41,7 +41,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -53,9 +53,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "<style>.container { width:90% !important; }</style>" + ], + "text/plain": [ + "<IPython.core.display.HTML object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "from IPython.core.display import display, HTML\n", "display(HTML(\"<style>.container { width:90% !important; }</style>\"))" @@ -70,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -92,9 +105,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Illegal target rail: 3 13 0001011000000001\n", + "Illegal target rail: 5 13 0100000000000010\n" + ] + } + ], "source": [ "oRT = rt.RenderTool(env,gl=\"PILSVG\")\n", "oRT.renderEnv()\n", @@ -103,9 +125,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "6f5c066c7dff47dbb3d2bfc1f9e77943", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Canvas()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "jpy_canvas.Canvas(img)" ] -- GitLab