View Single Post
Old 09-03-2011, 03:25 PM   #29
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,733
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
Here is a simplified example for you to replicate the issue (showing kind of what I am doing). You can just paste this into your "InterfaceDemo" ui.py file:
Code:
from PyQt4.Qt import QMenu, QToolButton
from calibre.gui2.actions import InterfaceAction

class InterfacePlugin(InterfaceAction):

    name = 'Interface Plugin Demo'

    action_spec = ('Interface Plugin Demo', None,
            'Run the Interface Plugin Demo', None)
    popup_type = QToolButton.MenuButtonPopup
    action_type = 'current'

    def genesis(self):
        icon = get_icons('images/icon.png')
        self.menu = QMenu(self.gui)

        self.rebuild_menu(first_time=True)

        self.qaction.setMenu(self.menu)
        self.qaction.setIcon(icon)

    def rebuild_menu(self, first_time=False):
        m = self.menu
        m.clear()

        shortcut = 'CTRL+7'
        if not first_time:
            shortcut=False
        my_unique_name='Foo'
        ac = self.create_menu_action(m, my_unique_name, 'Foo Menu', None, shortcut)

        if not first_time:
            # Cannot use ac.calibre_shortcut_unique_name because not set when shortcut=False
            my_unique_name = '%s : menu action : %s'%(self.unique_name, my_unique_name)
            self.gui.keyboard.replace_action(my_unique_name, ac)
            self.gui.keyboard.finalize()

    def initialization_complete(self):
        # Simulating menus getting rebuilt
        self.rebuild_menu(first_time=False)
        pass
kiwidude is offline   Reply With Quote