Skip to content

Commit 56a2127

Browse files
committed
Merge pull request #162 from nucleic/feature-dragdrop
Feature dragdrop
2 parents f72831f + 8c73b4c commit 56a2127

File tree

9 files changed

+913
-13
lines changed

9 files changed

+913
-13
lines changed

enaml/application.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2013, Nucleic Development Team.
2+
# Copyright (c) 2014, Nucleic Development Team.
33
#
44
# Distributed under the terms of the Modified BSD License.
55
#
@@ -308,6 +308,17 @@ def is_main_thread(self):
308308
"""
309309
raise NotImplementedError
310310

311+
def create_mime_data(self):
312+
""" Create a new mime data object to be filled by the user.
313+
314+
Returns
315+
-------
316+
result : MimeData
317+
A concrete implementation of the MimeData class.
318+
319+
"""
320+
raise NotImplementedError
321+
311322
#--------------------------------------------------------------------------
312323
# Public API
313324
#--------------------------------------------------------------------------

enaml/drag_drop.py

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
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

enaml/mime_data.py

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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
9+
10+
11+
class MimeData(Atom):
12+
""" An abstract class for defining mime data.
13+
14+
Concrete implementations of this class will be created by a
15+
toolkit backend and passed to the relevant frontend methods.
16+
17+
This will never be instantiated directly by user code. A concrete
18+
version can be created by calling the `create_mime_data` factory
19+
method of an Application instance.
20+
21+
"""
22+
def formats(self):
23+
""" Get a list of the supported mime type formats.
24+
25+
Returns
26+
-------
27+
result : list
28+
A list of mime types supported by the data.
29+
30+
"""
31+
raise NotImplementedError
32+
33+
def has_format(self, mime_type):
34+
""" Test whether the data supports the given mime type.
35+
36+
Parameters
37+
----------
38+
mime_type : unicode
39+
The mime type of interest.
40+
41+
Returns
42+
-------
43+
result : bool
44+
True if there is data for the given type, False otherwise.
45+
46+
"""
47+
raise NotImplementedError
48+
49+
def remove_format(self, mime_type):
50+
""" Remove the data entry for the given mime type.
51+
52+
Parameters
53+
----------
54+
mime_type : unicode
55+
The mime type of interest.
56+
57+
"""
58+
raise NotImplementedError
59+
60+
def data(self, mime_type):
61+
""" Get the data for the specified mime type.
62+
63+
Parameters
64+
----------
65+
mime_type : unicode
66+
The mime type of interest.
67+
68+
Returns
69+
-------
70+
result : str
71+
The data for the specified mime type.
72+
73+
"""
74+
raise NotImplementedError
75+
76+
def set_data(self, mime_type, data):
77+
""" Set the data for the specified mime type.
78+
79+
Parameters
80+
----------
81+
mime_type : unicode
82+
The mime type of interest.
83+
84+
data : str
85+
The serialized data for the given type.
86+
87+
"""
88+
raise NotImplementedError

enaml/qt/qt_application.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2013, Nucleic Development Team.
2+
# Copyright (c) 2014, Nucleic Development Team.
33
#
44
# Distributed under the terms of the Modified BSD License.
55
#
@@ -14,6 +14,7 @@
1414

1515
from .q_deferred_caller import deferredCall, timedCall
1616
from .qt_factories import QT_FACTORIES
17+
from .qt_mime_data import QtMimeData
1718

1819

1920
class QtApplication(Application):
@@ -101,3 +102,14 @@ def is_main_thread(self):
101102
102103
"""
103104
return QThread.currentThread() == self._qapp.thread()
105+
106+
def create_mime_data(self):
107+
""" Create a new mime data object to be filled by the user.
108+
109+
Returns
110+
-------
111+
result : QtMimeData
112+
A concrete implementation of the MimeData class.
113+
114+
"""
115+
return QtMimeData()

0 commit comments

Comments
 (0)