]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/URLDragAndDrop.py
A little less flicker when selecting text.
[wxWidgets.git] / wxPython / demo / URLDragAndDrop.py
1
2 from wxPython.wx import *
3
4 #----------------------------------------------------------------------
5
6 class MyURLDropTarget(wxPyDropTarget):
7 def __init__(self, window):
8 wxPyDropTarget.__init__(self)
9 self.window = window
10
11 self.data = wxURLDataObject();
12 self.SetDataObject(self.data)
13
14 def OnDragOver(self, x, y, d):
15 return wxDragLink
16
17 def OnData(self, x, y, d):
18 if not self.GetData():
19 return wxDragNone
20
21 url = self.data.GetURL()
22 self.window.AppendText(url + "\n")
23
24 return d
25
26
27 #----------------------------------------------------------------------
28
29 class TestPanel(wxPanel):
30 def __init__(self, parent, log):
31 wxPanel.__init__(self, parent, -1)
32
33 self.SetAutoLayout(true)
34 outsideSizer = wxBoxSizer(wxVERTICAL)
35
36 msg = "Drag-And-Drop of URLs"
37 text = wxStaticText(self, -1, "", style=wxALIGN_CENTRE)
38 text.SetFont(wxFont(24, wxSWISS, wxNORMAL, wxBOLD, false))
39 text.SetLabel(msg)
40 w,h = text.GetTextExtent(msg)
41 text.SetSize(wxSize(w,h+1))
42 text.SetForegroundColour(wxBLUE)
43 outsideSizer.Add(text, 0, wxEXPAND|wxALL, 5)
44 outsideSizer.Add(wxStaticLine(self, -1), 0, wxEXPAND)
45 outsideSizer.Add(20,20)
46
47 self.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD, false))
48
49 inSizer = wxFlexGridSizer(2, 2, 5, 5)
50 inSizer.AddGrowableCol(0)
51
52 inSizer.Add(20,20)
53 inSizer.Add(20,20)
54 inSizer.Add(wxStaticText(self, -1,
55 "Drag URLs from your browser to\nthis window:",
56 style = wxALIGN_RIGHT),
57 0, wxALIGN_RIGHT )
58 self.dropText = wxTextCtrl(self, -1, "", size=(380, 180),
59 style=wxTE_MULTILINE|wxTE_READONLY)
60 inSizer.Add(self.dropText, 0, wxEXPAND)
61
62
63 inSizer.Add(wxStaticText(self, -1,
64 "Drag this URL to your browser:",
65 style = wxALIGN_RIGHT),
66 0, wxALIGN_RIGHT )
67 self.dragText = wxTextCtrl(self, -1, "http://wxPython.org/")
68 inSizer.Add(self.dragText, 0, wxEXPAND)
69 EVT_MOTION(self.dragText, self.OnStartDrag)
70
71
72 ## inSizer.Add(wxStaticText(self, -1,
73 ## "Drag this TEXT to your browser:",
74 ## style = wxALIGN_RIGHT),
75 ## 0, wxALIGN_RIGHT )
76 ## self.dragText2 = wxTextCtrl(self, -1, "http://wxPython.org/")
77 ## inSizer.Add(self.dragText2, 0, wxEXPAND)
78 ## EVT_MOTION(self.dragText2, self.OnStartDrag2)
79
80
81 outsideSizer.Add(inSizer, 1, wxEXPAND)
82 self.SetSizer(outsideSizer)
83
84
85 self.dropText.SetDropTarget(MyURLDropTarget(self.dropText))
86
87
88
89 def OnStartDrag(self, evt):
90 if evt.Dragging():
91 url = self.dragText.GetValue()
92 data = wxURLDataObject()
93 data.SetURL(url)
94
95 dropSource = wxDropSource(self.dragText)
96 dropSource.SetData(data)
97 result = dropSource.DoDragDrop()
98
99
100 def OnStartDrag2(self, evt):
101 if evt.Dragging():
102 url = self.dragText2.GetValue()
103 data = wxTextDataObject()
104 data.SetText(url)
105
106 dropSource = wxDropSource(self.dragText2)
107 dropSource.SetData(data)
108 result = dropSource.DoDragDrop()
109
110
111 #----------------------------------------------------------------------
112
113 def runTest(frame, nb, log):
114 win = TestPanel(nb, log)
115 return win
116
117 #----------------------------------------------------------------------
118
119
120
121
122 overview = """\
123 """