| Author |
Message |
sunburnt

Joined: 08 Jun 2005 Posts: 4014 Location: Arizona, U.S.A.
|
Posted: Thu 11 Mar 2010, 02:31 Post subject:
Make gtkDialog appear in a given screen location? [Solved] |
|
I have code to get the screen resolution, but none to place a GUI in a give spot.
Having a GUI place itself would be really nice, even Geany remembers where you put it.
Zigbert may have something for this in his " GtkDialog - tips " thread, but I didn`t see it...
Last edited by sunburnt on Sun 04 Apr 2010, 16:56; edited 1 time in total
|
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 5290 Location: Valåmoen, Norway
|
Posted: Thu 11 Mar 2010, 03:58 Post subject:
|
|
This is what says in the 'tips and tricks'
How to store window size/placement
>> This example shows how we can save settings for window size and placement for next startup. Be also aware that this solution makes it possible to let user rescale gui smaller than the default size. Normally you define the size of ie. a <tree>, and the user can only resize the gui larger, but when using <window default_height="$HEIGHT" default_width="$WIDTH">, you don't need to define <height> and <width> for the tree widget.
| Code: | #! /bin/bash
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 ok>
</button>
</hbox>
</vbox>
<action signal=\"hide\">save_geometry</action>
</window>"
gtkdialog3 --program=DIALOG --geometry +"$X"+"$Y" |
_________________ Stardust resources
|
|
Back to top
|
|
 |
BarryK
Puppy Master

Joined: 09 May 2005 Posts: 6874 Location: Perth, Western Australia
|
Posted: Thu 11 Mar 2010, 04:29 Post subject:
|
|
The gtkdialog commandline also accepts '--geometry' option. I recently did '--geometry=540x0', which made the width 540 and the height the default.
_________________ http://bkhome.org/blog2/
|
|
Back to top
|
|
 |
sunburnt

Joined: 08 Jun 2005 Posts: 4014 Location: Arizona, U.S.A.
|
Posted: Thu 11 Mar 2010, 12:17 Post subject:
|
|
Thanks zigbert; I forgot to mention that it`s gtkdalog2, I can`t get gtkdialog3 to work..!
I tried all these to get info on my app., it can`t find it.
| Code: | # xwininfo -name "--program=DRIVEMAN"
xwininfo: error: No window with name --program=DRIVEMAN exists!
# xwininfo -name "gtkdialog2 --program=DRIVEMAN"
xwininfo: error: No window with name gtkdialog2 --program=DRIVEMAN exists!
# xwininfo -stats -name "gtkdialog2 --program=DRIVEMAN"
xwininfo: error: No window with name gtkdialog2 --program=DRIVEMAN exists! |
Also it gives incorrect info about GUIs, it give bad info on Geany, but good info for rxvt.
Barry; I need GUI screen placement ( X & Y) not ( width & height ).
I`ll look at your suggestion, I`m not sure how to write the code for it though.
And we all know how well documented gtkDialog is... ; )
|
|
Back to top
|
|
 |
8-bit

Joined: 03 Apr 2007 Posts: 3033 Location: Oregon
|
Posted: Thu 11 Mar 2010, 12:40 Post subject:
Subject description: Window position |
|
sunburnt,
See my post on position of a window Here.
It should help to explain how to position a window using the -geometry option.
|
|
Back to top
|
|
 |
8-bit

Joined: 03 Apr 2007 Posts: 3033 Location: Oregon
|
Posted: Thu 11 Mar 2010, 13:54 Post subject:
Subject description: xwininfo help |
|
To use xwininfo, Start your program and then open a terminal while your program windows are displayed.
In the terminal window, type "xwininfo -name [name that appears at top of xwindow you want to check].
Do not use "program="
I just tried it and it works.
For example, if the Title of your window is "DRIVEMAN" you would type "xwininfo -name DRIVEMAN" in the terminal window.
|
|
Back to top
|
|
 |
sunburnt

Joined: 08 Jun 2005 Posts: 4014 Location: Arizona, U.S.A.
|
Posted: Thu 11 Mar 2010, 16:03 Post subject:
|
|
Thanks 8-bit; The "use the name in the window`s tile bar" worked.
My app`s. title bar has " DM " in it as the GUI is so small.
I assumed that it used the info from " ps ".
Apps. like Geany are a problem because the title changes with the file that`s loaded into it.
And I see no way to find out what file is loaded into Geany...
|
|
Back to top
|
|
 |
sunburnt

Joined: 08 Jun 2005 Posts: 4014 Location: Arizona, U.S.A.
|
Posted: Thu 11 Mar 2010, 17:42 Post subject:
|
|
I finally figured out that " -geometry 0x0+$X+$Y " goes like this:
| Code: | | gtkdialog2 -geometry 0x0+$X+$Y --program=DRIVEMAN |
I was trying to run it as a script command line argument. ( DUH... )
8-bit; You should include this example scrap of code in your thread`s first post.
zigbert; I don`t know if you have a full example of this code in your GTK thread.
I could post an example there if you like and there`s no example already posted.
FULL code scraps of the gtkDialog code and the Button exit code to get the X Y position.
|
|
Back to top
|
|
 |
8-bit

Joined: 03 Apr 2007 Posts: 3033 Location: Oregon
|
Posted: Thu 11 Mar 2010, 23:46 Post subject:
|
|
zigbert,
Your window size and position example fails for me.
No /tmp/geometry file is written.
Also, after playing a little with it, I got it to write that file, but on the next run of the program example, nothing had changed as to window size and position.
This is after resizing and moving the window.
|
|
Back to top
|
|
 |
sunburnt

Joined: 08 Jun 2005 Posts: 4014 Location: Arizona, U.S.A.
|
Posted: Fri 12 Mar 2010, 01:19 Post subject:
|
|
I see what`s going on in zigberts example though I haven`t tried it out.
Without all gtkDialog`s info about the " <action signal= " and other "tags", it`s hell using it.
Fortunately gtkDialog2 is fine for such a simple GUI as this.
Here`s the gtkDialog2 code I came up with that works:
| Code: | ######## shell script file "/root/my-applications/bin/code"
#! /bin/sh
appPATH=/root/my-applications/bin # set app. path
posINFO=$appPATH/posinfo # set pos. file
if [ ! -e $posINFO ];then echo -e 'posX=60'\\n'posY=80' > $posINFO ;fi
if [ -z "$1" ];then gui $appPATH & # run file gui
exit ;fi
### Cancel button runs function that writes gui`s pos. to the file "posinfo"
cancel() {
posX=`xwininfo -name "DM" |grep 'Absolute upper-left X' |sed 's/^.* //'`
echo 'posX='`expr $posX - 3` > $posINFO
posY=`xwininfo -name "DM" |grep 'Absolute upper-left Y' |sed 's/^.* //'`
echo 'posY='`expr $posY - 22` >> $posINFO
psID=`ps |grep 'program=GUI' |egrep -v '(grep|geany)' |awk '{print $1}'`
if [ -n "$psID" ];then kill $psID ;fi # closes gui
}
$1 $2 $3
######## gtkDialog2 script file "/root/my-applications/bin/gui"
#! /bin/sh
appPATH=$1
. $appPATH/posinfo # get X and Y screen position
export GUI="
<wtitle>DM</wtitle>
<vbox>
<text><label>This is a demonstration of placing a GUI on screen.</label></text>
<button><label>Cancel</label><action>$appPATH/code cancel</action></button>
</vbox>
"
gtkdialog2 -geometry +${posX}+${posY} --program=GUI |
Run the top file "code" and it runs the file "gui".
Odd, the "Relative" position only outputs the number 3 for X and Y. ( Don`t know why...)
| Code: | | xwininfo -name "DM" |grep 'Absolute upper-left X' |sed 's/^.* //' |
##### . ERROR fix for code above: I " compressed " the code in my usual fashion.
............ The run in the background character " & " doesn`t like anything after it...
............ I also added a text box so you can grab the title bar and position the GUI to test it.
Last edited by sunburnt on Sun 14 Mar 2010, 01:05; edited 3 times in total
|
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 841
|
Posted: Fri 12 Mar 2010, 12:08 Post subject:
|
|
ON the example of window placement from "tips and tricks"
If you change this -
| Code: | </frame>
<hbox>
<button ok>
</button>
</hbox>
</vbox>
## <action signal=\"hide\">save_geometry</action>##
</window>"
gtkdialog3 --program=DIALOG --geometry +"$X"+"$Y" |
To this -
| Code: | </frame>
<hbox>
<button ok>
<action>save_geometry</action>
</button>
</hbox>
</vbox>
</window>"
gtkdialog3 --program=DIALOG --geometry +"$X"+"$Y" |
It works.
Apparently this line | Code: | | <action signal=\"hide\">save_geometry</action> |
just doesn't execute and don't ask me why.
Another dialog mystery in action (or no action in this case)
s
|
|
Back to top
|
|
 |
sunburnt

Joined: 08 Jun 2005 Posts: 4014 Location: Arizona, U.S.A.
|
Posted: Fri 12 Mar 2010, 15:42 Post subject:
|
|
To: seaside, 8-bit, zigbert and all others who "try" to use gtkDialog... : (
Years ago I make script libraries for handling: files, file systems, lists, and gtkDialog.
Zigbert`s forum thread on gtkDialog-Tips has me thinking that it all needs to be "collected".
My gtkDialog library made writing GUIs very simple, and it gathered the code in one place.
Instead of the XML style syntax of gtkDialog it`s a simple script syntax, a new GUI language.
A nice feature of it is that it can combine separate GUI files into one TabPanel GUI file.
Simply... GUI script code calls library file functions that write gtkDialog code to a file.
The library I made produces complete ready to run gtkDialog script files.
If there`s any interest in this idea, post here and I`ll start a new thread for it... Terry
|
|
Back to top
|
|
 |
amigo
Joined: 02 Apr 2007 Posts: 1776
|
Posted: Fri 12 Mar 2010, 17:32 Post subject:
|
|
Oh, definitely! I've done some similar work creating 'widgets' for xdialog and some that would let you use dialog or xdialog using the same code. It would be niice to have some universal functions which could be translated into dialg/xdialog/gtkdialog/xmessage/gmessage as the need/desire/availability dictated.
Post what you've got!
|
|
Back to top
|
|
 |
BarryK
Puppy Master

Joined: 09 May 2005 Posts: 6874 Location: Perth, Western Australia
|
Posted: Fri 12 Mar 2010, 18:23 Post subject:
|
|
sunburnt,
The intention is to phase-out gtkdialog2 sometime. I might have one or two scripts that still use gtkdialog2.
I recall that --geometry was buggy in earlier versions of gtkdialog, don't recall specifically about our gtkdialog2 though.
gtkdialog3 should work. It really is the best to use, the very latest from source patched by gposil.
CORRECTION: That was Patriot who patched gtkdialog3.
_________________ http://bkhome.org/blog2/
Last edited by BarryK on Fri 12 Mar 2010, 22:27; edited 1 time in total
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3845
|
Posted: Fri 12 Mar 2010, 18:50 Post subject:
|
|
@Barry - I did a search over /usr and no current scripts contained gtkdialog2 last time I checked (in 4.4) ... it can probably go already.
@sunburnt - I wish you would have posted your gui - gui before I wrote my bbgui template. Still would love to see it. (bbgui is just a script that builds your gui using only a set of numbered variables and uses that info to run a command line tool)
p.s. I also had issues with gtkdialog3 positioning as it is documented once before - heightxwidth was fine but positioning was odd - turns out + and - are not interchangeable as they are in jwm so to position in the bottom right I had to grep & cut xorg.conf to get the screen resolution and subtract height and width
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
|