Gtkdialog

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
TIHO0505
Posts: 3
Joined: Thu 08 May 2014, 09:05

Gtkdialog

#1 Post by TIHO0505 »

Hi
here is the part of code, where are have boxes with entries, and i want to create function that I will call with button, that will grep some values from folder and write them to this boxes (variables Cell12..). Here is how boxes looks

Code: Select all

<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>
                                       <action>echo '$Cell13'</action>
                                      </entry>
                                 </hbox>
and here is

Code: Select all

<hbox>
  <button>
   <label>Fill</label>
      <action>Cell11=`grep -i Cell11 /home/tihomir/Desktop/FolderCell3 | cut -d"=" -f2`</action>
      <action>refresh:Cell11</action>
   </button>
</hbox>
But it is not working. If somebody know's how could I do this, I would appriciate that. If more explanation is need let me know.

BR

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#2 Post by zigbert »

Hello, and welcome

It will work if you use temporary files instead

Code: Select all

<entry activates-default="true">
 <input file>/tmp/Cell13</input> 
 <variable>Cell13</variable>
 <action signal="activate">echo '$Cell13'</action>
</entry>

Code: Select all

<button>
 <label>Fill</label>
 <action>grep -i Cell13 /home/tihomir/Desktop/FolderCell3 | cut -d"=" -f2 > /tmp/Cell13</action>
 <action>refresh:Cell13</action>
</button> 
signal="activate" will run action when user press enter-button

TIHO0505
Posts: 3
Joined: Thu 08 May 2014, 09:05

#3 Post by TIHO0505 »

Thanks for reply, it's working.

Working with this gtkdialog is a little bit different then bash, so I get stuck from time to time :).. for example I have a function with grep command, and I want to pass a argument(varaible) to this function, but from gtkdialog it's not working:

Code: Select all

func_grep () {
$Cell=`grep -i '$Cell' /home/tihomir/Desktop/FolderCell3 | cut -d'"' -f2`
echo '$Cell'
}
 
and calling function form gtkdialog :

Code: Select all

<hbox>
                                   <text>
                                   <label>Cell1</label>
                                   </text>
                                    <entry file-monitor="true" auto-refresh="true">
                            <input>exec $SHELL -c func_grep Cell = "Cell11"</input>
                                     <variable>Cell11</variable>
                                     <visible>disabled</visible>
                                     </entry>
                                 </hbox>
it's not working. Did I miss something, or this is not possible to do this way?

Thanks

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#4 Post by zigbert »

since func_grep returns echo "$Cell" (you must use double quotes), it is enough to just run the function

Code: Select all

<entry file-monitor="true" auto-refresh="true">
 <input>func_grep</input>
 <variable>Cell11</variable>
 <visible>disabled</visible>
</entry>
Be aware that you probably need to make the function global by

Code: Select all

func_grep () {
$Cell=`grep -i '$Cell' /home/tihomir/Desktop/FolderCell3 | cut -d'"' -f2`
echo "$Cell"
}
export -f func_grep

Post Reply