2014-06-19 09:04:37 +02:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
2015-01-03 15:51:31 +01:00
|
|
|
# Copyright 2014-2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
2014-05-13 07:10:50 +02:00
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
"""The progress bar in the statusbar."""
|
|
|
|
|
2015-04-06 14:27:41 +02:00
|
|
|
from PyQt5.QtCore import pyqtSlot, QSize
|
2014-05-13 07:10:50 +02:00
|
|
|
from PyQt5.QtWidgets import QProgressBar, QSizePolicy
|
|
|
|
|
2014-12-13 17:28:50 +01:00
|
|
|
from qutebrowser.browser import webview
|
2014-08-26 19:10:14 +02:00
|
|
|
from qutebrowser.config import style
|
2014-09-26 15:48:24 +02:00
|
|
|
from qutebrowser.utils import utils
|
2014-05-13 07:10:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Progress(QProgressBar):
|
|
|
|
|
2014-08-28 17:46:56 +02:00
|
|
|
"""The progress bar part of the status bar."""
|
2014-05-13 07:10:50 +02:00
|
|
|
|
|
|
|
# FIXME for some reason, margin-left is not shown
|
2014-10-01 22:23:27 +02:00
|
|
|
# https://github.com/The-Compiler/qutebrowser/issues/125
|
|
|
|
|
2014-05-13 07:10:50 +02:00
|
|
|
STYLESHEET = """
|
2014-08-28 17:47:40 +02:00
|
|
|
QProgressBar {
|
2014-05-13 07:10:50 +02:00
|
|
|
border-radius: 0px;
|
|
|
|
border: 2px solid transparent;
|
|
|
|
margin-left: 1px;
|
|
|
|
background-color: transparent;
|
2014-08-28 17:47:40 +02:00
|
|
|
}
|
2014-05-13 07:10:50 +02:00
|
|
|
|
2014-08-28 17:47:40 +02:00
|
|
|
QProgressBar::chunk {
|
2014-08-28 17:54:11 +02:00
|
|
|
{{ color['statusbar.progress.bg'] }}
|
2014-08-28 17:47:40 +02:00
|
|
|
}
|
2014-05-13 07:10:50 +02:00
|
|
|
"""
|
|
|
|
|
2014-06-17 10:20:15 +02:00
|
|
|
def __init__(self, parent=None):
|
2014-05-13 07:10:50 +02:00
|
|
|
super().__init__(parent)
|
2014-08-26 19:10:14 +02:00
|
|
|
style.set_register_stylesheet(self)
|
2015-04-06 14:27:41 +02:00
|
|
|
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
|
2014-05-13 07:10:50 +02:00
|
|
|
self.setTextVisible(False)
|
|
|
|
self.hide()
|
|
|
|
|
2014-06-17 06:37:56 +02:00
|
|
|
def __repr__(self):
|
2014-09-26 15:48:24 +02:00
|
|
|
return utils.get_repr(self, value=self.value())
|
2014-06-17 06:37:56 +02:00
|
|
|
|
2014-05-13 07:10:50 +02:00
|
|
|
@pyqtSlot()
|
|
|
|
def on_load_started(self):
|
|
|
|
"""Clear old error and show progress, used as slot to loadStarted."""
|
|
|
|
self.setValue(0)
|
|
|
|
self.show()
|
2014-05-15 19:02:20 +02:00
|
|
|
|
|
|
|
@pyqtSlot(int)
|
2014-06-16 22:49:22 +02:00
|
|
|
def on_tab_changed(self, tab):
|
2014-05-15 22:02:43 +02:00
|
|
|
"""Set the correct value when the current tab changed."""
|
2015-08-02 01:49:33 +02:00
|
|
|
if self is None: # pragma: no branch
|
2014-07-06 21:33:50 +02:00
|
|
|
# This should never happen, but for some weird reason it does
|
|
|
|
# sometimes.
|
2015-08-02 01:49:33 +02:00
|
|
|
return # pragma: no cover
|
2014-05-15 19:02:20 +02:00
|
|
|
self.setValue(tab.progress)
|
2014-08-26 19:10:14 +02:00
|
|
|
if tab.load_status == webview.LoadStatus.loading:
|
2014-05-15 19:02:20 +02:00
|
|
|
self.show()
|
|
|
|
else:
|
|
|
|
self.hide()
|
2015-04-06 14:27:41 +02:00
|
|
|
|
|
|
|
def sizeHint(self):
|
2015-08-25 21:18:45 +02:00
|
|
|
"""Set the height to the text height."""
|
2015-04-06 14:27:41 +02:00
|
|
|
width = super().sizeHint().width()
|
2015-08-17 15:22:08 +02:00
|
|
|
height = self.fontMetrics().height()
|
2015-04-06 14:27:41 +02:00
|
|
|
return QSize(width, height)
|
2015-08-17 15:22:08 +02:00
|
|
|
|
|
|
|
def minimumSizeHint(self):
|
|
|
|
return self.sizeHint()
|