Yad list get value of selected line in function

2.2k views Asked by At

I developp a software in linux and i have problem, i have a primary yad window (for this exemple i use the name : w1) and button who execute an second : w2, w2 is list and i want to export the selected line, how I could extract the selected line from the function (knowing that I get there halfway but I can't get my line out of my function), my code :

w1=$(yad --title="TITLE"\
      --form \
      --no-escape \
      --center \
      --window-icon=gtk-preferences \
      --borders=10 \
      --fixed  \
      --text="TEST" --text-align=center \
      --button="LIST`!format-justify-fill:bash -c w2 && echo $w2"  \
      --button="`QUIT`"!gtk-quit:1 )

w2 () 
{
    INPUT="MY FILE WITH ALL DATA"
    item=$(while read l
    do
       echo "$l"
    done <$INPUT|yad --title="TITLE 2"\
             --borders=10 \
             --listen \
             --no-markup \
             --width=500 \
             --height=500 \
             --no-escape \
             --center \
             --window-icon=gtk-preferences \
             --list \
             --column="COLUMN 1":text \
             --column="COLUMN 2":text \
             --button=""!go-jump:1 \
             --button="QUIT"!go-jump:1)
}
export -f w2 

In this case, the variable $item contain the result.

1

There are 1 answers

0
anonim On
#!/bin/bash


# Licence: GNU GPL v3
# Version: 1
# Script use:   bash script_name
# This is example script

# Function in yad is not supported but it can work after 
# add in script "export -f function_name" 
# and will work as a separate process like command.


yad --title="TITLE"\
      --form \
      --no-escape \
      --center \
      --window-icon=gtk-preferences \
      --borders=10 \
      --fixed  \
      --text="TEST" --text-align=center \
      --button="LIST"!format-justify-fill:0  \
      --button="gtk-cancel":1 
VAR1="$?"
echo "  DEBUG: VAR1 = $VAR1" 


FUNCTION_VAR2 () {
INPUT=$(echo -e "one \naple \ntwo\nbanana \ntree \ncitrine \nfour \nnewfruit")

VAR2=$( echo "$INPUT" | yad --title="TITLE 2" \
--text="Select the correct one row:" \
--borders=10 \
--listen \
--no-markup \
--width=500 \
--height=500 \
--no-escape \
--center \
--window-icon=gtk-preferences \
--list \
--column="COLUMN 1":text \
--column="COLUMN 2":text \
--button="OK"!go-jump:0 \
--button="gtk-cancel":1 )

echo "  DEBUG: VAR2 = $VAR2" 
VAR3=$(echo "$VAR2" | awk -F"|" '{ print $1 }')
VAR4=$(echo "$VAR2" | awk -F"|" '{ print $2 }')
echo "  DEBUG: VAR3 = $VAR3" 
echo "  DEBUG: VAR4 = $VAR4" 
}


[[ "$VAR1" == "0" ]] && FUNCTION_VAR2