fix backtrace on opening program/resource on small screens
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Mon, 10 Apr 2017 18:29:12 +0300
changeset 1675 5f4e53508e4e
parent 1674 85e22d514c05
child 1676 eed01e0ab32a
fix backtrace on opening program/resource on small screens

Fix regression introduced by f4696d8 ("add stretching to columns Name,
Type, Doc in variable panel").
This problem happens only on wxPython-3.0.
controls/VariablePanel.py
--- a/controls/VariablePanel.py	Fri Apr 07 16:54:31 2017 +0300
+++ b/controls/VariablePanel.py	Mon Apr 10 18:29:12 2017 +0300
@@ -457,7 +457,7 @@
             setattr(self, name, button)
             controls_sizer.AddWindow(button)
 
-        self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL)
+        self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL | wx.HSCROLL)
         self.VariablesGrid.SetDropTarget(VariableDropTarget(self))
         self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE,
               self.OnVariablesGridCellChange)
@@ -532,6 +532,8 @@
             self.ColAlignements = [c,   l,      l,      l,      l,      l,       l]
             self.ColFixedSizeFlag=[True,False,  True,   False,  True,   True,    False]
 
+        self.PanelWidthMin = sum(self.ColSizes)
+        
         self.ElementType = element_type
         self.BodyType = None
 
@@ -638,20 +640,23 @@
                 self.DownButton.Enable(not self.Debug and (table_length > 0 and row < table_length - 1 and self.Filter == "All"))
         setattr(self.VariablesGrid, "RefreshButtons", _RefreshButtons)
 
-        stretch_cols_width = window.Parent.ScreenRect.Width - 35
-        stretch_cols_sum = 0
-        for col  in range(len(self.ColFixedSizeFlag)):
-            if self.ColFixedSizeFlag[col]:
-                stretch_cols_width -= self.ColSizes[col]
-            else:
-                stretch_cols_sum += self.ColSizes[col]
+        panel_width = window.Parent.ScreenRect.Width - 35
+        if panel_width > self.PanelWidthMin:
+            stretch_cols_width = panel_width
+            stretch_cols_sum = 0            
+            for col in range(len(self.ColFixedSizeFlag)):
+                if self.ColFixedSizeFlag[col]:
+                    stretch_cols_width -= self.ColSizes[col]
+                else:
+                    stretch_cols_sum += self.ColSizes[col]
+
         self.VariablesGrid.SetRowLabelSize(0)
         for col in range(self.Table.GetNumberCols()):
             attr = wx.grid.GridCellAttr()
             attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
             self.VariablesGrid.SetColAttr(col, attr)
             self.VariablesGrid.SetColMinimalWidth(col, self.ColSizes[col])
-            if not self.ColFixedSizeFlag[col]:
+            if (panel_width > self.PanelWidthMin) and not self.ColFixedSizeFlag[col]:
                 self.VariablesGrid.SetColSize(col, int((float(self.ColSizes[col])/stretch_cols_sum)*stretch_cols_width))
             else:
                 self.VariablesGrid.SetColSize(col, self.ColSizes[col])