diff options
Diffstat (limited to 'module/gui')
-rw-r--r-- | module/gui/Collector.py | 58 | ||||
-rw-r--r-- | module/gui/MainWindow.py | 2 | ||||
-rw-r--r-- | module/gui/Queue.py | 38 |
3 files changed, 68 insertions, 30 deletions
diff --git a/module/gui/Collector.py b/module/gui/Collector.py index 356ab36ec..112eb1cd5 100644 --- a/module/gui/Collector.py +++ b/module/gui/Collector.py @@ -23,14 +23,13 @@ from time import sleep from module.gui.Queue import ItemIterator -class PackageCollector(QThread): +class PackageCollector(QObject): def __init__(self, view, connector): - QThread.__init__(self) + QObject.__init__(self) self.view = view self.connector = connector self.collector = [] self.interval = 2 - self.running = True self.rootItem = self.view.invisibleRootItem() self.mutex = QMutex() item = self.PackageCollectorPack(self) @@ -40,14 +39,28 @@ class PackageCollector(QThread): self.rootItem.addChild(item) self.linkCollector = item self.pauseIDs = [] + self.updater = self.CollectorUpdater(self.interval) + self.connect(self.updater, SIGNAL("update()"), self.update) - def run(self): - while self.running: - self.update() - sleep(self.interval) + class CollectorUpdater(QThread): + def __init__(self, interval): + QThread.__init__(self) + self.interval = interval + self.running = True + + def run(self): + while self.running: + self.emit(SIGNAL("update()")) + self.sleep(self.interval) + + def start(self): + self.updater.start() + + def wait(self): + self.updater.wait() def stop(self): - self.running = False + self.updater.running = False def update(self): locker = QMutexLocker(self.mutex) @@ -210,23 +223,36 @@ class PackageCollector(QThread): def getPack(self): return self.pack -class LinkCollector(QThread): +class LinkCollector(QObject): def __init__(self, view, root, connector): - QThread.__init__(self) + QObject.__init__(self) self.view = view self.connector = connector self.interval = 2 - self.running = True self.rootItem = root self.mutex = QMutex() + self.updater = self.CollectorUpdater(self.interval) + self.connect(self.updater, SIGNAL("update()"), self.update) + + class CollectorUpdater(QThread): + def __init__(self, interval): + QThread.__init__(self) + self.interval = interval + self.running = True + + def run(self): + while self.running: + self.emit(SIGNAL("update()")) + self.sleep(self.interval) + + def start(self): + self.updater.start() - def run(self): - while self.running: - self.update() - sleep(self.interval) + def wait(self): + self.updater.wait() def stop(self): - self.running = False + self.updater.running = False def update(self): locker = QMutexLocker(self.mutex) diff --git a/module/gui/MainWindow.py b/module/gui/MainWindow.py index 94ff63dda..250b701e4 100644 --- a/module/gui/MainWindow.py +++ b/module/gui/MainWindow.py @@ -403,13 +403,11 @@ class MainWindow(QMainWindow): def slotEditPackage(self): item = self.tabs["collector"]["package_view"].currentItem() pid = self.tabs["collector"]["package_view"].currentItem().data(0, Qt.UserRole).toPyObject() - print type(pid) self.emit(SIGNAL("pauseItemUpdate"), pid, True) self.tabs["collector"]["package_view"].editItem(item, 0) def slotCloseItemEditor(self, editor, hint): pid = self.tabs["collector"]["package_view"].currentItem().data(0, Qt.UserRole).toPyObject() - print type(pid) self.emit(SIGNAL("changePackageName"), pid, editor.text()) self.emit(SIGNAL("pauseItemUpdate"), pid, False) diff --git a/module/gui/Queue.py b/module/gui/Queue.py index 499cb5199..ed1c0f0a1 100644 --- a/module/gui/Queue.py +++ b/module/gui/Queue.py @@ -21,9 +21,9 @@ from PyQt4.QtGui import * from time import sleep, time -class Queue(QThread): +class Queue(QObject): def __init__(self, view, connector): - QThread.__init__(self) + QObject.__init__(self) self.view = view self.connector = connector self.statusMap = { @@ -33,24 +33,38 @@ class Queue(QThread): "waiting": 3, "reconnected": 4, "starting": 5, - "downloading": 6, - "failed": 7, - "aborted": 8, + "failed": 6, + "aborted": 7, + "decrypting": 8, + "downloading": 9 } self.statusMapReverse = dict((v,k) for k, v in self.statusMap.iteritems()) self.interval = 1 - self.running = True self.wait_dict = {} self.rootItem = self.view.invisibleRootItem() self.mutex = QMutex() + self.updater = self.QueueUpdater(self.interval) + self.connect(self.updater, SIGNAL("update()"), self.update) - def run(self): - while self.running: - self.update() - sleep(self.interval) + class QueueUpdater(QThread): + def __init__(self, interval): + QThread.__init__(self) + self.interval = interval + self.running = True + + def run(self): + while self.running: + self.emit(SIGNAL("update()")) + self.sleep(self.interval) + + def start(self): + self.updater.start() + + def wait(self): + self.updater.wait() def stop(self): - self.running = False + self.updater.running = False def update(self): locker = QMutexLocker(self.mutex) @@ -241,7 +255,7 @@ class Queue(QThread): self.addChild(newChild) item = newChild speed = self.queue.getSpeed(item) - if speed == None or item.getFileData()["status_type"] == "starting": + if speed == None or item.getFileData()["status_type"] == "starting" or item.getFileData()["status_type"] == "decrypting": status = item.getFileData()["status_type"] else: status = "%s (%s KB/s)" % (item.getFileData()["status_type"], speed) |