]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/URLDragAndDrop.py
1 # 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
8 #----------------------------------------------------------------------
10 class MyURLDropTarget(wx
.PyDropTarget
):
11 def __init__(self
, window
):
12 wx
.PyDropTarget
.__init
__(self
)
15 self
.data
= wx
.URLDataObject();
16 self
.SetDataObject(self
.data
)
18 def OnDragOver(self
, x
, y
, d
):
21 def OnData(self
, x
, y
, d
):
22 if not self
.GetData():
25 url
= self
.data
.GetURL()
26 self
.window
.AppendText(url
+ "\n")
31 #----------------------------------------------------------------------
33 class TestPanel(wx
.Panel
):
34 def __init__(self
, parent
, log
):
35 wx
.Panel
.__init
__(self
, parent
, -1)
37 self
.SetAutoLayout(True)
38 outsideSizer
= wx
.BoxSizer(wx
.VERTICAL
)
40 msg
= "Drag-And-Drop of URLs"
41 text
= wx
.StaticText(self
, -1, "", style
=wx
.ALIGN_CENTRE
)
42 text
.SetFont(wx
.Font(24, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
, False))
44 w
,h
= text
.GetTextExtent(msg
)
45 text
.SetSize(wx
.Size(w
,h
+1))
46 text
.SetForegroundColour(wx
.BLUE
)
47 outsideSizer
.Add(text
, 0, wx
.EXPAND|wx
.ALL
, 5)
48 outsideSizer
.Add(wx
.StaticLine(self
, -1), 0, wx
.EXPAND
)
49 outsideSizer
.Add((20,20))
51 self
.SetFont(wx
.Font(10, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
, False))
53 inSizer
= wx
.FlexGridSizer(2, 2, 5, 5)
54 inSizer
.AddGrowableCol(0)
58 inSizer
.Add(wx
.StaticText(self
, -1,
59 "Drag URLs from your browser to\nthis window:",
60 style
= wx
.ALIGN_RIGHT
),
62 self
.dropText
= wx
.TextCtrl(self
, -1, "", size
=(380, 180),
63 style
=wx
.TE_MULTILINE|wx
.TE_READONLY
)
64 inSizer
.Add(self
.dropText
, 0, wx
.EXPAND
)
67 inSizer
.Add(wx
.StaticText(self
, -1,
68 "Drag this URL to your browser:",
69 style
= wx
.ALIGN_RIGHT
),
71 self
.dragText
= wx
.TextCtrl(self
, -1, "http://wxPython.org/")
72 inSizer
.Add(self
.dragText
, 0, wx
.EXPAND
)
73 self
.dragText
.Bind(wx
.EVT_MOTION
, self
.OnStartDrag
)
76 ## inSizer.Add(wx.StaticText(self, -1,
77 ## "Drag this TEXT to your browser:",
78 ## style = wx.ALIGN_RIGHT),
79 ## 0, wx.ALIGN_RIGHT )
80 ## self.dragText2 = wx.TextCtrl(self, -1, "http://wxPython.org/")
81 ## inSizer.Add(self.dragText2, 0, wx.EXPAND)
82 ## self.dragText2.Bind(EVT_MOTION, self.OnStartDrag2)
85 outsideSizer
.Add(inSizer
, 1, wx
.EXPAND
)
86 self
.SetSizer(outsideSizer
)
88 self
.dropText
.SetDropTarget(MyURLDropTarget(self
.dropText
))
91 def OnStartDrag(self
, evt
):
93 url
= self
.dragText
.GetValue()
94 data
= wx
.URLDataObject()
97 dropSource
= wx
.DropSource(self
.dragText
)
98 dropSource
.SetData(data
)
99 result
= dropSource
.DoDragDrop()
102 def OnStartDrag2(self
, evt
):
104 url
= self
.dragText2
.GetValue()
105 data
= wx
.TextDataObject()
108 dropSource
= wx
.DropSource(self
.dragText2
)
109 dropSource
.SetData(data
)
110 result
= dropSource
.DoDragDrop()
113 #----------------------------------------------------------------------
115 def runTest(frame
, nb
, log
):
116 win
= TestPanel(nb
, log
)
119 #----------------------------------------------------------------------
130 if __name__
== '__main__':
133 run
.main(['', os
.path
.basename(sys
.argv
[0])])