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