Page 42 of 76

Posted: Sun 25 Aug 2013, 15:55
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?

Posted: Sun 25 Aug 2013, 18:16
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.

Posted: Sun 25 Aug 2013, 19:08
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

Posted: Sun 25 Aug 2013, 19:18
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.

Posted: Thu 29 Aug 2013, 10:15
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? :)

notebook trick

Posted: Sat 31 Aug 2013, 02:06
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

Posted: Sat 31 Aug 2013, 17:47
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

example of refreshing

Posted: Wed 04 Sep 2013, 00:07
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

Posted: Wed 04 Sep 2013, 00:14
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

____________________________________________________

Posted: Wed 04 Sep 2013, 00:20
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

Posted: Sat 07 Sep 2013, 15:50
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

Posted: Sat 07 Sep 2013, 18:57
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.

toggle button example

Posted: Mon 09 Sep 2013, 18:30
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

odd number toggle

Posted: Mon 09 Sep 2013, 18:39
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


______________________

______________________

Posted: Thu 12 Sep 2013, 00:15
by don570
This example restricts the size of buttons so the text appears
normal sized.


Image

Posted: Thu 12 Sep 2013, 03:00
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

Posted: Tue 01 Oct 2013, 05:08
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!
.

Posted: Tue 01 Oct 2013, 11:15
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!

Posted: Tue 01 Oct 2013, 22:25
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.

Posted: Thu 03 Oct 2013, 23:11
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

_____________________________________