]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/demo/htmlview.py
The beginings of wxHtmlWindow support in the wxPython demo
[wxWidgets.git] / utils / wxPython / demo / htmlview.py
CommitLineData
efc5f224
RD
1from wxPython.wx import *
2from wxPython.html import *
3import sys
4
5default_page = """
6<H1>HTML Viewer</H1>Please select <I>File->Open</I>
7to open a HTML file, or edit this page in the
8text control below and select <I>File->Update</I>
9<P>
10The python source can be seen
11<a href="%s">here</a>.
12""" % (sys.argv[0], )
13
14class HtmlViewer(wxFrame):
15 def __init__(self, parent, id, title, pos = wxDefaultPosition, size = wxSize(400,400)):
16 wxFrame.__init__(self, parent, id, title, pos, size)
17 self.CreateStatusBar(1)
18 split = wxSplitterWindow(self, -1)
19 self.html = wxHtmlWindow(split)
20 self.html.SetRelatedFrame(self, "HTML Viewer: \%s")
21 self.html.SetRelatedStatusBar(0)
22 self.txt = wxTextCtrl(split, -1, default_page,
23 wxDefaultPosition, wxDefaultSize,
24 wxTE_MULTILINE)
25 split.SplitHorizontally(self.html, self.txt, size.y/2)
26 mbar = wxMenuBar()
27 menu = wxMenu()
28 menu.Append(1500, "Open")
29 menu.Append(1501, "Reset")
30 menu.Append(1502, "Update HTML")
31 menu.AppendSeparator()
32 menu.Append(1503, "Exit")
33 mbar.Append(menu, "File")
34 menu = wxMenu()
35 menu.Append(1510, "Back")
36 menu.Append(1511, "Forward")
37 mbar.Append(menu, "Go")
38 self.SetMenuBar(mbar)
39 self.filename = ""
40 EVT_MENU(self, 1500, self.OnFileOpen)
41 EVT_MENU(self, 1501, self.OnFileReset)
42 EVT_MENU(self, 1502, self.OnFileUpdate)
43 EVT_MENU(self, 1503, self.OnClose)
44 EVT_MENU(self, 1510, self.OnGoBack)
45 EVT_MENU(self, 1511, self.OnGoForward)
46 # A default opening text
47 self.html.SetPage( default_page )
48 def OnFileOpen(self, event):
49 dlg = wxFileDialog(NULL, "Open file")
50 if dlg.ShowModal() == wxID_OK:
51 self.filename = dlg.GetPath()
52 self.html.LoadPage(self.filename)
53 def OnFileReset(self, event):
54 self.html.SetPage( default_page )
55 self.txt.SetValue( default_page )
56 def OnFileUpdate(self, event):
57 self.html.SetPage( self.txt.GetValue() )
58 def OnGoBack(self, event):
59 self.html.HistoryBack()
60 def OnGoForward(self, event):
61 self.html.HistoryForward()
62 def OnClose(self,event):
63 self.Destroy()
64
65class MyApp(wxApp):
66 def OnInit(self):
67 frame = HtmlViewer(NULL, -1, "HTML Viewer")
68 frame.Show(TRUE)
69 self.SetTopWindow(frame)
70 return TRUE
71
72wxImage_AddHandler(wxPNGHandler())
73wxImage_AddHandler(wxGIFHandler())
74wxImage_AddHandler(wxJPEGHandler())
75
76theApp = MyApp(0)
77theApp.MainLoop()