From 95fac6845163cc898c83b2ed7b4ed6fec31a51a4 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 3 May 2012 23:30:43 +0000 Subject: [PATCH] Add wxDropSource and wxDropTarget git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@71350 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- TODO.txt | 2 +- docs/MigrationGuide.txt | 12 +++++++++ etg/defs.py | 1 - etg/dnd.py | 54 ++++++++++++++++++++++++++++++++++------- unittests/test_dnd.py | 36 +++++++++++++++++++++++++-- 5 files changed, 92 insertions(+), 13 deletions(-) diff --git a/TODO.txt b/TODO.txt index 0b56675a..7bb7acff 100644 --- a/TODO.txt +++ b/TODO.txt @@ -129,7 +129,7 @@ other dev stuff * joystick * sound * mimetype - * clipbrd, dnd, finish dataobj + * clipbrd, finish dataobj * power * overlay * PseudoDC diff --git a/docs/MigrationGuide.txt b/docs/MigrationGuide.txt index 75034fd7..13f8298c 100644 --- a/docs/MigrationGuide.txt +++ b/docs/MigrationGuide.txt @@ -307,3 +307,15 @@ you to tell the wx.Image to use memory buffers in other objects (such as a numpy array) as its RGB or Alpha data, as long as the other object supports the new buffer protocol. + + +wx.DropSource +------------- + +We don't (yet) have an easy way to support different APIs per platform +in the wx class constructors, so wx.DropSource (which optionally takes +parameters that should be a wx.Icon on wxGTK or a wx.Cursor on the +other platforms) has been changed to not accept the cursor/icon in the +constructors. Instead you'll have to call either SetCursor or SetIcon +depending on the platform. + diff --git a/etg/defs.py b/etg/defs.py index c04476b2..6d020d4e 100644 --- a/etg/defs.py +++ b/etg/defs.py @@ -68,7 +68,6 @@ def run(): module.insertItem(0, etgtools.WigCode("""\ // forward declarations class wxPalette; - class wxDropTarget; class wxCaret; class wxExecuteEnv; """)) diff --git a/etg/dnd.py b/etg/dnd.py index 7d8fda64..53ebfa08 100644 --- a/etg/dnd.py +++ b/etg/dnd.py @@ -18,10 +18,10 @@ DOCSTRING = "" # The classes and/or the basename of the Doxygen XML files to be processed by # this script. ITEMS = [ "interface_2wx_2dnd_8h.xml", - #"wxDropTarget", - #"wxTextDropTarget", - #"wxFileDropTarget", - #"wxDropSource", + "wxDropSource", + "wxDropTarget", + "wxTextDropTarget", + "wxFileDropTarget", ] #--------------------------------------------------------------------------- @@ -37,12 +37,48 @@ def run(): module.addHeaderCode('#include ') - #c = module.find('wxDropSource') - #assert isinstance(c, etgtools.ClassDef) + c = module.find('wxDropSource') + assert isinstance(c, etgtools.ClassDef) + c.addPrivateCopyCtor() + + for m in c.find('wxDropSource').all(): + if 'wxIcon' in m.argsString: + # Ignore the ctors taking wxIcon parameters. They are GTK only + # and we don't have an easy way yet to support platform specific + # APIs in the ctors. + m.ignore() + else: + # Ignore the cursor parameters. We'll need to use SetCursor or + # SetIcon instead. + m.find('iconCopy').ignore() + m.find('iconMove').ignore() + m.find('iconNone').ignore() + + # void SetCursor(wxDragResult res, const wxCursor& cursor); + c.find('SetCursor').setCppCode("""\ + #ifdef __WXGTK__ + wxPyRaiseNotImplementedMsg("Cursors not supported, use SetIcon on wxGTK instead."); + #else + self->SetCursor(res, *cursor); + #endif + """) - #for m in c.find('wxDropSource').all(): - # if 'wxIcon' in m.argsString: - # m.ignore() + # void SetIcon(wxDragResult res, const wxIcon& icon) + c.find('SetIcon').setCppCode("""\ + #ifdef __WXGTK__ + self->SetIcon(res, *icon); + #else + wxPyRaiseNotImplementedMsg("Icons not supported, use SetCursor on non-wxGTK ports."); + #endif + """) + + + + c = module.find('wxDropTarget') + c.addPrivateCopyCtor() + c.find('wxDropTarget.data').transfer = True + c.find('SetDataObject.data').transfer = True + c.addPyCode("PyDropTarget = wx.deprecated(DropTarget)") diff --git a/unittests/test_dnd.py b/unittests/test_dnd.py index 40d75da6..8526d2f1 100644 --- a/unittests/test_dnd.py +++ b/unittests/test_dnd.py @@ -1,14 +1,46 @@ import imp_unittest, unittest import wtc import wx +import os + +icoFile = os.path.join(os.path.dirname(__file__), 'mondrian.ico') +curFile = os.path.join(os.path.dirname(__file__), 'horse.cur') #--------------------------------------------------------------------------- class dnd_Tests(wtc.WidgetTestCase): - # TODO: Remove this test and add real ones. def test_dnd1(self): - self.fail("Unit tests for dnd not implemented yet.") + wx.Drag_CopyOnly + wx.Drag_AllowMove + wx.Drag_DefaultMove + + wx.DragError + wx.DragNone + wx.DragCopy + wx.DragMove + wx.DragLink + wx.DragCancel + + + def test_dndDropTarget(self): + class MyTarget(wx.DropTarget): + def OnData(self, x, y, defResult): + self.GetData() + return defResult + + dt = MyTarget() + dt.DefaultAction + self.frame.SetDropTarget(dt) + + + def test_dndDropSource(self): + ds = wx.DropSource(self.frame) + if 'wxGTK' in wx.PlatformInfo: + ds.SetIcon(wx.DragCopy, wx.Icon(icoFile)) + else: + ds.SetCursor(wx.DragCopy, wx.Cursor(curFile)) + #---------------------------------------------------------------------------