]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/URLDragAndDrop.py
4 #----------------------------------------------------------------------
6 class MyURLDropTarget(wx
.PyDropTarget
):
7 def __init__(self
, window
):
8 wx
.PyDropTarget
.__init
__(self
)
11 self
.data
= wx
.URLDataObject();
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(wx
.Panel
):
30 def __init__(self
, parent
, log
):
31 wx
.Panel
.__init
__(self
, parent
, -1)
33 self
.SetAutoLayout(True)
34 outsideSizer
= wx
.BoxSizer(wx
.VERTICAL
)
36 msg
= "Drag-And-Drop of URLs"
37 text
= wx
.StaticText(self
, -1, "", style
=wx
.ALIGN_CENTRE
)
38 text
.SetFont(wx
.Font(24, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
, False))
40 w
,h
= text
.GetTextExtent(msg
)
41 text
.SetSize(wx
.Size(w
,h
+1))
42 text
.SetForegroundColour(wx
.BLUE
)
43 outsideSizer
.Add(text
, 0, wx
.EXPAND|wx
.ALL
, 5)
44 outsideSizer
.Add(wx
.StaticLine(self
, -1), 0, wx
.EXPAND
)
45 outsideSizer
.Add((20,20))
47 self
.SetFont(wx
.Font(10, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
, False))
49 inSizer
= wx
.FlexGridSizer(2, 2, 5, 5)
50 inSizer
.AddGrowableCol(0)
54 inSizer
.Add(wx
.StaticText(self
, -1,
55 "Drag URLs from your browser to\nthis window:",
56 style
= wx
.ALIGN_RIGHT
),
58 self
.dropText
= wx
.TextCtrl(self
, -1, "", size
=(380, 180),
59 style
=wx
.TE_MULTILINE|wx
.TE_READONLY
)
60 inSizer
.Add(self
.dropText
, 0, wx
.EXPAND
)
63 inSizer
.Add(wx
.StaticText(self
, -1,
64 "Drag this URL to your browser:",
65 style
= wx
.ALIGN_RIGHT
),
67 self
.dragText
= wx
.TextCtrl(self
, -1, "http://wxPython.org/")
68 inSizer
.Add(self
.dragText
, 0, wx
.EXPAND
)
69 self
.dragText
.Bind(wx
.EVT_MOTION
, self
.OnStartDrag
)
72 ## inSizer.Add(wx.StaticText(self, -1,
73 ## "Drag this TEXT to your browser:",
74 ## style = wx.ALIGN_RIGHT),
75 ## 0, wx.ALIGN_RIGHT )
76 ## self.dragText2 = wx.TextCtrl(self, -1, "http://wxPython.org/")
77 ## inSizer.Add(self.dragText2, 0, wx.EXPAND)
78 ## self.dragText2.Bind(EVT_MOTION, self.OnStartDrag2)
81 outsideSizer
.Add(inSizer
, 1, wx
.EXPAND
)
82 self
.SetSizer(outsideSizer
)
84 self
.dropText
.SetDropTarget(MyURLDropTarget(self
.dropText
))
87 def OnStartDrag(self
, evt
):
89 url
= self
.dragText
.GetValue()
90 data
= wx
.URLDataObject()
93 dropSource
= wx
.DropSource(self
.dragText
)
94 dropSource
.SetData(data
)
95 result
= dropSource
.DoDragDrop()
98 def OnStartDrag2(self
, evt
):
100 url
= self
.dragText2
.GetValue()
101 data
= wx
.TextDataObject()
104 dropSource
= wx
.DropSource(self
.dragText2
)
105 dropSource
.SetData(data
)
106 result
= dropSource
.DoDragDrop()
109 #----------------------------------------------------------------------
111 def runTest(frame
, nb
, log
):
112 win
= TestPanel(nb
, log
)
115 #----------------------------------------------------------------------
126 if __name__
== '__main__':
129 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])