GtkDialog - tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
nikin
Posts: 18
Joined: Tue 15 Sep 2009, 01:15

PPDF 0.1.6

#46 Post by nikin »

hy everyone.

ppdf 0.1.6 is here.

- unnescesary line removed (thanks seaside)
- there is now dependency check on the apps used. with gxdialog error message
- helper script included

and now i have managed to build a pet package of it with menu entry and all
i hope everything works fine.
please test it :P

PS:
dear vovchik: the icon is nice but aa bit blurry? or thats intended to be?
Attachments
ppdf016screenshot.png
and a screenshot
(6.72 KiB) Downloaded 2474 times
ppdf-0.1.6.tar.gz
ppdf and ppdf helper
(2.22 KiB) Downloaded 870 times
ppdf-0.1.6.pet
ppdf 0.1.6 pet
(2.91 KiB) Downloaded 874 times

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

#47 Post by vovchik »

Dear nikin,

I will work on the icon - it is a bit blurry. With v.1.6 I have Abiword launching three instances after I quit. Can't be right. I will look tomorrow at the source. The dep check is a good idea. I think an ext check would also be in order (see above), because people might wish to print binary executables, for example :)

With kind regards,
vovchik

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

#48 Post by vovchik »

Dear nikin,

Another icon attempt. This one is much less fuzzy....

With kind regards,
vovchik
Attachments
ppdf-logo-but.png
(25.95 KiB) Downloaded 2322 times

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

#49 Post by vovchik »

Dear nikin,

And here is a modified version of my first attempt at an icon, with fuzziness removed.

With kind regards,
vovchik
Attachments
ppdf-logo-but2.png
(25.45 KiB) Downloaded 2326 times

nikin
Posts: 18
Joined: Tue 15 Sep 2009, 01:15

#50 Post by nikin »

i like the ppdf-logo-but.png one.
as you my have seen imade a small icon..
Did youtake alokk in the abiword problem... i couldn't reproduce it.

I started a new topic for the program

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

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

#51 Post by zigbert »

Drag'n drop
Gtkdialog supports drag'n drop from filebrowser (rox) to <entry> widget.

Code: Select all

export test="
<entry accept=\"directory\" width-request=\"300\">
 <default>Drag a directory from Rox</default>
</entry>"
gtkdialog3 -p test
But this is not all....The next script shows how to move items in list by drag'n drop. This example shows only one list, but it is of course possible to drag between 2 lists. Pmusic 0.9.0 shows this in practice.

Code: Select all

#!/bin/sh

move (){
	PRESS_EVENT="`cat /tmp/PRESS_EVENT`"
	grep -Fv "$PRESS_EVENT" /tmp/list > /tmp/tmp
	grep -Fm1 -B500 "$TREE" /tmp/tmp | grep -v "$TREE" > /tmp/tmp1
	echo "$PRESS_EVENT" >> /tmp/tmp1
	grep -Fm1 -A500 "$TREE" /tmp/tmp >> /tmp/tmp1
	mv -f /tmp/tmp1 /tmp/list
} 

export -f move
ls -1 /usr/share/backgrounds > /tmp/list

export test="
<tree rules_hint=\"true\" hover-selection=\"true\" tooltip-text=\"Drag'n drop items to move them in list\">
 <label>Backgrounds</label>
 <input>cat /tmp/list</input>
 <variable>TREE</variable>
 <height>300</height><width>200</width>
 <action signal=\"button-press-event\">echo \$TREE > /tmp/PRESS_EVENT</action>
 <action signal=\"button-release-event\">move</action>
 <action signal=\"button-release-event\">refresh:TREE</action>
</tree>"
gtkdialog3 -p test

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#52 Post by seaside »

zigbert,

Thanks for posting this. It's absolutely amazing what can be done with Gtkdialog.

It's really sad that the documentation is silent on all the possibilities available.

Keep the hints and tricks coming :D

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

#53 Post by zigbert »

Okay, here is todays gtkdialog trick. :)

How to add support of tail/log-text. Change TITLE and TAILFILE to see other info than /var/log/messages.

Code: Select all

#!/bin/sh

export TITLE="Kernel messages"
export TAILFILE=/var/log/messages

echo 99 > /tmp/tailbox_progress
echo " " > /tmp/tailbox_text

tailing (){
	I=`cat /tmp/tailbox_progress`
	echo $TITLE
	echo $I
	sleep 1
	[ -s "$TAILFILE" ] && tail -n 20 "$TAILFILE" | tr '\r' '\n' | tail -n 20 > /tmp/tailbox_text
	echo 100 > /tmp/tailbox_progress
}
export -f tailing

export tailbox="
<window title=\"tailbox\">
 <vbox>
  <progressbar>
   <input>"'while [ A != B ]; do tailing; done'"</input>
   <action>refresh:TAIL</action>
   <action>echo 99 > /tmp/tailbox_progress</action>
  </progressbar>
  <edit>
   <variable>TAIL</variable>
   <input file>/tmp/tailbox_text</input>
   <width>300</width><height>380</height>
  </edit>
 </vbox>
</window>"

I=$IFS; IFS=""
for STATEMENTS in $(gtkdialog3 -p tailbox); do
	eval $STATEMENTS
done
IFS=$I
Image

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

#54 Post by zigbert »

Todays lesson is the explanation of yesterdays tailbox trick. It can be used for endless of funny code. You'll find it in the main post - chapter 4.


Sigmund

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

#55 Post by zigbert »

MIME
What should happen when user double-click on an image-file in your gui. In some cases it is logical to show the image in an image-viewer. But....it is no need of linking all kinds of extensions to different programs. - It is already done by the filebrowser. Puppy uses 'rox' and if you execute 'rox /path/image.png' the image will show up in the defined viewer. Just as simple as that.

See main post for complete gtkdialog-guide

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#56 Post by seaside »

Zigbert,

Great material. This tutorial will soon be ready for prime time television. :D

There is no where else to find all of these valuable guidelines and most of all - thank you for taking the time to explain.

Best regards,
s

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#57 Post by 01micko »

Remebering our Radio Button Choice

Hello guys and gals :)

I just thought I would share this as it is not well documented. There are 2 examples in Puppy that I know of, Pfind and Nathan Wallpaper Setter.

Imagine you have an app that you use and it has radio buttons. Now, of the choice you make of those radio buttons you would like to remember that choice next time you start the app. It is quite simple-

Code: Select all

<radiobutton>
 <variable>VAR</variable>
  <label>some text</label>
   <default>true</default>
</radiobutton>

The key there is the <default> tag. It must be true or equate to true.

:?: How do we get it to equate to "true" then?

:idea: We need some sort of config file where the values of the variables are stored and changed accordingly.

Ok then we create this file. For this case it is called simply "variables". (There are a number of ways this file can be derived but that is not the point here.)

Lets say we have VAR1 and VAR2. In our "variables" file then we need

Code: Select all

VAR1=true
VAR2=false
That will make VAR1 the default.

So, our gtkdialog script now looks like this-

Code: Select all

<radiobutton>
 <variable>VAR1</variable>
  <label>some text</label>
   <default>$VAR1</default>
<radiobutton>
 <variable>VAR2</variable>
  <label>some other text</label>
   <default>$VAR2</default>
</radiobutton>
Ah.. but how do we change the value from true to false?

In this case, to keep it simple, we redirect the standard output to our variables file
----------------

Now we try it! (the fun part :) )

Make a directory on your system, I'll call mine "radiobutton-test" and I'm creating it in /root. Make it where ever you want but remember the path.

Code: Select all

#!/bin/bash
WORKDIR="/root/radiobutton-test"
. $WORKDIR/variables

export radiobuttonfun="
<window title=\"fun?\">
 <vbox>
  <frame Having fun yet?>
   <radiobutton>
    <variable>VAR1</variable>
     <label>Yes I am</label>
      <default>$VAR1</default>
    </radiobutton>
   <radiobutton>
    <variable>VAR2</variable>
     <label>No I'm not</label>
      <default>$VAR2</default>
   </radiobutton>  
  </frame>
  <hbox>
   <button ok></button>
  </hbox>
 </vbox>
</window>"

gtkdialog3 --program=radiobuttonfun > $WORKDIR/variables
Make this text file in your directory named "variables"

Code: Select all

VAR1=true
VAR2=false
Make your script executable and run it! Your radio button choice will be remembered!

TIP: In this example, do not kill the window because then there is no standard output. This is why you can not use standard output in this manner. There are plenty of other ways :) I have made a working example here- for Eeepcs http://www.murga-linux.com/puppy/viewto ... 561#347561

Cheers :D
Puppy Linux Blog - contact me for access

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

#58 Post by zigbert »

Hello Mick
Nice tutorial!
I will include this in the main post, but thought it might fit better as a new chapter - The benefits of a config file.
- Both <entry> and <edit> widgets uses the <default> tag.
- How to activate a given item in a combobox.


Sigmund

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

#59 Post by zigbert »

5.) The benefits of a config file - Set default status of Radiobuttons, Comboboxes...

A config file is a nice way to store the settings in your program. At next startup, it will show setting like you left them last time. An easy way to use a config file is to run it like an ordinary bash-script, and include variable definition in it. It is most common to keep config files in home directory as a hidden file ($HOME/.testrc). The file might look like this:

Code: Select all

COMBOBOX="item 3"
ENTRY="default text"
RADIOBUTTON1="false"
RADIOBUTTON2="true"

Now let's go to the main script. For the radiobuttons and the entry, we set the <default> tag to the coresponding variable in the config file. Since the combobox doesn't support the <default> tag, we need a workaround. We simply builds the combobox item-list so show our saved variable first.

Code: Select all

#!/bin/bash
. $HOME/.testrc
#in case no testc file (first run), build the file
[ ! -s $HOME/.testrc ] && echo -n 'COMBOBOX="item 3"\nENTRY="default text"\nRADIOBUTTON1="false"\nRADIOBUTTON2="true"'

#define combobox list items
COMBOBOX_ITEMS="<item>$COMBOBOX</item>" #stored value should be first in list
for I in 1 2 3 4; do COMBOBOX_ITEMS=`echo "$COMBOBOX_ITEMS<item>item $I</item>"`; done

export test="
<window title=\"The benefits of a config file\">
 <vbox>
  <frame The first item of list is the default choice in a Combobox>
   <combobox>
    <variable>COMBOBOX</variable>
    $COMBOBOX_ITEMS
   </combobox>
  </frame>
  <frame If nothing else is set, the first radiobutton is the active one>
   <radiobutton>
    <variable>RADIOBUTTON1</variable>
    <label>Yes I am</label>
    <default>$RADIOBUTTON1</default>
   </radiobutton>
   <radiobutton>
    <variable>RADIOBUTTON2</variable>
    <label>No I'm not</label>
    <default>$RADIOBUTTON2</default>
   </radiobutton> 
  </frame>
  <frame Fetch entry-value from config file>
   <entry>
    <variable>ENTRY</variable>
    <default>$ENTRY</default>
   </entry>
  </frame>
  <hbox>
   <button ok></button>
  </hbox>
 </vbox>
</window>"

gtkdialog3 -p test > $HOME/.testrc
The last codeline redirects output (variable values) to our config file instead of to the terminal.
Note that line 2 starts with a dot. It makes a huge different if you skip it.
. $HOME/.config --> run script as a childprocess as the main process. The variable values in the config file are reachable for the main script.
$HOME/.config --> run script as a new process as the main process. The variable values in the config file will NOT be reachable for the main script.

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

#60 Post by zigbert »

###################################################################################
6.) Speed issues - Let your turtle run
###################################################################################

Gtkdialog is not a fast gui-lib. If you are building a gui where speed matters, please check the following notes.

>> If you include a long list in your gui, you should consider to use the <table> widget instead of <tree> or <list>. While <tree> and <list> first reads content of list, and then render it, the <table> renders while content is read.

>> Progressbars can suck your cpu-power. Adding a reasonable sleep value in the loop helps a lot.

>> Run large calculations as a background process. Pmusic builtin filebrowser (version 0.9) first shows songs in the directory, then it starts a background process to find meta informations of the songs. When finished, it renders the song-list once again, now with complete information. How to use a background process with gtkdialog is explained in the chapter 'Let external code act on your gtkdialog gui'.

>> Even if gtkdialog is slow, your bash-code might make it MUCH slower. Be careful with the use of subshells, and slow commands as sed, ps, expr... This is of course most important when building a loop.

>> There are many ways of building a gui. The pictures below shows the builtin filebrowser/filesearch in Pburn 2 (left) and Pburn 3. The code has shrunk from 3110 to 997 chars. It does exactly the same, and the speed improvement are notable.

Image . . . . . . . Image

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#61 Post by 01micko »

zigbert wrote:Hello Mick
Nice tutorial!
I will include this in the main post, but thought it might fit better as a new chapter - The benefits of a config file.
- Both <entry> and <edit> widgets uses the <default> tag.
- How to activate a given item in a combobox.


Sigmund
Hi Sigmund,

Glad I could add something useful to this thread. It has some nice info. :D

Mick
Puppy Linux Blog - contact me for access

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

#62 Post by technosaurus »

I was trying to get some more documentation on GTK Dialog and figured out a reason why there may not be much documentation thus far. It seems that it was an intermediated step / building block for these:

CUI http://linux.pte.hu/~pipas/CUI/index.html
GUI Completion http://linux.pte.hu/~pipas/GUIcompletion/index.html

So goes the development cycle on a project with a small or one man team. They do look pretty promising for a couple of my projects (Pcompile in particular) Has anyone here done anything with them yet?
Last edited by technosaurus on Mon 05 Oct 2009, 22:15, edited 1 time in total.
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].

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#63 Post by disciple »

I looked at them the other day, but I can't remember why I gave up on them. I think one had some unreasonable (gnome?) dependencies.
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

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

#64 Post by zigbert »

Make the gui scalable
>> Did you know that it is possible to make gtkdialog windows fully scalable? That means to be able to drag the window corner, and make the gui bigger.

As long as a <tree>, <table>, <list> or <edit> widget is enclosed ONLY by a <hbox> OR <vbox>, the widget will remain scalable both horizontally and vertically. Pfind, Pmusic and Pprocess uses various solutions of this.

>> Note about frames
If you enclose a <frame> with <hbox> or <vbox>, you set a fixed size of the frame. If you instead put the <hbox>/<vbox> definitions inside the <frame>, the frame will dynamically scale to fit gui.

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

#65 Post by sunburnt »

Hi zigbert; I need help with the "tree", I don`t see how the sub levels are controlled.

Code: Select all

#! /bin/bash
export MAIN_DIALOG='
<vbox>
  <tree>
    <input file>tmp.text</input>
    <label>Device</label>
    <item stock="gtk-harddisk">Hard Disk</item>
    <item stock="gtk-floppy">Floppy Disk</item>
    <item stock="gtk-floppy">Floppy Disk</item>
    <item stock="gtk-floppy">Floppy Disk</item>
    <item stock="gtk-cdrom">CD_ROM Drive</item>
    <height>200</height>
    <width>300</width>
    <variable>TREE</variable>
  </tree>
</vbox>
'
gtkdialog2 --program=MAIN_DIALOG
This should give multi. levels but only gives a few, but what designates the sub levels?
The code above is gtk-2, so gtk-3 may be a better choice...

I`m trying to make a "WinExplorer" type file browser, left pane = dir. tree, right pane = file list.

Post Reply