dabo Commit
Revision 5023
Date: 2009-02-06 12:42:03 -0800 (Fri, 06 Feb 2009)
Author: Paul
Trac: http://trac.dabodev.com/changeset/5023

Changed:
U   trunk/dabo/ui/uiwx/dFormMixin.py

Log:
Reworked the restoration of form size, position, and state, inspired by the 
patch submitted by Jacek Ka?\197?\130ucki.

We don't need to wait until the form is activated anymore, as Name will have
been set somewhere in the initProperties() cycle. This change results in a
much smoother form instantiation, as the form isn't shown first in the 
default position, only to jump to the saved position.

I wrote this change on Mac, where it seems to be working sanely. I'll now
test on Linux and Windows.


Diff:
Modified: trunk/dabo/ui/uiwx/dFormMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dFormMixin.py    2009-02-05 23:44:53 UTC (rev 5022)
+++ trunk/dabo/ui/uiwx/dFormMixin.py    2009-02-06 20:42:03 UTC (rev 5023)
@@ -75,8 +75,10 @@
 
                super(dFormMixin, self).__init__(preClass, parent, properties, 
                                attProperties, *args, **kwargs)
-               
+       
+               self.restoreSizeAndPosition()
 
+
        def _getInitPropertiesList(self):
                additional = ["BorderResizable", "FloatOnParent", 
"ShowCloseButton", "ShowInTaskBar", 
                                "ShowMaxButton", "ShowMinButton", 
"ShowSystemMenu", "StayOnTop", "TinyTitleBar"]
@@ -102,7 +104,6 @@
 
                self.debugText = ""
                self.useOldDebugDialog = False
-               self.restoredSP = False
                self._holdStatusText = ""
                self._statusStack = []
                if app is not None:
@@ -159,16 +160,6 @@
        def __onWxActivate(self, evt):
                """ Raise the Dabo Activate or Deactivate appropriately."""
                if bool(evt.GetActive()):
-                       # Restore the saved size and position, which can't 
happen 
-                       # in __init__ because we may not have our name yet.
-                       try:
-                               restoredSP = self.restoredSP
-                       except AttributeError:
-                               restoredSP = False
-                       if not restoredSP:
-                               if self.SaveRestorePosition:
-                                       
dabo.ui.callAfter(self.restoreSizeAndPosition)
-                               
                        self.raiseEvent(dEvents.Activate, evt)
                else:
                        self.raiseEvent(dEvents.Deactivate, evt)
@@ -210,21 +201,11 @@
        
 
        def __onMove(self, evt):
-               try:
-                       restoredSP = self.restoredSP
-               except AttributeError:
-                       restoredSP = False
-               if restoredSP:          
-                       dabo.ui.callAfterInterval(800, self.saveSizeAndPosition)
+               dabo.ui.callAfterInterval(800, self.saveSizeAndPosition)
        
        
        def __onResize(self, evt):
-               try:
-                       restoredSP = self.restoredSP
-               except AttributeError:
-                       restoredSP = False
-               if restoredSP:
-                       dabo.ui.callAfterInterval(800, self.saveSizeAndPosition)
+               dabo.ui.callAfterInterval(800, self.saveSizeAndPosition)
                        
        
        def __onPaint(self, evt):
@@ -483,38 +464,45 @@
                Ask dApp for the last saved setting of height, width, left, and 
top, 
                and set those properties on this form.
                """
-               if self.Application and self.SaveRestorePosition:
-                       name = self.getAbsoluteName()
-                       if not self.Centered:
-                               left = 
self.Application.getUserSetting("%s.left" % name, self._defaultLeft)
-                               top = self.Application.getUserSetting("%s.top" 
% name, self._defaultTop)
-                               if isinstance(left, int) and isinstance(top, 
int):
-                                       self.Position = (left,top)
-                       width = self.Application.getUserSetting("%s.width" % 
name, self._defaultWidth)
-                       height = self.Application.getUserSetting("%s.height" % 
name, self._defaultHeight)
-                       state = 
self.Application.getUserSetting("%s.windowstate" % name, self._defaultState)
+               if not self.Application or not self.SaveRestorePosition:
+                       return
 
-                       if isinstance(width, int) and isinstance(height, int):
-                               if self.BorderResizable:
-                                       self.Size = (width,height)
+               name = self.getAbsoluteName()
+               state = self.Application.getUserSetting("%s.windowstate" % 
name, self._defaultState)
+               width = self.Application.getUserSetting("%s.width" % name, 
self._defaultWidth)
+               height = self.Application.getUserSetting("%s.height" % name, 
self._defaultHeight)
+               left = self.Application.getUserSetting("%s.left" % name, 
self._defaultLeft)
+               top = self.Application.getUserSetting("%s.top" % name, 
self._defaultTop)
 
-                       if state is not None:
-                               if state == "Minimized":
-                                       state = "Normal"
-                               self.WindowState = state
-                       # Make sure that the frame is on the visible display
-                       dispWd, dispHt = dabo.ui.getDisplaySize()
-                       self.Right = min(dispWd, self.Right)
-                       self.Bottom = min(dispHt, self.Bottom)
+               if not isinstance(width, int) or not isinstance(height, int) \
+                               or not isinstance(left, int) or not 
isinstance(top, int):
+                       # size/position unsaved from before
+                       return
+
+               if state not in ("Minimized", "Maximized", "Normal", 
"FullScreen"):
+                       state = self.WindowState
+                       
+               if state == "Minimized":
+                       state = "Normal"
+
+               if self.BorderResizable:
+                       self.Size = (width, height)
+
+               if not self.Centered:
+                       # Make sure that the frame is on the visible display:
+                       self.Position = (left, top)
                        if self.Application.Platform == "Mac":
                                # Need to account for the menu bar
                                minTop = 23
                        else:
                                minTop = 0
+                       dispWd, dispHt = dabo.ui.getDisplaySize()
+                       self.Right = min(dispWd, self.Right)
+                       self.Bottom = min(dispHt, self.Bottom)
                        self.Left = max(0, self.Left)
                        self.Top = max(minTop, self.Top)
 
-                       self.restoredSP = True
+               self.WindowState = state
 
 
        def saveSizeAndPosition(self):



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to