Simplify/cleanup stylesheets and statusbar
This commit is contained in:
parent
b14070845c
commit
7e3144964e
@ -7,16 +7,31 @@ from PyQt5.QtGui import QValidator, QKeySequence
|
|||||||
|
|
||||||
class StatusBar(QWidget):
|
class StatusBar(QWidget):
|
||||||
"""The statusbar at the bottom of the mainwindow"""
|
"""The statusbar at the bottom of the mainwindow"""
|
||||||
has_error = False # Statusbar is currently in error mode
|
|
||||||
hbox = None
|
hbox = None
|
||||||
cmd = None
|
cmd = None
|
||||||
txt = None
|
txt = None
|
||||||
prog = 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
|
# TODO: the statusbar should be a bit smaller
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.set_color("white", "black")
|
self.setStyleSheet(self._stylesheet.strip().format(self=self))
|
||||||
self.hbox = QHBoxLayout(self)
|
self.hbox = QHBoxLayout(self)
|
||||||
self.hbox.setContentsMargins(0, 0, 0, 0)
|
self.hbox.setContentsMargins(0, 0, 0, 0)
|
||||||
self.hbox.setSpacing(0)
|
self.hbox.setSpacing(0)
|
||||||
@ -30,33 +45,30 @@ class StatusBar(QWidget):
|
|||||||
self.prog = StatusProgress(self)
|
self.prog = StatusProgress(self)
|
||||||
self.hbox.addWidget(self.prog)
|
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):
|
def disp_error(self, text):
|
||||||
"""Displays an error in the statusbar"""
|
"""Displays an error in the statusbar"""
|
||||||
self.has_error = True
|
self.bgcolor = 'red'
|
||||||
self.set_color('white', 'red')
|
|
||||||
self.txt.error = text
|
self.txt.error = text
|
||||||
|
|
||||||
def clear_error(self):
|
def clear_error(self):
|
||||||
"""Clears a displayed error from the status bar"""
|
"""Clears a displayed error from the status bar"""
|
||||||
if self.has_error:
|
self.bgcolor = 'black'
|
||||||
self.has_error = False
|
self.txt.error = ''
|
||||||
self.set_color('white', 'black')
|
|
||||||
self.txt.error = ''
|
|
||||||
|
|
||||||
class StatusProgress(QProgressBar):
|
class StatusProgress(QProgressBar):
|
||||||
""" The progress bar part of the status bar"""
|
""" The progress bar part of the status bar"""
|
||||||
bar = None
|
bar = None
|
||||||
|
_stylesheet = """
|
||||||
|
QProgressBar {
|
||||||
|
border-radius: 0px;
|
||||||
|
border: 2px solid transparent;
|
||||||
|
margin-left: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
QProgressBar::chunk {
|
||||||
|
background-color: white;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, bar):
|
def __init__(self, bar):
|
||||||
self.bar = bar
|
self.bar = bar
|
||||||
@ -64,17 +76,7 @@ class StatusProgress(QProgressBar):
|
|||||||
|
|
||||||
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
|
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
|
||||||
self.setTextVisible(False)
|
self.setTextVisible(False)
|
||||||
self.setStyleSheet("""
|
self.setStyleSheet(self._stylesheet.strip())
|
||||||
QProgressBar {
|
|
||||||
border-radius: 0px;
|
|
||||||
border: 2px solid transparent;
|
|
||||||
margin-left: 1px;
|
|
||||||
}
|
|
||||||
|
|
||||||
QProgressBar::chunk {
|
|
||||||
background-color: white;
|
|
||||||
}
|
|
||||||
""")
|
|
||||||
self.hide()
|
self.hide()
|
||||||
|
|
||||||
def minimumSizeHint(self):
|
def minimumSizeHint(self):
|
||||||
|
@ -3,31 +3,34 @@ from PyQt5.QtCore import Qt
|
|||||||
|
|
||||||
class TabWidget(QTabWidget):
|
class TabWidget(QTabWidget):
|
||||||
"""The tabwidget used for TabbedBrowser"""
|
"""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):
|
def __init__(self, parent):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.setStyleSheet("""
|
self.setStyleSheet(self._stylesheet.strip())
|
||||||
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.setDocumentMode(True)
|
self.setDocumentMode(True)
|
||||||
self.setElideMode(Qt.ElideRight)
|
self.setElideMode(Qt.ElideRight)
|
||||||
|
Loading…
Reference in New Issue
Block a user