Added URL drag and drop sample to the wxPython demo
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12167 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
e6d318c25a
commit
846ec2f9ed
@ -111,6 +111,16 @@ class MyFileDropTarget(wxFileDropTarget):
|
||||
self.window.WriteText(file + '\n')
|
||||
|
||||
|
||||
class MyTextDropTarget(wxTextDropTarget):
|
||||
def __init__(self, window, log):
|
||||
wxTextDropTarget.__init__(self)
|
||||
self.window = window
|
||||
self.log = log
|
||||
|
||||
def OnDropText(self, x, y, text):
|
||||
self.window.WriteText("(%d, %d)\n%s\n" % (x, y, text))
|
||||
|
||||
|
||||
|
||||
class FileDropPanel(wxPanel):
|
||||
def __init__(self, parent, log):
|
||||
@ -128,6 +138,14 @@ class FileDropPanel(wxPanel):
|
||||
self.text.SetDropTarget(dt)
|
||||
sizer.Add(self.text, 1, wxEXPAND)
|
||||
|
||||
sizer.Add(wxStaticText(self, -1, " \nDrag some text here:"),
|
||||
0, wxEXPAND|wxALL, 2)
|
||||
self.text2 = wxTextCtrl(self, -1, "",
|
||||
style = wxTE_MULTILINE|wxHSCROLL|wxTE_READONLY)
|
||||
dt = MyTextDropTarget(self.text2, log)
|
||||
self.text2.SetDropTarget(dt)
|
||||
sizer.Add(self.text2, 1, wxEXPAND)
|
||||
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(sizer)
|
||||
|
||||
|
@ -33,6 +33,7 @@ _treeList = [
|
||||
'DrawXXXList',
|
||||
'ErrorDialogs',
|
||||
'wxRightTextCtrl',
|
||||
'URLDragAndDrop',
|
||||
##'wxPopupWindow',
|
||||
]),
|
||||
|
||||
@ -60,7 +61,8 @@ _treeList = [
|
||||
|
||||
('Window Layout', ['wxLayoutConstraints', 'LayoutAnchors', 'Sizers', 'XML_Resource']),
|
||||
|
||||
('Miscellaneous', [ 'DragAndDrop', 'CustomDragAndDrop', 'FontEnumerator',
|
||||
('Miscellaneous', [ 'DragAndDrop', 'CustomDragAndDrop', 'URLDragAndDrop',
|
||||
'FontEnumerator',
|
||||
'wxTimer', 'wxValidator', 'wxGLCanvas', 'DialogUnits',
|
||||
'wxImage', 'wxMask', 'PrintFramework', 'wxOGL',
|
||||
'PythonEvents', 'Threads',
|
||||
|
123
wxPython/demo/URLDragAndDrop.py
Normal file
123
wxPython/demo/URLDragAndDrop.py
Normal file
@ -0,0 +1,123 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class MyURLDropTarget(wxPyDropTarget):
|
||||
def __init__(self, window):
|
||||
wxPyDropTarget.__init__(self)
|
||||
self.window = window
|
||||
|
||||
self.data = wxURLDataObject();
|
||||
self.SetDataObject(self.data)
|
||||
|
||||
def OnDragOver(self, x, y, d):
|
||||
return wxDragLink
|
||||
|
||||
def OnData(self, x, y, d):
|
||||
if not self.GetData():
|
||||
return wxDragNone
|
||||
|
||||
url = self.data.GetURL()
|
||||
self.window.AppendText(url + "\n")
|
||||
|
||||
return d
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
def __init__(self, parent, log):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
|
||||
self.SetAutoLayout(true)
|
||||
outsideSizer = wxBoxSizer(wxVERTICAL)
|
||||
|
||||
msg = "Drag-And-Drop of URLs"
|
||||
text = wxStaticText(self, -1, "", style=wxALIGN_CENTRE)
|
||||
text.SetFont(wxFont(24, wxSWISS, wxNORMAL, wxBOLD, false))
|
||||
text.SetLabel(msg)
|
||||
w,h = text.GetTextExtent(msg)
|
||||
text.SetSize(wxSize(w,h+1))
|
||||
text.SetForegroundColour(wxBLUE)
|
||||
outsideSizer.Add(text, 0, wxEXPAND|wxALL, 5)
|
||||
outsideSizer.Add(wxStaticLine(self, -1), 0, wxEXPAND)
|
||||
outsideSizer.Add(20,20)
|
||||
|
||||
self.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD, false))
|
||||
|
||||
inSizer = wxFlexGridSizer(2, 2, 5, 5)
|
||||
inSizer.AddGrowableCol(0)
|
||||
|
||||
inSizer.Add(20,20)
|
||||
inSizer.Add(20,20)
|
||||
inSizer.Add(wxStaticText(self, -1,
|
||||
"Drag URLs from your browser to\nthis window:",
|
||||
style = wxALIGN_RIGHT),
|
||||
0, wxALIGN_RIGHT )
|
||||
self.dropText = wxTextCtrl(self, -1, "", size=(380, 180),
|
||||
style=wxTE_MULTILINE|wxTE_READONLY)
|
||||
inSizer.Add(self.dropText, 0, wxEXPAND)
|
||||
|
||||
|
||||
inSizer.Add(wxStaticText(self, -1,
|
||||
"Drag this URL to your browser:",
|
||||
style = wxALIGN_RIGHT),
|
||||
0, wxALIGN_RIGHT )
|
||||
self.dragText = wxTextCtrl(self, -1, "http://wxPython.org/")
|
||||
inSizer.Add(self.dragText, 0, wxEXPAND)
|
||||
|
||||
|
||||
inSizer.Add(wxStaticText(self, -1,
|
||||
"Drag this TEXT to your browser:",
|
||||
style = wxALIGN_RIGHT),
|
||||
0, wxALIGN_RIGHT )
|
||||
self.dragText2 = wxTextCtrl(self, -1, "http://wxPython.org/")
|
||||
inSizer.Add(self.dragText2, 0, wxEXPAND)
|
||||
|
||||
|
||||
outsideSizer.Add(inSizer, 1, wxEXPAND)
|
||||
self.SetSizer(outsideSizer)
|
||||
|
||||
|
||||
self.dropText.SetDropTarget(MyURLDropTarget(self.dropText))
|
||||
|
||||
EVT_MOTION(self.dragText, self.OnStartDrag)
|
||||
EVT_MOTION(self.dragText2, self.OnStartDrag2)
|
||||
|
||||
|
||||
def OnStartDrag(self, evt):
|
||||
if evt.Dragging():
|
||||
url = self.dragText.GetValue()
|
||||
data = wxURLDataObject()
|
||||
data.SetURL(url)
|
||||
|
||||
dropSource = wxDropSource(self.dragText)
|
||||
dropSource.SetData(data)
|
||||
result = dropSource.DoDragDrop()
|
||||
|
||||
|
||||
def OnStartDrag2(self, evt):
|
||||
if evt.Dragging():
|
||||
url = self.dragText2.GetValue()
|
||||
data = wxTextDataObject()
|
||||
data.SetText(url)
|
||||
|
||||
dropSource = wxDropSource(self.dragText2)
|
||||
dropSource.SetData(data)
|
||||
result = dropSource.DoDragDrop()
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestPanel(nb, log)
|
||||
return win
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
overview = """\
|
||||
"""
|
Loading…
Reference in New Issue
Block a user