Can`t get gtkDialog3 version of app. to work. [Solved]

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
potong
Posts: 88
Joined: Fri 06 Mar 2009, 04:01

#21 Post by potong »

sunburnt: HTH

Code: Select all

#!/bin/sh -a 
# -a option exports all variables and functions

RIGHT=14 DOWN=36 WIDTH=80 HEIGHT=150 # define variables with defaults
DRIVE= # export this variable now so the script can use it after gtkdialog3
       # has assigned it a value

#probepart |grep -v none |sed 's#^/dev/##' |sed 's/|.*$//' |sed 's/$/||/' > /tmp/drvinfo       # make tablebox input file
# Do we need a temp file?
# Stick it in a function and you can refresh it from the gui.

pp(){ probepart|sed '/\(none\|swap\)/d;s|/dev/||;s/|.*//'; }

display(){ echo "drive selected: ${!1}"; }

GUI=$(cat <<EOV|sed 's/#.*//'|tee /tmp/gui1 /tmp/gui3 # interpolate and allow comments in gui
#<window title="GUI" default_width="$WIDTH" default_height="$HEIGHT"> # comment
<window title="GUI"> # let the geometry option control the size and placement
 <vbox>
  <table>
   #<label>Drive|M|B</label>
   <label>Drive</label>
   <variable>DRIVE</variable>
   <input>pp</input>
  </table>
  <button use-underline="true" label="_Refresh">
   #<action>echo \$DRIVE</action> # must escape variable. Do you understand why?
   <action>display DRIVE</action> # call display use DRIVE indirectly
   <action type="clear">DRIVE</action>
   <action type="refresh">DRIVE</action>
  </button>
  <button cancel></button>
 </vbox>
</window>
EOV)

# run gui 3 times (peruse files /tmp/gui1 /tmp/gui2 /tmp/gui3)
gtkdialog3 -d -p GUI -G ${1-${WIDTH}x${HEIGHT}+${RIGHT}+${DOWN}} # --program
gtkdialog3 -d -f /tmp/gui1 -G ${1-${WIDTH}x${HEIGHT}+${RIGHT}+${DOWN}} # --file
# prepare files to run --event-driven (/tmp/gui2 & /tmp/gui3)
# N.B. --geometry not effective when used in this context 
#      so use width/height request instead
sed '/^GUI/,$d' $0 >/tmp/gui2
sed -i '$a\gtkdialog3 -e /tmp/gui3' /tmp/gui2
sed -i -e "1i\export MAIN_DIALOG='" -e "\$a\'" /tmp/gui3
sed -i 's/GUI"/& width-request="'$WIDTH'" height-request="'$HEIGHT'"/' /tmp/gui3
chmod +x /tmp/gui2
/tmp/gui2
Potong

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

#22 Post by sunburnt »

Very interesting potong, lots of nifty code... You`re right, a file isn`t needed for the Table.
But I can`t figure out what code made the GUI capable of being smaller.
Is it using only the geometry option? Please simplify what made it behave properly.
You`ve changed so much about the way the GUI works, it`s very hard to tell...

P.S. Ahhh yes... Now I remember why the Table needs a file, a variable won`t display right!

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

#23 Post by sunburnt »

Three cheers for potang, I got it sizing the gtkDialog3 GUI to any size in code..!!!
So weird that the GUI only gets bigger and never smaller with the mouse. Serious Bug!
But anyway... If you shutdown the GUI it will come back to the specified size when run again.

potong
Posts: 88
Joined: Fri 06 Mar 2009, 04:01

#24 Post by potong »

It boils down to this:

Code: Select all

#!/bin/sh -a

RIGHT=14 DOWN=36 WIDTH=80 HEIGHT=80 # define variables with defaults

GUI='
 <vbox>
  <button cancel></button>
 </vbox>
'
gtkdialog3 -p GUI -G ${1-${WIDTH}x${HEIGHT}+${RIGHT}+${DOWN}} # --program
Highlight the code above in your browser and then open a terminal and type:

Code: Select all

xclip -o >/tmp/gui; chmod +x /tmp/gui
If you want to play with the --geometry option, enter something like this:

Code: Select all

/tmp/gui 200x200+500+500
or

Code: Select all

/tmp/gui 75x75+0+0
or

Code: Select all

/tmp/gui 100x100
or

Code: Select all

/tmp/gui +200+600
or

Code: Select all

/tmp/gui
for the default geometry

Potong

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

#25 Post by 8-bit »

I have noticed in a number of gtkdialog3 programs that temporary file(s) are created in /tmp.
The reasoning is that the /tmp directory will be rebuilt when Puppy is next run.
This is true for frugal installs of Puppy.
But with a full install of Puppy, the /tmp directory does not get rebuilt and the temporary files do not get automatically removed on reboot.
So it would be good practice to add lines to the gtkdialog3 script when one creates it to remove those temporary files.

Comments?

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

#26 Post by sunburnt »

Actually the /tmp dir. use to be in ram only, so it was erased by default upon rebooting.
But now that Puppy unions on "/", the /tmp dir. has to be deleted by code at shutdown.
This means temp. files in /tmp aren`t really temp. at all... They`re written to the Save layer.
This slows the read / write procedure down as accessing /tmp is an access to the HD usually.

potong; Thanks, I got my small test GUI ( like the one you`ve shown above...) working..!
I like your extended strung out sed command, I`ve tried ones like it but have had little luck.
Defining the body of the GUI code differently is interesting also, it has some possibilities.

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

#27 Post by 8-bit »

sunburnt wrote:Three cheers for potang, I got it sizing the gtkDialog3 GUI to any size in code..!!!
So weird that the GUI only gets bigger and never smaller with the mouse. Serious Bug!
But anyway... If you shutdown the GUI it will come back to the specified size when run again.
The thing that bothers me is that there seems to be no consistency in use of code.

For example, Zigbert's example of saving window size and position slightly modified by me, works and will let you resize the window down to it's original size.
But the same code segments placed in your Driveman script will NOT let you shrink the size of the window.

The modified code from Zigbert so you can see what I mean.
Run it once and exit. Then when you run it again, it will show the window with the new size and position. And it WILL let you shrink the window back to its original size!

Code: Select all

#! /bin/bash
. /tmp/geometry
save_geometry (){
   XWININFO=`xwininfo -stats -name SizeMe`
   HEIGHT=`echo "$XWININFO" | grep 'Height:' | awk '{print $2}'`
   WIDTH=`echo "$XWININFO" | grep 'Width:' | awk '{print $2}'`
   X1=`echo "$XWININFO" | grep 'Absolute upper-left X' | awk '{print $4}'`
   Y1=`echo "$XWININFO" | grep 'Absolute upper-left Y' | awk '{print $4}'`
   X2=`echo "$XWININFO" | grep 'Relative upper-left X' | awk '{print $4}'`
   Y2=`echo "$XWININFO" | grep 'Relative upper-left Y' | awk '{print $4}'`
   X=$(($X1-$X2))
   Y=$(($Y1-$Y2))
   echo "export HEIGHT=$HEIGHT"   > /tmp/geometry
   echo "export WIDTH=$WIDTH"      >> /tmp/geometry
   echo "export X=$X"            >> /tmp/geometry
   echo "export Y=$Y"            >> /tmp/geometry
   chmod 700 /tmp/geometry
}

export -f save_geometry
[ -f /tmp/geometry ] && /tmp/geometry

export DIALOG="
<window title="SizeMe" default_height="$HEIGHT" default_width="$WIDTH">
  <vbox>
    <frame>
      <text>
        <label>If you resize or move this window, it will be remembered for next time.</label>
      </text>
    </frame>
    <hbox>
    <button>
      <label>Exit</label>
      <action signal="button-press-event">save_geometry</action>
      <action type="Exit">exit 0</action>
    </button>
    </hbox>
  </vbox>
</window>"

./tmp/geometry

gtkdialog3 --program=DIALOG --geometry +"$X"+"$Y"


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

#28 Post by sunburnt »

The thing that bothers me is that there seems to be no consistency in use of code.
This my experience with gtkDialog altogether... Especially gtkDialog3.
Users are driven to inconsistent use by no docs. and gtkDialog`s twitchy behavior.
gtkDialog is to blame...

This is what I finally settled upon that works ( works for me at least... :roll: ):

Code: Select all

export GUI="<window title=\"GUI\"><vbox>
  <button><label>Exit</label><action>gtkdialog.lib saveGeometry GUI $appPATH</action>
    <action type=\"Exit\">exit</action></button></vbox></window>"
gtkdialog3 -p GUI -G "$WIDTH"x"$HEIGHT"+"$LEFT"+"$TOP"

potong
Posts: 88
Joined: Fri 06 Mar 2009, 04:01

#29 Post by potong »

sunburnt: A small change to the window directive (adding allow-shrink="true") allows the user to resize in either direction.

Code: Select all

#!/bin/sh -a

RIGHT=14 DOWN=36 WIDTH=80 HEIGHT=80 # define variables with defaults

GUI='
<window allow-shrink="true">
 <vbox>
  <button cancel></button>
 </vbox>
</window>
'
gtkdialog3 -p GUI -G ${1-${WIDTH}x${HEIGHT}+${RIGHT}+${DOWN}} # --program 
Save the above code to /tmp/gui and try

Code: Select all

/tmp/gui 500x500+200+200
However the documentation does say this:
The "allow-shrink" property

"allow-shrink" gboolean : Read / Write

If TRUE, the window has no minimum size. Setting this to TRUE is 99% of the time a bad idea.

Default value: FALSE
On the other hand use

Code: Select all

<window allow-grow="false">
to prevent the user from resizing the gui

Potong

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

#30 Post by sunburnt »

Yep, that allows the GUI to be made to any size with the mouse.
Another code scrap for zigbert`s tutorial on gtkDialog...

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

#31 Post by 8-bit »

potong,
If I may be so bold as to ask, where are you getting this info from?
Is it from examining the source code or is their a site we can access to see more?

User avatar
trio
Posts: 2076
Joined: Sun 21 Dec 2008, 15:50
Location: अनà¥￾मोदना

#32 Post by trio »

haha, potong is "the guru" of gtkdialog..he's the one responsible that make Zigbert ditched "ptooltips" after potong told him that gtkdialog has inbuilt 'tooltips'...many hidden things inside gtkdialog were introduced to us by him...

potong
Posts: 88
Joined: Fri 06 Mar 2009, 04:01

#33 Post by potong »

8-bit:
You can find a lot of information here http://library.gnome.org/devel/gtk/stable
Also see my original post http://murga-linux.com/puppy/viewtopic.php?t=38608
For instance: see the the window widget here http://library.gnome.org/devel/gtk/stab ... indow.html and look in particular at its properties

Code: Select all

Properties

  "accept-focus"             gboolean              : Read / Write
  "allow-grow"               gboolean              : Read / Write
  "allow-shrink"             gboolean              : Read / Write
  "decorated"                gboolean              : Read / Write
  "default-height"           gint                  : Read / Write
  "default-width"            gint                  : Read / Write
  "deletable"                gboolean              : Read / Write
  "destroy-with-parent"      gboolean              : Read / Write
  "focus-on-map"             gboolean              : Read / Write
  "gravity"                  GdkGravity            : Read / Write
  "has-toplevel-focus"       gboolean              : Read
  "icon"                     GdkPixbuf*            : Read / Write
  "icon-name"                gchar*                : Read / Write
  "is-active"                gboolean              : Read
  "modal"                    gboolean              : Read / Write
  "opacity"                  gdouble               : Read / Write
  "resizable"                gboolean              : Read / Write
  "role"                     gchar*                : Read / Write
  "screen"                   GdkScreen*            : Read / Write
  "skip-pager-hint"          gboolean              : Read / Write
  "skip-taskbar-hint"        gboolean              : Read / Write
  "startup-id"               gchar*                : Write
  "title"                    gchar*                : Read / Write
  "transient-for"            GtkWindow*            : Read / Write / Construct
  "type"                     GtkWindowType         : Read / Write / Construct Only
  "type-hint"                GdkWindowTypeHint     : Read / Write
  "urgency-hint"             gboolean              : Read / Write
  "window-position"          GtkWindowPosition     : Read / Write
Remember most widgets have hierarchy

Code: Select all

GObject
   +----GInitiallyUnowned
         +----GtkObject
               +----GtkWidget
                     +----GtkContainer
                           +----GtkBin
                                 +----GtkWindow
                                       +----GtkDialog
                                       +----GtkAssistant
                                       +----GtkPlug
and so their properties can be used too.
To get a list of widgets used by gtkdialog you'll have to inspect the source code. It's pretty old now so some of the widgets are deprecated.

HTH

Potong

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

#34 Post by sunburnt »

Hope It Helps ??? Big time..!!!
This is more info about gtkDialog than I`ve seen in the 4 years I`ve been trying to use it!

potong; If you would be so kind...

-f, --file=filename Get the GUI description from a regular file.
Use like this: gtkdialog3 -f /path/file.gtk -G "$WIDTH"x"$HEIGHT"+"$LEFT"+"$TOP" &
And the body of the gtkDialog code is in: /path/file.gtk ( "kinda" like your example showed ).

-e, --event-driven=filename Execute the file as an event driven program.
This I have no idea where to begin with how to use it...

potong
Posts: 88
Joined: Fri 06 Mar 2009, 04:01

#35 Post by potong »

sunburnt:
Here's a program written in two ways to show the different options.

First the --file=filename and a shell wrapper script to run it

Code: Select all

#!/bin/sh -a
display(){ echo "Display: ${!1}"; }
cat <<EOV >/tmp/gui_file
<window>
 <vbox>
  <text label="Run from a terminal and monitor the messages"></text>
  <entry>
   <variable>ENTRY</variable>
   <default>Here is some text</default>
  </entry>
  <button use-underline="true" label="_Display">
   <action>display ENTRY</action>
  </button>
  <button cancel></button>
 </vbox>
</window>
EOV
gtkdialog3 -f /tmp/gui_file
now highlight the code above and in a terminal type:

Code: Select all

xclip -o >/tmp/a; chmod +x /tmp/a; /tmp/a
Observe the messages when you click Display.
Also type:

Code: Select all

cat /tmp/gui_file
and see the gui description.

Secondly --event-driven=filename

Code: Select all

#!/usr/sbin/gtkdialog3 -e
display(){ echo "Display: ${!1}"; }
export MAIN_DIALOG='
<window>
 <vbox>
  <text label="Run from a terminal and monitor the messages"></text>
  <entry>
   <variable>ENTRY</variable>
   <default>Here is some text</default>
  </entry>
  <button use-underline="true" label="_Display">
   <action>display ENTRY</action>
  </button>
  <button cancel></button>
 </vbox>
</window>
'
now highlight the code above and in a terminal type:

Code: Select all

xclip -o >/tmp/b; chmod +x /tmp/b; /tmp/b
You'll see the same program but run using the gtkdialog3 program directly.

HTH

Potong

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

#36 Post by zigbert »

Thank you potong. Great stuff here.
I have updated tips and tricks.
I have not added your wild progressbar examples...... I need a newer gtk to get it working.


Sigmund

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

#37 Post by 8-bit »

After reading some of the options for a gtkdialog window, trying them and not having them work, I begin to wonder if those options are even in GTK-2.0 that is included with Puppy.
Or is it a matter of not structuring the code line right for the option to work.
It is frustrating to have a list of window options that are supposed to let you do something with a window and then not have it work.
Also, they seem to be geared for writing a GUI in C rather than just a script.
As an example, Zigbert's size and position script lets you resize a window to it's original size. But using the same code segments in another script for the position and resize with save, takes the new size as the minimum window size and will not let you resize the window to it's original size.
Show me a short script that will let me shrink a window to it's original size and I will be happy.
I already tried "min_height=[height]" as an option along with "allow_shrink="true"" and I still cannot get a window back to it's original size using the mouse.

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

#38 Post by sunburnt »

8-bit; try this:

Code: Select all

export GUI="<window title=\"GUI\" allow_shrink=\"true\"><vbox>
  <button><label>Exit</label><action type=\"Exit\">exit</action></button></vbox></window>"
gtkdialog3 -p GUI -G 200x200+20+40
It will shrink all the way down to almost nothing for me... :wink:

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

#39 Post by 8-bit »

sunburnt wrote:8-bit; try this:

Code: Select all

export GUI="<window title="GUI" allow_shrink="true"><vbox>
  <button><label>Exit</label><action type="Exit">exit</action></button></vbox></window>"
gtkdialog3 -p GUI -G 200x200+20+40
It will shrink all the way down to almost nothing for me... :wink:
Thank you, it works! My mistake was including a default_height and default_width in the <window .....> line.
But I also noticed in the docs potong gave links to that on can supposedly set a min-width and min-height for the window.
I tried those, with your allow_shrink and they do not stop me from shrinking the window to a very small size.
Again, it may just be a matter of how to phrase those options.
But I guess we learn as we go along.

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

#40 Post by sunburnt »

I made a small gtkDialog tester to check the Tags in large files.
Now it needs to be expanded to check other parts of the syntax.
The file: /root/my-applications/bin/gtkdialog.test

Code: Select all

#!/bin/sh
#####		Test gtkDialog file for errors.
N=0
FILE=`Xdialog --stdout --title "  Select gtkDialog file." --fselect /mnt/home/apps/driveman 0 0`
[ $? -gt 0 ]&& exit
echo "    ###   NO Tag problems found.  ###" > /tmp/gtk-test.results ; GTK=$(<$FILE)

for TAG in vbox hbox pix note list edit text tree menu label input entry radio check table frame combo width height action button window variable progress @
do																															#####		Read the entire file each loop looking for the Tag.
	[ $TAG = '@' ]&& break
	PLUS=`echo "$GTK" |grep -o '<'$TAG | wc -w`
	MINUS=`echo "$GTK" |grep -o '</'$TAG | wc -w`
	N=$(($PLUS - $MINUS)) ; [ $N -eq 0 ]&& continue
	errTAG='' ; [ $N -gt 0 ]&& errTAG='/' ; N=`echo $N |sed 's/^-//'`
	echo "    ###   $errTAG$TAG = $N" >> /tmp/gtk-test.results
done
xmessage -title "  gtkDialog Test" "
    $FILE    

    ( Tag Type ) = ( Number Missing )    

`cat /tmp/gtk-test.results`
	" &
rm -f /tmp/gtk-test.results
### Revised gtkDialog tester... Does most of the tags.

### If you have more Tags to add, please post them below...
### Also any suggestions on how to make it check more... ( Tags out of place, Etc...)
.
Last edited by sunburnt on Thu 18 Mar 2010, 05:06, edited 16 times in total.

Post Reply