diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index 1db71f935..6140ebc3d 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -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) diff --git a/qutebrowser/models/downloadmodel.py b/qutebrowser/models/downloadmodel.py index 29fcef5e8..18fae8748 100644 --- a/qutebrowser/models/downloadmodel.py +++ b/qutebrowser/models/downloadmodel.py @@ -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 diff --git a/qutebrowser/widgets/downloads.py b/qutebrowser/widgets/downloads.py index 23ca51879..61cb4765f 100644 --- a/qutebrowser/widgets/downloads.py +++ b/qutebrowser/widgets/downloads.py @@ -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)