]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/util/__init__.py
Added the ActiveGrid IDE as a sample application
[wxWidgets.git] / wxPython / samples / ide / activegrid / util / __init__.py
1 import logging
2 import cStringIO
3 import traceback
4 import sys
5 import string
6 import os
7
8 def classForName(className):
9 pathList = className.split('.')
10 moduleName = string.join(pathList[:-1], '.')
11 code = __import__(moduleName)
12 for name in pathList[1:]:
13 code = code.__dict__[name]
14 return code
15
16 def hasattrignorecase(object, name):
17 for attr in dir(object):
18 if attr.lower() == name.lower():
19 return True
20 for attr in dir(object):
21 if attr.lower() == '_' + name.lower():
22 return True
23 return False
24
25
26 def setattrignorecase(object, name, value):
27 for attr in object.__dict__:
28 if attr.lower() == name.lower():
29 object.__dict__[attr] = value
30 return
31 ## for attr in dir(object):
32 ## if attr.lower() == '_' + name.lower():
33 ## object.__dict__[attr] = value
34 ## return
35 object.__dict__[name] = value
36
37 def getattrignorecase(object, name):
38 for attr in object.__dict__:
39 if attr.lower() == name.lower():
40 return object.__dict__[attr]
41 ## for attr in dir(object):
42 ## if attr.lower() == '_' + name.lower():
43 ## return object.__dict__[attr]
44 return object.__dict__[name]
45
46
47 def defaultLoad(fileObject):
48 xml = fileObject.read()
49 loadedObject = xmlmarshaller.unmarshal(xml)
50 if hasattr(fileObject, 'name'):
51 loadedObject.fileName = os.path.abspath(fileObject.name)
52 loadedObject.initialize()
53 return loadedObject
54
55 def defaultSave(fileObject, objectToSave):
56 xml = xmlmarshaller.marshal(objectToSave, prettyPrint=True)
57 fileObject.write(xml)
58
59
60 def clone(objectToClone):
61 xml = xmlmarshaller.marshal(objectToClone, prettyPrint=True)
62 clonedObject = xmlmarshaller.unmarshal(xml)
63 if hasattr(objectToClone, 'fileName'):
64 clonedObject.fileName = objectToClone.fileName
65 clonedObject.initialize()
66 return clonedObject
67
68 def exceptionToString(e):
69 sio = cStringIO.StringIO()
70 traceback.print_exception(e.__class__, e, sys.exc_traceback, file=sio)
71 return sio.getvalue()
72