summaryrefslogtreecommitdiff
path: root/efl/elementary/efl.elementary_toolbar.pxi
blob: 96ac2f7eafa60d8d5ac2bda714d201f915b19f2b (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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# Copyright (c) 2008-2009 Simon Busch
#
# 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 class ToolbarItemState(object):

    cdef Elm_Toolbar_Item_State *obj
    cdef object params

    def __init__(self, ObjectItem it, icon = None, label = None, callback = None, *args, **kwargs):
        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, kwargs)

        self.obj = elm_toolbar_item_state_add(it.item, _cfruni(icon), _cfruni(label), cb, <void*>self)
        if self.obj == NULL:
            Py_DECREF(self)


cdef class ToolbarItem(ObjectItem):

    def __init__(self, evasObject toolbar, icon, label,
                 callback, *args, **kargs):
        cdef Evas_Object *ic = NULL
        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)

        item = elm_toolbar_item_append(toolbar.obj, icon, _cfruni(label), cb, <void*>self)

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

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

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

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

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

    def priority_set(self, priority):
        elm_toolbar_item_priority_set(self.item, priority)

    def priority_get(self):
        return elm_toolbar_item_priority_get(self.item)

    property priority:
        def __get__(self):
            return elm_toolbar_item_priority_get(self.item)

        def __set__(self, priority):
            elm_toolbar_item_priority_set(self.item, priority)

    def selected_get(self):
        return elm_toolbar_item_selected_get(self.item)

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

    property selected:
        def __set__(self, selected):
            elm_toolbar_item_selected_set(self.item, selected)

        def __get__(self):
            return elm_toolbar_item_selected_get(self.item)

    def icon_set(self, ic):
        elm_toolbar_item_icon_set(self.item, _cfruni(ic))

    def icon_get(self):
        return _ctouni(elm_toolbar_item_icon_get(self.item))

    property icon:
        def __get__(self):
            return _ctouni(elm_toolbar_item_icon_get(self.item))

        def __set__(self, ic):
            elm_toolbar_item_icon_set(self.item, _cfruni(ic))

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

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

    def icon_object_get(self):
        return object_from_instance(elm_toolbar_item_icon_object_get(self.item))

    property icon_object:
        def __get__(self):
            return object_from_instance(elm_toolbar_item_icon_object_get(self.item))

    def icon_memfile_set(self, img, size, format, key):
        return False
        #TODO: return bool(elm_toolbar_item_icon_memfile_set(self.item, img, size, format, key))

    def icon_file_set(self, file, key):
        return bool(elm_toolbar_item_icon_file_set(self.item, _cfruni(file), _cfruni(key)))

    property icon_file:
        def __set__(self, value):
            if isinstance(value, tuple):
                file, key = value
            else:
                file = value
                key = None
            # TODO: check return status
            elm_toolbar_item_icon_file_set(self.item, _cfruni(file), _cfruni(key))

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

    def separator_get(self):
        return elm_toolbar_item_separator_get(self.item)

    property separator:
        def __set__(self, separator):
            elm_toolbar_item_separator_set(self.item, separator)

        def __get__(self):
            return elm_toolbar_item_separator_get(self.item)

    def menu_set(self, menu):
        elm_toolbar_item_menu_set(self.item, menu)

    def menu_get(self):
        cdef Evas_Object *menu
        menu = elm_toolbar_item_menu_get(self.item)
        if menu == NULL:
            return None
        else:
            return Menu(None, <object>menu)

    property menu:
        def __get__(self):
            cdef Evas_Object *menu
            menu = elm_toolbar_item_menu_get(self.item)
            if menu == NULL:
                return None
            else:
                return Menu(None, <object>menu)

        def __set__(self, menu):
            elm_toolbar_item_menu_set(self.item, menu)

    def state_add(self, icon = None, label = None, func = None, *args, **kwargs):
        return ToolbarItemState(self, icon, label, func, *args, **kwargs)

    def state_del(self, ToolbarItemState state):
        return bool(elm_toolbar_item_state_del(self.item, state.obj))

    property state:
        def __set__(self, ToolbarItemState state):
            # TODO: check return value bool for errors
            elm_toolbar_item_state_set(self.item, state.obj)

        def __del__(self):
            elm_toolbar_item_state_unset(self.item)

        def __get__(self):
            return None
            # TODO: C api doesn't have data_get() for states so we can't get
            #       the py object from there. Store it in the item instead?
            #elm_toolbar_item_state_get(self.item)

    property state_next:
        def __get__(self):
            return None
            # TODO: keep a list of the states?
            #return elm_toolbar_item_state_next(self.item)

    property state_prev:
        def __get__(self):
            return None
            # TODO: keep a list of the states?
            #return elm_toolbar_item_state_prev(self.item)


cdef class Toolbar(Object):

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

    def icon_size_set(self, icon_size):
        elm_toolbar_icon_size_set(self.obj, icon_size)

    def icon_size_get(self):
        return elm_toolbar_icon_size_get(self.obj)

    property icon_size:
        def __set__(self, icon_size):
            elm_toolbar_icon_size_set(self.obj, icon_size)

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

    def icon_order_lookup_set(self, order):
        elm_toolbar_icon_order_lookup_set(self.obj, order)

    def icon_order_lookup_get(self):
        return elm_toolbar_icon_order_lookup_get(self.obj)

    property icon_order_lookup:
        def __set__(self, order):
            elm_toolbar_icon_order_lookup_set(self.obj, order)

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

    def item_append(self, icon, label, callback = None, *args, **kargs):
        # Everything is done in the ToolbarItem class, because of wrapping the
        # C structures in python classes
        return ToolbarItem(self, icon, label, callback, *args, **kargs)

    #TODO: def item_prepend(self, icon, label, callback = None, *args, **kargs):
        #return ToolbarItem(self, icon, label, callback, *args, **kargs)

    #TODO: def item_insert_before(self, before, icon, label, callback = None, *args, **kargs):
        #return ToolbarItem(self, icon, label, callback, *args, **kargs)

    #TODO: def item_insert_after(self, after, icon, label, callback = None, *args, **kargs):
        #return ToolbarItem(self, icon, label, callback, *args, **kargs)

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

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

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

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

    def item_find_by_label(self, label):
        return _object_item_to_python(elm_toolbar_item_find_by_label(self.obj, _cfruni(label)))

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

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

    def more_item_get(self):
        return _object_item_to_python(elm_toolbar_more_item_get(self.obj))

    property more_item:
        def __get__(self):
            return _object_item_to_python(elm_toolbar_more_item_get(self.obj))

    def shrink_mode_set(self, mode):
        elm_toolbar_shrink_mode_set(self.obj, mode)

    def shrink_mode_get(self):
        return elm_toolbar_shrink_mode_get(self.obj)

    property shrink_mode:
        def __get__(self):
            return elm_toolbar_shrink_mode_get(self.obj)

        def __set__(self, mode):
            elm_toolbar_shrink_mode_set(self.obj, mode)

    def homogeneous_set(self, homogeneous):
        elm_toolbar_homogeneous_set(self.obj, homogeneous)

    def homogeneous_get(self):
        return elm_toolbar_homogeneous_get(self.obj)

    property homogeneous:
        def __set__(self, homogeneous):
            elm_toolbar_homogeneous_set(self.obj, homogeneous)

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

    def menu_parent_set(self, evasObject parent):
        elm_toolbar_menu_parent_set(self.obj, parent.obj)

    def menu_parent_get(self):
        return object_from_instance(elm_toolbar_menu_parent_get(self.obj))

    property menu_parent:
        def __get__(self):
            return object_from_instance(elm_toolbar_menu_parent_get(self.obj))

        def __set__(self, evasObject parent):
            elm_toolbar_menu_parent_set(self.obj, parent.obj)

    def align_set(self, align):
        elm_toolbar_align_set(self.obj, align)

    def align_get(self):
        return elm_toolbar_align_get(self.obj)

    property align:
        def __set__(self, align):
            elm_toolbar_align_set(self.obj, align)

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

    def horizontal_set(self, horizontal):
        elm_toolbar_horizontal_set(self.obj, horizontal)

    def horizontal_get(self):
        return elm_toolbar_horizontal_get(self.obj)

    property horizontal:
        def __set__(self, horizontal):
            elm_toolbar_horizontal_set(self.obj, horizontal)

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

    def items_count(self):
        return elm_toolbar_items_count(self.obj)

    property standard_priority:
        def __set__(self, priority):
            elm_toolbar_standard_priority_set(self.obj, priority)
        def __get__(self):
            return elm_toolbar_standard_priority_get(self.obj)

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

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

    property select_mode:
        def __get__(self):
            return elm_toolbar_select_mode_get(self.obj)

        def __set__(self, mode):
            elm_toolbar_select_mode_set(self.obj, mode)

    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_longpressed_add(self, func, *args, **kwargs):
        self._callback_add("longpressed", func, *args, **kwargs)

    def callback_longpressed_del(self, func):
        self._callback_del("longpressed", 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_toolbar", Toolbar)