Page 42 of 76

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

_____________________________________

Posted: Fri 04 Oct 2013, 08:31
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.?
.

Posted: Sat 05 Oct 2013, 07:50
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">

Posted: Sat 05 Oct 2013, 18:21
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.

Posted: Sat 05 Oct 2013, 21:52
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>

Posted: Sun 06 Oct 2013, 18:46
by sunburnt
Thanks again Geoffrey; It looks like Thunor has indeed fixed much of GtkDialog.

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