WIP to improve info tabs

This commit is contained in:
Keith Edmunds 2023-04-08 18:22:12 +01:00
parent b122ac06a9
commit 3d32ce2f34
4 changed files with 107 additions and 43 deletions

View File

@ -574,6 +574,10 @@ class Window(QMainWindow, Ui_MainWindow):
self.actionRenamePlaylist.triggered.connect(self.rename_playlist)
self.actionResume.triggered.connect(self.resume)
self.actionSave_as_template.triggered.connect(self.save_as_template)
self.actionSearch_title_in_Songfacts.triggered.connect(
lambda: self.tabPlaylist.currentWidget().lookup_row_in_songfacts())
self.actionSearch_title_in_Wikipedia.triggered.connect(
lambda: self.tabPlaylist.currentWidget().lookup_row_in_wikipedia())
self.actionSearch.triggered.connect(self.search_playlist)
self.actionSelect_next_track.triggered.connect(self.select_next_row)
self.actionSelect_previous_track.triggered.connect(

View File

@ -451,6 +451,19 @@ class PlaylistTab(QTableWidget):
# # ########## Externally called functions ##########
def clear_next(self) -> None:
"""
Unmark next track
"""
row_number = self._get_next_track_row_number()
if not row_number:
return
self._set_row_colour_default(row_number)
self.clear_selection()
self.musicmuster.set_next_plr_id(None, self)
def clear_selection(self) -> None:
"""Unselect all tracks and reset drag mode"""
@ -608,6 +621,30 @@ class PlaylistTab(QTableWidget):
self.save_playlist(session)
self._update_start_end_times(session)
def lookup_row_in_songfacts(self) -> None:
"""
If there is a selected row and it is a track row,
look up its title in songfacts.
If multiple rows are selected, only consider the first one.
Otherwise return.
"""
self._look_up_row(website="songfacts")
def lookup_row_in_wikipedia(self) -> None:
"""
If there is a selected row and it is a track row,
look up its title in wikipedia.
If multiple rows are selected, only consider the first one.
Otherwise return.
"""
self._look_up_row(website="wikipedia")
def play_ended(self) -> None:
"""
Called by musicmuster when play has ended.
@ -739,19 +776,6 @@ class PlaylistTab(QTableWidget):
for row in sorted(row_numbers, reverse=True):
self.removeRow(row)
def clear_next(self) -> None:
"""
Unmark next track
"""
row_number = self._get_next_track_row_number()
if not row_number:
return
self._set_row_colour_default(row_number)
self.clear_selection()
self.musicmuster.set_next_plr_id(None, self)
def save_playlist(self, session: scoped_session) -> None:
"""
Get the PlaylistRow objects for each row in the display. Correct
@ -974,11 +998,6 @@ class PlaylistTab(QTableWidget):
# ----------------------
self.menu.addSeparator()
# Look up in songfacts
if track_row:
self._add_context_menu("Songfacts",
lambda: self._songfacts(row_number))
# Remove track from row
if track_row and not current and not next_row:
self._add_context_menu('Remove track from row',
@ -1394,6 +1413,38 @@ class PlaylistTab(QTableWidget):
and pos.y() >= rect.center().y() # noqa W503
)
def _look_up_row(self, website: str) -> None:
"""
If there is a selected row and it is a track row,
look up its title in the passed website
If multiple rows are selected, only consider the first one.
Otherwise return.
"""
selected_row = self._get_selected_row()
if not selected_row:
return
if not self._get_row_track_id(selected_row):
return
title = self._get_row_title(selected_row)
if website == "wikipedia":
QTimer.singleShot(
0,
lambda: self.musicmuster.tabInfolist.open_in_wikipedia(title)
)
elif website == "songfacts":
QTimer.singleShot(
0,
lambda: self.musicmuster.tabInfolist.open_in_songfacts(title)
)
else:
return
def _mark_unplayed(self) -> None:
"""
Mark selected rows as unplayed in this playlist
@ -1690,11 +1741,6 @@ class PlaylistTab(QTableWidget):
self.musicmuster.lblSumPlaytime.setText("")
return
# If only one row is selected and it's a track row, show
# Wikipedia page for that track
if len(selected_rows) == 1:
QTimer.singleShot(0, lambda: self._wikipedia(selected_rows[0]))
ms = 0
for row_number in selected_rows:
ms += self._get_row_duration(row_number)
@ -2113,13 +2159,6 @@ class PlaylistTab(QTableWidget):
return item
def _songfacts(self, row_number: int) -> None:
"""Look up passed row title in songfacts and display info tab"""
title = self._get_row_title(row_number)
self.musicmuster.tabInfolist.open_in_songfacts(title)
def _track_time_between_rows(self, session: scoped_session,
from_plr: PlaylistRows,
to_plr: PlaylistRows) -> int:
@ -2282,12 +2321,3 @@ class PlaylistTab(QTableWidget):
self._get_row_duration(row_number))
self._update_section_headers(session)
def _wikipedia(self, row_number: int) -> None:
"""Look up passed row title in Wikipedia and display info tab"""
title = self._get_row_title(row_number)
if not title:
return
self.musicmuster.tabInfolist.open_in_wikipedia(title)

View File

@ -823,7 +823,7 @@ padding-left: 8px;</string>
<x>0</x>
<y>0</y>
<width>1280</width>
<height>26</height>
<height>29</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -880,6 +880,9 @@ padding-left: 8px;</string>
<addaction name="separator"/>
<addaction name="actionSelect_next_track"/>
<addaction name="actionSelect_previous_track"/>
<addaction name="separator"/>
<addaction name="actionSearch_title_in_Wikipedia"/>
<addaction name="actionSearch_title_in_Songfacts"/>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
@ -958,7 +961,7 @@ padding-left: 8px;</string>
<string>F&amp;ade</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
<string>Ctrl+Z</string>
</property>
</action>
<action name="actionStop">
@ -1205,6 +1208,22 @@ padding-left: 8px;</string>
<string>Ctrl+R</string>
</property>
</action>
<action name="actionSearch_title_in_Wikipedia">
<property name="text">
<string>Search title in Wikipedia</string>
</property>
<property name="shortcut">
<string>Ctrl+W</string>
</property>
</action>
<action name="actionSearch_title_in_Songfacts">
<property name="text">
<string>Search title in Songfacts</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -381,7 +381,7 @@ class Ui_MainWindow(object):
self.gridLayout_4.addWidget(self.cartsWidget, 2, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1280, 26))
self.menubar.setGeometry(QtCore.QRect(0, 0, 1280, 29))
self.menubar.setObjectName("menubar")
self.menuFile = QtWidgets.QMenu(self.menubar)
self.menuFile.setObjectName("menuFile")
@ -505,6 +505,10 @@ class Ui_MainWindow(object):
self.actionPaste.setObjectName("actionPaste")
self.actionResume = QtWidgets.QAction(MainWindow)
self.actionResume.setObjectName("actionResume")
self.actionSearch_title_in_Wikipedia = QtWidgets.QAction(MainWindow)
self.actionSearch_title_in_Wikipedia.setObjectName("actionSearch_title_in_Wikipedia")
self.actionSearch_title_in_Songfacts = QtWidgets.QAction(MainWindow)
self.actionSearch_title_in_Songfacts.setObjectName("actionSearch_title_in_Songfacts")
self.menuFile.addAction(self.actionNewPlaylist)
self.menuFile.addAction(self.actionNew_from_template)
self.menuFile.addAction(self.actionOpenPlaylist)
@ -545,6 +549,9 @@ class Ui_MainWindow(object):
self.menuSearc_h.addSeparator()
self.menuSearc_h.addAction(self.actionSelect_next_track)
self.menuSearc_h.addAction(self.actionSelect_previous_track)
self.menuSearc_h.addSeparator()
self.menuSearc_h.addAction(self.actionSearch_title_in_Wikipedia)
self.menuSearc_h.addAction(self.actionSearch_title_in_Songfacts)
self.menuHelp.addAction(self.action_About)
self.menuHelp.addAction(self.actionDebug)
self.menubar.addAction(self.menuFile.menuAction())
@ -598,7 +605,7 @@ class Ui_MainWindow(object):
self.actionAdd_file.setText(_translate("MainWindow", "Add &file"))
self.actionAdd_file.setShortcut(_translate("MainWindow", "Ctrl+F"))
self.actionFade.setText(_translate("MainWindow", "F&ade"))
self.actionFade.setShortcut(_translate("MainWindow", "Ctrl+S"))
self.actionFade.setShortcut(_translate("MainWindow", "Ctrl+Z"))
self.actionStop.setText(_translate("MainWindow", "S&top"))
self.actionStop.setShortcut(_translate("MainWindow", "Ctrl+Alt+S"))
self.action_Clear_selection.setText(_translate("MainWindow", "Clear &selection"))
@ -650,5 +657,9 @@ class Ui_MainWindow(object):
self.actionPaste.setShortcut(_translate("MainWindow", "Ctrl+V"))
self.actionResume.setText(_translate("MainWindow", "Resume"))
self.actionResume.setShortcut(_translate("MainWindow", "Ctrl+R"))
self.actionSearch_title_in_Wikipedia.setText(_translate("MainWindow", "Search title in Wikipedia"))
self.actionSearch_title_in_Wikipedia.setShortcut(_translate("MainWindow", "Ctrl+W"))
self.actionSearch_title_in_Songfacts.setText(_translate("MainWindow", "Search title in Songfacts"))
self.actionSearch_title_in_Songfacts.setShortcut(_translate("MainWindow", "Ctrl+S"))
from infotabs import InfoTabs
import icons_rc