wxPython DnD stops working after SetSizeHints

Discussion in 'Python' started by Emiliano Molina, Jun 7, 2004.

  1. This has been driving me crazy for a couple of days and I have finally
    narrowed it down to the following code. If the commented section is
    uncommented the drag and drop handler is never called. I have included
    the .xrc file for reference.

    Any help is greatly appreciated. An explanation would be great, but at
    the moment I would be eternally grateful for a workaround!

    Thanks in advance for those of you that spend some time helping out.

    Here is the blasted code,

    from wxPython.wx import *
    from wxPython.xrc import *

    class TestFrame(wxFrame):
    def __init__(self,parent,ID):
    wxFrame.__init__(self,parent,ID,"test
    frame",(100,30),(70,60),wxDEFAULT_FRAME_STYLE)
    self.panel=wxPanel(self,-1)

    class FileDropTarget(wxFileDropTarget):
    def __init__(self, window):
    wxFileDropTarget.__init__(self)

    def OnDropFiles(self, x, y, filenames):
    print filenames

    class App(wxApp):
    def OnInit(self):

    self.res=wxXmlResource("test.xrc")
    self.frame=self.res.LoadFrame(None,"FRAME1")
    self.frame.panel=XRCCTRL(self.frame,"test_list")

    dt=FileDropTarget(self.frame)
    self.frame.panel.SetDropTarget(dt)

    # The following lines break the drag and drop
    # self.panel=XRCCTRL(self.frame,"panel")
    # sizer=self.panel.GetSizer()
    # sizer.SetSizeHints(self.frame)

    self.frame.Show()
    self.SetTopWindow(self.frame)

    return True


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


    if __name__=="__main__":
    main()


    and here the XRC

    <?xml version="1.0" ?>
    <resource>
    <object class="wxFrame" name="FRAME1">
    <title></title>
    <object class="wxPanel" name="panel">
    <size>100,100</size>
    <object class="wxBoxSizer">
    <orient>wxVERTICAL</orient>
    <object class="sizeritem">
    <object class="wxStaticBoxSizer">
    <label>test_list</label>
    <orient>wxVERTICAL</orient>
    <object class="sizeritem">
    <object class="wxListBox" name="test_list">
    <content/>
    </object>
    </object>
    </object>
    </object>
    </object>
    </object>
    <size>100,100</size>
    </object>
    </resource>
     
    Emiliano Molina, Jun 7, 2004
    #1
    1. Advertising

  2. "Emiliano Molina" wrote

    > <snip>
    > from wxPython.wx import *
    > from wxPython.xrc import *
    >
    > class TestFrame(wxFrame):
    > def __init__(self,parent,ID):
    > wxFrame.__init__(self,parent,ID,"test

    frame",(100,30),(70,60),wxDEFAULT_FRAME_STYLE)
    > self.panel=wxPanel(self,-1)

    This gets overwritten -^

    >
    > class FileDropTarget(wxFileDropTarget):
    > def __init__(self, window):

    unused --------------------^

    > wxFileDropTarget.__init__(self)
    >
    > def OnDropFiles(self, x, y, filenames):
    > print filenames
    >
    > class App(wxApp):
    > def OnInit(self):
    >
    > self.res=wxXmlResource("test.xrc")
    > self.frame=self.res.LoadFrame(None,"FRAME1")
    > self.frame.panel=XRCCTRL(self.frame,"test_list")
    >
    > dt=FileDropTarget(self.frame)
    > self.frame.panel.SetDropTarget(dt)
    >
    > # The following lines break the drag and drop
    > # self.panel=XRCCTRL(self.frame,"panel")
    > # sizer=self.panel.GetSizer()
    > # sizer.SetSizeHints(self.frame)


    What is self.panel, as opposed to self.frame.panel?

    >
    > self.frame.Show()
    > self.SetTopWindow(self.frame)
    >
    > return True
    >



    Hi Emiliano, it isn't clear what you are trying to do here, you seem to
    have a panel being created in 3 different places -- which one do you
    want? I suspect that the self.panel, is hiding the other panel
    that you created (self.frame.panel) which is the drop target (just a
    guess)

    I've never used xrc, but this works for me (is it what you want?)

    class App(wxApp):
    def OnInit(self):

    self.res=wxXmlResource("test.xrc")
    self.frame=self.res.LoadFrame(None,"FRAME1")
    self.frame.panel=XRCCTRL(self.frame,"panel")

    dt=FileDropTarget()
    self.frame.panel.SetDropTarget(dt)

    # The following lines break the drag and drop
    sizer=self.frame.panel.GetSizer()
    sizer.SetSizeHints(self.frame)

    self.frame.Show()
    self.SetTopWindow(self.frame)

    return True
     
    Brett Calcott, Jun 8, 2004
    #2
    1. Advertising

  3. >> self.panel=wxPanel(self,-1)
    >
    > This gets overwritten -^
    >


    >> def __init__(self, window):

    >
    > unused --------------------^


    Yes, you are 100% right, its there because I have been cutting
    down the original program bit by bit to find the problem! It
    should no longer be there.

    >># The following lines break the drag and drop
    >># self.panel=XRCCTRL(self.frame,"panel")
    >># sizer=self.panel.GetSizer()
    >># sizer.SetSizeHints(self.frame)

    >
    >
    > What is self.panel, as opposed to self.frame.panel?


    self.panel is where I am temporarily storing the window that
    I am adding the DnD to. One of the steps that I took when
    trying to work out where the problem was was to start with
    nothing but a frame and a panel and see if I could drop files
    into the panel. That worked fine, it was only when I added a
    sizer and then had to fit and set hints that DnD broke.

    I'm sorryt that the naming is a bit confusing, I posted this
    last night as a last desperate attempt before going to bed!

    > Hi Emiliano, it isn't clear what you are trying to do here, you seem to
    > have a panel being created in 3 different places -- which one do you
    > want? I suspect that the self.panel, is hiding the other panel
    > that you created (self.frame.panel) which is the drop target (just a
    > guess)


    The confusion is understandable, I should have spent more time
    tidying up the code before posting.

    self.frame.panel is used to store the retrieved control to which
    the DnD handler is attached. Its called panel because originally
    it WAS a panel, its now a wxListBox.

    self.panel is used to store the retrieved panel (this one IS a panel,
    sorry for the confusion) from which we can then obtain the main sizer
    for the frame. If we don't have the sizer we can't call SetSizeHints
    to arrange the controls in the window. Its the calling of SetSizeHints
    that seems to break the DnD handling. If I don't call SetSizeHints
    then DnD works fine and I can drop a file onto the list in the frame
    and its name is printed. The frame looks terrible of course, the
    controls are only arranged properly when I call SetSizeHints.

    > I've never used xrc, but this works for me (is it what you want?)
    >
    > some helpful code
    >
    > return True


    I tried the code you sent on the iBook and no luck, but you mentioned
    that it worked so I sent it over to the PC and tried it again. It worked!

    I had a close look at it and you have changed the drop target from the
    list to the main panel. I did the same with my code on the PC and it
    also worked. So the conclusion is that neither your or my code works on
    the Mac. Both sets of code work on the PC as long as the drop target is
    the panel and not the list.

    Thanks for your help and time. Now I have to figure out what is
    happening on the Mac.
     
    Emiliano Molina, Jun 8, 2004
    #3
    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. Mike Bridge

    Postback stops working after a while?

    Mike Bridge, Jul 9, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    372
    Mike Bridge
    Jul 9, 2003
  2. feng
    Replies:
    1
    Views:
    284
  3. Replies:
    3
    Views:
    457
    Max Erickson
    Nov 10, 2005
  4. Chad
    Replies:
    1
    Views:
    144
    Kevin
    Jan 21, 2004
  5. Matthew Ferri
    Replies:
    0
    Views:
    102
    Matthew Ferri
    Feb 27, 2004
Loading...

Share This Page