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):
|
class Progress(QProgressBar):
|
||||||
""" The progress bar part of the status bar"""
|
""" The progress bar part of the status bar"""
|
||||||
bar = None
|
bar = None
|
||||||
|
color = 'white'
|
||||||
_stylesheet = """
|
_stylesheet = """
|
||||||
QProgressBar {
|
QProgressBar {{
|
||||||
border-radius: 0px;
|
border-radius: 0px;
|
||||||
border: 2px solid transparent;
|
border: 2px solid transparent;
|
||||||
margin-left: 1px;
|
margin-left: 1px;
|
||||||
}
|
}}
|
||||||
|
|
||||||
QProgressBar::chunk {
|
QProgressBar::chunk {{
|
||||||
background-color: white;
|
background-color: {self.color};
|
||||||
}
|
}}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, bar):
|
def __init__(self, bar):
|
||||||
@ -22,9 +23,15 @@ class Progress(QProgressBar):
|
|||||||
|
|
||||||
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
|
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
|
||||||
self.setTextVisible(False)
|
self.setTextVisible(False)
|
||||||
self.setStyleSheet(self._stylesheet.strip())
|
self.setStyleSheet(self._stylesheet.strip().format(self=self))
|
||||||
self.hide()
|
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):
|
def minimumSizeHint(self):
|
||||||
status_size = self.bar.size()
|
status_size = self.bar.size()
|
||||||
return QSize(100, status_size.height())
|
return QSize(100, status_size.height())
|
||||||
@ -37,11 +44,14 @@ class Progress(QProgressBar):
|
|||||||
# TODO display failed loading in some meaningful way?
|
# TODO display failed loading in some meaningful way?
|
||||||
if prog == 100:
|
if prog == 100:
|
||||||
self.setValue(prog)
|
self.setValue(prog)
|
||||||
self.hide()
|
|
||||||
else:
|
else:
|
||||||
|
if self.color != 'white':
|
||||||
|
self.color = 'white'
|
||||||
self.setValue(prog)
|
self.setValue(prog)
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
def load_finished(self, ok):
|
def load_finished(self, ok):
|
||||||
self.hide()
|
if ok:
|
||||||
|
self.hide()
|
||||||
|
else:
|
||||||
|
self.color = 'red'
|
||||||
|
Loading…
Reference in New Issue
Block a user