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
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#1471 Post by MochiMoppel »

misko_2083 wrote:I would try next: :)

Code: Select all

 step=$(( 100 / cnt )).$(( (100 * 100 / cnt) % 100 ))
1.78
I wouldn't :lol:
Remember that you would still have to add these values up. In bash? Good luck!

I find my approach much easier. Besides: The progressbar doesn't seem to care about fractions. Non-numeric characters after an integer are ignored. It doesn't matter if you echo a value of 1 or 1.99999 or even 1blabla, the bar will always show exactly 1% .

User avatar
TwoPuppies
Posts: 77
Joined: Wed 29 Dec 2010, 05:13
Location: Melbourne, Australia

#1472 Post by TwoPuppies »

MochiMoppel wrote:Change step=$((100/cnt)) to step=$((100000/cnt))
and
echo $bar to echo $((bar/1000))
This worked as expected. The Progress Bar continued all the way to the end before the window closed. Thanks MochiMoppel.
misko_2083 wrote:I would try next: :)

Code: Select all

step=$(( 100 / cnt )).$(( (100 * 100 / cnt) % 100 ))
This caused the Progress Bar to freeze after only one Package was installed. No more Packages installed after that.
[color=#006699]What you really need is two puppies:
Puppy Linux, and the sort with four legs and a tail.[/color]

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

#1473 Post by MochiMoppel »

TwoPuppies wrote:This worked as expected.
Image

User avatar
misko_2083
Posts: 114
Joined: Tue 08 Nov 2016, 13:42

#1474 Post by misko_2083 »

MochiMoppel wrote:
misko_2083 wrote:I would try next: :)

Code: Select all

 step=$(( 100 / cnt )).$(( (100 * 100 / cnt) % 100 ))
1.78
I wouldn't :lol:
Remember that you would still have to add these values up. In bash? Good luck!

I find my approach much easier. Besides: The progressbar doesn't seem to care about fractions. Non-numeric characters after an integer are ignored. It doesn't matter if you echo a value of 1 or 1.99999 or even 1blabla, the bar will always show exactly 1% .
I know, just forgot to mention that I used the pure bash calculator.
I saved && made executable this script https://github.com/bluebat/.bash/blob/master/bashbc.sh

Code: Select all

    IFS=$'\n'
    array=($PACKAGELIST)
    cnt=${#array[@]}

    step=$(( 100 / cnt )).$(( (100 * 100 / cnt) % 100 ))
    bar=$step
    for ((c=0;c<$cnt;c++));do
        file=${array[$c]}
        echo $bar                #progress indicator (MUST be number)
        echo $file               #text within progress bar (MUST NOT start with number)
       # set the path to bashbc.sh here !
        bar=$(scale=2 bashbc.sh $bar+$step)        #increase progress indicator
    done;
    echo 100  
The calculator script works like this

Code: Select all

bashbc.sh 2.555+6.335
8.89
scale=2 bashbc.sh 2*(3/7)
0.84
Maybe not so precise but good enough for a progress bar.

User avatar
recobayu
Posts: 387
Joined: Wed 15 Sep 2010, 22:48
Location: indonesia

#1475 Post by recobayu »

I have 20 button inside of scrollable vbox. When I use down arrow keyboard to move from one button to another button below that, after some button, the button not appear. Butwhen I usemoise to scroll down, it is select on that button. How to make the button always seen when we use down arrow keyboard? Just like tree. Is it possible? Thank you.

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

#1476 Post by MochiMoppel »

recobayu wrote:How to make the button always seen when we use down arrow keyboard? Just like tree. Is it possible?
No.

User avatar
recobayu
Posts: 387
Joined: Wed 15 Sep 2010, 22:48
Location: indonesia

#1477 Post by recobayu »

I have an exploration about bolding a text that use-markup. We must call a function outside of gtkdialog code. Like this:

Code: Select all

#!/bin/sh
touch tebalku
tebal(){
	printf "<b>$e</b>" > tebalku
}
export -f tebal

echo '
<window>
	<vbox>
		<entry>
			<action>tebal</action>
			<action>refresh:tt</action>
			<variable>e</variable>
		</entry>
		<text xalign="1" use-markup="true">
			<input file>tebalku</input>
			<variable>tt</variable>
		</text>
	</vbox>
</window>'|gtkdialog -s
I try to add printf "<b>"$e"</b>" in action of entry. But it fail. So I must call it from outside function.
Attachments
Screenshot.png
bold text automatically
(3.16 KiB) Downloaded 513 times

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

#1478 Post by MochiMoppel »

recobayu wrote:I try to add printf "<b>"$e"</b>" in action of entry. But it fail.
...not when you escape the pango tags:

Code: Select all

#!/bin/bash
echo ' 
<window> 
<vbox> 
	<entry> 
		<action>refresh:tt</action> 
		<variable>e</variable> 
	</entry> 
	<text xalign="1" use-markup="true"> 
		<input>printf \<b\>"$e"\</b\></input> 
		<variable>tt</variable> 
	</text> 
</vbox> 
</window>'|gtkdialog -s

User avatar
d4rkn1ght
Posts: 55
Joined: Wed 20 Jan 2010, 00:47
Contact:

Button Delay

#1479 Post by d4rkn1ght »

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>

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

Re: Button Delay

#1480 Post by Moose On The Loose »

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.

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 156 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

Post Reply