From 87869d15499ebde13dce41bde43ee917a43f7036 Mon Sep 17 00:00:00 2001
From: "Egli Adrian (IT-SCI-API-PFI)" <adrian.egli@sbb.ch>
Date: Wed, 29 May 2019 08:54:59 +0200
Subject: [PATCH] PIL (tk window) position and size

---
 examples/demo.py               |  6 +++---
 flatland/utils/graphics_pil.py | 12 ++++++++----
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/examples/demo.py b/examples/demo.py
index 6e9f053..2afc782 100644
--- a/examples/demo.py
+++ b/examples/demo.py
@@ -199,16 +199,16 @@ if True:
 
     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(300)
+    demo_flatland_000.run_demo(60)
     demo_flatland_000 = None
 
     demo_flatland_000 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_flatland_001.pkl'))
     demo_flatland_000.renderer.resize()
-    demo_flatland_000.run_demo(300)
+    demo_flatland_000.run_demo(60)
     demo_flatland_000 = None
 
 
 demo_flatland_000 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_network_003.pkl'))
 demo_flatland_000.renderer.resize()
-demo_flatland_000.run_demo(1800)
+demo_flatland_000.run_demo(60)
 demo_flatland_000 = None
diff --git a/flatland/utils/graphics_pil.py b/flatland/utils/graphics_pil.py
index cadc2e5..40e0a92 100644
--- a/flatland/utils/graphics_pil.py
+++ b/flatland/utils/graphics_pil.py
@@ -28,14 +28,17 @@ class PILGL(GraphicsLayer):
             self.screen_height = min(self.screen_height,m.height)
             self.screen_width = min(self.screen_width,m.width)
 
-        w = 0.95*self.screen_width/(self.width + 1 + self.linewidth)
-        h = 0.95*self.screen_height/(self.height + 1 + self.linewidth)
-        self.nPixCell = int(max(1,np.floor(min(w,h))))
-
+        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))))
 
         # Total grid size at native scale
         self.widthPx = self.width * self.nPixCell + self.linewidth
         self.heightPx = self.height * self.nPixCell + self.linewidth
+
+        self.xPx = int((self.screen_width - self.widthPx) / 2.0)
+        self.yPx = int((self.screen_height - self.heightPx) / 2.0)
+
         self.layers = []
         self.draws = []
 
@@ -99,6 +102,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_open = True
 
     def close_window(self):
-- 
GitLab