Graphics Reference
In-Depth Information
We're simply importing the various libraries we'll need and setting up an external PyQGIS
application using the techniques we learned earlier. We then create and display a blank
window so that the application will do something when it starts up.
Since we want the Lex application to work on any operating system, we're not going to
hard-wire the path to QGIS into our source code. Instead, we'll write a wrapper script
that sets up the required environment variables before launching our Python program. As
these wrapper scripts are operating-system dependent, you will need to create an appropri-
ate wrapper script for your operating system.
Note
Notice that we use os.environ['QGIS_PREFIX'] in our lex.py module to avoid
hard-wiring the path to the QGIS application into our source code. Our wrapper script will
take care of setting this environment variable before the application is run.
If you are using a computer with Microsoft Windows, your wrapper script will look
something like the following:
SET OSGEO4W_ROOT=C:\OSGeo4W
SET QGIS_PREFIX=%OSGEO4W_ROOT%\apps\qgis
SET PATH=%QGIS_PREFIX%\bin;%OSGWO4W_ROOT\bin;%PATH%
SET
PYTHONPATH=%QGIS_PREFIX%\python;%OSEO4W_ROOT%\apps\Python27;%PYTHONPATH%
SET PYTHONHOME=%OSGEO4W_ROOT%\apps\Python27
python lex.py
Name this script something sensible, for example, run.bat , and put it in the same dir-
ectory as your lex.py module.
If you are using a computer that runs Linux, your wrapper script will be named something
like run.sh , and will look like the following:
export PYTHONPATH="/path/to/qgis/build/output/python/"
export LD_LIBRARY_PATH="/path/to/qgis/build/output/lib/"
export QGIS_PREFIX="/path/to/qgis/build/output/"
python lex.py
You will need to modify the paths to refer to the directory where QGIS has been installed.
Search WWH ::




Custom Search