diff --git a/examples/demo.py b/examples/demo.py index bdb066d54953f154ed528c8e9ddcab1b2390d133..90ab261bcd0f02522273beef2022e53bae9605da 100644 --- a/examples/demo.py +++ b/examples/demo.py @@ -173,3 +173,9 @@ demo_001 = None demo_002 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_network_002.pkl')) demo_002.run_demo() demo_002 = None + + +demo_flatland_000 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_flatland_000.pkl')) +demo_flatland_000.renderer.resize() +demo_flatland_000.run_demo(100) +demo_flatland_000 = None diff --git a/flatland/utils/graphics_layer.py b/flatland/utils/graphics_layer.py index 4cfcc64bffb82f91a0f36822188db297bc1ed37e..527944b7831c7b172a7ffe133a9a6d7041918b27 100644 --- a/flatland/utils/graphics_layer.py +++ b/flatland/utils/graphics_layer.py @@ -68,3 +68,6 @@ class GraphicsLayer(object): def setAgentAt(self, iAgent, row, col, iDirIn, iDirOut): pass + + def resize(self,env): + pass diff --git a/flatland/utils/render_qt.py b/flatland/utils/render_qt.py index 73b8ca77a33042bf181097d4b1a0a1afcb48b56e..6413c99adfd243cb8283866848556283c50f7f13 100644 --- a/flatland/utils/render_qt.py +++ b/flatland/utils/render_qt.py @@ -1,14 +1,15 @@ -from flatland.utils.graphics_qt import QtRenderer -from numpy import array -from flatland.utils.graphics_layer import GraphicsLayer -# from matplotlib import pyplot as plt -import numpy as np import time -from flatland.utils.svg import Track, Zug -from flatland.envs.agent_utils import EnvAgent -from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QGridLayout +# from matplotlib import pyplot as plt +import numpy as np from PyQt5 import QtSvg +from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QGridLayout +from numpy import array + +from flatland.envs.agent_utils import EnvAgent +from flatland.utils.graphics_layer import GraphicsLayer +from flatland.utils.graphics_qt import QtRenderer +from flatland.utils.svg import Track, Zug def transform_string_svg(sSVG): @@ -16,6 +17,7 @@ def transform_string_svg(sSVG): bySVG = bytearray(sSVG, encoding='utf-8') return bySVG + def create_QtSvgWidget_from_svg_string(sSVG): svgWidget = QtSvg.QSvgWidget() ret = svgWidget.renderer().load(transform_string_svg(sSVG)) @@ -45,10 +47,10 @@ class QTGL(GraphicsLayer): # use the renderer to scale back to the desired size self.qtr.scale(self.tile_size / self.cell_pixels, self.tile_size / self.cell_pixels) - self.tColBg = (255, 255, 255) # white background + self.tColBg = (255, 255, 255) # white background # self.tColBg = (220, 120, 40) # background color - self.tColRail = (0, 0, 0) # black rails - self.tColGrid = (230,) * 3 # light grey for grid + self.tColRail = (0, 0, 0) # black rails + self.tColGrid = (230,) * 3 # light grey for grid # Draw the background of the in-world cells self.qtr.fillRect(0, 0, self.widthPx, self.heightPx, *self.tColBg) @@ -195,8 +197,8 @@ class QTSVG(GraphicsLayer): # We can only reuse the image if noth new and old are straight and the same: if iDirIn == iDirOut and \ - agentPrev.direction == iDirIn and \ - agentPrev.old_direction == agentPrev.direction: + agentPrev.direction == iDirIn and \ + agentPrev.old_direction == agentPrev.direction: return else: # need to load new image @@ -222,6 +224,13 @@ class QTSVG(GraphicsLayer): def show(self, block=False): self.wMain.update() + def resize(self, env): + screen_resolution = self.app.desktop().screenGeometry() + width, height = screen_resolution.width(), screen_resolution.height() + w = np.ceil(width * 0.8 / env.width) + h = np.ceil(height * 0.8 / env.height) + self.wWinMain.resize(env.width * w, env.height * h) + def main2(): gl = QTGL(10, 10) diff --git a/flatland/utils/rendertools.py b/flatland/utils/rendertools.py index b96531c6f2162553d13ba5b4dc7415626266e11f..4a1827f1df44ce8168d4facafc2fe0b686006eac 100644 --- a/flatland/utils/rendertools.py +++ b/flatland/utils/rendertools.py @@ -137,6 +137,9 @@ class RenderTool(object): self.new_rail = True + def resize(self): + self.gl.resize(self.env) + def set_new_rail(self): self.new_rail = True diff --git a/notebooks/Editor2.ipynb b/notebooks/Editor2.ipynb index 71b74b793e0ae3ba41dcb1f18ff501eb10595667..4ac6e9dbd974df1074b90b2f481561d2dbac5b50 100644 --- a/notebooks/Editor2.ipynb +++ b/notebooks/Editor2.ipynb @@ -114,7 +114,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "31e3248d9a0e4b5da8f2439abd13558d", + "model_id": "ece47ccd72af4638b61e9d93a66e9a57", "version_major": 2, "version_minor": 0 }, @@ -140,7 +140,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "c22754b330ce490383eb05972bc96afe", + "model_id": "86207439e5a94055bb3d837028f195fc", "version_major": 2, "version_minor": 0 },