#!/usr/bin/python3 from PyQt6.QtWidgets import QTabWidget, QTabBar from .tab_bar import PlaylistTabBar from .tab_title import TabTitle class PlaylistTabs(QTabWidget): def __init__(self, library, parent=None): super().__init__(parent) self.library = library self.app = library.app self.tab_bar = PlaylistTabBar(self) self.setTabBar(self.tab_bar) self.setDocumentMode(True) self.setMovable(True) self.setAcceptDrops(True) def addTab(self, playlist_view, label) -> int: index = super().addTab(playlist_view, None) title = TabTitle(self.app, label, self.tab_bar, index, playlist_view) self.tab_bar.setTabButton(index, QTabBar.ButtonPosition.RightSide, title) return index def tabRemoved(self, index): # Update indexes because when a playlist is replaced, (and the old playlist widget is deleted by deleteLater()) # the old playlist_widget is actually deleted later than the new one is created. # Because of this, the new playlist tab gets immediately moved one to the left and we have to update the # indexes. self.tab_bar.update_title_indexes(index)