# Copyright: (c) 1999 by Total Control Software
# Licence: wxWindows license
#----------------------------------------------------------------------
+# 12/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for V2.5 compatability
+#
'''
wxPython.lib.wxpTag
importing it will create the tag handler and add it to any
wxHtmlWinParsers created from that time forth.
-Tags of the following form are recognised:
+Tags of the following form are recognised::
<WXP class="classname" [module="modulename"] [width="num"] [height="num"]>
<PARAM name="parameterName" value="parameterValue>
where modulename is the name of a module (possibly in package
notation) to import and classname is the name of a class in that
module to create an instance of. If the module tag-attribute is not
-given or is an empty string, then wxPython.wx is used. The width and
-height attributes are expected to be integers and will be passed to
-the __init__ method of the class as a wxSize object named size.
-However, if the width attribute ends with the percent (%) symbol then
-the value will be used as a percentage of the available width and the
+given or is an empty string, then wx is used. The width and height
+attributes are expected to be integers and will be passed to the
+__init__ method of the class as a wxSize object named size. However,
+if the width attribute ends with the percent (%) symbol then the value
+will be used as a percentage of the available width and the
wxHtmlWindow will manage the size.
The name-value pairs in all the nested PARAM tags are packaged up as
strings into a python dictionary and passed to the __init__ method of
the class as keyword arguments. This means that they are all
accessible from the __init__ method as regular parameters, or you use
-the special Python **kw syntax in your __init__ method to get the
+the special Python \*\*kw syntax in your __init__ method to get the
dictionary directly.
Some parameter values are special and if they are present then they will
object and if it fails then the original string value
will be used instead.
-An example:
+An example::
- <wxp module="" class="wxButton">
+ <wxp module="wx" class="Button">
<param name="label" value="Click here">
- <param name="id" value="wxID_OK">
+ <param name="id" value="ID_OK">
</wxp>
Both the begining and ending WXP tags are required.
'''
#----------------------------------------------------------------------
-from wxPython.wx import *
-from wxPython.html import *
-import wxPython.wx
+import types
+
+import wx
+import wx.html
-import types
#----------------------------------------------------------------------
#----------------------------------------------------------------------
-class wxpTagHandler(wxHtmlWinTagHandler):
+class wxpTagHandler(wx.html.HtmlWinTagHandler):
def __init__(self):
- wxHtmlWinTagHandler.__init__(self)
+ wx.html.HtmlWinTagHandler.__init__(self)
self.ctx = None
def GetSupportedTags(self):
if modName:
self.ctx.classMod = _my_import(modName)
else:
- self.ctx.classMod = wxPython.wx
+ self.ctx.classMod = wx
# find and verify the class
if not tag.HasParam('CLASS'):
width = int(width)
if tag.HasParam('HEIGHT'):
height = int(tag.GetParam('HEIGHT'))
- self.ctx.kwargs['size'] = wxSize(width, height)
+ self.ctx.kwargs['size'] = wx.Size(width, height)
# parse up to the closing tag, and gather any nested Param tags.
self.ParseInner(tag)
# create the object
- parent = self.GetParser().GetWindow()
+ parent = self.GetParser().GetWindowInterface().GetHTMLWindow()
if parent:
obj = apply(self.ctx.classObj,
(parent,),
obj.Show(True)
# add it to the HtmlWindow
- self.GetParser().GetContainer().InsertCell(wxHtmlWidgetCell(obj, self.ctx.floatWidth))
+ self.GetParser().GetContainer().InsertCell(
+ wx.html.HtmlWidgetCell(obj, self.ctx.floatWidth))
self.ctx = None
return True
# check for something that should be evaluated
- elif value[0] in '[{(' or value[:2] == 'wx':
+ elif value and value[0] in '[{(' or value[:2] == 'wx':
saveVal = value
try:
value = eval(value, self.ctx.classMod.__dict__)
except:
value = saveVal
- # convert to wxColour
- elif value[0] == '#':
+ # convert to wx.Colour
+ elif value and value[0] == '#':
try:
red = int('0x'+value[1:3], 16)
green = int('0x'+value[3:5], 16)
blue = int('0x'+value[5:], 16)
- value = wxColor(red, green, blue)
+ value = wx.Color(red, green, blue)
except:
pass
- self.ctx.kwargs[str(name)] = value
+ if self.ctx:
+ self.ctx.kwargs[str(name)] = value
return False
-wxHtmlWinParser_AddTagHandler(wxpTagHandler)
+wx.html.HtmlWinParser_AddTagHandler(wxpTagHandler)