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 Wed 26 Nov 2014, 23:12
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
GtkDialog - How to change the value of a variable?
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message
MochiMoppel


Joined: 26 Jan 2011
Posts: 477
Location: Japan

PostPosted: Tue 04 Feb 2014, 10:14    Post_subject:  GtkDialog - How to change the value of a variable?  

I'm stuck with a simple task: to toggle a button label. I have a variable defined outside of the dialog
Code:
TEXT="go"

I now want a togglebutton to change its label whenever it's pushed. Something like this:
Code:
   <togglebutton>
      <label>'"$TEXT"'</label>
      <variable>BTN</variable>
      <action>if true let TEXT="stop"</action>
      <action>if false let TEXT="go"</action>
      <action>refresh:BTN</action>
   </togglebutton>

This doesn't work. Is it somehow possible to change the value of TEXT and let the button refresh accordingly?
Back to top
View user's profile Send_private_message 
zigbert


Joined: 29 Mar 2006
Posts: 5788
Location: Valåmoen, Norway

PostPosted: Tue 04 Feb 2014, 11:34    Post_subject:  

The 'refresh' command does only manage the <input> tag, so the text can only be refreshed for <entry>, <combo...>, <edit>, <text>, <tree> and <table>.

The way I get around this is to build a svg-icon for a <button> widget, and rebuild it with new label when refreshing.


Sigmund

_________________
Stardust resources
Back to top
View user's profile Send_private_message Visit_website 
don570


Joined: 10 Mar 2010
Posts: 3380
Location: Ontario

PostPosted: Tue 04 Feb 2014, 21:06    Post_subject:  

-to ZIGBERT's post...

I made a simple example of SVG buttons (YES and NO)
in my manual

http://murga-linux.com/puppy/viewtopic.php?t=89045

___________________________________________
Back to top
View user's profile Send_private_message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 477
Location: Japan

PostPosted: Tue 04 Feb 2014, 22:28    Post_subject:  

@ zigbert
Thanks for your prompt reply. Though this is quite a limitation, there is also something wrong with (the syntax?) of my code. The variabel doesn't change. Let's try another example with the <entry> tag. Outside of the dialog I've defined a variable TEXT="home". My code would look like this:
Code:
   <togglebutton>
      <input file stock="gtk-'"$TEXT"'"></input>
      <variable>BTN</variable>
      <action>if true let TEXT="yes"</action>
      <action>if false let TEXT="no"</action>
      <action>refresh:BTN</action>
   </togglebutton>


Doesn't work either. The button shows the home icon, but doesn't change. No wonder: After I've left the dialog the variable hasn't changed to "yes" or "no". Where is my mistake? Changing the value of the variable is my primary problem, having the dialog pick up the value would be the next.

@don570
Your manual is the first thing I look for when I need a good example. Thanks for work Very Happy Actually I studied your togglebutton example before posting, but I don't want to use icons, and if I must use them, I would like to stick to gtk stock icons. Does it really have to be svg icons?
Back to top
View user's profile Send_private_message 
zigbert


Joined: 29 Mar 2006
Posts: 5788
Location: Valåmoen, Norway

PostPosted: Wed 05 Feb 2014, 03:49    Post_subject:  

The mistake is the call for gtk stock icons. - You should refresh a file. don570 shows the solution.
When you first get used to svg, it is rather simple and powerful.


Sigmund

_________________
Stardust resources
Back to top
View user's profile Send_private_message Visit_website 
don570


Joined: 10 Mar 2010
Posts: 3380
Location: Ontario

PostPosted: Thu 06 Feb 2014, 15:27    Post_subject:  

To avoid using an SVG image button I tried a togglebutton instead.

http://murga-linux.com/puppy/viewtopic.php?p=756690#756690



________________________________________________

In my manual this is example that is closest ---->
The button changes color and label text changes. The signal that is
emitted changes the entry box text.


_____________________________________
Back to top
View user's profile Send_private_message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 477
Location: Japan

PostPosted: Sat 22 Feb 2014, 22:18    Post_subject:  

zigbert wrote:
The mistake is the call for gtk stock icons.
Hmmm...I'm afraid I failed to discribe my problem properly - though I tried to put it into the thread title. This thread was intended to clarify variable values and their scope, not togglebuttons and their limitations. I used togglebuttons only as an example. If this was a bad example, I'm sorry.
But I think I figured it out myself more or less: The variables in the main script that builds the dialog are accessible during the creation process. Once gtkdialog runs the MAIN_DIALOG (or whatever it was called) variable, this is done in a subshell (?), and this subshell has no access to the variables of other shells, not even the starting shell (unless the variables had been exported). But even in case of exported variables they would be read-only (?) and therefore can't be changed. So my real mistake was to assume that I can change the variable TEXT (containing the value "home") from within the dialog. My second mistake seems to be the value assignment in the <action> tags. Given that the TEXT variables declared in the main script and the variable in the dialog have nothing in common except the name, following assignment would fail:
Code:
<action>if true let TEXT="yes";xmessage $TEXT</action>

This also fails:
Code:
<action>TEXT="yes"</action>
<action>xmessage $TEXT</action>

However this works:
Code:
<action>TEXT="yes";xmessage $TEXT</action>

So we have exported read-only variables that can be used anywhere in the dialog, read-only variables declared with the <variable> tags that also can be used anywhere in the dialog, and finally read/write variables declared in the <action> tags that are local to the tag where they are declared. A bit confusing, but correct so far?


don570 wrote:
In my manual this is example that is closest
I didn't find this example in your manual.

don570 wrote:
To avoid using an SVG image button I tried a togglebutton instead.
Thanks, I've seen this example and it's a bit funny. The irony here: The togglebutton is the only button that does NOT toggle. The image doesn't change, the label doesn't change, but this would be essential for a togglebutton since the user needs a clue what the button will trigger.
I've played with your example and came up with a version that changes button image and label. I simply use 2 buttons (is that cheating?), which for the user appear as one. This also avoids the need to juggle symlinks and all other problems associated with using 2 sets of resources for only 1 button:
Two_toggled_buttons.gz
Description  Remove the fake gz extension
gz

 Download 
Filename  Two_toggled_buttons.gz 
Filesize  2.96 KB 
Downloaded  77 Time(s) 

Edited_time_total
Back to top
View user's profile Send_private_message 
Moose On The Loose


Joined: 24 Feb 2011
Posts: 535

PostPosted: Sun 23 Feb 2014, 13:01    Post_subject:  

MochiMoppel wrote:

Code:
<action>TEXT="yes"</action>
<action>xmessage $TEXT</action>

However this works:
Code:
<action>TEXT="yes";xmessage $TEXT</action>



I have found a reliable way to think about this sort of thing. In all cases where gtkdialog doesn't know the item used directly, I think of <action> as meaning "fire up a subshell and pass this string as a command to it". The subshell closes at the end of the command.

When the <action> starts with an item that gtkdialog knows then it does the work internally.

This breaks <action> into two very different things. The differences in behavior are kept from being confused this way. Variables created in the subshell only live until the end of the subshell. This explains why "TEXT" goes away between <action> lines.
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0794s ][ Queries: 13 (0.0059s) ][ GZIP on ]