]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/modules/html/htmlhelper.py
it is now possible to add custom buttons into wxHtmlHelpFrame's toolbar
[wxWidgets.git] / utils / wxPython / modules / html / htmlhelper.py
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
8 import wx
9 import string
10 import htmlc
11
12 # Function to parse a param string (of the form 'item=value item2="value etc"'
13 # and creates a dictionary
14 def _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.
47 def _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
59 htmlc.WidgetStarter = _WidgetStarter