Adding support for saving frame size while closing and restore it at next launch
authorlaurent
Thu, 21 Apr 2011 11:06:17 +0200
changeset 535 08f32198e932
parent 534 d506a353b3d3
child 536 288324dddfb8
Adding support for saving frame size while closing and restore it at next launch
PLCOpenEditor.py
--- a/PLCOpenEditor.py	Thu Apr 21 09:55:28 2011 +0200
+++ b/PLCOpenEditor.py	Thu Apr 21 11:06:17 2011 +0200
@@ -632,6 +632,7 @@
     #  @param debug The filepath to open if no controler defined (default: False).
     def __init__(self, parent, enable_debug = False):
         self.Controler = None
+        self.Config = wx.ConfigBase.Get()
         self.EnableDebug = enable_debug
         
         self._init_ctrls(parent)
@@ -696,9 +697,27 @@
         self.PageSetupData.SetMarginBottomRight(wx.Point(10, 20))
         
         self.SetRefreshFunctions()
-        
-        self.Maximize()
-        
+    
+    def Show(self):
+        wx.Frame.Show(self)
+        wx.CallAfter(self.RestoreFrameSize)
+    
+    def RestoreFrameSize(self):
+        frame_size = None
+        if self.Config.HasEntry("framesize"):
+            frame_size = cPickle.loads(str(self.Config.Read("framesize")))
+        
+        if frame_size is None:
+            self.Maximize()
+        else:
+            self.SetClientSize(frame_size)
+    
+    def SaveFrameSize(self):
+        if not self.IsMaximized():
+            self.Config.Write("framesize", cPickle.dumps(self.GetClientSize()))
+        elif self.Config.HasEntry("framesize"):
+            self.Config.DeleteEntry("framesize")
+        self.Config.Flush()
 
 #-------------------------------------------------------------------------------
 #                               General Functions
@@ -2526,6 +2545,9 @@
         if self.Controler is None or self.CheckSaveBeforeClosing(_("Close Application")):
             if USE_AUI:
                 self.AUIManager.UnInit()
+            
+            self.SaveFrameSize()
+            
             event.Skip()
         else:
             event.Veto()