[wxPython] wxStaticBoxSizer and OnPaint

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] wxStaticBoxSizer and OnPaint

Echeverria Rabi, Cristian  Rodrigo, TRANSELEC S.A.
Hi...

I am working with wxPython 2.1.11 on Win95

In the next code the wxListCtrl is not painted if you don´t resize the main
windows.
This problem happends only if I use wxStaticBoxSizer, if I use a wxBoxSizer
instead
the wxListCtrl is painted and repainted properly.

The solution to use wxStaticBoxSizer is to redefine OnPaint for my panel,
calling Refresh (see commented code).

Is this a bug or I forgot something???

Cristian Echeverria

#- <00>
-----------------------------------------------------------------------
# Archivo           : demo.py

from wxPython.wx import *

#- <00>
-----------------------------------------------------------------------

DT_HEADERS = ['Code','Name','Value']

class MainPanel(wxPanel):
    def __init__(self,parent):
        wxPanel.__init__(self,parent,-1)

        #box = wxBoxSizer(wxVERTICAL)
        box = wxStaticBoxSizer(wxStaticBox(self,-1,"Details"),wxVERTICAL)
       
        self.list = wxListCtrl(self,100,size=(300,200),
            style=wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER)
        for i in range(len(DT_HEADERS)):
            self.list.InsertColumn(i,DT_HEADERS[i])
        box.Add(self.list,1,wxEXPAND|wxALL,4)

        self.SetAutoLayout(true)
        self.SetSizer(box)
        box.Fit(self)
        box.SetSizeHints(self)

    #def OnPaint(self,event):
    #    dc = wxPaintDC(self)
    #    self.Refresh()
    #    event.Skip()

#- <00>
-----------------------------------------------------------------------

class MainFrame(wxFrame):
    def __init__(self, parent,title):
        wxFrame.__init__(self, parent,-1,title)
       
        self.CreateStatusBar()

        box = wxBoxSizer(wxVERTICAL)
        self.mp = MainPanel(self)
        box.Add(self.mp,1,wxEXPAND)

        self.SetAutoLayout(true)
        self.SetSizer(box)
        box.Fit(self)
        box.SetSizeHints(self)

        self.Center(wxBOTH)

    def OnCloseWindow(self,event):
        self.Destroy()

#- <00>
-----------------------------------------------------------------------

class MainApp(wxApp):
    def OnInit(self):
        frame = MainFrame(NULL,"Wx-Template")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

#- <00>
-----------------------------------------------------------------------

def main():
    app = MainApp(0)
    app.MainLoop()

#- <99>
-----------------------------------------------------------------------

if __name__ == '__main__':
    main()

_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] wxStaticBoxSizer and OnPaint

Robin Dunn
> I am working with wxPython 2.1.11 on Win95
>
> In the next code the wxListCtrl is not painted if you don´t resize the main
> windows.
> This problem happends only if I use wxStaticBoxSizer, if I use a wxBoxSizer
> instead
> the wxListCtrl is painted and repainted properly.

There is a known problem with wxStatixBoxes in that they sometimes paint
themselves in front of the other controls.  If you change it so the list is a
child of the static box then it should paint correctly.


        sb = wxStaticBox(self,-1,"Details")
        box = wxStaticBoxSizer(sb, wxVERTICAL)

        self.list = wxListCtrl(sb, 100,size=(300,200),
            style=wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER)


--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users