我有一个应用程序,我正在努力学习更多关于wxPython(我一直主要是一个scripter)。我现在忘了它,现在我打开了它。这是一个屏幕刮板,我按照我想要的方式工作,打算构建一个正则表达式解析器,以去掉每次不需要的刮擦中的链接。我有的问题是这样的。在它当前的状态下,如果我检查多个站点,它会出去并进行擦除,并将其返回到单独的窗口中,用于:Clicked函数中的每个部分。我想把它们放在一个框架里,完全放在窗口中。我也想知道,如果我可以将他们读入的列表发送给清单,那么有人可以检查单独的项目,我想构建一个保存功能并保留某些项目。关于保存功能,我想保留保存的检查,是否有调用窗口小部件来保存它们的状态?我知道这很多,但感谢您的帮助。wxPython格式问题
编辑(忘记密码)
import wx
import urllib2
from BeautifulSoup import BeautifulSoup
from BeautifulSoup import Tag
import re
from pyparsing import makeHTMLTags, originalTextFor, SkipTo, Combine
import wx
import wx.html
global P
siteDict = {0:'http://www.reddit.com', 1:'http://www.boston.com', 2:'http://www.stumbleupon.com', 3:'news.google.com'}
class citPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
allSites = ['Reddit', 'Boston.com', 'StumbleUpon', 'Google News']
wx.StaticText(self, -1, "Choose the Sites you would like Charlie to Visit:", (45, 15))
self.sitList = wx.CheckListBox(self, 20, (60, 50), wx.DefaultSize, allSites)
class nextButton(wx.Button):
def __init__(self, parent, id, label, pos):
wx.Button.__init__(self, parent, id, label, pos)
class checkList(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(400, 300))
self.panel = citPanel(self, -1)
nextButton(self.panel, 30, 'Ok', (275, 50))
self.Bind(wx.EVT_BUTTON, self.Clicked)
self.Centre()
self.Show(True)
def Clicked(self, event):
checkedItems = [i for i in range(self.panel.sitList.GetCount()) if self.panel.sitList.IsChecked(i)]
print checkedItems
r = [siteDict[k] for k in checkedItems]
print r
for each in r:
pre = '<HTML><head><title>Page title</title></head>'
post = '</HTML>'
site = urllib2.urlopen(each)
html=site.read()
soup = BeautifulSoup(html)
tags = soup.findAll('a')
soup1 = BeautifulSoup(''.join(str(t) for t in tags))
for link in soup1.findAll('a'):
br= Tag(soup, 'p')
index= link.parent.contents.index(link)
link.parent.insert(index+1, br)
P = soup1.prettify()
print P
#for link2 in soup1.findAll('a'):
#p1= Tag(soup, '
frm = MyHtmlFrame(None, "Charlie", P)
frm.Show()
class MyHtmlFrame(wx.Frame):
def __init__(self, parent, title, page):
wx.Frame.__init__(self, parent, -1, title)
html = wx.html.HtmlWindow(self)
if "gtk2" in wx.PlatformInfo:
html.SetStandardFonts()
html.SetPage(page)
#app = wx.PySimpleApp()
#app.MainLoop()
#event.Skip()
#self.Destroy()
app = wx.App()
checkList(None, -1, 'Charlie')
app.MainLoop()
我真的很抱歉,在您回答之后这么长时间,但是,我在月底有很多。我正在玩这个,我有几个问题。字典,你是说要把它返回的每一个链接,并把它放在一个字典中,关键是它来自哪个网站?这是让他们在同一个窗口中展示的唯一方法吗?另外,我有兴趣将html框架作为复选框的一部分,所以它会初始化为空,并在之后填充? – Kevin 2010-06-16 02:57:43
我在说,你不需要每个结果都有一个新的框架。您可以根据要查看的页面设置一帧的内容。当然,您可以使用wx.Notebook(或choicebook,listbook或wxTreebook)在ala Firefox选项卡的多个面板中进行选择。另外,看看wx sizer将多个小部件放在同一个框架中。但在尝试其他方法之前,先弄清楚一件事(布局或制表符)。 – wisty 2010-06-17 05:02:06