2 from wxPython
.wx
import *
4 #----------------------------------------------------------------------
6 class MyURLDropTarget(wxPyDropTarget
):
7 def __init__(self
, window
):
8 wxPyDropTarget
.__init
__(self
)
11 self
.data
= wxURLDataObject();
12 self
.SetDataObject(self
.data
)
14 def OnDragOver(self
, x
, y
, d
):
17 def OnData(self
, x
, y
, d
):
18 if not self
.GetData():
21 url
= self
.data
.GetURL()
22 self
.window
.AppendText(url
+ "\n")
27 #----------------------------------------------------------------------
29 class TestPanel(wxPanel
):
30 def __init__(self
, parent
, log
):
31 wxPanel
.__init
__(self
, parent
, -1)
33 self
.SetAutoLayout(True)
34 outsideSizer
= wxBoxSizer(wxVERTICAL
)
36 msg
= "Drag-And-Drop of URLs"
37 text
= wxStaticText(self
, -1, "", style
=wxALIGN_CENTRE
)
38 text
.SetFont(wxFont(24, wxSWISS
, wxNORMAL
, wxBOLD
, False))
40 w
,h
= text
.GetTextExtent(msg
)
41 text
.SetSize(wxSize(w
,h
+1))
42 text
.SetForegroundColour(wxBLUE
)
43 outsideSizer
.Add(text
, 0, wxEXPAND|wxALL
, 5)
44 outsideSizer
.Add(wxStaticLine(self
, -1), 0, wxEXPAND
)
45 outsideSizer
.Add(20,20)
47 self
.SetFont(wxFont(10, wxSWISS
, wxNORMAL
, wxBOLD
, False))
49 inSizer
= wxFlexGridSizer(2, 2, 5, 5)
50 inSizer
.AddGrowableCol(0)
54 inSizer
.Add(wxStaticText(self
, -1,
55 "Drag URLs from your browser to\nthis window:",
56 style
= wxALIGN_RIGHT
),
58 self
.dropText
= wxTextCtrl(self
, -1, "", size
=(380, 180),
59 style
=wxTE_MULTILINE|wxTE_READONLY
)
60 inSizer
.Add(self
.dropText
, 0, wxEXPAND
)
63 inSizer
.Add(wxStaticText(self
, -1,
64 "Drag this URL to your browser:",
65 style
= wxALIGN_RIGHT
),
67 self
.dragText
= wxTextCtrl(self
, -1, "http://wxPython.org/")
68 inSizer
.Add(self
.dragText
, 0, wxEXPAND
)
69 EVT_MOTION(self
.dragText
, self
.OnStartDrag
)
72 ## inSizer.Add(wxStaticText(self, -1,
73 ## "Drag this TEXT to your browser:",
74 ## style = wxALIGN_RIGHT),
76 ## self.dragText2 = wxTextCtrl(self, -1, "http://wxPython.org/")
77 ## inSizer.Add(self.dragText2, 0, wxEXPAND)
78 ## EVT_MOTION(self.dragText2, self.OnStartDrag2)
81 outsideSizer
.Add(inSizer
, 1, wxEXPAND
)
82 self
.SetSizer(outsideSizer
)
85 self
.dropText
.SetDropTarget(MyURLDropTarget(self
.dropText
))
89 def OnStartDrag(self
, evt
):
91 url
= self
.dragText
.GetValue()
92 data
= wxURLDataObject()
95 dropSource
= wxDropSource(self
.dragText
)
96 dropSource
.SetData(data
)
97 result
= dropSource
.DoDragDrop()
100 def OnStartDrag2(self
, evt
):
102 url
= self
.dragText2
.GetValue()
103 data
= wxTextDataObject()
106 dropSource
= wxDropSource(self
.dragText2
)
107 dropSource
.SetData(data
)
108 result
= dropSource
.DoDragDrop()
111 #----------------------------------------------------------------------
113 def runTest(frame
, nb
, log
):
114 win
= TestPanel(nb
, log
)
117 #----------------------------------------------------------------------