SF.net SVN: fclient:[738] trunk/fclient/src/fclient/Ui_ViewDownloads.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-07-25 07:14:43
|
Revision: 738
http://fclient.svn.sourceforge.net/fclient/?rev=738&view=rev
Author: jUrner
Date: 2008-07-25 07:14:51 +0000 (Fri, 25 Jul 2008)
Log Message:
-----------
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-25 07:14:19 UTC (rev 737)
+++ trunk/fclient/src/fclient/Ui_ViewDownloads.py 2008-07-25 07:14:51 UTC (rev 738)
@@ -27,6 +27,7 @@
if __name__ == '__main__': # see --> http://bugs.python.org/issue1510172 . works only current dir and below
import os; __path__ = [os.path.dirname(__file__)]
+import os
from PyQt4 import QtCore, QtGui
from . import config
@@ -56,7 +57,7 @@
QtGui.QItemDelegate.__init__(self, parent)
def paint(self, painter, option, index):
- if index.column() != self.parent().HeaderIndexProgressBar:
+ if index.column() != self.parent().HeaderIndexProgress:
return QtGui.QItemDelegate.paint(self, painter, option, index)
application = QtGui.QApplication.instance()
@@ -78,7 +79,10 @@
# Set the progress and text values of the style option.
progressBarOption.progress = progress
- progressBarOption.text = '%s%%' % round(progress * 100 / required, 2)
+ if required:
+ progressBarOption.text = '%s%%' % round(progress * 100 / required, 2)
+ else:
+ progressBarOption.text = '0%'
# Draw the progress bar onto the view.
application.style().drawControl(QtGui.QStyle.CE_ProgressBar, progressBarOption, painter)
@@ -88,10 +92,11 @@
#**********************************************************************************
class TreeItem(QtGui.QTreeWidgetItem):
- def __init__(self, fcpRequest, *params):
+ def __init__(self, fcpIdentifier, *params):
QtGui.QTreeWidgetItem.__init__(self, *params)
- self.fcpRequest = fcpRequest
-
+ self.fcpIdentifier = fcpIdentifier
+
+
#**********************************************************************************
#
#**********************************************************************************
@@ -116,7 +121,7 @@
HeaderIndexName = 0
HeaderIndexFoo = 1
- HeaderIndexProgressBar = 2
+ HeaderIndexProgress = 2
def __init__(self, parent, idGlobalFeedback=config.IdMainWindow):
QtGui.QWidget.__init__(self, parent)
@@ -129,23 +134,28 @@
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.RequestProgress, self.onFcpRequestProgress),
+ (config.fcpClient.events.RequestStarted, self.onFcpRequestStarted),
)
config.fcpClient.events += self.fcpEvents
+ self.fcHeadeLabels = {}
+ self.fcpRequests = {}
+
+ #XXX
+ self.foo = False
- self.fcRequests = Requests()
+
+ def retranslateUi(self, parent):
self.fcHeadeLabels = {
self.HeaderIndexName: self.trUtf8('Name'),
self.HeaderIndexFoo: self.trUtf8('Foo'),
- self.HeaderIndexProgressBar: self.trUtf8('Progress'),
+ self.HeaderIndexProgress: 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()
@@ -154,12 +164,24 @@
config.fcpClient.events -= self.fcpEvents
- def addRequest(self, fcpIdentifier):
- fcpRequest = config.fcpClient.getRequest(fcpIdentifier)
- item= TreeItem(fcpRequest, self.tree)
- self.fcRequests.addRequest(fcpIdentifier, item)
+ def downloadFile(self, fcpKey, fileName, **kws):
+ """"""
+ fileName = unicode(fileName)
+ fcpIdentifier = config.fcpClient.getFile(fcpKey, fileName, **kws)
+ item= TreeItem(fcpIdentifier, self.tree)
+ item.setData(
+ self.HeaderIndexName,
+ QtCore.Qt.DisplayRole,
+ QtCore.QVariant(os.path.basename(fileName))
+ )
+ progressBar = QtGui.QProgressBar(self)
+ progressBar.setRange(0, 0)
+ self.tree.setItemWidget(item, self.HeaderIndexProgress, progressBar)
+ self.fcpRequests[fcpIdentifier] = item
+
+
#########################################
## methods
#########################################
@@ -169,20 +191,62 @@
#########################################
## fcp event handlers
#########################################
- def onFcpConfigData(self, event, msg):
- pass
+ def onFcpConfigData(self, fcpEvent, fcpRequest):
+ if not self.foo:
+ self.foo = True
+
+ return
+ # for testing: dl some frost.zip
+ key = fcp2.Key('CHK@tJ0qyIr8dwvYKoSkmR1N-soABstL0RjgiYqQm3Gtv8g,Pqj7jpPUBzRgnVTaA3fEw6gE8QHcJsTwA4liL9FZ-Fg,AAIC--8/frost-04-Mar-2008.zip')
+ fileName = config.guessFileNameFromKey(key, default=self.trUtf8('Unknown.file'))
+ directory = config.settings.value('DownloadDir')
+ fpath = os.path.join(unicode(directory), unicode(fileName))
+ self.downloadFile(key, fpath)
- def onFcpRequestCompleted(self, event, msg):
+
+ def onFcpRequestCompleted(self, fcpEvent, fcpRequest):
+ item = self.fcpRequests.get(fcpRequest['Identifier'], None)
+ if item is not None:
+ progressBar = self.tree.itemWidget(item, self.HeaderIndexProgress)
+ progressBar.setValue(progressBar.maximum())
+
+ def onFcpRequestFailed(self, fcpEvent, fcpRequest):
pass
- def onFcpRequestProgress(self, event, msg):
- pass
+
+ #TODO: not tested
+ def onFcpRequestModified(self, fcpEvent, fcpRequest):
+ if fcp2.ConstRequestModified.Identifier in fcpRequest['Modified']:
+ newFcpIdentifier = fcpRequest['Identifier']
+ oldFcpIdentifier = fcpRequest['Modified'][fcp2.ConstRequestModified.Identifier]
+ item = self.fcpRequests.get(oldFcpIdentifier, None)
+ if item is not None:
+ del self.fcpRequests[oldFcpIdentifier]
+ self.fcpRequests[newFcpIdentifier] = item
+ item.fcpIdentifier = newFcpIdentifier
+
+ if fcp2.ConstRequestModified.Filename in fcpRequest['Modified']:
+ item = self.fcpRequests.get(fcpRequest['Identifier'], None)
+ if item is not None:
+ item.setData(
+ self.HeaderIndexName,
+ QtCore.Qt.DisplayRole,
+ QtCore.QVariant(os.path.basename(fcpRequest['Filename']))
+ )
+
+
+ def onFcpRequestProgress(self, fcpEvent, fcpRequest):
+ item = self.fcpRequests.get(fcpRequest['Identifier'], None)
+ if item is not None:
+ progressBar = self.tree.itemWidget(item, self.HeaderIndexProgress)
- def onFcpRequestFailed(self, event, msg):
- pass
+ progressBar.setRange(0, fcpRequest['ProgressRequired'])
+ progressBar.setValue(fcpRequest['ProgressSucceeded'])
- def onFcpRequestModified(self, event, msg):
+
+ def onFcpRequestStarted(self, fcpEvent, fcpRequest):
pass
+
#**********************************************************************************
#
@@ -193,8 +257,7 @@
from . import Ui_ViewConnection
from . import Ui_ViewLogger
from . import Ui_MainWindow
-
-
+
app = QtGui.QApplication(sys.argv)
mainWindow = Ui_MainWindow.MainWindow()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|