GtkDialog - tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

gtimer

#605 Post by jpeps »

This animated process indicator graphic makes use of the gtkdialog timer feature. Usage:

myfunction() {
gtimer
code .....
kill -9 `ps | grep GTIMER | grep -v grep | awk '{print $1}'`
}
Attachments
gtimer-2.0.pet
(1.19 KiB) Downloaded 444 times
gtimer.png
(5.56 KiB) Downloaded 1410 times
Last edited by jpeps on Wed 21 Aug 2013, 06:25, edited 1 time in total.

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

#606 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 1 <hbox> OR <vbox>, the widget will remain scalable both horizontally and vertically. Pfind, Pmusic and Pprocess uses various solutions of this.

>> We have of course a trick to scale more complex guis too...
A <hbox> or <vbox> supports the attribute; scrollable, which resets the hbox/vbox definition. You can enclose a widget by 1 <hbox/vbox> inside the scrollable box. The following example explains my words. Remove the scrollable attribute to see how it normally will act.

Code: Select all

#!/bin/sh
export DIALOG='<window default_width="500" default_height="300">
<vbox>
 <text><label>How to scale a complex gui</label></text>
 <hbox scrollable="true">
  <edit></edit>
  <edit></edit>
 </hbox>
</vbox>
</window>'
gtkdialog -p DIALOG

2byte
Posts: 353
Joined: Mon 09 Oct 2006, 18:10

#607 Post by 2byte »

Hi everyone,

I need some help please. I have tried to solve this for two days and I'm baffled. Using a tip from earlier in this thread this dialog was constructed with comments. Only in bash 4.1, I get this warning
“./Pupsave-backup: line 409: warning: here-document at line 305 delimited by end-of-file (wanted `EOV')


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

#608 Post by technosaurus »

i notice you are using EOV instead of EOF ... is that because an EOF is in one of your variables?

cat normally outputs until EOF (octal \004 ... it can be forced with echo -e "\004")
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].

potong
Posts: 88
Joined: Fri 06 Mar 2009, 04:01

#609 Post by potong »

2byte: "Sometimes it's hard to see the wood for the trees..."

Simplify the code by removing all the flesh and then add it bit by bit back on to the skeleton.

Code: Select all

# export PUPSAVE_HOT_BKP=$(cat <<EOV | sed -e 's/#.*//'    # allow comments in gui 
EOV)
# echo "$PUPSAVE_HOT_BKP"

# export PUPSAVE_HOT_BKP=$(cat <<EOV | sed -e 's/#.*//'    # allow comments in gui 
<window title="Hot Backup for Frugal Pups" icon-name="gtk-convert" default_width="400"> 
EOV)
# echo "$PUPSAVE_HOT_BKP"
<window title="Hot Backup for Frugal Pups" icon-name="gtk-convert" default_width="400"> 
# export PUPSAVE_HOT_BKP=$(cat <<EOV | sed -e 's/#.*//'    # allow comments in gui 
<window title="Hot Backup for Frugal Pups" icon-name="gtk-convert" default_width="400"> 
   <vbox> 
EOV)
# echo "$PUPSAVE_HOT_BKP"
<window title="Hot Backup for Frugal Pups" icon-name="gtk-convert" default_width="400"> 
   <vbox> 
#...
Of course there may be a problem in bash4.1?
Does this ring any bells?

If not maybe this may throw some light on the problem.

HTH

Potong

2byte
Posts: 353
Joined: Mon 09 Oct 2006, 18:10

#610 Post by 2byte »

Thanks guys

potong, your links led to the solution.
A here-document is supposed to be
terminated by a line containing the delimiter followed by a newline
The solution?

Code: Select all

</window>
EOV
) 
Sometimes the simplest things ...


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

#611 Post by zigbert »

Thunor has enlightened us with a huge speed improvement for complex guis. I have updated first post - Speed issues
______________________________________________________________________

>> For an unknown reason, it is much faster to start your gtkdialog-xml-code from a file than from a variable.
gtkdialog --file=filename
gtkdialog --program=variable
The file alternative is highly recommended if your xml-code is getting complex.

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#612 Post by 8-bit »

I hope I have it right, but I have written a gtkdialog script that uses a progress bar in its actions. It was written to restore 2byte's backed up pupsave files, but you can use it to copy a file to another destination.
I ran into a problem after uploading it and found that I had not allowed sufficient time for the copy to start and so a check of the destination file size failed and caused errors in the execution of the script.
Anyway, if you want to try it and see how I got a progress bar to work, just get the file from "Additional Software - utilities". It is under the heading of "Restore Pupsave file....".

I did this as a challenge as I had not seen any actual applications that used a progress bar.
The examples to me do not count because they only increment numbers to make the bar advance with no provision as to how one would use it in an application.
If it bombs for you, open the script in a text editor such as geany and increase the sleep value on line 25.

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#613 Post by jpeps »

8-bit wrote:
I did this as a challenge as I had not seen any actual applications that used a progress bar.
petcheck has one, also swapfilemanager (although not a bar...just an animated graphic).

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

#614 Post by seaside »

zigbert wrote:Thunor has enlightened us with a huge speed improvement for complex guis. I have updated first post - Speed issues
______________________________________________________________________

>> For an unknown reason, it is much faster to start your gtkdialog-xml-code from a file than from a variable.
gtkdialog --file=filename
gtkdialog --program=variable
The file alternative is highly recommended if your xml-code is getting complex.
Anyone have a theory on how this could happen? Something using file i/o being faster than memory?

Wait... perhaps it's because Gtkdialog reloads the entire program whenever called, whereas - if from a file it's displayed immediately?

Cheers,
s

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#615 Post by 8-bit »

UPDATE!
The Restore Pupsave utility I uploaded may not handle just copying a file since it was written to remove the date-time from a backed up pupsave file.
It uses sed to remove the last 19 characters in the filename after the source path is removed.
I wanted to pass that along to all that try to use it to copy files.

User avatar
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

#616 Post by thunor »

seaside wrote:Anyone have a theory on how this could happen? Something using file i/o being faster than memory?

Wait... perhaps it's because Gtkdialog reloads the entire program whenever called, whereas - if from a file it's displayed immediately?

Cheers,
s
I've found the issue and it's fixed in r308.

The problem was that strlen() was being called for every char read from memory to check that a char wasn't being read past the end, but this was pointless anyway since an environment variable is null terminated which is being checked for too.

Reading from a file or stdin are both fine though and it'd be a good idea to stick to these methods for complex apps until everyone is using at least r308.

Something else I've found: loading my rather large app from an environment variable is causing bash to display an error message: "./myapp: line 192: /usr/sbin/gtkdialog: Argument list too long", so I have to load from a file or stdin anyway. The limit I am experiencing which bash won't accept above is somewhere around 123KB.

Regards,
Thunor

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#617 Post by Geoffrey »

post deleted and moved

SK7000
Posts: 4
Joined: Wed 12 Oct 2011, 18:54

comboboxtext searching?

#618 Post by SK7000 »

Hello,

Today I discovered gtkdialog while building a minimal GUI around a commandline application I use frequently. I've got pretty much everything working except two things.

The first is behaviour I've come to expect of all comboboxes I've come across, and it is to be able to search the entry you are looking for by typing the first few characters. It appears that "comboboxtext" areas in Gtkdialog don't have this functionality built-in, not even the advanced demos do it.

So, is there any way to do it, either by setting some property or clever action-binding?

The second is quite simple, I just can't figure out a way so that the dialogue's "OK" button gets pressed when the user presses Enter while the comboboxtext area is focused. I didn't see any actions that can be bound to the Enter key.

So, again, is there some way to do this?

I imagine I could do without, but it's a bit slow searching the entry you want (amongst a few dozens) without help from the keyboard :/

PS: Thanks for a very interesting and flexible application :o

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#619 Post by big_bass »

I was looking for some simple on screen 600 pixel ruler but nothing I found was simple so
here is as simple as it gets

there is vertical ruler included also
Attachments
gtk-movable-ruler.png
(13.77 KiB) Downloaded 1265 times
ruler.tar.gz
(8.67 KiB) Downloaded 472 times

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

#620 Post by disciple »

big_bass wrote:I was looking for some simple on screen 600 pixel ruler but nothing I found was simple so
IIRC gruler used to be written in C (rather than ruby), and would have met your criteria ;)
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

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

#621 Post by technosaurus »

thunor wrote: Reading from a file or stdin are both fine though and it'd be a good idea to stick to these methods for complex apps until everyone is using at least r308.
and the -i file / --include=file is a very robust way of getting a slew of functions without having to use export -f (which is a bashism)

ex.

Code: Select all

#!/bin/sh
. /usr/local/myapp/myfunctions
#code
eval `gtkdialog --include=/usr/local/myapp/myfunctions --file=/usr/local/myapp/myMAIN`
#more code
btw, is there an example of "event driven" anywhere
I have found that commands in the shabang cannot end in a number (#!/usr/sbin/gtkdialog3 -e fails, but #!/usr/sbin/gtkdialog -e succeeds)

ex.

Code: Select all

#!/usr/sbin/gtkdialog -e

function print_this() {
  echo "print: $1"
}

export MAIN_DIALOG='
<vbox>
  <button>
    <label>function</label>
    <action>print_this button</action>
  </button>
  <button>
    <label>Exit</label>
  </button>
</vbox>
'
this works if you make a symlink to gtkdialog but fails if you just change the shabang to gtkdialog3
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].

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

#622 Post by vovchik »

Dear technosaurus,

Great observation (shebang ending with a number) and tip!

With kind regards,
vovchik

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

#623 Post by seaside »

technosaurus wrote:
btw, is there an example of "event driven" anywhere

this works if you make a symlink to gtkdialog but fails if you just change the shabang to gtkdialog3
technosaurus,

The gtkdialog "event driven" mode was my first attempt at gtkdialog with "LocnRox" here -

http://www.murga-linux.com/puppy/viewto ... df43910d84

I think Thunor found that the "gtkdialog" call was hardcoded.

Regards,
s

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

Re: comboboxtext searching?

#624 Post by seaside »

SK7000 wrote:Hello,

Today I discovered gtkdialog while building a minimal GUI around a commandline application I use frequently. I've got pretty much everything working except two things.

The first is behaviour I've come to expect of all comboboxes I've come across, and it is to be able to search the entry you are looking for by typing the first few characters. It appears that "comboboxtext" areas in Gtkdialog don't have this functionality built-in, not even the advanced demos do it.

So, is there any way to do it, either by setting some property or clever action-binding?

The second is quite simple, I just can't figure out a way so that the dialogue's "OK" button gets pressed when the user presses Enter while the comboboxtext area is focused. I didn't see any actions that can be bound to the Enter key.

So, again, is there some way to do this?

I imagine I could do without, but it's a bit slow searching the entry you want (amongst a few dozens) without help from the keyboard :/

PS: Thanks for a very interesting and flexible application :o
SK7000,

You can do an "enter default" for a single entry box-

Code: Select all

<entry activates-default="true">
.
It doesn't seem to be applicable to comboboxes, as the "enter" behaviour is coded to bring up more choices.

Both of these items seem like good candidates for the Cutting Edge>Gtkdialog Development thread.

Cheers,
s

Post Reply