Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

How to add custom menu from inside of plugin

webnull edited this page Dec 10, 2011 · 1 revision

To add custom menu from inside of plugin you need to hook your function to "onGTKWindowOpen" (right after drawing of main gtk window).

Now you can modify Subget main window from hooked function, for example to access menubar you have to use: self.Subget.window.Menubar

Example of plugin:

import subgetcore, gtk

####
PluginInfo = {'Requirements' : { 'OS' : 'All'}, 'API': 2, 'Authors': 'YOU', 'domain': '', 'type': 'extension', 'isPlugin': False}

class PluginMain(subgetcore.SubgetPlugin):

    def _pluginInit(self):
        """ Initialize plugin """

        self.Subget.Hooking.connectHook("onGTKWindowOpen", self._onGTKLoopEnd)

        # check if gtk main window is already initialized
        if "window" in dir(self.Subget):
            self._onGTKLoopEnd(False)

    def _onGTKLoopEnd(self, Data):
        """ Start when GTK window appears """

        myMenu = gtk.Menu()
        self.myMenuItem = gtk.MenuItem("Menu created by plugin")
        self.myMenuItem.set_submenu(myMenu)
        self.Subget.window.Menubar.append(self.myMenuItem)

        # add example element (without icon)
        testPosition = gtk.ImageMenuItem("Test")
        myMenu.append(testPosition)

        self.Subget.window.show_all() # remember to refresh the window, or the changes will not appear

    def _pluginDestroy(self):
        """ Unload plugin """

        self.Subget.window.Menubar.remove(self.myMenuItem) # remember to undo all changes on plugin exit
        del self
Clone this wiki locally