|
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 | +""" |
3 | 48 |
|
4 | 49 | __all__ = ('DragBehavior', )
|
5 | 50 |
|
|
18 | 63 |
|
19 | 64 |
|
20 | 65 | 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. |
43 | 72 |
|
44 | 73 | .. versionadded:: 1.8.0
|
45 | 74 | '''
|
|
0 commit comments