|
下面的代码:
[PHP]
#!/usr/bin/env python
# -*- coding:gb2312 -*-
from wxPython.wx import *
from wxPython.html import *
from wxPython.lib.floatbar import *
import time, os
class BrowserFrame(wxFrame):
ID_ADD = 5000
ID_REMOVE = 5001
ID_QUIT = 5002
wxImage_AddHandler(wxGIFHandler())
def __init__(self):
wxFrame.__init__(self, None, -1, '查看程序')
tb = wxFloatBar(self, -1)
addWin = wxButton(tb, self.ID_ADD, u'增加新窗口')
removewin = wxButton(tb, self.ID_REMOVE, u'移除旧窗口')
quit = wxButton(tb, self.ID_QUIT, u'退出程序')
#捕获按钮单击事件
EVT_BUTTON(tb, self.ID_ADD, self.OnAdd)
EVT_BUTTON(tb, self.ID_REMOVE, self.OnRemove)
EVT_BUTTON(tb, self.ID_QUIT, self.OnQuit)
#增加按钮到工具栏上
tb.AddControl(addWin)
tb.AddControl(removewin)
tb.AddSeparator()
tb.AddControl(quit)
tb.Realize()
self.SetToolBar(tb)
tb.SetFloatable(1)
self.SetToolBar(tb)
tb.SetFloatable(1)
#创建wxNoteBook类的部件
self.note = wxNotebook(self, -1)
def GetFileName(self):
types = 'HTML FILES|*.html;*.htm'
dlg = wxFileDialog(self, style = wxOPEN|wxFILE_MUST_EXIST, wildcard = types)
dlg.ShowModal()
file = dlg.GetFilename()
dlg.Destroy()
return file
def OnAdd(self, event):
file = self.GetFileName()
if file:
newWin = wxHtmlWindow(self.note ,-1)
self.note.AddPage(newWin, os.path.split(file)[1], 1)
newWin.LoadPage(file)
def OnRemove(self, event):
page = self.note.GetSelection()
if page != -1:
self.note.DeletePage(page)
self.note.AdvanceSelection()
def OnQuit(self, event):
self.Destroy()
class App(wxApp):
def OnInit(self):
frame = BrowserFrame()
frame.Show(true)
return true
if __name__ == "__main__":
app = App(0)
app.MainLoop()
[/PHP] |
|