dabo Commit
Revision 6918
Date: 2011-10-25 18:29:37 -0700 (Tue, 25 Oct 2011)
Author: Paul
Trac: http://trac.dabodev.com/changeset/6918

Changed:
U   trunk/dabo/lib/datanav/Form.py
U   trunk/dabo/lib/datanav/Page.py
U   trunk/dabo/ui/uiwx/dForm.py

Log:
Added new property RequeryChildrenOnNavigate to dBizobj, allowing a way to 
(temporarily) suspend requerying any child bizobjs when navigating the 
bizobj. Of course if an appdev does this, they are responsible for turning
it back on and/or calling requeryAllChildren() explicitly.

Reworked the navigation data update code in dForm to take advantage of
this property to navigate the primary bizobj quickly. Now, while the user
is navigating, the frm.afterPointerMove() will fire as the navigation
occurs, allowing appdev code to respond with a quick UI update to that
effect. But only after the DataUpdateDelay has passed will the children
be requeried, the RowNumChanged event be raised, and the form updated.

Reworked some code in datanav and added properties allowing the automatic
setting/unsetting of the new bizobj property depending on whether or not
the browse page is active, allowing for quick scrolling of the main grid.

I've tested this on Linux with my app and with a DataUpdateDelay of 250
it is really a very nice improvement. But of course we need to test on
other platforms as well.
 


Diff:
Modified: trunk/dabo/lib/datanav/Form.py
===================================================================
--- trunk/dabo/lib/datanav/Form.py      2011-10-26 01:21:45 UTC (rev 6917)
+++ trunk/dabo/lib/datanav/Form.py      2011-10-26 01:29:37 UTC (rev 6918)
@@ -1040,6 +1040,28 @@
                self._editPageClass = val
 
 
+       def _getEnableChildRequeriesWhenBrowsing(self):
+               try:
+                       val = self._enableChildRequeriesWhenBrowsing
+               except AttributeError:
+                       val = self._enableChildRequeriesWhenBrowsing = True
+               return val
+
+       def _setEnableChildRequeriesWhenBrowsing(self, val):
+               self._enableChildRequeriesWhenBrowsing = bool(val)
+
+
+       def _getEnableChildRequeriesWhenEditing(self):
+               try:
+                       val = self._enableChildRequeriesWhenEditing
+               except AttributeError:
+                       val = self._enableChildRequeriesWhenEditing = True
+               return val
+
+       def _setEnableChildRequeriesWhenEditing(self, val):
+               self._enableChildRequeriesWhenEditing = bool(val)
+
+
        def _getFormType(self):
                try:
                        return self._formType
@@ -1140,6 +1162,20 @@
        EditPageClass = property(_getEditPageClass, _setEditPageClass, None,
                        _("""Specifies the class to use for the edit page."""))
 
+       EnableChildRequeriesWhenBrowsing = 
property(_getEnableChildRequeriesWhenBrowsing,
+                       _setEnableChildRequeriesWhenBrowsing, None,
+                       _("""Specifies whether child bizobjs are requeried 
automatically when the parent
+                       RowNumber changes, while in the browse page. Default: 
True
+
+                       Turning this to False will result in better performance 
of the browse grid when
+                       there are lots of child bizobjs, but it may result in 
unintended consequences
+                       which is why it is True by default."""))
+
+       EnableChildRequeriesWhenEditing = 
property(_getEnableChildRequeriesWhenEditing,
+                       _setEnableChildRequeriesWhenEditing, None,
+                       _("""Specifies whether child bizobjs are requeried 
automatically when the parent
+                       RowNumber changes, while not in the browse page. 
Default: True"""))
+
        FormType = property(_getFormType, _setFormType, None,
                        _("""Specifies the type of form this is.
 

Modified: trunk/dabo/lib/datanav/Page.py
===================================================================
--- trunk/dabo/lib/datanav/Page.py      2011-10-26 01:21:45 UTC (rev 6917)
+++ trunk/dabo/lib/datanav/Page.py      2011-10-26 01:29:37 UTC (rev 6918)
@@ -69,6 +69,7 @@
        def initEvents(self):
                super(Page, self).initEvents()
                self.bindEvent(dEvents.PageEnter, self.__onPageEnter)
+               self.bindEvent(dEvents.PageLeave, self.__onPageLeave)
 
 
        def __onPageEnter(self, evt):
@@ -82,6 +83,16 @@
                pass
 
 
+       def __onPageLeave(self, evt):
+               self._onPageLeave()
+
+
+       def _onPageLeave(self):
+               """Subclass hook."""
+               pass
+
+
+
        def newRecord(self, ds=None):
                """Called by a browse grid when the user wants to add a new 
row."""
                if ds is None:
@@ -532,8 +543,17 @@
                        self.createItems()
                if self.Form.SetFocusToBrowseGrid:
                        self.BrowseGrid.setFocus()
+               if not self.Form.EnableChildRequeriesWhenBrowsing:
+                       biz = self.Form.getBizobj()
+                       biz.RequeryChildrenOnNavigate = False
 
+       def _onPageLeave(self):
+               if self.Form.EnableChildRequeriesWhenEditing:
+                       biz = self.Form.getBizobj()
+                       biz.RequeryChildrenOnNavigate = True
+                       biz.requeryAllChildren()
 
+
        def createItems(self):
                biz = self.Form.getBizobj()
                grid = self.Form.BrowseGridClass(self, NameBase="BrowseGrid", 
Size=(10, 10))
@@ -559,7 +579,6 @@
 
        def initEvents(self):
                super(EditPage, self).initEvents()
-               self.bindEvent(dEvents.PageLeave, self.__onPageLeave)
                self.Form.bindEvent(dEvents.RowNumChanged, 
self.__onRowNumChanged)
 
 
@@ -574,7 +593,7 @@
                        cg.populate()
 
 
-       def __onPageLeave(self, evt):
+       def _onPageLeave(self):
                self.Form.setPrimaryBizobjToDefault(self.DataSource)
 
 

Modified: trunk/dabo/ui/uiwx/dForm.py
===================================================================
--- trunk/dabo/ui/uiwx/dForm.py 2011-10-26 01:21:45 UTC (rev 6917)
+++ trunk/dabo/ui/uiwx/dForm.py 2011-10-26 01:29:37 UTC (rev 6918)
@@ -237,6 +237,19 @@
                                rowNumber=rowNumber)
 
 
+       def _afterPointerMoveUpdate(self, biz):
+               biz.RequeryChildrenOnNavigate = self.__oldChildRequery
+               self.__oldChildRequery = None 
+               biz.requeryAllChildren()
+               # Notify listeners that the row number changed:
+               self.raiseEvent(dEvents.RowNumChanged,
+                               newRowNumber=biz.RowNumber, 
oldRowNumber=self.__oldRowNum,
+                               bizobj=biz)
+               self.update()
+               self.refresh()
+               self.__inPointerMoveUpdate = False
+
+
        def _moveRecordPointer(self, func, dataSource=None, *args, **kwargs):
                """Move the record pointer using the specified function."""
                self.dataSourceParameter = dataSource
@@ -244,7 +257,7 @@
                        biz = dataSource
                else:
                        biz = self.getBizobj(dataSource)
-               oldRowNum = biz.RowNumber
+               oldRowNum = self.__oldRowNum = biz.RowNumber
 
                if self.activeControlValid() is False:
                        # Field validation failed
@@ -253,29 +266,39 @@
                if err:
                        self.notifyUser(err)
                        return False
+
+               if getattr(self, "__oldChildRequery", None) is None:
+                       self.__oldChildRequery = biz.RequeryChildrenOnNavigate
+                       biz.RequeryChildrenOnNavigate = False
+
+               def bail(msg, meth=None, *args, **kwargs):
+                       if func is None:
+                               meth = self.setStatusText
+                       meth(msg, *args, **kwargs)
+                       biz.RequeryChildrenOnNavigate = self.__oldChildRequery
+                       self.__oldChildRequery = None
+
                try:
                        response = func(*args, **kwargs)
                except dException.NoRecordsException:
-                       self.setStatusText(_("No records in dataset."))
+                       bail(_("No records in dataset."))
                        return False
                except dException.BeginningOfFileException:
-                       
self.setStatusText(self.getCurrentRecordText(dataSource) + " (BOF)")
+                       bail(self.getCurrentRecordText(dataSource) + " (BOF)")
                        return False
                except dException.EndOfFileException:
-                       
self.setStatusText(self.getCurrentRecordText(dataSource) + " (EOF)")
+                       bail(self.getCurrentRecordText(dataSource) + " (EOF)")
                        return False
                except dException.dException, e:
-                       self.notifyUser(ustr(e), exception=e)
+                       bail(ustr(e), meth=self.notifyUser, exception=e)
                        return False
                else:
                        if biz.RowNumber != oldRowNum:
-                               # Notify listeners that the row number changed:
-                               dabo.ui.callAfter(self.raiseEvent, 
dEvents.RowNumChanged,
-                                               newRowNumber=biz.RowNumber, 
oldRowNumber=oldRowNum,
-                                               bizobj=biz)
-                       self.update(self.DataUpdateDelay)
-               self.afterPointerMove()
-               self.refresh()
+                               
dabo.ui.callAfterInterval(self._afterPointerMoveUpdate, self.DataUpdateDelay, 
biz)
+                               self.afterPointerMove()  ## purposely putting 
it here before the update
+                       else:
+                               biz.RequeryChildrenOnNavigate = 
self.__oldChildRequery
+                               self.__oldChildRequery = None
                return True
 
 



_______________________________________________
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