Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 12-03-2016, 04:47 PM   #1
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 27,547
Karma: 193191846
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)
Set the icon (yada, yada)

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)
I then use the "about_to_show_menu" method to build a menu "on-the-fly" based on criteria concerning which book is highlighted in the calibre library.

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.
DiapDealer is offline   Reply With Quote
Old 12-03-2016, 05:30 PM   #2
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 27,547
Karma: 193191846
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.
DiapDealer is offline   Reply With Quote
Old 12-03-2016, 08:26 PM   #3
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
@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)
jackie_w is offline   Reply With Quote
Old 12-03-2016, 10:20 PM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,850
Karma: 22666666
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()
kovidgoyal is offline   Reply With Quote
Old 12-03-2016, 10:21 PM   #5
jhowell
Grand Sorcerer
jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.
 
jhowell's Avatar
 
Posts: 6,496
Karma: 84420419
Join Date: Nov 2011
Location: Tampa Bay, Florida
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
jhowell is offline   Reply With Quote
Old 12-03-2016, 10:21 PM   #6
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 27,547
Karma: 193191846
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.
DiapDealer is offline   Reply With Quote
Old 12-03-2016, 10:36 PM   #7
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,850
Karma: 22666666
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.
kovidgoyal is offline   Reply With Quote
Old 12-03-2016, 10:46 PM   #8
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,850
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
On third thoughts: https://github.com/kovidgoyal/calibr...51b5f936139e55
kovidgoyal is offline   Reply With Quote
Old 12-03-2016, 10:55 PM   #9
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 27,547
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by kovidgoyal View Post
And I thank you for that commit. Works like a charm!
DiapDealer is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 11:43 AM.


MobileRead.com is a privately owned, operated and funded community.