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
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

#721 Post by thunor »

RSH wrote:Hi.

I wanted to test the above posted script but it gives me an gtkdialog error in gtkdialog3, gtidialog4 and gtkdialog5.

Which version is used for this script?

RSH
Hi RSH

Change all <variable export="false"> to <variable> and it'll work. I'll edit the script and remove them, they're not necessary.

Regards,
Thunor

User avatar
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

#722 Post by thunor »

Here's another top tip:

A text widget that has space-expand and space-fill set to true can be used as a spacer to push neighbouring widgets in certain directions.

Here the spacer text is "[]" so you can see it -- drag the window out and watch the button.

Code: Select all

#!/bin/sh

GTKDIALOG=gtkdialog

Spacer="[]"

MAIN_DIALOG='
<window title="Spacer Test" window-position="1">
	<vbox>
		<hbox>
			<button space-expand="false" space-fill="false">
				<label>This button will stay put</label>
				<input file stock="gtk-about"></input>
			</button>
			<text space-expand="true" space-fill="true">
				<label>"'$Spacer'"</label>
			</text>
		</hbox>
   </vbox>
</window>
'
export MAIN_DIALOG

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

User avatar
oldyeller
Posts: 889
Joined: Tue 15 Nov 2011, 14:26
Location: Alaska

#723 Post by oldyeller »

Hello Everyone,

I have a question, Has anyone done hyper-links in gtkdialog? If so how do you go about doing it.

What I would like to do is link from one program to another. Hit a word in one program to show the answer in another program.

Any help would be great thanks.


Cheers

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

#724 Post by don570 »

Hit a word in one program to show the answer in another program
If you look at the code in puppy clock
you will see a button called 'World clock'

What it does is launch a second program.

You should check out how I wrote it.
When the button is first pressed, I check the version of
gtkdialog to make sure it is recent. Then I launch the second program.

_____________________________________________

User avatar
oldyeller
Posts: 889
Joined: Tue 15 Nov 2011, 14:26
Location: Alaska

#725 Post by oldyeller »

Hi don570,

Will take a look and see if that is what I am looking for.


Cheers

EDIT: Hi don570 took a look not what I was looking for thanks, but I did remember that what I need is just a button to go to one to another program.

Just need to look at my code.

Cheers

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

#726 Post by don570 »

Yes-No box with color

The Yes-No box in Xdialog is rather limited and the buttons
don't actually say 'Yes-No'

Image

So I wrote a script to be a replacement to the Xdialog Yes-No box.
Here's a picture of the result.

Image
Attachments
YES-NO.gz
Remove .gz extension to obtain script
(2.28 KiB) Downloaded 375 times
Last edited by don570 on Sat 16 Feb 2013, 19:36, edited 2 times in total.

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

#727 Post by don570 »

continuing......

The script has been made as general as possible.
The script first creats a file in /root.
Then the Yes-No box appears and asks if you want to overwrite the file
with different text. 'Yes' results in overwriting of the file and the
window closes. You can check to see if the file has been overwritten.

When the user clicks 'No' an alternate action is possible.
It is of course possible to have the 'No' button have one action

EDIT: I changed the script from using an if statement to a case statement.
This clearly shows that three posibilities are possible

1) YES
2) NO
3) Click on corner close box will cause cancellation

Code: Select all

#!/bin/bash
# demonstrate  YES-NO box by don570

for P in gtkdialog4 gtkdialog3 gtkdialog; do
  GTKDIALOG=$(which $P) && break
done

# create a message for demonstration
echo  "first message" > /root/demonstrate-script.txt
TEXT="TEXT"  # demonstrate a substitution in text

#  put the warning-function near beginning of script
# orange color is #DA7A05
# purple color is #A900FF

warning-function(){
export MYWINDOW="
<window title=\"Warning\">
<frame>
<vbox>
<frame>
     <pixmap>
     <width>48</width>
     <input file>/usr/share/pixmaps/hash.xpm</input>
     </pixmap>
   <vbox>
   <text width-request=\"100\"><label>Color Frame</label></text>
   <text use-markup=\"true\"><label>\"<b><u><span size='"'large'"'>???</span><span size='"'large'"' color='"#DA7A05"'>Overwrite</span> ??</u></b>\"</label></text>
   <text use-markup=\"true\"><label>\"<b><span size='"'large'"'  color='"blue"'>Danger </span><span size='"'large'"' color='"'red'"'>Destroy</span> $TEXT</b>\"</label></text>
   <text use-markup=\"true\"><label>\"<b><span size='"'large'"' color='"'red'"'>Overwrite</span>   $TEXT</b>    text\"</label></text>
   <text use-markup=\"true\"><label>\"<u><span size='"'large'"' color='"'#A900FF'"'>??????</span></u>\"</label></text>   
   </vbox>
</frame>	
</vbox>

<vbox border-width=\"20\">
			<text>
				<label>Do you want to overwrite the file??</label>				
			</text>
</vbox>
<hseparator></hseparator>
<hbox homogeneous=\"true\">
     <hbox>
         <button>
         <input file stock=\"gtk-yes\"></input>
         <label>Yes</label>
         <action>echo YES > /tmp/YES-NO.tmp</action>
         <action>exit:EXIT</action>         
         </button> 
     </hbox>
     <hbox>
         <button>
         <input file stock=\"gtk-no\"></input>
         <label>No</label>
          <action>echo NO > /tmp/YES-NO.tmp</action>
          <action>exit:EXIT</action>
         </button>    
     </hbox>
</hbox>    
</frame>
	
</window>"
$GTKDIALOG --program MYWINDOW --center
}



warning-function  # run the YES-NO box to ask user for permission
case "`cat /tmp/YES-NO.tmp`" in
   YES) echo  "second message" > /root/demonstrate-script.txt
      echo  "File has been overwritten" ;;
   NO) echo  "Do an alternate action" ;;
   *) echo  "Cancel" ;;
esac

rm -f /tmp/YES-NO.tmp  # delete temp file
exit 0
# End of demonstration

Last edited by don570 on Sat 16 Feb 2013, 19:41, edited 3 times in total.

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

#728 Post by recobayu »

Hi everyone,
I play a little thing about gtkdialog.
finally, I make a 'Limukstart'. with gtktheme wdz8.1 from here:
http://murga-linux.com/puppy/viewtopic. ... 393#671393
my startmenu tobe like this:
Image
but i still have a problem. I can't use mouse scroll to scroll horizontally with gtkdialog unless my pointer over the hscrollbar. Is possible to scroll horizontal with mouse? How?
Thanks
Attachments
limukstart.gz
remove .gz, chmod +x
(3.74 KiB) Downloaded 376 times
myblog: [url]http://muktyas.blogspot.com[/url]

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

#729 Post by smokey01 »

I needed to change the following line:
*) gtkdialog4 --program=MAIN_DIALOG ;;

Notice I added the 4 after gtkdialog.

Also the file needs to be renamed by removing the .gz and made executable.

I didn't get a horizontal scroll bar as my screen is quite wide.

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

#730 Post by recobayu »

you are right, smokey01. thanks for your respond. I linked gtkdialog4 to gtkdialog. i reupload limukstart. i still can't scroll horizontally by mouse unless my pointer over the scroller. how?
Attachments
limukstart2.gz
I reupload. hope this can appearing scrollbar
(3.76 KiB) Downloaded 389 times

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#731 Post by zigbert »

The vscale widget supports action signals as described inn the references

Code: Select all

<action signal="type">activity</action>
Do anyone know what signal to use to run action WHILE moving slider?


Thanks
Sigmund

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

#732 Post by SFR »

@Recobayu
I think there's a reason why it works this way - if you would had both horizontal AND vertical scrollbars at the same time, they would be scrolled simultaneously.
But horizontal scrolling works fine when I use touchpad ('Horizontal Edge Scroll' enabled).

@Zigbert
Is this what you mean? (see screenshot)
If so, leaving the default "value-changed" signal makes the given action executed properly while moving slider:

Code: Select all

echo '<window width-request="100" height-request="100"><vscale><variable>VAR</variable><action>echo $VAR</action></vscale></window>' | gtkdialog -s
HTH
Greetings!
Attachments
v.png
(6.48 KiB) Downloaded 677 times
[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
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#733 Post by zigbert »

SFR
I didn't have the 'value-changed' signal, but I had 'update-policy' defined.
- Now gone, and all works perfectly.


Thanks a lot!
Sigmund

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#734 Post by technosaurus »

There are too many hacked ways of getting the screen width,height and depth that make assumptions on a specific version of xrandr, xwininfo and their output format and the string manipulation tends to be pretty slow so I wrote a small and fast little helper in C here:
http://murga-linux.com/puppy/viewtopic. ... 996#685996
let me know if there are any other PITA parameters that are often needed and I can add them.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
oldyeller
Posts: 889
Joined: Tue 15 Nov 2011, 14:26
Location: Alaska

#735 Post by oldyeller »

Hello Everyone,

I have a question about menus, Can one put a menu in as a input file?

I will have a very big menu very soon and would like to know if this is possible


Thanks for any help

Cheers

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

vary the width opf combobox

#736 Post by don570 »

I've discovered how to vary the width of the combobox at
the time of launch of the script.

A practical example is Bulldog finder, which widens up
when it is launched with a folder path as an argument $1

As an example I change the width based on whether my app has an
argument $1

Code: Select all

export WIDTH=240
[ -z "$1" ] && WIDTH=150]

then while building the combobox

Code: Select all

<combobox case-sensitive="false" value-in-list="true" width-request="'$WIDTH'">

.

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

DYCP Effect

#737 Post by SFR »

Ah, the good old C64 times...
Does anyone remember DYCP (Different Y Character Position) effect?
It seems that Bash+Gtkdialog+SVG are powerful enough for that - here's an example (save it with .sh extension or else ROX will identify it as .svg file):

Code: Select all

#!/bin/bash

# DYCP example by SFR'2013

export SINUS=/dev/shm/sinus_table
[ -e $SINUS ] && rm $SINUS

# Create sinus table
for i in {0..63}; do
  RAD=`echo "$i*(3.14/32)" | bc -l`
  VAL=`echo "s($RAD) * 48 + 72" | bc -l`
  echo ${VAL/.*} >> $SINUS
done

dycp () {
SIN=( `cat $SINUS` )
echo '<svg width="256" height="128" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<text font-family="Monospace" font-size="32" font-weight="bold">
<tspan x="10" y="'${SIN[0]}'">P</tspan>
<tspan x="30" y="'${SIN[2]}'">U</tspan>
<tspan x="50" y="'${SIN[4]}'">P</tspan>
<tspan x="70" y="'${SIN[6]}'">P</tspan>
<tspan x="90" y="'${SIN[8]}'">Y</tspan>
<tspan x="130" y="'${SIN[12]}'">L</tspan>
<tspan x="150" y="'${SIN[14]}'">I</tspan>
<tspan x="170" y="'${SIN[16]}'">N</tspan>
<tspan x="190" y="'${SIN[18]}'">U</tspan>
<tspan x="210" y="'${SIN[20]}'">X</tspan>
<tspan x="230" y="'${SIN[22]}'">!</tspan>
</text>
</svg>' > /dev/shm/dycp_pic.svg

# Shift array right
echo ${SIN[63]} ${SIN[@]:0:63} > $SINUS
}
export -f dycp && dycp

export MAIN='
<window title="DYCP">
  <vbox>
    <pixmap>
      <variable>PICTURE</variable>
      <input file>/dev/shm/dycp_pic.svg</input>
    </pixmap>
    <button ok></button>
    <timer visible="false" milliseconds="true" interval="50">
      <action>dycp</action>
      <action>refresh:PICTURE</action>
    </timer>
  </vbox>
</window>
'

gtkdialog -cp MAIN
Of course it's rather pointless (and resource hungry), but personally I love such things! :D

_________________

EDIT: Ok, I wouldn't be myself if I wouldn't go further - here's DYCP-Scroller:

Code: Select all

#!/bin/bash

# DYCP Scroll by SFR'2013

export TEXT="             Hey! This is probably the very first DYCP-Scroller for Puppy Linux. ;) Greetings!"

TEMPDIR=/dev/shm/dycp_scroll_$$
mkdir $TEMPDIR
trap 'rm -rf $TEMPDIR' EXIT

export PIC=$TEMPDIR/pic.svg
export SINUS=$TEMPDIR/sinus_table
export X_POS=$TEMPDIR/dycp_x
export TEXT_POS=$TEMPDIR/text_position
echo 0 > $X_POS
echo 0 > $TEXT_POS

# Create sinus table
for i in {0..63}; do
  RAD=`echo "$i*(3.14/32)" | bc -l`
  VAL=`echo "s($RAD) * 48 + 72" | bc -l`
  echo ${VAL/.*} >> $SINUS
done

dycp () {
SIN=( `cat $SINUS` )
read X < $X_POS
read POS < $TEXT_POS
echo '<svg width="256" height="128" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<text font-family="Monospace" font-size="32" font-weight="bold">
<tspan x="'$((10-$X))'" y="'${SIN[0]}'">'${TEXT:$POS:1}'</tspan>
<tspan x="'$((30-$X))'" y="'${SIN[2]}'">'${TEXT:$(($POS+1)):1}'</tspan>
<tspan x="'$((50-$X))'" y="'${SIN[4]}'">'${TEXT:$(($POS+2)):1}'</tspan>
<tspan x="'$((70-$X))'" y="'${SIN[6]}'">'${TEXT:$(($POS+3)):1}'</tspan>
<tspan x="'$((90-$X))'" y="'${SIN[8]}'">'${TEXT:$(($POS+4)):1}'</tspan>
<tspan x="'$((110-$X))'" y="'${SIN[10]}'">'${TEXT:$(($POS+5)):1}'</tspan>
<tspan x="'$((130-$X))'" y="'${SIN[12]}'">'${TEXT:$(($POS+6)):1}'</tspan>
<tspan x="'$((150-$X))'" y="'${SIN[14]}'">'${TEXT:$(($POS+7)):1}'</tspan>
<tspan x="'$((170-$X))'" y="'${SIN[16]}'">'${TEXT:$(($POS+8)):1}'</tspan>
<tspan x="'$((190-$X))'" y="'${SIN[18]}'">'${TEXT:$(($POS+9)):1}'</tspan>
<tspan x="'$((210-$X))'" y="'${SIN[20]}'">'${TEXT:$(($POS+10)):1}'</tspan>
<tspan x="'$((230-$X))'" y="'${SIN[22]}'">'${TEXT:$(($POS+11)):1}'</tspan>
<tspan x="'$((250-$X))'" y="'${SIN[24]}'">'${TEXT:$(($POS+12)):1}'</tspan>
</text>
</svg>' > $PIC


X=$(($X+2))
if [ $X = 20 ]; then
  X=0
  POS=$(($POS+1)); [ $POS -gt ${#TEXT} ] && POS=0
  echo ${SIN[@]:1:63} ${SIN[0]} > $SINUS
else
  echo ${SIN[63]} ${SIN[@]:0:63} > $SINUS
fi
echo $X > $X_POS
echo $POS > $TEXT_POS
}
export -f dycp && dycp

export MAIN='
<window title="DYCP Scroller">
  <vbox>
    <pixmap>
      <variable>PICTURE</variable>
      <input file>'$PIC'</input>
    </pixmap>
    <button ok></button>
    <timer visible="false" milliseconds="true" interval="50">
      <action>dycp</action>
      <action>refresh:PICTURE</action>
    </timer>
  </vbox>
</window>
'

gtkdialog -cp MAIN
Have fun & 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
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#738 Post by zigbert »

like it :D

The days of C64 were sure wonderful. The coding wasn't meant to be useful - only cool.


Thank you for sharing
Sigmund

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#739 Post by vovchik »

Dear SFR,

That was an impressive bit of coding. I ported it to BaCon, with a few mods to reduce file reads/writes, and it works nicely. Thanks. Now to find a good use for this lovely routine :)

With kind regards,
vovchik

http://www.murga-linux.com/puppy/viewto ... 604#692604

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

#740 Post by SFR »

Thanks guys! :D

I guess I also miss the old days, because computers' capabilities were very limited and there was a challenge - to crush those limits!
For instance - see how amazing gfx can still be created in ancient 320x256x32 (my_jaw_dropped).
[sorry for being a bit off-topic]

@Vovchik - Bacon version works OOTB on Slacko, no recompiling needed; nice work!

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]

Post Reply