Skip to content

Commit 6cdff7d

Browse files
committed
doc: extracted module docs, simplified example in uix/behaviors/drag.py
And made the example runnable.
1 parent 2c1729e commit 6cdff7d

File tree

1 file changed

+53
-24
lines changed

1 file changed

+53
-24
lines changed

kivy/uix/behaviors/drag.py

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,50 @@
1-
'''See :class:`DragBehavior` for details.
2-
'''
1+
"""
2+
Drag Behavior
3+
=============
4+
5+
The :class:`~kivy.uix.behaviors.drag.DragBehavior`
6+
`mixin <https://en.wikipedia.org/wiki/Mixin>`_ class provides Drag behavior.
7+
When combined with a widget, dragging in the rectangle defined by the
8+
:attr:`~kivy.uix.behaviors.drag.DragBehavior.drag_rectangle` will drag the
9+
widget.
10+
11+
Example
12+
-------
13+
14+
The following example creates a draggable label::
15+
16+
from kivy.uix.label import Label
17+
from kivy.app import App
18+
from kivy.uix.behaviors import DragBehavior
19+
from kivy.lang import Builder
20+
21+
# You could also put the following in your kv file...
22+
kv = '''
23+
<DragLabel>:
24+
# Define the properties for the DragLabel
25+
drag_rectangle: self.x, self.y, self.width, self.height
26+
drag_timeout: 10000000
27+
drag_distance: 0
28+
29+
FloatLayout:
30+
# Define the root widget
31+
DragLabel:
32+
size_hint: 0.25, 0.2
33+
text: 'Drag me'
34+
'''
35+
36+
37+
class DragLabel(DragBehavior, Label):
38+
pass
39+
40+
41+
class TestApp(App):
42+
def build(self):
43+
return Builder.load_string(kv)
44+
45+
TestApp().run()
46+
47+
"""
348

449
__all__ = ('DragBehavior', )
550

@@ -18,28 +63,12 @@
1863

1964

2065
class DragBehavior(object):
21-
'''This `mixin <https://en.wikipedia.org/wiki/Mixin>`_ class
22-
provides Drag behavior. When combined with a widget,
23-
dragging in the rectangle defined by :attr:`drag_rectangle` will drag the
24-
widget.
25-
26-
For example, to make a popup which is draggable by its title do::
27-
28-
from kivy.uix.behaviors import DragBehavior
29-
from kivy.uix.popup import Popup
30-
31-
class DragPopup(DragBehavior, Popup):
32-
pass
33-
34-
And in .kv do:
35-
36-
.. code-block:: kv
37-
38-
<DragPopup>:
39-
drag_rectangle: self.x, self.y+self._container.height, self.width,\
40-
self.height - self._container.height
41-
drag_timeout: 10000000
42-
drag_distance: 0
66+
'''
67+
The DragBehavior `mixin <https://en.wikipedia.org/wiki/Mixin>`_ provides
68+
Drag behavior. When combined with a widget, dragging in the rectangle
69+
defined by :attr:`drag_rectangle` will drag the widget. Please see
70+
the :mod:`drag behaviors module <kivy.uix.behaviors.drag>` documentation
71+
for more information.
4372
4473
.. versionadded:: 1.8.0
4574
'''

0 commit comments

Comments
 (0)