Reputation: 173
I have code in bash, with gtkdialog and I need your help. here is code:
#!/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
so the code is now creating GUI with 4 vertical boxes which are immediately filled with data. What I want to do is, when GUI start's I need empty boxes, and I would like to add one more button (Refresh or Fill) which will then fill the data.
Upvotes: 1
Views: 743
Reputation: 4496
You can use the refresh:<variable id>
action.
#!/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
Additional notes :
$SHELL -c
stuff, due to this problem Screenshot:
Upvotes: 1