Color statusbar red on failed load
This commit is contained in:
parent
b83bf4e238
commit
9ac3f51db2
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user