GtkDialog - tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
Gedrean
Posts: 139
Joined: Fri 05 Jun 2009, 05:59

#81 Post by Gedrean »

It seems apparent that Laszlo Pere, while making a cool tool, managed to basically abandon it once it was able to create the tool he was actually aiming for, so documenting it was more of an afterthought for him.

Thanks to Zigbert for putting together all these awesome tips and helper notes, they've managed to make it so much easier (even as gtkdialog makes it so much harder) to build a good looking GUI.

User avatar
Ale
Posts: 34
Joined: Fri 30 Nov 2007, 06:14

#82 Post by Ale »

I have been working on a gui lately for prboom. Has anyone found a way to make the file select dialogs start in directories other than root?

The only work around I have found is to execute the script in a directory where one wishes to open it. What I am asking is if I can have different file select widgets start in different directories.

Thanks for your time.

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

#83 Post by sunburnt »

Hi Ale; I use the Xdialog file selector for my apps. ( This may be what you ment )
Notice the: /mnt after: --fselect and --dselect? Set the path there...

Code: Select all

FILE=`Xdialog --title "$TITLE" --dselect /mnt 0 0`
echo `Xdialog --title "$TITLE" --fselect /mnt 0 0` > /tmp/$Path-File
Two different ways of getting the /path/file info, a variable or a /tmp file.
The upper one is a directory /path selector and the lower is a /path/file selector.
An Xdialog file selector "bug": You must click on a file or no path is given.

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

#84 Post by zigbert »

Ale
You can execute 'cd /dir' before opening the fileselect widget.


Sigmund

User avatar
Ale
Posts: 34
Joined: Fri 30 Nov 2007, 06:14

#85 Post by Ale »

zigbert wrote:Ale
You can execute 'cd /dir' before opening the fileselect widget.


Sigmund
That does work quite well. I was using a helper script before to change the directory because I wanted to make it callable from the command line and open in a certain directory.

I wasn't specific enough, but I would like to know if it is possible to allow each file select box to search in separate directories. The first one would search in a directory of IWADs, and the second would be for PWADs, etc.

I used Technosaurus's template to get started and have been essentially working in reverse to learn more gtkdialog and bash.
My current work in progress can be found here:

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

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

#86 Post by sunburnt »

Ale; Both zigbert`s and my examples will open Xdialog or whatever in any dir. you specify.
Just change the parameters for each file browser you want to open.

Code: Select all

cd /(path)/IWADs
IFILE=`Xdialog --title "$TITLE" --fselect 0 0` 
cd /(path)/PWADs
PFILE=`Xdialog --title "$TITLE" --fselect 0 0` 

User avatar
Patriot
Posts: 733
Joined: Thu 15 Jan 2009, 19:04

#87 Post by Patriot »

Hmmm .....

@zigbert
I consider you our resident gtkdialog guru (at least so :) ), so I hope you can help shed some light ... I have completed my service manager script (alpha quality stage) and I'm wondering if its possible to specify specific entry widget width sizes ... I was about to take a whack at gtkdialog sources but I thought I'll ask you first .... Take a peek at the screenshot ... It's the entry widgets that displays either running or stopped messages, I can't seem to control the width (to make the width smaller) ...

Kindly advise.


Best Rgds
Attachments
svcdialog.png
(27.3 KiB) Downloaded 1579 times

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

#88 Post by sunburnt »

Just thought I`d pop in here Patriot, did you try the width-height tags?

Code: Select all

<width>60</width><height>30</height>
Also the next frame down with checkboxes is the widest thing on the GUI.
This sets the GUI width and gtkDialog has a tendency to "fill in the spaces".

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

#89 Post by technosaurus »

I haven't used height and width but it looks like it would "fix" itself if you put the Registered services only part on its own line (that line is increasing the width)

vbox
--- Registered services ....
hbox
---next checkbox
---next checkbox
....
/hbox
/vbox
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
Patriot
Posts: 733
Joined: Thu 15 Jan 2009, 19:04

#90 Post by Patriot »

Hmmm .....

Well, sunburnt, technosaurus ... thanks for your input ...

I've used previously the width/height tags (ie. width-request) but it didn't work as expected. I had already thought about the Registered services line length too and already tested it prior to posting the above question. Moving it onto its own line did not have any effect on the entry widget.

Anyway, after some messing with the tags, I now have an acceptable result. I've specified a longer text widget width and it squashed the entry widgets shorter and yet still retain overall compact window height. Still, there's no direct control over the entry widget widths ...

One thing that I find funny, for the text widget, specifying width-chars tag will make texts center justified within the specified width without being requested ...


Rgds

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

#91 Post by sunburnt »

Yeah, it all comes back to me like it was yesterday...
I can`t count how many times I have gotten disgusted with gtkDialog.
It`s fine for small simple utility GUIs like most of Puppy`s, but if the
complexity grows even a little bit, the GUI quickly becomes unmanageable.
Being able to absolute position the controls on the window would help a lot.
Another words... <left> & <top> tags in addition to <width> & <height>.

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

#92 Post by zigbert »

Hello Patriot (and everyone else) :)
This examples shows 2 ways how to place a <entry> widget. It will of course work the same way for vertical placement.

Code: Select all

#! /bin/bash
export MAIN_DIALOG='
<hbox width-request="300">
 <hbox width-request="20">
  <entry><height>50</height><width>20</width></entry>
 </hbox>
 <hbox width-request="200">
   <pixmap><input file>null</input></pixmap>
 </hbox>
</hbox>
'
gtkdialog -p MAIN_DIALOG
Looking forward to your service manager.
Please ask. I'm very happy to help you get used to gtkdialog. In fact, I'm extemly happy to see that you are using gtkdialog...... You are possibly one of very few around here that are capable to hack the source-code.


Sigmund

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

#93 Post by sunburnt »

Hi zigbert; I tried you suggestion and got an error, it doesn`t like the tag.

Code: Select all

# ./test
<
Error in line 28, near token 'hbox width-request=': syntax error
#
This is the control I added to a working gtkDialog script:

Code: Select all

 <hbox width-request="60">
 <entry><variable>ENTRY</variable><width>60</width><height>20</height></entry>
 </hbox>
 </vbox>
' 
gtkdialog2 --program=Test
It`s a gtkdialog2 script, I tried gtkdialog3, but it threw other errors.
There is a /usr/sbin/gtkdialog3, but I have had no luck using it.

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

#94 Post by zigbert »

sunburnt wrote:Error in line 28, near token 'hbox width-request=': syntax error
There is no line 28 in my test script. My test script works with gtkdialog3. If you have trouble with your code, please show us, and I'm sure someone will give some feedback.


Sigmund

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

#95 Post by seaside »

sunburnt wrote:Hi zigbert; I tried you suggestion and got an error, it doesn`t like the tag.

Code: Select all

# ./test
<
Error in line 28, near token 'hbox width-request=': syntax error
#
This is the control I added to a working gtkDialog script:

Code: Select all

 <hbox width-request="60">
 <entry><variable>ENTRY</variable><width>60</width><height>20</height></entry>
 </hbox>
 </vbox>
' 
gtkdialog2 --program=Test
It`s a gtkdialog2 script, I tried gtkdialog3, but it threw other errors.
There is a /usr/sbin/gtkdialog3, but I have had no luck using it.
Sunburnt,

Yes, Gtkdialog2 gives this error with that coding and Gtkdialog3 does not.

Also - I've found that if you use #!gtkdialog2/3 instead of bash to run a script, you need to link gtkdialog to gtkdialog2/3 or it won't work properly.

Perhaps standard Puppy should link all gtkdialog to gtkdialog3. (or will that break something else - maybe gtkdialog3 isn't totally back compatible) :D

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

#96 Post by sunburnt »

seaside; Yep, I had to add a 3 to gtkdialog in zigbert`s script and then it worked.
I`m guessing the tags I used in my script are gtkdialog2, so #3 errors.

This seems to be what I got from zigbert`s example

# First <hbox width-request="400"> sets total window width.
# Second <hbox width-request="40"> sets "Width=" spacing of control.
# Third <hbox width-request="200"> sets "Right=" spacing of control.
# Empty pix box is just a place holder for <hbox width-request="200">.

Subtract "Width" and "Right" spacings from "Total" spacing, we get "Left"
So to reverse; "Total" - "Left" - "Width" = "Right"
Last edited by sunburnt on Wed 21 Oct 2009, 23:13, edited 3 times in total.

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

#97 Post by sunburnt »

In fact the <width> and <height> tags in the entry box are unneeded.
The tag: <hbox width-request="200"> sets the entry box width...

Code: Select all

#! /bin/sh
export MAIN_DIALOG='
<vbox>
<hbox width-request="400">
 <hbox width-request="200">
  <entry></entry>
 </hbox>
 <hbox width-request="100">
   <pixmap><input file>null</input></pixmap>
 </hbox>
</hbox>

 <hbox width-request="100">
  <button cancel></button>
 </hbox>
</vbox>
'
gtkdialog3 -p MAIN_DIALOG
The button is a test, without the tag it`s full window width.

Addendum: I just removed the tag and it stays "short"... Weird!!!

### I keep getting this error... sh: locate: command not found

User avatar
Gedrean
Posts: 139
Joined: Fri 05 Jun 2009, 05:59

#98 Post by Gedrean »

sunburnt wrote:Addendum: I just removed the tag and it stays "short"... Weird!!!
A button inside an hbox is always "short". This is because the hbox must size itself to the needed width of the contents. With only one button, the hbox sizes itself to the needed width of the button. Likewise, the button expands to as much space as it is given within its container. The two logics combine together and so as a result the button takes exactly as much space as is needed for its text.

Otherwise, with no hbox to constrain it, it expands to window width.

User avatar
Patriot
Posts: 733
Joined: Thu 15 Jan 2009, 19:04

#99 Post by Patriot »

Hmmm .....

@zigbert, @sunburnt

There's another way to add controllable gaps:

Code: Select all

<text width-chars="10" height-request="80"><input>echo ""</input></text>
I've seen the "sh:locate bla bla bla" error before and used the above for gaps ... We can use the width/height tags to fine tune ... I believe the pixmap input uses locate to search for valid file ... You may want to update your tips section about the gaps ...

The service manager script needs just a little bit more polishing before going full alpha ...


Rgds

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

#100 Post by sunburnt »

Patriot; I tried your suggestion and couldn`t get it to work.
No surprise, most of these I couldn`t get to work for awhile.
I didn`t know <text> could take an <input> tag, I thought it only took <label>.
I seem to recall I tried that and it didn`t like it, maybe gtkDialog3 does it.
If so... Maybe there`s hope the TextBox label can be changed while running.

Perhaps change the "code" in your post above to a small "full GUI script".

Gedrean; Yes... But I removed the: <hbox width-request="100"> and it`s still small !

Post Reply