Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 16 Sep 2019, 00:32
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
[gtk dialog] How to change value of external variable?
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [4 Posts]  
Author Message
fabrice_035


Joined: 28 Apr 2014
Posts: 642
Location: Bretagne / France

PostPosted: Sat 29 Sep 2018, 11:21    Post subject:  [gtk dialog] How to change value of external variable?  

Hi,

It is possible to change the value of external variable ?

In this example, i try change AD=1 to AD=-1

And make the negative button work.

Thanks.

Code:

#!/bin/bash

GTKDIALOG=gtkdialog

export AD
AD=1

MAIN_DIALOG='
<window title="compute" decorated="true" icon_name="gtk-media-record" >
   <vbox>
      <hbox>

      <button can-focus="no" relief="2">
      <input file stock="gtk-add"></input>
      <action function="refresh">'RESULT'</action>
      </button>
      
      
      <button can-focus="no" relief="2">
      <input file stock="gtk-remove"></input>
      
      </button>

            <entry>
            <variable>RESULT</variable>
            <input>echo $(( (RESULT + AD) ))</input>
             </entry>
         </hbox>
   </vbox>
</window>
'
export MAIN_DIALOG

gtkdialog  --program=MAIN_DIALOG
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1897
Location: Japan

PostPosted: Sat 29 Sep 2018, 12:29    Post subject: Re: [gtk dialog] addition subtraction  

fabrice_035 wrote:
Hi,

It is possible to change the value of external variable ?
Well, yes...sort of, but I don't see how these would help you, at least in your chosen approach.

The following example tries to stay as close as possible to your code and uses 2 text widgets to keep your internal variables:
Code:
#!/bin/bash
GTKDIALOG=gtkdialog

MAIN_DIALOG='
<window title="compute" decorated="true" icon_name="gtk-media-record" >
<vbox>
   <text visible="false"><variable>ADD</variable><input>echo 1</input></text>
   <text visible="false"><variable>SUB</variable><input>echo 1</input></text>
   <hbox>
      <button can-focus="no" relief="2">
         <input file stock="gtk-add"></input>
         <action>refresh:ADD</action>
         <action>clear:SUB</action>
         <action>refresh:RESULT</action>
      </button>
      <button can-focus="no" relief="2">
         <input file stock="gtk-remove"></input>
         <action>refresh:SUB</action>
         <action>clear:ADD</action>
         <action>refresh:RESULT</action>
      </button>
      <entry>
         <variable>RESULT</variable>
         <input>echo $(( RESULT + ADD - SUB ))</input>
      </entry>
   </hbox>
</vbox>
 </window>
 '
export MAIN_DIALOG

gtkdialog  --program=MAIN_DIALOG
Back to top
View user's profile Send private message 
fabrice_035


Joined: 28 Apr 2014
Posts: 642
Location: Bretagne / France

PostPosted: Sat 29 Sep 2018, 16:34    Post subject:  

Hi MochiMoppel, nice way Razz you help me
So I imagine change external var is not possible in gtk ?
Thanks.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1897
Location: Japan

PostPosted: Sat 29 Sep 2018, 18:46    Post subject:  

fabrice_035 wrote:
So I imagine change external var is not possible in gtk ?
I guess it's not possible anywhere in Linux. You can't change a parent shell variable from a subshell. You may use and change the variable in a subshell, e.g. in a gtkdialog <action> statement, but you can't make such changed value usable for other actions or widgets. So for all practical purposes let's say: It's not possible.

I'm glad you like the solution. You can make it even simpler. Only 1 variable:
Code:
#!/bin/bash
MAIN_DIALOG='
<window title="compute" decorated="true" icon_name="gtk-media-record" >
<vbox>
   <text visible="false"><variable>SUB</variable><input>echo 2</input></text>
   <hbox>
      <button can-focus="no" relief="2">
         <input file stock="gtk-add"></input>
         <action>clear:SUB</action>
         <action>refresh:RESULT</action>
      </button>
      <button can-focus="no" relief="2">
         <input file stock="gtk-remove"></input>
         <action>refresh:SUB</action>
         <action>refresh:RESULT</action>
      </button>
      <entry>
         <variable>RESULT</variable>
         <default>100</default>
         <input>echo $(( RESULT + 1 - SUB ))</input>
      </entry>
   </hbox>
</vbox>
 </window>
 '
export MAIN_DIALOG

gtkdialog  --program=MAIN_DIALOG
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [4 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0370s ][ Queries: 11 (0.0076s) ][ GZIP on ]