Ugly artefacts with newly created windows

“Doctor!. Doctor! It hurts when I do this!”

Many problems are needlessly created when a wx program doesn’t use
classes for, at the very least, the app frame or app window. If pnl2 is
that special or gives you problems, then a class should be written for
it. Creating a class gives you the means to experiment and find out how
to get the widget to work properly.

“One liner” frame
and window creation just won’t do.

All the proposed solutions shown so far use classes.

However, I avoided using class definitions and forced using one-liner
widget creations in the attached program. I had to rewrite the given
program using classes, get the app to work properly and then insert
into the given program the working lines of code. Doing this was
painful, needless, and a very bad technique. It was like hitting my
head with a hammer for a while, stopping and then thinking, ‘Gee, I
feel so much better now that I stopped !’

Ray Pasco

artefact_test.PY (873 Bytes)

This might explain the class hierarchies in some of projects I've seen in the past :smiley:

-Matthias

···

Am 20.06.2010, 20:02 Uhr, schrieb Ray Pasco <pascor@verizon.net>:

"Doctor!. Doctor! It hurts when I do this!"

Many problems are needlessly created when a wx program doesn't use classes for,
at the very least, the app frame or app window. If pnl2 is that special or gives
you problems, then a class should be written for it.

Hi,

You are right in saying the code looks ugly. It is.
It seems you missunderstand the discussed issue.
My solution is not a panacea, it - sometimes - helps
a lot. Unfortunately a better class hierarchy does not
help.

# Win7, Py265, wxPy2811-ansi

class MainPanel(wx.Panel):

    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
        self.parent = parent

        # >>>>> comment/uncomment this line <<<<<
        self.SetSize(self.parent.GetClientSize())

        print 'MainPanel.__init__ :', self.GetSize(),
self.parent.GetClientSize()

class MainFrame(wx.Frame):

    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, 'test',
wx.DefaultPosition, \
                wx.DefaultSize, wx.DEFAULT_FRAME_STYLE)

        panel = MainPanel(self, wx.ID_ANY)
        print 'MainFrame.__init__ :', panel.GetSize(),
self.GetClientSize()

        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

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

class MainApp(wx.App):

    def OnInit(self):
        frame = MainFrame(None, wx.ID_ANY)
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

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

if __name__ == "__main__":
    main()

Outputs:

MainPanel.__init__ : (20, 20) (382, 205)
MainFrame.__init__ : (20, 20) (382, 205)

MainPanel.__init__ : (382, 205) (382, 205)
MainFrame.__init__ : (382, 205) (382, 205)

jmf

···

On 20 juin, 20:02, Ray Pasco <pas...@verizon.net> wrote:

"Doctor!. Doctor! It hurts when I do this!"