Skip to content

Commit

Permalink
Add base tool to facilitate drag and drop support.
Browse files Browse the repository at this point in the history
  • Loading branch information
corranwebster committed Aug 22, 2014
1 parent 267d7f3 commit 757b820
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions enable/tools/drop_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#------------------------------------------------------------------------------
# Copyright (c) 2014, Enthought, Inc.
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only
# under the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
# Thanks for using Enthought open source!
#------------------------------------------------------------------------------
""" Abstract base class for tools that handle drag and drop """

from __future__ import absolute_import, print_function, division

from enable.base_tool import BaseTool


class BaseDropTool(BaseTool):
""" Abstract base class for tools that handle drag and drop """

def normal_drag_over(self, event):
""" Handle dragging over the component """
try:
result = self.accepts_drop(event.obj)
self.component.window.set_drag_result(result)
except Exception:
self.component.window.set_drag_result("error")
raise

def normal_dropped_on(self, event):
if self.accepts_drop(event.obj) != "none":
self.handle_drop(event.obj)

def accepts_drop(self, urls):
""" Whether or not to accept the drag, and the type of drag
The return value is either "none", if the drag is refused for the
dragged object types, or one of "copy", "move", or "link".
Subclasses should override this method.
"""
raise NotImplementedError

def handle_drop(self, urls):
""" Handle objects being dropped on the component
Subclasses should override this method.
"""
raise NotImplementedError

0 comments on commit 757b820

Please sign in to comment.