]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/modules/html/test/htmlwidget.py
1 from wxPython
.wx
import *
2 from wxPython
.html
import *
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" )
17 class Widget2(wxButton
):
18 def __init__(self
, parent
, param
):
19 wxButton
.__init
__(self
, parent
, int(param
['id']), param
['title'])
21 class Widget3(wxTextCtrl
):
22 def __init__(self
, parent
, param
):
23 wxTextCtrl
.__init
__(self
, parent
, -1, "No clicks")
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
,))
30 # make the widgets known in the widget module (aka htmlc)
31 widget
.Widget1
= Widget1
32 widget
.Widget2
= Widget2
33 widget
.Widget3
= Widget3
37 <H2>wxPython widgets go HTML</H2>
38 A bunch of wxPython widgets are scattered on this HTML page.
40 <center><python class="Widget1" greeting="Hello World"></center>
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>
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."""
56 default_page
= default_page
+ "The HTML code for this page is\n <pre>" + default_page
+ "</pre>"
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)
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
)
74 # change apology below to default_page, if you dare!
75 self
.html
.SetPage( default_page
)
76 def OnClose(self
,event
):
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
83 self
.GetMenuBar().Enable(1500, FALSE
)
87 frame
= HtmlViewer(NULL
, -1, "HTML Viewer")
89 self
.SetTopWindow(frame
)
92 wxImage_AddHandler(wxPNGHandler())
93 wxImage_AddHandler(wxGIFHandler())
94 wxImage_AddHandler(wxJPEGHandler())