The keyboard shortcut plugin upgrade mission slowly continues. So far I have managed to upgrade eight plugins which are all the non dynamic menus based ones (the "easy" cases), and that is all working fine.
However on my way to attempting a dynamic menu, I tried to start with Quality Check. In this plugin, it is possible for the users to decide which menu items will appear on the menu. So to do things "properly" I need to cover for the situation where a user assigns a keyboard shortcut to a menu item, and then chooses to "hide" that menu item without them removing their shortcut first.
So in this situation, I thought it might be as "simple" as calling gui.keyboard.unregister_shortcut for each menu item that the user is hiding when they click ok on the configuration dialog. That part of the code I have working, though it is a little messy as you can see below from this extract:
Code:
kb = self.plugin_action.gui.keyboard
# Need to manually construct the menu name because at this point I have
# no action at all as I am not creating them
unique_name = '%s : menu action : %s'%(self.plugin_action.unique_name, menu_key)
# Have to check for existence (same applies to replace_action call)
if unique_name in kb.shortcuts:
kb.unregister_shortcut(unique_name)
This works ok, however then when I try to go into Preferences->Keyboard, I always get this error:
Code:
calibre, version 0.8.17
ERROR: Unhandled exception: <b>KeyError</b>:u'Interface Action: Quality Check (Quality Check) : menu action : check_covers'
Traceback (most recent call last):
File "D:\CalibreDev\latest\calibre\src\calibre\gui2\preferences\main.py", line 282, in show_plugin
File "D:\CalibreDev\latest\calibre\src\calibre\gui2\preferences\keyboard.py", line 27, in initialize
File "D:\CalibreDev\latest\calibre\src\calibre\gui2\keyboard.py", line 615, in initialize
File "D:\CalibreDev\latest\calibre\src\calibre\gui2\keyboard.py", line 179, in __init__
File "D:\CalibreDev\latest\calibre\src\calibre\gui2\keyboard.py", line 178, in <dictcomp>
File "D:\CalibreDev\latest\calibre\src\calibre\gui2\keyboard.py", line 178, in <lambda>
KeyError: u'Interface Action: Quality Check (Quality Check) : menu action : check_covers'
Where check_covers is the unique_name I associated with the menu that I have called unregister_shortcut() method with a few moments before.
Now for this particular plugin I could just store the actions in a dictionary, creating them only once etc. However I believe the error I see is going to come up for plugins where that is not an option, so better to figure it all out now...