From ddd93d0e571edbe1a62f928436ea79818466e940 Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 17 Dec 2009 17:47:41 +0100 Subject: splited gui file, extended .hgignore --- module/gui/Queue.py | 252 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 module/gui/Queue.py (limited to 'module/gui/Queue.py') diff --git a/module/gui/Queue.py b/module/gui/Queue.py new file mode 100644 index 000000000..7e63e6180 --- /dev/null +++ b/module/gui/Queue.py @@ -0,0 +1,252 @@ +# -*- coding: utf-8 -*- +""" + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . + + @author: mkaay +""" + +from PyQt4.QtCore import * +from PyQt4.QtGui import * + +from time import sleep + +class Queue(QThread): + def __init__(self, view, connector): + QThread.__init__(self) + self.view = view + self.connector = connector + self.statusMap = { + "finished": 0, + "checking": 1, + "waiting": 2, + "reconnected": 3, + "downloading": 4, + "failed": 5, + "aborted": 6, + } + self.statusMapReverse = dict((v,k) for k, v in self.statusMap.iteritems()) + self.queue = [] + self.interval = 2 + self.running = True + self.mutex = QMutex() + + def run(self): + while self.running: + self.update() + sleep(self.interval) + + def update(self): + locker = QMutexLocker(self.mutex) + packs = self.connector.getPackageQueue() + downloading_raw = self.connector.getDownloadQueue() + downloading = {} + for d in downloading: + did = d["id"] + del d["id"] + del d["name"] + del d["status"] + downloading[did] = d + for data in packs: + pack = self.getPack(data["id"]) + if not pack: + pack = self.QueuePack(self) + pack.setData(data) + self.addPack(data["id"], pack) + files = self.connector.getPackageFiles(data["id"]) + for fid in files: + info = self.connector.getLinkInfo(fid) + child = pack.getChild(fid) + if not child: + child = self.QueueFile(self, pack) + try: + info["downloading"] = downloading[data["id"]] + except: + info["downloading"] = None + child.setData(info) + pack.addChild(fid, child) + + def addPack(self, pid, newPack): + pos = None + try: + for k, pack in enumerate(self.queue): + if pack.getData()["id"] == pid: + pos = k + break + if pos == None: + raise Exception() + self.queue[pos] = newPack + except: + self.queue.append(newPack) + pos = self.queue.index(newPack) + item = self.view.topLevelItem(pos) + if not item: + item = QTreeWidgetItem() + self.view.insertTopLevelItem(pos, item) + item.setData(0, Qt.DisplayRole, QVariant(newPack.getData()["package_name"])) + status = -1 + for child in newPack.getChildren(): + if self.statusMap.has_key(child.data["status_type"]) and self.statusMap[child.data["status_type"]] > status: + status = self.statusMap[child.data["status_type"]] + if status >= 0: + item.setData(1, Qt.DisplayRole, QVariant(self.statusMapReverse[status])) + item.setData(0, Qt.UserRole, QVariant(pid)) + item.setData(2, Qt.UserRole, QVariant(newPack)) + + def getPack(self, pid): + for k, pack in enumerate(self.queue): + if pack.getData()["id"] == pid: + return pack + return None + + def getProgress(self, q): + locker = QMutexLocker(self.mutex) + if isinstance(q, self.QueueFile): + data = q.getData() + if data["downloading"]: + return int(data["downloading"]["percent"]) + if data["status_type"] == "finished" or \ + data["status_type"] == "failed" or \ + data["status_type"] == "aborted": + return 100 + elif isinstance(q, self.QueuePack): + children = q.getChildren() + count = len(children) + perc_sum = 0 + for child in children: + val = 0 + data = child.getData() + if data["downloading"]: + val = int(data["downloading"]["percent"]) + elif child.data["status_type"] == "finished" or \ + child.data["status_type"] == "failed" or \ + child.data["status_type"] == "aborted": + val = 100 + perc_sum += val + if count == 0: + return 0 + return perc_sum/count + return 0 + + def getSpeed(self, q): + locker = QMutexLocker(self.mutex) + if isinstance(q, self.QueueFile): + data = q.getData() + if data["downloading"]: + return int(data["downloading"]["speed"]) + elif isinstance(q, self.QueuePack): + children = q.getChildren() + count = len(children) + speed_sum = 0 + for child in children: + val = 0 + data = child.getData() + running = False + if data["downloading"]: + val = int(data["downloading"]["speed"]) + running = True + speed_sum += val + if count == 0 or not running: + return None + return speed_sum + return None + + class QueuePack(): + def __init__(self, queue): + self.queue = queue + self.data = [] + self.children = [] + + def addChild(self, cid, newChild): + pos = None + try: + for k, child in enumerate(self.getChildren()): + if child.getData()["id"] == cid: + pos = k + break + if pos == None: + raise Exception() + self.children[pos] = newChild + except: + self.children.append(newChild) + pos = self.children.index(newChild) + ppos = self.queue.queue.index(self) + parent = self.queue.view.topLevelItem(ppos) + item = parent.child(pos) + if not item: + item = QTreeWidgetItem() + parent.insertChild(pos, item) + status = "%s (%s)" % (newChild.getData()["status_type"], newChild.getData()["plugin"]) + item.setData(0, Qt.DisplayRole, QVariant(newChild.getData()["filename"])) + item.setData(1, Qt.DisplayRole, QVariant(status)) + item.setData(0, Qt.UserRole, QVariant(cid)) + item.setData(2, Qt.UserRole, QVariant(newChild)) + + def getChildren(self): + return self.children + + def getChild(self, cid): + try: + return self.children[cid] + except: + return None + + def hasChildren(self, data): + return (len(self.children) > 0) + + def setData(self, data): + self.data = data + + def getData(self): + return self.data + + class QueueFile(): + def __init__(self, queue, pack): + self.queue = queue + self.pack = pack + + def getData(self): + return self.data + + def setData(self, data): + self.data = data + + def getPack(self): + return self.pack + +class QueueProgressBarDelegate(QItemDelegate): + def __init__(self, parent, queue): + QItemDelegate.__init__(self, parent) + self.queue = queue + + def paint(self, painter, option, index): + if index.column() == 2: + qe = index.data(Qt.UserRole).toPyObject() + progress = self.queue.getProgress(qe) + opts = QStyleOptionProgressBarV2() + opts.maximum = 100 + opts.minimum = 0 + opts.progress = progress + opts.rect = option.rect + opts.rect.setRight(option.rect.right()-1) + opts.rect.setHeight(option.rect.height()-1) + opts.textVisible = True + opts.textAlignment = Qt.AlignCenter + speed = self.queue.getSpeed(qe) + if speed == None: + opts.text = QString.number(opts.progress) + "%" + else: + opts.text = QString("%s kb/s - %s" % (speed, opts.progress)) + "%" + QApplication.style().drawControl(QStyle.CE_ProgressBar, opts, painter) + return + QItemDelegate.paint(self, painter, option, index) -- cgit v1.2.3 From ab5d907f48a8879f717e0c6482695ef1afe280a0 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sun, 20 Dec 2009 18:25:19 +0100 Subject: gui can return to connection manager, new collector --- module/gui/Queue.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'module/gui/Queue.py') diff --git a/module/gui/Queue.py b/module/gui/Queue.py index 7e63e6180..52f11fd8c 100644 --- a/module/gui/Queue.py +++ b/module/gui/Queue.py @@ -46,6 +46,9 @@ class Queue(QThread): self.update() sleep(self.interval) + def stop(self): + self.running = False + def update(self): locker = QMutexLocker(self.mutex) packs = self.connector.getPackageQueue() -- cgit v1.2.3 From ed36dd5988907019cc9cc5b98265f00a52462c85 Mon Sep 17 00:00:00 2001 From: mkaay Date: Tue, 22 Dec 2009 17:07:35 +0100 Subject: more docstrings, small design changes --- module/gui/Queue.py | 79 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 17 deletions(-) (limited to 'module/gui/Queue.py') diff --git a/module/gui/Queue.py b/module/gui/Queue.py index 52f11fd8c..c9a3e858b 100644 --- a/module/gui/Queue.py +++ b/module/gui/Queue.py @@ -19,7 +19,7 @@ from PyQt4.QtCore import * from PyQt4.QtGui import * -from time import sleep +from time import sleep, time class Queue(QThread): def __init__(self, view, connector): @@ -37,8 +37,9 @@ class Queue(QThread): } self.statusMapReverse = dict((v,k) for k, v in self.statusMap.iteritems()) self.queue = [] - self.interval = 2 + self.interval = 1 self.running = True + self.wait_dict = {} self.mutex = QMutex() def run(self): @@ -54,7 +55,7 @@ class Queue(QThread): packs = self.connector.getPackageQueue() downloading_raw = self.connector.getDownloadQueue() downloading = {} - for d in downloading: + for d in downloading_raw: did = d["id"] del d["id"] del d["name"] @@ -73,7 +74,7 @@ class Queue(QThread): if not child: child = self.QueueFile(self, pack) try: - info["downloading"] = downloading[data["id"]] + info["downloading"] = downloading[info["id"]] except: info["downloading"] = None child.setData(info) @@ -98,13 +99,22 @@ class Queue(QThread): self.view.insertTopLevelItem(pos, item) item.setData(0, Qt.DisplayRole, QVariant(newPack.getData()["package_name"])) status = -1 + speed = self.getSpeed(newPack) + plugins = [] for child in newPack.getChildren(): if self.statusMap.has_key(child.data["status_type"]) and self.statusMap[child.data["status_type"]] > status: status = self.statusMap[child.data["status_type"]] + if not child.data["plugin"] in plugins: + plugins.append(child.data["plugin"]) if status >= 0: - item.setData(1, Qt.DisplayRole, QVariant(self.statusMapReverse[status])) + if speed == None: + statustxt = self.statusMapReverse[status] + else: + statustxt = "%s (%s KB/s)" % (self.statusMapReverse[status], speed) + item.setData(2, Qt.DisplayRole, QVariant(statustxt)) + item.setData(1, Qt.DisplayRole, QVariant(", ".join(plugins))) item.setData(0, Qt.UserRole, QVariant(pid)) - item.setData(2, Qt.UserRole, QVariant(newPack)) + item.setData(3, Qt.UserRole, QVariant(newPack)) def getPack(self, pid): for k, pack in enumerate(self.queue): @@ -112,6 +122,27 @@ class Queue(QThread): return pack return None + def getWaitingProgress(self, q): + locker = QMutexLocker(self.mutex) + if isinstance(q, self.QueueFile): + data = q.getData() + if data["status_type"] == "waiting" and data["downloading"]: + until = float(data["downloading"]["wait_until"]) + try: + since, until_old = self.wait_dict[data["id"]] + if not until == until_old: + raise Exception + except: + since = time() + self.wait_dict[data["id"]] = since, until + since = float(since) + max_wait = float(until-since) + rest = int(until-time()) + res = 100/max_wait + perc = rest*res + return perc, rest + return None + def getProgress(self, q): locker = QMutexLocker(self.mutex) if isinstance(q, self.QueueFile): @@ -142,7 +173,7 @@ class Queue(QThread): return 0 def getSpeed(self, q): - locker = QMutexLocker(self.mutex) + #locker = QMutexLocker(self.mutex) if isinstance(q, self.QueueFile): data = q.getData() if data["downloading"]: @@ -151,15 +182,18 @@ class Queue(QThread): children = q.getChildren() count = len(children) speed_sum = 0 + all_waiting = True for child in children: val = 0 data = child.getData() running = False if data["downloading"]: + if not data["status_type"] == "waiting": + all_waiting = False val = int(data["downloading"]["speed"]) running = True speed_sum += val - if count == 0 or not running: + if count == 0 or not running or all_waiting: return None return speed_sum return None @@ -189,11 +223,16 @@ class Queue(QThread): if not item: item = QTreeWidgetItem() parent.insertChild(pos, item) - status = "%s (%s)" % (newChild.getData()["status_type"], newChild.getData()["plugin"]) + speed = self.queue.getSpeed(newChild) + if speed == None: + status = newChild.getData()["status_type"] + else: + status = "%s (%s KB/s)" % (newChild.getData()["status_type"], speed) item.setData(0, Qt.DisplayRole, QVariant(newChild.getData()["filename"])) - item.setData(1, Qt.DisplayRole, QVariant(status)) + item.setData(2, Qt.DisplayRole, QVariant(status)) + item.setData(1, Qt.DisplayRole, QVariant(newChild.getData()["plugin"])) item.setData(0, Qt.UserRole, QVariant(cid)) - item.setData(2, Qt.UserRole, QVariant(newChild)) + item.setData(3, Qt.UserRole, QVariant(newChild)) def getChildren(self): return self.children @@ -217,6 +256,7 @@ class Queue(QThread): def __init__(self, queue, pack): self.queue = queue self.pack = pack + self.wait_since = None def getData(self): return self.data @@ -233,9 +273,15 @@ class QueueProgressBarDelegate(QItemDelegate): self.queue = queue def paint(self, painter, option, index): - if index.column() == 2: + if index.column() == 3: qe = index.data(Qt.UserRole).toPyObject() - progress = self.queue.getProgress(qe) + w = self.queue.getWaitingProgress(qe) + wait = None + if w: + progress = w[0] + wait = w[1] + else: + progress = self.queue.getProgress(qe) opts = QStyleOptionProgressBarV2() opts.maximum = 100 opts.minimum = 0 @@ -245,11 +291,10 @@ class QueueProgressBarDelegate(QItemDelegate): opts.rect.setHeight(option.rect.height()-1) opts.textVisible = True opts.textAlignment = Qt.AlignCenter - speed = self.queue.getSpeed(qe) - if speed == None: - opts.text = QString.number(opts.progress) + "%" + if not wait == None: + opts.text = QString("waiting %d seconds" % (wait,)) else: - opts.text = QString("%s kb/s - %s" % (speed, opts.progress)) + "%" + opts.text = QString.number(opts.progress) + "%" QApplication.style().drawControl(QStyle.CE_ProgressBar, opts, painter) return QItemDelegate.paint(self, painter, option, index) -- cgit v1.2.3 From ea04c11ce1fb52895449a56e862eff5448ea456a Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 24 Dec 2009 01:28:08 +0100 Subject: downloads are now aborted correctly, gui: remove downloads, new icons --- module/gui/Queue.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'module/gui/Queue.py') diff --git a/module/gui/Queue.py b/module/gui/Queue.py index c9a3e858b..35e1163b9 100644 --- a/module/gui/Queue.py +++ b/module/gui/Queue.py @@ -61,8 +61,10 @@ class Queue(QThread): del d["name"] del d["status"] downloading[did] = d + ids = [] for data in packs: pack = self.getPack(data["id"]) + ids.append(data["id"]) if not pack: pack = self.QueuePack(self) pack.setData(data) @@ -73,12 +75,15 @@ class Queue(QThread): child = pack.getChild(fid) if not child: child = self.QueueFile(self, pack) + info["downloading"] = None try: info["downloading"] = downloading[info["id"]] except: - info["downloading"] = None + pass child.setData(info) pack.addChild(fid, child) + pack.clear(files) + self.clear(ids) def addPack(self, pid, newPack): pos = None @@ -122,6 +127,17 @@ class Queue(QThread): return pack return None + def clear(self, ids): + clear = False + for pack in self.queue: + if not pack.getData()["id"] in ids: + clear = True + break + if not clear: + return + self.queue = [] + self.view.emit(SIGNAL("clear")) + def getWaitingProgress(self, q): locker = QMutexLocker(self.mutex) if isinstance(q, self.QueueFile): @@ -173,7 +189,6 @@ class Queue(QThread): return 0 def getSpeed(self, q): - #locker = QMutexLocker(self.mutex) if isinstance(q, self.QueueFile): data = q.getData() if data["downloading"]: @@ -251,6 +266,17 @@ class Queue(QThread): def getData(self): return self.data + + def clear(self, ids): + clear = False + for file in self.getChildren(): + if not file.getData()["id"] in ids: + clear = True + break + if not clear: + return + self.queue.queue = [] + self.queue.view.emit(SIGNAL("clear")) class QueueFile(): def __init__(self, queue, pack): -- cgit v1.2.3 From 504b313112be6a82d6eee418ae059646ecfc4b30 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sat, 26 Dec 2009 20:18:11 +0100 Subject: fixed ddl-music, cleaned up, new status (starting), some more fixes --- module/gui/Queue.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'module/gui/Queue.py') diff --git a/module/gui/Queue.py b/module/gui/Queue.py index 35e1163b9..f542c9a6b 100644 --- a/module/gui/Queue.py +++ b/module/gui/Queue.py @@ -198,10 +198,10 @@ class Queue(QThread): count = len(children) speed_sum = 0 all_waiting = True + running = False for child in children: val = 0 data = child.getData() - running = False if data["downloading"]: if not data["status_type"] == "waiting": all_waiting = False @@ -239,7 +239,7 @@ class Queue(QThread): item = QTreeWidgetItem() parent.insertChild(pos, item) speed = self.queue.getSpeed(newChild) - if speed == None: + if speed == None or newChild.getData()["status_type"] == "starting": status = newChild.getData()["status_type"] else: status = "%s (%s KB/s)" % (newChild.getData()["status_type"], speed) @@ -269,12 +269,23 @@ class Queue(QThread): def clear(self, ids): clear = False + children = {} for file in self.getChildren(): if not file.getData()["id"] in ids: clear = True break + try: + children[file.getData()["id"]] + clear = True + except: + children[file.getData()["id"]] = True + if not clear: return + ppos = self.queue.queue.index(self) + parent = self.queue.view.topLevelItem(ppos) + parent.takeChildren() + self.children = [] self.queue.queue = [] self.queue.view.emit(SIGNAL("clear")) -- cgit v1.2.3 From 8888b714d748398e99f7425fa861f4e165579da6 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sat, 26 Dec 2009 20:46:36 +0100 Subject: fixed view update --- module/gui/Queue.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'module/gui/Queue.py') diff --git a/module/gui/Queue.py b/module/gui/Queue.py index f542c9a6b..0def31bf6 100644 --- a/module/gui/Queue.py +++ b/module/gui/Queue.py @@ -40,6 +40,7 @@ class Queue(QThread): self.interval = 1 self.running = True self.wait_dict = {} + self.rootItem = self.view.invisibleRootItem() self.mutex = QMutex() def run(self): @@ -63,13 +64,16 @@ class Queue(QThread): downloading[did] = d ids = [] for data in packs: - pack = self.getPack(data["id"]) ids.append(data["id"]) + self.clear(ids) + for data in packs: + pack = self.getPack(data["id"]) if not pack: pack = self.QueuePack(self) pack.setData(data) self.addPack(data["id"], pack) files = self.connector.getPackageFiles(data["id"]) + pack.clear(files) for fid in files: info = self.connector.getLinkInfo(fid) child = pack.getChild(fid) @@ -82,8 +86,6 @@ class Queue(QThread): pass child.setData(info) pack.addChild(fid, child) - pack.clear(files) - self.clear(ids) def addPack(self, pid, newPack): pos = None @@ -98,10 +100,10 @@ class Queue(QThread): except: self.queue.append(newPack) pos = self.queue.index(newPack) - item = self.view.topLevelItem(pos) + item = self.rootItem.child(pos) if not item: item = QTreeWidgetItem() - self.view.insertTopLevelItem(pos, item) + self.rootItem.insertChild(pos, item) item.setData(0, Qt.DisplayRole, QVariant(newPack.getData()["package_name"])) status = -1 speed = self.getSpeed(newPack) @@ -136,7 +138,7 @@ class Queue(QThread): if not clear: return self.queue = [] - self.view.emit(SIGNAL("clear")) + self.rootItem.takeChildren() def getWaitingProgress(self, q): locker = QMutexLocker(self.mutex) @@ -233,7 +235,7 @@ class Queue(QThread): self.children.append(newChild) pos = self.children.index(newChild) ppos = self.queue.queue.index(self) - parent = self.queue.view.topLevelItem(ppos) + parent = self.queue.rootItem.child(ppos) item = parent.child(pos) if not item: item = QTreeWidgetItem() @@ -283,11 +285,9 @@ class Queue(QThread): if not clear: return ppos = self.queue.queue.index(self) - parent = self.queue.view.topLevelItem(ppos) + parent = self.queue.rootItem.child(ppos) parent.takeChildren() self.children = [] - self.queue.queue = [] - self.queue.view.emit(SIGNAL("clear")) class QueueFile(): def __init__(self, queue, pack): -- cgit v1.2.3 From ce2a8294b5aefe4497c88f24c817084868b8b1eb Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 28 Dec 2009 15:32:06 +0100 Subject: gui now stable --- module/gui/Queue.py | 217 ++++++++++++++++++++++++++++------------------------ 1 file changed, 118 insertions(+), 99 deletions(-) (limited to 'module/gui/Queue.py') diff --git a/module/gui/Queue.py b/module/gui/Queue.py index 0def31bf6..c0f43c740 100644 --- a/module/gui/Queue.py +++ b/module/gui/Queue.py @@ -28,15 +28,16 @@ class Queue(QThread): self.connector = connector self.statusMap = { "finished": 0, - "checking": 1, - "waiting": 2, - "reconnected": 3, - "downloading": 4, - "failed": 5, - "aborted": 6, + "queued": 1, + "checking": 2, + "waiting": 3, + "reconnected": 4, + "starting": 5, + "downloading": 6, + "failed": 7, + "aborted": 8, } self.statusMapReverse = dict((v,k) for k, v in self.statusMap.iteritems()) - self.queue = [] self.interval = 1 self.running = True self.wait_dict = {} @@ -70,10 +71,10 @@ class Queue(QThread): pack = self.getPack(data["id"]) if not pack: pack = self.QueuePack(self) - pack.setData(data) - self.addPack(data["id"], pack) + pack.setPackData(data) files = self.connector.getPackageFiles(data["id"]) pack.clear(files) + self.addPack(data["id"], pack) for fid in files: info = self.connector.getLinkInfo(fid) child = pack.getChild(fid) @@ -84,35 +85,36 @@ class Queue(QThread): info["downloading"] = downloading[info["id"]] except: pass - child.setData(info) - pack.addChild(fid, child) + if not info["status_type"]: + info["status_type"] = "queued" + child.setFileData(info) + pack.addPackChild(fid, child) + self.addPack(data["id"], pack) def addPack(self, pid, newPack): pos = None try: - for k, pack in enumerate(self.queue): - if pack.getData()["id"] == pid: - pos = k + for pack in QueueIterator(self.rootItem): + if pack.getPackData()["id"] == pid: + pos = self.rootItem.indexOfChild(pack) break if pos == None: raise Exception() - self.queue[pos] = newPack + item = self.rootItem.child(pos) + item.setPackData(newPack.getPackData()) except: - self.queue.append(newPack) - pos = self.queue.index(newPack) - item = self.rootItem.child(pos) - if not item: - item = QTreeWidgetItem() - self.rootItem.insertChild(pos, item) - item.setData(0, Qt.DisplayRole, QVariant(newPack.getData()["package_name"])) + self.rootItem.addChild(newPack) + item = newPack + item.setData(0, Qt.DisplayRole, QVariant(item.getPackData()["package_name"])) status = -1 - speed = self.getSpeed(newPack) + speed = self.getSpeed(item) plugins = [] - for child in newPack.getChildren(): - if self.statusMap.has_key(child.data["status_type"]) and self.statusMap[child.data["status_type"]] > status: - status = self.statusMap[child.data["status_type"]] - if not child.data["plugin"] in plugins: - plugins.append(child.data["plugin"]) + for child in item.getChildren(): + data = child.getFileData() + if self.statusMap.has_key(data["status_type"]) and self.statusMap[data["status_type"]] > status: + status = self.statusMap[data["status_type"]] + if not data["plugin"] in plugins: + plugins.append(data["plugin"]) if status >= 0: if speed == None: statustxt = self.statusMapReverse[status] @@ -121,29 +123,28 @@ class Queue(QThread): item.setData(2, Qt.DisplayRole, QVariant(statustxt)) item.setData(1, Qt.DisplayRole, QVariant(", ".join(plugins))) item.setData(0, Qt.UserRole, QVariant(pid)) - item.setData(3, Qt.UserRole, QVariant(newPack)) + item.setData(3, Qt.UserRole, QVariant(item)) def getPack(self, pid): - for k, pack in enumerate(self.queue): - if pack.getData()["id"] == pid: + for k, pack in enumerate(ItemIterator(self.rootItem)): + if pack.getPackData()["id"] == pid: return pack return None def clear(self, ids): clear = False - for pack in self.queue: - if not pack.getData()["id"] in ids: + for pack in ItemIterator(self.rootItem): + if not pack.getPackData()["id"] in ids: clear = True break if not clear: return - self.queue = [] self.rootItem.takeChildren() def getWaitingProgress(self, q): locker = QMutexLocker(self.mutex) if isinstance(q, self.QueueFile): - data = q.getData() + data = q.getFileData() if data["status_type"] == "waiting" and data["downloading"]: until = float(data["downloading"]["wait_until"]) try: @@ -164,7 +165,7 @@ class Queue(QThread): def getProgress(self, q): locker = QMutexLocker(self.mutex) if isinstance(q, self.QueueFile): - data = q.getData() + data = q.getFileData() if data["downloading"]: return int(data["downloading"]["percent"]) if data["status_type"] == "finished" or \ @@ -177,12 +178,12 @@ class Queue(QThread): perc_sum = 0 for child in children: val = 0 - data = child.getData() + data = child.getFileData() if data["downloading"]: val = int(data["downloading"]["percent"]) - elif child.data["status_type"] == "finished" or \ - child.data["status_type"] == "failed" or \ - child.data["status_type"] == "aborted": + elif data["status_type"] == "finished" or \ + data["status_type"] == "failed" or \ + data["status_type"] == "aborted": val = 100 perc_sum += val if count == 0: @@ -192,7 +193,7 @@ class Queue(QThread): def getSpeed(self, q): if isinstance(q, self.QueueFile): - data = q.getData() + data = q.getFileData() if data["downloading"]: return int(data["downloading"]["speed"]) elif isinstance(q, self.QueuePack): @@ -203,7 +204,7 @@ class Queue(QThread): running = False for child in children: val = 0 - data = child.getData() + data = child.getFileData() if data["downloading"]: if not data["status_type"] == "waiting": all_waiting = False @@ -215,91 +216,87 @@ class Queue(QThread): return speed_sum return None - class QueuePack(): + class QueuePack(QTreeWidgetItem): def __init__(self, queue): + QTreeWidgetItem.__init__(self) self.queue = queue - self.data = [] - self.children = [] + self._data = {} - def addChild(self, cid, newChild): + def addPackChild(self, cid, newChild): pos = None try: - for k, child in enumerate(self.getChildren()): + for child in ItemIterator(self): if child.getData()["id"] == cid: - pos = k + pos = self.indexOfChild(child) break if pos == None: raise Exception() - self.children[pos] = newChild + item = self.child(pos) + item.setFileData(newChild.getFileData()) except: - self.children.append(newChild) - pos = self.children.index(newChild) - ppos = self.queue.queue.index(self) - parent = self.queue.rootItem.child(ppos) - item = parent.child(pos) - if not item: - item = QTreeWidgetItem() - parent.insertChild(pos, item) - speed = self.queue.getSpeed(newChild) - if speed == None or newChild.getData()["status_type"] == "starting": - status = newChild.getData()["status_type"] + self.addChild(newChild) + item = newChild + speed = self.queue.getSpeed(item) + if speed == None or item.getFileData()["status_type"] == "starting": + status = item.getFileData()["status_type"] else: - status = "%s (%s KB/s)" % (newChild.getData()["status_type"], speed) - item.setData(0, Qt.DisplayRole, QVariant(newChild.getData()["filename"])) + status = "%s (%s KB/s)" % (item.getFileData()["status_type"], speed) + item.setData(0, Qt.DisplayRole, QVariant(item.getFileData()["filename"])) item.setData(2, Qt.DisplayRole, QVariant(status)) - item.setData(1, Qt.DisplayRole, QVariant(newChild.getData()["plugin"])) + item.setData(1, Qt.DisplayRole, QVariant(item.getFileData()["plugin"])) item.setData(0, Qt.UserRole, QVariant(cid)) - item.setData(3, Qt.UserRole, QVariant(newChild)) - - def getChildren(self): - return self.children + item.setData(3, Qt.UserRole, QVariant(item)) - def getChild(self, cid): - try: - return self.children[cid] - except: - return None + def setPackData(self, data): + self._data = data - def hasChildren(self, data): - return (len(self.children) > 0) + def getPackData(self): + return self._data - def setData(self, data): - self.data = data + def getChildren(self): + ret = [] + for item in ItemIterator(self): + ret.append(item) + return ret - def getData(self): - return self.data + def getChild(self, cid): + for item in ItemIterator(self): + if item.getFileData()["id"] == cid: + return item + return None def clear(self, ids): clear = False - children = {} - for file in self.getChildren(): - if not file.getData()["id"] in ids: - clear = True - break - try: - children[file.getData()["id"]] - clear = True - except: - children[file.getData()["id"]] = True - - if not clear: + remove = [] + children = [] + for k, file in enumerate(self.getChildren()): + if not file.getFileData()["id"] in ids: + remove.append(file.getFileData()["id"]) + if file.getFileData()["id"] in children and not file.getFileData()["id"] in remove: + remove.append(file.getFileData()["id"]) + continue + children.append(file.getFileData()["id"]) + if not remove: return - ppos = self.queue.queue.index(self) - parent = self.queue.rootItem.child(ppos) - parent.takeChildren() - self.children = [] + remove.sort() + remove.reverse() + parent = self + for k in remove: + parent.takeChild(k) - class QueueFile(): + class QueueFile(QTreeWidgetItem): def __init__(self, queue, pack): + QTreeWidgetItem.__init__(self) self.queue = queue self.pack = pack + self._data = {} self.wait_since = None - def getData(self): - return self.data + def getFileData(self): + return self._data - def setData(self, data): - self.data = data + def setFileData(self, data): + self._data = data def getPack(self): return self.pack @@ -335,3 +332,25 @@ class QueueProgressBarDelegate(QItemDelegate): QApplication.style().drawControl(QStyle.CE_ProgressBar, opts, painter) return QItemDelegate.paint(self, painter, option, index) + +class ItemIterator(): + def __init__(self, item): + self.item = item + self.current = -1 + + def __iadd__(self, val): + self.current += val + + def value(self): + return self.item.child(self.current) + + def next(self): + self.__iadd__(1) + value = self.value() + if value: + return self.value() + else: + raise StopIteration + + def __iter__(self): + return self -- cgit v1.2.3 From da359f8c770bac754234e0f899058b25126cd476 Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 28 Dec 2009 19:51:37 +0100 Subject: gui: easier package management --- module/gui/Queue.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'module/gui/Queue.py') diff --git a/module/gui/Queue.py b/module/gui/Queue.py index c0f43c740..499cb5199 100644 --- a/module/gui/Queue.py +++ b/module/gui/Queue.py @@ -133,13 +133,17 @@ class Queue(QThread): def clear(self, ids): clear = False - for pack in ItemIterator(self.rootItem): + remove = [] + for k, pack in enumerate(ItemIterator(self.rootItem)): if not pack.getPackData()["id"] in ids: clear = True - break + remove.append(k) if not clear: return - self.rootItem.takeChildren() + remove.sort() + remove.reverse() + for k in remove: + self.rootItem.takeChild(k) def getWaitingProgress(self, q): locker = QMutexLocker(self.mutex) -- cgit v1.2.3 From 4f904bd9610795c36d9e896bdf44c263ff43f5fd Mon Sep 17 00:00:00 2001 From: mkaay Date: Fri, 1 Jan 2010 17:13:43 +0100 Subject: fixed SerienjunkiesOrg, no more segfault in gui? --- module/gui/Queue.py | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'module/gui/Queue.py') 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) -- cgit v1.2.3 From d2ea03a068c9cbc43750d672aab7f2574ccfd9b4 Mon Sep 17 00:00:00 2001 From: mkaay Date: Fri, 1 Jan 2010 20:54:44 +0100 Subject: fixed netload.in premium --- module/gui/Queue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/gui/Queue.py') diff --git a/module/gui/Queue.py b/module/gui/Queue.py index ed1c0f0a1..be2170309 100644 --- a/module/gui/Queue.py +++ b/module/gui/Queue.py @@ -130,7 +130,7 @@ class Queue(QObject): if not data["plugin"] in plugins: plugins.append(data["plugin"]) if status >= 0: - if speed == None: + if speed == None or self.statusMapReverse[status] == "starting" or self.statusMapReverse[status] == "decrypting": statustxt = self.statusMapReverse[status] else: statustxt = "%s (%s KB/s)" % (self.statusMapReverse[status], speed) -- cgit v1.2.3 From bdb3deb371bbbcb5452e97ee560b793834d1a3f3 Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 21 Jan 2010 19:39:27 +0100 Subject: fixed link deletion --- module/gui/Queue.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'module/gui/Queue.py') diff --git a/module/gui/Queue.py b/module/gui/Queue.py index be2170309..8681d3bb1 100644 --- a/module/gui/Queue.py +++ b/module/gui/Queue.py @@ -298,9 +298,8 @@ class Queue(QObject): return remove.sort() remove.reverse() - parent = self for k in remove: - parent.takeChild(k) + self.takeChild(k) class QueueFile(QTreeWidgetItem): def __init__(self, queue, pack): -- cgit v1.2.3