diff --git a/flatland/utils/graphics_pil.py b/flatland/utils/graphics_pil.py index 496433c6067ee975330530dbb7adf5e64ffcef8a..7d6d876bae8239d7c263e37e93be97551d8ec80f 100644 --- a/flatland/utils/graphics_pil.py +++ b/flatland/utils/graphics_pil.py @@ -30,7 +30,7 @@ from flatland.core.transitions import RailEnvTransitions class PILGL(GraphicsLayer): - def __init__(self, width, height, nPixCell=60): + def __init__(self, width, height, jupyter=False): self.yxBase = (0, 0) self.linewidth = 4 self.nAgentColors = 1 # overridden in loadAgent @@ -39,16 +39,20 @@ class PILGL(GraphicsLayer): self.width = width self.height = height - self.screen_width = 99999 - self.screen_height = 99999 - for m in get_monitors(): - self.screen_height = min(self.screen_height,m.height) - self.screen_width = min(self.screen_width,m.width) - w = (self.screen_width-self.width-10)/(self.width + 1 + self.linewidth) - h = (self.screen_height-self.height-10)/(self.height + 1 + self.linewidth) - self.nPixCell = int(max(1,np.ceil(min(w,h)))) + if jupyter == False: + self.screen_width = 99999 + self.screen_height = 99999 + for m in get_monitors(): + self.screen_height = min(self.screen_height,m.height) + self.screen_width = min(self.screen_width,m.width) + w = (self.screen_width-self.width-10)/(self.width + 1 + self.linewidth) + h = (self.screen_height-self.height-10)/(self.height + 1 + self.linewidth) + self.nPixCell = int(max(1,np.ceil(min(w,h)))) + else: + self.nPixCell = 40 + # Total grid size at native scale self.widthPx = self.width * self.nPixCell + self.linewidth self.heightPx = self.height * self.nPixCell + self.linewidth @@ -119,7 +123,7 @@ class PILGL(GraphicsLayer): self.window = tk.Tk() self.window.title("Flatland") self.window.configure(background='grey') - self.window.geometry('%dx%d+%d+%d' % (self.widthPx, self.heightPx, self.xPx, self.yPx)) + #self.window.geometry('%dx%d+%d+%d' % (self.widthPx, self.heightPx, self.xPx, self.yPx)) self.window_open = True def close_window(self): @@ -213,11 +217,11 @@ class PILGL(GraphicsLayer): class PILSVG(PILGL): - def __init__(self, width, height): + def __init__(self, width, height,jupyter=False): print(self, type(self)) oSuper = super() print(oSuper, type(oSuper)) - oSuper.__init__(width, height) + oSuper.__init__(width, height,jupyter) # self.track = self.track = Track() # self.lwTrack = [] diff --git a/flatland/utils/render_qt.py b/flatland/utils/render_qt.py index dc2217c3ee9041caf39c88d8898bf3fb0c7cb24e..97a0799b42af2b545d2496a3ca2488d16b9e3c70 100644 --- a/flatland/utils/render_qt.py +++ b/flatland/utils/render_qt.py @@ -112,7 +112,7 @@ class QTGL(GraphicsLayer): class QTSVG(GraphicsLayer): - def __init__(self, width, height): + def __init__(self, width, height, jupyter=False): self.app = QApplication([]) self.wWinMain = QMainWindow() diff --git a/flatland/utils/rendertools.py b/flatland/utils/rendertools.py index 14a2de1f84f6f7c7c15d1c93821df4b099917870..a4ad66d95184203015110c68a3f38c16eae0e192 100644 --- a/flatland/utils/rendertools.py +++ b/flatland/utils/rendertools.py @@ -15,7 +15,7 @@ import numpy as np import os class MPLGL(GraphicsLayer): - def __init__(self, width, height): + def __init__(self, width, height,jupyter=False): self.width = width self.height = height self.yxBase = array([6, 21]) # pixel offset @@ -119,7 +119,7 @@ class RenderTool(object): gTheta = np.linspace(0, np.pi / 2, 5) gArc = array([np.cos(gTheta), np.sin(gTheta)]).T # from [1,0] to [0,1] - def __init__(self, env, gl="MPL", show=False): + def __init__(self, env, gl="MPL", jupyter=False): self.env = env self.iFrame = 0 self.time1 = time.time() @@ -127,15 +127,15 @@ class RenderTool(object): # self.gl = MPLGL() if gl == "MPL": - self.gl = MPLGL(env.width, env.height) + self.gl = MPLGL(env.width, env.height,jupyter) elif gl == "QT": - self.gl = QTGL(env.width, env.height) + self.gl = QTGL(env.width, env.height,jupyter) elif gl == "PIL": - self.gl = PILGL(env.width, env.height) + self.gl = PILGL(env.width, env.height,jupyter) elif gl == "PILSVG": - self.gl = PILSVG(env.width, env.height) + self.gl = PILSVG(env.width, env.height,jupyter) elif gl == "QTSVG": - self.gl = QTSVG(env.width, env.height) + self.gl = QTSVG(env.width, env.height,jupyter) self.new_rail = True diff --git a/notebooks/Editor2.ipynb b/notebooks/Editor2.ipynb index 0e3f54661d432670a8a938b565e16bfac218227e..b51aae6b936a8f3af0856a2b8281e053bf060c1d 100644 --- a/notebooks/Editor2.ipynb +++ b/notebooks/Editor2.ipynb @@ -56,7 +56,15 @@ "cell_type": "code", "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "cairo installed: OK\n" + ] + } + ], "source": [ "from flatland.utils.editor import EditorMVC, EditorModel, View, Controller" ] @@ -106,7 +114,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "aa182ad0390745ef99f82d330f22edbc", + "model_id": "7e8d0b5604ed45d6a0ed9c935157169c", "version_major": 2, "version_minor": 0 }, @@ -132,7 +140,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "1d2b965bf6ab497585594dd64ac9be66", + "model_id": "2efd4100033d401d9f79aba6d4cf1df4", "version_major": 2, "version_minor": 0 },