Got the context menu and focusing working.
This commit is contained in:
parent
60dee10d1a
commit
b2aa7ffd8c
4 changed files with 51 additions and 4 deletions
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from .tab_widget import PlaylistTabs
|
||||
from .tab_bar import PlaylistTabBar
|
||||
from .tab_title import TabTitle
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from PyQt6.QtGui import QDragEnterEvent
|
||||
from PyQt6.QtGui import QDragEnterEvent, QContextMenuEvent
|
||||
from PyQt6.QtWidgets import QTabBar
|
||||
|
||||
from .tab_context_menu import PlaylistContextMenu
|
||||
|
||||
|
||||
class PlaylistTabBar(QTabBar):
|
||||
def __init__(self, parent=None):
|
||||
|
@ -11,6 +13,8 @@ class PlaylistTabBar(QTabBar):
|
|||
self.tab_widget = parent
|
||||
self.app = parent.library.app
|
||||
|
||||
self.context_menu = PlaylistContextMenu(self)
|
||||
|
||||
self.setAcceptDrops(True)
|
||||
|
||||
self.tabBarClicked.connect(self.on_click)
|
||||
|
@ -33,3 +37,13 @@ class PlaylistTabBar(QTabBar):
|
|||
|
||||
self.app.player.start_playlist(playlist)
|
||||
|
||||
def contextMenuEvent(self, event: QContextMenuEvent, title=None):
|
||||
if title is None:
|
||||
pos = event.pos()
|
||||
|
||||
index = self.tabAt(pos)
|
||||
title = self.tabButton(index, QTabBar.ButtonPosition.RightSide)
|
||||
print(index)
|
||||
|
||||
self.context_menu.exec(event.globalPos(), title)
|
||||
|
||||
|
|
29
wobuzz/ui/playlist_tabs/tab_context_menu.py
Normal file
29
wobuzz/ui/playlist_tabs/tab_context_menu.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from PyQt6.QtCore import QPoint
|
||||
from PyQt6.QtGui import QAction
|
||||
from PyQt6.QtWidgets import QMenu, QTabBar
|
||||
|
||||
|
||||
class PlaylistContextMenu(QMenu):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
self.tab_bar: QTabBar = parent
|
||||
|
||||
self.playlist_title = None
|
||||
|
||||
self.rename_action = QAction("Rename")
|
||||
|
||||
self.addAction(self.rename_action)
|
||||
|
||||
self.rename_action.triggered.connect(self.rename)
|
||||
|
||||
def exec(self, pos: QPoint, title):
|
||||
self.playlist_title = title
|
||||
|
||||
super().exec(pos)
|
||||
|
||||
def rename(self):
|
||||
self.playlist_title.setFocus()
|
||||
|
|
@ -16,7 +16,9 @@ class TabTitle(QLineEdit):
|
|||
|
||||
self.setStyleSheet("QLineEdit {background: transparent;}")
|
||||
|
||||
self.setFocusPolicy(Qt.FocusPolicy.NoFocus)
|
||||
self.setFocusPolicy(Qt.FocusPolicy.TabFocus)
|
||||
|
||||
self.returnPressed.connect(self.clearFocus)
|
||||
|
||||
def mouseDoubleClickEvent(self, event: QMouseEvent):
|
||||
self.tab_bar.tabBarDoubleClicked.emit(self.index)
|
||||
|
@ -25,3 +27,6 @@ class TabTitle(QLineEdit):
|
|||
self.tab_bar.tabBarClicked.emit(self.index)
|
||||
self.tab_bar.setCurrentIndex(self.index)
|
||||
|
||||
def contextMenuEvent(self, event):
|
||||
self.tab_bar.contextMenuEvent(event, self)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue