Fwd: Python Signal/Slot + QThred code analysis

Juan Christian juan0christian at gmail.com
Tue Nov 25 16:36:24 EST 2014


So guys, I had to change to approach, I read that using Qt I can't do
multiple inheritance. So my Outpost class can't be like 'Outpost(QObject,
QThred)'. I had to change the code a bit:

from PySide.QtCore import QObject, QThread, Signal
import requests
import bs4


class Worker(QThread):
def __init__(self, url, *args, **kwargs):
super().__init__(*args, **kwargs)
self.trades = None
self.posts = None
self.url = url
self.start()

def run(self):
soup = bs4.BeautifulSoup(requests.get(self.url).text)
self.trades = soup.select('div.stat_box
div.value')[0].get_text().replace(',', '')
self.posts = soup.select('div.stat_box div.value')[1].get_text()
return self


class Outpost(QObject):
received = Signal()

def __init__(self, id64, *args, **kwargs):
super().__init__(*args, **kwargs)
worker = Worker('http://www.myurl.com/' + id64)
self.received.emit(worker)

So, what I see people doing is creating a 'Worker' class for thread related
stuff and another separate class for the main stuff.

So, let's see the problems:

Traceback (most recent call last):
  File "D:/.../main.py", line 44, in output_slot
    outpost = Outpost('12345')
  File "D:\...\outpost.py", line 27, in __init__
    self.received.emit(worker)
TypeError: received() only accepts 0 arguments, 2 given!

The URL is OK, I externally checked, and return the expected.

So, what I'm trying to do here is call my Worker when outpost is
instantiated, then the Worker call the site in the run function, and then
set the variables and return itself.

Back to the main class, I have the init where I instantiate the Worker and
return it in the emit().

If I got it correctly, when I call the 'outpost.received.connect(IPSUM)',
IPSUM will be execute when, and only when I have all values set, because in
my Outpost class it will emit when it has everything done, did I get it
right?

OFF-TOPIC: You guys said that my emails had some trash HTML and strange
stuffs, is it OK now?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141125/f8560d1c/attachment.html>


More information about the Python-list mailing list