]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/modules/html/test/htmlview.py
wxPython stuff:
[wxWidgets.git] / utils / wxPython / modules / html / test / htmlview.py
1 from wxPython.wx import *
2 from wxPython.html import *
3 import sys
4
5 default_page = """
6 <H1>HTML Viewer</H1>Please select <I>File->Open</I>
7 to open a HTML file, or edit this page in the
8 text control below and select <I>File->Update</I>
9 <P>
10 The python source can be seen
11 <a href="%s">here</a>.
12 """ % (sys.argv[0], )
13
14 class 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
65 class 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
72 wxImage_AddHandler(wxPNGHandler())
73 wxImage_AddHandler(wxGIFHandler())
74 wxImage_AddHandler(wxJPEGHandler())
75
76 theApp = MyApp(0)
77 theApp.MainLoop()