wxPython: panel not fully painted

Discussion in 'Python' started by citronelu@yahoo.com, Jan 24, 2007.

  1. Guest

    Hi,

    I'm new to wxpython, and the following code is my first serious
    attempt:


    #~ start code
    import wx

    class MyPanel(wx.Panel):
    def __init__(self, parent, id):
    wx.Panel.__init__(self, parent, id)
    self.parent = parent
    button = wx.Button(self, -1, "Refresh")
    button.SetPosition((100, 100))
    button.SetFocus()

    self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)

    def OnCloseMe(self, event):
    self.parent.f_redraw(self)
    pass


    class MyFrame(wx.Frame):
    def __init__(
    self, parent, ID, title, pos=wx.DefaultPosition,
    size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE
    ):

    wx.Frame.__init__(self, parent, ID, title, pos, size, style)

    def f_redraw(self, kill_window):
    kill_window.Destroy()
    MyPanel(self, -1)
    #~ self.SendSizeEvent()


    wxApp = wx.App()
    f = MyFrame(None, -1, "App Title")
    MyPanel(f, -1)
    f.Show()
    wxApp.MainLoop()


    #~ end code


    My problem is: when I press the "refresh" button, the new panel is
    painted only as a 20x20 pixels square on the top right side of the
    frame. If I resize the frame, the panel is repainted correctly (that's
    why I inserted the self.SendSizeEvent() line - commented above).

    Is there something I'm missing, or this is normal ?

    I'm using python 2.4.3 and wxpython 2.8.1.1 unicode, on WinXP SP2.
    Windows extensions are also installed.
    , Jan 24, 2007
    #1
    1. Advertising

  2. Chris Mellon Guest

    On 24 Jan 2007 13:35:51 -0800, <> wrote:
    > Hi,
    >
    > I'm new to wxpython, and the following code is my first serious
    > attempt:
    >
    >
    > #~ start code
    > import wx
    >
    > class MyPanel(wx.Panel):
    > def __init__(self, parent, id):
    > wx.Panel.__init__(self, parent, id)
    > self.parent = parent
    > button = wx.Button(self, -1, "Refresh")
    > button.SetPosition((100, 100))
    > button.SetFocus()
    >
    > self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
    >
    > def OnCloseMe(self, event):
    > self.parent.f_redraw(self)
    > pass
    >
    >
    > class MyFrame(wx.Frame):
    > def __init__(
    > self, parent, ID, title, pos=wx.DefaultPosition,
    > size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE
    > ):
    >
    > wx.Frame.__init__(self, parent, ID, title, pos, size, style)
    >
    > def f_redraw(self, kill_window):
    > kill_window.Destroy()
    > MyPanel(self, -1)
    > #~ self.SendSizeEvent()
    >
    >
    > wxApp = wx.App()
    > f = MyFrame(None, -1, "App Title")
    > MyPanel(f, -1)
    > f.Show()
    > wxApp.MainLoop()
    >
    >
    > #~ end code
    >
    >
    > My problem is: when I press the "refresh" button, the new panel is
    > painted only as a 20x20 pixels square on the top right side of the
    > frame. If I resize the frame, the panel is repainted correctly (that's
    > why I inserted the self.SendSizeEvent() line - commented above).
    >
    > Is there something I'm missing, or this is normal ?
    >
    > I'm using python 2.4.3 and wxpython 2.8.1.1 unicode, on WinXP SP2.
    > Windows extensions are also installed.
    >


    This is expected. Note that your "redraw" is no such thing - you are
    destroying the window and creating a new one.

    A feature of the wx.Frame class is that if it has one and only one
    child, that child is sized to fill the client area of the frame.
    However, this sizing happens in response to size events of the frame
    itself, so when you create the new panel, it is shown at its default
    size until you resize the frame (or emulate resizing the frame via
    SendSizeEvent).
    Chris Mellon, Jan 24, 2007
    #2
    1. Advertising

  3. Morpheus Guest

    On Wed, 24 Jan 2007 13:35:51 -0800, citronelu wrote:

    > Hi,
    >
    > I'm new to wxpython, and the following code is my first serious
    > attempt:
    >
    >
    > #~ start code
    > import wx
    >
    > class MyPanel(wx.Panel):
    > def __init__(self, parent, id):
    > wx.Panel.__init__(self, parent, id)
    > self.parent = parent
    > button = wx.Button(self, -1, "Refresh")
    > button.SetPosition((100, 100))
    > button.SetFocus()
    >
    > self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
    >
    > def OnCloseMe(self, event):
    > self.parent.f_redraw(self)
    > pass
    >
    >
    > class MyFrame(wx.Frame):
    > def __init__(
    > self, parent, ID, title, pos=wx.DefaultPosition,
    > size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE
    > ):
    >
    > wx.Frame.__init__(self, parent, ID, title, pos, size, style)
    >
    > def f_redraw(self, kill_window):
    > kill_window.Destroy()
    > MyPanel(self, -1)
    > #~ self.SendSizeEvent()
    >
    >
    > wxApp = wx.App()
    > f = MyFrame(None, -1, "App Title")
    > MyPanel(f, -1)
    > f.Show()
    > wxApp.MainLoop()
    >
    >
    > #~ end code
    >
    >
    > My problem is: when I press the "refresh" button, the new panel is
    > painted only as a 20x20 pixels square on the top right side of the
    > frame. If I resize the frame, the panel is repainted correctly (that's
    > why I inserted the self.SendSizeEvent() line - commented above).
    >
    > Is there something I'm missing, or this is normal ?
    >
    > I'm using python 2.4.3 and wxpython 2.8.1.1 unicode, on WinXP SP2.
    > Windows extensions are also installed.


    Consider using sizers, you'll need them anyway. They do such things for
    you, and many other things too.

    The help file has a good chapter on this: Working with sizers.

    Kind regards
    Morpheus
    Morpheus, Jan 25, 2007
    #3
  4. Guest

    Thank you.
    , Jan 28, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TL
    Replies:
    4
    Views:
    785
  2. JustSomeGuy

    I've painted myself into a corner!

    JustSomeGuy, Jun 22, 2004, in forum: C++
    Replies:
    4
    Views:
    350
    Dietmar Kuehl
    Jun 23, 2004
  3. venkat
    Replies:
    7
    Views:
    547
    Joshua Cranmer
    Mar 18, 2007
  4. =?Utf-8?B?QW5pbCBNb2Rlc3Q=?=

    Div Item not get Painted some times

    =?Utf-8?B?QW5pbCBNb2Rlc3Q=?=, Apr 12, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    269
    =?Utf-8?B?QW5pbCBNb2Rlc3Q=?=
    Apr 12, 2007
  5. Cameron Simpson
    Replies:
    0
    Views:
    99
    Cameron Simpson
    May 19, 2013
Loading...

Share This Page