The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 3,266     Votes:  2 
Tags: scripts   zenity   yad  
Link: 🔍 See Original Answer on Ask Ubuntu ⧉ 🔗

URL: https://askubuntu.com/q/895471
Title: How to edit YAD question labels (example)?
ID: /2017/03/21/How-to-edit-YAD-question-labels-_example__
Created: March 21, 2017    Edited:  April 13, 2017
Upload: March 26, 2024    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


I happened to write this a few days ago for a question of my own (Bash template to use zenity (or yad) to insert / edit / delete records in a file or database) and thought it was worth sharing:

websync 1

Notice the six buttons on the screen and how they are handled in the code below (sorry still a work in progress). An important note is when using custom buttons to always trap default return codes like 252 for Escape and Windows close (clicking X).

while true ; do

Record=(`yad \
	--title "websync - Compare local scripts to those published on internet." --list \
        --text '<span foreground="blue" font="14">Toggle select next to file then click action button</span>' \
        --width=900 --height=600 --center --radiolist -separator="$IFS" --no-click \
        --button="Insert before":1 --button=Edit:2 --button=Delete:3 --button=Run:4 \
        --button="Cancel ALL":5 --button=Save:6 --search-column=3 \
        --column "Select" --column "Record number" --hide-column=2 --column "File Name" \
        --column "Status" --column " Website Address" \
        "${choices[@]}"`)
Action=$?

RecSelected=false
RecArr=()
i=0

# With radio list only one choice is possible
for Field in "${Record[@]}" ; do
    RecSelected=true
    RecArr[i]=$Field
# echo "RecArr $i ${RecArr[$i]}"
    ((i++))
done

echo "button: $Action"# 
# Note: When X closes window or Escape pressed 252 is returned.

# Insert before || or Edit ?
if [[ $Action == 1 ]] || [[ $Action == 2 ]] ; then
    RecArr[3]="New"
    # --text="Set fields and click OK to update" 
    # Note if there is a space at end of line, next line generates invalid command error from yad
    yad --width=600 --height=400 --title="Link file to Website Address" \
        --form --center \
        --field="Record Number":RO --field="File name":FL --field="Status":RO \
        --field="Website Address":TXT \
        ${RecArr[1]} ${RecArr[2]} ${RecArr[3]} ${RecArr[4]}
    ret=$?

    # Cancel =252, OK = 0
    if [[ $ret == 0 ]] ; then
        # Update array and renumber
        : # noop
    else
        continue # cancel changes.
    fi

elif [[ $Action == 3 ]] ; then
    : # Delete
elif [[ $Action == 4 ]] ; then
    : # Run
elif [[ $Action == 5 ]] || [[ $Action == 252 ]] ; then
    # Cancel ALL || or X the window or Escape
    exit
elif [[ $Action == 6 ]] ; then
    # Save
    exit
else
    zenity --error --text "~/bin/websync - Unknown button return code: $Action"
fi

done # End of while loop
⇧ Is there a command to display a Calendar in the terminal? Automatically adjust display brightness based on sunrise and sunset  ⇩