45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
#!/usr/bin/python3
|
|
|
|
from PyQt6.QtCore import QPoint
|
|
from PyQt6.QtGui import QAction
|
|
from PyQt6.QtWidgets import QMenu, QTabBar
|
|
|
|
from .tab_title_editor import TabTitleEditor
|
|
|
|
|
|
class PlaylistContextMenu(QMenu):
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent)
|
|
|
|
self.tab_bar: QTabBar = parent
|
|
|
|
self.tab_index = -1
|
|
self.playlist = None
|
|
|
|
self.title = self.addSection("Playlist Actions")
|
|
|
|
self.rename_action = QAction("Rename")
|
|
self.addAction(self.rename_action)
|
|
|
|
self.delete_action = QAction("Delete")
|
|
self.addAction(self.delete_action)
|
|
|
|
self.rename_action.triggered.connect(self.rename)
|
|
self.delete_action.triggered.connect(self.delete)
|
|
|
|
def exec(self, pos: QPoint, index: int, playlist):
|
|
self.tab_index = index
|
|
self.playlist = playlist
|
|
|
|
self.title.setText(playlist.title)
|
|
|
|
super().exec(pos)
|
|
|
|
def rename(self):
|
|
# create temporary QLineEdit for renaming the tab
|
|
title_editor = TabTitleEditor(self.playlist, self.tab_bar, self.tab_index)
|
|
|
|
self.tab_bar.setTabButton(self.tab_index, QTabBar.ButtonPosition.RightSide, title_editor)
|
|
|
|
def delete(self):
|
|
self.playlist.delete()
|