Basic frame-sizing problem

I'm a novice wxPython user as well as a near-novice Python user, and I'm having trouble with basic frame sizing. In the example below, I want to create a screen-centered frame that takes up 90% of the horizontal and vertical screen space. But my TestFrame size parameter is not taking.

···

__________________________________________________

import wx

class TestFrame(wx.Frame):
   def __init__(self, parent, id, title, size):
     wx.Frame.__init__(self, parent, id, title, size)

class App(wx.App):
   def OnInit(self):

     x = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X)
     y = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y)

     frame = TestFrame(None,-1,"Test Frame", size=(.9*x,.9*y))
     frame.Center(wx.BOTH)
     frame.Show(True)
     self.SetTopWindow(frame)
     return True

if __name__ == '__main__':
   app = App(0)
   app.MainLoop()
__________________________________________________

(1) What am I missing here?
(2) Is there a better way to accomplish my 90%-of-screen sizing goal?
(3) Is there anything else about my code above that is not up to wxPython coding "best practice" standards?

Bob

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

HTH, Q 2 and 3 i leave out.

<snip>
class TestFrame(wx.Frame):
    def __init__(self, parent, id, title):
  x = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X)
  y = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y)
  x -= (x / 10)
  y -= (y / 10)
  wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(x, y))
class App(wx.App):
    def OnInit(self):
  frame = TestFrame(None,-1,"Test Frame")
  frame.Center(wx.BOTH)
  frame.Show(True)
  self.SetTopWindow(frame)
  return True

if __name__ == '__main__':
    app = App(0)
    app.MainLoop()
</snip>

citation of <bobstones@comcast.net> from Sat, Oct 21, 2006 at 01:16:42PM -0400, Bob Klahn :

I'm a novice wxPython user as well as a near-novice Python user, and
I'm having trouble with basic frame sizing. In the example below, I
want to create a screen-centered frame that takes up 90% of the
horizontal and vertical screen space. But my TestFrame size
parameter is not taking.

__________________________________________________

import wx

class TestFrame(wx.Frame):
  def __init__(self, parent, id, title, size):
    wx.Frame.__init__(self, parent, id, title, size)

class App(wx.App):
  def OnInit(self):

    x = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X)
    y = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y)

    frame = TestFrame(None,-1,"Test Frame", size=(.9*x,.9*y))
    frame.Center(wx.BOTH)
    frame.Show(True)
    self.SetTopWindow(frame)
    return True

if __name__ == '__main__':
  app = App(0)
  app.MainLoop()
__________________________________________________

(1) What am I missing here?
(2) Is there a better way to accomplish my 90%-of-screen sizing goal?
(3) Is there anything else about my code above that is not up to
wxPython coding "best practice" standards?

Bob

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

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

AZ

···

--
    ** GSM : +420 736 171 802
    ** IRC : irc.kunstlabor.at #kunstlabor
    ** ICQ : 298387338
    ** GPG : public key at http://keyserver.net ID 0x01FD52C3

<snip>
class TestFrame(wx.Frame):

    def __init__(self, parent, id, title):
        x = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X)
        y = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y)
        x -= (x / 10)
        y -= (y / 10)
        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(x, y))
class App(wx.App):

    def OnInit(self):
        frame = TestFrame(None,-1,"Test Frame")
        frame.Center(wx.BOTH)
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

if __name__ == '__main__':

    app = App(0)
    app.MainLoop()
</snip>

I knew I should have added one more comment to my note. I knew I could accomplish the desired result by placing the size info directly into the wx.Frame.___init___ invocation.

What I don't understand, Alex and all, is why what I'm doing doesn't work. ???

Bob

···

At 06:28 PM 10/21/2006, Alex wrote:

>>> citation of <bobstones@comcast.net> from Sat, Oct 21, 2006 at 01:16:42PM -0400, Bob Klahn :
> I'm a novice wxPython user as well as a near-novice Python user, and
> I'm having trouble with basic frame sizing. In the example below, I
> want to create a screen-centered frame that takes up 90% of the
> horizontal and vertical screen space. But my TestFrame size
> parameter is not taking.
>
> __________________________________________________
>
> import wx
>
> class TestFrame(wx.Frame):
> def __init__(self, parent, id, title, size):
> wx.Frame.__init__(self, parent, id, title, size)
>
> class App(wx.App):
> def OnInit(self):
>
> x = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X)
> y = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y)
>
> frame = TestFrame(None,-1,"Test Frame", size=(.9*x,.9*y))
> frame.Center(wx.BOTH)
> frame.Show(True)
> self.SetTopWindow(frame)
> return True
>
> if __name__ == '__main__':
> app = App(0)
> app.MainLoop()
> __________________________________________________
>
> (1) What am I missing here?
> (2) Is there a better way to accomplish my 90%-of-screen sizing goal?
> (3) Is there anything else about my code above that is not up to
> wxPython coding "best practice" standards?
>
> Bob

AZ
--
    ** GSM : +420 736 171 802
    ** IRC : irc.kunstlabor.at #kunstlabor
    ** ICQ : 298387338
    ** GPG : public key at http://keyserver.net ID 0x01FD52C3

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

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

I knew I should have added one more comment to my note. I knew I could accomplish the desired result by placing the size info directly into the wx.Frame.___init___ invocation.

What I don't understand, Alex and all, is why what I'm doing doesn't work. ???

Ah, I see now. My supposed size parameter in my wx.Frame.__Init__ invocation was actually the position parameter. Presumably I would have noticed that had I not centered the frame before displaying it.

And my apologies, Ales, for calling you Alex. Seeing wx.DefaultPosition in your wx.Frame.__init__ invocation finally clued me in. Thank you.

Bob

···

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

citation of <bobstones@comcast.net> from Sat, Oct 21, 2006 at 07:00:57PM -0400, Bob Klahn :

Ah, I see now. My supposed size parameter in my wx.Frame.__Init__
invocation was actually the position parameter. Presumably I would
have noticed that had I not centered the frame before displaying it.

no, i think it works ok also if you center frame after showing it.

And my apologies, Ales, for calling you Alex. Seeing

n.p.

wx.DefaultPosition in your wx.Frame.__init__ invocation finally clued
me in. Thank you.

or wx.Point(x,y) instead wx.DefaultPosition ...

AZ

···

--
    ** GSM : +420 736 171 802
    ** IRC : irc.kunstlabor.at #kunstlabor
    ** ICQ : 298387338
    ** GPG : public key at http://keyserver.net ID 0x01FD52C3

Bob Klahn wrote:

Ah, I see now. My supposed size parameter in my wx.Frame.__Init__ invocation was actually the position parameter.

This is a great reason to use one of Python's fabulous features: keyword arguments and *args, **kwargs:

class TestFrame(wx.Frame):
   def __init__(self, *args, **kwargs):
     wx.Frame.__init__(self, *args, **kwargs)

class App(wx.App):
   def OnInit(self):

     x = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X)
     y = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y)

     frame = TestFrame(None, title="Test Frame", size=(.9*x,.9*y))
     frame.Center(wx.BOTH)
     frame.Show(True)
     self.SetTopWindow(frame)
     return True

if __name__ == '__main__':
   app = App(0)
   app.MainLoop()

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov