Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I found by chance it was possible to display a combo box with zenity (version tested: 2.32.1). See the following code:

#!/bin/bash
array=(a b c d e)
value=$(zenity --entry --title "Window title" --text "${array[@]}" --text "Insert your choice.")

The result is illustrated with the following 3 images:

enter image description here

enter image description here

enter image description here

I have two questions about that:

  1. Is there a documentation about this functionality? I didn't find anything in the zenity documentation.

  2. Why the first value of my array doesn't appear in the combo box? In the example above, my array is (a b c d e), and the combo box only displays b c d e.

    As a workaround, I add a value in my array, for example (0 a b c d e).

share|improve this question
up vote 4 down vote accepted

The first element of the array gets eaten up by --text. After expansion, your zentiy-line looks like:

zenity --entry --title "Window title" --text a b c d e --text "Insert your choice."
# Which zenity treats equivalent to
zenity --entry --title "Window title" --text a --text "Insert your choice." b c d e

So you first set the text to "a", then you override that with "Insert your choice." And the remaining arguments become the choices.

What you want is:

zenity --entry --title "Window title" --text "Insert your choice." a b c d e
# Hence:
zenity --entry --title "Window title" --text "Insert your choice." "${array[@]}"
share|improve this answer

See http://library.gnome.org/users/zenity/2.32/zenity.html#zenity-text-entry-options I think you want to use --text-entry for the array of values, not --text. Using:

#!/bin/bash
array=(a b c d e)
value=$(zenity --entry --title "Window title" --entry-text "${array[@]}" --text "Insert your choice.")

I see the default value of the dropdown box pre-filled with the first value of array, and all values available.

share|improve this answer
    
Thanks for the answer. It's curious that the manual does not refer to combo box. – jpfleury Jul 5 '11 at 20:25

This is actually documented (maybe not at the time the question was posted, didn't check), not in the manual but in zenity --help-forms :

$ LANG=en_US zenity --help-forms
Usage:
  zenity [OPTION...]

Forms dialog options
  --forms                                           Display forms dialog
  --add-entry=Field name                            Add a new Entry in forms dialog
  --add-password=Field name                         Add a new Password Entry in forms dialog
  --add-calendar=Calendar field name                Add a new Calendar in forms dialog
  --add-list=List field and header name             Add a new List in forms dialog
  --list-values=List of values separated by |       List of values for List
  --column-values=List of values separated by |     List of values for columns
  --add-combo=Combo box field name                  Add a new combo box in forms dialog
  --combo-values=List of values separated by |      List of values for combo box
  --show-header                                     Show the columns header
  --text=TEXT                                       Set the dialog text
  --separator=SEPARATOR                             Set output separator character
  --forms-date-format=PATTERN                       Set the format for the returned date

Therefore :

zenity --forms --title "Window title" --text "Combo name" --add-combo "Insert your choice." --combo-values "a|b|c|d|e"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.