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
recobayu
Posts: 387
Joined: Wed 15 Sep 2010, 22:48
Location: indonesia

notebook trick

#826 Post by recobayu »

I learn something very usefull with notebook from here:
/usr/share/doc/gtkdialog/examples/notebook/notebook_advanced
I uncomment the dump line and I know some trick, there is in the inputfile:
0 --> tab0
1 --> tab1
...
here is my code:

Code: Select all

#!/bin/bash
cek(){
	if [[ $E = "" ]]; then
		#echo kosong
		echo 0 > inputfile
	else
		#echo ada
		echo 1 > inputfile
	fi
}
export -f cek
Width=`xwininfo -root | grep Width | awk '{ print $2 }'`
Height=`xwininfo -root | grep Height | awk '{ print $2 }'`
export aku='
<window title="nbkNotebook" width-request="'$Width'" height-request="'$Height'">
  <vbox>
		<entry>
			<variable>E</variable>
			<action>cek</action>
			<action>refresh:nbk0</action>
		</entry>
		<notebook show-tabs="false" show-border="false">
			<vbox border-width="20">
				<text label="this is the main start metro"></text>
			</vbox>
			<vbox border-width="20">
				<text label="and this is the search window"></text>
			</vbox>
			<variable>nbk0</variable>
			<input file>inputfile</input>
		</notebook>
  </vbox>
</window>'
gtkdialog --program=aku
if we type in the entry box, we can see the window get different face, and when we clear the entrybox, the window back to the our first face.
Nice gtkdialog :D
I Like it

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

#827 Post by don570 »

Here's a simple example to show how the refresh button works.

Just enter text in Entry box and click 'REFRESH'.

The entry goes to the
head of a text file that in displayed in comboboxtext widget

The refresh button code looks like this. Add another action tag line and
the refresh button could do some useful function.

Code: Select all

    <button>
               <label>refresh</label>
               <action>list_refresh</action>
               <action>refresh:LIST_ENTRY</action>
          </button>

Image
Attachments
Script-refresh.gz
remove fake gz extension
(1.37 KiB) Downloaded 437 times

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

example of refreshing

#828 Post by don570 »

More examples of practical refreshing...

This example(suggested by Nathan F) shows the contents of a dot file in /root.
The user then selects a file on the list and then
a function can be run by clicking button.

To make the comboboxtext items a command was used

Code: Select all

find $HOME -maxdepth 1 -mindepth 1 -type d -name ".*"
Image
Attachments
Script-tree.gz
remove fake gz extension
(1.51 KiB) Downloaded 407 times

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

#829 Post by don570 »

Here is another refresh example using comboboxtext.
The letters of alphabet are the items. Choosing a letter will
refresh the righthand side list of applications found installed.
Note the first letter of application.

Then a selection of the list can be further used by a function.
(Click on button 'refresh' to see what is possible with selection)

Image

____________________________________________________
Attachments
Script-app.gz
Remove fake extension
(2.09 KiB) Downloaded 404 times
Last edited by don570 on Wed 04 Sep 2013, 00:25, edited 1 time in total.

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

#830 Post by don570 »

Here is the same example as before but instead of a comboboxtext widget
a list widget is used. It then refreshes a tree .
A selection of the tree can then be further processed by
clicking on the button.



Image
Attachments
Script-list.gz
remove fake gz extension
(1.64 KiB) Downloaded 408 times

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

#831 Post by recobayu »

Hi don570, I am very interested about refresh. How to refresh the label of button? Until this time, i use input file, and then i make an svg file to change the button's label. something like this:

Code: Select all

#!/bin/sh

changei(){
	if [ -f /tmp/i ];then
		i=`cat /tmp/i`
	else
		i=1
	fi
	i=$(($i+1))
	echo $i >/tmp/i
	echo '<svg><text x="0" y="9"><tspan>'$i'</tspan></text></svg>'>/tmp/angkaku.svg
}
export -f changei
j=0  #i add this value. but still same, the label doesn't want to walk
ln -sf /root/puppy-reference/midi-icons/edit48.png /tmp/gbku.png
echo '<svg><text x="0" y="9"><tspan>1</tspan></text></svg>'>/tmp/angkaku.svg
export gantiBil='
<window>
	<hbox>
			<button width-request="48" height-request="48">
				<variable>a</variable>
				<label>"'$j'"</label>
				<action>j=$(($j+1))</action>
				<action>refresh:a</action>
			</button>
			<entry visible="false">
				<variable>E</variable>
			</entry>
			<button>
				<variable>b</variable>
				<width>48</width>
				<height>48</height>
				<input file>/tmp/gbku.png</input>
				<action>fileselect:E</action>
				<action>ln -sf $E /tmp/gbku.png</action>
				<action>refresh:b</action>
			</button>
			<button width-request="48" height-request="48">
				<variable>c</variable>
				<input file>/tmp/angkaku.svg</input>
				<action>changei</action>
				<action>refresh:c</action>
			</button>
	</hbox>
</window>'
gtkdialog --program=gantiBil

rm /tmp/gbku.png
rm /tmp/angkaku.svg
rm /tmp/i
exit
Edit:
I have 3 buttons. I think this is better than toggle button, because toggle button just have two condition (yes or no), and I think the button is more flexible.
The first, I want to change the label, but not work.
The second, we can change the picture by clicking that button, and select picture file (.jpg, .png, or .svg).
The third, this is my tricky method. I use svg, that can seen as label.
Is possible to change the label button? (in my example, the first button).
Thank You.

Now, I know that gtkdialog still can't refresh button.
I hope in the future, gtkdialog can refresh button, or maybe the vbox and hbox. So we can change everything inside the vbox or hbox without close the gtkdialog. I very like this gtkdialog and I start to enjoy this programming language.
:D
Last edited by recobayu on Tue 10 Sep 2013, 11:53, edited 1 time in total.

User avatar
Nathan F
Posts: 1764
Joined: Wed 08 Jun 2005, 14:45
Location: Wadsworth, OH (occasionally home)
Contact:

#832 Post by Nathan F »

A simple method would be to make two buttons and use show/hide actions to hide the first and show the second, or vice versa. I've used it on a few other widgets and it works pretty flawlessly.

The only drawback comes in with large groups of widgets, where there will be a speed and startup penalty due to the sheer size of it all. Not a problem for just one or two widgets.
Bring on the locusts ...

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

toggle button example

#833 Post by don570 »

to recobayu : You should have given j an initial value so that
something would have shown in that button... but
apparently gtkdialog has no method to change a script variable
used by a widget :cry:

___________________________________________________

I looked atThunor's examples and I spotted a toggle button example.

One button sends a signal to another button to show and hide.

I have simplified the code as much as possible. Look at the
code to see if it is useful. Togglebutton official page

Image
Attachments
toggle_example.gz
remove fake gz extension
(612 Bytes) Downloaded 375 times
Last edited by don570 on Mon 09 Sep 2013, 20:13, edited 2 times in total.

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

odd number toggle

#834 Post by don570 »

I thought up this wacky example by combining a Toggle button with
a svg image and another button that is refreshed.

By clicking on the right hand icon the number on the left hand button
increases by two. This means that only an odd number will show.


Image


______________________

______________________
Attachments
odd-number.sh.gz
remove fake gz extension
(1.2 KiB) Downloaded 390 times

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

#835 Post by don570 »

This example restricts the size of buttons so the text appears
normal sized.


Image
Attachments
odd-number2.sh.gz
remove fake gz extension
(1.54 KiB) Downloaded 371 times

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

#836 Post by recobayu »

To appear the text in normal size, we can use group in svg. this is my example :D

Code: Select all

#!/bin/sh
echo '<svg><g><rect style="fill-opacity:0" width="1" height="10"/><text x="0" y="9">0</text></g></svg>'>/tmp/angkaku.svg
changei(){
   if [ -f /tmp/i ];then
      i=`cat /tmp/i`
   else
      i=0
   fi
   i=$(($i+1))
   echo $i >/tmp/i
   echo '<svg><g><rect style="fill-opacity:0" width="1" height="10"/><text x="0" y="9">'$i'</text></g></svg>'>/tmp/angkaku.svg
}
export -f changei

export gantiBil='
<window>
	<hbox>
		<button>
			<variable>c</variable>
			<width>110</width>
			<input file>/tmp/angkaku.svg</input>
			<action>changei</action>
			<action>refresh:c</action>
		</button>
	</hbox>
</window>'
gtkdialog --program=gantiBil -c --space-expand=true --space-fill=true

rm /tmp/angkaku.svg
rm /tmp/i
exit

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#837 Post by sunburnt »

Hi guys; So much info. and no way to access it all.!

I`m writing a GtkDialog script for the first time in a very long while.
I don`t like it much, but it does work with all of the Puppy variations.

# I can`t remember how to get a button to close the dialog with an: <action>
EXIT doesn`t seem to work, nether does most examples I have.

Code: Select all

#!/bin/sh
BTNs=$(echo "$PKGs" |while read PKG
do
	echo "
	  <button>
		<label>$PKG</label>
		<action>$PKG</action>
		<action>EXIT</action>
	  </button>"
done)

export MENU_DLG='
<window title=" Libs.">
 <vbox>
  <text>
    <label>Select a Package.</label>
  </text>
'$BTNs'
  <hbox>
   <button ok></button>
   <button cancel></button>
  </hbox>
 </vbox>
</window>
'
gtkdialog --program=MENU_DLG
### Many thanks!
.

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

#838 Post by SFR »

To close the dialog right after pressing a button, right?

Code: Select all

<action>$PKG &</action> 
<action>EXIT:exit</action>
exit is kind of return code, so might be anything really...

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
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#839 Post by sunburnt »

And Greetings to you SFR; I thank you kindly for your help.
I now recall this bit of GtkDialog code thanks to you. I have the menu gui working great.

The menu will be usable for downloading binary or source packages and setting them up.
Last edited by sunburnt on Fri 04 Oct 2013, 08:17, edited 1 time in total.

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

#840 Post by don570 »

I have a page devoted to the exit variable in the
Gtkdialog Tutorial Manual

http://murga-linux.com/puppy/viewtopic.php?t=89045

_____________________________________

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#841 Post by sunburnt »

Another Q guys...

Has GtkDialog been patched so it`s easy to use: /path/icon in place of GTK`s "stock" gtk-ok ?
I know thunor has done work on GtkDialog, I don`t know if it`s still on-going though.

I know you can set a new path for this, but it`s obvious that this should be extremely simple.

Maybe Puppy should default to /usr/share/pixmaps as an alternate GTK icon path.?
.

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#842 Post by Geoffrey »

sunburnt wrote:Another Q guys...

Has GtkDialog been patched so it`s easy to use: /path/icon in place of GTK`s "stock" gtk-ok ?
I know thunor has done work on GtkDialog, I don`t know if it`s still on-going though.

I know you can set a new path for this, but it`s obvious that this should be extremely simple.

Maybe Puppy should default to /usr/share/pixmaps as an alternate GTK icon path.?
.
This works for me.

Code: Select all

<window image-name="/path/to/any/icon">
[b]Carolina:[/b] [url=http://smokey01.com/carolina/pages/recent-repo.html]Recent Repository Additions[/url]
[img]https://dl.dropboxusercontent.com/s/ahfade8q4def1lq/signbot.gif[/img]

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#843 Post by sunburnt »

Thanks Geoffrey; It looks like the line sets the GTK window`s icon, am I correct.?

I was wanting to substitute user icons for GTK button icons mainly.


Someone gave me a GTK environment command that set a new path for this ( can`t remember it...).
Then you would substitute a user icon for a stock button icon ( gtk-ok ).

Puppy should have this GTK env. command in it`s boot code to set: /usr/share/pixmaps
Then all those icons would be usable substitutes for the GTK stock buttons.

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#844 Post by Geoffrey »

sunburnt,

This works for button icons which the size can be varied also

Code: Select all

<button>
<label>"any icon"</label>
<input file>"/path/to/any/icon"</input>
<height>16</height>
</button>
Image positioning works too.

Code: Select all

<button image-position="2">
<label>"any icon"</label>
<input file>"/path/to/any/icon"</input>
<height>48</height>
</button>
Attachments
Screenshot-2.png
(6.93 KiB) Downloaded 716 times
Screenshot-1.png
(3.56 KiB) Downloaded 738 times
[b]Carolina:[/b] [url=http://smokey01.com/carolina/pages/recent-repo.html]Recent Repository Additions[/url]
[img]https://dl.dropboxusercontent.com/s/ahfade8q4def1lq/signbot.gif[/img]

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#845 Post by sunburnt »

Thanks again Geoffrey; It looks like Thunor has indeed fixed much of GtkDialog.

# Are there up-to-date docs. somewhere to download?

Post Reply