2010-05-25 7 views
0

wxPython에 대해 더 알고 싶습니다. (저는 주로 스크립터였습니다). 나는 지금 그것을 열어두고 있습니다. 그것은 스크린 스크레이퍼이고, 내가 원하는 방식으로 작업하고, 필요하지 않은 모든 긁힌 자국의 링크를 제거하는 정규 표현식 파서를 만들 것입니다. 내가 가진 질문은 이것이다. 현재 상태에서 두 개 이상의 사이트를 검사하면 나가서 긁어내어 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() 

답변

0

당신은 하나의 대답 패널 또는 프레임을 만들 수 있습니다 (당신이 지금하고있는 것처럼, 별도의 프레임으로 시작 - MyHtmlFrame은 괜찮습니다). 모든 결과에 대해 새 패널이나 프레임을 만들지 마십시오.

어딘가에 wx.ComboBox (self, -1, choices = [ 'google', 'so'])를 만들고 self.Bind (wx.EVT_COMBOBOX, myHtmlFrame.setFrame)를 바인딩하십시오.

이제 MyHtmlFrame.setFrame (self, event);를 작성해야합니다. 다음 choice = event.GetSelection(), self.html.SetPage(self.results_dict[choice])

오 사용하고, 스크레이퍼 결과와 선택 ("google")를 매핑 MyHtmlFrame에 사전 (results_dict)를 연결합니다.

콤보 상자를 별도의 프레임에 넣지 않으려면 wx.Sizer 사용 방법을 배워야합니다.

class MyHtmlFrame(wx.Frame): 
    def __init__(self, parent, title, page, results_dict): 
     wx.Frame.__init__(self, parent, -1, title) 
     self.html = wx.html.HtmlWindow(self) 
     if "gtk2" in wx.PlatformInfo: 
      self.html.SetStandardFonts() 
     self.results_dict=results_dict #here 

     self.html.SetPage('') 

    def setFrame(self,event): 
     self.html.SetPage(self.results_dict[choice]) 
+0

정말 죄송합니다. 답변을 드린 지 오래지만, 이달 말에는 많이 먹었습니다. 나는 이것으로 놀고 있었고 몇 가지 질문이있었습니다. dict, 당신은 그것이 반환하는 모든 링크를 가져 와서 그것이 나오는 사이트가되는 키가있는 사전에 넣으라고 말하는 것입니까? 그것들이 같은 창에 나타나게하는 유일한 방법입니까? 또한 html 프레임을 체크 박스와 동일한 프레임에 포함시키는 것에 관심이 있었기 때문에 빈 상태로 초기화되고 채워 졌을까요? – Kevin

+0

나는 모든 결과에 대해 새로운 프레임이 필요 없다고 말하고 있습니다. 보려는 페이지에 따라 한 프레임의 내용을 설정할 수 있습니다. 물론 wx.Notebook (또는 choicebook 또는 listbook 또는 wxTreebook)을 사용하여 Firefox 탭과 같은 여러 패널 사이에서 선택할 수 있습니다. 또한 동일한 프레임에 여러 위젯을 넣는 wx 크기 조절기를 살펴보십시오. 그러나 다른 것을 시도하기 전에 한 가지 (레이아웃 또는 탭)를 사용해보십시오. – wisty