Replacing Panel by ScrolledWindow for displaying node information for more clarity when window is small
authorLaurent Bessard
Wed, 23 May 2012 10:39:14 +0200
changeset 2058 b3bc00dae385
parent 2057 bb63c0479411
child 2059 b74955d211c7
Replacing Panel by ScrolledWindow for displaying node information for more clarity when window is small
etherlab/ConfigEditor.py
--- a/etherlab/ConfigEditor.py	Tue May 22 22:28:05 2012 +0200
+++ b/etherlab/ConfigEditor.py	Wed May 23 10:39:14 2012 +0200
@@ -3,7 +3,7 @@
 import wx.gizmos
 
 from controls import CustomGrid, CustomTable
-from ConfTreeNodeEditor import ConfTreeNodeEditor
+from ConfTreeNodeEditor import ConfTreeNodeEditor, SCROLLBAR_UNIT
 
 [ETHERCAT_VENDOR, ETHERCAT_GROUP, ETHERCAT_DEVICE] = range(3)
 
@@ -80,8 +80,9 @@
         self.ConfNodeEditor.SetSizer(self.MainSizer)
 
     def _init_ConfNodeEditor(self, prnt):
-        self.ConfNodeEditor = wx.Panel(id=-1, name='SlavePanel', parent=prnt,
-              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
+        self.ConfNodeEditor = wx.ScrolledWindow(id=-1, name='SlavePanel', parent=prnt,
+              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL)
+        self.ConfNodeEditor.Bind(wx.EVT_SIZE, self.OnConfNodeEditorResize)
         
         self.VendorLabel = wx.StaticText(id=ID_NODEEDITORVENDORLABEL,
               label=_('Vendor:'), name='VendorLabel', parent=self.ConfNodeEditor,
@@ -121,7 +122,7 @@
         
         self.SyncManagersGrid = CustomGrid(id=ID_NODEEDITORSYNCMANAGERSGRID,
               name='SyncManagersGrid', parent=self.ConfNodeEditor, pos=wx.Point(0, 0), 
-              size=wx.Size(0, 0), style=wx.VSCROLL)
+              size=wx.Size(0, 200), style=wx.VSCROLL)
         
         self.VariablesLabel =  wx.StaticText(id=ID_NODEEDITORVARIABLESLABEL,
               label=_('Variable entries:'), name='VariablesLabel', parent=self.ConfNodeEditor,
@@ -129,11 +130,11 @@
         
         self.VariablesGrid = wx.gizmos.TreeListCtrl(id=ID_NODEEDITORVARIABLESGRID,
               name='VariablesGrid', parent=self.ConfNodeEditor, pos=wx.Point(0, 0), 
-              size=wx.Size(0, 0), style=wx.TR_DEFAULT_STYLE |
-                                        wx.TR_ROW_LINES |
-                                        wx.TR_COLUMN_LINES |
-                                        wx.TR_HIDE_ROOT |
-                                        wx.TR_FULL_ROW_HIGHLIGHT)
+              size=wx.Size(0, 400), style=wx.TR_DEFAULT_STYLE |
+                                          wx.TR_ROW_LINES |
+                                          wx.TR_COLUMN_LINES |
+                                          wx.TR_HIDE_ROOT |
+                                          wx.TR_FULL_ROW_HIGHLIGHT)
         self.VariablesGrid.GetMainWindow().Bind(wx.EVT_LEFT_DOWN, self.OnVariablesGridLeftClick)
                 
         self._init_sizers()
@@ -252,4 +253,16 @@
             
         event.Skip()
 
+    def OnConfNodeEditorResize(self, event):
+        self.ConfNodeEditor.GetBestSize()
+        xstart, ystart = self.ConfNodeEditor.GetViewStart()
+        window_size = self.ConfNodeEditor.GetClientSize()
+        maxx, maxy = self.ConfNodeEditor.GetMinSize()
+        posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
+        posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
+        self.ConfNodeEditor.Scroll(posx, posy)
+        self.ConfNodeEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
+                maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
+        event.Skip()
+
 CIA402NodeEditor = NodeEditor