2001-10-25 22:13:11 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
import wx
|
2001-10-25 22:13:11 -04:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class MyURLDropTarget(wx.PyDropTarget):
|
2001-10-25 22:13:11 -04:00
|
|
|
def __init__(self, window):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.PyDropTarget.__init__(self)
|
2001-10-25 22:13:11 -04:00
|
|
|
self.window = window
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
self.data = wx.URLDataObject();
|
2001-10-25 22:13:11 -04:00
|
|
|
self.SetDataObject(self.data)
|
|
|
|
|
|
|
|
def OnDragOver(self, x, y, d):
|
2003-12-08 20:23:28 -05:00
|
|
|
return wx.DragLink
|
2001-10-25 22:13:11 -04:00
|
|
|
|
|
|
|
def OnData(self, x, y, d):
|
|
|
|
if not self.GetData():
|
2003-12-08 20:23:28 -05:00
|
|
|
return wx.DragNone
|
2001-10-25 22:13:11 -04:00
|
|
|
|
|
|
|
url = self.data.GetURL()
|
|
|
|
self.window.AppendText(url + "\n")
|
|
|
|
|
|
|
|
return d
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestPanel(wx.Panel):
|
2001-10-25 22:13:11 -04:00
|
|
|
def __init__(self, parent, log):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
2001-10-25 22:13:11 -04:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
self.SetAutoLayout(True)
|
2003-12-08 20:23:28 -05:00
|
|
|
outsideSizer = wx.BoxSizer(wx.VERTICAL)
|
2001-10-25 22:13:11 -04:00
|
|
|
|
|
|
|
msg = "Drag-And-Drop of URLs"
|
2003-12-08 20:23:28 -05:00
|
|
|
text = wx.StaticText(self, -1, "", style=wx.ALIGN_CENTRE)
|
|
|
|
text.SetFont(wx.Font(24, wx.SWISS, wx.NORMAL, wx.BOLD, False))
|
2001-10-25 22:13:11 -04:00
|
|
|
text.SetLabel(msg)
|
|
|
|
w,h = text.GetTextExtent(msg)
|
2003-12-11 14:55:48 -05:00
|
|
|
text.SetSize(wx.Size(w,h+1))
|
|
|
|
text.SetForegroundColour(wx.BLUE)
|
|
|
|
outsideSizer.Add(text, 0, wx.EXPAND|wx.ALL, 5)
|
|
|
|
outsideSizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND)
|
2003-11-22 17:57:49 -05:00
|
|
|
outsideSizer.Add((20,20))
|
2001-10-25 22:13:11 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
self.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False))
|
2001-10-25 22:13:11 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
inSizer = wx.FlexGridSizer(2, 2, 5, 5)
|
2001-10-25 22:13:11 -04:00
|
|
|
inSizer.AddGrowableCol(0)
|
|
|
|
|
2003-11-22 17:57:49 -05:00
|
|
|
inSizer.Add((20,20))
|
|
|
|
inSizer.Add((20,20))
|
2003-12-11 14:55:48 -05:00
|
|
|
inSizer.Add(wx.StaticText(self, -1,
|
2001-10-25 22:13:11 -04:00
|
|
|
"Drag URLs from your browser to\nthis window:",
|
2003-12-08 20:23:28 -05:00
|
|
|
style = wx.ALIGN_RIGHT),
|
|
|
|
0, wx.ALIGN_RIGHT )
|
|
|
|
self.dropText = wx.TextCtrl(self, -1, "", size=(380, 180),
|
|
|
|
style=wx.TE_MULTILINE|wx.TE_READONLY)
|
|
|
|
inSizer.Add(self.dropText, 0, wx.EXPAND)
|
2001-10-25 22:13:11 -04:00
|
|
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
inSizer.Add(wx.StaticText(self, -1,
|
2001-10-25 22:13:11 -04:00
|
|
|
"Drag this URL to your browser:",
|
2003-12-08 20:23:28 -05:00
|
|
|
style = wx.ALIGN_RIGHT),
|
|
|
|
0, wx.ALIGN_RIGHT )
|
|
|
|
self.dragText = wx.TextCtrl(self, -1, "http://wxPython.org/")
|
|
|
|
inSizer.Add(self.dragText, 0, wx.EXPAND)
|
|
|
|
self.dragText.Bind(wx.EVT_MOTION, self.OnStartDrag)
|
2001-10-25 22:13:11 -04:00
|
|
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
## inSizer.Add(wx.StaticText(self, -1,
|
2001-10-30 01:43:54 -05:00
|
|
|
## "Drag this TEXT to your browser:",
|
2003-12-08 20:23:28 -05:00
|
|
|
## style = wx.ALIGN_RIGHT),
|
|
|
|
## 0, wx.ALIGN_RIGHT )
|
|
|
|
## self.dragText2 = wx.TextCtrl(self, -1, "http://wxPython.org/")
|
|
|
|
## inSizer.Add(self.dragText2, 0, wx.EXPAND)
|
|
|
|
## self.dragText2.Bind(EVT_MOTION, self.OnStartDrag2)
|
2001-10-25 22:13:11 -04:00
|
|
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
outsideSizer.Add(inSizer, 1, wx.EXPAND)
|
2001-10-25 22:13:11 -04:00
|
|
|
self.SetSizer(outsideSizer)
|
|
|
|
|
|
|
|
self.dropText.SetDropTarget(MyURLDropTarget(self.dropText))
|
|
|
|
|
|
|
|
|
|
|
|
def OnStartDrag(self, evt):
|
|
|
|
if evt.Dragging():
|
|
|
|
url = self.dragText.GetValue()
|
2003-12-08 20:23:28 -05:00
|
|
|
data = wx.URLDataObject()
|
2001-10-25 22:13:11 -04:00
|
|
|
data.SetURL(url)
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
dropSource = wx.DropSource(self.dragText)
|
2001-10-25 22:13:11 -04:00
|
|
|
dropSource.SetData(data)
|
|
|
|
result = dropSource.DoDragDrop()
|
|
|
|
|
|
|
|
|
|
|
|
def OnStartDrag2(self, evt):
|
|
|
|
if evt.Dragging():
|
|
|
|
url = self.dragText2.GetValue()
|
2003-12-08 20:23:28 -05:00
|
|
|
data = wx.TextDataObject()
|
2001-10-25 22:13:11 -04:00
|
|
|
data.SetText(url)
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
dropSource = wx.DropSource(self.dragText2)
|
2001-10-25 22:13:11 -04:00
|
|
|
dropSource.SetData(data)
|
|
|
|
result = dropSource.DoDragDrop()
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestPanel(nb, log)
|
|
|
|
return win
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
overview = """\
|
|
|
|
"""
|
2003-07-02 19:13:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
|
|
|
run.main(['', os.path.basename(sys.argv[0])])
|
|
|
|
|