View Single Post
Old 11-15-2014, 12:12 PM   #8
JimmXinu
Plugin Developer
JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.JimmXinu ought to be getting tired of karma fortunes by now.
 
JimmXinu's Avatar
 
Posts: 7,027
Karma: 4604637
Join Date: Dec 2011
Location: Midwest USA
Device: Kobo Clara Colour running KOReader
Cutting to the chase, I removed all the plugin zip files except for my own FFDL from the plugin dir (I assume that will work the same as removing via Prefs and let me put them all back easier).

(Many of the plugins I have installed can't be disabled--including my own. Is there some additional part of the plugin API that needs to be implemented for that? I was able to disable Device, File and Metadata plugins, but not UI plugins.)

FFDL does configure keyboard shortcuts by connecting a button to InterfaceActionBase.actual_plugin_.edit_shortcuts. I assume that part is correct.

My short cuts worked until I changed libraries, then they stopped working. Also if I pull up the FFDL menu--both cases where FFDL rebuilds its menu list. The same function is called when the plugin is first initialized.

FFDL can change its menus depending on library settings. At the end of rebuilding its menus, it spins through all it's menu items unregistering them and then calling self.gui.keyboard.finalize() to re-register the ones that need to be:
Code:
            for menu_id, unique_name in self.old_actions_unique_map.iteritems():
                if menu_id not in self.actions_unique_map:
                    self.gui.keyboard.unregister_shortcut(unique_name)
            self.old_actions_unique_map = self.actions_unique_map
            self.gui.keyboard.finalize()
Commenting that block out keeps the short cuts when menus are rebuilt. But without self.gui.keyboard.finalize(), the shortcuts don't appear (visually) on the menu.

I believe I copied that pattern from one of kiwidude's plugins (like everybody else).

Kovid, can you suggest a better way to handle this case--menus and shortcuts that can change by library/settings? Or a pointer to a place in calibre's code that does it better?

I appreciate any guidance you can give me, thanks.
JimmXinu is online now