2020-02-23 22:08:20 +01:00
|
|
|
# ============================================================
|
|
|
|
# Tab Counter - plugin for Falkon
|
|
|
|
# Copyright (C) 2020 Juraj Oravec <sgd.orava@gmail.com>
|
|
|
|
#
|
|
|
|
# This program 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.
|
|
|
|
#
|
|
|
|
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# ============================================================
|
|
|
|
|
2020-09-01 01:07:22 +02:00
|
|
|
import Falkon
|
2020-02-29 21:18:13 +01:00
|
|
|
|
2020-02-23 22:08:20 +01:00
|
|
|
from PySide2 import QtWidgets
|
|
|
|
|
2020-02-29 21:18:13 +01:00
|
|
|
from tabcounter.constants import DISPLAY_TYPE
|
2020-09-01 01:07:22 +02:00
|
|
|
from tabcounter.i18n import i18n
|
2020-02-29 21:18:13 +01:00
|
|
|
|
2020-02-23 22:08:20 +01:00
|
|
|
|
2020-02-29 21:18:13 +01:00
|
|
|
class Label(QtWidgets.QLabel):
|
2020-02-23 22:08:20 +01:00
|
|
|
window = None
|
2020-09-01 01:07:22 +02:00
|
|
|
config = None
|
2020-02-29 21:18:13 +01:00
|
|
|
|
2020-02-23 22:08:20 +01:00
|
|
|
allTabs = 0
|
|
|
|
loadedTabs = 0
|
|
|
|
|
2020-09-01 01:07:22 +02:00
|
|
|
def __init__(self, window, config):
|
2020-02-23 22:08:20 +01:00
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
self.window = window
|
2020-09-01 01:07:22 +02:00
|
|
|
self.config = config
|
2020-02-23 22:08:20 +01:00
|
|
|
|
|
|
|
self.setFrameStyle(QtWidgets.QFrame.StyledPanel)
|
|
|
|
|
|
|
|
self.updateText()
|
|
|
|
|
|
|
|
self.window.tabWidget().changed.connect(self.updateText)
|
2020-03-01 14:38:38 +01:00
|
|
|
self.window.tabWidget().tabRemoved.connect(self.updateText)
|
2020-09-01 01:07:22 +02:00
|
|
|
self.config.displayTypeChanged.connect(lambda x: self.updateText())
|
2020-02-23 22:08:20 +01:00
|
|
|
|
|
|
|
def id(self):
|
|
|
|
return "tab-counter-button"
|
|
|
|
|
|
|
|
def name(self):
|
|
|
|
return "Tab Counter"
|
|
|
|
|
|
|
|
def updateText(self):
|
|
|
|
self.ubdateCounts()
|
|
|
|
|
2020-09-01 01:07:22 +02:00
|
|
|
if self.config.displayType == DISPLAY_TYPE.ALL:
|
2020-02-29 21:18:13 +01:00
|
|
|
self.setText("%d" % self.allTabs)
|
2020-09-01 01:07:22 +02:00
|
|
|
elif self.config.displayType == DISPLAY_TYPE.LOADED:
|
2020-02-29 21:18:13 +01:00
|
|
|
self.setText("%d" % self.loadedTabs)
|
2020-09-01 01:07:22 +02:00
|
|
|
elif self.config.displayType == DISPLAY_TYPE.UNLOADED:
|
2020-02-29 21:18:13 +01:00
|
|
|
self.setText("%d" % self.unloadedTabs())
|
2020-09-01 01:07:22 +02:00
|
|
|
elif self.config.displayType == DISPLAY_TYPE.LOADED_AND_ALL:
|
2020-02-29 21:18:13 +01:00
|
|
|
self.setText("%d/%d" % (self.loadedTabs, self.allTabs))
|
|
|
|
else:
|
|
|
|
self.setText("%d/%d" % (self.loadedTabs, self.allTabs))
|
2020-02-23 22:08:20 +01:00
|
|
|
|
|
|
|
def ubdateCounts(self):
|
|
|
|
tabs = self.window.tabWidget().allTabs()
|
|
|
|
|
|
|
|
self.allTabs = len(tabs)
|
|
|
|
self.loadedTabs = 0
|
|
|
|
|
|
|
|
for tab in tabs:
|
|
|
|
if tab.isRestored():
|
|
|
|
self.loadedTabs += 1
|
2020-02-29 21:18:13 +01:00
|
|
|
|
|
|
|
def unloadedTabs(self):
|
|
|
|
return self.allTabs - self.loadedTabs
|
|
|
|
|
2020-09-01 01:07:22 +02:00
|
|
|
def updateToolTip(self):
|
|
|
|
windows_all = 0
|
|
|
|
tabs_all = 0
|
|
|
|
tabs_active = 0
|
|
|
|
|
|
|
|
windows = Falkon.MainApplication.instance().windows()
|
|
|
|
windows_all = len(windows)
|
|
|
|
|
|
|
|
for window in windows:
|
|
|
|
tabs = self.window.tabWidget().allTabs()
|
|
|
|
tabs_all += len(tabs)
|
|
|
|
|
|
|
|
for tab in tabs:
|
|
|
|
if tab.isRestored():
|
|
|
|
tabs_active += 1
|
|
|
|
|
|
|
|
tooltip = """<table>
|
|
|
|
<tr><td>{tr_windows}:</td><td style='text-align:right;'>{windows}</td></tr>
|
|
|
|
<tr><td>{tr_active}:</td><td style='text-align:right;'>{tabs_active}</td></tr>
|
|
|
|
<tr><td>{tr_inactive}:</td><td style='text-align:right;'>{tabs_inactive}</td></tr>
|
|
|
|
<tr><td>{tr_all}:</td><td style='text-align:right;'>{tabs_all}</td></tr>
|
|
|
|
</table>"""
|
|
|
|
|
|
|
|
self.setToolTip(tooltip.format(
|
|
|
|
windows=windows_all,
|
|
|
|
tabs_active=tabs_active,
|
|
|
|
tabs_inactive=(tabs_all - tabs_active),
|
|
|
|
tabs_all=tabs_all,
|
|
|
|
tr_windows=i18n("Windows"),
|
|
|
|
tr_active=i18n("Active"),
|
|
|
|
tr_inactive=i18n("Inactive"),
|
|
|
|
tr_all=i18n("All")
|
|
|
|
))
|
|
|
|
|
|
|
|
def enterEvent(self, event):
|
|
|
|
self.setToolTip("");
|
|
|
|
|
|
|
|
if self.config.enableTooltip:
|
|
|
|
self.updateToolTip()
|
|
|
|
|
|
|
|
super().enterEvent(event)
|