]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/demo/DragAndDrop.py
merge from 2.8 branch
[wxWidgets.git] / wxPython / demo / DragAndDrop.py
index d04bdc7048d9d5e459851f91c740c54d1f181494..95b192dbbb07f16b1d86c2a94cf9f3195b4418e1 100644 (file)
@@ -1,14 +1,3 @@
-# 11/5/2003 - Jeff Grimmett (grimmtooth@softhome.net)
-#
-# o Updated for wx namespace
-# o Got rid of all the hardcoded window IDs.
-# o Fixed a bug in class TestPanel() (empty sizer Add())
-#
-# 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net)
-#
-# o Fixed a bug in the BMP file dialog; was using GetFilename() 
-#   instead of GetPath() to get the file to load.
-#
 
 import  wx
 
 
 import  wx
 
@@ -59,16 +48,19 @@ class ClipTextPanel(wx.Panel):
     def OnCopy(self, evt):
         self.do = wx.TextDataObject()
         self.do.SetText(self.text.GetValue())
     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):
 
 
     def OnPaste(self, evt):
+        success = False
         do = wx.TextDataObject()
         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())
 
         if success:
             self.text.SetValue(do.GetText())
@@ -84,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)
         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()
 
 
         dlg.Destroy()
 
@@ -272,5 +269,5 @@ processor. Let us describe what each of them should do.
 if __name__ == '__main__':
     import sys,os
     import run
 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:])