How to clear and modify entry boxes in gtk using variables?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
arivas_2005
Posts: 212
Joined: Sun 25 Feb 2007, 14:39

How to clear and modify entry boxes in gtk using variables?

#1 Post by arivas_2005 »

regards

i want to learn a little bit of gtk
my auto-lesson " Using Box and Variables (no files, only variables)"
in " GtkDialog - tips" there are many examples
hence I took the following lines
but many scripts, I do not understand them
like the following

in my next script
-- entry B should display mid of A
1) I can not clean two boxes A and B
2) I can not insert mid_A value through ORIGINALFILE=${ORIGINALFILE:$mid_A} in box B
3) I can not clean box A at the time of drag and drop

Code: Select all

#!/bin/sh
RIGHT=550 DOWN=36 WIDTH=600 HEIGHT=150   # define variables with defaults 

unset ORIGINALFILE
unset length_A
unset mid_A
unset PDFFILE

function change_pdf_A() {
length_A=${#ORIGINALFILE}
let mid_A=length_A/2
ORIGINALFILE=${ORIGINALFILE:$mid_A}
Xdialog --msgbox "$ORIGINALFILE"" pdf_A" x
}

function change_pdf_B() {
ORIGINALFILE=`echo "Hello John -fill box B-"`
Xdialog --msgbox "$ORIGINALFILE"" pdf_B" x
}

export -f change_pdf_A
export -f change_pdf_B

export MAIN_DIALOG='
<window title="Learning gtk: clear and modify boxs using variables">
	<vbox>
	    <text use-markup="true">
			<label>"<span color='"'blue'"' font-family='"'mono'"' weight='"'bold'"' size='"'x-large'"'><big>Learning kgt I</big></span>"
			</label>
		  </text>	
	    <text use-markup="true">
		    <label>"<span color='"'brown'"' weight='"'bold'"' size='"'large'"' >drag ando drop text to A box</span>"
			</label>
    </text>
    
		<hbox>
			<text label="A" xalign="0"></text>
			<entry>
				<variable>ORIGINALFILE</variable>
				<action>refresh:PDFFILE</action>
				<action signal="changed">change_pdf_A</action>
				<action>eval ORIGINALFILE</action>
				<action>refresh:PDFFILE</action>
			</entry>
		</hbox>
		
		<hbox>
			<text label="B" xalign="0"></text>		
			<entry>
				<variable>PDFFILE</variable>
				<input>echo $ORIGINALFILE</input>			
			</entry>
		</hbox>
		
		<hbox>
			<button>
				<label>Clear A and B</label>
				<action>ORIGINALFILE=`ECHO ""`</action>
				 <action>refresh:ORIGINALFILE</action>
			</button>
			<button>
				<label>Refresh B</label>
				<action>change_pdf_B</action>
			</button>
			<button>
				<label>Exit</label>
				 <action>exit:Exit</action>
			</button>			
	  </hbox>
	  
	</vbox>

</window>
'
# 
# gtkdialog -p GUI -G ${1-${WIDTH}x${HEIGHT}+${RIGHT}+${DOWN}}
#   for STATEMENTS in $(gtkdialog3 -p MAIN_DIALOG); do
I=$IFS; IFS=""
for STATEMENTS in $(gtkdialog -p MAIN_DIALOG -G ${1-${WIDTH}x${HEIGHT}+${RIGHT}+${DOWN}}); do
   eval $STATEMENTS
done
IFS=$I
#eval gtkdialog -p MAIN_DIALOG
unset RIGHT
unset DOWN
unset WIDTH
unset HEIGHT 
Xdialog --msgbox "$PDFFILE"" \n""$ORIGINALFILE" x

How could I do it?
Thank you very much for the help
exit
Last edited by arivas_2005 on Sun 01 Oct 2017, 03:26, edited 1 time in total.

arivas_2005
Posts: 212
Joined: Sun 25 Feb 2007, 14:39

#2 Post by arivas_2005 »

regards. here again. :oops:
I have spent hours and hours looking for ..
I have reviewed hundreds of pages.
and I only found something similar

Code: Select all

MY_VAR="DEFAULT VALUE"
export script='
<vbox>
  <entry>
    <variable>ENTRY</variable>
    <input>echo -n '"$MY_VAR"'</input>
  </entry>
  <button>
    <label>Change</label>
    <action>MY_VAR="NEW VALUE"</action>    
    <action>refresh:ENTRY</action>
  </button>
</vbox>'
gtkdialog -p script
http://www.murga-linux.com/puppy/viewto ... &start=660
(users: @EDDIE_THE_HEAD and @thunor, year: 2012)
without resolving
Then,
It is not possible to use variables to pass data between entry ?
--- Is that it has not yet changed that property (use variables to pass data) in Gtk (2017)?

i will appreciate your support
Thanks you!

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#3 Post by MochiMoppel »

It is resolved.
Thunor explained it 2 times to EDDIE_THE_HEAD.
thunor wrote:Widget variables (the ones that you have created and named yourself) will be placed into the shell when an action executes so that you can read the contents of widgets, but you can't change the contents of widgets by modifying their variables -- you'll likely want something like this:

Code: Select all

<entry>
	<variable>ENTRY</variable>
	<input file>/tmp/inputfile</input>
</entry>
<button>
	<label>Change</label>
	<action>echo "NEW VALUE" > /tmp/inputfile</action>
	<action>refresh:ENTRY</action>
</button>

arivas_2005
Posts: 212
Joined: Sun 25 Feb 2007, 14:39

#4 Post by arivas_2005 »

@ MochiMoppel, Thanks for your reply
then
It is impossible to change the alignment in an entry?
I ask you to comment if this applies also to variables in the properties.
align text in an entry on the fly (o button too...)
see the next code, for example.

Code: Select all

#!/bin/sh 
export v_align=0.5


MY_VAR="DEFAULT VALUE"
export script='
<hbox width-request="400">
<vbox>
  <entry width-request="250" xalign="'$v_align'">
    <variable>ENTRY</variable>
    <input>echo -n '"$MY_VAR"'</input>
  </entry>
  <hbox>
		<button>
			       <label>Change left</label>
			       <action>v_align="0"</action>
			       <action>refresh:ENTRY</action>
		</button>
		<button>
		         <label>Change center</label>
			       <action>v_align="0.5"</action>
			       <action>refresh:ENTRY</action>
		 </button>
		 <button>
		         <label>Change right</label>
			       <action>v_align="1"</action>
			       <action>refresh:ENTRY</action>
		 </button>
  </hbox>
</vbox>
</hbox>'
gtkdialog -p script
again, i will appreciate your support
Thanks you!

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#5 Post by MochiMoppel »

Unfortunately not possible. Almost all of gtkdialog's properties are read-only. There are only 2 properties that I'm aware of that you can set while gtkdialog is running: visibility and sensibility.

Post Reply