| 1 |
#!/usr/bin/env python |
|---|
| 2 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 3 |
##~ License |
|---|
| 4 |
##~ |
|---|
| 5 |
##- The RuneBlade Foundation library is intended to ease some |
|---|
| 6 |
##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.) |
|---|
| 7 |
##- applications, while providing the flexibility to modularly change the |
|---|
| 8 |
##- architecture. Enjoy. |
|---|
| 9 |
##~ |
|---|
| 10 |
##~ Copyright (C) 2002 TechGame Networks, LLC. |
|---|
| 11 |
##~ |
|---|
| 12 |
##~ This library is free software; you can redistribute it and/or |
|---|
| 13 |
##~ modify it under the terms of the BSD style License as found in the |
|---|
| 14 |
##~ LICENSE file included with this distribution. |
|---|
| 15 |
##~ |
|---|
| 16 |
##~ TechGame Networks, LLC can be reached at: |
|---|
| 17 |
##~ 3578 E. Hartsel Drive #211 |
|---|
| 18 |
##~ Colorado Springs, Colorado, USA, 80920 |
|---|
| 19 |
##~ |
|---|
| 20 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 21 |
|
|---|
| 22 |
"""RBSkinning Components""" |
|---|
| 23 |
|
|---|
| 24 |
__version__ = '0.4.0' |
|---|
| 25 |
__license__ = 'BSD-style (See LICENSE)' |
|---|
| 26 |
__platforms__ ='same as wxPython', |
|---|
| 27 |
__author__ = 'Shane Holloway' |
|---|
| 28 |
__author_email__ = 'shane.holloway@runeblade.com' |
|---|
| 29 |
__url__ = 'http://www.runeblade.com/' |
|---|
| 30 |
__keywords__ = ['skinning', 'xml', 'user interface', 'UI'] |
|---|
| 31 |
__packages__ = ['RBSkinning', |
|---|
| 32 |
'RBSkinning.skin', |
|---|
| 33 |
'RBSkinning.xmlPython', |
|---|
| 34 |
'RBSkinning.xmlObjectifySkin', |
|---|
| 35 |
'RBSkinning.wxPythonSkin', |
|---|
| 36 |
'RBSkinning.wxTools', |
|---|
| 37 |
'RBSkinning.xhtml', |
|---|
| 38 |
'RBSkinning.svg', |
|---|
| 39 |
'RBSkinning.dotSkin'] |
|---|
| 40 |
|
|---|
| 41 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 42 |
#~ Imports |
|---|
| 43 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 44 |
|
|---|
| 45 |
from XMLSkinner import XMLSkinner as _XMLSkinner |
|---|
| 46 |
from RBFoundation.XMLClassBuilder import ElementFactory as EF |
|---|
| 47 |
|
|---|
| 48 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 49 |
#~ Constants / Variables / Etc. |
|---|
| 50 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 51 |
|
|---|
| 52 |
StandardElementFactories = { |
|---|
| 53 |
## Long names |
|---|
| 54 |
('http://namespaces.runeblade.com/skin',): EF.NodeImport('RBSkinning.skin'), |
|---|
| 55 |
('http://namespaces.runeblade.com/wxPythonSkin',): EF.NodeImport('RBSkinning.wxPythonSkin'), |
|---|
| 56 |
('http://namespaces.runeblade.com/xmlPython',): EF.NodeImport('RBSkinning.xmlPython'), |
|---|
| 57 |
('http://namespaces.runeblade.com/dot',): EF.NodeImport('RBSkinning.dotSkin'), |
|---|
| 58 |
('http://namespaces.runeblade.com/objectify',): EF.CachedTryList([ |
|---|
| 59 |
EF.NodeImport('RBSkinning.xmlObjectifySkin'), |
|---|
| 60 |
EF.StaticImport('RBSkinning.xmlObjectifySkin.ObjectifiedXMLSkin', 'ObjectifiedXMLSkin')]), |
|---|
| 61 |
|
|---|
| 62 |
## Not-Just-RuneBlade schemes |
|---|
| 63 |
('http://www.w3.org/1999/xhtml',): EF.CachedTryList([ |
|---|
| 64 |
EF.NodeImport('RBSkinning.xhtml'), |
|---|
| 65 |
EF.StaticImport('RBSkinning.xhtml.xhtml', 'xhtml'),]), |
|---|
| 66 |
|
|---|
| 67 |
('http://www.w3.org/2000/svg',): EF.CachedTryList([ |
|---|
| 68 |
EF.NodeImport('RBSkinning.svg'), |
|---|
| 69 |
EF.StaticImport('RBSkinning.svg.svg', 'svg'),]), |
|---|
| 70 |
|
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 74 |
|
|---|
| 75 |
StandardNamespaceSynonyms = { |
|---|
| 76 |
'skin': 'http://namespaces.runeblade.com/skin', |
|---|
| 77 |
'wxPythonSkin': 'http://namespaces.runeblade.com/wxPythonSkin', |
|---|
| 78 |
'xmlPython': 'http://namespaces.runeblade.com/xmlPython', |
|---|
| 79 |
'wxogl': 'http://namespaces.runeblade.com/wxogl', |
|---|
| 80 |
'state': 'http://namespaces.runeblade.com/state', |
|---|
| 81 |
'dot': 'http://namespaces.runeblade.com/dot', |
|---|
| 82 |
'objectify': 'http://namespaces.runeblade.com/objectify', |
|---|
| 83 |
|
|---|
| 84 |
'xhtml': 'http://www.w3.org/1999/xhtml', |
|---|
| 85 |
'svg': 'http://www.w3.org/2000/svg', |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 89 |
#~ Definitions |
|---|
| 90 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 91 |
|
|---|
| 92 |
class StandardXMLSkinner(_XMLSkinner): |
|---|
| 93 |
ElementFactories = _XMLSkinner.ElementFactories.copy() |
|---|
| 94 |
ElementFactories.update(StandardElementFactories) |
|---|
| 95 |
|
|---|
| 96 |
NamespaceSynonyms = _XMLSkinner.NamespaceSynonyms.copy() |
|---|
| 97 |
NamespaceSynonyms.update(StandardNamespaceSynonyms) |
|---|
| 98 |
|
|---|
| 99 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 100 |
|
|---|
| 101 |
def SkinFile(*args, **kw): |
|---|
| 102 |
return StandardXMLSkinner().SkinFile(*args, **kw) |
|---|
| 103 |
|
|---|
| 104 |
def SkinXML(*args, **kw): |
|---|
| 105 |
return StandardXMLSkinner().SkinXML(*args, **kw) |
|---|
| 106 |
|
|---|
| 107 |
try: |
|---|
| 108 |
from xml.parsers.expat import ExpatError |
|---|
| 109 |
|
|---|
| 110 |
def DebugExpatError(err, printlines=3): |
|---|
| 111 |
xmlsource = err.xmlsource |
|---|
| 112 |
cur_line = 0 |
|---|
| 113 |
line = err.lineno |
|---|
| 114 |
column = err.offset |
|---|
| 115 |
|
|---|
| 116 |
if isinstance(xmlsource, (str, unicode)): |
|---|
| 117 |
import StringIO |
|---|
| 118 |
xmlsource = StringIO.StringIO(xmlsource) |
|---|
| 119 |
xmlsource.seek(0) |
|---|
| 120 |
|
|---|
| 121 |
print |
|---|
| 122 |
print |
|---|
| 123 |
print "XML Expat Error at line %s, column %s" % (line, column) |
|---|
| 124 |
print |
|---|
| 125 |
for xmlline in xmlsource: |
|---|
| 126 |
cur_line += 1 |
|---|
| 127 |
if (line - cur_line) < printlines: |
|---|
| 128 |
print '%4d:%s' % (cur_line, xmlline), |
|---|
| 129 |
if cur_line == line: |
|---|
| 130 |
print "%s%s" % ('='*(5+column), '^') |
|---|
| 131 |
break |
|---|
| 132 |
print |
|---|
| 133 |
print |
|---|
| 134 |
return 1 |
|---|
| 135 |
|
|---|
| 136 |
except ImportError: |
|---|
| 137 |
pass |
|---|