summaryrefslogtreecommitdiff
path: root/efl/elementary/efl.elementary_multibuttonentry.pxi
blob: eb6d7a19a16b500068290626ac1b9c9bae0c53dd (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
# Copyright (c)  2012 Davide Andreoli <dave@gurumeditation.it>
#
# This file is part of python-elementary.
#
# python-elementary 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-elementary 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 python-elementary.  If not, see <http://www.gnu.org/licenses/>.
#

cdef Eina_Bool _multibuttonentry_filter_callback(Evas_Object *obj, const_char_ptr item_label, void *item_data, void *data) with gil:
    try:
        (mbe, callback, a, ka) = <object>data
        ret = callback(mbe, item_label, *a, **ka)
        if isinstance(ret, str):
            # TODO this is BROKEN! the doc say should work, but it's a const char*  :/
            # free(<void*>item_label)
            # item_label = strdup(ret)
            return 1
        elif ret:
            return 1
        else:
            return 0
    except Exception, e:
        traceback.print_exc()

cdef enum Elm_MultiButtonEntry_Item_Insert_Kind:
    ELM_MULTIBUTTONENTRY_INSERT_APPEND
    ELM_MULTIBUTTONENTRY_INSERT_PREPEND
    ELM_MULTIBUTTONENTRY_INSERT_BEFORE
    ELM_MULTIBUTTONENTRY_INSERT_AFTER


cdef class MultiButtonEntryItem(ObjectItem):

    def __init__(self, kind, evasObject mbe, label,
                       MultiButtonEntryItem before_after = None,
                       callback = None, *args, **kargs):
        cdef Evas_Smart_Cb cb = NULL

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

        self.params = (callback, args, kargs)

        if kind == ELM_MULTIBUTTONENTRY_INSERT_PREPEND:
            item = elm_multibuttonentry_item_prepend(mbe.obj,
                                                    _cfruni(label), cb, <void*>self)
        elif kind == ELM_MULTIBUTTONENTRY_INSERT_APPEND:
            item = elm_multibuttonentry_item_append(mbe.obj,
                                                    _cfruni(label), cb, <void*>self)
        elif kind == ELM_MULTIBUTTONENTRY_INSERT_BEFORE:
            item = elm_multibuttonentry_item_insert_before(mbe.obj,
                                 before_after.item, _cfruni(label), cb, <void*>self)
        elif kind == ELM_MULTIBUTTONENTRY_INSERT_AFTER:
            item = elm_multibuttonentry_item_insert_after(mbe.obj,
                                 before_after.item, _cfruni(label), cb, <void*>self)

        if item != NULL:
            self._set_obj(item)
        else:
            Py_DECREF(self)

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

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

    def selected_set(self, selected):
        elm_multibuttonentry_item_selected_set(self.item, bool(selected))

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

    property selected:
        def __get__(self):
            return self.selected_get()
        def __set__(self, value):
            self.selected_set(value)

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

    property prev:
        def __get__(self):
            return self.prev_get()

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

    property next:
        def __get__(self):
            return self.next_get()


cdef class MultiButtonEntry(Object):

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

    def entry_get(self):
        return object_from_instance(elm_multibuttonentry_entry_get(self.obj))

    property entry:
        def __get__(self):
            return self.entry_get()

    def expanded_set(self, enabled):
        elm_multibuttonentry_expanded_set(self.obj, bool(enabled))

    def expanded_get(self):
        return bool(elm_multibuttonentry_expanded_get(self.obj))

    property expanded:
        def __get__(self):
            return self.expanded_get()
        def __set__(self, value):
            self.expanded_set(value)

    def item_prepend(self, label, func = None, *args, **kwargs):
        return MultiButtonEntryItem(ELM_MULTIBUTTONENTRY_INSERT_PREPEND,
                                    self, label, None, func, *args, **kwargs)

    def item_append(self, label, func = None, *args, **kwargs):
        return MultiButtonEntryItem(ELM_MULTIBUTTONENTRY_INSERT_APPEND,
                                    self, label, None, func, *args, **kwargs)

    def item_insert_before(self, MultiButtonEntryItem before, label, func = None, *args, **kwargs):
        return MultiButtonEntryItem(ELM_MULTIBUTTONENTRY_INSERT_BEFORE,
                                    self, label, before, func, *args, **kwargs)

    def item_insert_after(self, MultiButtonEntryItem after, label, func = None, *args, **kwargs):
        return MultiButtonEntryItem(ELM_MULTIBUTTONENTRY_INSERT_AFTER,
                                    self, label, after, func, *args, **kwargs)

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

    property items:
        def __get__(self):
            return self.items_get()

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

    property first_item:
        def __get__(self):
            return self.first_item_get()

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

    property last_item:
        def __get__(self):
            return self.last_item_get()

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

    property selected_item:
        def __get__(self):
            return self.selected_item_get()

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

    def filter_append(self, func, *args, **kwargs):
        cbdata = (self, func, args, kwargs)
        elm_multibuttonentry_item_filter_append(self.obj,
                            _multibuttonentry_filter_callback, <void *>cbdata)
        Py_INCREF(cbdata)

    def filter_prepend(self, func, *args, **kwargs):
        cbdata = (self, func, args, kwargs)
        elm_multibuttonentry_item_filter_prepend(self.obj,
                            _multibuttonentry_filter_callback, <void *>cbdata)
        Py_INCREF(cbdata)

    def filter_remove(self, func, *args, **kwargs):
        #TODO
        pass

    def callback_item_selected_add(self, func, *args, **kwargs):
        self._callback_add("item,selected", func, *args, **kwargs)

    def callback_item_selected_del(self, func):
        self._callback_del("item,selected", func)

    def callback_item_added_add(self, func, *args, **kwargs):
        self._callback_add("item,added", func, *args, **kwargs)

    def callback_item_added_del(self, func):
        self._callback_del("item,added", func)

    def callback_item_deleted_add(self, func, *args, **kwargs):
        self._callback_add("item,deleted", func, *args, **kwargs)

    def callback_item_deleted_del(self, func):
        self._callback_del("item,deleted", func)

    def callback_item_clicked_add(self, func, *args, **kwargs):
        self._callback_add("item,clicked", func, *args, **kwargs)

    def callback_item_clicked_del(self, func):
        self._callback_del("item,clicked", func)

    def callback_clicked_add(self, func, *args, **kwargs):
        self._callback_add("clicked", func, *args, **kwargs)

    def callback_clicked_del(self, func):
        self._callback_del("clicked", func)

    def callback_focused_add(self, func, *args, **kwargs):
        self._callback_add("focused", func, *args, **kwargs)

    def callback_focused_del(self, func):
        self._callback_del("focused", func)

    def callback_unfocused_add(self, func, *args, **kwargs):
        self._callback_add("unfocused", func, *args, **kwargs)

    def callback_unfocused_del(self, func):
        self._callback_del("unfocused", func)

    def callback_expanded_add(self, func, *args, **kwargs):
        self._callback_add("expanded", func, *args, **kwargs)

    def callback_expanded_del(self, func):
        self._callback_del("expanded", func)

    def callback_contracted_add(self, func, *args, **kwargs):
        self._callback_add("contracted", func, *args, **kwargs)

    def callback_contracted_del(self, func):
        self._callback_del("contracted", func)

    def callback_expand_state_changed_add(self, func, *args, **kwargs):
        self._callback_add("expand,state,changed", func, *args, **kwargs)

    def callback_expand_state_changed_del(self, func):
        self._callback_del("expand,state,changed", func)


_object_mapping_register("elm_multibuttonentry", MultiButtonEntry)