Avoid division by zero in case width or height for page are not specified
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Tue, 25 Sep 2018 18:29:10 +0300
changeset 2341 210cddfa16cf
parent 2302 69fefac5760e
child 2342 4ec6d6cd23ca
Avoid division by zero in case width or height for page are not specified

traceback:
File "/home/developer/WorkData/PLC/beremiz/beremiz/editors/Viewer.py", line 3755, in OnPaint
self.DoDrawing(dc)
File "/home/developer/WorkData/PLC/beremiz/beremiz/editors/Viewer.py", line 3723, in DoDrawing
for y in xrange(self.PageSize[1] - (ystart * SCROLLBAR_UNIT) % self.PageSize[1], int(window_size[1] / self.ViewScale[1]), self.PageSize[1]):
<type 'exceptions.ZeroDivisionError'>: integer division or modulo by zero
editors/Viewer.py
--- a/editors/Viewer.py	Wed Aug 29 18:58:51 2018 +0300
+++ b/editors/Viewer.py	Tue Sep 25 18:29:10 2018 +0300
@@ -3717,12 +3717,14 @@
             dc.SetPen(self.PagePen)
             xstart, ystart = self.GetViewStart()
             window_size = self.Editor.GetClientSize()
-            for x in xrange(self.PageSize[0] - (xstart * SCROLLBAR_UNIT) % self.PageSize[0], int(window_size[0] / self.ViewScale[0]), self.PageSize[0]):
-                dc.DrawLine(xstart * SCROLLBAR_UNIT + x + 1, int(ystart * SCROLLBAR_UNIT / self.ViewScale[0]),
-                            xstart * SCROLLBAR_UNIT + x + 1, int((ystart * SCROLLBAR_UNIT + window_size[1]) / self.ViewScale[0]))
-            for y in xrange(self.PageSize[1] - (ystart * SCROLLBAR_UNIT) % self.PageSize[1], int(window_size[1] / self.ViewScale[1]), self.PageSize[1]):
-                dc.DrawLine(int(xstart * SCROLLBAR_UNIT / self.ViewScale[0]), ystart * SCROLLBAR_UNIT + y + 1,
-                            int((xstart * SCROLLBAR_UNIT + window_size[0]) / self.ViewScale[1]), ystart * SCROLLBAR_UNIT + y + 1)
+            if self.PageSize[0] != 0:
+                for x in xrange(self.PageSize[0] - (xstart * SCROLLBAR_UNIT) % self.PageSize[0], int(window_size[0] / self.ViewScale[0]), self.PageSize[0]):
+                    dc.DrawLine(xstart * SCROLLBAR_UNIT + x + 1, int(ystart * SCROLLBAR_UNIT / self.ViewScale[0]),
+                                xstart * SCROLLBAR_UNIT + x + 1, int((ystart * SCROLLBAR_UNIT + window_size[1]) / self.ViewScale[0]))
+            if self.PageSize[1] != 0:
+                for y in xrange(self.PageSize[1] - (ystart * SCROLLBAR_UNIT) % self.PageSize[1], int(window_size[1] / self.ViewScale[1]), self.PageSize[1]):
+                    dc.DrawLine(int(xstart * SCROLLBAR_UNIT / self.ViewScale[0]), ystart * SCROLLBAR_UNIT + y + 1,
+                                int((xstart * SCROLLBAR_UNIT + window_size[0]) / self.ViewScale[1]), ystart * SCROLLBAR_UNIT + y + 1)
 
         # Draw all elements
         for comment in self.Comments.itervalues():