Tell me more ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I need to make a separate module to the toolbar(python).

share|improve this question
8  
Please give more details! – Arabella Jun 19 '12 at 6:42
I tried to put a picture, but I have a little reputation. I have a module that can be accessed from the menu> modules, but I need to make this module was on the main toolbar with "file", "Edit", "Type", "Layer", etc. ... – Cathrin Jun 19 '12 at 6:58
If by module you mean plugin, is the plugin one that you are creating or one that you have installed? – dakcarto Jun 19 '12 at 7:18
I installed it and changed the code. For example, the module HelloWorld – Cathrin Jun 19 '12 at 7:30
2  
So you are trying to build a plugin with a button that runs some code? Right? If not we are going to need some code you have tried. – Nathan W Jun 19 '12 at 9:36
show 4 more comments

closed as not a real question by iant, Aragon, Get Spatial, RyanDalton, djq Oct 1 '12 at 21:55

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

1 Answer

Cathrin, using the Plugin Installer install the CadTools plugin.

In the file:

(path to user plugins)/cadtools/cadtools.py

you can use the CadTools class's initGui() method as an example to do this. You will need to instantiate a QMenu then add it to QGIS's menubar. The best position for plugin menus is just before the Help menu (or Window menu on Mac). The 'add to menubar' code in CadTools does not handle the Mac use case, but can be changed to the following to work:

menu_bar = self.iface.mainWindow().menuBar()
actions = menu_bar.actions()
rightmenu_offset = 1
if sys.platform.startswith('darwin'):
    rightmenu_offset = 2
lastAction = actions[len(actions) - rightmenu_offset]
menu_bar.insertMenu(lastAction, self.menu)

self.menu in the above example is the menu that you would have already created.

share|improve this answer
My above answer assumes that when you mentioned 'main toolbar with "file", "Edit", "Type", "Layer", etc. ...' you really meant menubar. BTW: there is no 'Type' menu in QGIS, so I'm still a bit unsure of what you are really asking. – dakcarto Jun 19 '12 at 17:54
Thanks, I'll try. and sorry, I have a Russian version, I just made ​​a wrong translation – Cathrin Jun 20 '12 at 5:31
I installed the CadTools, but I do not understand how to continue to work with him to achieve the desired result – Cathrin Jun 20 '12 at 6:49
Use the code of CadTools plugin as an example for initializing your menubar menu. Once installed, you will see that it creates a menu like you want to do for your plugin. The code to do that is in its initGui() method of the CadTools class in the file noted above. For help on what the initGui() method does study the PyQGIS Cookbook, which is the official documentation for QGIS plugins. – dakcarto Jun 20 '12 at 12:01
I get it. Thank you very much – Cathrin Jun 21 '12 at 5:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.