Open reticulatus opened 2 years ago
This issue has been mentioned on Discuss wxPython. There might be relevant details there:
https://discuss.wxpython.org/t/disabling-drag-and-drop-in-a-richtextctrl/35795/3
I think the real workaround is to call rt.RichTextBuffer.AddHandler(rt.RichTextXMLHandler())
in OnInit. However, you have a good point that it doesn't make sense that you should have to do that.
After doing that, it doesn't appear that drag and drop actually works in RichTextCtrl, at least on Linux/GTK. Does it work for you?
I am also running on Linux/GTK.
I can drag successfully from a RichTextCtrl to another editor (xed), but not the other way around. I can't drag & drop from a RichTextCtrl to itself.
It would be useful if I could prevent the drag operation from changing the mouse pointer.
I use yaml to save and load the text in my real application, so would prefer not to have to attach an XML handler that I won't be using.
Operating system: Linux Mint 20.3 wxPython version & source: wxPython 4.1.1 gtk3 (phoenix) wxWidgets 3.1.5 (built from https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-20.04 using pip). Python version & source: Python 3.8.10 from Linux Mint distribution.
Description of the problem:
If I double-click on a word in a RichTextCtrl and release the mouse button, the word is selected. If I then click on the word and drag with the mouse, the cursor changes to show a drag operation is taking place. If I release the mouse button while the mouse pointer is still in the RichTextCtrl an error dialog is displayed which says "An error occurred during drag and drop operation”. When you click on the Details button, it says “Could not write the buffer to an XML stream. You may have forgotten to add the XML file handler”.
Why does the control have a dependency on an XML Stream when dragging text from and to itself?
If the XML Stream is really required, why does it even allow the operation to start when an XML file handler hasn't been installed?
Why does it display an error message suitable for a developer, which would be confusing to most end users?
I have raised this issue at: https://discuss.wxpython.org/t/disabling-drag-and-drop-in-a-richtextctrl/35795 where @komoto48g has confirmed that it also occurs on Windows 10.
I have included a simple app below that can be used to demonstrate the issue.
To prevent the issue happening, uncomment the line
__init__()
that setsself.rtc.DropTarget = None
.Code Example (click to expand)
```python import wx import wx.richtext as rt TEXT = ( "Lorem IPSUM dolor sit amet, consectetur adipiscing elit, " "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " "Vestibulum lectus mauris ultrices eros in cursus turpis. " "Dui vivamus arcu felis bibendum ut. " "Ac turpis egestas integer eget aliquet nibh praesent tristique magna. " "Mauris ultrices eros in cursus turpis massa tincidunt dui. " "Mi bibendum neque egestas congue. " "Nunc sed augue lacus viverra vitae congue eu consequat. " "Consectetur adipiscing elit pellentesque habitant morbi. " "Pellentesque elit ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at. " "Ut lectus arcu bibendum at varius. " "Pellentesque eu tincidunt tortor aliquam nulla facilisi cras fermentum odio. " "Eget aliquet nibh praesent tristique. " "Sit amet aliquam id diam maecenas ultricies mi eget. " "Iaculis nunc sed augue lacus viverra vitae congue eu. " "Fames ac turpis egestas sed tempus urna. A diam maecenas sed enim ut sem. " "Aenean pharetra magna ac placerat vestibulum lectus mauris ultrices. " "Velit egestas dui id ornare arcu odio ut sem nulla. " "Placerat duis ultricies lacus sed. " "Libero enim sed faucibus turpis in eu mi bibendum. " ) class MyFrame(wx.Frame): def __init__(self, *args, **kwds): kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) self.SetSize((600, 300)) self.SetTitle("Test drag & drop") self.panel_1 = wx.Panel(self, wx.ID_ANY) sizer_1 = wx.BoxSizer(wx.VERTICAL) self.rtc = rt.RichTextCtrl(self.panel_1, wx.ID_ANY) sizer_1.Add(self.rtc, 1, wx.ALL | wx.EXPAND, 4) sizer_2 = wx.BoxSizer(wx.HORIZONTAL) sizer_1.Add(sizer_2, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.TOP, 8) self.close_button = wx.Button(self.panel_1, wx.ID_ANY, "Close") sizer_2.Add(self.close_button, 0, 0, 0) self.panel_1.SetSizer(sizer_1) self.Layout() self.Bind(wx.EVT_BUTTON, self.OnClose, self.close_button) # self.rtc.DropTarget = None self.rtc.SetValue(TEXT) def OnClose(self, _event): self.Destroy() class MyApp(wx.App): def OnInit(self): self.frame = MyFrame(None, wx.ID_ANY, "") self.SetTopWindow(self.frame) self.frame.Show() return True if __name__ == "__main__": app = MyApp(0) app.MainLoop() ```