summaryrefslogtreecommitdiff
path: root/efl/elementary/efl.elementary_list.pxi
blob: bb679edf7272755f84b285c1a69b839655064fa6 (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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# Copyright (C) 2007-2013 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 2.1 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/>.


cdef enum Elm_List_Item_Insert_Kind:
    ELM_LIST_ITEM_INSERT_APPEND
    ELM_LIST_ITEM_INSERT_PREPEND
    ELM_LIST_ITEM_INSERT_BEFORE
    ELM_LIST_ITEM_INSERT_AFTER
    ELM_LIST_ITEM_INSERT_SORTED

cdef class ListItem(ObjectItem):

    def __init__(self, kind, evasObject list, label, evasObject icon = None,
                 evasObject end = None, ListItem before_after = None,
                 callback = None, *args, **kargs):

        cdef Evas_Object* icon_obj = NULL
        cdef Evas_Object* end_obj = NULL
        cdef Evas_Smart_Cb cb = NULL

        if icon is not None:
            icon_obj = icon.obj
        if end is not None:
            end_obj = end.obj

        if callback is not None:
            if not callable(callback):
                raise TypeError("callback is not callable")
            cb = _object_item_callback

        self.params = (callback, args, kargs)

        if kind == ELM_LIST_ITEM_INSERT_APPEND:
            item = elm_list_item_append(   list.obj,
                                            _cfruni(label),
                                            icon_obj,
                                            end_obj,
                                            cb,
                                            <void*>self)

        elif kind == ELM_LIST_ITEM_INSERT_PREPEND:
            item = elm_list_item_prepend(  list.obj,
                                            _cfruni(label),
                                            icon_obj,
                                            end_obj,
                                            cb,
                                            <void*>self)

        #elif kind == ELM_LIST_ITEM_INSERT_SORTED:
            #item = elm_list_item_sorted_insert(   list.obj,
                                                    #_cfruni(label),
                                                    #icon_obj,
                                                    #end_obj,
                                                    #cb,
                                                    #<void*>self,
                                                    #cmp_f)

        else:
            if before_after == None:
                raise ValueError("need a valid after object to add an item before/after another item")

            if kind == ELM_LIST_ITEM_INSERT_BEFORE:
                item = elm_list_item_insert_before(list.obj,
                                                    before_after.item,
                                                    _cfruni(label),
                                                    icon_obj,
                                                    end_obj,
                                                    cb,
                                                    <void*>self)

            else:
                item = elm_list_item_insert_after( list.obj,
                                                    before_after.item,
                                                    _cfruni(label),
                                                    icon_obj,
                                                    end_obj,
                                                    cb,
                                                    <void*>self)
        if item != NULL:
            self._set_obj(item)
        else:
            Py_DECREF(self)

    def __str__(self):
        return ("%s(label=%r, icon=%s, end=%s, "
                "callback=%r, args=%r, kargs=%s)") % \
            (self.__class__.__name__, self.text_get(), bool(self.part_content_get("icon")),
             bool(self.part_content_get("end")), self.params[0], self.params[1], self.params[2])

    def __repr__(self):
        return ("%s(%#x, refcount=%d, Elm_Object_Item=%#x, "
                "label=%r, icon=%s, end=%s, "
                "callback=%r, args=%r, kargs=%s)") % \
            (self.__class__.__name__, <unsigned long><void *>self,
             PY_REFCOUNT(self), <unsigned long><void *>self.item,
             self.text_get(), bool(self.part_content_get("icon")),
             bool(self.part_content_get("end")), self.params[0], self.params[1], self.params[2])

    def selected_set(self, selected):
        elm_list_item_selected_set(self.item, selected)

    def selected_get(self):
        return bool(elm_list_item_selected_get(self.item))

    property selected:
        def __get__(self):
            return bool(elm_list_item_selected_get(self.item))

        def __set__(self, selected):
            elm_list_item_selected_set(self.item, selected)

    def separator_set(self, separator):
        elm_list_item_separator_set(self.item, separator)

    def separator_get(self):
        return bool(elm_list_item_separator_get(self.item))

    property separator:
        def __get__(self):
            return bool(elm_list_item_separator_get(self.item))

        def __set__(self, separator):
            elm_list_item_separator_set(self.item, separator)

    def show(self):
        elm_list_item_show(self.item)

    def bring_in(self):
        elm_list_item_bring_in(self.item)

    def object_get(self):
        return object_from_instance(elm_list_item_object_get(self.item))

    property object:
        def __get__(self):
            return object_from_instance(elm_list_item_object_get(self.item))

    def prev_get(self):
        return _object_item_to_python(elm_list_item_prev(self.item))

    property prev:
        def __get__(self):
            return _object_item_to_python(elm_list_item_prev(self.item))

    def next_get(self):
        return _object_item_to_python(elm_list_item_next(self.item))

    property next:
        def __get__(self):
            return _object_item_to_python(elm_list_item_next(self.item))

cdef class List(Object):

    def __init__(self, evasObject parent):
        self._set_obj(elm_list_add(parent.obj))

    def go(self):
        elm_list_go(self.obj)

    def multi_select_set(self, multi):
        elm_list_multi_select_set(self.obj, multi)

    def multi_select_get(self):
        return bool(elm_list_multi_select_get(self.obj))

    property multi_select:
        def __get__(self):
            return elm_list_multi_select_get(self.obj)

        def __set__(self, multi):
            elm_list_multi_select_set(self.obj, multi)

    def mode_set(self, Elm_List_Mode mode):
        elm_list_mode_set(self.obj, mode)

    def mode_get(self):
        return elm_list_mode_get(self.obj)

    property mode:
        def __get__(self):
            return elm_list_mode_get(self.obj)

        def __set__(self, Elm_List_Mode mode):
            elm_list_mode_set(self.obj, mode)

    property horizontal:
        def __get__(self):
            return elm_list_horizontal_get(self.obj)

        def __set__(self, horizontal):
            elm_list_horizontal_set(self.obj, horizontal)

    def select_mode_set(self, mode):
        elm_list_select_mode_set(self.obj, mode)

    def select_mode_get(self):
        return elm_list_select_mode_get(self.obj)

    property select_mode:
        def __set__(self, mode):
            elm_list_select_mode_set(self.obj, mode)

        def __get__(self):
            return elm_list_select_mode_get(self.obj)

    def bounce_set(self, h, v):
        elm_scroller_bounce_set(self.obj, h, v)

    def bounce_get(self):
        cdef Eina_Bool h, v
        elm_scroller_bounce_get(self.obj, &h, &v)
        return (h, v)

    property bounce:
        def __set__(self, value):
            h, v = value
            elm_scroller_bounce_set(self.obj, h, v)

    def scroller_policy_set(self, policy_h, policy_v):
        elm_scroller_policy_set(self.obj, policy_h, policy_v)

    def scroller_policy_get(self):
        cdef Elm_Scroller_Policy policy_h, policy_v
        elm_scroller_policy_get(self.obj, &policy_h, &policy_v)
        return (policy_h, policy_v)

    property scroller_policy:
        def __set__(self, value):
            policy_h, policy_v = value
            elm_scroller_policy_set(self.obj, policy_h, policy_v)

        def __get__(self):
            cdef Elm_Scroller_Policy policy_h, policy_v
            elm_scroller_policy_get(self.obj, &policy_h, &policy_v)
            return (policy_h, policy_v)

    def item_append(self, label, evasObject icon = None,
                    evasObject end = None, callback = None, *args, **kargs):
        return ListItem(ELM_LIST_ITEM_INSERT_APPEND, self, label, icon, end,
                        None, callback, *args, **kargs)

    def item_prepend(self, label, evasObject icon = None,
                    evasObject end = None, callback = None, *args, **kargs):
        return ListItem(ELM_LIST_ITEM_INSERT_PREPEND, self, label, icon, end,
                        None, callback, *args, **kargs)

    def item_insert_before(self, ListItem before, label, evasObject icon = None,
                    evasObject end = None, callback = None, *args, **kargs):
        return ListItem(ELM_LIST_ITEM_INSERT_BEFORE, self, label, icon, end,
                        before, callback, *args, **kargs)

    def item_insert_after(self, ListItem after, label, evasObject icon = None,
                    evasObject end = None, callback = None, *args, **kargs):
        return ListItem(ELM_LIST_ITEM_INSERT_AFTER, self, label, icon, end,
                        after, callback, *args, **kargs)

    #def item_sorted_insert(self, label, evasObject icon = None,
                    #evasObject end = None, callback = None, cmp_func=None, *args, **kargs):
        #return ListItem(ELM_LIST_ITEM_INSERT_SORTED, self, label, icon, end,
                        #None, callback, *args, **kargs)

    def clear(self):
        elm_list_clear(self.obj)

    def items_get(self):
        return _object_item_list_to_python(elm_list_items_get(self.obj))

    property items:
        def __get__(self):
            return _object_item_list_to_python(elm_list_items_get(self.obj))

    def selected_item_get(self):
        return _object_item_to_python(elm_list_selected_item_get(self.obj))

    property selected_item:
        def __get__(self):
            return _object_item_to_python(elm_list_selected_item_get(self.obj))

    def selected_items_get(self):
        return _object_item_list_to_python(elm_list_selected_items_get(self.obj))

    property selected_items:
        def __get__(self):
            return _object_item_list_to_python(elm_list_selected_items_get(self.obj))

    def first_item_get(self):
        return _object_item_to_python(elm_list_first_item_get(self.obj))

    property first_item:
        def __get__(self):
            return _object_item_to_python(elm_list_first_item_get(self.obj))

    def last_item_get(self):
        return _object_item_to_python(elm_list_last_item_get(self.obj))

    property last_item:
        def __get__(self):
            return _object_item_to_python(elm_list_last_item_get(self.obj))

    def callback_activated_add(self, func, *args, **kwargs):
        self._callback_add_full("activated", _cb_object_item_conv,
                                func, *args, **kwargs)

    def callback_activated_del(self, func):
        self._callback_del_full("activated",  _cb_object_item_conv, func)

    def callback_clicked_double_add(self, func, *args, **kwargs):
        self._callback_add_full("clicked,double", _cb_object_item_conv,
                                func, *args, **kwargs)

    def callback_clicked_double_del(self, func):
        self._callback_del_full("clicked,double",  _cb_object_item_conv, func)

    def callback_selected_add(self, func, *args, **kwargs):
        self._callback_add_full("selected", _cb_object_item_conv,
                                func, *args, **kwargs)

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

    def callback_unselected_add(self, func, *args, **kwargs):
        self._callback_add_full("unselected", _cb_object_item_conv,
                                func, *args, **kwargs)

    def callback_unselected_del(self, func):
        self._callback_del_full("unselected", _cb_object_item_conv, func)

    def callback_longpressed_add(self, func, *args, **kwargs):
        self._callback_add_full("longpressed", _cb_object_item_conv,
                                func, *args, **kwargs)

    def callback_longpressed_del(self, func):
        self._callback_del_full("longpressed", _cb_object_item_conv, func)

    def callback_edge_top_add(self, func, *args, **kwargs):
        self._callback_add("edge,top", func, *args, **kwargs)

    def callback_edge_top_del(self, func):
        self._callback_del("edge,top",  func)

    def callback_edge_bottom_add(self, func, *args, **kwargs):
        self._callback_add("edge,bottom", func, *args, **kwargs)

    def callback_edge_bottom_del(self, func):
        self._callback_del("edge,bottom",  func)

    def callback_edge_left_add(self, func, *args, **kwargs):
        self._callback_add("edge,left", func, *args, **kwargs)

    def callback_edge_left_del(self, func):
        self._callback_del("edge,left",  func)

    def callback_edge_right_add(self, func, *args, **kwargs):
        self._callback_add("edge,right", func, *args, **kwargs)

    def callback_edge_right_del(self, func):
        self._callback_del("edge,right",  func)

    def callback_language_changed_add(self, func, *args, **kwargs):
        self._callback_add("language,changed", func, *args, **kwargs)

    def callback_language_changed_del(self, func):
        self._callback_del("language,changed",  func)


_object_mapping_register("elm_list", List)