diff --git a/README.asciidoc b/README.asciidoc index e7be9b6b1..f445a9c6f 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -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 diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index 3c646e5cf..dbcead867 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -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) diff --git a/qutebrowser/mainwindow/statusbar/bar.py b/qutebrowser/mainwindow/statusbar/bar.py index 8e07db23c..a1c8aabd0 100644 --- a/qutebrowser/mainwindow/statusbar/bar.py +++ b/qutebrowser/mainwindow/statusbar/bar.py @@ -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. diff --git a/qutebrowser/mainwindow/statusbar/tabindex.py b/qutebrowser/mainwindow/statusbar/tabindex.py new file mode 100644 index 000000000..519f522ed --- /dev/null +++ b/qutebrowser/mainwindow/statusbar/tabindex.py @@ -0,0 +1,34 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2015 Florian Bruhin (The Compiler) +# +# 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 . + +"""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)) diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index 590f0e89a..9d4303735 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -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):