From: Robin Dunn Date: Fri, 26 Oct 2001 02:13:11 +0000 (+0000) Subject: Added URL drag and drop sample to the wxPython demo X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/846ec2f9ed25beab5015e156b4c92de8caec6a62 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 --- diff --git a/wxPython/demo/DragAndDrop.py b/wxPython/demo/DragAndDrop.py index 090c162b89..59dff7b2b7 100644 --- a/wxPython/demo/DragAndDrop.py +++ b/wxPython/demo/DragAndDrop.py @@ -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) diff --git a/wxPython/demo/Main.py b/wxPython/demo/Main.py index e0ca92f260..afd2b131c9 100644 --- a/wxPython/demo/Main.py +++ b/wxPython/demo/Main.py @@ -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', diff --git a/wxPython/demo/URLDragAndDrop.py b/wxPython/demo/URLDragAndDrop.py new file mode 100644 index 0000000000..4225a27707 --- /dev/null +++ b/wxPython/demo/URLDragAndDrop.py @@ -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 = """\ +"""