root/trunk/RBSkinning/RBSkinning/skin/CompoundSkinObject.py

Revision 522, 4.0 kB (checked in by gwm, 6 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 weakref
27 from RBSkinning.SkinObject import SkinObject
28 from RBSkinning.UtilitySkinElements import StoreXML, RestoreStoredXMLMixin
29 from RBFoundation.XMLClassBuilder import ElementFactory, ElementFactorySet
30 from template import TemplateElementFactorySet
31
32 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33 #~ Definitions
34 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35
36 class CompoundSkinModel(object):
37     def OnSkinInitialize(self, Obj):
38         """Called before CompoundSkinObject has been initialized.
39         Obj is the owning CompoundSkinObject element"""
40         pass
41    
42     def OnSkinFinalize(self, Obj):
43         """Called after CompoundSkinObject has been finalized.
44         Obj is the owning CompoundSkinObject element"""
45         pass
46
47 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48    
49 class CompoundSkinObject(SkinObject, RestoreStoredXMLMixin):
50     """This object is meant to be derived from in order to generate compound skin elements.
51    
52     In the derived class, place the compound object's xml skin description in
53     xmlskin, then instantiate as usual."""
54
55     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
56     #~ Constants / Variables / Etc.
57     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58
59     default_settings = SkinObject.default_settings.copy()
60     default_settings[SkinObject.BaseSettingsSave] = "::settings"
61     modelctxvar = "compoundmodel"
62     invokename = "::contents"
63     xmlskin = """<template xmlns='http://namespaces.runeblade.com/skin' expand='::contents'/>"""
64
65     ElementFactories = TemplateElementFactorySet
66
67     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68     #~ Public Methods
69     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70
71     def __init__(self, owner, parent, node, attributes, namespacemap):
72         SkinObject.__init__(self, owner, parent, node, attributes, namespacemap)
73         self.owner = owner
74
75     def _InitContext(self, *args, **kw):
76         result = SkinObject._InitContext(self, *args, **kw)
77         self.PushContext() # This needs to happen before self._InitSettings
78         return result
79
80     def GetCompoundModel(self):
81         pass
82
83     def SkinInitialize(self):
84         self.object = self.GetCompoundModel()
85
86         # Call the model's OnSkinInitialize, if it has one
87         try: objOnSkinInitialize = self.object.OnSkinInitialize
88         except AttributeError: pass
89         else: objOnSkinInitialize(self)
90        
91         setattr(self.context, self.modelctxvar, self.object)
92         self.owner.PushElementFactorySet(self.ElementFactories)
93
94     def SkinFinalize(self):
95         self.owner.PopElementFactorySet()
96
97         setattr(self.context, '::invoke:' + self.invokename, weakref.proxy(self))
98         self.ReferenceSkin(self.settings)
99         delattr(self.context, '::invoke:' + self.invokename)
100        
101         # Call the model's OnSkinFinalize, if it has one
102         try: objOnSkinFinalize = self.object.OnSkinFinalize
103         except AttributeError: pass
104         else: objOnSkinFinalize(self)
105
106         del self.owner
107        
108     def ReferenceSkin(self, kwAddedContext={}):
109         if self.xmlskin:
110             self.context.__skinner__()._SkinXMLFromTopElement(self.xmlskin, kwAddedContext)
111            
Note: See TracBrowser for help on using the browser.