From 6928a3a0f5d4b6476059e5a3420d36ceefff69a8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 21 Nov 2021 20:39:43 +0530 Subject: [PATCH] Restore the ability to associate menus with actions --- .../gui2/progress_indicator/QProgressIndicator.cpp | 10 ++++++++++ .../gui2/progress_indicator/QProgressIndicator.h | 3 +++ .../gui2/progress_indicator/QProgressIndicator.sip | 2 ++ src/calibre/gui2/pyqt6_compat.py | 11 ++++++++++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/progress_indicator/QProgressIndicator.cpp b/src/calibre/gui2/progress_indicator/QProgressIndicator.cpp index 6d359908d0..66f9da481c 100644 --- a/src/calibre/gui2/progress_indicator/QProgressIndicator.cpp +++ b/src/calibre/gui2/progress_indicator/QProgressIndicator.cpp @@ -431,3 +431,13 @@ void draw_snake_spinner(QPainter &painter, QRect rect, int angle, const QColor & painter.drawArc(drawing_rect, angle * 16, (360 - gap) * 16); painter.restore(); } + +void +set_menu_on_action(QAction* ac, QMenu* menu) { + ac->setMenu(menu); +} + +QMenu* +menu_for_action(QAction *ac) { + return ac->menu(); +} diff --git a/src/calibre/gui2/progress_indicator/QProgressIndicator.h b/src/calibre/gui2/progress_indicator/QProgressIndicator.h index fdb60b2d05..ccef8130b0 100644 --- a/src/calibre/gui2/progress_indicator/QProgressIndicator.h +++ b/src/calibre/gui2/progress_indicator/QProgressIndicator.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -140,3 +141,5 @@ private: int load_style(const QHash &icon_map, int transient_scroller=0); void set_no_activate_on_click(QWidget *widget); void draw_snake_spinner(QPainter &painter, QRect rect, int angle, const QColor & light, const QColor & dark); +void set_menu_on_action(QAction* ac, QMenu* menu); +QMenu* menu_for_action(QAction *ac); diff --git a/src/calibre/gui2/progress_indicator/QProgressIndicator.sip b/src/calibre/gui2/progress_indicator/QProgressIndicator.sip index 8230622e85..93d8096234 100644 --- a/src/calibre/gui2/progress_indicator/QProgressIndicator.sip +++ b/src/calibre/gui2/progress_indicator/QProgressIndicator.sip @@ -86,3 +86,5 @@ int load_style(SIP_PYDICT icon_map_, int transient_scroller); %End void set_no_activate_on_click(QWidget *widget); void draw_snake_spinner(QPainter &painter, QRect rect, int angle, const QColor & light, const QColor & dark) /ReleaseGIL/; +void set_menu_on_action(QAction* ac, QMenu* menu); +QMenu* menu_for_action(QAction *ac); diff --git a/src/calibre/gui2/pyqt6_compat.py b/src/calibre/gui2/pyqt6_compat.py index d8f7fd371a..a9d5615753 100644 --- a/src/calibre/gui2/pyqt6_compat.py +++ b/src/calibre/gui2/pyqt6_compat.py @@ -6,8 +6,12 @@ # for no good reason. Since we have a huge body of poorly maintained third # party plugin code, we NEED backward compat. -from qt.core import QSinglePointEvent, QDialog, QMenu, QDrag, QEventLoop, QThread, QMessageBox +from qt.core import ( + QAction, QDialog, QDrag, QEventLoop, QMenu, QMessageBox, QSinglePointEvent, + QThread +) +from calibre_extensions import progress_indicator # Restore removed functions from QMouseEvent QSinglePointEvent.x = lambda self: int(self.position().x()) @@ -27,3 +31,8 @@ QDrag.exec_ = QDrag.exec QEventLoop.exec_ = QEventLoop.exec QThread.exec_ = QThread.exec QMessageBox.exec_ = QMessageBox.exec + + +# Restore ability to associate a menu with an action +QAction.setMenu = lambda self, menu: progress_indicator.set_menu_on_action(self, menu) +QAction.menu = lambda self, menu: progress_indicator.menu_for_action(self)