81 lines
2.7 KiB
Python
81 lines
2.7 KiB
Python
"""Widget to show the percentage of the page load in the statusbar."""
|
|
|
|
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
|
#
|
|
# This file is part of qutebrowser.
|
|
#
|
|
# qutebrowser is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# qutebrowser is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import qutebrowser.utils.config as config
|
|
|
|
from PyQt5.QtWidgets import QProgressBar, QSizePolicy
|
|
|
|
|
|
class Progress(QProgressBar):
|
|
"""The progress bar part of the status bar."""
|
|
statusbar = None
|
|
color = None
|
|
_stylesheet = """
|
|
QProgressBar {{
|
|
border-radius: 0px;
|
|
border: 2px solid transparent;
|
|
margin-left: 1px;
|
|
}}
|
|
|
|
QProgressBar::chunk {{
|
|
{color[statusbar.progress.bg.__cur__]}
|
|
}}
|
|
"""
|
|
|
|
def __init__(self, statusbar):
|
|
self.statusbar = statusbar
|
|
super().__init__(statusbar)
|
|
|
|
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Ignored)
|
|
self.setTextVisible(False)
|
|
self.color = config.colordict.getraw('statusbar.progress.bg')
|
|
self.hide()
|
|
|
|
def __setattr__(self, name, value):
|
|
"""Update the stylesheet if relevant attributes have been changed."""
|
|
super().__setattr__(name, value)
|
|
if name == 'color' and value is not None:
|
|
config.colordict['statusbar.progress.bg.__cur__'] = value
|
|
self.setStyleSheet(config.get_stylesheet(self._stylesheet))
|
|
|
|
def set_progress(self, prog):
|
|
"""Set the progress of the bar and show/hide it if necessary."""
|
|
# TODO display failed loading in some meaningful way?
|
|
if prog == 100:
|
|
self.setValue(prog)
|
|
else:
|
|
color = config.colordict.getraw('status.progress.bg')
|
|
if self.color != color:
|
|
self.color = color
|
|
self.setValue(prog)
|
|
self.show()
|
|
|
|
def load_finished(self, ok):
|
|
|
|
"""Hide the progress bar or color it red, depending on ok.
|
|
|
|
Slot for the loadFinished signal of a QWebView.
|
|
"""
|
|
|
|
if ok:
|
|
self.color = config.colordict.getraw('status.progress.bg')
|
|
self.hide()
|
|
else:
|
|
self.color = config.colordict.getraw('statusbar.progress.bg.error')
|