]> git.saurik.com Git - wxWidgets.git/blame_incremental - utils/wxPython/modules/html/htmlhelper.py
New wxHtml stuff, including a TagHandler for placing wxPython widgets
[wxWidgets.git] / utils / wxPython / modules / html / htmlhelper.py
... / ...
CommitLineData
1#
2# htmlhelper.py
3#
4# A few helper functions for putting wxPython widgets in html pages
5#
6# Harm van der Heijden, 11 aug 1999.
7
8import wx
9import string
10import htmlc
11
12# Function to parse a param string (of the form 'item=value item2="value etc"'
13# and creates a dictionary
14def _param2dict(param):
15 i = 0; j = 0; s = len(param); d = {}
16 d['param_str'] = param
17 while 1:
18 while i<s and param[i] == " " : i = i+1
19 if i>=s: break
20 j = i
21 while j<s and param[j] != "=": j=j+1
22 if j+1>=s:
23 break
24 word = param[i:j]
25 i=j+1
26 if (param[i] == '"'):
27 j=i+1
28 while j<s and param[j] != '"' : j=j+1
29 if j == s: break
30 val = param[i+1:j]
31 elif (param[i] != " "):
32 j=i+1
33 while j<s and param[j] != " " : j=j+1
34 val = param[i:j]
35 else:
36 val = ""
37 i=j+1
38 d[string.lower(word)] = val
39 return d
40
41# This function gets called by the <python> tag handler.
42# Arguments are the parent (wxHtmlWindow) SWIG pointer (in python, a string)
43# and a string containing the parameters.
44# The return value must be the SWIG pointer of the created widget (the 'this'
45# attribute in python). The widget must be derived from a wxWindow or one
46# of its descendants.
47def _WidgetStarter(parentptr, param):
48 # create a python instance of the parent
49 parent = wx.wxWindowPtr(parentptr)
50 # try to find the widget class in the htmlwinc (=htmlwidget) module
51 dict = _param2dict(param)
52 classname = dict['class']
53 obj = htmlc.__dict__[classname]
54 # now create the class with arguments parent, dictionary
55 cls = apply(obj, (parent, dict))
56 # return the class instance's pointer
57 return cls.this
58
59htmlc.WidgetStarter = _WidgetStarter