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

#41 Post by nikin »

Dear vovchik,

You right. But thereis no easy way to solve it as i see. becouse gtkdialog does not give you the entered command line args.

what works fine is a helper-script.

Code: Select all

#!/bin/bash

export ORIGIFILE="$@"
`./ppdf`
Bests

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

#42 Post by vovchik »

Dear nikin,

Your solution with the helper script is great and WORKS! I am now thinking of a few additional file types that could perhaps be processed by other programs - and a case statement in the ppdf_convert() function could determine which prog - abiword or something else - would do the "xxx2pdf" processing....

With kind regards,
vovchik

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

#43 Post by nikin »

Dear vovchik

It is god idea.. first thing that comes in mind are ppt-s but we need openoffice for that
i also have a little script wich was never finished and it ries to make some size optimization on images inside odp files.

if any program comes in your mind, just tell me.
Merging multiple files would be good to, but that is something for 0.2.0

Bests nikin

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

#44 Post by vovchik »

Dear nikin,

I am thinking about what additional conversions to pdf might be included without burdening Puppy too much. I have OO installed, so odt would be useful for me. The which command could be sued to check for soffice or swriter and, if not found, that extension would not be processed and a gxmessage error could pop up indicating the absence of OO on the user's machine (e,g, Cannot handle the extension "xxx" on this computer). For a case statement check, we could use this:

Code: Select all

ORIGIEXT=${ORIGIFILE##*.}
export ORIGIEXT
Here is a stupid icon I came up with last night.

With kind regards,
vovchik
Attachments
ppdf-but.png
(22.85 KiB) Downloaded 3178 times

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

#45 Post by seaside »

nikin,

I just downloaded and looked at your program (forum has been down). You have put together a very attractive, useful, and well-done program. Thank you.

I tried it out with Choicepup and it accepted all the input very nicely and it then produced nothing and no error.... and suddenly a light bulb :idea: went off.....Choicepup does not have Abiword installed! I installed it and everything was perfect. :D

There is one line ##### that you can remove here..

Code: Select all

export MAIN_DIALOG='
<vbox>
<entry>
<input>echo $ORIGINALFILE</input>
<variable>ORIGINALFILE</variable>
######<action>change_pdf</action>######
<action>refresh:PDFFILE</action>
</entry>
<entry>
<input>change_pdf</input>
<variable>PDFFILE</variable>
</entry> 
The "refresh:PDFFILE" action makes the "change-pdf" action take place.

The "helper script" wrapper was a great idea and I sure agree with you that it would be much better if GTKdialog could be commented (it makes my head hurt to read XML :x )

Very nicely done!

vovchik:

I liked your icon - is that a hat on the top?

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

Post Reply