root/trunk/RBSkinning/RBSkinning/wxPythonSkin/htmlwindowex.py

Revision 573, 5.1 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 import weakref
27 from htmlwindow import html, wx, htmlwindow
28
29 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30 #~ wxPythonSkin tag
31 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32
33 class wxPythonSkinTagHandler(html.wxHtmlWinTagHandler):
34     """Derived from wxPython.lib.wxpTag written by Robin Dunn and adapted to
35     the RBSkinning framework."""
36
37     wxPythonSkinTag = 'wxPythonSkin'.upper()
38
39     def GetSupportedTags(self):
40         return self.wxPythonSkinTag + ','
41
42     def HandleTag(self, tag):
43         tagname = tag.GetName()
44         if tagname != self.wxPythonSkinTag:
45             raise ValueError, 'Tag %s not supported by %s' % (tagname, self.__class__.__name__)
46         else:
47             container = self.GetParser().GetContainer()
48             if not container: return False
49             window = self.GetParser().GetWindow()
50             if not window: return False
51             skinelement = window.skinelement()
52             if not skinelement: return False
53
54             # Load the skin representing this tag
55             SkinnedObj = skinelement.LoadSkinForTag(self, tag)
56             if not SkinnedObj:
57                 return False
58
59             if tag.HasParam('width'):
60                 width = int(tag.GetParam('width'))
61             else: width = 0
62
63             # Load the SkinObject into a html widget cell
64             cell = html.wxHtmlWidgetCell(SkinnedObj, width)
65             # and place it in the proper container
66             container.InsertCell(cell)
67             return True
68
69     def AddTagHandler(klass):
70         html.wxHtmlWinParser_AddTagHandler(klass)
71     AddTagHandler = classmethod(AddTagHandler)
72
73 wxPythonSkinTagHandler.AddTagHandler()
74
75 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76 #~ Class
77 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78
79 class htmlwindowex(htmlwindow):
80     """htmlwindow extended with wxPythonSkinTagHandler"""
81
82     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83     #~ Constants / Variables / Etc.
84     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85
86     default_settings = htmlwindow.default_settings.copy()
87     TagSkinner = None # to support wxPythonSkin tags
88     IsSkinningComplete = 0 # to support wxPythonSkin tags
89
90     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91     #~ Public
92     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93
94     def SkinInitialize(self):
95         self.IsSkinningComplete = 0
96         self.PushContext()
97         winParent = self.wxGetParentObject(wx.wxWindowPtr)
98         Settings = map(self.wxEval, ['wxid', 'pos', 'size', 'style'])
99         Settings.append(self.settings['name'])
100         self.object = html.wxHtmlWindow(winParent, *Settings)
101         self.object.skinelement = weakref.ref(self)
102         if self.settings.get('tagskinner'):
103             self.TagSkinner = self.wxEval('tagskinner')
104         self.wxInitialStandardOptions()
105         self.wxHtmlWindowOptions()
106
107     def SkinFinalize(self):
108         self.wxFinalStandardOptions()
109         self.IsSkinningComplete = 1
110
111     #~ to support wxPythonSkin tags ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
112
113     def LoadSkinForTag(self, taghandler, tag):
114         skinner = self.TagSkinner or self.context.__skinner__()
115         if not skinner: return None
116         # Determine if the tag is a reference or a skin invokation
117         if tag.HasParam('ref'):
118             SkinFilename = tag.GetParam('ref')
119             return self.ReferenceSkinFile(skinner, SkinFilename)
120         elif tag.HasParam('invoke'):
121             invokename = tag.GetParam('invoke')
122             return self.InvokeSkin(skinner, invokename)
123         else:
124             return None
125
126     def ReferenceSkinFile(self, skinner, SkinFilename, kwAddedContext={}):
127         SkinFilename = os.path.join(self.context.__root__, SkinFilename)
128         if self.IsSkinningComplete:
129             result = skinner.GraftFile([self], SkinFilename, **kwAddedContext)
130         else:
131             result = skinner._SkinFileFromTopElement(SkinFilename, kwAddedContext)
132         return result.object
133        
134     def InvokeSkin(self, skinner, invokename, kwAddedContext={}):
135         template = self.context.getnamedvar(invokename)
136         setattr(self.context, '::invoke:' + invokename, weakref.proxy(self))
137         result = template.RestoreChildren(skinner)
138         delattr(self.context, '::invoke:' + invokename)
139         return result[-1].object
140        
Note: See TracBrowser for help on using the browser.