wxPython DnD stops working after SetSizeHints

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Emiliano Molina

    wxPython DnD stops working after SetSizeHints

    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(wxFra me):
    def __init__(self,p arent,ID):
    wxFrame.__init_ _(self,parent,I D,"test
    frame",(100,30) ,(70,60),wxDEFA ULT_FRAME_STYLE )
    self.panel=wxPa nel(self,-1)

    class FileDropTarget( wxFileDropTarge t):
    def __init__(self, window):
    wxFileDropTarge t.__init__(self )

    def OnDropFiles(sel f, x, y, filenames):
    print filenames

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

    self.res=wxXmlR esource("test.x rc")
    self.frame=self .res.LoadFrame( None,"FRAME1")
    self.frame.pane l=XRCCTRL(self. frame,"test_lis t")

    dt=FileDropTarg et(self.frame)
    self.frame.pane l.SetDropTarget (dt)

    # The following lines break the drag and drop
    # self.panel=XRCC TRL(self.frame, "panel")
    # sizer=self.pane l.GetSizer()
    # sizer.SetSizeHi nts(self.frame)

    self.frame.Show ()
    self.SetTopWind ow(self.frame)

    return True


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


    if __name__=="__ma in__":
    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="wxBoxSiz er">
    <orient>wxVERTI CAL</orient>
    <object class="sizerite m">
    <object class="wxStatic BoxSizer">
    <label>test_lis t</label>
    <orient>wxVERTI CAL</orient>
    <object class="sizerite m">
    <object class="wxListBo x" name="test_list ">
    <content/>
    </object>
    </object>
    </object>
    </object>
    </object>
    </object>
    <size>100,100 </size>
    </object>
    </resource>
  • Brett Calcott

    #2
    Re: wxPython DnD stops working after SetSizeHints



    "Emiliano Molina" wrote
    [color=blue]
    > <snip>
    > from wxPython.wx import *
    > from wxPython.xrc import *
    >
    > class TestFrame(wxFra me):
    > def __init__(self,p arent,ID):
    > wxFrame.__init_ _(self,parent,I D,"test[/color]
    frame",(100,30) ,(70,60),wxDEFA ULT_FRAME_STYLE )[color=blue]
    > self.panel=wxPa nel(self,-1)[/color]
    This gets overwritten -^
    [color=blue]
    >
    > class FileDropTarget( wxFileDropTarge t):
    > def __init__(self, window):[/color]
    unused --------------------^
    [color=blue]
    > wxFileDropTarge t.__init__(self )
    >
    > def OnDropFiles(sel f, x, y, filenames):
    > print filenames
    >
    > class App(wxApp):
    > def OnInit(self):
    >
    > self.res=wxXmlR esource("test.x rc")
    > self.frame=self .res.LoadFrame( None,"FRAME1")
    > self.frame.pane l=XRCCTRL(self. frame,"test_lis t")
    >
    > dt=FileDropTarg et(self.frame)
    > self.frame.pane l.SetDropTarget (dt)
    >
    > # The following lines break the drag and drop
    > # self.panel=XRCC TRL(self.frame, "panel")
    > # sizer=self.pane l.GetSizer()
    > # sizer.SetSizeHi nts(self.frame)[/color]

    What is self.panel, as opposed to self.frame.pane l?
    [color=blue]
    >
    > self.frame.Show ()
    > self.SetTopWind ow(self.frame)
    >
    > return True
    >[/color]


    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.pan el) 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=wxXmlR esource("test.x rc")
    self.frame=self .res.LoadFrame( None,"FRAME1")
    self.frame.pane l=XRCCTRL(self. frame,"panel")

    dt=FileDropTarg et()
    self.frame.pane l.SetDropTarget (dt)

    # The following lines break the drag and drop
    sizer=self.fram e.panel.GetSize r()
    sizer.SetSizeHi nts(self.frame)

    self.frame.Show ()
    self.SetTopWind ow(self.frame)

    return True




    Comment

    • Emiliano Molina

      #3
      Re: wxPython DnD stops working after SetSizeHints

      >> self.panel=wxPa nel(self,-1)[color=blue]
      >
      > This gets overwritten -^
      >[/color]
      [color=blue][color=green]
      >> def __init__(self, window):[/color]
      >
      > unused --------------------^[/color]

      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.
      [color=blue][color=green]
      >># The following lines break the drag and drop
      >># self.panel=XRCC TRL(self.frame, "panel")
      >># sizer=self.pane l.GetSizer()
      >># sizer.SetSizeHi nts(self.frame)[/color]
      >
      >
      > What is self.panel, as opposed to self.frame.pane l?[/color]

      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!
      [color=blue]
      > 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.pan el) which is the drop target (just a
      > guess)[/color]

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

      self.frame.pane l 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.
      [color=blue]
      > I've never used xrc, but this works for me (is it what you want?)
      >
      > some helpful code
      >
      > return True[/color]

      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.

      Comment

      Working...