我在bash中有代码,使用gtkdialog,我需要你的帮助。 这是代码:
#!/bin/bash
Cell11=`grep -i Cell11 /home/Desktop/grep | cut -d"=" -f2`
Cell12=`grep -i Cell12 /home/Desktop/grep | cut -d"=" -f2`
Cell13=`grep -i Cell13 /home/Desktop/grep | cut -d"=" -f2`
Cell14=`grep -i Cell14 /home/Desktop/grep | cut -d"=" -f2`
export MAIN_DIALOG='
<vbox homogeneous="True">
<frame Sector 1>
<hbox>
<text>
<label>Cell1</label>
</text>
<entry activates-default="true">
<variable>Cell11</variable>
<input>echo '$Cell11'</input>
</entry>
</hbox>
<hbox>
<text>
<label>Cell2</label>
</text>
<entry activates-default="true">
<variable>Cell12</variable>
<input>echo '$Cell12'</input>
</entry>
</hbox>
<hbox>
<text>
<label>Cell3</label>
</text>
<entry activates-default="true">
<variable>Cell13</variable>
<input>echo '$Cell13'</input>
</entry>
</hbox>
<hbox>
<text>
<label>Cell4</label>
</text>
<entry activates-default="true">
<variable>Cell14</variable>
<input>echo '$Cell14'</input>
</entry>
</hbox>
</frame>
</vbox>
gtkdialog --program=MAIN_DIALOG
所以代码现在正在创建带有4个垂直框的GUI,这些框立即填充数据。我想要做的是,当GUI启动我需要空盒子时,我想再添加一个按钮(刷新或填充),然后填充数据。
答案 0 :(得分:1)
您可以使用refresh:<variable id>
操作。
#!/bin/bash
#Cell11="" #`grep -i Cell11 /home/Desktop/grep | cut -d"=" -f2`
#Cell12="" #`grep -i Cell12 /home/Desktop/grep | cut -d"=" -f2`
#Cell13="" #`grep -i Cell13 /home/Desktop/grep | cut -d"=" -f2`
#Cell14="" #`grep -i Cell14 /home/Desktop/grep | cut -d"=" -f2`
# for testing.
function updateFile() {
for i in {1..4};do echo "Cell1$i=$RANDOM";done > grepFile
}
#this must be done, otherwise the child process cannot call it
export -f updateFile
export MAIN_DIALOG='
<vbox homogeneous="True">
<frame Sector 1>
<hbox>
<text>
<label>Cell1</label>
</text>
<entry activates-default="true">
<variable>Cell11</variable>
<input>grep -i Cell11 grepFile | cut -d"=" -f2</input>
</entry>
</hbox>
<hbox>
<text>
<label>Cell2</label>
</text>
<entry activates-default="true">
<variable>Cell12</variable>
<input>grep -i Cell12 grepFile | cut -d"=" -f2</input>
</entry>
</hbox>
<hbox>
<text>
<label>Cell3</label>
</text>
<entry activates-default="true">
<variable>Cell13</variable>
<input>grep -i Cell13 grepFile | cut -d"=" -f2</input>
</entry>
</hbox>
<hbox>
<text>
<label>Cell4</label>
</text>
<entry activates-default="true">
<variable>Cell14</variable>
<input>grep -i Cell14 grepFile | cut -d"=" -f2</input>
</entry>
</hbox>
<hbox>
<button>
<label>Refresh</label>
<action>refresh:Cell11</action>
<action>refresh:Cell12</action>
<action>refresh:Cell13</action>
<action>refresh:Cell14</action>
</button>
<button>
<label>Update file</label>
<action>$SHELL -c 'updateFile'</action>
</button>
</hbox>
</frame>
</vbox>'
gtkdialog --program=MAIN_DIALOG
附加说明:
$SHELL -c
内容
截图: