From 7e3144964eab12af9047e6d3b696f194fcf18ad4 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 21 Jan 2014 10:47:22 +0100 Subject: [PATCH] Simplify/cleanup stylesheets and statusbar --- qutebrowser/widgets/statusbar.py | 62 ++++++++++++++++---------------- qutebrowser/widgets/tabbar.py | 51 +++++++++++++------------- 2 files changed, 59 insertions(+), 54 deletions(-) diff --git a/qutebrowser/widgets/statusbar.py b/qutebrowser/widgets/statusbar.py index 2749e61ac..6e60c3f7c 100644 --- a/qutebrowser/widgets/statusbar.py +++ b/qutebrowser/widgets/statusbar.py @@ -7,16 +7,31 @@ from PyQt5.QtGui import QValidator, QKeySequence class StatusBar(QWidget): """The statusbar at the bottom of the mainwindow""" - has_error = False # Statusbar is currently in error mode hbox = None cmd = None txt = None prog = None + fgcolor = 'white' + bgcolor = 'black' + font = 'Monospace, Courier' + _stylesheet = """ + * {{ + background: {self.bgcolor}; + color: {self.fgcolor}; + font-family: {self.font}; + }} + """ + + def __setattr__(self, name, value): + """Update the stylesheet if relevant attributes have been changed""" + super().__setattr__(name, value) + if name in ['fgcolor', 'bgcolor', 'font']: + self.setStyleSheet(self._stylesheet.strip().format(self=self)) # TODO: the statusbar should be a bit smaller def __init__(self, parent): super().__init__(parent) - self.set_color("white", "black") + self.setStyleSheet(self._stylesheet.strip().format(self=self)) self.hbox = QHBoxLayout(self) self.hbox.setContentsMargins(0, 0, 0, 0) self.hbox.setSpacing(0) @@ -30,33 +45,30 @@ class StatusBar(QWidget): self.prog = StatusProgress(self) self.hbox.addWidget(self.prog) - def set_color(self, fg, bg): - """Sets background and foreground color of the statusbar""" - # FIXME maybe this would be easier with setColor()? - - self.setStyleSheet(""" - * { - background: """ + bg + """; - color: """ + fg + """; - font-family: Monospace, Courier; - }""") - def disp_error(self, text): """Displays an error in the statusbar""" - self.has_error = True - self.set_color('white', 'red') + self.bgcolor = 'red' self.txt.error = text def clear_error(self): """Clears a displayed error from the status bar""" - if self.has_error: - self.has_error = False - self.set_color('white', 'black') - self.txt.error = '' + self.bgcolor = 'black' + self.txt.error = '' class StatusProgress(QProgressBar): """ The progress bar part of the status bar""" bar = None + _stylesheet = """ + QProgressBar { + border-radius: 0px; + border: 2px solid transparent; + margin-left: 1px; + } + + QProgressBar::chunk { + background-color: white; + } + """ def __init__(self, bar): self.bar = bar @@ -64,17 +76,7 @@ class StatusProgress(QProgressBar): self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.setTextVisible(False) - self.setStyleSheet(""" - QProgressBar { - border-radius: 0px; - border: 2px solid transparent; - margin-left: 1px; - } - - QProgressBar::chunk { - background-color: white; - } - """) + self.setStyleSheet(self._stylesheet.strip()) self.hide() def minimumSizeHint(self): diff --git a/qutebrowser/widgets/tabbar.py b/qutebrowser/widgets/tabbar.py index 2a3bccec8..541fd9578 100644 --- a/qutebrowser/widgets/tabbar.py +++ b/qutebrowser/widgets/tabbar.py @@ -3,31 +3,34 @@ from PyQt5.QtCore import Qt class TabWidget(QTabWidget): """The tabwidget used for TabbedBrowser""" + + _stylesheet = """ + QTabWidget::pane { + position: absolute; + top: 0px; + } + + QTabBar { + font-family: Monospace, Courier; + font-size: 8pt; + } + + QTabBar::tab { + background-color: grey; + color: white; + padding-left: 5px; + padding-right: 5px; + padding-top: 0px; + padding-bottom: 0px; + } + + QTabBar::tab:selected { + background-color: black; + } + """ + def __init__(self, parent): super().__init__(parent) - self.setStyleSheet(""" - QTabWidget::pane { - position: absolute; - top: 0px; - } - - QTabBar { - font-family: Monospace, Courier; - font-size: 8pt; - } - - QTabBar::tab { - background-color: grey; - color: white; - padding-left: 5px; - padding-right: 5px; - padding-top: 0px; - padding-bottom: 0px; - } - - QTabBar::tab:selected { - background-color: black; - } - """) + self.setStyleSheet(self._stylesheet.strip()) self.setDocumentMode(True) self.setElideMode(Qt.ElideRight)