]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/modules/html/test/htmlwidget.py
bug fix for OnLinkClicked callback
[wxWidgets.git] / utils / wxPython / modules / html / test / htmlwidget.py
1 from wxPython.wx import *
2 from wxPython.html import *
3 import sys,string
4
5 # A bunch of simple widgets, all somehow derived from wxWindow
6 class Widget1(wxWindow):
7 def __init__(self, parent, param):
8 wxWindow.__init__(self, parent, -1)
9 self.text = wxTextCtrl(self, -1, param['param_str'], wxPoint(5,5),
10 wxSize(200,150), wxTE_MULTILINE)
11 but = wxButton(self, 1001, "Click me", wxPoint(50,160), wxSize(100,30))
12 EVT_BUTTON(self, 1001, self.OnButton)
13 self.SetSize(wxSize(210,200))
14 def OnButton(self, event):
15 self.text.AppendText( "Click!\n" )
16
17 class Widget2(wxButton):
18 def __init__(self, parent, param):
19 wxButton.__init__(self, parent, int(param['id']), param['title'])
20
21 class Widget3(wxTextCtrl):
22 def __init__(self, parent, param):
23 wxTextCtrl.__init__(self, parent, -1, "No clicks")
24 self.clicked = 0;
25 EVT_BUTTON(parent, int(param['button_id']), self.OnButton)
26 def OnButton(self, event):
27 self.clicked = self.clicked + 1
28 self.SetValue("%d clicks" % (self.clicked,))
29
30 # make the widgets known in the widget module (aka htmlc)
31 widget.Widget1 = Widget1
32 widget.Widget2 = Widget2
33 widget.Widget3 = Widget3
34
35 # our default page
36 default_page = """
37 <H2>wxPython widgets go HTML</H2>
38 A bunch of wxPython widgets are scattered on this HTML page.
39 Here's one:
40 <center><python class="Widget1" greeting="Hello World"></center>
41 <hr>
42 Here's another:
43 <center><python class="Widget2" float=70 id=1002 title="Button A"></center>
44 It should always take up 70% of the page width.
45 <p>And then there's this, listening to button A:
46 <python class="Widget3" button_id=1002></p>
47 """
48
49 # our explanation
50 apology = """
51 For some bizarre reason, it takes forever and a day to display the
52 widgets if they are constructed in the frame's constructor. This
53 only happens in MSW, wxGTK works fine.
54 <p>Select <I>File->Show it</I> to draw the widgets."""
55
56 default_page = default_page + "The HTML code for this page is\n <pre>" + default_page + "</pre>"
57
58
59 class HtmlViewer(wxFrame):
60 def __init__(self, parent, id, title, pos = wxDefaultPosition, size = wxSize(400,400)):
61 wxFrame.__init__(self, parent, id, title, pos, size)
62 self.CreateStatusBar(1)
63 self.html = wxHtmlWindow(self)
64 self.html.SetRelatedFrame(self, "HTML Viewer: \%s")
65 self.html.SetRelatedStatusBar(0)
66 mbar = wxMenuBar()
67 menu = wxMenu()
68 menu.Append(1500, "Show it")
69 menu.Append(1503, "Exit")
70 mbar.Append(menu, "File")
71 EVT_MENU(self, 1500, self.OnShowIt)
72 EVT_MENU(self, 1503, self.OnClose)
73 self.SetMenuBar(mbar)
74 # change apology below to default_page, if you dare!
75 self.html.SetPage( default_page )
76 def OnClose(self,event):
77 self.Destroy()
78 def OnShowIt(self,event):
79 self.html.SetPage( default_page )
80 # now quickly remove the menu option, to hide that
81 # other bug; namely that widgets aren't removed when the
82 # HTML page is.
83 self.GetMenuBar().Enable(1500, FALSE)
84
85 class MyApp(wxApp):
86 def OnInit(self):
87 frame = HtmlViewer(NULL, -1, "HTML Viewer")
88 frame.Show(TRUE)
89 self.SetTopWindow(frame)
90 return TRUE
91
92 wxImage_AddHandler(wxPNGHandler())
93 wxImage_AddHandler(wxGIFHandler())
94 wxImage_AddHandler(wxJPEGHandler())
95
96 theApp = MyApp(0)
97 theApp.MainLoop()