1

I am an absolute beginner in QGIS no idea in this field. I just created a Python plugin with pluging builder in QGIS successfully

PYTHON_PLUGINS_PATH/ MyPlugin/ ----------------- inside it contain these files

       ____init__.py  
       mainPlugin.py  
       mainPlugin_dialog.py
       mainPlugin_dialog_base.ui
       plugin_upload.py
       README.txt
       metadata.txt  
       resources.qrc  
       resources.py
       resources_rc.py
       .
       .
       etc

I just want to write some code like print("hello world"). I want to know should I write it inside the mainPlugin.py file If yes then ok, otherwise tell me where should write my code.

After writing my code how can I run It through my plugin which I created in QGIS. I am seeing only my plugin name in QGIS my plugin has no option to import file to take this file mainPlugin.py and run it.

What is the procedure to run my mainPlugin.py file through my plugin inside QGIS?

9
  • I would suggest to start with some tutorials like: docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/…
    – eurojam
    Commented Dec 21, 2018 at 7:27
  • i already read this didn't get what actually i want. Commented Dec 21, 2018 at 15:12
  • 1
    did you try with plugin builder? then add your code in the run method... btw without the code it's impossible to help you. Please create the scheleton of the plugin with plugin builder of using github.com/wonder-sk/qgis-minimal-plugin Commented Dec 21, 2018 at 17:02
  • If you created it with Plugin builder you should also have a mainPlugin_dialog.ui file. That is what you can edit to make a QT user interface - GUI. You should also have a file README.html that will give you some Next Steps.
    – Cary H
    Commented Dec 21, 2018 at 18:40
  • @CaryH i have all these file and i created GUI interface using QT creator which will select a layer and save the output file in my system and its working fine. Commented Dec 21, 2018 at 20:10

2 Answers 2

1

I have a video that covers the v3x plugin deployment process.

https://www.youtube.com/watch?v=NqkP_fCH098

Once you get the plugin created and complied you can add a hello world print statement after the .show() method in the mainPlugin.py file. The normal print statement will not show since the plugin is not directly interacting with the python console so I'd recommend you write to the PyQt5 QMessageBox() method.

0

If you have not already pip install pb_tool Get to the directory with your pb_tool.cfg file. You may have to modify the path: inside the pb_tool.cfg to point to your /plugins directory in QGIS3.4.

Then open your directory with your pb_tool.cfg file from the cmd line and type pb_tool deploy.

If that goes well you should have a new plugin in QGIS that will open a blank dialog.

What's Next From your README.html file - some of this is redundant if you have already ran pb_tool deploy

  1. In your plugin directory, compile the resources file using pyrcc5
    (simply run make if you have automake or use pb_tool)
  2. Test the generated sources using make test (or run tests from your IDE) Copy the entire directory containing your new plugin to the QGIS plugin directory (see Notes below)
  3. Test the plugin by enabling it in the QGIS plugin manager
  4. Customize it by editing the implementation file MainPlugin.py
  5. Modify your user interface by opening MainPlugin.ui in Qt Designer
  6. Create your own custom icon, replacing the default icon.png
2
  • i installed pb_tool & i went to my plugin directory through cmd and typed pb_tool config and i get the pb_tool.cfg file after that i run the command pb_tool deploy and got a new directory inside my python/plugins folder that's good but my question is that i modified my mainPlugin.py file and i write some my own code like print('hello word') now tell me how can i get the output hello world if i run my plugin on QGIS. Commented Dec 21, 2018 at 22:10
  • you should be using QMessagebox. tutorialspoint.com/pyqt/pyqt_qmessagebox.htm
    – Cary H
    Commented Dec 23, 2018 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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