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