dabo Commit
Revision 7049
Date: 2012-01-11 15:09:16 -0800 (Wed, 11 Jan 2012)
Author: Paul
Trac: http://trac.dabodev.com/changeset/7049
Changed:
U trunk/dabo/ui/uiwx/dHtmlBox.py
Log:
Enhanced dHtmlBox to allow link hrefs to refer to application or
form methods. For instance, I have this html in the dHtmlBox,
which is a listing of orders and payments:
<li><a href="app://showOrder?11234">Order 11234</a></li>
<li><a href="app://showOrder?11235">Order 11235</a></li>
<li><a href="app://showPayment?9932">Payment 9932</a></li>
When the user clicks on the first link ("Order 11234"), the following
code will be executed:
self.Application.showOrder("11234")
This is basically allowing me to make html drill-down reports.
Diff:
Modified: trunk/dabo/ui/uiwx/dHtmlBox.py
===================================================================
--- trunk/dabo/ui/uiwx/dHtmlBox.py 2012-01-05 22:18:36 UTC (rev 7048)
+++ trunk/dabo/ui/uiwx/dHtmlBox.py 2012-01-11 23:09:16 UTC (rev 7049)
@@ -59,13 +59,43 @@
def __onLinkClicked(self, evt):
if self.RespondToLinks:
- if wb and self.OpenLinksInBrowser:
+ if evt.href.startswith("app://") or
evt.href.startswith("form://"):
+ # query string contains method to call and
optional arguments.
+ self._processInternalLink(evt.href)
+ evt.stop()
+ elif wb and self.OpenLinksInBrowser:
wb.open(evt.href, new=True)
else:
# Open in the control itself
self.Page = evt.href
+ def _processInternalLink(self, queryString):
+ # Note that all arguments are string
+ if queryString.startswith("app://"):
+ obj = self.Application
+ elif queryString.startswith("form://"):
+ obj = self.Form
+ else:
+ raise ValueError, _("Internal link must resolve to Form
or Application.")
+ queryString = queryString[queryString.index("//") + 2:]
+ try:
+ meth, args = queryString.split("?")
+ qsargs = args.split("&")
+ except ValueError:
+ meth = queryString
+ qsargs = []
+ args = []
+ kwargs = {}
+ for qsarg in qsargs:
+ try:
+ name, value = qsarg.split("=", 1)
+ kwargs[name] = value
+ except ValueError:
+ args.append(qsarg)
+ getattr(obj, meth)(*args, **kwargs)
+
+
def copy(self):
"""Implement the plain text version of copying"""
return self.SelectionToText()
_______________________________________________
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]