summaryrefslogtreecommitdiff
path: root/efl/elementary/actionslider.pyx
blob: e10c454e5444764b4bdaa1b6d7d2b405cefebce4 (plain) (blame)
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# Copyright (C) 2007-2015 various contributors (see AUTHORS)
#
# This file is part of Python-EFL.
#
# Python-EFL is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# Python-EFL is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this Python-EFL.  If not, see <http://www.gnu.org/licenses/>.
#

"""

:mod:`actionslider` Module
##########################

.. image:: /images/actionslider-preview.png


Widget description
==================

An actionslider is a switcher for two or three labels with
customizable magnet properties.

The user drags and releases the indicator, to choose a label.

Labels can occupy the following positions.

- Left
- Right
- Center

Positions can be enabled or disabled.

Magnets can be set on the above positions.

When the indicator is released, it will move to its nearest "enabled and
magnetized" position.


Emitted signals
===============

- ``selected`` - when user selects an enabled position (the label is
  passed as event info)".
- ``pos_changed`` - when the indicator reaches any of the
  positions("left", "right" or "center").


Layout text parts
=================

- ``indicator`` - An indicator label of the actionslider
- ``left`` - A left label of the actionslider
- ``right`` - A right label of the actionslider
- ``center`` - A center label of the actionslider


Enumerations
============

.. _Elm_Actionslider_Pos:

Actionslider positions
----------------------

.. data:: ELM_ACTIONSLIDER_NONE

    No position

.. data:: ELM_ACTIONSLIDER_LEFT

    Left position

.. data:: ELM_ACTIONSLIDER_CENTER

    Center position

.. data:: ELM_ACTIONSLIDER_RIGHT

    Right position

.. data:: ELM_ACTIONSLIDER_ALL

    All positions


Inheritance diagram
===================

.. inheritance-diagram:: efl.elementary.actionslider
    :parts: 2

"""

from libc.stdint cimport uintptr_t

from efl.eo cimport _object_mapping_register
from efl.utils.conversions cimport _ctouni
from efl.evas cimport Object as evasObject
from layout_class cimport LayoutClass


def _cb_string_conv(uintptr_t addr):
    cdef const char *s = <const char *>addr
    return _ctouni(s) if s is not NULL else None

cdef class Actionslider(LayoutClass):
    """

    This is the class that actually implements the widget.

    """

    def __init__(self, evasObject parent, *args, **kwargs):
        """Actionslider(..)

        :param parent: Parent object
        :type parent: :py:class:`efl.evas.Object`
        :param \**kwargs: All the remaining keyword arguments are interpreted
                          as properties of the instance

        """
        self._set_obj(elm_actionslider_add(parent.obj))
        self._set_properties_from_keyword_args(kwargs)

    property selected_label:
        """Selected label.

        :type: string

        """
        def __get__(self):
            return _ctouni(elm_actionslider_selected_label_get(self.obj))

    def selected_label_get(self):
        return _ctouni(elm_actionslider_selected_label_get(self.obj))

    property indicator_pos:
        """Indicator position.

        :type: :ref:`Elm_Actionslider_Pos`

        """
        def __get__(self):
            return elm_actionslider_indicator_pos_get(self.obj)
        def __set__(self, pos):
            elm_actionslider_indicator_pos_set(self.obj, pos)

    def indicator_pos_set(self, pos):
        elm_actionslider_indicator_pos_set(self.obj, pos)
    def indicator_pos_get(self):
        return elm_actionslider_indicator_pos_get(self.obj)

    property magnet_pos:
        """The actionslider magnet position. To make multiple positions
        magnets ``or`` them together(e.g.: ``ELM_ACTIONSLIDER_LEFT |
        ELM_ACTIONSLIDER_RIGHT``)

        :type: :ref:`Elm_Actionslider_Pos`

        """
        def __get__(self):
            return self.magnet_pos_get()
        def __set__(self, pos):
            self.magnet_pos_set(pos)

    def magnet_pos_set(self, pos):
        elm_actionslider_magnet_pos_set(self.obj, pos)
    def magnet_pos_get(self):
        return elm_actionslider_magnet_pos_get(self.obj)

    property enabled_pos:
        """The actionslider enabled position. To set multiple positions as
        enabled ``or`` them together(e.g.: ``ELM_ACTIONSLIDER_LEFT |
        ELM_ACTIONSLIDER_RIGHT``).

        .. note:: All positions are enabled by default.

        :type: :ref:`Elm_Actionslider_Pos`

        """
        def __get__(self):
            return elm_actionslider_enabled_pos_get(self.obj)
        def __set__(self, pos):
            elm_actionslider_enabled_pos_set(self.obj, pos)

    def enabled_pos_set(self, pos):
        elm_actionslider_enabled_pos_set(self.obj, pos)
    def enabled_pos_get(self):
        return elm_actionslider_enabled_pos_get(self.obj)

    def callback_selected_add(self, func, *args, **kwargs):
        """Called when user selects an enabled position. The label is passed
        as event info."""
        self._callback_add_full("selected", _cb_string_conv, func, args, kwargs)

    def callback_selected_del(self, func):
        self._callback_del_full("selected", _cb_string_conv, func)

    def callback_pos_changed_add(self, func, *args, **kwargs):
        """Called when the indicator reaches any of the positions **left**,
        **right** or **center**. The label is passed as event info."""
        self._callback_add_full("pos_changed", _cb_string_conv, func, args, kwargs)

    def callback_pos_changed_del(self, func):
        self._callback_del_full("pos_changed", _cb_string_conv, func)


_object_mapping_register("Elm_Actionslider", Actionslider)