def registerDatabaseActions(self, mainWindow): action = QAction(QApplication.translate("DBManagerPlugin", "&Re-connect"), self) mainWindow.registerAction( action, QApplication.translate("DBManagerPlugin", "&Database"), self.reconnectActionSlot ) if self.schemas() is not None: action = QAction(QApplication.translate("DBManagerPlugin", "&Create schema"), self) mainWindow.registerAction( action, QApplication.translate("DBManagerPlugin", "&Schema"), self.createSchemaActionSlot ) action = QAction(QApplication.translate("DBManagerPlugin", "&Delete (empty) schema"), self) mainWindow.registerAction( action, QApplication.translate("DBManagerPlugin", "&Schema"), self.deleteSchemaActionSlot ) action = QAction(QApplication.translate("DBManagerPlugin", "Delete selected item"), self) mainWindow.registerAction( action, None, self.deleteActionSlot ) action.setShortcuts(QKeySequence.Delete) action = QAction(QIcon(":/db_manager/actions/create_table"), QApplication.translate("DBManagerPlugin", "&Create table"), self) mainWindow.registerAction( action, QApplication.translate("DBManagerPlugin", "&Table"), self.createTableActionSlot ) action = QAction(QIcon(":/db_manager/actions/edit_table"), QApplication.translate("DBManagerPlugin", "&Edit table"), self) mainWindow.registerAction( action, QApplication.translate("DBManagerPlugin", "&Table"), self.editTableActionSlot ) action = QAction(QIcon(":/db_manager/actions/del_table"), QApplication.translate("DBManagerPlugin", "&Delete table/view"), self) mainWindow.registerAction( action, QApplication.translate("DBManagerPlugin", "&Table"), self.deleteTableActionSlot ) action = QAction(QApplication.translate("DBManagerPlugin", "&Empty table"), self) mainWindow.registerAction( action, QApplication.translate("DBManagerPlugin", "&Table"), self.emptyTableActionSlot ) if self.schemas() is not None: action = QAction(QApplication.translate("DBManagerPlugin", "&Move to schema"), self) action.setMenu( QMenu(mainWindow) ) invoke_callback = lambda: mainWindow.invokeCallback(self.prepareMenuMoveTableToSchemaActionSlot) QObject.connect( action.menu(), SIGNAL("aboutToShow()"), invoke_callback ) mainWindow.registerAction( action, QApplication.translate("DBManagerPlugin", "&Table") )
def addMenus(self): if self.profilesMenu is not None: self.profilesMenu.clear() self.actions = defaultdict(list) settings = QSettings() defaultProfile = settings.value('profilesplugin/LastProfile', 'Default', unicode) autoLoad = settings.value('profilesplugin/AutoLoad', False, bool) for k, v in profiles.iteritems(): action = QAction(k, self.iface.mainWindow()) action.setCheckable(True) if k == defaultProfile and autoLoad: action.setChecked(True) action.triggered.connect(lambda _, menuName=k: self.applyProfile(menuName)) action.setObjectName('mProfilesPlugin_' + k) self.actions[v.group].append(action) actions = self.iface.mainWindow().menuBar().actions() settingsMenu = None self.profilesGroup = QActionGroup(self.iface.mainWindow()) if self.profilesMenu is None: for action in actions: if action.menu().objectName() == 'mSettingsMenu': settingsMenu = action.menu() self.profilesMenu = QMenu(settingsMenu) self.profilesMenu.setObjectName('mProfilesPlugin') self.profilesMenu.setTitle(self.tr('Profiles')) settingsMenu.addMenu(self.profilesMenu) break if self.profilesMenu is not None: for k,v in self.actions.iteritems(): submenu = QMenu(self.profilesMenu) submenu.setObjectName('mProfilesPlugin_submenu_' + k) submenu.setTitle(k) for action in v: self.profilesGroup.addAction(action) submenu.addAction(action) self.profilesMenu.addMenu(submenu) self.profilesMenu.addSeparator() settings = QSettings() def _setAutoLoad(): settings.setValue('profilesplugin/AutoLoad', self.autoloadAction.isChecked()) self.autoloadAction = QAction(self.tr('Auto-load last profile on QGIS start'), iface.mainWindow()) self.autoloadAction.setCheckable(True) autoLoad = settings.value('profilesplugin/AutoLoad', False, bool) self.autoloadAction.setChecked(autoLoad) self.autoloadAction.setObjectName('mProfilesPluginAutoLoad') self.autoloadAction.triggered.connect(_setAutoLoad) self.profilesMenu.addAction(self.autoloadAction) self.saveProfileAction = QAction(self.tr('Profiles manager...'), self.iface.mainWindow()) self.saveProfileAction.setObjectName('mProfilesPluginProfilesManager') self.saveProfileAction.triggered.connect(self.saveProfile) self.profilesMenu.addAction(self.saveProfileAction) self.showHelpAction = QAction(self.tr('Help'), self.iface.mainWindow()) self.showHelpAction.setIcon(QgsApplication.getThemeIcon('/mActionHelpContents.svg')) self.showHelpAction.setObjectName('mProfilesPluginShowHelp') self.showHelpAction.triggered.connect(self.showHelp) self.profilesMenu.addAction(self.showHelpAction)