GtkDialog - tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
d4rkn1ght
Posts: 55
Joined: Wed 20 Jan 2010, 00:47
Contact:

Re: Button Delay

#1481 Post 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)

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

a script to explain the refresh action

#1482 Post 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
Attachments
refresh.sh.gz
remove fake extension
(2.19 KiB) Downloaded 165 times
screenshot-example.png
(9.9 KiB) Downloaded 378 times

User avatar
fabrice_035
Posts: 765
Joined: Mon 28 Apr 2014, 17:54
Location: Bretagne / France

#1483 Post 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
Attachments
user3.jpg
(24.77 KiB) Downloaded 218 times
user2.jpg
(24.75 KiB) Downloaded 218 times
user1.jpg
(24.82 KiB) Downloaded 218 times
Bionicpup64-8.0 _ Kernel 5.4.27-64oz _ Asus Rog GL752

lxgr
Posts: 2
Joined: Tue 28 Apr 2020, 09:56

Hbox alignment

#1484 Post 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.

User avatar
Moose On The Loose
Posts: 965
Joined: Thu 24 Feb 2011, 14:54

Re: Hbox alignment

#1485 Post 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

lxgr
Posts: 2
Joined: Tue 28 Apr 2020, 09:56

Re: Hbox alignment

#1486 Post 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

User avatar
UncleScrooge
Posts: 104
Joined: Tue 07 Apr 2020, 06:07
Location: Norway

#1487 Post by UncleScrooge »

Hi guys,

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

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

User avatar
UncleScrooge
Posts: 104
Joined: Tue 07 Apr 2020, 06:07
Location: Norway

#1488 Post 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?

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#1489 Post 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!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
UncleScrooge
Posts: 104
Joined: Tue 07 Apr 2020, 06:07
Location: Norway

#1490 Post by UncleScrooge »

@SFR

cheers mate and happy mayday

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

#1491 Post 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.

User avatar
UncleScrooge
Posts: 104
Joined: Tue 07 Apr 2020, 06:07
Location: Norway

#1492 Post 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.

User avatar
UncleScrooge
Posts: 104
Joined: Tue 07 Apr 2020, 06:07
Location: Norway

Again on combotext widget

#1493 Post 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

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

Re: Again on combotext widget

#1494 Post 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.

User avatar
UncleScrooge
Posts: 104
Joined: Tue 07 Apr 2020, 06:07
Location: Norway

#1495 Post 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 ....

User avatar
UncleScrooge
Posts: 104
Joined: Tue 07 Apr 2020, 06:07
Location: Norway

Re: Again on combotext widget

#1496 Post by UncleScrooge »

deleted by me: irrelevant
Last edited by UncleScrooge on Fri 08 May 2020, 06:13, edited 1 time in total.

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

Re: Again on combotext widget

#1497 Post 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.
Attachments
diagram.jpg
(106.54 KiB) Downloaded 71 times

User avatar
UncleScrooge
Posts: 104
Joined: Tue 07 Apr 2020, 06:07
Location: Norway

Re: Again on combotext widget

#1498 Post by UncleScrooge »

MochiMoppel wrote:......
sorry to have bothered you. just forget it

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

Re: Again on combotext widget

#1499 Post 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

User avatar
smokey01
Posts: 2813
Joined: Sat 30 Dec 2006, 23:15
Location: South Australia :-(
Contact:

#1500 Post 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

Post Reply