root/trunk/RBRapier/RBRapier/Formats/SVG/SVGSkin/SVGSkinObject.py

Revision 734, 3.4 kB (checked in by sholloway, 5 years ago)

Added support for a precompile step

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 import XMLBuilder
27 from RBSkinning import SkinContext
28
29 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30 #~ Definitions
31 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32
33 class SVGSkinObject(XMLBuilder.XMLBuilderObjectBase):
34     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35     #~ Definitions
36     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37
38     def __init__(self, builder, parent, node, settings, namespacemap):
39         self.node = node
40         self.settings = settings
41         if parent:
42             self.context = parent.context
43         else:
44             self.context = builder.context
45
46     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47
48     def GetRenderItem(self):
49         return self.context.SVGRenderItemFactory(self.node[1])
50
51     def InterpretSettings(self, settings):
52         raise NotImplementedError
53
54     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55
56     def PushContext(self):
57         self.context = SkinContext.SkinContext(self.context)
58         return self.context
59
60     def _xmlInitStarted(self):
61         self.children = []
62         self.object = self.GetRenderItem()
63
64         try:
65             if self._GetSaveId():
66                 idname = self.settings['id']
67                 idmapping = self.context.idmapping
68                 idmapping[idname] = self.object
69         except (KeyError, AttributeError):
70             pass
71
72         if self.object is not None:
73             self.InterpretSettings(self.settings)
74
75     def _addElement(self, node, element):
76         self.children.append(element)
77
78     def _addData(self, data):
79         pass
80
81     def _xmlInitFinalized(self):
82         if self.object is not None:
83             if self.children:
84                 children = filter(None, [getattr(child, 'object', None) for child in self.children])
85                 self.object.SetChildren(children)
86
87     def _xmlInitComplete(self):
88         del self.children
89         del self.node
90         del self.context
91
92     def _GetSaveId(self):
93         return self.context.saveids
94
95 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96
97 class SVGSkinContentObject(SVGSkinObject):
98     def _xmlInitStarted(self):
99         SVGSkinObject._xmlInitStarted(self)
100         self.content = ''
101
102     def _addData(self, data):
103         self.content += data
104
105     def _xmlInitFinalized(self):
106         SVGSkinObject._xmlInitFinalized(self)
107         if self.object is not None:
108             self.object.SetContent(self.content)
109
110     def _xmlInitComplete(self):
111         SVGSkinObject._xmlInitComplete(self)
112         del self.content
113
Note: See TracBrowser for help on using the browser.