Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Screen position of a transient window

42 views
Skip to first unread message

Rob

unread,
May 20, 2013, 5:46:52 AM5/20/13
to

In checking how an application I wrote originally for Linux works under
Windows XP, I found a significant difference in default positioning of a
transient window over a top-level one.

Under Linux, the centre of the transient window is automatically positioned
over the centre of the top-level window, while under XP the transient aligns
with its top-left corner at 0,0 screen position regardless of where the top-
level window is positioned.

Is this due to an deliberate Tk implementation decision on these different
operating systems or an effect of window manager handling behaviour? If I
need to do my own transient window centring routine it's not a problem, but
I want to be aware of where this default behaviour comes from. And also if
the centring effect can be relied on regardless of which Linux windows
manager/desktop environment I use.

BTW, the observed Linux behaviour occurs with both a Gnome-based desktop
environment and a KDE-based one.

TIA

Rob.

Robert Heller

unread,
May 20, 2013, 11:31:30 AM5/20/13
to
Are you doing *anything* with the geometry of the transient window?


>
> TIA
>
> Rob.
>

--
Robert Heller -- 978-544-6933 / hel...@deepsoft.com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments



Rob

unread,
May 21, 2013, 5:48:32 AM5/21/13
to
Robert Heller wrote:

> At Mon, 20 May 2013 19:46:52 +1000 Rob
> <dislexi...@nospamyahoo.com.invalid> wrote:
>
>>
>>
>> In checking how an application I wrote originally for Linux works under
>> Windows XP, I found a significant difference in default positioning of a
>> transient window over a top-level one.
>>
>> Under Linux, the centre of the transient window is automatically
>> positioned over the centre of the top-level window, while under XP the
>> transient aligns with its top-left corner at 0,0 screen position
>> regardless of where the top- level window is positioned.
>
> Are you doing *anything* with the geometry of the transient window?
>

Robert,

The only geometry-related things I do to the transient window are:

a) Related to resizing the label which holds a varying amount of textual
data.
b) Stopping the user manually resizing this window.

Just in case there's something else I'm not aware of, I'll post the relevant
code.

It's quite a bit of code (2 procs). In case it matters, the code for
invoking the transient window is done in the 'displayMediaInfo' proc. The
calling of this proc is set up in the top-level GUI definition as code in a
bind statement.

Rob.

-----------------------------------------------------------------------------

1) Code used to build the transient window:

proc defineInfoDlg {} {

global infoDlg
global mediaTable

toplevel .infoDlg
wm transient .infoDlg .
wm resizable .infoDlg 0 0

set infoDlg(id) ".infoDlg.f1.lbl1"
set infoDlg(comment) ".infoDlg.f1.lbl2"
set infoDlg(button) ".infoDlg.f2.btn"
set infoDlg(toplevel) ".infoDlg"

ttk::frame .infoDlg.f1 -padding 3
ttk::frame .infoDlg.f2 -padding 2

ttk::label $infoDlg(id) -padding 3 -anchor center \
-foreground "blue4"
# wraplength - determined by experiment
ttk::label $infoDlg(comment) \
-wraplength 350 -padding 8 \
-relief sunken \
-justify left -background "lightyellow2"

ttk::button $infoDlg(button) -padding 5 -text "OK" \
-default active -underline 0 \
-command {destroy $infoDlg(toplevel)}

pack .infoDlg.f1 -side top -fill both -expand true
pack .infoDlg.f2 -side top -fill x
pack $infoDlg(id) -side top -fill x
pack $infoDlg(comment) -side top -fill both -expand true
pack $infoDlg(button) -side top

bind $infoDlg(toplevel) <Key-Escape> {
$infoDlg(button) invoke
}

return
}

2) Invoking the transient window as child to top-level window:

proc displayMediaInfo {rownum} {

global mediaTable
global tblColNo
global infoDlg

set infoHeader [file tail [$mediaTable cellcget \
$rownum,$tblColNo(mediafile) -text]]

set comment [$mediaTable cellcget \
$rownum,$tblColNo(comment) -text]

if {$comment == ""} {
set comment "There is no additional\
information for this item\n"
}

defineInfoDlg

$infoDlg(id) configure -text "ID: $infoHeader"

set currWrapLen [$infoDlg(comment) cget -wraplength]

if {[string length $infoHeader] > 35} {
# Use of 'update' statement is required to allow the dynamic
# resizing of 'comment' label and thus the full infoDlg window

update
set currWrapLen [winfo width $infoDlg(comment)]
}

# Reasonable comment size vs. label wrap length - determined by
experiment
if {[string length $comment] > 800} {
set currWrapLen 550
}

$infoDlg(comment) configure -text $comment -wraplength $currWrapLen
wm title $infoDlg(toplevel) "Additional Information"

focus $infoDlg(button)

grab $infoDlg(toplevel)
tkwait window $infoDlg(toplevel)
grab release $infoDlg(toplevel)

selectTableRow $rownum
$mediaTable see $rownum
$mediaTable seecolumn 0

return
}

-----------------------------------------------------------------------------

Robert Heller

unread,
May 21, 2013, 8:48:15 AM5/21/13
to
At Tue, 21 May 2013 19:48:32 +1000 Rob <dislexi...@nospamyahoo.com.invalid> wrote:

>
> Robert Heller wrote:
>
> > At Mon, 20 May 2013 19:46:52 +1000 Rob
> > <dislexi...@nospamyahoo.com.invalid> wrote:
> >
> >>
> >>
> >> In checking how an application I wrote originally for Linux works under
> >> Windows XP, I found a significant difference in default positioning of a
> >> transient window over a top-level one.
> >>
> >> Under Linux, the centre of the transient window is automatically
> >> positioned over the centre of the top-level window, while under XP the
> >> transient aligns with its top-left corner at 0,0 screen position
> >> regardless of where the top- level window is positioned.
> >
> > Are you doing *anything* with the geometry of the transient window?
> >
>
> Robert,
>
> The only geometry-related things I do to the transient window are:
>
> a) Related to resizing the label which holds a varying amount of textual
> data.
> b) Stopping the user manually resizing this window.
>
> Just in case there's something else I'm not aware of, I'll post the relevant
> code.
>
> It's quite a bit of code (2 procs). In case it matters, the code for
> invoking the transient window is done in the 'displayMediaInfo' proc. The
> calling of this proc is set up in the top-level GUI definition as code in a
> bind statement.

OK, what you need to do is look at the 'wm geometry ...' command. You need to
fetch the root position of the parent and the sizes of the parent and child
(dialog/transient), and compute values for the geometry of the child
(dialog/transient). Here is the code from dialog.tcl (this code fragment is
pretty universal -- $w is the dialog toplevel, [winfo parent $w] is the parent
window the dialog is transient for -- adjust to suit your code):

# 6. Withdraw the window, then update all the geometry information
# so we know how big it wants to be, then center the window in the
# display and de-iconify it.

wm withdraw $w
update idletasks
set x [expr {[winfo screenwidth $w]/2 - [winfo reqwidth $w]/2 \
- [winfo vrootx [winfo parent $w]]}]
set y [expr {[winfo screenheight $w]/2 - [winfo reqheight $w]/2 \
- [winfo vrooty [winfo parent $w]]}]
# Make sure that the window is on the screen and set the maximum
# size of the window is the size of the screen. That'll let things
# fail fairly gracefully when very large messages are used. [Bug 827535]
if {$x < 0} {
set x 0
}
if {$y < 0} {
set y 0
}
wm maxsize $w [winfo screenwidth $w] [winfo screenheight $w]
wm geometry $w +$x+$y
wm deiconify $w

Rob

unread,
May 21, 2013, 9:29:30 AM5/21/13
to
Robert Heller wrote:

> At Tue, 21 May 2013 19:48:32 +1000 Rob
> <dislexi...@nospamyahoo.com.invalid> wrote:
>
>>
>> Robert Heller wrote:
>>
>> > At Mon, 20 May 2013 19:46:52 +1000 Rob
>> > <dislexi...@nospamyahoo.com.invalid> wrote:
>> >
>> >>
>> >>
>> >> In checking how an application I wrote originally for Linux works
>> >> under Windows XP, I found a significant difference in default
>> >> positioning of a transient window over a top-level one.
>> >>
>> >> Under Linux, the centre of the transient window is automatically
>> >> positioned over the centre of the top-level window, while under XP the
>> >> transient aligns with its top-left corner at 0,0 screen position
>> >> regardless of where the top- level window is positioned.
>> >
>> > Are you doing *anything* with the geometry of the transient window?
>> >
>> The only geometry-related things I do to the transient window are:
>>
>> a) Related to resizing the label which holds a varying amount of textual
>> data.
>> b) Stopping the user manually resizing this window.
::
::
>
> OK, what you need to do is look at the 'wm geometry ...' command. You
> need to fetch the root position of the parent and the sizes of the parent
> and child (dialog/transient), and compute values for the geometry of the
> child
> (dialog/transient). Here is the code from dialog.tcl (this code fragment
> is pretty universal -- $w is the dialog toplevel, [winfo parent $w] is the

Thank you for this code. I've seen something similar elsewhere, but your
example is more complete.

I was going to ask about tk common dialogue boxes, like tk_chooseDirectory
and tk_messageBox, and automatic centring, but I just noticed that there is
a -parent option which I'm not currently using. So much for carefully
reading documentation! <not so happy smile> Hopefully adding that option
will sort out those issues.

Thanks again,

Rob.

Robert Heller

unread,
May 21, 2013, 11:06:25 AM5/21/13
to
The code is typical piece of all of the Tk dialog code -- you probably saw it
somewhere in the Tk library in one or another of the various dialog box code
files. I just copied and pasted from the Tk library. It has been said "Use
the Source, Luke...".

>
> I was going to ask about tk common dialogue boxes, like tk_chooseDirectory
> and tk_messageBox, and automatic centring, but I just noticed that there is
> a -parent option which I'm not currently using. So much for carefully
> reading documentation! <not so happy smile> Hopefully adding that option
> will sort out those issues.

Yes, tk_chooseDirectory, tk_messageBox, and others use some variation of the
code I posted.

>
> Thanks again,
>
> Rob.
0 new messages