GtkDialog - tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
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 471 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

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

Re: comboboxtext searching?

#625 Post by SK7000 »

seaside wrote: 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
Thanks for the information, I submitted the ideas to the development thread. I just thought there might be a way to do these things already, it just wasn't documented. Well, let's wait and see if we get support for at least incremental search, that would be very useful, IMHO.

brokenman
Posts: 25
Joined: Thu 20 Oct 2011, 23:00

Large projects

#626 Post by brokenman »

I have a question in relation o the post above by technosaurus.

I am designing a larger project and don't want to get to the size litmit mentioned only to find failures. I want to break the scripts up. Here is what i have:

main-script.sh

Code: Select all

#!/bin/bash

. ./functions.sh

echo "This is the starter script"

eval `gtkdialog --include=./functions.sh --file=./gtkfile.sh`
functions.sh

Code: Select all

#!/bin/bash

VAR1="variable1-from-$0"

myfunction(){
VAR2="variable2 from $FUNCNAME"
}
myfunction
gtkfile.sh

Code: Select all

#! /usr/bin/gtkdialog -f

<vbox>
<button ok></button>
<text><label>This is some text</label></text>
<text><label>VAR1 is $VAR1</label></text>
<text><label>"VAR2 is $VAR2"</label></text>
</vbox>
After starting the main-script.sh the output gives me a window with:
VAR1=$VAR1
VAR2=$VAR2

According to the post above, i assume i can have this setup ... but i am having trouble passing variables to the gtkdialog application. I get the same result if the variables are exported. How is the technique above useful for large applications split over multiple files?

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

Re: Large projects

#627 Post by seaside »

brokenman wrote:. but i am having trouble passing variables to the gtkdialog application. I get the same result if the variables are exported. How is the technique above useful for large applications split over multiple files?
brokenman,

Usually, if the variables are exported, the problem may be traced to variables being created in a child process. In that case the parent can't see those variables.

You can save those variables to temp files instead for reference.

Cheers,
s

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

#628 Post by technosaurus »

here is another goody:

you don't even really need to export most functions, you can use something like this:

Code: Select all

gtkdialogworker(){
while read A; do
	case $A in
		#add your stuff here);;
		EXIT)return 0;;
		*)echo $A;;
	esac
done
}

gtkdialog ... | gtkdialogworker
just use echo for your actions and let your "worker" do the rest.
(sorry for the abbreviated explanation, I have somewhere to be and didn't want to forget this ... it may be quite useful)

and I wanted to post this other waitpid quickie:
(no need to use ps and grep to parse output, plus works for multiple processes)
command &
COMMANDPID=$!

while ([ -d /proc/$COMMANDPID ]) do usleep 1000; done

you can do this for multiple commands using " || "

(this could be extremely useful in speeding up scripts like init or others that use "wait" for all child processes to finish when we are only concerned about a couple)
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].

brokenman
Posts: 25
Joined: Thu 20 Oct 2011, 23:00

#629 Post by brokenman »

Thanks seaside. My goal here was to avoid dumping temp files. I gathered it was due to child not being able to pass to parent. This is why i questioned the use of the code:

Code: Select all

. ./functions.sh
echo "This is the starter script"
eval `gtkdialog --include=./functions.sh --file=./gtkfile.sh`
What is the purpose of the --include call?

If i begin the script (main-script.sh) with . ./functions.sh i am running this as a child process and the vars become available to parent (main-script.sh). The 'eval' line appears to me to start the gtkfile.sh while including the functions.sh for access. I must be missing something, i don't entirely understand how this --include line works. Perhaps someone will edify me.

At the moment i have a large main script containing functions of gtkdialog script. I have a separate library script for 'shell only' code. This works ok, but i am having to export everything so it is available for gtkdialog. This concerns me as my script will most certainly exceed the mentioned size limit where problems begin to occur.

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

#630 Post by technosaurus »

The --include is so you don't have to export the functions (you can't even export the with ash, dash, etc ... as the shell instead of bash) .

BTW, I don't think there is a chance of reaching a size limit, I have been up to 1mb before (bashbox) with no problem. As far as readability goes geany's code folding eliminates that issue. You can do extra code blocks like this:

Code: Select all

{ #begin foo block

Foo code here

} #end foo block
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].

brokenman
Posts: 25
Joined: Thu 20 Oct 2011, 23:00

#631 Post by brokenman »

Thanks very much. I understand now.

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

#632 Post by 8-bit »

First, I am not going to post an example for this since the example Barry posted in Cutting Edge - Gtkdialog can be used to show what I am talking about.
In the Country selection one, if one clicks on the down arrow to show the item choices, a selection window is shown that has a height that takes the full height of my display with additional up and down arrows at each end of that window.
My question is:

Since one has to use the additional up/down arrows in that window, is it possible to specify the height of it?
It would sure help in cleaning up the looks of it for selection of country/language/keyboard if the popup selection window was a given height.

I tried changing <comboboxtext> to <combobox> throughout the script and to me, I think it helped. The height is still there in the selection windows, but the change gave a vertical scrollbar that helps in locating a selection.

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#633 Post by Argolance »

Hello,
Please, see this thread: => Converting gtkdialog3 script into gtkdialog4 problem...

Thank you.

Cordialement.
[SOLVED] Thanks thunor!
Last edited by Argolance on Thu 17 Nov 2011, 08:17, edited 1 time in total.

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

#634 Post by Geoffrey »

I was trying to find a way to center the text in a label in a tree list, but came across this by accident

Code: Select all

<tree> 
		<label>'"_MY LIST OF STUFF"'</label>
this gives the label bar a keyboard control of Alt+M, I didn't see this mentioned anywhere else, so I thought I'd pass it on.

Geoffrey
Attachments
tree_list.jpg
(4.42 KiB) Downloaded 1242 times

User avatar
darkcity
Posts: 2534
Joined: Sun 23 May 2010, 19:16
Location: near here
Contact:

#635 Post by darkcity »

updated wiki

http://puppylinux.org/wikka/PBurn

is this limitation still true?
It will only perform the writing function with a blank disc, i.e. the disc is either new, or, as in the case of a re-writable disc, it has been erased first.

Post Reply