Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 22 May 2013, 14:30
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
GtkDialog - tips
Post new topic   Reply to topic View previous topic :: View next topic
Page 8 of 52 [767 Posts]   Goto page: Previous 1, 2, 3, ..., 6, 7, 8, 9, 10, ..., 50, 51, 52 Next
Author Message
Patriot


Joined: 15 Jan 2009
Posts: 734

PostPosted: Thu 22 Oct 2009, 15:36    Post subject:  

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 Smile... 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
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 4005
Location: Arizona, U.S.A.

PostPosted: Thu 22 Oct 2009, 16:24    Post subject:  

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:
#! /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:
#! /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.
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 4005
Location: Arizona, U.S.A.

PostPosted: Thu 22 Oct 2009, 18:13    Post subject:  

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.
libgtkbash-0.0.1.tar.gz
Description 
gz

 Download 
Filename  libgtkbash-0.0.1.tar.gz 
Filesize  232.4 KB 
Downloaded  271 Time(s) 
Back to top
View user's profile Send private message 
Patriot


Joined: 15 Jan 2009
Posts: 734

PostPosted: Thu 22 Oct 2009, 19:22    Post subject:  

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:
#!/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
Back to top
View user's profile Send private message 
Patriot


Joined: 15 Jan 2009
Posts: 734

PostPosted: Thu 22 Oct 2009, 19:29    Post subject:  

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:
#!/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
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 3843

PostPosted: Thu 22 Oct 2009, 20:29    Post subject:  

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

http://live.gnome.org/Zenity

Quote:
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.
zenity-2.20.1-i486.pet
Description  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|
pet

 Download 
Filename  zenity-2.20.1-i486.pet 
Filesize  91.49 KB 
Downloaded  292 Time(s) 

_________________
Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 4005
Location: Arizona, U.S.A.

PostPosted: Thu 22 Oct 2009, 21:12    Post subject:  

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.
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6179
Location: Auckland, New Zealand

PostPosted: Thu 22 Oct 2009, 22:00    Post subject:  

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?

_________________
DEATH TO SPREADSHEETS
- - -
Classic Puppy quotes
- - -
Beware the demented serfers!
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 7018
Location: qld

PostPosted: Fri 23 Oct 2009, 01:08    Post subject:  

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:
# ./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:
#!/bin/bash
szAnswer=$(zenity --entry --text "where are you?" --entry-text "at home"); echo $szAnswer
from http://linux.byexamples.com/archives/259/a-complete-zenity-dialog-examples-1/

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

Thanks and cheers

Mick

_________________
keep the faith Cool ..
Back to top
View user's profile Send private message Visit poster's website 
8-bit


Joined: 03 Apr 2007
Posts: 3012
Location: Oregon

PostPosted: Fri 23 Oct 2009, 02:42    Post subject:
Subject description: Modification to your add script by me.
 

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. Smile
Code:

#! /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, 10:40; edited 1 time in total
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 3843

PostPosted: Fri 23 Oct 2009, 10:16    Post subject:  

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.

_________________
Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 7018
Location: qld

PostPosted: Fri 23 Oct 2009, 15:55    Post subject:  

Nah, more that maybe it warrants a new topic Smile
_________________
keep the faith Cool ..
Back to top
View user's profile Send private message Visit poster's website 
zigbert


Joined: 29 Mar 2006
Posts: 5241
Location: Valåmoen, Norway

PostPosted: Fri 23 Oct 2009, 19:51    Post subject:  

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:
#!/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:
#!/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

_________________
Stardust resources
Back to top
View user's profile Send private message Visit poster's website 
Patriot


Joined: 15 Jan 2009
Posts: 734

PostPosted: Sat 24 Oct 2009, 00:03    Post subject:  

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:
#!/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
Back to top
View user's profile Send private message 
zigbert


Joined: 29 Mar 2006
Posts: 5241
Location: Valåmoen, Norway

PostPosted: Sat 24 Oct 2009, 04:05    Post subject:  

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. Smile


See you around
Sigmund

_________________
Stardust resources
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 8 of 52 [767 Posts]   Goto page: Previous 1, 2, 3, ..., 6, 7, 8, 9, 10, ..., 50, 51, 52 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1159s ][ Queries: 12 (0.0113s) ][ GZIP on ]