-
Notifications
You must be signed in to change notification settings - Fork 0
/
tabbar.py
86 lines (69 loc) · 2.54 KB
/
tabbar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from PySide import QtGui, QtCore
class TabBar(QtGui.QTabBar):
loadMd = QtCore.Signal(str)
newTab = QtCore.Signal()
def __init__(self, parent):
super(TabBar, self).__init__()
self.setParent(parent)
self.setAcceptDrops(True)
self.setElideMode(QtCore.Qt.ElideRight)
self.setUsesScrollButtons(True)
self.customContextMenuRequested.connect(self.contextMenuRequested)
self.m_showTabBarWhenOneTab = True
self.m_viewTabBarAction = QtGui.QAction(self)
self.updateViewToolBarAction()
self.setMovable(True)
# Signals
def showTabBarWhenOneTab(self):
return self.m_showTabBarWhenOneTab
def setShowTabBarWhenOneTab(self, enabled):
self.m_showTabBarWhenOneTab = enabled
def viewTabBarAction(self):
return self.m_viewTabBarAction
def freeSide(self):
side = self.style().styleHint(
QtGui.QStyle.SH_TabBar_CloseButtonPosition,
0, self)
if side == QtGui.QTabBar.LeftSide:
return QtGui.QTabBar.RightSide
else:
return QtGui.QTabBar.LeftSide
def updateViewToolBarAction(self):
show = self.showTabBarWhenOneTab()
if(self.count() > 1):
show = True
text = ''
if not show:
text = "Show Tab Bar"
else:
text = "Hide Tab Bar"
self.m_viewTabBarAction.setText(text)
def viewTabBar(self):
self.setShowTabBarWhenOneTab(not self.showTabBarWhenOneTab())
self.updateViewToolBarAction
def selectTabAction(self):
index = self.sender().tab()
self.setCurrentIndex(index)
def tabSizeHint(self, index):
sizeHint = QtGui.QTabBar.tabSizeHint(index)
fm = self.fontMetrics()
return sizeHint.boundedTo(QtGui.QSize(fm.width('M')) * 18,
sizeHint.height())
def cloneTabSlot(self):
action = self.sender()
if self is not None:
index = action.data().toInt()
self.cloneTab.emit(index)
def closeTabSlot(self):
action = self.sender()
if self is not None:
index = action.data().toInt()
self.closeTab.emit(index)
def mouseDoubleClickEvent(self, event):
if event.button() == QtCore.Qt.LeftButton \
and self.tabAt(event.pos()) is -1:
return
super(QtGui.QTabBar, self).mouseDoubleClickEvent
@QtCore.Slot(QtCore.QPoint)
def contextMenuRequested(self, point):
print("context menu requested")