summaryrefslogtreecommitdiff
path: root/efl/elementary/toolbar.pyx
blob: 03a68293dae0561f8d2dee23b5082140a4f3fc1e (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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
# Copyright (C) 2007-2014 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 python-elementary.  If not, see <http://www.gnu.org/licenses/>.
#

"""

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

Widget description
------------------

A toolbar is a widget that displays a list of items inside a box. It
can be scrollable, show a menu with items that don't fit to toolbar size
or even crop them.

Only one item can be selected at a time.

Items can have multiple states, or show menus when selected by the user.

Smart callbacks one can listen to:

- ``clicked`` - when the user clicks on a toolbar item and becomes selected.
- ``longpressed`` - when the toolbar is pressed for a certain amount of time.
- ``language,changed`` - when the program language changes.
- ``focused`` - When the toolbar has received focus. (since 1.8)
- ``unfocused`` - When the toolbar has lost focus. (since 1.8)
- ``item,focused`` - When the toolbar item has received focus. (since 1.10)
- ``item,unfocused`` - When the toolbar item has lost focus. (since 1.10)

Available styles for it:

- ``default``
- ``transparent`` - no background or shadow, just show the content

Default text parts of the toolbar items that you can use for are:

- ``default`` - label of the toolbar item

Scrollable Interface
====================

This widget supports the scrollable interface.

If you wish to control the scrolling behaviour using these functions,
inherit both the widget class and the
:py:class:`~efl.elementary.scroller.Scrollable` class
using multiple inheritance, for example::

    class ScrollableGenlist(Genlist, Scrollable):
        def __init__(self, canvas, *args, **kwargs):
            Genlist.__init__(self, canvas)

Enumerations
------------

.. _Elm_Toolbar_Icon_Lookup_Order:

Icon lookup modes
=================

.. data:: ELM_ICON_LOOKUP_FDO_THEME

    freedesktop, theme

.. data:: ELM_ICON_LOOKUP_THEME_FDO

    theme, freedesktop

.. data:: ELM_ICON_LOOKUP_FDO

    freedesktop

.. data:: ELM_ICON_LOOKUP_THEME

    theme


.. _Elm_Toolbar_Object_Select_Mode:

Selection modes
===============

.. data:: ELM_OBJECT_SELECT_MODE_DEFAULT

    Default select mode

.. data:: ELM_OBJECT_SELECT_MODE_ALWAYS

    Always select mode

.. data:: ELM_OBJECT_SELECT_MODE_NONE

    No select mode

.. data:: ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY

    No select mode with no finger size rule


.. _Elm_Toolbar_Shrink_Mode:

Toolbar shrink modes
====================

.. data:: ELM_TOOLBAR_SHRINK_NONE

    Set toolbar minimum size to fit all the items

.. data:: ELM_TOOLBAR_SHRINK_HIDE

    Hide exceeding items

.. data:: ELM_TOOLBAR_SHRINK_SCROLL

    Allow accessing exceeding items through a scroller

.. data:: ELM_TOOLBAR_SHRINK_MENU

    Inserts a button to pop up a menu with exceeding items

.. data:: ELM_TOOLBAR_SHRINK_EXPAND

    Expand all items according the size of the toolbar.


.. _Elm_Toolbar_Item_Scrollto_Type:

Toolbar item scrollto types
===========================

Where to position the item in the toolbar.

.. data:: ELM_TOOLBAR_ITEM_SCROLLTO_NONE

    No scrollto

.. data:: ELM_TOOLBAR_ITEM_SCROLLTO_IN

    To the nearest viewport

.. data:: ELM_TOOLBAR_ITEM_SCROLLTO_FIRST

    To the first of viewport

.. data:: ELM_TOOLBAR_ITEM_SCROLLTO_MIDDLE

    To the middle of viewport

.. data:: ELM_TOOLBAR_ITEM_SCROLLTO_LAST

    To the last of viewport

"""

from cpython cimport PyUnicode_AsUTF8String, Py_INCREF, Py_DECREF
from libc.stdint cimport uintptr_t

from efl.eo cimport _object_mapping_register, object_from_instance
from efl.utils.conversions cimport _ctouni
from efl.evas cimport Object as evasObject
from layout_class cimport LayoutClass
from object_item cimport _object_item_callback, _object_item_to_python, \
    _object_item_callback2, ObjectItem

from efl.utils.deprecated cimport DEPRECATED
from scroller cimport elm_scroller_policy_get, elm_scroller_policy_set, \
    elm_scroller_bounce_get, elm_scroller_bounce_set, Elm_Scroller_Policy

cimport enums

ELM_ICON_LOOKUP_FDO_THEME = enums.ELM_ICON_LOOKUP_FDO_THEME
ELM_ICON_LOOKUP_THEME_FDO = enums.ELM_ICON_LOOKUP_THEME_FDO
ELM_ICON_LOOKUP_FDO = enums.ELM_ICON_LOOKUP_FDO
ELM_ICON_LOOKUP_THEME = enums.ELM_ICON_LOOKUP_THEME

ELM_OBJECT_SELECT_MODE_DEFAULT = enums.ELM_OBJECT_SELECT_MODE_DEFAULT
ELM_OBJECT_SELECT_MODE_ALWAYS = enums.ELM_OBJECT_SELECT_MODE_ALWAYS
ELM_OBJECT_SELECT_MODE_NONE = enums.ELM_OBJECT_SELECT_MODE_NONE
ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY = enums.ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY
ELM_OBJECT_SELECT_MODE_MAX = enums.ELM_OBJECT_SELECT_MODE_MAX

ELM_TOOLBAR_SHRINK_NONE = enums.ELM_TOOLBAR_SHRINK_NONE
ELM_TOOLBAR_SHRINK_HIDE = enums.ELM_TOOLBAR_SHRINK_HIDE
ELM_TOOLBAR_SHRINK_SCROLL = enums.ELM_TOOLBAR_SHRINK_SCROLL
ELM_TOOLBAR_SHRINK_MENU = enums.ELM_TOOLBAR_SHRINK_MENU
ELM_TOOLBAR_SHRINK_EXPAND = enums.ELM_TOOLBAR_SHRINK_EXPAND
ELM_TOOLBAR_SHRINK_LAST = enums.ELM_TOOLBAR_SHRINK_LAST

ELM_TOOLBAR_ITEM_SCROLLTO_NONE = enums.ELM_TOOLBAR_ITEM_SCROLLTO_NONE
ELM_TOOLBAR_ITEM_SCROLLTO_IN = enums.ELM_TOOLBAR_ITEM_SCROLLTO_IN
ELM_TOOLBAR_ITEM_SCROLLTO_FIRST = enums.ELM_TOOLBAR_ITEM_SCROLLTO_FIRST
ELM_TOOLBAR_ITEM_SCROLLTO_MIDDLE = enums.ELM_TOOLBAR_ITEM_SCROLLTO_MIDDLE
ELM_TOOLBAR_ITEM_SCROLLTO_LAST = enums.ELM_TOOLBAR_ITEM_SCROLLTO_LAST


import traceback

def _cb_object_item_conv(uintptr_t addr):
    cdef Elm_Object_Item *it = <Elm_Object_Item *>addr
    return _object_item_to_python(it)

cdef void _toolbar_item_state_callback(void *data, Evas_Object *obj, void *event_info) with gil:
    cdef ToolbarItemState state = <object>data
    cdef ToolbarItem item = ToolbarItem.__new__(ToolbarItem)
    item.item = <Elm_Object_Item *>event_info
    (callback, a, ka) = state.params
    try:
        o = object_from_instance(obj)
        callback(o, item, *a, **ka)
    except Exception:
        traceback.print_exc()

    # The C item will be freed unless this is done
    item.item = NULL

cdef class ToolbarItemState(object):

    """A state for a :py:class:`ToolbarItem`."""

    cdef Elm_Toolbar_Item_State *state
    cdef object params

    def __init__(self, ToolbarItem 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 = _toolbar_item_state_callback

        self.params = (callback, args, kwargs)

        if isinstance(icon, unicode): icon = PyUnicode_AsUTF8String(icon)
        if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
        self.state = elm_toolbar_item_state_add(it.item,
            <const char *>icon if icon is not None else NULL,
            <const char *>label if label is not None else NULL,
            cb, <void*>self)
        if self.state == NULL:
            Py_DECREF(self)

        Py_INCREF(self)

    def delete(self):
        self.state = NULL
        Py_DECREF(self)


cdef class ToolbarItem(ObjectItem):

    """An item for the toolbar."""

    cdef:
        object label
        object icon
        Evas_Smart_Cb cb

    def __init__(self, icon = None, label = None, callback = None,
        cb_data = None, *args, **kwargs):
        """

        If a function is passed as argument, it will be called every time
        this item is selected, i.e., the user clicks over an unselected item.
        If such function isn't needed, just passing ``None`` as ``func`` is
        enough. The same should be done for ``data``.

        Toolbar will load icon image from fdo or current theme. This
        behavior can be set by :py:attr:`Toolbar.icon_order_lookup` function.
        If an absolute path is provided it will load it direct from a file.

        :param icon: A string with icon name or the absolute path of an
            image file.
        :type icon: string
        :param label: The label of the item.
        :type label: string
        :param callback: The function to call when the item is clicked.
        :type callback: function

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

        if isinstance(icon, unicode): icon = PyUnicode_AsUTF8String(icon)
        if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
        self.icon = icon
        self.label = label
        self.cb_func = callback
        self.cb_data = cb_data
        self.args = args
        self.kwargs = kwargs

    def append_to(self, Toolbar toolbar):
        """Append item to the toolbar.

        A new item will be created and appended to the toolbar, i.e., will
        be set as **last** item.

        Items created with this method can be deleted with
        :py:meth:`~efl.elementary.object_item.ObjectItem.delete`

        :seealso: :py:attr:`ToolbarItem.icon`

        :param toolbar: The toolbar this item should be appended to
        :type toolbar: :py:class:`Toolbar`
        :return: The created item or ``None`` upon failure.
        :rtype: :py:class:`ToolbarItem`

        """
        cdef Elm_Object_Item *item
        cdef Evas_Smart_Cb cb = NULL

        if self.cb_func is not None:
            cb = _object_item_callback2

        item = elm_toolbar_item_append(toolbar.obj,
            <const char *>self.icon if self.icon is not None else NULL,
            <const char *>self.label if self.label is not None else NULL,
            cb, <void*>self)

        if item == NULL:
            raise RuntimeError("The item could not be added to the widget.")

        self._set_obj(item)
        self._set_properties_from_keyword_args(self.kwargs)
        return self

    def prepend_to(self, Toolbar toolbar):
        """Prepend item to the toolbar.

        A new item will be created and prepended to the toolbar, i.e., will
        be set as **first** item.

        Items created with this method can be deleted with
        :py:meth:`~efl.elementary.object_item.ObjectItem.delete`

        :param toolbar: The toolbar this item should be prepended to
        :type toolbar: :py:class:`Toolbar`
        :return: The created item or ``None`` upon failure.
        :rtype: :py:class:`ToolbarItem`

        """
        cdef Elm_Object_Item *item
        cdef Evas_Smart_Cb cb = NULL

        if self.cb_func is not None:
            cb = _object_item_callback2

        item = elm_toolbar_item_prepend(toolbar.obj,
            <const char *>self.icon if self.icon is not None else NULL,
            <const char *>self.label if self.label is not None else NULL,
            cb, <void*>self)

        if item == NULL:
            raise RuntimeError("The item could not be added to the widget.")

        self._set_obj(item)
        self._set_properties_from_keyword_args(self.kwargs)
        return self

    def insert_after(self, ToolbarItem after):
        """Insert a new item into the toolbar object after item ``after``.

        A new item will be created and added to the toolbar. Its position in
        this toolbar will be just after item ``after``.

        Items created with this method can be deleted with
        :py:meth:`~efl.elementary.object_item.ObjectItem.delete`

        :param after: The toolbar item to insert after.
        :type after: :py:class:`ToolbarItem`
        :return: The created item or ``None`` upon failure.
        :rtype: :py:class:`ToolbarItem`

        """
        cdef:
            Elm_Object_Item *item
            Evas_Object *toolbar = elm_object_item_widget_get(after.item)
            Evas_Smart_Cb cb = NULL

        if self.cb_func is not None:
            cb = _object_item_callback2

        item = elm_toolbar_item_insert_after(toolbar,
            after.item,
            <const char *>self.icon if self.icon is not None else NULL,
            <const char *>self.label if self.label is not None else NULL,
            cb, <void*>self)

        if item == NULL:
            raise RuntimeError("The item could not be added to the widget.")

        self._set_obj(item)
        self._set_properties_from_keyword_args(self.kwargs)
        return self

    def insert_before(self, ToolbarItem before):
        """Insert a new item into the toolbar object before item ``before``.

        A new item will be created and added to the toolbar. Its position in
        this toolbar will be just before item ``before``.

        Items created with this method can be deleted with
        :py:meth:`~efl.elementary.object_item.ObjectItem.delete`

        :param before: The toolbar item to insert before.
        :type before: :py:class:`ToolbarItem`
        :return: The created item or ``None`` upon failure.
        :rtype: :py:class:`ToolbarItem`

        """
        cdef:
            Elm_Object_Item *item
            Evas_Object *toolbar = elm_object_item_widget_get(before.item)
            Evas_Smart_Cb cb = NULL

        if self.cb_func is not None:
            cb = _object_item_callback2

        item = elm_toolbar_item_insert_before(toolbar,
            before.item,
            <const char *>self.icon if self.icon is not None else NULL,
            <const char *>self.label if self.label is not None else NULL,
            cb, <void*>self)

        if item == NULL:
            raise RuntimeError("The item could not be added to the widget.")

        self._set_obj(item)
        self._set_properties_from_keyword_args(self.kwargs)
        return self

    property next:
        """Get the item after ``item`` in toolbar.

        .. note:: If it is the last item, ``None`` will be returned.

        .. seealso:: :py:meth:`ToolbarItem.append_to`

        :type: :py:class:`ToolbarItem`

        """
        def __get__(self):
            return _object_item_to_python(elm_toolbar_item_next_get(self.item))

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

    property prev:
        """Get the item before ``item`` in toolbar.

        .. note:: If it is the first item, ``None`` will be returned.

        .. seealso:: :py:func:`ToolbarItem.prepend_to`

        :type: :py:class:`ToolbarItem`

        """
        def __get__(self):
            return _object_item_to_python(elm_toolbar_item_prev_get(self.item))

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

    property priority:
        """The priority of a toolbar item.

        This is used only when the toolbar shrink mode is set to
        ELM_TOOLBAR_SHRINK_MENU or ELM_TOOLBAR_SHRINK_HIDE. When space is
        less than required, items with low priority will be removed from the
        toolbar and added to a dynamically-created menu, while items with
        higher priority will remain on the toolbar, with the same order they
        were added.

        :type: int

        """
        def __get__(self):
            return elm_toolbar_item_priority_get(self.item)

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

    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 selected:
        """The selected state of an item.

        This reflects the selected state of the given item. ``True`` for
        selected, ``False`` for not selected.

        If a new item is selected the previously selected will be unselected.
        Previously selected item can be get with function
        :py:attr:`Toolbar.selected_item`.

        Selected items will be highlighted.

        .. seealso:: :py:attr:`Toolbar.selected_item`

        :type: bool

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

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

    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 icon:
        """The icon associated with the item.

        Toolbar will load icon image from fdo or current theme. This
        behavior can be set by :py:attr:`Toolbar.icon_order_lookup` function.
        If an absolute path is provided it will load it direct from a file.

        .. seealso:: :py:attr:`Toolbar.icon_order_lookup`

        :type: string

        """
        def __get__(self):
            return _ctouni(elm_toolbar_item_icon_get(self.item))

        def __set__(self, ic):
            if isinstance(ic, unicode): ic = PyUnicode_AsUTF8String(ic)
            elm_toolbar_item_icon_set(self.item,
                <const char *>ic if ic is not None else NULL)

    def icon_set(self, ic):
        if isinstance(ic, unicode): ic = PyUnicode_AsUTF8String(ic)
        elm_toolbar_item_icon_set(self.item,
            <const char *>ic if ic is not None else NULL)
    def icon_get(self):
        return _ctouni(elm_toolbar_item_icon_get(self.item))

    property object:
        """Get the object of item.

        :type: :py:class:`~efl.evas.Object`

        """
        def __get__(self):
            return object_from_instance(elm_toolbar_item_object_get(self.item))

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

    property icon_object:
        """Get the icon object of item.

        .. seealso::
            :py:attr:`icon`,
            :py:attr:`icon_file`, or
            :py:attr:`icon_memfile` for details.

        :type: :py:class:`~efl.elementary.icon.Icon`

        """
        def __get__(self):
            return object_from_instance(elm_toolbar_item_icon_object_get(self.item))

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

    # TODO:
    # def icon_memfile_set(self, img, size, format, key):
    #     """Set the icon associated with item to an image in a binary buffer.

    #     .. note:: The icon image set by this function can be changed
    #         by :py:attr:`icon`.

    #     :param img: The binary data that will be used as an image
    #     :param size: The size of binary data ``img``
    #     :type size: int
    #     :param format: Optional format of ``img`` to pass to the image loader
    #     :type format: string
    #     :param key: Optional key of ``img`` to pass to the image loader (eg.
    #         if ``img`` is an edje file)
    #     :type key: string

    #     :return: (``True`` = success, ``False`` = error)
    #     :rtype: bool

    #     """
    #     return bool(elm_toolbar_item_icon_memfile_set(self.item, img, size, format, key))

    property icon_file:
        """Set the icon associated with item to an image in a binary buffer.

        .. note:: The icon image set by this function can be changed
            by :py:attr:`icon`.

        :type: string or tuple of strings

        """
        def __set__(self, value):
            if isinstance(value, tuple):
                file_name, key = value
            else:
                file_name = value
                key = None
            self.icon_file_set(file_name, key)

    def icon_file_set(self, file_name, key):
        if isinstance(file_name, unicode): file_name = PyUnicode_AsUTF8String(file_name)
        if isinstance(key, unicode): key = PyUnicode_AsUTF8String(key)
        if not elm_toolbar_item_icon_file_set(self.item,
            <const char *>file_name if file_name is not None else NULL,
            <const char *>key if key is not None else NULL):
                raise RuntimeError("Could not set icon_file.")

    property separator:
        """Whether item is a separator or not.

        Items aren't set as separator by default.

        If set as separator it will display separator theme, so won't display
        icons or label.

        :type: bool

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

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

    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 menu:
        """

        This property has two diffent functionalities. The object you get from
        it is the :py:class:`~efl.elementary.menu.Menu` object used by this
        toolbar item, and setting it to True or False controls whether this item
        is a menu or not.

        If item wasn't set as menu item, getting the value of this property
        sets it to be that.

        Once it is set to be a menu, it can be manipulated through
        :py:attr:`Toolbar.menu_parent` and the
        :py:class:`~efl.elementary.menu.Menu` functions and properties.

        So, items to be displayed in this item's menu should be added with
        :py:func:`efl.elementary.menu.Menu.item_add()`.

        The following code exemplifies the most basic usage::

            tb = Toolbar(win)
            item = tb.item_append("refresh", "Menu")
            item.menu = True
            tb.menu_parent = win
            menu = item.menu
            menu.item_add(None, "edit-cut", "Cut")
            menu_item = menu.item_add(None, "edit-copy", "Copy")

        :type: bool

        """
        def __get__(self):
            import efl.elementary.menu  # XXX: Hack for class not being known
            return object_from_instance(elm_toolbar_item_menu_get(self.item))

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

    def menu_set(self, menu):
        elm_toolbar_item_menu_set(self.item, menu)
    def menu_get(self):
        import efl.elementary.menu  # XXX: Hack for class not being known
        return object_from_instance(elm_toolbar_item_menu_get(self.item))


    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):
        if not elm_toolbar_item_state_del(self.item, state.state):
            raise RuntimeError("Could not delete state.")

    property state:
        """An item state."""
        def __set__(self, ToolbarItemState state):
            if not elm_toolbar_item_state_set(self.item, state.state):
                raise RuntimeError("Could not set state")

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

        def __get__(self):
            cdef ToolbarItemState ret = ToolbarItemState.__new__(ToolbarItemState)
            ret.state = elm_toolbar_item_state_get(self.item)
            return ret if ret.state != NULL else None

    def state_set(self, ToolbarItemState state):
        if not elm_toolbar_item_state_set(self.item, state.state):
            raise RuntimeError("Could not set state")

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

    def state_get(self):
        cdef ToolbarItemState ret = ToolbarItemState.__new__(ToolbarItemState)
        ret.state = elm_toolbar_item_state_get(self.item)
        return ret if ret.state != NULL else None

    def state_next(self):
        cdef ToolbarItemState ret = ToolbarItemState.__new__(ToolbarItemState)
        ret.state = elm_toolbar_item_state_next(self.item)
        return ret if ret.state != NULL else None

    def state_prev(self):
        cdef ToolbarItemState ret = ToolbarItemState.__new__(ToolbarItemState)
        ret.state = elm_toolbar_item_state_prev(self.item)
        return ret if ret.state != NULL else None

    def show(self, Elm_Toolbar_Item_Scrollto_Type scrollto_type):
        """Show this item, when the toolbar can be scrolled.

        :see: :py:func:`bring_in`

        .. versionadded:: 1.8

        """
        elm_toolbar_item_show(self.item, scrollto_type)

    def bring_in(self, Elm_Toolbar_Item_Scrollto_Type scrollto_type):
        """Show this item with scroll animation, when the toolbar can be scrolled.

        :see: :py:func:`show`

        .. versionadded:: 1.8

        """
        elm_toolbar_item_bring_in(self.item, scrollto_type)


cdef class Toolbar(LayoutClass):

    """

    This is the class that actually implements the widget.

    .. versionchanged:: 1.8
        Inherits from LayoutClass.

    """

    def __init__(self, evasObject parent, *args, **kwargs):
        self._set_obj(elm_toolbar_add(parent.obj))
        self._set_properties_from_keyword_args(kwargs)

    property icon_size:
        """The icon size, in pixels, to be used by toolbar items.

        .. note:: Default value is ``32``. It reads value from elm config.

        :type: int

        """
        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_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_order_lookup:
        """Icon lookup order, for toolbar items' icons.

        Icons added before calling this function will not be affected.
        The default lookup order is ELM_ICON_LOOKUP_THEME_FDO.

        :type: :ref:`Elm_Toolbar_Icon_Lookup_Order`

        """
        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 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)

    def item_append(self, icon, label, callback = None, *args, **kargs):
        cdef:
            Elm_Object_Item *item
            Evas_Smart_Cb cb = NULL
            ToolbarItem ret = ToolbarItem.__new__(ToolbarItem)

        if callback is not None and callable(callback):
            cb = _object_item_callback

        if isinstance(icon, unicode): icon = PyUnicode_AsUTF8String(icon)
        if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)

        item = elm_toolbar_item_append(self.obj,
            <const char *>icon if icon is not None else NULL,
            <const char *>label if label is not None else NULL,
            cb, <void*>ret)

        if item != NULL:
            ret._set_obj(item)
            ret.cb_func = callback
            ret.args = args
            ret.kwargs = kargs
            return ret
        else:
            return None

    #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)

    property first_item:
        """Get the first item in the given toolbar widget's list of items.

        .. seealso:: :py:func:`ToolbarItem.append_to` :py:attr:`last_item`

        :type: :py:class:`ToolbarItem`

        """
        def __get__(self):
            return _object_item_to_python(elm_toolbar_first_item_get(self.obj))

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

    property last_item:
        """Get the last item in the given toolbar widget's list of items.

        .. seealso:: :py:func:`ToolbarItem.prepend_to` :py:attr:`first_item`

        :type: :py:class:`ToolbarItem`

        """
        def __get__(self):
            return _object_item_to_python(elm_toolbar_last_item_get(self.obj))

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

    def item_find_by_label(self, label):
        """Returns a toolbar item by its label.

        :param label: The label of the item to find.
        :type label: string
        :return: The toolbar item matching ``label`` or ``None`` on failure.
        :rtype: :py:class:`ToolbarItem`

        """
        if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
        return _object_item_to_python(elm_toolbar_item_find_by_label(self.obj,
            <const char *>label if label is not None else NULL))

    property selected_item:
        """The selected item.

        The selected item can be unselected with :py:attr:`ToolbarItem.selected`.

        The selected item always will be highlighted on toolbar.

        .. seealso:: :py:attr:`selected_items`

        :type: :py:class:`ToolbarItem`

        """
        def __get__(self):
            return _object_item_to_python(elm_toolbar_selected_item_get(self.obj))

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

    property more_item:
        """Get the more item.

        The more item can be changed with
        :py:attr:`~efl.elementary.object_item.ObjectItem.text` and
        :py:attr:`~efl.elementary.object_item.ObjectItem.content`.

        :type: :py:class:`ToolbarItem`

        """
        def __get__(self):
            return _object_item_to_python(elm_toolbar_more_item_get(self.obj))

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

    property shrink_mode:
        """The shrink state of toolbar.

        The toolbar won't scroll if ELM_TOOLBAR_SHRINK_NONE, but will
        enforce a minimum size so all the items will fit, won't scroll and
        won't show the items that don't fit if ELM_TOOLBAR_SHRINK_HIDE, will
        scroll if ELM_TOOLBAR_SHRINK_SCROLL, and will create a button to pop
        up excess elements with ELM_TOOLBAR_SHRINK_MENU.

        :type: :ref:`Elm_Toolbar_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 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 transverse_expanded:
        """Item's transverse expansion.

        :type: bool

        This will expand the transverse length of the item according the
        transverse length of the toolbar. The default is what the transverse
        length of the item is set according its min value (this property is False).

        .. versionadded:: 1.8

        """
        def __set__(self, bint transverse_expanded):
            elm_toolbar_transverse_expanded_set(self.obj, transverse_expanded)

        def __get__(self):
            return bool(elm_toolbar_transverse_expanded_get(self.obj))

    def transverse_expanded_set(self, bint transverse_expanded):
        elm_toolbar_transverse_expanded_set(self.obj, transverse_expanded)

    def transverse_expanded_get(self):
        return bool(elm_toolbar_transverse_expanded_get(self.obj))

    property homogeneous:
        """Homogeneous mode.

        This will enable the homogeneous mode where items are of the same size.

        :type: bool

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

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

    def homogeneous_set(self, homogeneous):
        elm_toolbar_homogeneous_set(self.obj, homogeneous)
    def homogeneous_get(self):
        return elm_toolbar_homogeneous_get(self.obj)

    property menu_parent:
        """The parent object of the toolbar items' menus.

        Each item can be set as item menu, with :py:attr:`ToolbarItem.menu`.

        For more details about setting the parent for toolbar menus, see
        :py:attr:`~efl.elementary.menu.Menu.parent`.

        :type: :py:class:`~efl.elementary.object.Object`

        """
        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 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 align:
        """The alignment of the items.

        Alignment of toolbar items, from ``0.0`` to indicates to align
        left, to ``1.0``, to align to right. ``0.5`` centralize
        items.

        Centered items by default.

        :type: float

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

        def __get__(self):
            return elm_toolbar_align_get(self.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 horizontal:
        """A toolbar's orientation

        By default, a toolbar will be horizontal. Change this property to
        create a vertical toolbar.

        :type: bool

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

        def __get__(self):
            return elm_toolbar_horizontal_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)

    def items_count(self):
        """Get the number of items in a toolbar

        :return: The number of items in toolbar
        :rtype: int

        """
        return elm_toolbar_items_count(self.obj)

    property standard_priority:
        """The standard priority of visible items in a toolbar

        If the priority of the item is up to standard priority, it is shown
        in basic panel. The other items are located in more menu or panel.
        The more menu or panel can be shown when the more item is clicked.

        :type: int

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

    property select_mode:
        """The toolbar select mode.

        :type: :ref:`Elm_Toolbar_Object_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 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 reorder_mode:
        """Reorder mode

        :type: bool

        .. versionadded:: 1.8

        """
        def __set__(self, bint reorder_mode):
            elm_toolbar_reorder_mode_set(self.obj, reorder_mode)

        def __get__(self):
            return bool(elm_toolbar_reorder_mode_get(self.obj))

    def reorder_mode_set(self, bint reorder_mode):
        elm_toolbar_reorder_mode_set(self.obj, reorder_mode)

    def reorder_mode_get(self):
        return bool(elm_toolbar_reorder_mode_get(self.obj))

    def callback_clicked_add(self, func, *args, **kwargs):
        """When the user clicks on a toolbar item and becomes selected."""
        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):
        """When the toolbar is pressed for a certain amount of time."""
        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):
        """When the program language changes."""
        self._callback_add("language,changed", func, *args, **kwargs)

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

    def callback_focused_add(self, func, *args, **kwargs):
        """When the toolbar has received focus.

        .. versionadded:: 1.8
        """
        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):
        """When the toolbar has lost focus.

        .. versionadded:: 1.8
        """
        self._callback_add("unfocused", func, *args, **kwargs)

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

    def callback_item_focused_add(self, func, *args, **kwargs):
        """When the toolbar item has received focus.

        .. versionadded:: 1.10

        """
        self._callback_add_full("item,focused", _cb_object_item_conv, func, *args, **kwargs)

    def callback_item_focused_del(self, func):
        self._callback_del_full("item,focused", _cb_object_item_conv, func)

    def callback_item_unfocused_add(self, func, *args, **kwargs):
        """When the toolbar item has lost focus.

        .. versionadded:: 1.10

        """
        self._callback_add_full("item,unfocused", _cb_object_item_conv, func, *args, **kwargs)

    def callback_item_unfocused_del(self, func):
        self._callback_del_full("item,unfocused", _cb_object_item_conv, func)

    property scroller_policy:
        """

        .. deprecated:: 1.8
            You should combine with Scrollable class instead.

        """
        def __get__(self):
            return self.scroller_policy_get()

        def __set__(self, value):
            cdef Elm_Scroller_Policy policy_h, policy_v
            policy_h, policy_v = value
            self.scroller_policy_set(policy_h, policy_v)

    @DEPRECATED("1.8", "You should combine with Scrollable class instead.")
    def scroller_policy_set(self, policy_h, policy_v):
        elm_scroller_policy_set(self.obj, policy_h, policy_v)
    @DEPRECATED("1.8", "You should combine with Scrollable class instead.")
    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 bounce:
        """

        .. deprecated:: 1.8
            You should combine with Scrollable class instead.

        """
        def __get__(self):
            return self.bounce_get()
        def __set__(self, value):
            cdef Eina_Bool h, v
            h, v = value
            self.bounce_set(h, v)

    @DEPRECATED("1.8", "You should combine with Scrollable class instead.")
    def bounce_set(self, h, v):
        elm_scroller_bounce_set(self.obj, h, v)
    @DEPRECATED("1.8", "You should combine with Scrollable class instead.")
    def bounce_get(self):
        cdef Eina_Bool h, v
        elm_scroller_bounce_get(self.obj, &h, &v)
        return (h, v)

_object_mapping_register("Elm_Toolbar", Toolbar)