# ============================================================ # Tab Counter - plugin for Falkon # Copyright (C) 2020 Juraj Oravec # # 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 . # ============================================================ from PySide2 import QtWidgets from tabcounter.constants import DISPLAY_TYPE class Label(QtWidgets.QLabel): window = None displayType = None allTabs = 0 loadedTabs = 0 def __init__(self, window, displayType): super().__init__() self.window = window self.displayType = displayType self.setFrameStyle(QtWidgets.QFrame.StyledPanel) self.updateText() self.window.tabWidget().changed.connect(self.updateText) self.window.tabWidget().tabRemoved.connect(self.updateText) def id(self): return "tab-counter-button" def name(self): return "Tab Counter" def updateText(self): self.ubdateCounts() if self.displayType == DISPLAY_TYPE.ALL: self.setText("%d" % self.allTabs) elif self.displayType == DISPLAY_TYPE.LOADED: self.setText("%d" % self.loadedTabs) elif self.displayType == DISPLAY_TYPE.UNLOADED: self.setText("%d" % self.unloadedTabs()) elif self.displayType == DISPLAY_TYPE.LOADED_AND_ALL: self.setText("%d/%d" % (self.loadedTabs, self.allTabs)) else: self.setText("%d/%d" % (self.loadedTabs, self.allTabs)) 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 def unloadedTabs(self): return self.allTabs - self.loadedTabs def displayTypeChanged(self, displayType): self.displayType = displayType self.updateText()