X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/95bfd958bda8955ac81277c78e5627c926154f39..db679b8c836e69c111cdc31e62cf92cebe4f938f:/wxPython/demo/DragAndDrop.py diff --git a/wxPython/demo/DragAndDrop.py b/wxPython/demo/DragAndDrop.py index 5039872fc2..95b192dbbb 100644 --- a/wxPython/demo/DragAndDrop.py +++ b/wxPython/demo/DragAndDrop.py @@ -48,16 +48,19 @@ class ClipTextPanel(wx.Panel): def OnCopy(self, evt): self.do = wx.TextDataObject() self.do.SetText(self.text.GetValue()) - wx.TheClipboard.Open() - wx.TheClipboard.SetData(self.do) - wx.TheClipboard.Close() + if wx.TheClipboard.Open(): + wx.TheClipboard.SetData(self.do) + wx.TheClipboard.Close() + else: + wx.MessageBox("Unable to open the clipboard", "Error") def OnPaste(self, evt): + success = False do = wx.TextDataObject() - wx.TheClipboard.Open() - success = wx.TheClipboard.GetData(do) - wx.TheClipboard.Close() + if wx.TheClipboard.Open(): + success = wx.TheClipboard.GetData(do) + wx.TheClipboard.Close() if success: self.text.SetValue(do.GetText()) @@ -73,14 +76,19 @@ class ClipTextPanel(wx.Panel): if dlg.ShowModal() == wx.ID_OK: bmp = wx.Bitmap(dlg.GetPath(), wx.BITMAP_TYPE_BMP) bmpdo = wx.BitmapDataObject(bmp) - wx.TheClipboard.Open() - wx.TheClipboard.SetData(bmpdo) - wx.TheClipboard.Close() - - wx.MessageBox( - "The bitmap is now in the Clipboard. Switch to a graphics\n" - "editor and try pasting it in..." - ) + if wx.TheClipboard.Open(): + wx.TheClipboard.SetData(bmpdo) + wx.TheClipboard.Close() + + wx.MessageBox( + "The bitmap is now in the Clipboard. Switch to a graphics\n" + "editor and try pasting it in..." + ) + else: + wx.MessageBox( + "There is no data in the clipboard in the required format", + "Error" + ) dlg.Destroy() @@ -261,5 +269,5 @@ processor. Let us describe what each of them should do. if __name__ == '__main__': import sys,os import run - run.main(['', os.path.basename(sys.argv[0])]) + run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])