Merge branch 'ff2000-tabindex_in_statusbar'

This commit is contained in:
Florian Bruhin 2015-04-02 11:59:29 +02:00
commit e1cdbd5f16
5 changed files with 58 additions and 3 deletions

View File

@ -157,6 +157,7 @@ Contributors, sorted by the number of commits in descending order:
* Helen Sherwood-Taylor
* HalosGhost
* Gregor Pohl
* Franz Fellner
* Eivind Uggedal
* Andreas Fischer
// QUTE_AUTHORS_END

View File

@ -242,6 +242,8 @@ class MainWindow(QWidget):
tabs.current_tab_changed.connect(status.percentage.on_tab_changed)
tabs.cur_scroll_perc_changed.connect(status.percentage.set_perc)
tabs.tab_index_changed.connect(status.tabindex.on_tab_index_changed)
tabs.current_tab_changed.connect(status.txt.on_tab_changed)
tabs.cur_statusbar_message.connect(status.txt.on_statusbar_message)
tabs.cur_load_started.connect(status.txt.on_load_started)

View File

@ -28,7 +28,8 @@ from PyQt5.QtWidgets import QWidget, QHBoxLayout, QStackedLayout, QSizePolicy
from qutebrowser.config import config, style
from qutebrowser.utils import usertypes, log, objreg, utils
from qutebrowser.mainwindow.statusbar import (command, progress, keystring,
percentage, url, prompt)
percentage, url, prompt,
tabindex)
from qutebrowser.mainwindow.statusbar import text as textwidget
@ -174,6 +175,9 @@ class StatusBar(QWidget):
self.percentage = percentage.Percentage()
self._hbox.addWidget(self.percentage)
self.tabindex = tabindex.TabIndex()
self._hbox.addWidget(self.tabindex)
# We add a parent to Progress here because it calls self.show() based
# on some signals, and if that happens before it's added to the layout,
# it will quickly blink up as independent window.

View File

@ -0,0 +1,34 @@
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2015 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/>.
"""TabIndex displayed in the statusbar."""
from PyQt5.QtCore import pyqtSlot
from qutebrowser.mainwindow.statusbar import textbase
class TabIndex(textbase.TextBase):
"""Shows current tab index and number of tabs in the statusbar."""
@pyqtSlot(int, int)
def on_tab_index_changed(self, current, count):
"""Update tab index when tab changed."""
self.setText('[{}/{}]'.format(current + 1, count))

View File

@ -26,7 +26,7 @@ Module attributes:
import functools
from PyQt5.QtCore import pyqtSlot, Qt, QSize, QRect, QPoint, QTimer
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QSize, QRect, QPoint, QTimer
from PyQt5.QtWidgets import (QTabWidget, QTabBar, QSizePolicy, QCommonStyle,
QStyle, QStylePainter, QStyleOptionTab)
from PyQt5.QtGui import QIcon, QPalette, QColor
@ -41,7 +41,15 @@ PM_TabBarPadding = QStyle.PM_CustomBase
class TabWidget(QTabWidget):
"""The tab widget used for TabbedBrowser."""
"""The tab widget used for TabbedBrowser.
Signals:
tab_index_changed: Emitted when the current tab was changed.
arg 0: The index of the tab which is now focused.
arg 1: The total count of tabs.
"""
tab_index_changed = pyqtSignal(int, int)
def __init__(self, win_id, parent=None):
super().__init__(parent)
@ -50,6 +58,7 @@ class TabWidget(QTabWidget):
bar.tabCloseRequested.connect(self.tabCloseRequested)
bar.tabMoved.connect(functools.partial(
QTimer.singleShot, 0, self.update_tab_titles))
bar.currentChanged.connect(self.emit_tab_index_changed)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.setDocumentMode(True)
self.setElideMode(Qt.ElideRight)
@ -184,6 +193,11 @@ class TabWidget(QTabWidget):
self.set_page_title(new_idx, text)
return new_idx
@pyqtSlot(int)
def emit_tab_index_changed(self, index):
"""Emit the tab_index_changed signal if the current tab changed."""
self.tab_index_changed.emit(index, self.count())
class TabBar(QTabBar):