File: MyTabBrowser.py

package info (click to toggle)
kuttypy 2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,896 kB
  • sloc: python: 58,651; javascript: 14,686; xml: 5,767; ansic: 2,716; makefile: 453; asm: 254; sh: 48
file content (34 lines) | stat: -rw-r--r-- 1,264 bytes parent folder | download | duplicates (2)
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
from PyQt5.QtGui import QKeySequence
from PyQt5.QtWidgets import QTabWidget, QShortcut

from utilities import Qt


class MyTabBrowser(QTabWidget):
    def __init__(self):
        super().__init__()
        # Set up shortcuts for Ctrl+Left and Ctrl+Right
        self.prev_tab_shortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_Left), self)
        self.next_tab_shortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_Right), self)

        # Connect shortcuts to navigation functions
        self.prev_tab_shortcut.activated.connect(self.showPreviousTab)
        self.next_tab_shortcut.activated.connect(self.showNextTab)

    def keyPressEvent(self, event):
        # Override the keyPressEvent to prevent default handling of Ctrl+Tab
        if event.key() == Qt.Key_Tab and event.modifiers() == Qt.ControlModifier:
            return

        # Call the base class implementation for other key events
        super().keyPressEvent(event)

    def showPreviousTab(self):
        current_index = self.currentIndex()
        if current_index > 0:
            self.setCurrentIndex(current_index - 1)

    def showNextTab(self):
        current_index = self.currentIndex()
        if current_index < self.count() - 1:
            self.setCurrentIndex(current_index + 1)