Make gtkDialog appear in a given screen location? [Solved]

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

Make gtkDialog appear in a given screen location? [Solved]

#1 Post by sunburnt »

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, 20:56, edited 1 time in total.

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

#2 Post by zigbert »

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: 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"

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#3 Post by BarryK »

The gtkdialog commandline also accepts '--geometry' option. I recently did '--geometry=540x0', which made the width 540 and the height the default.
[url]https://bkhome.org/news/[/url]

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

#4 Post by sunburnt »

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: 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!
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... ; )

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

#5 Post by 8-bit »

sunburnt,

See my post on position of a window Here.

It should help to explain how to position a window using the -geometry option.

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

#6 Post by 8-bit »

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.

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

#7 Post by sunburnt »

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

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

#8 Post by sunburnt »

I finally figured out that " -geometry 0x0+$X+$Y " goes like this:

Code: Select all

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.

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

#9 Post by 8-bit »

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.

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

#10 Post by sunburnt »

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: 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
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: Select all

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, 05:05, edited 3 times in total.

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#11 Post by seaside »

ON the example of window placement from "tips and tricks"

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"
To this -

Code: Select all

</frame>
    <hbox> 
 <button ok>
     <action>save_geometry</action>
 </button>
    </hbox>
  </vbox> 
</window>"
gtkdialog3 --program=DIALOG --geometry +"$X"+"$Y"
It works.

Apparently this line

Code: Select all

<action signal=\"hide\">save_geometry</action> 
just doesn't execute and don't ask me why. :D

Another dialog mystery in action (or no action in this case) :D

s

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

#12 Post by sunburnt »

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

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#13 Post by amigo »

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!

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#14 Post by BarryK »

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.
Last edited by BarryK on Sat 13 Mar 2010, 02:27, edited 1 time in total.
[url]https://bkhome.org/news/[/url]

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

#15 Post by technosaurus »

@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
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
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#16 Post by 8-bit »

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.

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

#17 Post by 8-bit »

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.
Is gposil's patched version going to be included in future Puppy versions and does it expand on Patriot's version?

Also, where is the gposil version?

And lastly, will the modified versions work with exsisting gtkdialog scripts?

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

#18 Post by sunburnt »

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... :lol: ).

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#19 Post by BarryK »

8-bit wrote:
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.
Is gposil's patched version going to be included in future Puppy versions and does it expand on Patriot's version?

Also, where is the gposil version?

And lastly, will the modified versions work with exsisting gtkdialog scripts?
Oh sorry, I meant Patriot's patch, not gposil.
[url]https://bkhome.org/news/[/url]

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

#20 Post by 8-bit »

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.

Post Reply