hi,
i found an example in wxpython-2.8-cookbook that registers an DataObjectComposite (isa DataObject)
to an PyDropTarget with .SetDataObject()
but i got the error :
Traceback (most recent call last):
File “tuf.py”, line 50, in
F().Show()
File “tuf.py”, line 32, in init
o.t = FT(o.OnFileDrop,o.OnTextDrop)
File “tuf.py”, line 14, in init
o.SetDataObject( o._data )
File “/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/_misc.py”, line 5363, in SetDataObject
return misc.DropTarget_SetDataObject(*args, **kwargs)
TypeError: in method ‘DropTarget_SetDataObject’, expected argument 1 of type ‘wxPyDropTarget *’
the example in attachment ( tuf.py ).
another situation:
t1,t2 : textctrl ( t1 source , t2 target )
t2.SetDropTarget(wx.TextDropTarget())
before this was :
target = wx.TextDropTarget(t2)
t2.SetDropTarget( target )
t1.bind( wx.EVT_RIGHT_DOWN, on_rightdown )
on_rightdown(o,e):
tds = wx.DropSource( o.t1 )
tds.SetData( wx.PyTextDataObject(o.t1.GetStringSelection()) )
tds.DoDragDrop( True )
this works as expected.
i do not want to think too much about things that may happen internally, but i guess
DataSource (of type DF_TEXT) -> TextDataObject (implicit created in TextDropTarget?) -> textctrl.AppendText( GetData())
but i found an example using class T inherits from wx.TextDropTarget()
no target-window at constructor is given to base-class, instead it is registered as self.obj
and in eventhandler OnDropText(x,y,data) the data are written to self.obj with WriteText()
class T(wx.TextDropTarget):
def init(o,obj):
super(T,o).init()
o.target = obj
tuf.py (1016 Bytes)
text.py (4.68 KB)
···
def OnDropText(o,x,y,data):
o.target.WriteText( data + ‘\n’ )
now the dragged text is pasted twice ?!
i guess, if window.SetDropTarget(T( window )) the SetDropTarget() method registers the window
as target-window at the TextDropTarget() and in an event-handler of the base class that reference (to the same textctrl)
succeeds in updating the textctrl the same as the T::OnDropText()
if instead i save the target-window in o.obj :
class T(wx.TextDropTarget):
def init(o,obj):
super(T,o).init()
o.obj = obj
def OnDropText(o,x,y,data):
obj.WriteText( data + \n )
then the text is pasted once as expected.
but why ?
and if now i allow t1 as target, too and drop over t1 than the dragged text is pasted correct at the end, but
next to the previous selection there are some new empty lines. (attached as text.py)
thanks in advance
andreas