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

Revision 656, 3.9 kB (checked in by sholloway, 5 years ago)

*** empty log message ***

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 import logging
27 from RBFoundation import XMLBuilder
28 #from RBSkinning.SkinObject import SkinObject
29 from RBSkinning import SkinContext
30
31 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32 #~ Definitions
33 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34
35 class SVGSkinObject(XMLBuilder.XMLBuilderObjectBase):
36     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37     #~ Constants / Variables / Etc.
38     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39
40     log = logging.getLogger('SVG.SVGSkin')
41     RenderItemFactory = lambda self: None # result should derive from Common.RenderItemBase
42
43     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44     #~ Definitions
45     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46
47     def __init__(self, builder, parent, node, settings, namespacemap):
48         self.node = node
49         self.settings = settings
50         if parent:
51             self.context = parent.context
52         else:
53             self.context = None
54
55         SVGSkinObject.count += 1
56     count = 0
57     def __del__(self):
58         SVGSkinObject.count -= 1
59         if not SVGSkinObject.count:
60             print "Zero point for svg skin elements"
61
62     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
63
64     def DisplayOn(self, renderer):
65         if self.object is None:
66             self.log.warning("RenderItem is not set for element %r", self.node[1])
67         else:
68             renderer.Display(self.object)
69
70     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
71
72     def PushContext(self):
73         self.context = SkinContext.SkinContext(self.context)
74         return self.context
75
76     def _xmlInitStarted(self):
77         self.children = []
78         self.object = self.RenderItemFactory()
79
80         try:
81             if self.context.saveids:
82                 idname = self.settings['id']
83                 idmapping = self.context.idmapping
84                 idmapping[idname] = self.object
85         except (KeyError, AttributeError):
86             pass
87
88         if self.object is not None:
89             self.object.InterpretSettings(self.settings)
90
91     def _addElement(self, node, element):
92         self.children.append(element)
93
94     def _addData(self, data):
95         pass
96
97     def _xmlInitFinalized(self):
98         if self.object is not None:
99             children = filter(None, [getattr(child, 'object', None) for child in self.children])
100             self.object.AddChildRenderItems(children)
101
102     def _xmlInitComplete(self):
103         del self.children
104         del self.node
105         del self.context
106
107 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
108
109 class SVGSkinContentObject(SVGSkinObject):
110     def _xmlInitStarted(self):
111         SVGSkinObject._xmlInitStarted(self)
112         self.content = ''
113
114     def _addData(self, data):
115         self.content += data
116
117     def _xmlInitFinalized(self):
118         SVGSkinObject._xmlInitFinalized(self)
119         if self.object is not None:
120             self.object.AddContent(self.content)
121
122     def _xmlInitComplete(self):
123         SVGSkinObject._xmlInitComplete(self)
124         del self.content
125
Note: See TracBrowser for help on using the browser.