dabo Commit
Revision 2566
Date: 2006-12-20 09:32:34 -0800 (Wed, 20 Dec 2006)
Author: Carl
Changed:
U branches/carl/dabo/ui/uiwx/__init__.py
Log:
refacored _getWild()
Diff:
Modified: branches/carl/dabo/ui/uiwx/__init__.py
===================================================================
--- branches/carl/dabo/ui/uiwx/__init__.py 2006-12-20 15:43:52 UTC (rev
2565)
+++ branches/carl/dabo/ui/uiwx/__init__.py 2006-12-20 17:32:34 UTC (rev
2566)
@@ -1,3 +1,5 @@
+# dabo/ui/uiwx/__init__.py
+
import sys
import os
import re
@@ -758,42 +760,59 @@
def _getWild(*args):
- ret = "*"
- if args:
- arglist = []
- tmplt = "%s Files (*.%s)|*.%s"
- fileDict = {"html" : "HTML",
- "xml" : "XML",
- "txt" : "Text",
- "jpg" : "JPEG",
- "gif" : "GIF",
- "png" : "PNG",
- "ico" : "Icon",
- "bmp" : "Bitmap" }
-
- for a in args:
- descrp = ext = ""
- if a == "py":
- fDesc = "Python Scripts (*.py)|*.py"
- elif a == "*":
- fDesc = "All Files (*)|*"
- elif a == "fsxml":
- fDesc = "Dabo FieldSpec Files (*.fsxml)|*.fsxml"
- elif a == "cnxml":
- fDesc = "Dabo Connection Files
(*.cnxml)|*.cnxml"
- elif a == "rfxml":
- fDesc = "Dabo Report Format Files
(*.rfxml)|*.rfxml"
- elif a == "cdxml":
- fDesc = "Dabo Class Designer Files
(*.cdxml)|*.cdxml"
- else:
- if a in fileDict:
- fDesc = tmplt % (fileDict[a], a, a)
- else:
- fDesc = "%s files (*.%s)|*.%s" %
(a.upper(), a, a)
- arglist.append(fDesc)
- ret = "|".join(arglist)
+ """ returns a pipe delimited list of human readable descriptions """
+ return "|".join(_getWildList(*args))
+
+def _getWildList(*args):
+ """Given a list of extentions (or more like a bunch of parameters),
+ return a list of human readable descriptions
+ defaults to '*'
+ It seems all extentions should be lower case. This should be
examined.
+ """
+ if not args:
+ args = '*'
+ tmplt = "%s Files (*.%s)|*.%s"
+ arglist = []
+ for a in args:
+ try:
+ fDesc = tmplt % ( {
+ 'py':"Python Script",
+ '*':"All",
+ "fsxml":"Dabo FieldSpec",
+ "cnxml":"Dabo Connection",
+ "rfxml":"Dabo Report Format",
+ "cdxml":"Dabo Class Designer",
+ "html" : "HTML",
+ "xml" : "XML",
+ "txt" : "Text",
+ "jpg" : "JPEG",
+ "gif" : "GIF",
+ "png" : "PNG",
+ "ico" : "Icon",
+ "bmp" : "Bitmap" }[a], a, a )
+ except KeyError:
+ # catchall
+ fDesc = tmplt % (a.upper(), a, a)
+ arglist.append(fDesc)
+ # ret = "|".join(arglist)
+ ret = arglist
return ret
+def _test_GetWild():
+ tests = {
+ '*': ['All Files (*.*)|*.*'],
+ 'ico': ['Icon Files (*.ico)|*.ico'],
+ 'foo': ['FOO Files (*.foo)|*.foo'],
+ 'fsxml':['Dabo FieldSpec Files (*.fsxml)|*.fsxml'] }
+ for x, r1 in tests.iteritems():
+ r2 = _getWildList(x)
+ assert r1==r2
+
+ assert _getWildList() == ['All Files (*.*)|*.*']
+ assert _getWildList('fsxml', 'jpg') == \
+ ['Dabo FieldSpec Files (*.fsxml)|*.fsxml', 'JPEG Files
(*.jpg)|*.jpg']
+
+ return 'tests passed'
def sortList(chc, Caption="", ListCaption=""):
"""Wrapper function for the list sorting dialog. Accepts a list,
@@ -1185,9 +1204,9 @@
else:
ret = "file://%s" % ret
return ret
-
+
def setdFormClass(typ):
"""Re-defines 'dForm' as either the SDI form class, or the child MDI
form class, depending on the parameter, which can be either 'SDI'
@@ -1205,3 +1224,6 @@
ColSpan of an item to an illegal value.
"""
pass
+
+if __name__ == "__main__":
+ print _test_GetWild()
\ No newline at end of file
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev