I'm trying to teach myself to make my first QGIS plugin. I used the Plugin Builder to create the base python files, and the plugin seems to work fine when I press the toolbar icon. I'm now trying to allow the user to use a keyboard shortcut to trigger the plugin as if they were pressing the "ok" button in the plugin dialog - assuming the plugin dialog is already open. I've done something wrong and now my menu item is repeated in more than one place and I can't remove them:
I had trouble getting the method described here to work, and only later realized I wasn't unloading correctly, or at all.
My plugin loading in the initGui is certainly wrong, but so is my current unload wrong:
def unload(self): """Removes the plugin menu item and icon from QGIS GUI.""" for action in self.actions: self.iface.removePluginMenu( self.tr(u'&Copy Attributes'), action) self.iface.removePluginMenu( self.tr(u'&Please Copy the Attributes'), action) self.iface.removeToolBarIcon(action) # remove the toolbar del self.toolbar self.iface.unregisterMainWindowAction(self.keyAction)
I've used the Settings -> Configure Shortcuts manager to remove shortcuts, but I have multiple entries there as well. I originally tried to create a shortcut for the plugin by just using the Shortcut Manager, but it didn't work, so that's why I started trying to do it in the initGui.
I'm not sure of the correct method to unload a menu or toolbar item, but will ask this in a different question.
Update: I've managed to figure out how to remove the duplicate menu items. I simply restarted QGIS without the plugin loaded. Then reloaded it from the Plugin Manager. The duplicate menu entries have now disappeared.