File: tab_bar.py

package info (click to toggle)
turing 0.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,340 kB
  • sloc: python: 106,582; xml: 101; makefile: 53; sh: 29
file content (29 lines) | stat: -rw-r--r-- 961 bytes parent folder | download | duplicates (4)
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
"""
This module contains the tab bar used in the splittable tab widget.
"""
from pyqode.qt import QtWidgets, QtCore
from pyqode.core.api import DelayJobRunner


class TabBar(QtWidgets.QTabBar):
    """
    Tab bar specialized to allow the user to close a tab using mouse middle
    click. Also exposes a double clicked signal.
    """
    double_clicked = QtCore.Signal()

    def __init__(self, parent):
        QtWidgets.QTabBar.__init__(self, parent)
        self.setTabsClosable(True)
        self._timer = DelayJobRunner(delay=1)

    def mousePressEvent(self, event):
        QtWidgets.QTabBar.mousePressEvent(self, event)
        if event.button() == QtCore.Qt.MiddleButton:
            tab = self.tabAt(event.pos())
            self._timer.request_job(
                self.parentWidget().tabCloseRequested.emit, tab)

    def mouseDoubleClickEvent(self, event):
        if event.button() == QtCore.Qt.LeftButton:
            self.double_clicked.emit()