wxpython拖放dataobjectcomposite

时间:2014-06-23 17:07:35

标签: python drag-and-drop wxpython

我花了更多的时间而不是承认这一点,我真的很喜欢 帮助理解wxPython的内外拖放。

注意:是的我已经阅读了文档,不幸的是我很难跟踪和理解它们。是的,代码过于简单,无法进行共享和测试。

请和谢谢!

详细

- Python 2.7.6
- Wxpython 3.0.0.0 msw (classic)

我想实现以下

1. Have a view that calls dropSource.doDragDrop() that makes use of a wx.CompositeDataObject
2. Have a window you can drop in that reads wx.CompositeDataObject
3. The wx.CompositeDataObject components would contain generic DataObjects (no TextDataObject, etc... )

问题是

  1. 如何从CompositeDataObjects发送和检索数据?
  2. 当前代码

    Screen Shot http://i58.tinypic.com/2z3tglf.jpg

    import wx
    
    #Bare Bones App for Testing Only
    app = wx.App()
    someParentWindow = wx.Frame(None)
    someParentWindow.Show(True)
    
    #Drag Implementation
    def _drag(e):
            if e.Dragging():
                    dropSource = wx.DropSource( e.GetEventObject() )
                    textdf = wx.DataFormat( wx.DF_TEXT )
                    textdo = wx.DataObjectSimple()
                    textdo.SetData("asd")
                    data = wx.DataObjectComposite()
                    data.Add( textdo )
                    dropSource.SetData(data)
                    result = dropSource.DoDragDrop()
                    print result
    
    text = wx.StaticText( someParentWindow, label="Drag Me")
    text.Bind(wx.EVT_MOTION, _drag)
    
    #Drop Implementation
    class DropTarget(wx.PyDropTarget):
            def __init__(self, windowTarget):
                    super(DropTarget,self).__init__()
                    self.window = windowTarget
                    textdf = wx.DataFormat( wx.DF_TEXT )
                    self.textdo = wx.DataObjectSimple()
                    self.do = wx.DataObjectComposite()
                    self.do.Add( self.textdo )
                    self.SetDataObject( self.do )
    
            def OnData(self,x,y,d):
                    #Get the composite data
                    pass
    
    
    textctr = wx.TextCtrl( someParentWindow, pos=(3,20) )
    textctr.SetDropTarget( DropTarget( textctr ) )
    
    
    #MainLoop
    app.MainLoop()
    

0 个答案:

没有答案