dabo Commit
Revision 4115
Date: 2008-06-08 08:05:30 -0700 (Sun, 08 Jun 2008)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/4115
Changed:
U trunk/dabo/ui/uiwx/__init__.py
U trunk/dabo/ui/uiwx/dBaseMenuBar.py
U trunk/dabo/ui/uiwx/dFormMixin.py
U trunk/dabo/ui/uiwx/dImage.py
U trunk/dabo/ui/uiwx/dMenu.py
U trunk/dabo/ui/uiwx/dMenuItem.py
U trunk/dabo/ui/uiwx/dPanel.py
U trunk/dabo/ui/uiwx/dPemMixin.py
Log:
Added the method 'resolvePathAndUpdate()' to dabo.ui. This introduces much more
robust path resolution, especially in cases where files are within a project
structure. It also allows to dynamically updated files via the changes in dApp.
Changed several of the creation routines to use resolvePathAndUpdate().
Changed several 'has_key()' calls to try/except structures. Profiling showed
has_key() to be very slow.
Changed the way 'special' items are handled in menus. Previously, the only way
that the About and Preference menu items were handled on OS X was some special
code inserted in dBaseMenuBar. That code is now abstracted out to dMenu and
dMenuItem; there is now an additional parameter that can be included called
'special': right now, the only special item is 'pref', indicating the
Preferences menu. The About menu is keyed off of the id of wx.ID_ABOUT. If
either of these two cases are found, the appropriate Mac-specific menu handling
will occur.
Added 'scrollVertically()' and 'scrollHorizontally()' methods to dScrollPanel,
allowing for external scrolling.
Diff:
Modified: trunk/dabo/ui/uiwx/__init__.py
===================================================================
--- trunk/dabo/ui/uiwx/__init__.py 2008-06-08 14:54:52 UTC (rev 4114)
+++ trunk/dabo/ui/uiwx/__init__.py 2008-06-08 15:05:30 UTC (rev 4115)
@@ -927,21 +927,31 @@
def getSaveAs(*args, **kwargs):
- if not kwargs.has_key("message"):
+ try:
+ kwargs["message"]
+ except KeyError:
kwargs["message"] = "Save to:"
- if kwargs.has_key("wildcard"):
+ try:
+ wc = kwargs["wildcard"]
args = list(args)
- args.append(kwargs["wildcard"])
+ args.append(wc)
+ except KeyError:
+ pass
kwargs["wildcard"] = _getWild(*args)
return _getPath(dSaveDialog, **kwargs)[0]
def getSaveAsAndType(*args, **kwargs):
- if not kwargs.has_key("message"):
+ try:
+ kwargs["message"]
+ except KeyError:
kwargs["message"] = "Save to:"
- if kwargs.has_key("wildcard"):
+ try:
+ wc = kwargs["wildcard"]
args = list(args)
- args.append(kwargs["wildcard"])
+ args.append(wc)
+ except KeyError:
+ pass
kwargs["wildcard"] = _getWild(*args)
pth, idx = _getPath(dSaveDialog, **kwargs)
if idx is None:
@@ -1047,6 +1057,44 @@
return ret
+def resolvePathAndUpdate(srcFile):
+ app = dabo.dAppRef
+ cwd = os.getcwd()
+ opexists = os.path.exists
+ # Make sure that the file exists
+ if not opexists(srcFile):
+ # Try common paths. First use the whole string; then use
+ # each subdirectory in turn.
+ fname = srcFile
+ keepLooping = True
+ while keepLooping:
+ keepLooping = False
+ for subd in ("ui", "forms", "menus", "resources", "db",
"biz"):
+ newpth = os.path.join(cwd, subd, fname)
+ if opexists(newpth):
+ srcFile = newpth
+ break
+ if not opexists(srcFile):
+ try:
+ fname = fname.split(os.path.sep, 1)[1]
+ keepLooping = True
+ except IndexError:
+ # No more directories to remove
+ break
+ if app is not None:
+ if app.SourceURL:
+ # The srcFile has an absolute path; the URLs work on
relative.
+ try:
+ splt = srcFile.split(cwd)[1]
+ except IndexError:
+ splt = srcFile
+ app.urlFetch(splt)
+ # At this point the file should be present and updated. If not...
+ if not os.path.exists(srcFile):
+ raise IOError, _("The file '%s' cannot be found") % srcFile
+ 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
@@ -1055,20 +1103,11 @@
from dabo.lib.DesignerXmlConverter import DesignerXmlConverter
isRawXML = srcFile.strip().startswith("<")
if not isRawXML:
- # Make sure that the file exists
- if not os.path.exists(srcFile):
- # Try common paths
- ok = False
- cwd = os.getcwd()
- for subd in ("ui", "forms", "resources"):
- newpth = os.path.join(cwd, subd, srcFile)
- if os.path.exists(newpth):
- srcFile = newpth
- ok = True
- break
- if not ok:
- stop(_("The file '%s' cannot be found") %
srcFile, _("File Not Found"))
- return
+ try:
+ srcFile = resolvePathAndUpdate(srcFile)
+ except IOError, e:
+ stop(e, _("File Not Found"))
+ return
conv = DesignerXmlConverter()
cls = conv.classFromXml(srcFile)
frm = cls(*args, **kwargs)
@@ -1112,6 +1151,7 @@
cap = itmatts["Caption"]
hk = itmatts["HotKey"]
pic = itmatts["Picture"]
+ special = itmatts.get("special", None)
if hk:
cap += "\t%s" % hk
txt = cap
@@ -1127,8 +1167,13 @@
binding = fnc
help = itmatts["HelpText"]
menuItem = menu.append(cap, OnHit=binding,
help=help,
- picture=pic)
+ picture=pic, special=special)
+ try:
+ srcFile = resolvePathAndUpdate(srcFile)
+ except IOError, e:
+ stop(e, _("File Not Found"))
+ return
mnd = dabo.lib.xmltodict.xmltodict(srcFile)
mb = dabo.ui.dMenuBar()
for mn in mnd["children"]:
@@ -1335,29 +1380,30 @@
final image will be a bitmap resized to those specs.
"""
ret = None
- if _bmpCache.has_key(val):
+ try:
ret = _bmpCache[val]
- elif os.path.exists(val):
- ret = pathToBmp(val)
- else:
- # Include all the pathing possibilities
- iconpaths = [os.path.join(pth, val)
- for pth in dabo.icons.__path__]
- dabopaths = [os.path.join(pth, val)
- for pth in dabo.__path__]
- localpaths = [os.path.join(os.getcwd(), pth, val)
- for pth in ("icons", "resources")]
- # Create a list of the places to search for the image, with
- # the most likely choices first.
- paths = [val] + iconpaths + dabopaths + localpaths
- # See if it's a standard icon
- for pth in paths:
- ret = dIcons.getIconBitmap(pth, noEmptyBmp=True)
- if ret:
- break
- if not ret and len(val) > 0:
- # See if it's a built-in graphic
- ret = getCommonBitmap(val)
+ except KeyError:
+ if os.path.exists(val):
+ ret = pathToBmp(val)
+ else:
+ # Include all the pathing possibilities
+ iconpaths = [os.path.join(pth, val)
+ for pth in dabo.icons.__path__]
+ dabopaths = [os.path.join(pth, val)
+ for pth in dabo.__path__]
+ localpaths = [os.path.join(os.getcwd(), pth, val)
+ for pth in ("icons", "resources")]
+ # Create a list of the places to search for the image,
with
+ # the most likely choices first.
+ paths = [val] + iconpaths + dabopaths + localpaths
+ # See if it's a standard icon
+ for pth in paths:
+ ret = dIcons.getIconBitmap(pth, noEmptyBmp=True)
+ if ret:
+ break
+ if not ret and len(val) > 0:
+ # See if it's a built-in graphic
+ ret = getCommonBitmap(val)
if not ret:
# Return an empty bitmap
ret = wx.EmptyBitmap(1, 1)
Modified: trunk/dabo/ui/uiwx/dBaseMenuBar.py
===================================================================
--- trunk/dabo/ui/uiwx/dBaseMenuBar.py 2008-06-08 14:54:52 UTC (rev 4114)
+++ trunk/dabo/ui/uiwx/dBaseMenuBar.py 2008-06-08 15:05:30 UTC (rev 4115)
@@ -99,13 +99,10 @@
itm = self.append(_("Pr&eferences"),
OnHit=app.onEditPreferences,
bmp="%s/categories/preferences-system.png" %
iconPath,
- help=_("Set user preferences") )
+ help=_("Set user preferences"), special="pref" )
- # Put the prefs item in the App Menu on Mac
- wx.App_SetMacPreferencesMenuItemId(itm.GetId())
-
class ViewMenu(dMenu):
def _afterInit(self):
super(ViewMenu, self)._afterInit()
@@ -137,9 +134,6 @@
itm = self.append(caption, id=wx.ID_ABOUT,
OnHit=app.onHelpAbout,
help=_("About this application") )
- # Put the about menu in the App Menu on Mac
- wx.App_SetMacAboutMenuItemId(itm.GetId())
- wx.App_SetMacHelpMenuTitleName(self.Caption)
class dBaseMenuBar(dMenuBar):
Modified: trunk/dabo/ui/uiwx/dFormMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dFormMixin.py 2008-06-08 14:54:52 UTC (rev 4114)
+++ trunk/dabo/ui/uiwx/dFormMixin.py 2008-06-08 15:05:30 UTC (rev 4115)
@@ -582,6 +582,8 @@
txt = self._statusStack.pop()
if txt:
self.StatusText = txt
+ else:
+ self.StatusText = ""
################################
Modified: trunk/dabo/ui/uiwx/dImage.py
===================================================================
--- trunk/dabo/ui/uiwx/dImage.py 2008-06-08 14:54:52 UTC (rev 4114)
+++ trunk/dabo/ui/uiwx/dImage.py 2008-06-08 15:05:30 UTC (rev 4115)
@@ -208,6 +208,9 @@
origVal = val
val = dabo.ui.getImagePath(val)
if val is None or not os.path.exists(val):
+ # This will raise an IOError if it fails
+ val =
dabo.ui.resolvePathAndUpdate(origVal)
+ if val is None or not os.path.exists(val):
# Bad image reference
raise IOError, "No file named '%s'
exists." % origVal
self._picture = val
Modified: trunk/dabo/ui/uiwx/dMenu.py
===================================================================
--- trunk/dabo/ui/uiwx/dMenu.py 2008-06-08 14:54:52 UTC (rev 4114)
+++ trunk/dabo/ui/uiwx/dMenu.py 2008-06-08 15:05:30 UTC (rev 4115)
@@ -126,9 +126,30 @@
self._daboChildren[wxItem.GetId()] = dMenuItemInstance
if dMenuItemInstance.Icon and sys.platform.lower()[:3] == "win":
wxItem.SetBitmap(dMenuItemInstance.Icon)
+ self._processNewItem(wxItem, dMenuItemInstance)
return wxItem
+ def _processNewItem(self, itm, daboItem):
+ """After a menu item is created, perform any platform-specific
handling."""
+ id_ = itm.GetId()
+ if id_ == wx.ID_ABOUT:
+ # Put the about menu in the App Menu on Mac
+ wx.App_SetMacAboutMenuItemId(id_)
+ cap = daboItem.Parent.Caption
+ wx.App_SetMacHelpMenuTitleName(cap)
+
+ # Process any 'special' menus
+ try:
+ special = daboItem._special
+ print special
+ except AttributeError:
+ return
+ if special == "pref":
+ # Put the prefs item in the App Menu on Mac
+ wx.App_SetMacPreferencesMenuItemId(id_)
+
+
def appendItem(self, item):
"""Insert a dMenuItem at the bottom of the menu."""
wxItem = self._getWxItem(self.AppendItem, item)
@@ -209,8 +230,8 @@
self.appendItem(item)
item.Caption = caption
return item
-
-
+
+
def insert(self, pos, caption, bindfunc=None, help="", bmp=None,
picture=None,
menutype="", *args, **kwargs):
"""Insert a dMenuItem at the given position with the specified
properties.
@@ -349,12 +370,18 @@
itmid = self._getItemID(menutype)
if itmid != wx.ID_DEFAULT:
kwargs["id"] = itmid
+ try:
+ itmSpecial = kwargs.pop("special")
+ except KeyError:
+ itmSpecial = None
cls = {NormalItemType: dabo.ui.dMenuItem,
CheckItemType: dabo.ui.dCheckMenuItem,
RadioItemType: dabo.ui.dRadioMenuItem}[itmtyp]
itm = cls(self, HelpText=help, Icon=icon, kind=itmtyp, *args,
**kwargs)
if bindfunc:
itm.bindEvent(dEvents.Hit, bindfunc)
+ if itmSpecial:
+ itm._special = itmSpecial
return itm
Modified: trunk/dabo/ui/uiwx/dMenuItem.py
===================================================================
--- trunk/dabo/ui/uiwx/dMenuItem.py 2008-06-08 14:54:52 UTC (rev 4114)
+++ trunk/dabo/ui/uiwx/dMenuItem.py 2008-06-08 15:05:30 UTC (rev 4115)
@@ -63,7 +63,15 @@
if hk:
cap = "%s\t%s" % (cap, hk)
curr = self.GetText()
- if cap != curr:
+ def toUni(s):
+ if isinstance(s, str):
+ try:
+ enc = self.Application.Encoding
+ except AttributeError:
+ enc = dabo.defaultEncoding
+ s = unicode(s, enc)
+ return s
+ if toUni(cap) != toUni(curr):
## Win32 seems to need to clear the caption first, or
funkiness
## can arise. And win32 in wx2.8 needs for the caption
to never be
## an empty string, or you'll get an invalid stock id
assertion.
Modified: trunk/dabo/ui/uiwx/dPanel.py
===================================================================
--- trunk/dabo/ui/uiwx/dPanel.py 2008-06-08 14:54:52 UTC (rev 4114)
+++ trunk/dabo/ui/uiwx/dPanel.py 2008-06-08 15:05:30 UTC (rev 4115)
@@ -216,8 +216,21 @@
attProperties=attProperties, *args, **kwargs)
self.SetScrollRate(10, 10)
# self.SetScrollbars(10, 10, -1, -1)
-
+
+ def scrollHorizontally(self, amt):
+ """Change the horizontal scroll position by 'amt' units."""
+ x,y = self.GetViewStart()
+ self.Scroll(x+amt, y)
+
+
+ def scrollVertically(self, amt):
+ """Change the vertical scroll position by 'amt' units."""
+ x,y = self.GetViewStart()
+ # Scrolling is reversed in the y-axis, so subtract
+ self.Scroll(x, y-amt)
+
+
def _getChildren(self):
ret = super(dScrollPanel, self)._getChildren()
return [kid for kid in ret
Modified: trunk/dabo/ui/uiwx/dPemMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dPemMixin.py 2008-06-08 14:54:52 UTC (rev 4114)
+++ trunk/dabo/ui/uiwx/dPemMixin.py 2008-06-08 15:05:30 UTC (rev 4115)
@@ -72,10 +72,10 @@
# be modified by our pre-init method hooks if needed:
self._preInitProperties = {"parent": parent}
for arg, default in (("style", 0), ("id", -1)):
- if kwargs.has_key(arg):
+ try:
self._preInitProperties[arg] = kwargs[arg]
del kwargs[arg]
- else:
+ except KeyError:
self._preInitProperties[arg] = default
self._initProperties()
@@ -722,10 +722,12 @@
Fail silently if the key combination didn't exist already.
"""
table = self._acceleratorTable
- if table.has_key(keyCombo):
+ try:
self.Unbind(wx.EVT_MENU, id=table[keyCombo][2])
del table[keyCombo]
self.SetAcceleratorTable(wx.AcceleratorTable(table.values()))
+ except KeyError:
+ pass
def _getID(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]