Dear group,
The wx.TextCtrl provides a built-in Drag&Drop feature when the TE_RICH
or
TE_RICH2 style is set.
I'd like to apply my own TextDropTarget though, as I need additional
action.
I currently run python 2.6.5 and wxpython 2.8.10.1. This is my code:
···
---
import wx
class MyDropTarget(wx.TextDropTarget):
def __init__(self, window):
wx.TextDropTarget.__init__(self)
self._window = window
def OnDropText(self, x, y, text): self._window.WriteText("<%s>" %
text)
def OnDragOver(self, x, y, d): return wx.DragCopy
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "DnD test",
size=(300,60))
sizer = wx.BoxSizer(wx.HORIZONTAL)
self._control = wx.TextCtrl(self, wx.ID_ANY, "",
style=wx.TE_RICH)
sizer.Add(self._control, 1, wx.EXPAND)
self.SetSizer(sizer)
self.SetAutoLayout(True)
self._control.SetDropTarget(MyDropTarget(self._control))
def main():
app = wx.App(False)
frame = MyFrame()
frame.Show(True)
app.MainLoop()
if __name__ == "__main__": main()
---
Thus, when dragging "text" into my textfield, I'd like to put it as
"<text>" (This is only a simplified example for what I really intent).
If I instead set None in SetDropTarget, the DnD is disabled (as
expected),
but if I set MyDropTarget(...), I only get the default behaviour.
If I don't define the TE_RICH style for the TextCtrl, my example works
as
expected.
Q: How can I replace the default drop target by my own for a rich-
text
enabled TextCtrl?
Best regads
Volker