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
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 !

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

#101 Post by Gedrean »

sunburnt wrote: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 !
First, input tag is available for a whole lot of items. It runs a command in shell and stdout goes to the item's value or label or whatever. So to pull an exported $VAR, echo "$VAR".

And as far as the tag, you removed the hbox part too? weird.

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

#102 Post by sunburnt »

I tried this and there`s no error for having the <variable> in the <text> tag.
But it won`t run: ** ERROR **: gtkdialog: Error in line 5, near token '>': syntax error
Line 5 is: <action clear>TEXT</action><action>refresh:TEXT</action>
It appears unwilling to use the TEXT variable, if I take the line out it runs...

Code: Select all

#! /usr/sbin/gtkdialog3 -e
text() {
 echo 'TEST 2' > /tmp/test.txt
}
export MAIN_DIALOG='
<vbox>
 <text><variable>TEXT</variable>
   <input>cat /tmp/test.txt</input></text>
 <button><action>text</action>
   <action clear>TEXT</action><action>refresh:TEXT</action>
 </button>
 <button cancel></button>
</vbox>
'

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

#103 Post by Patriot »

Hmmm .....
sunburnt wrote:.....
Line 5 is: <action clear>TEXT</action><action>refresh:TEXT</action>
.....
It's the misplaced closing tag, ie: "<action clear>TEXT" should be <action>clear:TEXT" but the text widget does not seem to have clear function to it ...

Allow me to give a simpler example, if I may:

Code: Select all

#!/bin/sh

export MAIN_DIALOG='
<vbox>
 <text><variable>TEXT</variable>
   <input>cat /tmp/test.txt</input></text>
 <button>
   <action>echo "NEW TEXT">/tmp/test.txt</action>
   <action>refresh:TEXT</action>
 </button>
 <button cancel></button>
</vbox>
'

echo 'INIT' > /tmp/test.txt
gtkdialog3 -p MAIN_DIALOG
unset MAIN_DIALOG
Yeah, perhaps I should mention that I'm using only gtkdialog3 ... If I hit a brick wall, maybe I'll use gtkdialog4, who knows ....


Rgds

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

#104 Post by Gedrean »

Since WHEN is there a gtkdialog4?

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

#105 Post by zigbert »

Patriot
Yes, I will update main post with your gap-code. But wouldn't
<text width-chars="10" height-request="80"><label>""</label></text>
be better than
<text width-chars="10" height-request="80"><input>echo ""</input></text>


..... In case you ever hit a brick wall , I think you should know these thoughts :)
You should not feel any of this as a pressure. - It is just for pleasure.....

I think gtkdialog could benefit of some simple fixes. I don't ask for new features, nor ask for fixing all known bugs. I will only talk about small fixes (I THINK they are small) that will give gtkdialog new kind of use.

1. <action type="closewindow"> doesn't work from other windows than itself. (The one containing this code. - Not from the window that launched the new window.) It would be very handy that the main gui could control its satellites.

2. Today gtkdialog supports drag'n drop as explained in my main post. To build drag'n drop support between <tree> widgets, they must be set to <tree hover-selection="true">. Most common, and most flexible is to use a normal selection mode. The reason why normal selection doesn't support drag'n drop is because <action signal="button-press-event"> is executed before item is selected. If it was the other way around, drag'n drop would be possible.

3. What do we need to get a right-click-menu:
- First we need to fix the above (nr. 2).
- The <menu> widget must be loadable without a <menubar>.
- Now we could launch a new gui with a <menu> if user right-clicks.
- The launched gui must use <window decorated="false" skip_taskbar_hint="true">, but skip taskbar doesn't work.

4. Click on <table> header doesn't sort.

5. It is not easy to build a scalable gui (increase size by dragging in wm window corner, and gui still fill window). Including a notebook into the gui, makes it nearly impossible to remain scalable. If <notebook> could use another seperator than <vbox>, it would be easier to scale a gui including tabs.

6. Close gui including <menubar> from wm, doesn't kill pid. This major bug is irritating and it is hard to get an easy workaround.

7. <list selection-mode="3"> allows user to select multiple items in list, But gtkdialog doesn't output any value. Why multiple selection is included for <list>, and not <tree> is weird for me, but I promised not to ask for new features, so it's time to stop now :)


Take care
Sigmund

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

#106 Post by Patriot »

Hmmm .....

zigbert,
zigbert wrote:..... But wouldn't
<text width-chars="10" height-request="80"><label>""</label></text>
be better than .....
Hey, that's a quicker way ... great catch zigbert .... I tried the <label> tags before but missed the quotes ... See, that's why you're our resident gtkdialog guru .....

I knew you love carrots zigbert :)... Sure, if I hit a brickwall (and couldn't find a wand to zap it) then we'll see how gtkdialog4 will come about .... Ok, your list is noted, but you should first know that I'm a klutz with GTK2 ....

Now, item 1 seems to be possible to achieve with a scripted workaround. I'll try to whip up a sample later ..... That item 5 about notebook, well, I'm using <frame> as separators ... is that any help for now ? But, that item no 6. close gui issue sounds like fun ... Which one of your apps have this difficulty ? Or could you whip up a sample ?


Rgds

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

#107 Post by sunburnt »

Patriot; Delightedly your example works, but too simple. I`ve spent several hours trying to make it do something useful.
If we can get it to interact with a function we`re home... Run a function that increments a number and displays it in the textbox:

Code: Select all

#! /usr/sbin/gtkdialog3 -e
add() {
  N=`expr $N + 1`
  echo $N
}
N=0
export MAIN_DIALOG='
<vbox>
 <text><variable>TEXT</variable>
   <input>add</input></text>
 <button>
   <action>refresh:TEXT</action>
 </button>
 <button cancel></button>
</vbox>
'
It starts up displaying "1", so the function runs and adds, and the textbox displays "1", so it works the first time.
Press the OK button and nothing happens, refreshing TEXT should run the function again and increment $N. It works the first time???
This is the simplest attempt, I also tried:

Code: Select all

#! /usr/sbin/gtkdialog3 -e
add() {
  N=`expr $N + 1`
  echo $N
}
N=0
add
export MAIN_DIALOG='
<vbox>
 <text><variable>TEXT</variable>
   <input>echo $N</input></text>
 <button>
   <action>add</action>
   <action>refresh:TEXT</action>
 </button>
 <button cancel></button>
</vbox>
'
I also tried using files to hold the variable as in your example, no luck... Using variables is always preferable to files.

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

#108 Post by sunburnt »

I found this trying to find a way to use GTK+ with Bash:
http://bror.org/mark/software/gtkbash/
It looks like it uses Bash scripts to run C commands to GTK+.
Using GTK+ would probably be much better than gtkDialog ( going to the source ).
Here`s the downloaded file, it has examples but the executable "gtk.bash" needs compiling.

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

#109 Post by Patriot »

Hmmm .....

sunburnt

Always remember that gtkdialog script cannot access or modify bash variables directly ... So, lets make do with what we have first ...

This one's for you :

Code: Select all

#!/bin/sh

add() {
  N=$(cat /tmp/number)
  let N=N+1
  echo $N
  echo $N >/tmp/number
}

export -f add
echo 0>/tmp/number

export MAIN_DIALOG='
<vbox width-request="160">
 <text><variable>TEXT</variable>
   <input>add</input></text>
 <button>
   <action>refresh:TEXT</action>
 </button>
 <button cancel></button>
</vbox>
'

gtkdialog3 -p MAIN_DIALOG
unset -f add
unset MAIN_DIALOG

I suggest doing your gtkdialog with /bin/sh ... It's more predictable it seems ... If you want to know why, comment out the last three lines above and change the shebang to #!/usr/sbin/gtkdialog3 -e ....

Run the script and try to explain to yourself why it does what it does .....


Rgds

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

#110 Post by Patriot »

Hmmm .....

zigbert

I have a bit of free time, so I did a working sample of gtkdialog3 parent-control-for-launching-and-closing-child. You can expand it to control all known opened dialogs ...

Code: Select all

#!/bin/sh

export CHILD_DIALOG='
<window title="Child Dialog">
  <vbox width-request="180">
	<frame>
	  <text><label> I am coming </label></text>
	  <text><label> out to play. </label></text>
	</frame>
  </vbox>
</window>
'

export MAIN_DIALOG='
<window title="Main Dialog">
  <vbox width-request="240">
  <text width-chars="40"><label>"Clickity click to open"</label></text>
  <text width-chars="40"><label>"Clickity click to close"</label></text>
  <text width-chars="40"><label>"Clickity click to exit"</label></text>
	<frame>
	<text width-chars="40" height-request="120"><label>""</label></text>
	</frame>
	<button><label>Open child dialog</label>
	  <variable>OCD</variable>
	  <action>gtkdialog3 -p CHILD_DIALOG -c &</action>
	  <action>echo $(ps ax|awk '"'"'{if (match($7, "CHILD_DIALOG")) print $1}'"'"')>/tmp/child.pid</action>
	  <action>enable:CCD</action>
	  <action>disable:OCD</action>
	</button>
	<button sensitive="false"><label>close child dialog</label>
	  <variable>CCD</variable>
	  <action>[ -f /tmp/child.pid ] && p=$(cat /tmp/child.pid) && kill $p</action>
	  <action>enable:OCD</action>
	  <action>disable:CCD</action>
	</button>
	<button><label>Exit </label>
	<action>p=$(cat /tmp/child.pid) ; kill $p</action>
	<action>exit:Exit</action>
	</button>
  </vbox>
</window>>
'

gtkdialog3 -p MAIN_DIALOG -c
unset CHILD_DIALOG
unset MAIN_DIALOG
Have fun and see you later ...

Rgds

Post Reply