bash 如何在zenity中获取不同形式的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21368107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 09:22:35  来源:igfitidea点击:

how to get the values of different forms in zenity

bashshellzenity

提问by user573014

I want to get the values of the form in zenity (Ipaddress value written by user) in order to do some video streaming with ffmpeg, I tried several examples such as lists, forms, .. etc

我想在 zenity 中获取表单的值(用户编写的 Ipaddress 值)以便使用 ffmpeg 进行一些视频流,我尝试了几个示例,例如列表、表单等

zenity --forms --title="Add Friend" --text="Enter Multicast address" --separator="," --add-entry="IP address" --add-entry="PORT" 

OR

或者

if zenity --list --title="Record Video Stream"  --text "Enter the Multicast IP address and port of each of the video stream" --column "Video IP" --print-column=2 --multiple --column "PORT" --editable ip="0.0.0.0" port="2002"

回答by Petesh

The output from zenityis the text that was inputted, separated by the --separatorcharacter. The exit code is if it was accepted or not (i.e. OK, Cancelselected).

输出来自zenity输入的文本,由--separator字符分隔。退出代码是它是否被接受(即OKCancel被选中)。

So for example (in bash):

例如(在 bash 中):

OUTPUT=$(zenity --forms --title="Add Friend" --text="Enter Multicast address" --separator="," --add-entry="IP address" --add-entry="PORT")
accepted=$?
if ((accepted != 0)); then
    echo "something went wrong"
    exit 1
fi

ip=$(awk -F, '{print }' <<<$OUTPUT)
port=$(awk -F, '{print }' <<<$OUTPUT)

That gets you the ip address from zenity into the ip variable and the port from the zenity form into the port variable.

这使您将 zenity 的 ip 地址转换为 ip 变量,并将 zenity 形式的端口转换为 port 变量。

The second example is a little more complex, it's using the 'editable' template, which means that you don't get any output if the data is unchanged, but it follows a similar pattern to the previous example. Now, because you said --print-column=, it only displays that column in the output. Unfortunately, --listis for the selection of one or more rows from a list of items. Editing multiple rows will work, but you haveto select every one of the rows to get the output from that row, even after making a change to the data. In this case, because you didn't specify the --separatoroption, the default separator is used |.

第二个示例稍微复杂一些,它使用“可编辑”模板,这意味着如果数据未更改,您将不会获得任何输出,但它遵循与前一个示例类似的模式。现在,因为你说--print-column=,它只在输出中显示该列。不幸的是,--list用于从项目列表中选择一行或多行。编辑多行会起作用,但您必须选择每一行才能从该行获取输出,即使在对数据进行更改之后也是如此。在这种情况下,因为您没有指定--separator选项,所以使用默认分隔符|

In the second case, using editable and list inputs isn't really what a list is designed to do from a user input perspective.

在第二种情况下,从用户输入的角度来看,使用可编辑和列表输入并不是列表的真正目的。