X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/05394a18d47c8d6d2e7e91dcfe96b2a83f566c8d..4b123bb9ccbacf21c742173e95f418cca9a5516c:/utils/wxPython/modules/html/test/htmlwidget.py diff --git a/utils/wxPython/modules/html/test/htmlwidget.py b/utils/wxPython/modules/html/test/htmlwidget.py new file mode 100644 index 0000000000..ffa0fcb356 --- /dev/null +++ b/utils/wxPython/modules/html/test/htmlwidget.py @@ -0,0 +1,97 @@ +from wxPython.wx import * +from wxPython.html import * +import sys,string + +# A bunch of simple widgets, all somehow derived from wxWindow +class Widget1(wxWindow): + def __init__(self, parent, param): + wxWindow.__init__(self, parent, -1) + self.text = wxTextCtrl(self, -1, param['param_str'], wxPoint(5,5), + wxSize(200,150), wxTE_MULTILINE) + but = wxButton(self, 1001, "Click me", wxPoint(50,160), wxSize(100,30)) + EVT_BUTTON(self, 1001, self.OnButton) + self.SetSize(wxSize(210,200)) + def OnButton(self, event): + self.text.AppendText( "Click!\n" ) + +class Widget2(wxButton): + def __init__(self, parent, param): + wxButton.__init__(self, parent, int(param['id']), param['title']) + +class Widget3(wxTextCtrl): + def __init__(self, parent, param): + wxTextCtrl.__init__(self, parent, -1, "No clicks") + self.clicked = 0; + EVT_BUTTON(parent, int(param['button_id']), self.OnButton) + def OnButton(self, event): + self.clicked = self.clicked + 1 + self.SetValue("%d clicks" % (self.clicked,)) + +# make the widgets known in the widget module (aka htmlc) +widget.Widget1 = Widget1 +widget.Widget2 = Widget2 +widget.Widget3 = Widget3 + +# our default page +default_page = """ +

wxPython widgets go HTML

+A bunch of wxPython widgets are scattered on this HTML page. +Here's one: +
+
+Here's another: +
+It should always take up 70% of the page width. +

And then there's this, listening to button A: +

+""" + +# our explanation +apology = """ +For some bizarre reason, it takes forever and a day to display the +widgets if they are constructed in the frame's constructor. This +only happens in MSW, wxGTK works fine. +

Select File->Show it to draw the widgets.""" + +default_page = default_page + "The HTML code for this page is\n

" + default_page + "
" + + +class HtmlViewer(wxFrame): + def __init__(self, parent, id, title, pos = wxDefaultPosition, size = wxSize(400,400)): + wxFrame.__init__(self, parent, id, title, pos, size) + self.CreateStatusBar(1) + self.html = wxHtmlWindow(self) + self.html.SetRelatedFrame(self, "HTML Viewer: \%s") + self.html.SetRelatedStatusBar(0) + mbar = wxMenuBar() + menu = wxMenu() + menu.Append(1500, "Show it") + menu.Append(1503, "Exit") + mbar.Append(menu, "File") + EVT_MENU(self, 1500, self.OnShowIt) + EVT_MENU(self, 1503, self.OnClose) + self.SetMenuBar(mbar) + # change apology below to default_page, if you dare! + self.html.SetPage( default_page ) + def OnClose(self,event): + self.Destroy() + def OnShowIt(self,event): + self.html.SetPage( default_page ) + # now quickly remove the menu option, to hide that + # other bug; namely that widgets aren't removed when the + # HTML page is. + self.GetMenuBar().Enable(1500, FALSE) + +class MyApp(wxApp): + def OnInit(self): + frame = HtmlViewer(NULL, -1, "HTML Viewer") + frame.Show(TRUE) + self.SetTopWindow(frame) + return TRUE + +wxImage_AddHandler(wxPNGHandler()) +wxImage_AddHandler(wxGIFHandler()) +wxImage_AddHandler(wxJPEGHandler()) + +theApp = MyApp(0) +theApp.MainLoop()