Search code examples
zenityyad

If YAD is a fork of Zenity why is there no --imagelist?


Zenity is used in many of my bash projects, but looking at the advanced features of YAD there are many reasons to switch. After some testing unfortunately I discovered there is no --imagelist option for the list type dialog. This is a major problem as most of my projects use imagelists.

The below example runs on zenity version 3.28.1

#!/bin/bash

table=(~/image.png " " "Title1" " " "description1" "output1" ~/image.png " " "Title2" " " "description2" "output2" ~/image.png " " "Title3" " " "description3" "output3")


zenity --list --title="page title" --text="some random text" --imagelist --ok-label=Open --cancel-label=Home --print-column=6 --hide-column=6 --separator=' ' --width=600 --height=400 \
   --column="Cover image"  \
   --column="     "  \
   --column="Name"  \
   --column="     "  \
   --column="details"  \
   --column="Folder"  \
   "${table[@]}"

the dialog should look like this:Zenity image list

In this example ${table[@]} is an array that contains all the data for each row including the file-path to the image in column 1. Is there a way to do this in YAD?

I installed YAD and looked at all the help pages provided in terminal, also tried to run similar imagelist examples, but it seems to be not supported (syntax is mostly the same as YAD is a fork of zenity)


Solution

  • With yad the columns can have a type associated with them. In your case you want to use the :IMG type for the first column, and the other two can remain as plain text.

    table=(
       ~/image.png  ""  "Title1"  ""  "description1"  "output1"
       ~/image.png  ""  "Title2"  ""  "description2"  "output2"
       ~/image.png  ""  "Title3"  ""  "description3"  "output3"
    )
    
    yad                             \
       --list                       \
       --title="page title"         \
       --text="some random text"    \
       --imagelist                  \
       --print-column=6             \
       --hide-column=6              \
       --separator=' '              \
       --width=600                  \
       --height=400                 \
       --column="Cover image:IMG"   \
       --column=" "                 \
       --column="Name"              \
       --column="     "             \
       --column="details"           \
       --column="Folder"            \
       --button="Home":1            \
       --button="Open":20           \
       --response=20                \
       "${table[@]}"
    

    The output, missing your images

    That will set the exit code to 20 if you press Enter or click Open on a list item, as well as outputting "output1" or "output2" etc.

    That said, I have been experiencing issues with the exit codes or output text not appearing correctly. The above example works fine for me, but if I change the the Open exit code to "25" instead of "20" it stops working. No idea why it behaves inconsistently.