SF.net SVN: fclient:[715] trunk/fclient/src/fclient/Ui_ViewDownloads.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-07-21 11:03:01
|
Revision: 715
http://fclient.svn.sourceforge.net/fclient/?rev=715&view=rev
Author: jUrner
Date: 2008-07-21 11:02:08 +0000 (Mon, 21 Jul 2008)
Log Message:
-----------
haz many changes
Modified Paths:
--------------
trunk/fclient/src/fclient/Ui_ViewDownloads.py
Modified: trunk/fclient/src/fclient/Ui_ViewDownloads.py
===================================================================
--- trunk/fclient/src/fclient/Ui_ViewDownloads.py 2008-07-21 10:59:00 UTC (rev 714)
+++ trunk/fclient/src/fclient/Ui_ViewDownloads.py 2008-07-21 11:02:08 UTC (rev 715)
@@ -18,10 +18,10 @@
# should be enough. maybe along with a separate widget or some separate color code for pendings
#
# x. performance
-# start with a standard model and improve it over time. no need to set any hard
-# limits. the user will find out by himself how many dls his machine can handle.
-# have to be carefrul though when adding dls, like from a *.frdx to provide appropriate
-# warnings
+# start with a standard model and improve it over time. no need to set any hard
+# limits. the user will find out by himself how many dls his machine can handle.
+# have to be carefrul though when adding dls, like from a *.frdx to provide appropriate
+# warnings
#**************************************************************************************************************
from __future__ import absolute_import
if __name__ == '__main__': # see --> http://bugs.python.org/issue1510172 . works only current dir and below
@@ -45,23 +45,79 @@
self.displayName=self.trUtf8('Downloads')
self.icon=QtGui.QIcon()
-
#**********************************************************************************
#
#**********************************************************************************
-class Model(QtGui.QStandardItemModel):
+# from: network/torrent/mainwindow.cpp
+# TorrentViewDelegate is used to draw the progress bars.
+class DownloadTreeDelegate(QtGui.QItemDelegate):
- def __init__(self, parent=None):
- pass
+ def __init__(self, parent):
+ QtGui.QItemDelegate.__init__(self, parent)
+ def paint(self, painter, option, index):
+ if index.column() != self.parent().HeaderIndexProgressBar:
+ return QtGui.QItemDelegate.paint(self, painter, option, index)
+
+ application = QtGui.QApplication.instance()
+ fcpRequest = self.parent().fcRequests.itemFromIndex(index.row()).fcpRequest
+ progress = fcpRequest['ProgressSucceeeded']
+ required = fcpRequest['ProgressRequired']
+
+ # Set up a QprogressbarOptionProgressBar to precisely mimic the
+ # environment of a progress bar.
+ progressBarOption = QtGui.QStyleOptionProgressBar()
+ progressBarOption.state = QtGui.QStyle.State_Enabled
+ progressBarOption.direction = application.layoutDirection()
+ progressBarOption.rect = option.rect
+ progressBarOption.fontMetrics = application.fontMetrics()
+ progressBarOption.minimum = 0
+ progressBarOption.maximum = fcpRequest['ProgressRequired']
+ progressBarOption.textAlignment = QtCore.Qt.AlignCenter
+ progressBarOption.textVisible = True
+
+ # Set the progress and text values of the style option.
+ progressBarOption.progress = progress
+ progressBarOption.text = '%s%%' % round(progress * 100 / required, 2)
+
+ # Draw the progress bar onto the view.
+ application.style().drawControl(QtGui.QStyle.CE_ProgressBar, progressBarOption, painter)
+
#**********************************************************************************
#
#**********************************************************************************
+class TreeItem(QtGui.QTreeWidgetItem):
+
+ def __init__(self, fcpRequest, *params):
+ QtGui.QTreeWidgetItem.__init__(self, *params)
+ self.fcpRequest = fcpRequest
+
+#**********************************************************************************
+#
+#**********************************************************************************
+class Requests(object):
+
+ def __init__(self):
+ self.identifiers = []
+ self.items = []
+
+ def addRequest(self, identifier, item):
+ self.identifiers.append(identifier)
+ self.items.append(item)
+
+ def itemFromIndex(self, index):
+ return self.items[index]
+
+
class ViewDownloadsWidget(QtGui.QWidget, Ui_ViewDownloadsWidget):
- IdTreeView = 'treeView'
+ IdTree = 'tree'
+ HeaderIndexName = 0
+ HeaderIndexFoo = 1
+ HeaderIndexProgressBar = 2
+
def __init__(self, parent, idGlobalFeedback=config.IdMainWindow):
QtGui.QWidget.__init__(self, parent)
self._isCreated = False
@@ -70,17 +126,64 @@
config.ObjectRegistry.register(self)
self.fcViewObject = DownloadsViewObject(self)
+ self.fcpEvents = (
+ (config.fcpClient.events.ConfigData, self.onFcpConfigData),
+ (config.fcpClient.events.RequestCompleted, self.onFcpRequestCompleted),
+ (config.fcpClient.events.RequestProgress, self.onFcpRequestProgress),
+ (config.fcpClient.events.RequestFailed, self.onFcpRequestFailed),
+ (config.fcpClient.events.RequestModified, self.onFcpRequestModified),
+ )
+ config.fcpClient.events += self.fcpEvents
+
+ self.fcRequests = Requests()
+ self.fcHeadeLabels = {
+ self.HeaderIndexName: self.trUtf8('Name'),
+ self.HeaderIndexFoo: self.trUtf8('Foo'),
+ self.HeaderIndexProgressBar: self.trUtf8('Progress'),
+ }
+
+ self.tree.setHeaderLabels([i[1] for i in sorted(self.fcHeadeLabels.items())])
+ self.tree.setItemDelegate(DownloadTreeDelegate(self))
+
+ def closeEvent(self):
+ self.viewClose()
+
+
def viewClose(self):
- pass
+ config.fcpClient.events -= self.fcpEvents
+
+ def addRequest(self, fcpIdentifier):
+ fcpRequest = config.fcpClient.getRequest(fcpIdentifier)
+ item= TreeItem(fcpRequest, self.tree)
+ self.fcRequests.addRequest(fcpIdentifier, item)
+
+
#########################################
## methods
#########################################
def controlById(idGlobalFeedback, idControl):
return getattr(idGlobalFeedback, idControl)
-
+ #########################################
+ ## fcp event handlers
+ #########################################
+ def onFcpConfigData(self, event, msg):
+ pass
+
+ def onFcpRequestCompleted(self, event, msg):
+ pass
+
+ def onFcpRequestProgress(self, event, msg):
+ pass
+
+ def onFcpRequestFailed(self, event, msg):
+ pass
+
+ def onFcpRequestModified(self, event, msg):
+ pass
+
#**********************************************************************************
#
#**********************************************************************************
@@ -89,16 +192,22 @@
from . import Ui_View
from . import Ui_ViewConnection
from . import Ui_ViewLogger
+ from . import Ui_MainWindow
app = QtGui.QApplication(sys.argv)
- w = Ui_View.ViewWidget(None)
- w.addTopViews(
+
+ mainWindow = Ui_MainWindow.MainWindow()
+ viewWidget = Ui_View.ViewWidget(mainWindow)
+ mainWindow.setCentralWidget(viewWidget)
+
+
+ viewWidget.addTopViews(
Ui_ViewConnection.ViewConnectionWidget(None),
ViewDownloadsWidget(None),
)
- w.addBottomViews(Ui_ViewLogger.ViewLoggerWidget(None))
+ viewWidget.addBottomViews(Ui_ViewLogger.ViewLoggerWidget(None))
- w.show()
+ mainWindow.show()
res = app.exec_()
sys.exit(res)
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|