]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/util/__init__.py
1 #----------------------------------------------------------------------------
9 # Copyright: (c) 2004-2005 ActiveGrid, Inc.
10 # License: wxWindows License
11 #----------------------------------------------------------------------------
20 def classForName(className
):
21 pathList
= className
.split('.')
22 moduleName
= string
.join(pathList
[:-1], '.')
23 code
= __import__(moduleName
)
24 for name
in pathList
[1:]:
25 code
= code
.__dict
__[name
]
28 def hasattrignorecase(object, name
):
29 for attr
in dir(object):
30 if attr
.lower() == name
.lower():
32 for attr
in dir(object):
33 if attr
.lower() == '_' + name
.lower():
38 def setattrignorecase(object, name
, value
):
39 for attr
in object.__dict
__:
40 if attr
.lower() == name
.lower():
41 object.__dict
__[attr
] = value
43 ## for attr in dir(object):
44 ## if attr.lower() == '_' + name.lower():
45 ## object.__dict__[attr] = value
47 object.__dict
__[name
] = value
49 def getattrignorecase(object, name
):
50 for attr
in object.__dict
__:
51 if attr
.lower() == name
.lower():
52 return object.__dict
__[attr
]
53 ## for attr in dir(object):
54 ## if attr.lower() == '_' + name.lower():
55 ## return object.__dict__[attr]
56 return object.__dict
__[name
]
59 def defaultLoad(fileObject
, knownTypes
=None):
60 xml
= fileObject
.read()
61 loadedObject
= xmlmarshaller
.unmarshal(xml
, knownTypes
=knownTypes
)
62 if hasattr(fileObject
, 'name'):
63 loadedObject
.fileName
= os
.path
.abspath(fileObject
.name
)
64 loadedObject
.initialize()
67 def defaultSave(fileObject
, objectToSave
, knownTypes
=None):
68 xml
= xmlmarshaller
.marshal(objectToSave
, prettyPrint
=True, knownTypes
=knownTypes
)
72 def clone(objectToClone
):
73 xml
= xmlmarshaller
.marshal(objectToClone
, prettyPrint
=True)
74 clonedObject
= xmlmarshaller
.unmarshal(xml
)
75 if hasattr(objectToClone
, 'fileName'):
76 clonedObject
.fileName
= objectToClone
.fileName
77 clonedObject
.initialize()
80 def exceptionToString(e
):
81 sio
= cStringIO
.StringIO()
82 traceback
.print_exception(e
.__class
__, e
, sys
.exc_traceback
, file=sio
)