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

#821 Post by recobayu »

:D
Thank you don570 and nathan. signal="activate" works great.
I do a little trick here. I make a function mlaku that run the application that writed in the first item of tree (by read a < ketemu). Ya, although the clicked effect doesn't appear in the tree. :) Please correct me.

Code: Select all

#!/bin/sh
ls /usr/share/applications > aplikasiku

luru(){
	cat aplikasiku | grep -i $Entriku > ketemu
	cat ketemu | sed 's/.desktop//' > ditampilkan
}
export -f luru
mlaku(){
	read a < ketemu
	$(cat /usr/share/applications/$a | grep Exec | cut -d "=" -f2)&
}
export -f mlaku
export auto='
<window height-request="400" width-request="200">
	<vbox>
		<entry>
			<variable>Entriku</variable>
			<label>search application here</label>
			<action>luru</action>
			<action>refresh:Wit</action>
			<action signal="activate">mlaku</action>
		</entry>
		<tree rules-hint="true" headers-visible="false" activates-default="true" hover-selection="true">
			<variable>Wit</variable>
			<input file>ditampilkan</input>
			<action>exec $Wit</action>
		</tree>
	</vbox>
</window>'
gtkdialog --program=auto --center
Ok, now I want to hide the tree if the entrybox is empty and show that again if I write something in the entrybox. How to do that?

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

#822 Post by Nathan F »

Ok, now I want to hide the tree if the entrybox is empty and show that again if I write something in the entrybox. How to do that?
Try something like this

Code: Select all

<tree visible="false">
  <variable>TREE</variable>
</tree>
<entry>
 <action function="show">TREE</action>
</entry>
I do a little trick here. I make a function mlaku that run the application that writed in the first item of tree (by read a < ketemu). Ya, although the clicked effect doesn't appear in the tree. Please correct me.
Not sure what the question is again, sorry.
Bring on the locusts ...

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

#823 Post by recobayu »

Nathan F wrote: Try something like this

Code: Select all

<tree visible="false">
  <variable>TREE</variable>
</tree>
<entry>
 <action function="show">TREE</action>
</entry>
:) yes, it happen just one time. But when i clear the text in entry, the tree still show, it doesn't hide anymore.
I try this code, but fail.

Code: Select all

#!/bin/sh
a="false"
muncul(){
	if [[ $Entryku == "" ]]; then
		echo '<action function="hide">Wit</action>';
	else
		echo '<action function="show">Wit</action>';
	fi
	echo $Entryku
}
export -f muncul

export ketok='
<window>
	<vbox>
		<entry>
			<variable>Entryku</variable>
			<action>eval $Entryku</action>
			'"`muncul`"'
			<action>refresh:Entryku</action>
		</entry>
			<tree visible="'$a'">
				<variable>Wit</variable>
				<item>first line</item>
				<item>second</item>
				<item>third</item>
			</tree>
			<button>
				<label>ada</label>
				<action function="show">Wit</action>
			</button>
			<button>
				<label>sembunyi</label>
				<action function="hide">Wit</action>
			</button>
	</vbox>
</window>'

gtkdialog --program=ketok

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

#824 Post by Nathan F »

That's probably because your function is only being run the first time the dialog is created. In order to get it to run whenever the widget refreshes you have to put it inside a pair of input tags.

Code: Select all

      <entry> 
         <variable>Entryku</variable> 
         <action>eval $Entryku</action> 
         <input>muncul</input
         <action>refresh:Entryku</action> 
      </entry>
EDIT: I'm still fuzzy on whether it will do what you want it to. I think you need to use a conditional on the action itself (as a tag attribute), which I've only tried once.
Bring on the locusts ...

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

#825 Post by recobayu »

Thanks All, this is the new mukstart from me. I also use gtk2desklet by akash_rawal. here: http://murga-linux.com/puppy/viewtopic.php?t=74204
how about this? :)
Attachments
mukstart1.0.tar.gz
now, i think it's better than before..
(2.89 KiB) Downloaded 435 times

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

_____________________________________

Post Reply