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