Add optional tooltip for toolbar button
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
parent
c4f27426f8
commit
bd61abd5f4
@ -34,7 +34,8 @@ class tabCounter(Falkon.PluginInterface, QtCore.QObject):
|
|||||||
def init(self, state, settingsPath):
|
def init(self, state, settingsPath):
|
||||||
self.config = Config(
|
self.config = Config(
|
||||||
settingsFile=os.path.join(settingsPath, "tabcounter", "settings.ini"),
|
settingsFile=os.path.join(settingsPath, "tabcounter", "settings.ini"),
|
||||||
displayType=DISPLAY_TYPE.LOADED_AND_ALL
|
displayType=DISPLAY_TYPE.LOADED_AND_ALL,
|
||||||
|
enableTooltip=False
|
||||||
)
|
)
|
||||||
self.config.load()
|
self.config.load()
|
||||||
|
|
||||||
@ -61,8 +62,7 @@ class tabCounter(Falkon.PluginInterface, QtCore.QObject):
|
|||||||
|
|
||||||
|
|
||||||
def onMainWindowCreated(self, window):
|
def onMainWindowCreated(self, window):
|
||||||
labelWidget = Label(window, self.config.displayType)
|
labelWidget = Label(window, self.config)
|
||||||
self.config.displayTypeChanged.connect(labelWidget.displayTypeChanged)
|
|
||||||
|
|
||||||
window.navigationBar().addWidget(labelWidget, labelWidget.id(), labelWidget.name())
|
window.navigationBar().addWidget(labelWidget, labelWidget.id(), labelWidget.name())
|
||||||
self.panelWidgets[window] = labelWidget
|
self.panelWidgets[window] = labelWidget
|
||||||
|
@ -23,16 +23,18 @@ from PySide2.QtCore import QObject, Signal, QSettings
|
|||||||
|
|
||||||
class Config(QObject):
|
class Config(QObject):
|
||||||
displayTypeChanged = Signal(int)
|
displayTypeChanged = Signal(int)
|
||||||
|
enableTooltipChanged = Signal(bool)
|
||||||
settingsFileChanged = Signal(str)
|
settingsFileChanged = Signal(str)
|
||||||
|
|
||||||
configLoaded = Signal()
|
configLoaded = Signal()
|
||||||
configSaved = Signal()
|
configSaved = Signal()
|
||||||
|
|
||||||
def __init__(self, displayType=None, settingsFile=None):
|
def __init__(self, displayType=None, settingsFile=None, enableTooltip=None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self._displayType = displayType
|
self._displayType = displayType
|
||||||
self._settingsFile = settingsFile
|
self._settingsFile = settingsFile
|
||||||
|
self._enableTooltip = enableTooltip
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
if not self.settingsFile:
|
if not self.settingsFile:
|
||||||
@ -44,6 +46,7 @@ class Config(QObject):
|
|||||||
|
|
||||||
settings.beginGroup("Config")
|
settings.beginGroup("Config")
|
||||||
self.displayType = int(settings.value("displayType", self.displayType))
|
self.displayType = int(settings.value("displayType", self.displayType))
|
||||||
|
self.enableTooltip = settings.value("enableTooltip", self.enableTooltip) == "true"
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
|
|
||||||
self.configLoaded.emit()
|
self.configLoaded.emit()
|
||||||
@ -58,6 +61,7 @@ class Config(QObject):
|
|||||||
|
|
||||||
settings.beginGroup("Config")
|
settings.beginGroup("Config")
|
||||||
settings.setValue("displayType", self.displayType)
|
settings.setValue("displayType", self.displayType)
|
||||||
|
settings.setValue("enableTooltip", self.enableTooltip)
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
|
|
||||||
settings.sync()
|
settings.sync()
|
||||||
@ -78,6 +82,20 @@ class Config(QObject):
|
|||||||
self._displayType = displayType
|
self._displayType = displayType
|
||||||
self.displayTypeChanged.emit(displayType)
|
self.displayTypeChanged.emit(displayType)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def enableTooltip(self):
|
||||||
|
return self._enableTooltip
|
||||||
|
|
||||||
|
@enableTooltip.setter
|
||||||
|
def enableTooltip(self, enableTooltip):
|
||||||
|
if not isinstance(enableTooltip, bool):
|
||||||
|
return
|
||||||
|
if self._enableTooltip == enableTooltip:
|
||||||
|
return
|
||||||
|
|
||||||
|
self._enableTooltip = enableTooltip
|
||||||
|
self.enableTooltipChanged.emit(enableTooltip)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def settingsFile(self):
|
def settingsFile(self):
|
||||||
return self._settingsFile
|
return self._settingsFile
|
||||||
|
@ -16,24 +16,26 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
|
import Falkon
|
||||||
|
|
||||||
from PySide2 import QtWidgets
|
from PySide2 import QtWidgets
|
||||||
|
|
||||||
from tabcounter.constants import DISPLAY_TYPE
|
from tabcounter.constants import DISPLAY_TYPE
|
||||||
|
from tabcounter.i18n import i18n
|
||||||
|
|
||||||
|
|
||||||
class Label(QtWidgets.QLabel):
|
class Label(QtWidgets.QLabel):
|
||||||
window = None
|
window = None
|
||||||
displayType = None
|
config = None
|
||||||
|
|
||||||
allTabs = 0
|
allTabs = 0
|
||||||
loadedTabs = 0
|
loadedTabs = 0
|
||||||
|
|
||||||
def __init__(self, window, displayType):
|
def __init__(self, window, config):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.window = window
|
self.window = window
|
||||||
self.displayType = displayType
|
self.config = config
|
||||||
|
|
||||||
self.setFrameStyle(QtWidgets.QFrame.StyledPanel)
|
self.setFrameStyle(QtWidgets.QFrame.StyledPanel)
|
||||||
|
|
||||||
@ -41,6 +43,7 @@ class Label(QtWidgets.QLabel):
|
|||||||
|
|
||||||
self.window.tabWidget().changed.connect(self.updateText)
|
self.window.tabWidget().changed.connect(self.updateText)
|
||||||
self.window.tabWidget().tabRemoved.connect(self.updateText)
|
self.window.tabWidget().tabRemoved.connect(self.updateText)
|
||||||
|
self.config.displayTypeChanged.connect(lambda x: self.updateText())
|
||||||
|
|
||||||
def id(self):
|
def id(self):
|
||||||
return "tab-counter-button"
|
return "tab-counter-button"
|
||||||
@ -51,13 +54,13 @@ class Label(QtWidgets.QLabel):
|
|||||||
def updateText(self):
|
def updateText(self):
|
||||||
self.ubdateCounts()
|
self.ubdateCounts()
|
||||||
|
|
||||||
if self.displayType == DISPLAY_TYPE.ALL:
|
if self.config.displayType == DISPLAY_TYPE.ALL:
|
||||||
self.setText("%d" % self.allTabs)
|
self.setText("%d" % self.allTabs)
|
||||||
elif self.displayType == DISPLAY_TYPE.LOADED:
|
elif self.config.displayType == DISPLAY_TYPE.LOADED:
|
||||||
self.setText("%d" % self.loadedTabs)
|
self.setText("%d" % self.loadedTabs)
|
||||||
elif self.displayType == DISPLAY_TYPE.UNLOADED:
|
elif self.config.displayType == DISPLAY_TYPE.UNLOADED:
|
||||||
self.setText("%d" % self.unloadedTabs())
|
self.setText("%d" % self.unloadedTabs())
|
||||||
elif self.displayType == DISPLAY_TYPE.LOADED_AND_ALL:
|
elif self.config.displayType == DISPLAY_TYPE.LOADED_AND_ALL:
|
||||||
self.setText("%d/%d" % (self.loadedTabs, self.allTabs))
|
self.setText("%d/%d" % (self.loadedTabs, self.allTabs))
|
||||||
else:
|
else:
|
||||||
self.setText("%d/%d" % (self.loadedTabs, self.allTabs))
|
self.setText("%d/%d" % (self.loadedTabs, self.allTabs))
|
||||||
@ -75,7 +78,44 @@ class Label(QtWidgets.QLabel):
|
|||||||
def unloadedTabs(self):
|
def unloadedTabs(self):
|
||||||
return self.allTabs - self.loadedTabs
|
return self.allTabs - self.loadedTabs
|
||||||
|
|
||||||
def displayTypeChanged(self, displayType):
|
def updateToolTip(self):
|
||||||
self.displayType = displayType
|
windows_all = 0
|
||||||
|
tabs_all = 0
|
||||||
|
tabs_active = 0
|
||||||
|
|
||||||
self.updateText()
|
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)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>298</width>
|
<width>299</width>
|
||||||
<height>96</height>
|
<height>96</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -49,6 +49,16 @@
|
|||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="enableTooltipLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Enable tooltip</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QCheckBox" name="enableTooltipCheckBox"/>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -43,6 +43,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
|||||||
self.translations()
|
self.translations()
|
||||||
|
|
||||||
self.ui.displayTypeComboBox.setCurrentIndex(self.config.displayType - 1)
|
self.ui.displayTypeComboBox.setCurrentIndex(self.config.displayType - 1)
|
||||||
|
self.ui.enableTooltipCheckBox.setChecked(self.config.enableTooltip)
|
||||||
|
|
||||||
self.ui.buttonBoxConfirm.accepted.connect(self.accept)
|
self.ui.buttonBoxConfirm.accepted.connect(self.accept)
|
||||||
self.ui.buttonBoxConfirm.rejected.connect(self.reject)
|
self.ui.buttonBoxConfirm.rejected.connect(self.reject)
|
||||||
@ -50,9 +51,11 @@ class SettingsDialog(QtWidgets.QDialog):
|
|||||||
def translations(self):
|
def translations(self):
|
||||||
self.setWindowTitle(i18n("Tab Counter Settings"))
|
self.setWindowTitle(i18n("Tab Counter Settings"))
|
||||||
self.ui.displayTypeLabel.setText(i18n("Show count of tabs:"))
|
self.ui.displayTypeLabel.setText(i18n("Show count of tabs:"))
|
||||||
|
self.ui.enableTooltipLabel.setText(i18n("Enable tooltip"))
|
||||||
|
|
||||||
def updateData(self):
|
def updateData(self):
|
||||||
self.config.displayType = self.ui.displayTypeComboBox.currentIndex() + 1
|
self.config.displayType = self.ui.displayTypeComboBox.currentIndex() + 1
|
||||||
|
self.config.enableTooltip = self.ui.enableTooltipCheckBox.isChecked()
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
self.updateData()
|
self.updateData()
|
||||||
|
Loading…
Reference in New Issue
Block a user