PyScripter is a general purpose Python Integrated Development Environment (IDE). Quantum GIS (QGIS) is a desktop GIS application that can be extended with Python plugins. Both are open source softwares. We intend to use PyScripter as an IDE to build QGIS Python plugin.
We are using PyScripter 2.4.1.0 and QGIS 1.6.0 in Windows.
PyScripter does not come with Python. On the other hand, QGIS is built in with Python. Thus, we will setup up PyScripter to use the build in Python in QGIS. We assume both PyScripter and QGIS are already installed.
Preparing PyScripter batch file
We assume that QGIS is installed in C:\OSGeo4W\ folder and PyScripter is installed in C:\Program Files\PyScripter\.
1. Copy qgis.bat in C:\OSGeo4W\bin to pyscripter.bat
2. Edit pyscripter.bat to remove the last line that read something like this
start "Quantum GIS" /B "%OSGEO4W_ROOT%"\apps\qgis\bin\qgis.exe %*
and replace it with this in one line
Start "PyScripter" /B "C:\Program Files\PyScripter\PyScripter.exe" --python25 --pythondllpath=C:\OSGeo4W\bin
Preparing PyScripter for Quantum GIS menu
We can just run pyscripter.bat file to open PyScripter. However, it will be convenient to have a PyScripter for QGIS menu in the Windows Start menu.
1. Click Start->All Programs->PyScripter
2. Right click on "PyScripter (Latest Python Version)" and copy.
3. Right click on "PyScripter" and paste.
4. Right click on "PyScripter (Latest Python Version) - Copy" and rename it to "PyScripter for Quantum GIS".
5. Right click on "PyScripter for Quantum GIS" and select Properties.
6. Change the Target to "C:\OSGeo4W\bin\pyscripter.bat"
Now we can start PyScripter by clicking on Start->All Programs->PyScripter->PyScripter for Quantum GIS.
Using Python from command prompt
QGIS Python command prompt can be accessed via PyScripter. Open the command prompt box from within PyScripter. Click on Tools->Tools->Command Prompt.
Hello
ReplyDeleteI am new to QGIS, Open Source and Python etc, though I have been working with ESRI since the age of floppies.
I have QGIS 1.7.1-Wroclaw installed code Rev e6718b6
I have Python Scripter installed 2.4.3.0
I am trying to learn myPlugin Builder as per your Tutorial. However when I Copy and edit qgis.bat TO -> pyscripter.bat I FIND THE FILE EMPTY. Even the original qgis.bat is also empty. There is no last line like
start "Quantum GIS" /B "%OSGEO4W_ROOT%"\apps\qgis\bin\qgis.exe %*
Kindly help - email is gisproo@gmail.com
Thanks- Jazaak Allah
If you install QGIS using OSGeo4W Installer then the qgis.bat file will initialize OSGeo and QGIS dependencies such as Python, GRASS, GDAL, etc before starting QGIS. We want to do the same before we start PyScripter. The last line in qgis.bat is to start QGIS. We want to replace it with a command to start PyScripter that uses the python interpreter which is built-in with QGIS.
ReplyDeleteIf your qgis.bat is empty then just create an empty pyscripter.bat file and add this command in one line (do not split -- and pythondllpath):
Start "PyScripter" /B "C:\Program Files\PyScripter\PyScripter.exe" --python25 --pythondllpath=C:\OSGeo4W\bin
...assuming that your PyScripter is installed in C:\Program Files\PyScripter\PyScripter.exe and your QGIS Python 2.5 interpreter is installed in C:\OSGeo4W\bin.
Hello Chelahmy
ReplyDeleteThanks for your help, but I am afraid I am far apart in my understanding
I have corrected the pyscripter.bat and when I run this batch file from the E:\Program Files\Quantum GIS Wroclaw\bin
IT OPENS THE PYSCRIPTER
-------------------------------
I have completed Installing Plugin Builder
I have copied my plugin folder to C:\Documents and Settings\123\.qgis\python\plugins
NOW I am not clear how to follow steps 2 - 8 under the heading of
Generating QGIS Python plugin file set
THANKS
Hi gisproo
ReplyDeleteFor step 2 and 3, please refer to Compiling our plugin in Getting Ready for Quantum GIS Plugin Development.
Open the command prompt from within PyScripter - Tools->Tools->Command Prompt. Change directory to your plugin directory in qgis. And execute pyrcc4 and pyuic4 accordingly.
And for step 4, please refer to Testing our plugin.
For step 5 - 8, these are all python and qt programming.
Use python console in qgis to experiment with qgis api.
Hello Chelahmy
ReplyDeleteI have been able to do it, by figuring out my mistakes
I have created 2 plugins and added them
Thanks ... but
How to activate a simple command like
1) " Name of the 1st layer"
2) " open table of 1st layer"
Once again Thanks ... your post is very Good
Hi gisproo
ReplyDeleteI'm glad that you managed to do it.
Qgis api is the reference point.
Here are some api calls to do what you want. Try them in python console on qgis:
Get the first layer:
>>> layer1 = QgsMapLayerRegistry.instance().mapLayers().values()[0]
Get the name of the first layer:
>>> layer1.name()
Make the first layer active:
>>> qgis.utils.iface.setActiveLayer(layer1)
Open attribute table of the active layer:
>>> qgis.utils.iface.actionOpenTable().activate(0)
Thanks Chelahmy
ReplyDeleteI have been able to run the commands; though it took me some time to figure out as to what is "PYTHON CONSOLE" and from where to launch it.
--------------------------------
looking at API itself means deciphering a lot;I am not a professional programmer. About couple of years ago, I used to program a lot in Avenue in ArcGIS 3.x. I hope that with your help I will be able to do it.
---------------------------------
I am thankful for your help
Regards
Thank you for your hints, Chelahmy. Unfortunately, it doesn't work in my case. I've a USB-Stick with both QuantumGIS and Python27 plus PyScripter. The Stick shows two directories: OSGeo4W and PyScripter and i have to handle varying Drive Letters.
ReplyDeleteSo i tried the following: After copying PyScripter.ini from %APPDATA%/PyScripter to "MyStickDrive"\PyScripter, i deleted the first directory.
Then i copied the OSGeo4W-Batch file and made changed it as followed:
#####
@echo on
set DRV_LTR=%~d0
set OSGEO4W_ROOT=%DRV_LTR%\OSGeo4W\
call %OSGEO4W_ROOT%\bin\o4w_env.bat
SET PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python;%OSGEO4W_ROOT%\apps\python27\lib;%OSGEO4W_ROOT%\apps\python27\lib\site-packages;%OSGEO4W_ROOT%\bin;%DRV_LTR%\PyScripter\Lib
SET PATH=%OSGEO4W_ROOT%\bin;%PATH%
SET PYTHONHOME=%OSGEO4W_ROOT%\bin
start "PyScripter" /B %DRV_LTR%\PyScripter\PyScripter.exe --python27 --pythondllpath=%OSGEO4W_ROOT%\bin
#####
Maybe that some entries are unnecessary, they result from a try to use PythonWin as an simple IDE, coming with the OSGeo4W install.