I have a little program that goes to news aggregater's, gets the hrefs, and returns in a window. I want to have multiple windows open if multiple sites are choosen, right now, it will only go to the first one in a list, and completes perfectly. I assume I am not passing the the contents of the list properly to the next step in my program.

import wx
import urllib2
from BeautifulSoup import BeautifulSoup
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.digg.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', 'Digg', '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)       
    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)
            soup = BeautifulSoup(html)
            tags = soup.findAll('a')

            soup1 = BeautifulSoup(''.join(str(t) for t in tags))
            print soup1.prettify()

            aTag,aEnd = makeHTMLTags("A")

            aTag = originalTextFor(aTag)
            aEnd = originalTextFor(aEnd)

            aLink = aTag + SkipTo(aEnd) + aEnd
            aLink.setParseAction(lambda tokens : ''.join(tokens))

            links = aLink.searchString(html)

            out = []
            out.extend(['  '+lnk[0] for lnk in links])

            P= '\n'.join(out)
            print type(P)

            print P

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


            #app = wx.PySimpleApp()
            frm = MyHtmlFrame(None, "Charlie")


app = wx.App()

checkList(None, -1, 'Charlie')

I have some print statements mixed in for debugging. So, any help, much appreciated. Also, if they all ended up on the same window, that would be fine too. Just trying to get past the only doing the first one

Edited by TheNational22: n/a

7 Years
Discussion Span
Last Post by woooee

Generally, you would use mutiprocessing or threading, with a separate class instance/window running in a separate process or thread.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.