From bed1d101486b6677c629e7e3fa47d1ef32f04b51 Mon Sep 17 00:00:00 2001 From: hagrid67 <jdhwatson@gmail.com> Date: Fri, 26 Apr 2019 20:07:54 +0100 Subject: [PATCH] small editor bugfix --- flatland/utils/editor.py | 10 +++++++-- notebooks/CanvasEditor.ipynb | 40 +++++++++--------------------------- 2 files changed, 18 insertions(+), 32 deletions(-) diff --git a/flatland/utils/editor.py b/flatland/utils/editor.py index 567c894..0a0bbc4 100644 --- a/flatland/utils/editor.py +++ b/flatland/utils/editor.py @@ -38,6 +38,7 @@ class JupEditor(object): self.wid_output = None self.drawMode = "Draw" self.env_filename = "temp.npy" + self.set_env(env) def set_env(self, env): self.env = env @@ -104,6 +105,11 @@ class JupEditor(object): # If we have already touched 3 cells # We have a transition into a cell, and out of it. + if self.drawMode == "Draw": + bTransition = True + elif self.drawMode == "Erase": + bTransition = False + while len(rcHistory) >= 3: rc3Cells = array(rcHistory[:3]) # the 3 cells rcMiddle = rc3Cells[1] # the middle cell which we will update @@ -122,14 +128,14 @@ class JupEditor(object): # Set the transition # oEnv.rail.set_transition((*rcLast, iTransLast), iTrans, True) # does nothing iValCell = env.rail.transitions.set_transition( - env.rail.grid[tuple(rcMiddle)], liTrans[0], liTrans[1], True) + env.rail.grid[tuple(rcMiddle)], liTrans[0], liTrans[1], bTransition) # Also set the reverse transition iValCell = env.rail.transitions.set_transition( iValCell, (liTrans[1] + 2) % 4, (liTrans[0] + 2) % 4, - True) + bTransition) # Write the cell transition value back into the grid env.rail.grid[tuple(rcMiddle)] = iValCell diff --git a/notebooks/CanvasEditor.ipynb b/notebooks/CanvasEditor.ipynb index faa57ce..5193b72 100644 --- a/notebooks/CanvasEditor.ipynb +++ b/notebooks/CanvasEditor.ipynb @@ -48,7 +48,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -174,7 +174,7 @@ }, { "cell_type": "code", - "execution_count": 144, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -214,7 +214,7 @@ }, { "cell_type": "code", - "execution_count": 156, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ @@ -232,7 +232,7 @@ }, { "cell_type": "code", - "execution_count": 157, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ @@ -285,7 +285,7 @@ }, { "cell_type": "code", - "execution_count": 158, + "execution_count": 28, "metadata": { "scrolled": false }, @@ -293,7 +293,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "2fceb907aab945788d32e2c4555d5071", + "model_id": "4c71c3622edc4d1b8d28916b65ae12fc", "version_major": 2, "version_minor": 0 }, @@ -314,7 +314,7 @@ }, { "cell_type": "code", - "execution_count": 138, + "execution_count": 15, "metadata": { "scrolled": false }, @@ -322,12 +322,12 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "b9c28e5dab4e46b49ab1fb7dd9f3834b", + "model_id": "58e49268613640a581df588132692c4b", "version_major": 2, "version_minor": 0 }, "text/plain": [ - "Output(outputs=({'output_type': 'stream', 'text': 'Debug: True\\n', 'name': 'stdout'},))" + "Output()" ] }, "metadata": {}, @@ -347,7 +347,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -361,26 +361,6 @@ "## Junk below here" ] }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Draw'" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "wid_buttons.get_interact_value()" - ] - }, { "cell_type": "code", "execution_count": 17, -- GitLab