![]() |
#1 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 28,341
Karma: 203719646
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Stumped by a UI plugin malfunction
Got a plugin that stopped working the way I expect it to on Arch Linux with calibre 2.73. I'm not exactly sure at what version of calibre things might have gone south (and it's frankly driving me a bit nuts), so I'll just get right to the nitty gritty and hope someone can help.
An Interface plugin (it does function for the most part, by the way). In the InterfaceAction class's genesis method, I create a menu and set it as the menu for the plugin's qaction: Code:
self.menu = QMenu() self.qaction.setMenu(self.menu) And then I connect the menu's aboutToShowMenu signal to my "about_to_show_menu" method. Code:
self.menu.aboutToShow.connect(self.about_to_show_menu) So far, so good. The plugin gets installed (to the main toolbar and the library's context menu) and works as expected as long as I use the action/menu on the main toolbar to launch the plugin. Menus get built, actions happen when clicking them. Where it gets weird is that when trying to launch the plugin from the library context menu, the aboutToShow signal never fires. Or rather, the signal is not being connected to my "about_to_show_menu" method. It used to work ... with no change to the plugin's code. Any ideas what's going wonky with the aboutToShow signal and calibre's library context menu? Last edited by DiapDealer; 12-03-2016 at 05:48 PM. |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 28,341
Karma: 203719646
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
It's not just my plugin, anyway. The Favorites Menu plugin behaves the same way: works from the main menu, but not from the library's context menu (on Arch Linux). Right-clicking a library entry after first launching calibre, will result in an empty menu for the plugin.
Seems the last menu built "on the fly" from the main toolbar will persist when next attempting to use the context menu, but the aboutToShow signal is not firing on the context menu. This is not tragic for the Favorites Menu plugin (since once the menu is configured, the menu doesn't really change often). However for my plugin, the last menu built from the main toolbar will often contain actions set to operate on a different book than the one that is currently highlighted. Last edited by DiapDealer; 12-03-2016 at 05:50 PM. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,247
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
|
@DiapDealer,
I'm probably not the best person to answer this but on the off chance it helps ... The first thing that struck me was that the InterfaceAction genesis method in my plugins (originally copied from other plugins) all have QMenu with self.gui as an argument. In addition 'self.menu.aboutToShow' doesn't appear anywhere in my plugins so I'm not sure about that. Code:
def genesis(self):
self.menu = QMenu(self.gui)
self.icons = get_icons([...])
self.rebuild_menu()
self.qaction.setMenu(self.menu)
self.qaction.setIcon(self.icons['images/plugin_icon.png'])
self.qaction.triggered.connect(self.show_dialog)
def rebuild_menu(self):
m = self.menu
m.clear()
ac1 = self.create_action(spec=(...), attr='...')
ac1.setIcon(self.icons['images/plugin_icon.png'])
ac1.triggered.connect(self.show_dialog)
m.addAction(ac1)
m.addSeparator()
ac2 = self.create_action(spec=(...), attr='...')
ac2.triggered.connect(...)
m.addAction(ac2)
|
![]() |
![]() |
![]() |
#4 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,164
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
That's because in linux context menus are cloned, see the clone_menu() function in main_window.py
You can probably fix it by adding aboutToShow to the list of forwarded signals in clone_menu() |
![]() |
![]() |
![]() |
#5 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,015
Karma: 89771379
Join Date: Nov 2011
Location: Charlottesville, VA
Device: Kindles
|
The same issue in Linux was reported for my Overdrive Link plugin by eschwartz in early November. I wasn't able to duplicate the problem under Windows.
https://www.mobileread.com/forums/sho...56#post3422756 |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 28,341
Karma: 203719646
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
I've tried the QMenu generation with and without the self.gui parent parameter with no luck (the original had the parameter), but, good eye!
![]() I'm going to have to fire up some other Linux/Windows machines and make sure the problem's not limited to the one Arch Linux machine. |
![]() |
![]() |
![]() |
#7 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,164
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
On second thoughts forwarding the signal will not work in your case, because it does not pass a reference to the QMenu object, so you will not get access to the cloned menu. You can instead just directly connect to the selection change signal from gui.library_view and modify the menu there rather than in aboutToShow.
|
![]() |
![]() |
![]() |
#8 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,164
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
On third thoughts: https://github.com/kovidgoyal/calibr...51b5f936139e55
|
![]() |
![]() |
![]() |
#9 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 28,341
Karma: 203719646
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Quote:
![]() |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
I'm Stumped.... | 93terp | Amazon Kindle | 19 | 08-04-2016 04:27 PM |
Kindle won't sync and I'm stumped | JimPhelps | Amazon Kindle | 33 | 05-30-2016 04:46 AM |
Computer malfunction, everything has gone! | kevinmacdonald | Library Management | 3 | 08-26-2012 12:30 PM |
Calibre malfunction | mikaelalind | Calibre | 7 | 04-13-2010 01:26 AM |
Stumped | Grauheim | ePub | 5 | 10-21-2009 12:32 PM |