Sunday, 4 December 2016

pyqgis - Letting user choose from 2 options for QGIS Processing script input parameter?


I want to make a drop down box that shows 2 or 3 options and let the user choose 1 from them?


I would like to let the user to choose from "millimeter", "centimeter" and "meter". These Options are not from the field of input.


It seems like none of them here is valid:


It seems like none of them here is valid




Answer



Germán Carrillo's answer is the most convenient. A possible alternative (if you're stuck with QGIS 2.8) could be to:




  • Use a string which allows the user to enter the units they want to use:


    ##units=string mm

    if units == 'mm':
    # Do something
    elif units == 'cm':

    # Do something
    elif units == 'm':
    # Do something

    Text units









  • Or use three boolean checkboxes:


    ##Millimeter=boolean
    ##Centimeter=boolean
    ##Meter=boolean

    if Millimeter == True:
    # Do something
    elif Centimeter == True:
    # Do something
    elif Meter == True:

    # Do something

    Checkbox units




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...