]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/URLDragAndDrop.py
New wxDesigner-less version of the MimeTypesManager demo
[wxWidgets.git] / wxPython / demo / URLDragAndDrop.py
CommitLineData
8fa876ca
RD
1# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2#
3# o Updated for wx namespace
4#
846ec2f9 5
8fa876ca 6import wx
846ec2f9
RD
7
8#----------------------------------------------------------------------
9
8fa876ca 10class MyURLDropTarget(wx.PyDropTarget):
846ec2f9 11 def __init__(self, window):
8fa876ca 12 wx.PyDropTarget.__init__(self)
846ec2f9
RD
13 self.window = window
14
8fa876ca 15 self.data = wx.URLDataObject();
846ec2f9
RD
16 self.SetDataObject(self.data)
17
18 def OnDragOver(self, x, y, d):
8fa876ca 19 return wx.DragLink
846ec2f9
RD
20
21 def OnData(self, x, y, d):
22 if not self.GetData():
8fa876ca 23 return wx.DragNone
846ec2f9
RD
24
25 url = self.data.GetURL()
26 self.window.AppendText(url + "\n")
27
28 return d
29
30
31#----------------------------------------------------------------------
32
8fa876ca 33class TestPanel(wx.Panel):
846ec2f9 34 def __init__(self, parent, log):
8fa876ca 35 wx.Panel.__init__(self, parent, -1)
846ec2f9 36
1e4a197e 37 self.SetAutoLayout(True)
8fa876ca 38 outsideSizer = wx.BoxSizer(wx.VERTICAL)
846ec2f9
RD
39
40 msg = "Drag-And-Drop of URLs"
8fa876ca
RD
41 text = wx.StaticText(self, -1, "", style=wx.ALIGN_CENTRE)
42 text.SetFont(wx.Font(24, wx.SWISS, wx.NORMAL, wx.BOLD, False))
846ec2f9
RD
43 text.SetLabel(msg)
44 w,h = text.GetTextExtent(msg)
372bde9b
RD
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)
fd3f2efe 49 outsideSizer.Add((20,20))
846ec2f9 50
8fa876ca 51 self.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False))
846ec2f9 52
8fa876ca 53 inSizer = wx.FlexGridSizer(2, 2, 5, 5)
846ec2f9
RD
54 inSizer.AddGrowableCol(0)
55
fd3f2efe
RD
56 inSizer.Add((20,20))
57 inSizer.Add((20,20))
372bde9b 58 inSizer.Add(wx.StaticText(self, -1,
846ec2f9 59 "Drag URLs from your browser to\nthis window:",
8fa876ca
RD
60 style = wx.ALIGN_RIGHT),
61 0, 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)
846ec2f9
RD
65
66
8fa876ca 67 inSizer.Add(wx.StaticText(self, -1,
846ec2f9 68 "Drag this URL to your browser:",
8fa876ca
RD
69 style = wx.ALIGN_RIGHT),
70 0, 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)
846ec2f9
RD
74
75
8fa876ca 76## inSizer.Add(wx.StaticText(self, -1,
b37c7e1d 77## "Drag this TEXT to your browser:",
8fa876ca
RD
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)
846ec2f9
RD
83
84
8fa876ca 85 outsideSizer.Add(inSizer, 1, wx.EXPAND)
846ec2f9
RD
86 self.SetSizer(outsideSizer)
87
846ec2f9
RD
88 self.dropText.SetDropTarget(MyURLDropTarget(self.dropText))
89
846ec2f9 90
846ec2f9
RD
91 def OnStartDrag(self, evt):
92 if evt.Dragging():
93 url = self.dragText.GetValue()
8fa876ca 94 data = wx.URLDataObject()
846ec2f9
RD
95 data.SetURL(url)
96
8fa876ca 97 dropSource = wx.DropSource(self.dragText)
846ec2f9
RD
98 dropSource.SetData(data)
99 result = dropSource.DoDragDrop()
100
101
102 def OnStartDrag2(self, evt):
103 if evt.Dragging():
104 url = self.dragText2.GetValue()
8fa876ca 105 data = wx.TextDataObject()
846ec2f9
RD
106 data.SetText(url)
107
8fa876ca 108 dropSource = wx.DropSource(self.dragText2)
846ec2f9
RD
109 dropSource.SetData(data)
110 result = dropSource.DoDragDrop()
111
112
113#----------------------------------------------------------------------
114
115def runTest(frame, nb, log):
116 win = TestPanel(nb, log)
117 return win
118
119#----------------------------------------------------------------------
120
121
122
123
124overview = """\
125"""
1fded56b
RD
126
127
128
129
130if __name__ == '__main__':
131 import sys,os
132 import run
133 run.main(['', os.path.basename(sys.argv[0])])
134