dabo Commit
Revision 4834
Date: 2008-12-14 10:25:43 -0800 (Sun, 14 Dec 2008)
Author: Ed
Trac: http://trac.dabodev.com/dabo/changeset/4834
Changed:
U trunk/dabo/dApp.py
U trunk/dabo/ui/uiwx/__init__.py
U trunk/dabo/ui/uiwx/dForm.py
U trunk/dabo/ui/uiwx/dFormMixin.py
U trunk/dabo/ui/uiwx/uiApp.py
Log:
Added the ability to reload a live form when it is based on a .cdxml file. This
is analogous to reloading a web page, except that all the bizobj information is
preserved.
Moved the refresh() method out of dForm and into dFormMixin.
Diff:
Modified: trunk/dabo/dApp.py
===================================================================
--- trunk/dabo/dApp.py 2008-12-14 18:24:02 UTC (rev 4833)
+++ trunk/dabo/dApp.py 2008-12-14 18:25:43 UTC (rev 4834)
@@ -1150,6 +1150,8 @@
self.uiApp.onEditFindAgain(evt)
def onShowSizerLines(self, evt):
self.uiApp.onShowSizerLines(evt)
+ def onReloadForm(self, evt):
+ self.uiApp.onReloadForm(evt)
def onEditPreferences(self, evt):
if self.beforeEditPreferences() is False:
Modified: trunk/dabo/ui/uiwx/__init__.py
===================================================================
--- trunk/dabo/ui/uiwx/__init__.py 2008-12-14 18:24:02 UTC (rev 4833)
+++ trunk/dabo/ui/uiwx/__init__.py 2008-12-14 18:25:43 UTC (rev 4834)
@@ -1060,7 +1060,7 @@
def resolvePathAndUpdate(srcFile):
app = dabo.dAppRef
- cwd = os.getcwd()
+ hd = app.HomeDirectory
opexists = os.path.exists
# Make sure that the file exists
if not opexists(srcFile):
@@ -1071,7 +1071,7 @@
while keepLooping:
keepLooping = False
for subd in ("ui", "forms", "menus", "resources", "db",
"biz"):
- newpth = os.path.join(cwd, subd, fname)
+ newpth = os.path.join(hd, subd, fname)
if opexists(newpth):
srcFile = newpth
break
@@ -1086,7 +1086,7 @@
if app.SourceURL:
# The srcFile has an absolute path; the URLs work on
relative.
try:
- splt = srcFile.split(cwd)[1].lstrip("/")
+ splt = srcFile.split(hd)[1].lstrip("/")
except IndexError:
splt = srcFile
app.urlFetch(splt)
@@ -1106,21 +1106,35 @@
return srcFile
-def createForm(srcFile, show=False, *args, **kwargs):
- """Pass in a .cdxml file from the Designer, and this will
- instantiate a form from that spec. Returns a reference
- to the newly-created form.
- """
- from dabo.lib.DesignerXmlConverter import DesignerXmlConverter
+def _checkForRawXML(srcFile):
isRawXML = srcFile.strip().startswith("<")
if not isRawXML:
try:
srcFile = resolvePathAndUpdate(srcFile)
except IOError, e:
- stop(e, _("File Not Found"))
- return
+ dabo.errorLog.write(_("Class file '%s' not found") %
srcFile)
+ raise
+ return srcFile, isRawXML
+
+
+def createClass(srcFile, *args, **kwargs):
+ """Given a .cdxml class definition file path, will return the
+ corresponding Python class."""
+ from dabo.lib.DesignerXmlConverter import DesignerXmlConverter
+ srcFile, isRaw = _checkForRawXML(srcFile)
conv = DesignerXmlConverter()
cls = conv.classFromXml(srcFile)
+ if not isRaw:
+ cls._sourceFilePath = srcFile
+ return cls
+
+
+def createForm(srcFile, show=False, *args, **kwargs):
+ """Pass in a .cdxml file from the Designer, and this will
+ instantiate a form from that spec. Returns a reference
+ to the newly-created form.
+ """
+ cls = createClass(srcFile)
frm = cls(*args, **kwargs)
if show:
frm.show()
Modified: trunk/dabo/ui/uiwx/dForm.py
===================================================================
--- trunk/dabo/ui/uiwx/dForm.py 2008-12-14 18:24:02 UTC (rev 4833)
+++ trunk/dabo/ui/uiwx/dForm.py 2008-12-14 18:25:43 UTC (rev 4834)
@@ -99,31 +99,6 @@
func(message=msg, title=title)
- def refresh(self, interval=None):
- """Repaints the form and all contained objects.
-
- This method is called repeatedly from many different places
during
- a single change in the UI, so by default the actual execution
is cached
- using callAfterInterval(). The default interval is 100
milliseconds. You
- can change that to suit your app needs by passing a different
interval
- in milliseconds.
-
- Sometimes, though, you want to force immediate execution of the
- refresh. In these cases, pass an interval of 0 to this method,
which
- means don't wait; execute now.
- """
- if interval is None:
- interval = 100
- if interval == 0:
- self.__refresh()
- else:
- dabo.ui.callAfterInterval(interval, self.__refresh)
- def __refresh(self):
- self.Freeze()
- super(BaseForm, self).refresh()
- self.Thaw()
-
-
def update(self, interval=None):
"""Updates the contained controls with current values from the
source.
Modified: trunk/dabo/ui/uiwx/dFormMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dFormMixin.py 2008-12-14 18:24:02 UTC (rev 4833)
+++ trunk/dabo/ui/uiwx/dFormMixin.py 2008-12-14 18:25:43 UTC (rev 4834)
@@ -272,8 +272,44 @@
if not hasattr(ac, "_oldVal") or (not ac._oldVal) or
(ac._oldVal != ac.Value):
return ac.flushValue()
return True
-
-
+
+
+ def refresh(self, interval=None):
+ """Repaints the form and all contained objects.
+
+ This method is called repeatedly from many different places
during
+ a single change in the UI, so by default the actual execution
is cached
+ using callAfterInterval(). The default interval is 100
milliseconds. You
+ can change that to suit your app needs by passing a different
interval
+ in milliseconds.
+
+ Sometimes, though, you want to force immediate execution of the
+ refresh. In these cases, pass an interval of 0 to this method,
which
+ means don't wait; execute now.
+ """
+ if interval is None:
+ interval = 100
+ if interval == 0:
+ self.__refresh()
+ else:
+ dabo.ui.callAfterInterval(interval, self.__refresh)
+ def __refresh(self):
+ self.Freeze()
+ super(dFormMixin, self).refresh()
+ self.Thaw()
+
+
+ def reload(self):
+ """Tells the application to check for a newer version of the
form, and if there is,
+ to replace this instance with an instance of the newer class.
+ """
+ # First, create a dummy event object
+ class DummyEvent(object): pass
+ evt = DummyEvent()
+ evt.EventObject = self
+ dabo.ui.callAfter(self.Application.onReloadForm, evt)
+
+
def createBizobjs(self):
"""Can be overridden in instances to create the bizobjs this
form needs.
It is provided so that tools such as the Class Designer can
create skeleton
Modified: trunk/dabo/ui/uiwx/uiApp.py
===================================================================
--- trunk/dabo/ui/uiwx/uiApp.py 2008-12-14 18:24:02 UTC (rev 4833)
+++ trunk/dabo/ui/uiwx/uiApp.py 2008-12-14 18:25:43 UTC (rev 4834)
@@ -1007,6 +1007,29 @@
self.ActiveForm.refresh()
+ def onReloadForm(self, evt):
+ """Re-creates the active form with a newer class definition."""
+ frm = evt.EventObject
+ if not frm:
+ frm = self.ActiveForm
+ try:
+ pth = frm._sourceFilePath
+ except AttributeError:
+ dabo.errorLog.write(_("Only .cdxml forms can be
re-loaded"))
+ return
+ frm.lockDisplay()
+ # Store the old form's bizobj dict
+ bizDict = frm.bizobjs
+ bizPrimary = frm.PrimaryBizobj
+ newForm = dabo.ui.createForm(pth)
+ newForm.Position = frm.Position
+ newForm.Size = frm.Size
+ newForm.bizobjs = bizDict
+ newForm.PrimaryBizobj = bizPrimary
+ dabo.ui.callAfter(frm.release)
+ newForm.show()
+
+
def _getActiveForm(self):
af = getattr(self, "_activeForm", None)
if af is None:
_______________________________________________
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]