1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
#------------------------------------------------------------------------------
# Copyright (c) 2014-2024, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
from enum import IntFlag
from atom.api import Atom, Typed, Coerced, Tuple, Int
from .application import Application
from .image import Image
from .mime_data import MimeData
class DropAction(IntFlag):
""" An enum defining the possible drop actions.
"""
#: The action is ignored.
Ignore = 0x0
#: The data is copied to the target.
Copy = 0x1
#: The data is moved from the source to the target.
Move = 0x2
#: Create a link from the source to the target.
Link = 0x4
def mime_data_factory():
""" Create a new MimeData object for a drag operation.
Returns
-------
result : MimeData
A toolkit specific mime data object.
"""
return Application.instance().create_mime_data()
class DragData(Atom):
""" An object which initialize the data for a drag operation.
"""
#: The mime data to use for the drag operation. This is created
#: automatically, but can be reassigned by the user if necessary.
mime_data = Typed(MimeData, factory=mime_data_factory)
#: The default drop action for the drag data. If not provided,
#: the toolkit will choose a suitable default from among the
#: supported action.
default_drop_action = Coerced(DropAction, (DropAction.Ignore,))
#: The supported drop actions of the drag data. This is an OR'd
#: combination of the available DropAction flags.
supported_actions = Coerced(DropAction, (DropAction.Move,))
#: The image to use for the drag. If this is not provided, the
#: toolkit will choose a suitable default value.
image = Typed(Image)
#: The x,y position the drag image appears under the cursor.
#: If not provided, this is the last position of the cursor in the widget.
hotspot = Tuple(item=Int())
class DropEvent(Atom):
""" An abstract class for defining a drag event.
Concrete implementations of this class will be created by a
toolkit backend and passed to the relevant frontend handlers.
Instances of this class will never be created by the user.
"""
def pos(self):
""" Get the current mouse position of the operation.
Returns
-------
result : Pos
The mouse position of the operation in widget coordinates.
"""
raise NotImplementedError
def mime_data(self):
""" Get the mime data contained in the drag operation.
Returns
-------
result : MimeData
The mime data contained in the drag operation.
"""
raise NotImplementedError
def drop_action(self):
""" Get the action to be performed by the drop target.
Returns
-------
result : DropAction
A drop action enum value.
"""
raise NotImplementedError
def possible_actions(self):
""" Get the OR'd combination of possible drop actions.
Returns
-------
result : DropAction
The combination of possible drop actions.
"""
raise NotImplementedError
def proposed_action(self):
""" Get the action proposed to be taken by the drop target.
Returns
-------
result : DropAction
The proposed action for the drop target.
"""
raise NotImplementedError
def accept_proposed_action(self):
""" Accept the event using the proposed drop action.
"""
raise NotImplementedError
def set_drop_action(self, action):
""" Set the drop action to one of the possible actions.
Parameters
----------
action : DropAction
The drop action to be performed by the target.
"""
raise NotImplementedError
def is_accepted(self):
""" Test whether the event has been accepted.
Returns
-------
result : bool
True if the event is accepted, False otherwise.
"""
raise NotImplementedError
def set_accepted(self, accepted):
""" Set the accepted state of the event.
Parameters
----------
accepted : bool
The target accepted state of the event.
"""
raise NotImplementedError
def accept(self):
""" Accept the current drop event action.
"""
raise NotImplementedError
def ignore(self):
""" Ignore the current drop event action.
"""
raise NotImplementedError
|