diff options
author | mkaay <mkaay@mkaay.de> | 2011-01-26 03:18:07 +0100 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2011-01-26 03:18:07 +0100 |
commit | e9618b4b1c03f8ed68dc18aa12a23b47b7359c80 (patch) | |
tree | 158e88ec74e7a4f7a9f47c91ded96d34ede29e92 /module | |
parent | added data storage (currently used for plugins), ev0.in rss fetcher, ul.to ma... (diff) | |
download | pyload-e9618b4b1c03f8ed68dc18aa12a23b47b7359c80.tar.xz |
[GUI] added nice overview
Diffstat (limited to 'module')
-rw-r--r-- | module/gui/MainWindow.py | 9 | ||||
-rw-r--r-- | module/gui/Overview.py | 139 | ||||
-rw-r--r-- | module/gui/Queue.py | 3 |
3 files changed, 151 insertions, 0 deletions
diff --git a/module/gui/MainWindow.py b/module/gui/MainWindow.py index a02ea7989..b000f6fc7 100644 --- a/module/gui/MainWindow.py +++ b/module/gui/MainWindow.py @@ -28,6 +28,7 @@ from module.gui.SettingsWidget import SettingsWidget from module.gui.Collector import CollectorView, Package, Link from module.gui.Queue import QueueView +from module.gui.Overview import OverviewView from module.gui.Accounts import AccountView from module.gui.AccountEdit import AccountEdit @@ -125,6 +126,7 @@ class MainWindow(QMainWindow): #tabs self.tabw = QTabWidget() self.tabs = {} + self.tabs["overview"] = {"w":QWidget()} self.tabs["queue"] = {"w":QWidget()} self.tabs["collector"] = {"w":QWidget()} self.tabs["accounts"] = {"w":QWidget()} @@ -134,6 +136,7 @@ class MainWindow(QMainWindow): #self.tabs["settings"]["s"].setWidgetResizable(True) #self.tabs["settings"]["s"].setWidget(self.tabs["settings"]["w"]) self.tabs["log"] = {"w":QWidget()} + self.tabw.addTab(self.tabs["overview"]["w"], _("Overview")) self.tabw.addTab(self.tabs["queue"]["w"], _("Queue")) self.tabw.addTab(self.tabs["collector"]["w"], _("Collector")) self.tabw.addTab(self.tabs["accounts"]["w"], _("Accounts")) @@ -203,6 +206,12 @@ class MainWindow(QMainWindow): """ create tabs """ + #overview + self.tabs["overview"]["l"] = QGridLayout() + self.tabs["overview"]["w"].setLayout(self.tabs["overview"]["l"]) + self.tabs["overview"]["view"] = OverviewView(connector) + self.tabs["overview"]["l"].addWidget(self.tabs["overview"]["view"]) + #queue self.tabs["queue"]["l"] = QGridLayout() self.tabs["queue"]["w"].setLayout(self.tabs["queue"]["l"]) diff --git a/module/gui/Overview.py b/module/gui/Overview.py new file mode 100644 index 000000000..47f3a7421 --- /dev/null +++ b/module/gui/Overview.py @@ -0,0 +1,139 @@ +# -*- 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 <http://www.gnu.org/licenses/>. + + @author: mkaay +""" + +from PyQt4.QtCore import * +from PyQt4.QtGui import * + +from time import sleep, time + +class OverviewModel(QAbstractListModel): + PackageName = 10 + Progress = 11 + PartsFinished = 12 + Parts = 13 + ETA = 14 + Speed = 15 + + def __init__(self, view, connector): + QAbstractListModel.__init__(self) + + self.packages = [] + + def queueChanged(self): #dirty.. + self.beginResetModel() + + self.packages = [] + + def partsFinished(p): + f = 0 + for c in p.children: + if c.data["status"] == 0: + f += 1 + return f + + d = self.queue._data + for p in d: + info = { + OverviewModel.PackageName: p.data["name"], + OverviewModel.Progress: self.queue.getProgress(p), + OverviewModel.PartsFinished: partsFinished(p), + OverviewModel.Parts: len(p.children), + OverviewModel.ETA: "n/a", + OverviewModel.Speed: self.queue.getSpeed(p), + } + + self.packages.append(info) + + self.endResetModel() + + def headerData(self, section, orientation, role=Qt.DisplayRole): + return QVariant(_("Package")) + + def rowCount(self, parent=QModelIndex()): + return len(self.packages) + + def data(self, index, role=Qt.DisplayRole): + if role in [OverviewModel.PackageName, OverviewModel.Progress, OverviewModel.PartsFinished, OverviewModel.Parts, OverviewModel.ETA, OverviewModel.Speed]: + return QVariant(self.packages[index.row()][role]) + return QVariant() + +class OverviewView(QListView): + def __init__(self, connector): + QListView.__init__(self) + self.setModel(OverviewModel(self, connector)) + + self.setAlternatingRowColors(True) + self.delegate = OverviewDelegate(self) + self.setItemDelegate(self.delegate) + +class OverviewDelegate(QItemDelegate): + def __init__(self, parent): + QItemDelegate.__init__(self, parent) + self.parent = parent + self.model = parent.model() + + def paint(self, painter, option, index): + option.rect.setHeight(59+16) + option.rect.setWidth(self.parent.width()) + + #if option.state & QStyle.State_Selected: + # painter.fillRect(option.rect, option.palette.color(QPalette.Highlight)) + + packagename = index.data(OverviewModel.PackageName).toString() + partsf = index.data(OverviewModel.PartsFinished).toString() + parts = index.data(OverviewModel.Parts).toString() + eta = index.data(OverviewModel.ETA).toString() + speed = index.data(OverviewModel.Speed).toString() + progress = int(index.data(OverviewModel.Progress).toString()) + + statusline = QString(_("Parts: %s/%s ETA: %s Speed: %s kb/s" % (partsf, parts, eta, speed))) + + f = painter.font() + f.setPointSize(12) + f.setBold(True) + painter.setFont(f) + + r = option.rect.adjusted(4, 4, -4, -4) + painter.drawText(r.left(), r.top(), r.width(), r.height(), Qt.AlignTop | Qt.AlignLeft, packagename) + newr = painter.boundingRect(r.left(), r.top(), r.width(), r.height(), Qt.AlignTop | Qt.AlignLeft, packagename) + + f.setPointSize(11) + f.setBold(False) + painter.setFont(f) + + painter.drawText(r.left(), newr.bottom()+4, r.width(), r.height(), Qt.AlignTop | Qt.AlignLeft, statusline) + newr = painter.boundingRect(r.left(), newr.bottom()+2, r.width(), r.height(), Qt.AlignTop | Qt.AlignLeft, statusline) + newr.setTop(newr.bottom()+8) + newr.setBottom(newr.top()+20) + newr.setRight(self.parent.width()-5) + + f.setPointSize(10) + painter.setFont(f) + + opts = QStyleOptionProgressBarV2() + opts.maximum = 100 + opts.minimum = 0 + opts.progress = progress + opts.rect = newr + opts.textVisible = True + opts.textAlignment = Qt.AlignCenter + opts.text = QString.number(opts.progress) + "%" + QApplication.style().drawControl(QStyle.CE_ProgressBar, opts, painter) + + def sizeHint(self, option, index): + return QSize(self.parent.width(), 59+16) diff --git a/module/gui/Queue.py b/module/gui/Queue.py index aa1afbd3c..4ac68ca31 100644 --- a/module/gui/Queue.py +++ b/module/gui/Queue.py @@ -76,7 +76,9 @@ class QueueModel(CollectorModel): fileCount = 0 for p in self._data: fileCount += len(p.children) + self.mutex.unlock() self.emit(SIGNAL("updateCount"), packageCount, fileCount) + self.mutex.lock() def update(self): locker = QMutexLocker(self.mutex) @@ -91,6 +93,7 @@ class QueueModel(CollectorModel): child.data["progress"] = child.data["downloading"]["percent"] k = pack.getChildKey(d["id"]) self.emit(SIGNAL("dataChanged(const QModelIndex &, const QModelIndex &)"), self.index(k, 0, self.index(p, 0)), self.index(k, self.cols, self.index(p, self.cols))) + self.updateCount() def headerData(self, section, orientation, role=Qt.DisplayRole): if orientation == Qt.Horizontal and role == Qt.DisplayRole: |