[GRASS-dev] Using a dynamic text in module header for parser

Blumentrath, Stefan Stefan.Blumentrath at nina.no
Mon Oct 12 02:35:32 PDT 2015


Hi,

I would like to fill:
#% options:
and
#% answer
in a parser option for a python script dynamically.  In particular I want to have tickboxes for available mapsets in the module GUI...

Meaning something like this  (but less complex / not interactive):
http://permalink.gmane.org/gmane.comp.gis.grass.gui/667
My amateur programming skills do unfortunately not allow me to really understand how to accomplish what Glynn describes in the post above...

I tried to generate and run a temporary python script from within my script like this:
def main():

    answer = grass.mapsets(search_path = True)
    available_mapsets = str(grass.mapsets())

    with tempfile.NamedTemporaryFile(delete = False) as s:
        s.write('''    #!/usr/bin/env python
# -*- coding: utf-8 -*-
# Here comes the full module with header for the parser
#% options: ''' + str(','.join(available_mapsets))
...
''')
    startcmd = 'python ' + s.name
    os.system(startcmd)
    os.remove(s.name)

But that way the GUI never starts, when I call the outer script from GRASS and it seems that option never get parsed...

Any hints how to proceed?

Thanks for helping in advance.

Stefan


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20151012/fabfbdad/attachment-0001.html>


More information about the grass-dev mailing list