class ConvertThreadDirect(QtCore.QRunnable):
def __init__(self, item, soft, itemnumber):
QtCore.QRunnable.__init__(self)
self.item = item
self.soft = soft
self.itemnumber=itemnumber
self.softname=self.soft.softname
self.str=''
def run(self):
print "inside threadDirect"
self.emitter.emit(QtCore.SIGNAL("itemSetChecking(PyQt_PyObject)"),(self.itemnumber))
self.str=self.read_page(self.soft.url, self.soft.regexp)
qlist
=QtCore.
QStringList([str
(self.
itemnumber), self.
str]) self.emitter.emit(QtCore.SIGNAL("itemCheckedDirect(PyQt_PyObject)"),(self.itemnumber, self.str, self.soft))
def read_page(self, urlStr, tobefound):
pass
def __init__(self, parent=None):
self.threadPool=QtCore.QThreadPool(self)
self.threadPool.setMaxThreadCount(4)
[....]
[....]
def actStop(self):
print "I have to stop all the thread not started yet!!!"
def actRun(self):
print("Run")
tree=self.ui.treeWidget
nitem=tree.topLevelItemCount()
self.nitem=0
self.pb.setRange(0, nitem)
for i in range(0,nitem):
item=tree.topLevelItem(i)
s=self.softDic[unicode(item.text(0))]
ct = ConvertThreadDirect(item, s, i)
QtCore.
QObject.
connect(ct.
emitter,QtCore.
SIGNAL('itemCheckedDirect(PyQt_PyObject)'),self.
itemCheckedDirect) QtCore.
QObject.
connect(ct.
emitter,QtCore.
SIGNAL('itemSetChecking(PyQt_PyObject)'),self.
itemSetChecking) self.threadPool.start(ct)
print item.text(0)
self.ui.statusbar.showMessage(self.tr("Ready"))
class ConvertThreadDirect(QtCore.QRunnable):
def __init__(self, item, soft, itemnumber):
self.emitter = QtCore.QObject()
QtCore.QRunnable.__init__(self)
self.item = item
self.soft = soft
self.itemnumber=itemnumber
self.softname=self.soft.softname
self.str=''
def run(self):
print "inside threadDirect"
self.emitter.emit(QtCore.SIGNAL("itemSetChecking(PyQt_PyObject)"),(self.itemnumber))
self.str=self.read_page(self.soft.url, self.soft.regexp)
qlist=QtCore.QStringList([str(self.itemnumber), self.str])
self.emitter.emit(QtCore.SIGNAL("itemCheckedDirect(PyQt_PyObject)"),(self.itemnumber, self.str, self.soft))
def read_page(self, urlStr, tobefound):
pass
class MainForm(QtGui.QMainWindow):
def __init__(self, parent=None):
self.threadPool=QtCore.QThreadPool(self)
self.threadPool.setMaxThreadCount(4)
[....]
[....]
def actStop(self):
print "I have to stop all the thread not started yet!!!"
def actRun(self):
print("Run")
tree=self.ui.treeWidget
nitem=tree.topLevelItemCount()
self.nitem=0
self.pb.setRange(0, nitem)
for i in range(0,nitem):
item=tree.topLevelItem(i)
s=self.softDic[unicode(item.text(0))]
ct = ConvertThreadDirect(item, s, i)
QtCore.QObject.connect(ct.emitter,QtCore.SIGNAL('itemCheckedDirect(PyQt_PyObject)'),self.itemCheckedDirect)
QtCore.QObject.connect(ct.emitter,QtCore.SIGNAL('itemSetChecking(PyQt_PyObject)'),self.itemSetChecking)
self.threadPool.start(ct)
print item.text(0)
self.ui.statusbar.showMessage(self.tr("Ready"))
To copy to clipboard, switch view to plain text mode
Bookmarks