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

#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

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

#111 Post by technosaurus »

I built zenity without the gnome dependencies - only 49kb binary if anyone wants to try it out

http://live.gnome.org/Zenity
Zenity is a tool that allows you to display Gtk+ dialog boxes from the command line and through shell scripts. It is similar to gdialog, but is intended to be saner. It comes from the same family as dialog, Xdialog, and cdialog, but it surpasses those projects by having a cooler name.
Attachments
zenity-2.20.1-i486.pet
zenity-2.20.1-i486|zenity|2.20.1-i486||BuildingBlock|212K|pet_packages-4|zenity-2.20.1-i486.pet||no description provided|puppy|4|official|
(91.49 KiB) Downloaded 544 times
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
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#112 Post by sunburnt »

technosaurus; I`m willing to give it a go, my hope is that it`s saner than gtkDialog.
Obviously there will be some dependency chasing, something I`m use to...
If it`s a more base level control of the widgets than gtkDialog it might be better.
Consistency in how the controls work is key, something gtkDialog sorely lacks.
Then if a Bash wrapper were made and then a simple IDE, it could be real sharp.

I`ve made a GUI-IDE for gtkDialog, but I`m waiting to see what`s possible with it.

Patriot; You do know gtkDialog, I see now why the function didn`t work.
And my version lacked the "export -f add", but I`m not sure why it`s necessary.
I`ll play with it some more and see what it does for the script.

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

#113 Post by disciple »

I didn't know you could build zenity without gnome...
The rox guy maintaining his version of the trash roxapp uses zenity... it seemed to pretty much be xdialog or xmessage (can't remember which one we use for the trash) compatible. Does it have much extra functionality?
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#114 Post by 01micko »

techno

dir "zenity" seems that it should be in "/usr/local/share/"... not "/usr/share"... (I may be wrong) ..I had an error and so I coppied the dir and it works.... playing some more..

Code: Select all

# ./zen1

(zenity:29537): libglade-WARNING **: could not find glade file '/usr/local/share/zenity/zenity.glade'

** (zenity:29537): WARNING **: Could not load glade file : /usr/local/share/zenity/zenity.glade
And here's the code for the example I named "zen1"..

Code: Select all

#!/bin/bash
szAnswer=$(zenity --entry --text "where are you?" --entry-text "at home"); echo $szAnswer
from http://linux.byexamples.com/archives/25 ... xamples-1/

(Hmmmm... maybe a new topic techno???)

Thanks and cheers

Mick
Puppy Linux Blog - contact me for access

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

#115 Post by 8-bit »

I ran your script from a terminal and got "add: command not found"
So it was not recognizing the function call.
This is rough, from my inexperience, but try this modified script.
Other than adding the ending lines to have it run, pay attention to the inclusion of "sh " to the call of the function. :)

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>sh add</input></text>
 <button>
   <action>refresh:TEXT</action>
 </button>
 <button cancel></button>
</vbox>
'
gtkdialog3 -p MAIN_DIALOG
unset -f add
unset MAIN_DIALOG
IGNORE THIS! I had another script in the same directory I had called add and it was being used. So the function was not being called.
Last edited by 8-bit on Sat 24 Oct 2009, 14:40, edited 1 time in total.

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

#116 Post by technosaurus »

I didn't want to get off topic. I just thought it may help add some functionality to gtkdialog since you can do oneliner GUIs like xdialog but with a little better gtk integration and a couple different functions.

I compiled it with --prefix=/usr so it "should NOT" need to be in /usr/local unless it is somehow hardcoded. I'll have to take a look at the code and see.
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
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#117 Post by 01micko »

Nah, more that maybe it warrants a new topic :)
Puppy Linux Blog - contact me for access

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

#118 Post by zigbert »

Patriot
Using <frame> as separator in <notebook> is great. I have updated main post. Thanks a lot.

It has been a known bug for a long time that a gtkdialog script including <menubar> doesn't exit correct when closing via wm. The worst is still that background processes will not be closed. (like a while loop for a progressbar.) This eats the cpu power. I have solved it with a background loop checking for window using xwininfo. /usr/bin/pburn includes such a loop. The following example shows it:

Code: Select all

#!/bin/sh

export MAIN_DIALOG='
<vbox>
 <menubar>
  <menu>
   <menuitem icon="gtk-new">
    <label>New</label>
   </menuitem>
   <menuitem icon="gtk-open">
    <label>Open...</label>
   </menuitem>
   <label>File</label>
  </menu>
 </menubar>
 <hbox>
  <text><label>Bash PID is :</label></text>
  <text><input>cat /tmp/tmp</input></text> 
 </hbox>
 <text><label>Please close this script with the button in upper-right corner of the jwm window. and see that both the bash PID is running, and that `ps | grep gtkdialog` shows result.</label></text>
</vbox>
'

echo $$ > /tmp/tmp
gtkdialog3 -p MAIN_DIALOG -c


Now to your script with parent/child windows. It works just great, but not if you want child window to act on the main window. It is a great feature in gtkdialog that different windows cooperate well. In fact they are all the same program... I have extended your script to show what I mean.

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>
     <text><label> But since I have my own PID, I cant act on my parent dialog. </label></text>
   </frame>
   <button><label>increase number</label>
     <action>A=$(cat /tmp/tmp); echo $(($A+1)) > /tmp/tmp</action>
     <action>refresh:TEXT</action>
   </button>
  </vbox>
</window>
'

export LAUNCED_DIALOG='
  <vbox>
    <text>
      <label>This is an other dialog window.</label>
    </text>
    <button><label>increase number</label>
      <action>A=$(cat /tmp/tmp); echo $(($A+1)) > /tmp/tmp</action>
      <action>refresh:TEXT</action>
    </button>
    <button>
      <label>Close me</label>
      <action type="closewindow">LAUNCED_DIALOG</action>
    </button>
  </vbox>
'

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"><variable>TEXT</variable><input>cat /tmp/tmp</input></text>
   </frame>
   <button><label>Open child dialog with unique PID</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 with unique PID</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>launch child dialog</label>
     <action type="launch">LAUNCED_DIALOG</action>
   </button>
   <button><label>close child dialog (but look what happens)</label>
     <action type="closewindow">LAUNCED_DIALOG</action>
   </button>

   <button><label>Exit </label>
   <action>p=$(cat /tmp/child.pid) ; kill $p</action>
   <action>exit:Exit</action>
   </button>
  </vbox>
</window>>
'
echo 1 > /tmp/tmp
gtkdialog3 -p MAIN_DIALOG -c
unset CHILD_DIALOG
unset MAIN_DIALOG 

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

#119 Post by Patriot »

Hmmm .....

zigbert

I read the menubar issue above and I thought of a borked event checking ... I'm guessing that the events probably got mixed-up during the parsing ... I hope this specific workaround can help to make your day easier ...

Code: Select all

#!/bin/sh

export MAIN_DIALOG='
<window title="Borked gtkd" icon-name="gtk-info">

<vbox>
  <menubar>
	<menu>
		<menuitem stock="gtk-open">
		<action>echo You selected the open menu item.</action>
		</menuitem>
		<menuitem stock="gtk-save">
		<action>echo You selected the open menu item.</action>
		</menuitem>
		<separator></separator>
		<menuitem stock="gtk-quit">
		<action>echo You selected the quit menu item</action>
		<action type="exit">exit by menu</action>
		</menuitem>
		<label>File</label>
	</menu>
  </menubar>
  <text><label>""</label></text>
  <text width-chars="40"><label>Please close this window using the close button in upper-right corner of the jwm window ...</label></text>
  <text><label>""</label></text>
  <text width-chars="40"><label>Hey, zigbert, I need more coffee !</label></text>
  <text><label>""</label></text>
</vbox>

<action signal="hide">exit:Exit</action>
</window>
'

echo $$ > /tmp/tmp
gtkdialog3 -p MAIN_DIALOG -c

Really, I get dizzy skimming through gtkdialog sources ... JWM was a lot more fun than that ... The launch and close window issue is probably related to a borked widget checking ... I believe that the widget window is pointing to itself and closing any window resulted in closing itself ... A workaround could be possible but I'm out of coffee right now .....

Nope, I'm not touching the sources for now ... I thought CUPS sources was hard ... Compared to gtkdialog, CUPS sources now seems like a walk in the park ..... I know, I know, I'm lame with C .....


Rgds

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

#120 Post by zigbert »

Patriot
You are Good.
I have to test your workaround more, but it seems to work excellent.

I am glad you took your time to skimming the source code. Even if you haven't hacked anything in gtkdialog3, you have solved 3 issues ..... already. :)


See you around
Sigmund

Post Reply