Make gtkDialog appear in a given screen location? [Solved]
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...
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, 20:56, edited 1 time in total.
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.
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: Select all
#! /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"
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.
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... ; )
I tried all these to get info on my app., it can`t find it.
Code: Select all
# 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!
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... ; )
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.
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.
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...
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...
I finally figured out that " -geometry 0x0+$X+$Y " goes like this:
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.
Code: Select all
gtkdialog2 -geometry 0x0+$X+$Y --program=DRIVEMAN
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.
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.
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.
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:
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...)
##### . 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.
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: Select all
######## 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
Odd, the "Relative" position only outputs the number 3 for X and Y. ( Don`t know why...)
Code: Select all
xwininfo -name "DM" |grep 'Absolute upper-left X' |sed 's/^.* //'
............ 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, 05:05, edited 3 times in total.
ON the example of window placement from "tips and tricks"
If you change this -
To this -
It works.
Apparently this line
just doesn't execute and don't ask me why.
Another dialog mystery in action (or no action in this case)
s
If you change this -
Code: Select all
</frame>
<hbox>
<button ok>
</button>
</hbox>
</vbox>
## <action signal=\"hide\">save_geometry</action>##
</window>"
gtkdialog3 --program=DIALOG --geometry +"$X"+"$Y"
Code: Select all
</frame>
<hbox>
<button ok>
<action>save_geometry</action>
</button>
</hbox>
</vbox>
</window>"
gtkdialog3 --program=DIALOG --geometry +"$X"+"$Y"
Apparently this line
Code: Select all
<action signal=\"hide\">save_geometry</action>
Another dialog mystery in action (or no action in this case)
s
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
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
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!
Post what you've got!
- BarryK
- Puppy Master
- Posts: 9392
- Joined: Mon 09 May 2005, 09:23
- Location: Perth, Western Australia
- Contact:
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.
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.
Last edited by BarryK on Sat 13 Mar 2010, 02:27, edited 1 time in total.
[url]https://bkhome.org/news/[/url]
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
@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
@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
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].
I found that it is not a good idea to use negative values for position with gtkdialog.
If you use "gtkdialog3 -p myprogram --geometry 0x0+200+400" for instance that says 200pixels from left edge of screen and 400 pixels from top of screen.
And it stays consistent when running program multiple times.
But, if you use "gtkdialog3 -p myprogram --geometry 0x0-400-400" and run the program multiple times the program window position will change.
Negative values are measured from the right edge and bottom edge of screen.
Don't believe my heresay, try it with a small gtkdialog script.
If you use "gtkdialog3 -p myprogram --geometry 0x0+200+400" for instance that says 200pixels from left edge of screen and 400 pixels from top of screen.
And it stays consistent when running program multiple times.
But, if you use "gtkdialog3 -p myprogram --geometry 0x0-400-400" and run the program multiple times the program window position will change.
Negative values are measured from the right edge and bottom edge of screen.
Don't believe my heresay, try it with a small gtkdialog script.
Is gposil's patched version going to be included in future Puppy versions and does it expand on Patriot's version?BarryK wrote: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.
Also, where is the gposil version?
And lastly, will the modified versions work with exsisting gtkdialog scripts?
8-bit; The movement may be what I found that is the desktop`s "cascade" windows effect.
I had to subtract a small amount from the X and Y positions before saving the GUI`s location.
See my code above in the "cancel() {" function.
technosaurus; Mine is a working script also, but I have a fairly complete GUI for it.
Unfortunately I forgot to mention that it`s gtkDialog2, but written years ago it`d have to be.
### Is your script for gtkDialog3 ? If it is then I`m guessing that our scripts are similar...
### I think I`ll start a thread for developing a GUI builder that makes gtkDialog3 GUIs.
### The problem is I can`t remember ever getting a gtkDialog3 script to work yet...
Barry; I figured as much, it`s the circle of life ( or cycle of code... ).
I had to subtract a small amount from the X and Y positions before saving the GUI`s location.
See my code above in the "cancel() {" function.
technosaurus; Mine is a working script also, but I have a fairly complete GUI for it.
Unfortunately I forgot to mention that it`s gtkDialog2, but written years ago it`d have to be.
### Is your script for gtkDialog3 ? If it is then I`m guessing that our scripts are similar...
### I think I`ll start a thread for developing a GUI builder that makes gtkDialog3 GUIs.
### The problem is I can`t remember ever getting a gtkDialog3 script to work yet...
Barry; I figured as much, it`s the circle of life ( or cycle of code... ).
- BarryK
- Puppy Master
- Posts: 9392
- Joined: Mon 09 May 2005, 09:23
- Location: Perth, Western Australia
- Contact:
Oh sorry, I meant Patriot's patch, not gposil.8-bit wrote:Is gposil's patched version going to be included in future Puppy versions and does it expand on Patriot's version?BarryK wrote: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.
Also, where is the gposil version?
And lastly, will the modified versions work with exsisting gtkdialog scripts?
[url]https://bkhome.org/news/[/url]
After playing with Zigbert's example script, and not having it work correctly, it dawned on me that the /tmp/geometry file was not being run upon rerunning the script.
I made 2 changes to it and now it works.
First, I moved the action line so that the ok button saved changes and added a cancel button for ease of exiting the program.
Those changes did not help in the script using the new parameters.
So after looking at "The benefits of a Configuration file" example,
I then added ". /tmp/geometry" right after the first line of the script.
This ran the /tmp/geometry file to pass the saved parameters to the script.
And in running it settings were retained and used on the next run of the script.
If you want to see my mods to his script in their entirety, I will post it as code.
I made 2 changes to it and now it works.
First, I moved the action line so that the ok button saved changes and added a cancel button for ease of exiting the program.
Those changes did not help in the script using the new parameters.
So after looking at "The benefits of a Configuration file" example,
I then added ". /tmp/geometry" right after the first line of the script.
This ran the /tmp/geometry file to pass the saved parameters to the script.
And in running it settings were retained and used on the next run of the script.
If you want to see my mods to his script in their entirety, I will post it as code.