Add missing docstrings

This commit is contained in:
Florian Bruhin 2014-06-12 17:56:28 +02:00
parent ad7856569f
commit 3c2c08f73a
3 changed files with 17 additions and 0 deletions

View File

@ -303,6 +303,7 @@ class DownloadManager(QObject):
@pyqtSlot()
def on_finished(self):
"""Remove finished download."""
idx = self.downloads.index(self.sender())
self.download_about_to_be_finished.emit(idx)
del self.downloads[idx]
@ -310,9 +311,11 @@ class DownloadManager(QObject):
@pyqtSlot()
def on_data_changed(self):
"""Emit data_changed signal when download data changed."""
idx = self.downloads.index(self.sender())
self.data_changed.emit(idx)
@pyqtSlot(str)
def on_error(self, msg):
"""Display error message on download errors."""
message.error("Download error: {}".format(msg), queue=True)

View File

@ -24,6 +24,12 @@ from PyQt5.QtWidgets import QApplication
class DownloadModel(QAbstractListModel):
"""Glue model to show downloads in a QListView.
Glue between qutebrowser.browser.download (DownloadManager) and
qutebrowser.widgets.download (DownloadView).
"""
def __init__(self, parent=None):
super().__init__(parent)
self.downloadmanager = QApplication.instance().downloadmanager
@ -37,10 +43,12 @@ class DownloadModel(QAbstractListModel):
@pyqtSlot(int)
def on_data_changed(self, idx):
"""Update view when DownloadManager data changed."""
model_idx = self.index(idx, 0)
self.dataChanged.emit(model_idx, model_idx)
def headerData(self, section, orientation, role):
"""Simple constant header."""
if (section == 0 and orientation == Qt.Horizontal and
role == Qt.DisplayRole):
return "Downloads"
@ -48,6 +56,7 @@ class DownloadModel(QAbstractListModel):
return ""
def data(self, index, role):
"""Download data from DownloadManager."""
if not index.isValid():
return QVariant()
elif role != Qt.DisplayRole:
@ -65,6 +74,7 @@ class DownloadModel(QAbstractListModel):
return str(round(perc)) # FIXME
def rowCount(self, parent):
"""Get count of active downloads."""
if parent.isValid():
# We don't have children
return 0

View File

@ -25,6 +25,8 @@ from qutebrowser.models.downloadmodel import DownloadModel
class DownloadView(QListView):
"""QListView which shows currently running downloads as a bar."""
def __init__(self, parent=None):
super().__init__(parent)
self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
@ -36,9 +38,11 @@ class DownloadView(QListView):
self.setWrapping(True)
def minimumSizeHint(self):
"""Override minimumSizeHint so the size is correct in a layout."""
return self.sizeHint()
def sizeHint(self):
"""Return sizeHint based on the view contents."""
height = self.sizeHintForRow(0)
if height != -1:
return QSize(0, height + 2)