From 9ac3f51db212293ed9c67b5d8e275458b8a8db5c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 28 Jan 2014 06:59:35 +0100 Subject: [PATCH] Color statusbar red on failed load --- qutebrowser/widgets/statusbar/progress.py | 28 +++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/qutebrowser/widgets/statusbar/progress.py b/qutebrowser/widgets/statusbar/progress.py index d576861ca..3e63b7a13 100644 --- a/qutebrowser/widgets/statusbar/progress.py +++ b/qutebrowser/widgets/statusbar/progress.py @@ -4,16 +4,17 @@ from PyQt5.QtCore import QSize class Progress(QProgressBar): """ The progress bar part of the status bar""" bar = None + color = 'white' _stylesheet = """ - QProgressBar { + QProgressBar {{ border-radius: 0px; border: 2px solid transparent; margin-left: 1px; - } + }} - QProgressBar::chunk { - background-color: white; - } + QProgressBar::chunk {{ + background-color: {self.color}; + }} """ def __init__(self, bar): @@ -22,9 +23,15 @@ class Progress(QProgressBar): self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.setTextVisible(False) - self.setStyleSheet(self._stylesheet.strip()) + self.setStyleSheet(self._stylesheet.strip().format(self=self)) self.hide() + def __setattr__(self, name, value): + """Update the stylesheet if relevant attributes have been changed""" + super().__setattr__(name, value) + if name == 'color': + self.setStyleSheet(self._stylesheet.strip().format(self=self)) + def minimumSizeHint(self): status_size = self.bar.size() return QSize(100, status_size.height()) @@ -37,11 +44,14 @@ class Progress(QProgressBar): # TODO display failed loading in some meaningful way? if prog == 100: self.setValue(prog) - self.hide() else: + if self.color != 'white': + self.color = 'white' self.setValue(prog) self.show() def load_finished(self, ok): - self.hide() - + if ok: + self.hide() + else: + self.color = 'red'