Page 75 of 76

Re: Button Delay

Posted: Wed 25 Dec 2019, 20:14
by d4rkn1ght
Moose On The Loose wrote:
d4rkn1ght wrote:First of all, I’m a beginner. All I’ve done so far is pasted code from other sources and molded to the direction I want to go. I still don’t know how to actually make something like you guys. :P

Anyway, I’ve been trying to have a button that pauses for a few seconds before it closes the button window.

This is what I have so far. Is this right? It works in Tahrpup.

Code: Select all

<button> 
  <label>Connect</label>
  <input file icon="gtk-yes"></input>
  <action>/usr/bin/start-gtkdialog-script.sh &</action>
  <action>sleep 8;</action>
  <action>Exit:exit &</action>
</button>
Yes, that looks about right. I tend to make only one action per button but what you have should work. I do question the "&" in the last action. I suspect that it just gets ignored.
Thank you! 8)

a script to explain the refresh action

Posted: Thu 30 Jan 2020, 22:05
by don570
For beginners here is a script to explain the refresh action when it is given to a entry widget by another widget.
Explanation: Choosing a folder starts the estimate function.
Estimate function will return a number above zero
(This is the time estimate of the compression. The formula is based on SIZE)
Variable TIME is updated i.e. refreshed

Code: Select all

<action>refresh:TIME</action>


This can be done over and over.

Code: Select all

#!/bin/bash
# example to show refresh

export TEXTDOMAIN=refresh.sh
export OUTPUT_CHARSET=UTF-8

TEXT="$(gettext 'Select a folder')"

###############################################
#                                             #
#                 ESTIMATE                    #
#                                             #
###############################################
estimate(){

SIZE=`du -s "$DIR"  | awk '{print $1}'`
let "TIME_ESTIMATE = $SIZE * 40 / 1029000"
if  [   "$TIME_ESTIMATE" -le 0  ];then
TIME_ESTIMATE=1
fi
echo $TIME_ESTIMATE > /tmp/compression_estimate
}
export -f estimate

###############################################
#                                             #
#                 MAIN GUI                    #
#                                             #
###############################################

export EXAMPLE='
<window title="Example"  resizable="false">
<vbox   width-request="500">

        <text height-request="10"><label>""</label></text>
        <text><label>"'$TEXT'"</label></text>
 
<hbox>       
        <entry accept="directory"  activates_default="true">        
        <input>cat  /tmp/compression_path</input>
        <variable>DIR</variable>
        </entry>
        <button  tooltip-text="'$(gettext 'Select a directory')'">
        <input file stock="gtk-open"></input>
        <action type="fileselect">DIR</action>
        <action>estimate</action>  
        <action>refresh:TIME</action>               
       </button>   
</hbox>
<text height-request="20"><label>""</label></text> 
<hseparator></hseparator>
<hbox  homogeneous="true"> 
      <text>
      <label>'$(gettext 'Time for Compression')'</label>
       </text></hbox>
<hbox  homogeneous="true"> 
<hbox width-request="130">            
      <entry editable="false">    
      <variable>TIME</variable>
      <input>cat /tmp/compression_estimate</input>
      </entry>
      <text>
      <label>'$(gettext 'second(s)')'</label>
      </text>
</hbox>     
</hbox>   
  
 <hbox> 
 <button>
        <input file stock="gtk-cancel"></input>
        <label>'$(gettext 'Quit')'</label>
        <action type="exit">CLOSE</action>
</button>    
</hbox>
</vbox>
</window>'

gtkdialog --center -p EXAMPLE

rm -f  /tmp/compression_*

More advanced examples http://murga-linux.com/puppy/viewtopic. ... 151#648151

Posted: Sat 25 Apr 2020, 11:25
by fabrice_035
I wanted to see if it was possible to choose an area on a picture to perform an action, that's how I did it.

for this example you need 3 different images that you can find below
they must be in the program folder and each image is named :
user1.jpg user2.jpg user3.jpg


Code: Select all

#!/bin/sh
# example by fabrice_035, 25 avril 2020
# button selector into picture
# need 3 differents pictures, user1.jpg user2.jpg user3.jpg
# 


# default picture, defaut user 1
cp -f user1.jpg tmp.jpg
echo "user 1" > user.txt


show(){

# take only right button
if [ "$PTR_BTN" != "1" ] ; then
exit
fi
	
# show x axis y axis
echo "$PTR_X $PTR_Y$ $PTR_BTN"

#enter y axis, min 20 max 69
case $PTR_Y in
	[2-6][0-9] )
	echo "y"
	
# enter x axis
# first button, min 21, max 69
	case $PTR_X in
 2[1-9]|[3-6][0-9])
  echo "bouton 1"
 cp -f user1.jpg tmp.jpg
echo "user 1" > user.txt
    ;;
# second button, min 155 max 199
  1[5-9][0-9])
    echo "bouton 2"
cp -f user2.jpg tmp.jpg
echo "user 2" > user.txt
    ;;
    
# third button, min 270 max 319
   2[7-9][0-9]|3[0-1][0-9])
    echo "bouton 3"
cp -f user3.jpg tmp.jpg
echo "user 3" > user.txt
   esac
  ;;

esac
}
export -f show

GTKDIALOG=gtkdialog

MAIN_DIALOG='
<window title="Button Selector" icon_name="gtk-media-play"> 

	<vbox>
			<eventbox above-child="false" visible-window="false"> 
				<pixmap sensitive="true" auto-refresh="true" visible="true">
				 <variable>PIXMAP</variable>
				 	<sensitive>true</sensitive>	
                <input file>tmp.jpg</input>
				</pixmap>
				
		<action signal="button-press-event">show</action> 
		 <action signal="button-press-event">refresh:USER</action>
</eventbox> 
		<hbox space-expand="true" space-fill="true">
			<entry editable="false" can-focus="false">
					<variable>USER</variable>
					<input file>user.txt</input>
				</entry>
		</hbox>
	</vbox>
</window>
'

export MAIN_DIALOG

case $1 in
	-d | --dump) echo "$MAIN_DIALOG" ;;
	*) $GTKDIALOG --program=MAIN_DIALOG ;;
esac

Try it!

Regard

Hbox alignment

Posted: Tue 28 Apr 2020, 10:00
by lxgr
Hey, does someone know how to align a a hbox on the left and not at the right of a window?
Would be nice to know.

Re: Hbox alignment

Posted: Tue 28 Apr 2020, 14:59
by Moose On The Loose
lxgr wrote:Hey, does someone know how to align a a hbox on the left and not at the right of a window?
Would be nice to know.
I would try:

Code: Select all

<hbox xalign="0">
Changing the "0" to see what it does.

there is also a width-request="123" thing

Re: Hbox alignment

Posted: Tue 28 Apr 2020, 17:02
by lxgr
Moose On The Loose wrote:
lxgr wrote:Hey, does someone know how to align a a hbox on the left and not at the right of a window?
Would be nice to know.
I would try:

Code: Select all

<hbox xalign="0">
Changing the "0" to see what it does.

there is also a width-request="123" thing
Doesn't work with h/vbox
Just with text and pixmap etc. ...

But I got what I want via another way

Posted: Wed 29 Apr 2020, 16:42
by UncleScrooge
Hi guys,

is there any IDE for GTKDialog. like GLADE for GTK+?

coz I'm a slob.........

Posted: Fri 01 May 2020, 17:14
by UncleScrooge
Hi again
total newbie in GTK_dialog

I have two comboboxtext widgets, and I need to enable the second one only if choice 3 or choice 4 of the first combo are selected. disable combo2 in the other cases

Code: Select all

<comboboxtext>
	<variable>firstCombo</variable>
	<item>choice 1</item>		## disable second combo
	<item>choice 2</item>		## disable second combo
	<item>choice 3</item>		## enable second combo	
	<item>choice 4</item>		## enable second combo
</comboboxtext>
<comboboxtext>
	<variable>secondCombo</variable>
	<sensitive>false</sensitive>
	<item>choice 1</item>
	<item>choice 2</item>
	<item>choice 3</item>
	<item>choice 4</item>
</comboboxtext>
how do I do that?

Posted: Fri 01 May 2020, 17:53
by SFR
UncleScrooge wrote:is there any IDE for GTKDialog. like GLADE for GTK+?
I'm not aware of any.
UncleScrooge wrote:I have two comboboxtext widgets, and I need to enable the second one only if choice 3 or choice 4 of the first combo are selected. disable combo2 in the other cases
[...]
how do I do that?

Like this:

Code: Select all

#!/bin/sh

echo '
<vbox>

<comboboxtext>
   <variable>firstCombo</variable>
   <item>choice 1</item>
   <item>choice 2</item>
   <item>choice 3</item>  
   <item>choice 4</item>
   <action condition="command_is_true( [ "$firstCombo" = "choice 1" ] || [ "$firstCombo" = "choice 2" ] && echo true )">disable:secondCombo</action>
   <action condition="command_is_true( [ "$firstCombo" = "choice 3" ] || [ "$firstCombo" = "choice 4" ] && echo true )">enable:secondCombo</action>
</comboboxtext>
<comboboxtext>
   <variable>secondCombo</variable>
   <sensitive>false</sensitive>
   <item>choice 1</item>
   <item>choice 2</item>
   <item>choice 3</item>
   <item>choice 4</item>
</comboboxtext>

</vbox>
' | gtkdialog -s
It's not very convenient, but I don't know any other way to do it.

Greetings!

Posted: Fri 01 May 2020, 19:10
by UncleScrooge
@SFR

cheers mate and happy mayday

Posted: Sat 02 May 2020, 01:59
by MochiMoppel
SFR wrote:It's not very convenient, but I don't know any other way to do it.
I don't know any other way either :cry: This can become pretty nasty when there are more than just 2 items to trigger an enabled second box.

Maybe using a regex can bring some relief:

Code: Select all

<action condition="command_is_true( [[ $firstCombo =~ (choice 3|choice 4) ]] || echo true )">disable:secondCombo</action> 
<action condition="command_is_true( [[ $firstCombo =~ (choice 3|choice 4) ]] && echo true )">enable:secondCombo</action> 
More item labels could be added to (choice 3|choice 4) and unique parts of the labels would be sufficient, so for the demo code (3|4) would do.

Posted: Sun 03 May 2020, 06:01
by UncleScrooge
@ SFR and MochiMoppel

thnx guys
following your hints I am actually creating a pyramidal block of functions handling different cases for a set of different widgets and their desired intreactions.
thus I'll end up in the dialog config file with a lot of:

Code: Select all

<action condition="command_is_true(testCondition $widgetVar "RuleN" arg1 arg2 ... argN)">command_or_function</action>
that hopefully will keep the dialog config structure kinda more readable, while in the code function(s) one can see the logic behind the command firing condition.

Again on combotext widget

Posted: Wed 06 May 2020, 06:06
by UncleScrooge
Hi guys,

is it possible to dynamically add/delete items in a combotext widget at runtime?

at the moment, since I use a separate .conf file to define the GUI, what I am doing is to have a function which modifies the GUI.conf file, then kills the gtkdialog process, refreshes the MAIN_DIALOG variable with the updated GUI.conf and re-launches the GUI.
which to me looks like a very ugly way to do the job (not to mention that the dead GUI shadow hangs in the desktop background hovering like a zombie, so if I have to repeat the process several times I end up with an army of gloomy zombies in the background)

And btw, is there any way to send signals from the code to the GUI so it can exit nicely instead of terminating it by "kill $pidof_GTKDialog" (which causes the hovering zombie problem above)?
so summarizing:
  1. can the items in the comboboxtext be added/deleted at runtime? if yes how?
  2. can the script send signals to the live GTKDialog? if yes, how?
thnx for the patience

PS: on question 1: I thought the comboboxtext <input> or <input file> directive would do the job (it works fine for the text widget for instance, although I have to use "cat filename" as command in the <input> directive), but here it seems to do nothing, or I just misinterpreted the concept of this directive

Re: Again on combotext widget

Posted: Wed 06 May 2020, 07:43
by MochiMoppel
UncleScrooge wrote:is it possible to dynamically add/delete items in a combotext widget at runtime?
Yes.

Code: Select all

#!/bin/bash
echo 'choice 1
choice 2
choice 3
choice 4' > /tmp/itemlist

echo ' 
<vbox> 
<comboboxtext> 
	<variable>firstCombo</variable>
	<input file>/tmp/itemlist</input>
</comboboxtext> 
<button label="Remove last item">
	<action>echo "$(head -n-1 /tmp/itemlist)" > /tmp/itemlist</action>
	<action>refresh:firstCombo</action>
</button>
<button label="Add item blabla">
	<action>echo blabla >> /tmp/itemlist</action>
	<action>refresh:firstCombo</action>
</button>
</vbox> 
 ' | gtkdialog -s
can the script send signals to the live GTKDialog? if yes, how?
What script? And what is wrong with the kill command? If you do it right and kill the parent and not the child you shouldn't see zombies. I'm also not sure what you mean by conf file (external GUI file, gtkdialog include file or a bash sourced file?). In principle you can edit external files from within the GUI, then restart the GUI with the new values that you wrote to the conf file. A simple demo showing what you try to achieve would be helpful.

Posted: Wed 06 May 2020, 14:49
by UncleScrooge
@ MochiMoppel

your code example made me go back to my script and... I am a moron, Looks like I forgot a dot in the input file path ....

Re: Again on combotext widget

Posted: Thu 07 May 2020, 09:00
by UncleScrooge
deleted by me: irrelevant

Re: Again on combotext widget

Posted: Thu 07 May 2020, 10:04
by MochiMoppel
UncleScrooge wrote:here is my final goal:
Accessing your linked site doesn't make the diagram more readable but at least it provides a valuable tip how to process a can of Coca Cola properly.
I am sorry if all these sounds like dumb gibberish
Not exactly gibberish but this doesn't mean that it makes sense to me, especially the red block. How does your blue script call external functions? By source command? And how would the MAIN_GUI then access the same functions? And why and how would the red functions and not the blue script kill the GUI? The more I look at the diagram the more questions pop up. Without a demo I don't understand this. Maybe someone else does.

Re: Again on combotext widget

Posted: Thu 07 May 2020, 12:39
by UncleScrooge
MochiMoppel wrote:......
sorry to have bothered you. just forget it

Re: Again on combotext widget

Posted: Tue 26 May 2020, 22:33
by wiak
UncleScrooge wrote:And btw, is there any way to send signals from the code to the GUI so it can exit nicely instead of terminating it by "kill $pidof_GTKDialog" (which causes the hovering zombie problem above)?
I can't give you an answer to the above per se, but just agreeing that gtkdialog-based scripts, used to often have problems with zombies hanging around after use (and still does if you don't take care to clean up processes sometimes). I remember working on that issue in some of my own programs in the early days, but too long ago to remember details of solutions I adopted (nowadays I tend to just use the 'pattern' that worked so I don't need to think about it).

It certainly is important to keep control of process ids in shell scripts that fork child processes generally, so that is definitely the case with gtkdialog since it is being run as a child of the main script process and having variables exported to it. I remember that the main issue often occurred if the window decoration X box was used to close the dialog gui rather than the 'Close' button - for that one, I believe I use shell 'trap' to notice the abrupt interrupt, which runs a function to make sure all running processes involved get cleaned up correctly. Sorry for no details - just a confirmation that it was/can-be a common issue.

As for which widgets <input> works with, you can generally find that out from Gtkdialog reference. 01micko has an online version for Puppy:

http://01micko.com/reference/

A more accurate understanding can be obtained if you know C - just look at the source code, which is 'sometimes' commented.

wiak

Posted: Tue 02 Jun 2020, 11:58
by smokey01
Is there a way to make a functional progress bar that actually shows progress and not just activity?

I would like to be able to have a progress bar that shows the progress of a function with a number of different commands.

function() {
command 1
command 2
command 3
}
export -f function