bash - 在 yad 笔记本中添加按钮

标签 bash yad

任何可以帮助我解决 YAD(又一个对话)问题的人。

我正在为软件安装设计一个 GUI。我被表单字段困住了。这是我正在使用的示例代码:

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

现在的问题是我不知道如何让按钮工作。假设我单击按钮MSP,它应该调用函数install_pre_ser,其中包含安装基本软件的命令。这同样适用于其他按钮。

任何人都可以帮助我解决这个问题,因为过去几天我已经尝试了几乎所有的可能性。 预先感谢:-)

最佳答案

您的代码 action=$(yad ....) 部分无法正常工作,因为由于 >$res2,yad 输出而不是操作会转到 $res2 文件。

在您的代码中,您需要应用action=$(cat $res2),然后应该运行案例检查。

无论如何,通过应用不同的安装函数调用方法,我能够使您的代码在我的机器上运行:

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        

尝试我的测试,让我知道它是否适合您。

PS:这里有一个很好的教程,可能会对您的项目有所帮助:http://smokey01.com/yad/

关于bash - 在 yad 笔记本中添加按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40609812/

相关文章:

linux - 如何在变量中使用路径?

bash - 在 Bash 中将带空格的字符串作为函数参数传递

bash - 从 bash shell 脚本连接到 mongoDB

git - 如何在一个命令中创建多个 git 分支?

ORACLE:需要导出表数据,列之间没有空格

Python-yad 进度条在 python 3.4 中不起作用,但在 python 2.7 中起作用

bash - 组合表单和按钮时如何获取YAD中的值//用户指定按钮的退出代码