[Qgis-developer] Python support in project file

Martin Dobias wonder.sk at gmail.com
Wed May 30 14:37:18 PDT 2012


Hi Giuseppe

(sorry for joining the thread so late)

On Wed, May 23, 2012 at 9:24 PM, Giuseppe Sucameli
<brush.tyler at gmail.com> wrote:
> 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:

Maybe I would call it "macros" - everyone knows that term from Excel
and Word :-)

How the GUI is going to look like? Should the user enter the Python
code directly into some text edit widgets?

> 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).

Right, so the interface is similar to plugins (load+unload), with an
addition of a callback when saving project. Makes sense.

How are you going to save the python code? In an external file or
embedded into XML file or even something else?


> I'm also adding a safe-check, it asks to the user if enabling them.

Good, it would be good to have the check done in a way that does not
disturb the user with some popups - ideally something like a "yellow"
bar that currently browsers use when asking questions.


> 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.

Before, plugins had to get iface reference directly when a plugin
instance was created because there was no other way to get iface.
Nowadays when there's iface reference within qgis.utils module it is
not necessary to pass iface directly.


> 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?

I would vote for 2.a: in fact when the user applies changes done to
the python code, the python stuff could get reloaded, i.e. unload
(from old code) would be called, followed by load (from new code) - I
hope this will make the transition quite smooth.


> 3. should I call them project-embedded-scripts or routines??? :)

As said above, I would call them macros. But I am not insisting. But
"routines" does not sound very familiar in this context.


Martin


More information about the Qgis-developer mailing list