Re: [wxPython-users] How to center a file dialog on its parent?

261 views
Skip to first unread message

Uwe C. Schroeder

unread,
Oct 28, 2006, 9:51:45 PM10/28/06
to wxPytho...@lists.wxwidgets.org, Bob Klahn

AFAIK it's

dlg.CentreOnParent()

(note the spelling)
I use it without parameters and it works.


UC

On Saturday 28 October 2006 13:03, Bob Klahn wrote:
> This should be simple ...
>
> How do I center a file dialog on its parent? No matter what I do,
> the dialog window almost always positions itself in the
> parent panel's upper left corner. Not too pretty.
>
> ---------------------------------------------------------------------------
>----------------------------------------------------------------------------
>---------------------
>
> dlg = wx.FileDialog(self, "Open something..."
> , defaultDir = "", defaultFile = ""
> , wildcard = '*', style =
> wx.OPEN|wx.MULTIPLE|wx.CHANGE_DIR
> # , pos = (400,400) # <====This doesn't
> seem to do anything
> )
>
> # dlg.CenterOnParent(wx.BOTH) # <=============This causes
> python.exe to BOMB
>
> if dlg.ShowModal() == wx.ID_OK:
> print "You selected", dlg.GetPaths()
>
> dlg.Destroy()
>
> ---------------------------------------------------------------------------
>----------------------------------------------------------------------------
>---------------------
>
> Neither of the above commented-out lines does the job. The first
> doesn't seem to do anything at all (so why does it
> exist?), no matter what x and y values I use, and the second causes
> python.exe to bomb:
>
> python.exe has encountered a problem and needs to close. We are
> sorry for the inconvenience.
>
>
> It's probably super-obvious that I'm relatively new to Python and to
> object-oriented programming, and that I'm very new to
> wxPython. Were I more experienced with these tools I think I'd at
> least understand why the second commented-out line
> is accepted by the interpreter but causes python.exe to die.
>
> Help please.
>
> Bob
>
> P.S. I'm still using wxPython 2.6.1.0.

--
UC

--
Open Source Solutions 4U, LLC 1618 Kelly St
Phone: +1 707 568 3056 Santa Rosa, CA 95401
Cell: +1 650 302 2405 United States
Fax: +1 707 568 6416

Robin Dunn

unread,
Oct 28, 2006, 9:59:28 PM10/28/06
to wxPytho...@lists.wxwidgets.org
Bob Klahn wrote:
> This should be simple ...
>
> How do I center a file dialog on its parent? No matter what I do, the
> dialog window almost always positions itself in the
> parent panel's upper left corner. Not too pretty.

On all three main platforms the file dialog is now not really a
wx.Dialog, but just a simple wrapper around a platform API function that
causes the native dialog to be shown. As such it doesn't really derive
from wx.Dialog and so it doesn't inherit all of its functionality and
properties, and you are stuck with however the platform decides that the
dialog should work.

> P.S. I'm still using wxPython 2.6.1.0.

BTW, I think that the crash you are seeing with CenterOnParent has been
fixed. It still won't center, but it should no longer crash.


--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!


Bob Klahn

unread,
Oct 28, 2006, 10:19:46 PM10/28/06
to wxPytho...@lists.wxwidgets.org
At 09:59 PM 10/28/2006, you wrote:
>Bob Klahn wrote:
>>This should be simple ...
>>How do I center a file dialog on its parent? No matter what I do,
>>the dialog window almost always positions itself in the
>>parent panel's upper left corner. Not too pretty.
>
>On all three main platforms the file dialog is now not really a
>wx.Dialog, but just a simple wrapper around a platform API function
>that causes the native dialog to be shown. As such it doesn't
>really derive from wx.Dialog and so it doesn't inherit all of its
>functionality and properties, and you are stuck with however the
>platform decides that the dialog should work.
>
>>P.S. I'm still using wxPython 2.6.1.0.
>
>BTW, I think that the crash you are seeing with CenterOnParent has
>been fixed. It still won't center, but it should no longer crash.

Thanks, Robin. Then since FileDialog's pos parameter no longer does
anything, shouldn't it now be removed? I think it's very misleading.

Bob


--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.0.408 / Virus Database: 268.13.17/505 - Release Date: 10/27/2006

Bob Klahn

unread,
Oct 28, 2006, 4:03:33 PM10/28/06
to wxPython users
This should be simple ...

How do I center a file dialog on its parent?  No matter what I do, the dialog window almost always positions itself in the
parent panel's upper left corner.  Not too pretty.

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


        dlg = wx.FileDialog(self, "Open something..."
                           , defaultDir = "", defaultFile = ""
                           , wildcard = '*', style = wx.OPEN|wx.MULTIPLE|wx.CHANGE_DIR
#                          , pos = (400,400)   # <====This doesn't seem to do anything
                           )

#       dlg.CenterOnParent(wx.BOTH)   # <=============This causes python.exe to BOMB

        if dlg.ShowModal() == wx.ID_OK:
            print "You selected", dlg.GetPaths()

        dlg.Destroy()

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

Neither of the above commented-out lines does the job.  The first doesn't seem to do anything at all (so why does it
exist?), no matter what x and y values I use, and the second causes python.exe to bomb:

    python.exe has encountered a problem and needs to close.  We are sorry for the inconvenience.


It's probably super-obvious that I'm relatively new to Python and to object-oriented programming, and that I'm very new to
wxPython.  Were I more experienced with these tools I think I'd at least understand why the second commented-out line
is accepted by the interpreter but causes python.exe to die.

Help please.

Bob

Robin Dunn

unread,
Oct 30, 2006, 10:05:41 PM10/30/06
to wxPytho...@lists.wxwidgets.org
Bob Klahn wrote:
> At 09:59 PM 10/28/2006, you wrote:
>> Bob Klahn wrote:
>>> This should be simple ...
>>> How do I center a file dialog on its parent? No matter what I do,
>>> the dialog window almost always positions itself in the
>>> parent panel's upper left corner. Not too pretty.
>>
>> On all three main platforms the file dialog is now not really a
>> wx.Dialog, but just a simple wrapper around a platform API function
>> that causes the native dialog to be shown. As such it doesn't really
>> derive from wx.Dialog and so it doesn't inherit all of its
>> functionality and properties, and you are stuck with however the
>> platform decides that the dialog should work.
>>
>>> P.S. I'm still using wxPython 2.6.1.0.
>>
>> BTW, I think that the crash you are seeing with CenterOnParent has
>> been fixed. It still won't center, but it should no longer crash.
>
> Thanks, Robin. Then since FileDialog's pos parameter no longer does
> anything, shouldn't it now be removed? I think it's very misleading.

Yes, that is one way of thinking about it. The other is that all window
classes should have a same or similar set of constructor parameters.
(Plus, on some platforms the file dialog really is derived from wxDialog
and then the pos and other parameters will have meaning.)

Reply all
Reply to author
Forward
0 new messages