Browse code

Zoom-to-fit on open.

From: Marius Gedminas <marius@gedmin.as>

Jose.R.Fonseca authored on 13/07/2008 03:22:56
Showing 1 changed files

  • xdot.py index 9015686..5e77141 100755
... ...
@@ -968,16 +968,7 @@ class DotWidget(gtk.DrawingArea):
968 968
         self.y = (y1 + y2) / 2
969 969
         self.queue_draw()
970 970
 
971
-    ZOOM_INCREMENT = 1.25
972
-    ZOOM_TO_FIT_MARGIN = 12
973
-
974
-    def on_zoom_in(self, action):
975
-        self.zoom_image(self.zoom_ratio * self.ZOOM_INCREMENT)
976
-
977
-    def on_zoom_out(self, action):
978
-        self.zoom_image(self.zoom_ratio / self.ZOOM_INCREMENT)
979
-
980
-    def on_zoom_fit(self, action):
971
+    def zoom_to_fit(self):
981 972
         rect = self.get_allocation()
982 973
         rect.x += self.ZOOM_TO_FIT_MARGIN
983 974
         rect.y += self.ZOOM_TO_FIT_MARGIN
... ...
@@ -989,6 +980,18 @@ class DotWidget(gtk.DrawingArea):
989 980
         )
990 981
         self.zoom_image(zoom_ratio, center=True)
991 982
 
983
+    ZOOM_INCREMENT = 1.25
984
+    ZOOM_TO_FIT_MARGIN = 12
985
+
986
+    def on_zoom_in(self, action):
987
+        self.zoom_image(self.zoom_ratio * self.ZOOM_INCREMENT)
988
+
989
+    def on_zoom_out(self, action):
990
+        self.zoom_image(self.zoom_ratio / self.ZOOM_INCREMENT)
991
+
992
+    def on_zoom_fit(self, action):
993
+        self.zoom_to_fit()
994
+
992 995
     def on_zoom_100(self, action):
993 996
         self.zoom_image(1.0)
994 997
 
... ...
@@ -1181,6 +1184,7 @@ class DotWindow(gtk.Window):
1181 1184
     def set_dotcode(self, dotcode, filename='<stdin>'):
1182 1185
         if self.widget.set_dotcode(dotcode, filename):
1183 1186
             self.set_title(os.path.basename(filename) + ' - Dot Viewer')
1187
+            self.widget.zoom_to_fit()
1184 1188
 
1185 1189
     def open_file(self, filename):
1186 1190
         try: