]> git.saurik.com Git - wxWidgets.git/commitdiff
Added URL drag and drop sample to the wxPython demo
authorRobin Dunn <robin@alldunn.com>
Fri, 26 Oct 2001 02:13:11 +0000 (02:13 +0000)
committerRobin Dunn <robin@alldunn.com>
Fri, 26 Oct 2001 02:13:11 +0000 (02:13 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12167 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

wxPython/demo/DragAndDrop.py
wxPython/demo/Main.py
wxPython/demo/URLDragAndDrop.py [new file with mode: 0644]

index 090c162b890e9070eecaa4821ada00e4b10afc44..59dff7b2b7ecbcc0a9cc713fa75ecff6ff3dbc69 100644 (file)
@@ -111,6 +111,16 @@ class MyFileDropTarget(wxFileDropTarget):
             self.window.WriteText(file + '\n')
 
 
+class MyTextDropTarget(wxTextDropTarget):
+    def __init__(self, window, log):
+        wxTextDropTarget.__init__(self)
+        self.window = window
+        self.log = log
+
+    def OnDropText(self, x, y, text):
+        self.window.WriteText("(%d, %d)\n%s\n" % (x, y, text))
+
+
 
 class FileDropPanel(wxPanel):
     def __init__(self, parent, log):
@@ -128,6 +138,14 @@ class FileDropPanel(wxPanel):
         self.text.SetDropTarget(dt)
         sizer.Add(self.text, 1, wxEXPAND)
 
+        sizer.Add(wxStaticText(self, -1, " \nDrag some text here:"),
+                  0, wxEXPAND|wxALL, 2)
+        self.text2 = wxTextCtrl(self, -1, "",
+                               style = wxTE_MULTILINE|wxHSCROLL|wxTE_READONLY)
+        dt = MyTextDropTarget(self.text2, log)
+        self.text2.SetDropTarget(dt)
+        sizer.Add(self.text2, 1, wxEXPAND)
+
         self.SetAutoLayout(true)
         self.SetSizer(sizer)
 
index e0ca92f26008c19e7a9574e9dc09ee31efe75eb8..afd2b131c9cb5c287f53b9dbd84b13c0111be456 100644 (file)
@@ -33,6 +33,7 @@ _treeList = [
                                 'DrawXXXList',
                                 'ErrorDialogs',
                                 'wxRightTextCtrl',
+                                'URLDragAndDrop',
                                 ##'wxPopupWindow',
                                 ]),
 
@@ -60,7 +61,8 @@ _treeList = [
 
     ('Window Layout', ['wxLayoutConstraints', 'LayoutAnchors', 'Sizers', 'XML_Resource']),
 
-    ('Miscellaneous', [ 'DragAndDrop', 'CustomDragAndDrop', 'FontEnumerator',
+    ('Miscellaneous', [ 'DragAndDrop', 'CustomDragAndDrop', 'URLDragAndDrop',
+                        'FontEnumerator',
                         'wxTimer', 'wxValidator', 'wxGLCanvas', 'DialogUnits',
                         'wxImage', 'wxMask', 'PrintFramework', 'wxOGL',
                         'PythonEvents', 'Threads',
diff --git a/wxPython/demo/URLDragAndDrop.py b/wxPython/demo/URLDragAndDrop.py
new file mode 100644 (file)
index 0000000..4225a27
--- /dev/null
@@ -0,0 +1,123 @@
+
+from wxPython.wx import *
+
+#----------------------------------------------------------------------
+
+class MyURLDropTarget(wxPyDropTarget):
+    def __init__(self, window):
+        wxPyDropTarget.__init__(self)
+        self.window = window
+
+        self.data = wxURLDataObject();
+        self.SetDataObject(self.data)
+
+    def OnDragOver(self, x, y, d):
+        return wxDragLink
+
+    def OnData(self, x, y, d):
+        if not self.GetData():
+            return wxDragNone
+
+        url = self.data.GetURL()
+        self.window.AppendText(url + "\n")
+
+        return d
+
+
+#----------------------------------------------------------------------
+
+class TestPanel(wxPanel):
+    def __init__(self, parent, log):
+        wxPanel.__init__(self, parent, -1)
+
+        self.SetAutoLayout(true)
+        outsideSizer = wxBoxSizer(wxVERTICAL)
+
+        msg = "Drag-And-Drop of URLs"
+        text = wxStaticText(self, -1, "", style=wxALIGN_CENTRE)
+        text.SetFont(wxFont(24, wxSWISS, wxNORMAL, wxBOLD, false))
+        text.SetLabel(msg)
+        w,h = text.GetTextExtent(msg)
+        text.SetSize(wxSize(w,h+1))
+        text.SetForegroundColour(wxBLUE)
+        outsideSizer.Add(text, 0, wxEXPAND|wxALL, 5)
+        outsideSizer.Add(wxStaticLine(self, -1), 0, wxEXPAND)
+        outsideSizer.Add(20,20)
+
+        self.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD, false))
+
+        inSizer = wxFlexGridSizer(2, 2, 5, 5)
+        inSizer.AddGrowableCol(0)
+
+        inSizer.Add(20,20)
+        inSizer.Add(20,20)
+        inSizer.Add(wxStaticText(self, -1,
+                                 "Drag URLs from your browser to\nthis window:",
+                                 style = wxALIGN_RIGHT),
+                    0, wxALIGN_RIGHT )
+        self.dropText = wxTextCtrl(self, -1, "", size=(380, 180),
+                                   style=wxTE_MULTILINE|wxTE_READONLY)
+        inSizer.Add(self.dropText, 0, wxEXPAND)
+
+
+        inSizer.Add(wxStaticText(self, -1,
+                                 "Drag this URL to your browser:",
+                                 style = wxALIGN_RIGHT),
+                    0, wxALIGN_RIGHT )
+        self.dragText = wxTextCtrl(self, -1, "http://wxPython.org/")
+        inSizer.Add(self.dragText, 0, wxEXPAND)
+
+
+        inSizer.Add(wxStaticText(self, -1,
+                                 "Drag this TEXT to your browser:",
+                                 style = wxALIGN_RIGHT),
+                    0, wxALIGN_RIGHT )
+        self.dragText2 = wxTextCtrl(self, -1, "http://wxPython.org/")
+        inSizer.Add(self.dragText2, 0, wxEXPAND)
+
+
+        outsideSizer.Add(inSizer, 1, wxEXPAND)
+        self.SetSizer(outsideSizer)
+
+
+        self.dropText.SetDropTarget(MyURLDropTarget(self.dropText))
+
+        EVT_MOTION(self.dragText, self.OnStartDrag)
+        EVT_MOTION(self.dragText2, self.OnStartDrag2)
+
+
+    def OnStartDrag(self, evt):
+        if evt.Dragging():
+            url = self.dragText.GetValue()
+            data = wxURLDataObject()
+            data.SetURL(url)
+
+            dropSource = wxDropSource(self.dragText)
+            dropSource.SetData(data)
+            result = dropSource.DoDragDrop()
+
+
+    def OnStartDrag2(self, evt):
+        if evt.Dragging():
+            url = self.dragText2.GetValue()
+            data = wxTextDataObject()
+            data.SetText(url)
+
+            dropSource = wxDropSource(self.dragText2)
+            dropSource.SetData(data)
+            result = dropSource.DoDragDrop()
+
+
+#----------------------------------------------------------------------
+
+def runTest(frame, nb, log):
+    win = TestPanel(nb, log)
+    return win
+
+#----------------------------------------------------------------------
+
+
+
+
+overview = """\
+"""