Clean up autohide and make it work on start.
This commit is contained in:
parent
7721d7b029
commit
c3531de71a
@ -26,7 +26,7 @@ Module attributes:
|
|||||||
|
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSlot, Qt, QSize, QRect, QPoint
|
from PyQt5.QtCore import pyqtSlot, Qt, QSize, QRect, QPoint, QTimer
|
||||||
from PyQt5.QtWidgets import (QTabWidget, QTabBar, QSizePolicy, QCommonStyle,
|
from PyQt5.QtWidgets import (QTabWidget, QTabBar, QSizePolicy, QCommonStyle,
|
||||||
QStyle, QStylePainter, QStyleOptionTab,
|
QStyle, QStylePainter, QStyleOptionTab,
|
||||||
QApplication)
|
QApplication)
|
||||||
@ -108,11 +108,20 @@ class TabBar(QTabBar):
|
|||||||
p = self.palette()
|
p = self.palette()
|
||||||
p.setColor(QPalette.Window, config.get('colors', 'tab.bg.bar'))
|
p.setColor(QPalette.Window, config.get('colors', 'tab.bg.bar'))
|
||||||
self.setPalette(p)
|
self.setPalette(p)
|
||||||
|
QTimer.singleShot(0, self._autohide)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<{} with {} tabs>'.format(self.__class__.__name__,
|
return '<{} with {} tabs>'.format(self.__class__.__name__,
|
||||||
self.count())
|
self.count())
|
||||||
|
|
||||||
|
def _autohide(self):
|
||||||
|
"""Auto-hide the tabbar if needed."""
|
||||||
|
auto_hide = config.get('tabs', 'auto-hide')
|
||||||
|
if auto_hide and self.count() == 1:
|
||||||
|
self.hide()
|
||||||
|
else:
|
||||||
|
self.show()
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
"""Properly repaint the tab bar and relayout tabs."""
|
"""Properly repaint the tab bar and relayout tabs."""
|
||||||
# This is a horrible hack, but we need to do this so the underlaying Qt
|
# This is a horrible hack, but we need to do this so the underlaying Qt
|
||||||
@ -139,11 +148,7 @@ class TabBar(QTabBar):
|
|||||||
p.setColor(QPalette.Window, config.get('colors', 'tab.bg.bar'))
|
p.setColor(QPalette.Window, config.get('colors', 'tab.bg.bar'))
|
||||||
self.setPalette(p)
|
self.setPalette(p)
|
||||||
elif section == 'tabs' and option == 'auto-hide':
|
elif section == 'tabs' and option == 'auto-hide':
|
||||||
hide = config.get('tabs', 'auto-hide')
|
self._autohide()
|
||||||
if hide and self.count() == 1:
|
|
||||||
self.hide()
|
|
||||||
elif not hide:
|
|
||||||
self.show()
|
|
||||||
|
|
||||||
def mousePressEvent(self, e):
|
def mousePressEvent(self, e):
|
||||||
"""Override mousePressEvent to close tabs if configured."""
|
"""Override mousePressEvent to close tabs if configured."""
|
||||||
@ -248,14 +253,12 @@ class TabBar(QTabBar):
|
|||||||
|
|
||||||
def tabInserted(self, idx):
|
def tabInserted(self, idx):
|
||||||
"""Show the tabbar if configured to hide and >1 tab is open."""
|
"""Show the tabbar if configured to hide and >1 tab is open."""
|
||||||
if self.count() > 1 and config.get('tabs', 'auto-hide'):
|
self._autohide()
|
||||||
self.show()
|
|
||||||
super().tabInserted(idx)
|
super().tabInserted(idx)
|
||||||
|
|
||||||
def tabRemoved(self, idx):
|
def tabRemoved(self, idx):
|
||||||
"""Hide the tabbar if configured when only one tab is open."""
|
"""Hide the tabbar if configured when only one tab is open."""
|
||||||
if self.count() <= 1 and config.get('tabs', 'auto-hide'):
|
self._autohide()
|
||||||
self.hide()
|
|
||||||
super().tabRemoved(idx)
|
super().tabRemoved(idx)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user