From 97947ba176c1bf3fa35f8d8a775df18dab0c8dc7 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 2 Aug 2016 15:08:44 -0700 Subject: [PATCH] DnD of text or files to wx.TextCtrl doesn't work on OSX (Apple doesn't let us override the build-in behavior I think) so don't use a wx.TextCrtl for the drop target. --- demo/DragAndDrop.py | 38 ++++++++++++++------------------------ ext/wxWidgets | 2 +- unittests/test_dataobj.py | 2 ++ 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/demo/DragAndDrop.py b/demo/DragAndDrop.py index 297a27fe..b2d0be57 100644 --- a/demo/DragAndDrop.py +++ b/demo/DragAndDrop.py @@ -15,8 +15,6 @@ class ClipTextPanel(wx.Panel): wx.Panel.__init__(self, parent, -1) self.log = log - #self.SetFont(wx.Font(10, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False)) - sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( wx.StaticText( @@ -42,7 +40,6 @@ class ClipTextPanel(wx.Panel): self.Bind(wx.EVT_BUTTON, self.OnPaste, id=ID_PasteBtn) self.Bind(wx.EVT_BUTTON, self.OnCopyBitmap, id=ID_BitmapBtn) - self.SetAutoLayout(True) self.SetSizer(sizer) @@ -71,6 +68,7 @@ class ClipTextPanel(wx.Panel): "Error" ) + def OnCopyBitmap(self, evt): dlg = wx.FileDialog(self, "Choose a bitmap to copy", wildcard="*.bmp") @@ -120,7 +118,7 @@ class OtherDropTarget(wx.DropTarget): def OnData(self, x, y, d): self.log.WriteText("OnData: %d, %d, %d\n" % (x, y, d)) self.GetData() - self.log.WriteText("%s\n" % self.do.GetFilenames()) + self.log.SetLabel("%s\n" % self.do.GetFilenames()) return d @@ -131,11 +129,9 @@ class MyFileDropTarget(wx.FileDropTarget): self.log = log def OnDropFiles(self, x, y, filenames): - self.window.SetInsertionPointEnd() - self.window.WriteText("\n%d file(s) dropped at %d,%d:\n" % - (len(filenames), x, y)) - for file in filenames: - self.window.WriteText(file + '\n') + txt = "\n%d file(s) dropped at %d,%d:\n" % (len(filenames), x, y) + txt += '\n'.join(filenames) + self.window.SetLabel(txt) return True @@ -146,7 +142,7 @@ class MyTextDropTarget(wx.TextDropTarget): self.log = log def OnDropText(self, x, y, text): - self.window.WriteText("(%d, %d)\n%s\n" % (x, y, text)) + self.window.SetLabel("(%d, %d)\n%s\n" % (x, y, text)) return True def OnDragOver(self, x, y, d): @@ -165,38 +161,32 @@ class FileDropPanel(wx.Panel): 0, wx.EXPAND|wx.ALL, 2 ) - self.text = wx.TextCtrl( - self, -1, "", - style = wx.TE_MULTILINE|wx.HSCROLL|wx.TE_READONLY - ) + self.text = wx.StaticText(self, -1, "", style=wx.ST_NO_AUTORESIZE|wx.BORDER_SIMPLE) + self.text.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) dt = MyFileDropTarget(self, log) self.text.SetDropTarget(dt) - sizer.Add(self.text, 1, wx.EXPAND) + sizer.Add(self.text, 1, wx.EXPAND|wx.ALL, 5) sizer.Add( wx.StaticText(self, -1, " \nDrag some text here:"), 0, wx.EXPAND|wx.ALL, 2 ) - self.text2 = wx.TextCtrl( - self, -1, "", - style = wx.TE_MULTILINE|wx.HSCROLL|wx.TE_READONLY - ) + self.text2 = wx.StaticText(self, -1, "", style=wx.ST_NO_AUTORESIZE|wx.BORDER_SIMPLE) + self.text2.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) dt = MyTextDropTarget(self.text2, log) self.text2.SetDropTarget(dt) - sizer.Add(self.text2, 1, wx.EXPAND) + sizer.Add(self.text2, 1, wx.EXPAND|wx.ALL, 5) self.SetAutoLayout(True) self.SetSizer(sizer) - def WriteText(self, text): - self.text.WriteText(text) + def SetLabel(self, text): + self.text.SetLabel(text) - def SetInsertionPointEnd(self): - self.text.SetInsertionPointEnd() #---------------------------------------------------------------------- diff --git a/ext/wxWidgets b/ext/wxWidgets index 24d5ff7d..73fca4c3 160000 --- a/ext/wxWidgets +++ b/ext/wxWidgets @@ -1 +1 @@ -Subproject commit 24d5ff7dc1f6c9c14f001cf4004e342f52a19a3a +Subproject commit 73fca4c37d1ee2e9e495aaa68442cdfcb4243b52 diff --git a/unittests/test_dataobj.py b/unittests/test_dataobj.py index c657c51c..5a1c45d4 100644 --- a/unittests/test_dataobj.py +++ b/unittests/test_dataobj.py @@ -117,6 +117,7 @@ class DataObjTests(wtc.WidgetTestCase): def test_DataObject2(self): + # More-or-less a duplicate of the above, but with a custom data format class MyDataObject(wx.DataObject): def __init__(self, value=''): wx.DataObject.__init__(self) @@ -211,6 +212,7 @@ class DataObjTests(wtc.WidgetTestCase): def test_DataObjectSimple3(self): + # More-or-less a duplicate of the above, but with a custom data format class MyDataObject(wx.DataObjectSimple): def __init__(self, value=''): wx.DataObjectSimple.__init__(self)