]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/URLDragAndDrop.py
Don't bind events to the return value of SetDefault, D'oh!
[wxWidgets.git] / wxPython / demo / URLDragAndDrop.py
1
2 import wx
3
4 #----------------------------------------------------------------------
5
6 class MyURLDropTarget(wx.PyDropTarget):
7 def __init__(self, window):
8 wx.PyDropTarget.__init__(self)
9 self.window = window
10
11 self.data = wx.URLDataObject();
12 self.SetDataObject(self.data)
13
14 def OnDragOver(self, x, y, d):
15 return wx.DragLink
16
17 def OnData(self, x, y, d):
18 if not self.GetData():
19 return wx.DragNone
20
21 url = self.data.GetURL()
22 self.window.AppendText(url + "\n")
23
24 return d
25
26
27 #----------------------------------------------------------------------
28
29 class TestPanel(wx.Panel):
30 def __init__(self, parent, log):
31 wx.Panel.__init__(self, parent, -1)
32
33 self.SetAutoLayout(True)
34 outsideSizer = wx.BoxSizer(wx.VERTICAL)
35
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))
39 text.SetLabel(msg)
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))
46
47 self.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False))
48
49 inSizer = wx.FlexGridSizer(2, 2, 5, 5)
50 inSizer.AddGrowableCol(0)
51
52 inSizer.Add((20,20))
53 inSizer.Add((20,20))
54 inSizer.Add(wx.StaticText(self, -1,
55 "Drag URLs from your browser to\nthis window:",
56 style = wx.ALIGN_RIGHT),
57 0, 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)
61
62
63 inSizer.Add(wx.StaticText(self, -1,
64 "Drag this URL to your browser:",
65 style = wx.ALIGN_RIGHT),
66 0, 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)
70
71
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)
79
80
81 outsideSizer.Add(inSizer, 1, wx.EXPAND)
82 self.SetSizer(outsideSizer)
83
84 self.dropText.SetDropTarget(MyURLDropTarget(self.dropText))
85
86
87 def OnStartDrag(self, evt):
88 if evt.Dragging():
89 url = self.dragText.GetValue()
90 data = wx.URLDataObject()
91 data.SetURL(url)
92
93 dropSource = wx.DropSource(self.dragText)
94 dropSource.SetData(data)
95 result = dropSource.DoDragDrop()
96
97
98 def OnStartDrag2(self, evt):
99 if evt.Dragging():
100 url = self.dragText2.GetValue()
101 data = wx.TextDataObject()
102 data.SetText(url)
103
104 dropSource = wx.DropSource(self.dragText2)
105 dropSource.SetData(data)
106 result = dropSource.DoDragDrop()
107
108
109 #----------------------------------------------------------------------
110
111 def runTest(frame, nb, log):
112 win = TestPanel(nb, log)
113 return win
114
115 #----------------------------------------------------------------------
116
117
118
119
120 overview = """\
121 """
122
123
124
125
126 if __name__ == '__main__':
127 import sys,os
128 import run
129 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
130