Browse code

Keep zoom to fit on reload

Robert Cranston authored on 25/08/2022 21:22:09
Showing 2 changed files

... ...
@@ -1,7 +1,8 @@
1 1
 About _xdot.py_
2 2
 =================
3 3
 
4
-This is a fork of [`jrfonseca/xdot.py`][] that removes `--filter` restriction.
4
+This is a fork of [`jrfonseca/xdot.py`][] that removes `--filter` restriction
5
+and keeps zoom-to-fit on reload.
5 6
 
6 7
 _xdot.py_ is an interactive viewer for graphs written in [Graphviz](http://www.graphviz.org/)'s [dot language](http://www.graphviz.org/doc/info/lang.html).
7 8
 
... ...
@@ -87,7 +87,7 @@ class DotWidget(Gtk.DrawingArea):
87 87
 
88 88
         self.x, self.y = 0.0, 0.0
89 89
         self.zoom_ratio = 1.0
90
-        self.zoom_to_fit_on_resize = False
90
+        self.zoom_to_fit_on_resize_reload = False
91 91
         self.animation = animation.NoAnimation(self)
92 92
         self.drag_action = actions.NullAction(self)
93 93
         self.presstime = None
... ...
@@ -165,7 +165,7 @@ class DotWidget(Gtk.DrawingArea):
165 165
 
166 166
         parser = XDotParser(xdotcode, graphviz_version=self.graphviz_version)
167 167
         self.graph = parser.parse()
168
-        self.zoom_image(self.zoom_ratio, center=center)
168
+        self.queue_draw()
169 169
 
170 170
     def reload(self):
171 171
         if self.openfilename is not None:
... ...
@@ -177,6 +177,8 @@ class DotWidget(Gtk.DrawingArea):
177 177
                 pass
178 178
             else:
179 179
                 del self.history_back[:], self.history_forward[:]
180
+                if self.zoom_to_fit_on_resize_reload:
181
+                    self.zoom_to_fit()
180 182
 
181 183
     def update(self):
182 184
         if self.openfilename is not None:
... ...
@@ -250,7 +252,7 @@ class DotWidget(Gtk.DrawingArea):
250 252
             self.x += x / self.zoom_ratio - x / zoom_ratio
251 253
             self.y += y / self.zoom_ratio - y / zoom_ratio
252 254
         self.zoom_ratio = zoom_ratio
253
-        self.zoom_to_fit_on_resize = False
255
+        self.zoom_to_fit_on_resize_reload = False
254 256
         self.queue_draw()
255 257
 
256 258
     def zoom_to_area(self, x1, y1, x2, y2):
... ...
@@ -264,7 +266,7 @@ class DotWidget(Gtk.DrawingArea):
264 266
                 float(rect.width)/float(width),
265 267
                 float(rect.height)/float(height)
266 268
             )
267
-        self.zoom_to_fit_on_resize = False
269
+        self.zoom_to_fit_on_resize_reload = False
268 270
         self.x = (x1 + x2) / 2
269 271
         self.y = (y1 + y2) / 2
270 272
         self.queue_draw()
... ...
@@ -280,7 +282,7 @@ class DotWidget(Gtk.DrawingArea):
280 282
             float(rect.height)/float(self.graph.height)
281 283
         )
282 284
         self.zoom_image(zoom_ratio, center=True)
283
-        self.zoom_to_fit_on_resize = True
285
+        self.zoom_to_fit_on_resize_reload = True
284 286
 
285 287
     ZOOM_INCREMENT = 1.25
286 288
     ZOOM_TO_FIT_MARGIN = 12
... ...
@@ -468,7 +470,7 @@ class DotWidget(Gtk.DrawingArea):
468 470
         return True
469 471
 
470 472
     def on_area_size_allocate(self, area, allocation):
471
-        if self.zoom_to_fit_on_resize:
473
+        if self.zoom_to_fit_on_resize_reload:
472 474
             self.zoom_to_fit()
473 475
 
474 476
     def animate_to(self, x, y):