How to run QGIS plugin from python script - python

I would like to access external qgis plugins through a python script. I have been able to access the built in qgis processing and vector toolboxs, but have been unsuccessful with external plugins such as the topology checker plugin. I have tried this both using the built in qgis python console, and an exteranl IDE, but attempts have failed.
I am sure that there is a way to do this, has someone done this before?
Thank you!

You could add the qgis plugin folder to your path. That way you should be able to import them as a module.

Have a look at my blog to find a way to load QGIS plugins in a standalone PyQGIS application (in Spanish):
http://geotux.tuxfamily.org/index.php/en/component/k2/item/229-cargando-plugins-de-quantum-gis-en-el-visor-de-pyqgis
There you'll find a QgisInterface class, which you must use to be able to run plugins out of QGIS. This class is now being employed by QGIS devs to run PyQGIS tests.
As you can se, the blog post is very old, so I don't warrant it'll work out of the box, but for sure it's a very good guide for you to accomplish what you want.

Related

Is there a Python function for creating a desktop shortcut?

I just made a little Python project, then used PyInstaller to convert it to a .exe. I want to create a shortcut to the desktop when the user downloads it from an HTML page I made. Any way to do this?
The best way to go about this is to set up a windows installer for your python program. This installer can also be made in python, by the way, this method is fairly unorthodox since you would not make windows style apps with python.
https://python101.pythonlibrary.org/chapter44_creating_an_installer.html
I recommend you take a look at the link above, it gives a good guide on creating an installer for your program as well as how to package it properly.
Hope it Helps :)

How to run Python + Qt application in Squish testing tool?

I am having a trouble with starting testing my Python + Qt4.8 application using Squish.
I am new to that, so if anyone has some experience with using Squish, please read my question.
So I have a couple of Python files which make my application.
The Squish IDE requires an .exe or .bat file in order to start recording. So I successfully generated .exe from all .py files using PyInstaller. When I open the .exe file generated it works fine.
Then I select New Test Suite in Squish I select that .exe I mentioned.
It seems to be fine, but when I try to start recording, Squish cannot open my application. I get an error message like the picture below. I am sure I am using Squish with the right version of Qt. I read about the problem and I found out that it might be because I am using debug version of my application. So do anyone know how can I make my application as non-debug? Or is there any other way to fix this problem? Any help will be really appreciated, thanks.
EDIT: I found the information:
py2exe distributions: Exclude Qt libraries With py2exe on Windows the
Qt libraries must be excluded from the distribution/.exe file.
This is required because Squish for Qt only supports application that
dynamically load the Qt libraries.
But I tried to use py2exe and excluded the libraries. Maybe I am excluding the wrong ones? Does anyone know which exactly libraries should be excluded? Thank you in advance.
#Nela, all Qt libraries included in your packaged application must be excluded (QtCore4.dll, etc.).
If it still does not work please contact froglogic's technical support and provide the support information (Help > Collect Support Information...) directly after reproducing the problem.

Referencing an external library in a Python appengine project, using Pydev/Eclipse

it's a couple of months I've started development in Python - having myself a C# and Java background.
I'm currently working on 2 different python/appengine applications, and as often happens in those cases, both application share common code - so I would like to refactor and move the common/generic code into a shared place.
In either Java or C# I'd just create a new library project, move the code into the new project and add a reference to the library from the main projects.
I tried the same in Python, but I am unable to make it work.
I am using Eclipse with Pydev plugin.
I've created a new Pydev project, moved the code, and attempted to:
reference the library project from the main projects (using Project Properties -> Project References)
add the library src folder folder into the main projects (in this case I have an error - I presume it's not possible to leave the project boundaries when adding an existing source folder)
add as external library (pretty much the same as google libraries are defined, using Properties -> External libraries)
Import as link (from Import -> File System and enabling "Create links in workspace")
In all cases I am able to reference the library code while developing, but when I start debugging, the appengine development server throws an exception because it can't find what I have moved into a separate library project.
Of course I've searched for a solution a lot, but it looks like nobody has experienced the same problem - or maybe nobody doesn't need to do the same :)
The closest solution I've been able to find is to add an ant script to zip the library sources and copy in the target project - but this way debugging is a pain, as I am unable to step into the library code.
Any suggestion?
Needless to say, the proposed solution must take into account that the library code has to be included in the upload process to appengine...
Thanks
The dev_appserver and the production environment don't have any concept of projects or libraries, so you need to structure your app so that all the necessary libraries are under the application's root. The easiest way to do this, usually, is to symlink them in as subdirectories, or worst-case, to copy them (or, using version control, make them sub-repositories).
How that maps to operations in your IDE depends on the IDE, but in general, it's probably easiest to get the app structured as you need it on disk, and work backwards from that to get your IDE set up how you like it.

Roll-out of a python project

I'm looking for some information about the roll-out of a python project that uses several external libraries wrapped for python. Are there tools for this? What kind of external files do I need to use my project on anonther PC? Dlls? .pyd? What else? What to do with user- and pythonpath?
Background: I'm working on a C++ application with some other developers. To learn some python and because of some other reasons, I also build the functionality of this C++ app into a python app that does the same things the way I would like them to work. Several libs are used, QT (via PyQt4), VTK, and some more.
So what would I need to do to use my python program on another computer which the least amout of work for the other computers user?
The answer is highly dependent on what libraries you are using, how they are installed, which platforms you will deploy to etc.
Take a look at
Pip (dependency handling, installation)
Virtualenv (python environment sandboxing)
Fabric (automation)

How do I develop and create a self-contained PyGTK application bundle for MacOS, with native-looking widgets?

I have read that it is possible to build GTK+ on MacOS X. I know that it's possible to create a bundle of a GTK+ application on MacOS. I also know that it's possible to create widgets that look sort of native. However, searching around I am not really clear on how to create a bundle that includes the native theme stuff, and uses Python rather than its own C main-point. There are also rumors that it's possible to build PyGTK, but it sounds like there might still be some wrinkles in that process.
However, there is no step-by-step guide that explains how one can set up an environment where an application might be run from Python source, then built and deployed in an app bundle. How can I go about doing that?
Native looking widgets is quite complicated.
There's a beginning of quartz engine (for theming) found here http://git.gnome.org/browse/gtk+/tree/gdk/quartz
For self-contained applications check out the newly released bundle on http://live.gnome.org/GTK%2B/OSX
I'm not sure if I'm grokking all the details of your question, but looking at your problem in general (how do I deploy a python app on mac), I'm inclined to say that the answer is py2app. Basically this will bundle a python interpreter and all relevant python files for you, and give you a scriptable system that you can use to add in whatever other resources/dependencies you need.
While it's not a guide solely targetted at python/GTK+/OS X, this post is a good, detailed description of someone else's attempt to do most of what you describe. Obviously, the app-specific stuff is going to vary.

Categories

Resources