2

Anyone who can help me with YAD (Yet Another Dialog).

I'm designing a GUI for a software installation. I'm stuck with the form field. Here is the sample code that I'm working with :

sersoft()
{
    root_verify  #fucntion for root verification
    os_verify   #function to detect the OS and its version

    if [ "$ret_val" == 3 ] || [ "$ret_val" == 4 ]; then #ret_val indicates type of OS
            apt-get update -y
            apt-get upgrade -y
            apt-get -y install gcc g++ libpcap0.8-dev build-essential
            #and many other installations
            service ssh restart
            apt-get -y update
            apt-get -y upgrade

    elif [ "$ret_val" == 5 ];then
            yum groupinstall "Development Tools"
            yum -y install gcc libpcap-devel fontconfig-devel
            #etc
            yum -y update
            yum -y upgrade
    fi
}

    MSP="Install Prerequesites for Server"
    MCP="Install Prerequesites for Client"
    MSP1="Software for Server"
    MCP1="Software for Client"

    #Welcome Tab
    yad --plug=$KEY --tabnum=1 --form --image="$banner" --separator='\n' --quoted-output \
             > $res4 &

    #Prerequesites Tab
    yad --plug=$KEY --tabnum=2 --form --separator='\n' --text="\n\nPlease install the required softwares needed to configure Monosek software. \n\nClick any one of the options.\n\n" --text-align=center --quoted-output \
            --field="$MSP!gtk-yes:2":FBTN --align=center \
            --field="$MCP!gtk-yes:3":FBTN --align=center  > $res1 &

    #Installation Tab
    action=$(yad --plug=$KEY --tabnum=3 --form --seperator='\n' --quoted-output \
            --field="Select:CBE" "\--Install\--!$MSP1!$MCP1") > $res2 &

    #Main Dialog
    yad --center --fixed --notebook --key=$KEY --tab-pos=left --tab="Welcome Tab" --tab="Prerequesites" --tab="Install" \
    --title="Software Setup Wizard" --image="$icon" \
    --button="OK:0" \
    --button="Exit:1" \
    --height=560 --width=665 --image-on-top --text="  Software version $VERSION"

case $action in

           $MSP1*) TAB2=install_ser_soft ;;
           $MCP1*) TAB3=instal_client_soft ;;

           *) yad --center --text="error"
           ;;
   esac

Now the problem is I have no idea how to get the buttons work. Say suppose I click the button MSP, it should call the function install_pre_ser which contains the commands to install the essential softwares. The same applies to the other button.

Can anyone help me with this as I have tried with almost all possibilities from past couple of days. Thanks in advance :-)

StackUseR
  • 884
  • 1
  • 11
  • 40

1 Answers1

2

The part of your code action=$(yad ....) is not working due to the fact that yad output instead of action goes to a $res2 file due to the >$res2.

In your code you need to apply action=$(cat $res2) and then case check should run.

In any case, i was able to make your code work in my machine by applying different methods for installation function calls:

function sersoft {
yad --text "Server Prerequesites Will be installed now"
}
export -f sersoft

function clientsoft {
yad --text "Client Prerequesites Will be installed now"
}
export -f clientsoft

function install_ser_soft {
yad --text "Server SOFTWARE to be installed now"
}

function install_client_soft {
yad --text "Client SOFTWARE to be installed now"
}


    MSP="Install Prerequesites for Server"
    MCP="Install Prerequesites for Client"
    MSP1="Software for Server"
    MCP1="Software for Client"

    yad --plug=12346 --tabnum=1 --form --image="abp.png" --separator='\n' &\
    yad --plug=12346 --tabnum=2 --form --separator='\n' --text="Please install softwares" --text-align=center \
    --field="$MSP!gtk-yes:2:FBTN" "bash -c sersoft" --align=center --field="$MCP!gtk-yes:3:FBTN" "bash -c clientsoft" \
    --align=center &\
    action=$(yad --plug=12346 --tabnum=3 --form --seperator=' ' --field="Select:CBE" "\--Install\--!$MSP1!$MCP1" &\
    yad --center --notebook --key=12346 --tab="Welcome Tab" --tab="Prerequesites" --tab="Install" --title="Software Setup Wizard" --image="abp.png" --button="OK:0" --button="Exit:1" --height=560 --width=665 --image-on-top --text="Software version 3")
    ret=$?
    echo "output=" $ret
    echo "answer=" $action
    case $action in
    $MSP1*) install_ser_soft ;;
    $MCP1*) install_client_soft ;;
    *) yad --center --text="error";;
    esac        

Try my test and let me know if it works for you.

PS: There is a nice tutorial here that might help you for your project: http://smokey01.com/yad/

George Vasiliou
  • 6,130
  • 2
  • 20
  • 27
  • After hitting the install button I can see the progress on the terminal. But after installing the prerequisites, the control doesn't comes back to the dialog. If I hit exit on the dialog window it hangs and asks me to force quit the wizard. – StackUseR Nov 17 '16 at 07:35
  • Is the install button function working ok? It could be possible that the commands that you execute inside button function to have fail thus raising an error code which could conflict with yad. In my test that only one command is executed , control returns to yad notebook dialogue without hangs. – George Vasiliou Nov 17 '16 at 08:52
  • This is how terminal output looks: `Hit http://in.archive.ubuntu.com precise-backports/multiverse Translation-en Hit http://in.archive.ubuntu.com precise-backports/restricted Translation-en Hit http://in.archive.ubuntu.com precise-backports/universe Translation-en Ign http://ppa.launchpad.net precise/main Translation-en_IN Ign http://ppa.launchpad.net precise/main Translation-en Reading package lists... Done Reading package lists... Done Building dependency tree Reading state information... Done 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. ` – StackUseR Nov 17 '16 at 09:04
  • Functions seems good , but maybe something breaks within and crashes yad. It is not clear. I would suggest to try to call the function out of yad to see how it goes and to isolate commands step by step in order to find which one cause the crash. i.e comment functions root verify, os verify and the corresponding if section.If still crashes you can further comment some apt-get lines till you reach to the problem. You need to reach a point that return on yad will be OK. Debugging is always a trouble... – George Vasiliou Nov 17 '16 at 13:48
  • Ok everything seems to be good just the problem was I had forgot to define the function which shows me the terminal output on the yad dialog. Thanx anyway. – StackUseR Nov 18 '16 at 05:49