From 2f6022cc8b6d0c7c37f61759ec9eb3bf55495d19 Mon Sep 17 00:00:00 2001 From: cosven Date: Tue, 12 Nov 2024 23:25:37 +0800 Subject: [PATCH] close dialog with esc --- feeluown/gui/components/menu.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/feeluown/gui/components/menu.py b/feeluown/gui/components/menu.py index 7582d642e..845514502 100644 --- a/feeluown/gui/components/menu.py +++ b/feeluown/gui/components/menu.py @@ -58,6 +58,8 @@ async def goto_song_album(song): self._app.show_msg('该歌曲没有专辑信息') menu.hovered.connect(self.on_action_hovered) + menu.addAction('搜索相似资源').triggered.connect( + lambda: self.show_similar_resource(song)) artist_menu = menu.addMenu('查看歌手') artist_menu.menuAction().setData({'artists': None, 'song': song}) mv_menu = menu.addMenu(MV_BTN_TEXT) @@ -69,14 +71,19 @@ async def goto_song_album(song): lambda: enter_song_radio(song)) menu.addAction('歌曲详情').triggered.connect( lambda: goto_song_explore(song)) - menu.addAction('搜索相似资源').triggered.connect( - lambda: self.show_similar_resource(song)) def show_similar_resource(self, song): from feeluown.gui.components.search import SearchResultView + class SearchResultViewWithEsc(SearchResultView): + def keyPressEvent(self, event): + if event.key() == Qt.Key_Escape: + self.close() + else: + super().keyPressEvent(event) + q = f'{song.title} {song.artists_name}' - view = SearchResultView(self._app, parent=self._app) + view = SearchResultViewWithEsc(self._app, parent=self._app) source_in = self._app.browser.local_storage.get(KeySourceIn, None) run_afn(view.search_and_render, q, SearchType.so, source_in)