[Qgis-developer] Python support in project file

Giuseppe Sucameli brush.tyler at gmail.com
Wed May 23 17:02:42 PDT 2012

Hi Victor,

On Wed, May 23, 2012 at 9:35 PM, Victor Olaya <volayaf at gmail.com> wrote:
> it woould be solved if I could add a script to be
> executed when saving a project, so it can check that layers are not
> temporary (and if they are, save them to a permanent location).

what you need is just a signal sent when the project is saved, like the
projectRead() signal available through the qgis iface, although there's
no way to update the URI of a loaded layer.

What I'm working on is a way to define user routines.

> Even, the algorithms used to generate a given layer could be stored in
> the project file, so if a layer is missing, it could be recomputed if
> the input ones are available.

Good idea!, but you have to get bad (missing) layers, so while
the project is loading, not after.
When the project is loaded you've already lost bad layers.

There's a setBadLayerHandler in QgsProject, but I suppose if you
create a new handler in the python code it doesn't work due to the
current "asymmetric bindings" (python code can access C++ object,
C++ code cannot access python objects).

If setting the badLayerHandler from python worked, you could do:
1. store info on layers created by sextante using custom properties,
2. create a sextanteBadLayerHandler that checks bad layers' custom
properties to understand if it was sextante their creator and if so
recreates them otherwise call the default bad layer handler.

> Looking forward to knowing more about it and starting working on
> those features. If there is anything I can do to help you, tell me
> and I will see what I can do.

We have to wait for other people,
hoping they'll join this thread soon ;)


> 2012/5/23 Giuseppe Sucameli <brush.tyler at gmail.com>:
>> Hi all,
>> I started to work on adding python support in project files (see [1]).
>> I've added a new tab "Project routines" to the project properties dialog
>> where the user can define 3 different python routines:
>> one is executed when the project is loaded,
>> the next one when the project is saved,
>> and the last one when the project is closed (saved or not).
>> I'm also adding a safe-check, it asks to the user if enabling them.
>> I've few questions:
>> 1. In [1] Martin wrote: """The routines should be able to access QGIS
>> application with the use of the interface in the same way how plugins do""".
>> I'm wondering if those routines must be functions with a specific signature
>> or they could just access the QGis interface using the qgis.utils.iface
>> since I'll use the QgsPythonRunner to run them.
>> 2. In a loaded project with trusted scripts (the user has trusted them)
>> if the user changes their definitions from project properties dialog
>> 2.a. should the new routines become active immediately when the user
>> clicks on the apply button in the project properies dialog,
>> 2.b. or should become active when he saves the project (the new
>> projectSaved script has to be called just after the project is saved),
>> 2.c. or should I keep the previous ones until the project is reloaded?
>> 3. should I call them project-embedded-scripts or routines??? :)
>> Opinions are welcome.
>> Cheers.
>> [1] http://hub.qgis.org/wiki/quantum-gis/Google_Summer_of_Code_2012#Python-Support-in-Project-Files
>> --
>> Giuseppe Sucameli
>> _______________________________________________
>> Qgis-developer mailing list
>> Qgis-developer at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/qgis-developer

Giuseppe Sucameli

More information about the Qgis-developer mailing list