root/trunk/RBSkinning/RBSkinning/UtilitySkinElements.py

Revision 573, 4.3 kB (checked in by sholloway, 6 years ago)

mega bugfixes

Line 
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 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 #~ Imports
24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25
26 from RBFoundation.XMLBuilder import XMLBuilderObjectBase
27
28 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29 #~ Definitions
30 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31
32 def _RestoreChildren(self, owner=None, children=None):
33     if children is None:
34         children = self.children
35     if owner is None:
36         owner = self.owner
37     result = []
38     # Emulate the Sub Elements
39     for isnode, item in children:
40         if isnode:
41             try: Restore = item.Restore
42             except AttributeError: pass
43             else: result.append(Restore(owner))
44         else:
45             owner._char_data(item)
46     return result
47
48 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49
50 class IgnoreXML(XMLBuilderObjectBase):
51     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52     #~ Special
53     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
54
55     def _xmlChildFactory(self, owner, parent, node, attributes, namespacemap):
56         return self.__class__
57
58 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59
60 class StoreXML(XMLBuilderObjectBase):
61     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62     #~ Special
63     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
64
65     def __init__(self, owner, parent, node, attributes, namespacemap):
66         self.owner, self.parent, self.node, self.attributes, self.namespacemap = owner, parent, node, attributes, namespacemap
67         self.children = []
68
69     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70     #~ Public Methods
71     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72
73     def Restore(self, owner=None, children=None):
74         if owner is None:
75             owner = self.owner
76         if children is None:
77             children = self.children
78
79         # Emulate the namespace start calls
80         for uri, prefix in self.namespacemap.iterxmlns(False):
81             owner._start_namespace_decl_handler(prefix, uri)
82
83         # Construct the joined node name
84         sep = owner._seperator
85         name = sep.join(self.node)
86
87         newattributes = {}
88         for attrname, attrvalue in self.attributes.iteritems():
89             if isinstance(attrname, tuple):
90                 if attrname[1] not in self.attributes:
91                     attrname = sep.join(attrname)
92                     newattributes[attrname] = attrvalue
93             else:
94                 newattributes[attrname] = attrvalue
95
96         # Emulate the Start of an element
97         restoredself = owner._start_element(name, newattributes)
98
99         self.RestoreChildren(owner)
100
101         # Emulate the End of an element
102         owner._end_element(name)
103
104         # Emulate the namespace end calls
105         for uri, prefix in self.namespacemap.iterxmlns(False):
106             owner._end_namespace_decl_handler(prefix)
107
108         return restoredself
109
110     RestoreChildren = _RestoreChildren
111
112     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
113     #~ Protected Methods
114     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
115
116     def _addElement(self, node, obj):
117         self.children.append((1, obj))
118
119     def _addData(self, data):
120         self.children.append((0, data))
121
122     def _xmlInitStarted(self):
123         pass
124
125     def _xmlInitComplete(self):
126         pass
127
128     def _xmlChildFactory(self, owner, parent, node, attributes, namespacemap):
129         return self.__class__
130
131 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132
133 class RestoreStoredXMLMixin(object):
134     RestoreChildren = _RestoreChildren
Note: See TracBrowser for help on using the browser.