2016-11-15 51 views
2

任何能夠幫助我使用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,其中包含用於安裝基本軟件的命令。這同樣適用於另一個按鈕。

任何人都可以幫助我,因爲我已經嘗試過幾天所有的可能性。 在此先感謝:-)

回答

1

您的代碼action = $(yad ....)的一部分不起作用,因爲yad輸出而不是action會轉到$ res2文件,原因是$ 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/

+0

歡迎您!我很高興這有助於。 –

+0

點擊安裝按鈕後,我可以看到終端的進度。但是在安裝先決條件後,控件不會回到對話框。如果我在對話窗口點擊退出,它會掛起並要求我強制退出嚮導。 –

+0

安裝按鈕功能是否正常工作?在按鈕函數內部執行的命令可能會失敗,從而引發可能與yad衝突的錯誤代碼。在我的測試中,只有一個命令被執行,控制返回到沒有掛起的筆記本對話。 –