[Qgis-developer] New Python console idea: Expanding the Python console to handle DSLs for plugins eg CADTools

Nathan Woodrow madmanwoo at gmail.com
Fri Jun 17 08:55:04 EDT 2011


Barry,

I think it could be a pretty powerful and cool thing to at least try out
with the prototype.   I'm a ex MapInfo user and in MapBasic we were able to
call a user defined function in SQL for a update, insert, etc etc.   So you
could do:

Function MyFunction(someStringVar) as String
   Return "Foo Bar " + someStringVar
End Function

And then in the SQL statement.

UPDATE table SET column = MyFunction("Hello World") where column > 100

This would call MyFunction() for each feature and call a update.  However
one shortfall of this is that you couldn't define functions in the
interactive Mapbasic shell inside MapInfo, meaning that you had to write a
custom script just to do the above.

If we could do something like this in the python console and pass functions
and variables to custom DSLs I think it would be quite handy.  Of course the
DSL would have to know how to handle the variables or it would just return a
error.

I know it might not be a easy thing to do but I'm willing to give it a go in
my prototype to flesh it out.

Like you said we should just have to find way to say "this is a python
variable" and "this is part of the string to send to the DSL".   You might
be able to use something like %%variableName or %%functionName. The console
would parse the string that goes to the DSL and build a dictionary with
%%variableName = realPythonVariable and then sends the string and the
dictionary to the DSL which at that point it's up it to worry about
evaluating and replacing the values and functions.

Thoughts?

On Fri, Jun 17, 2011 at 5:27 PM, Barry Rowlingson <
b.rowlingson at lancaster.ac.uk> wrote:

> On Fri, Jun 17, 2011 at 4:36 AM, Nathan Woodrow <madmanwoo at gmail.com>
> wrote:
>
> > Well would that be such a bad thing? The DSLs can return a object from
> the
> > evaluated string so why not let them be mixed.  This would mean you can
> do
> > things like:
> >
> > mypythonVar = (SQL:Select Sum(column) From Table)
> > #Some more python code to assign the value to a QgsFeature
>
>  Oh I didnt say it was bad, just tricky! Done right it would be good -
> Python in Qgis is getting variable values from C++ all the time.
>
>  For example, someone might think they can do:
>
>  > foo = 1 + 2 # python
>  > SQL: select * from table where x=foo
>
> In fact, I'd be quite frustrated if I couldn't do that in a single
> console. So to implement this, you've got to have some way of getting
> variables from one interpreter into another, so you might end up with:
>
>  > SQL: select * from table where x=PYTHON:foo
>
> but now you are parsing everything before it gets to the destination
> parser, but that could be ambiguous with the destination language. So
> then the console becomes a macro language all of its own...
>
> Barry
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20110617/ffba1608/attachment.html


More information about the Qgis-developer mailing list