aboutsummaryrefslogtreecommitdiffstats
path: root/examples/elementary/test_hoversel.py
blob: c38117976cd1d05f06eae739a0c22f0c4ea1f5b5 (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
#!/usr/bin/env python
# encoding: utf-8

import os

from efl.ecore import Timer
from efl.evas import EVAS_HINT_EXPAND, EXPAND_BOTH, FILL_BOTH
from efl import elementary
from efl.elementary.window import StandardWindow
from efl.elementary.box import Box
from efl.elementary.hoversel import Hoversel, ELM_ICON_STANDARD, ELM_ICON_FILE
from efl.elementary.icon import Icon

WEIGHT_ZERO = 0.0, 0.0
ALIGN_CENTER = 0.5, 0.5

script_path = os.path.dirname(os.path.abspath(__file__))
img_path = os.path.join(script_path, "images")

def hoversel_clicked(obj):
    win = StandardWindow("hoversel", "Hoversel", autodel=True, size=(320, 320))
    if obj is None:
        win.callback_delete_request_add(lambda o: elementary.exit())

    bx = Box(win, size_hint_weight=EXPAND_BOTH)
    win.resize_object_add(bx)
    bx.show()

    def _sel_label_cb(hoversel, item):
        text = hoversel.text
        hoversel.text = item.text
        Timer(2.0, lambda: hoversel.text_set("Labels"))

    bt = Hoversel(win, hover_parent=win, text="Labels",
                  size_hint_weight=WEIGHT_ZERO, size_hint_align=ALIGN_CENTER)
    bt.item_add("Item 1")
    bt.item_add("Item 2")
    bt.item_add("Item 3")
    bt.item_add("Item 4 - Long Label Here")
    bt.callback_selected_add(_sel_label_cb)
    bx.pack_end(bt)
    bt.show()

    bt = Hoversel(win, hover_parent=win, text="Some Icons",
                  size_hint_weight=WEIGHT_ZERO, size_hint_align=ALIGN_CENTER)
    bt.item_add("Item 1")
    bt.item_add("Item 2")
    bt.item_add("Item 3", "user-home", ELM_ICON_STANDARD)
    bt.item_add("Item 4", "view-close", ELM_ICON_STANDARD)
    bx.pack_end(bt)
    bt.show()

    bt = Hoversel(win, hover_parent=win, text="All Icons",
                  size_hint_weight=WEIGHT_ZERO, size_hint_align=ALIGN_CENTER)
    bt.item_add("Item 1", "user-trash", ELM_ICON_STANDARD)
    bt.item_add("Item 2", "go-down", ELM_ICON_STANDARD)
    bt.item_add("Item 3", "user-home", ELM_ICON_STANDARD)
    bt.item_add("Item 4", "view-close", ELM_ICON_STANDARD)
    bx.pack_end(bt)
    bt.show()

    bt = Hoversel(win, hover_parent=win, text="All Icons",
                  size_hint_weight=WEIGHT_ZERO, size_hint_align=ALIGN_CENTER)
    bt.item_add("Item 1", "user-trash", ELM_ICON_STANDARD)
    bt.item_add("Item 2", os.path.join(img_path, "logo_small.png"),
                ELM_ICON_FILE)
    bt.item_add("Item 3", "user-home", ELM_ICON_STANDARD)
    bt.item_add("Item 4", "view-close", ELM_ICON_STANDARD)
    bx.pack_end(bt)
    bt.show()

    bt = Hoversel(win, hover_parent=win, text="Disabled Hoversel",
                  disabled=True, size_hint_weight=WEIGHT_ZERO,
                  size_hint_align=ALIGN_CENTER)
    bt.item_add("Item 1", "folder", ELM_ICON_STANDARD)
    bt.item_add("Item 2", "view-close", ELM_ICON_STANDARD)
    bx.pack_end(bt)
    bt.show()

    ic = Icon(win, file=os.path.join(img_path, "sky_03.jpg"))
    bt = Hoversel(win, hover_parent=win, text="Icon + Label", content=ic,
                  size_hint_weight=WEIGHT_ZERO, size_hint_align=ALIGN_CENTER)
    ic.show()

    bt.item_add("Item 1", "user-trash", ELM_ICON_STANDARD)
    bt.item_add("Item 2", "go-down", ELM_ICON_STANDARD)
    bt.item_add("Item 3", "user-home", ELM_ICON_STANDARD)
    bt.item_add("Item 4", "view-close", ELM_ICON_STANDARD)
    bx.pack_end(bt)
    bt.show()

    bt = Hoversel(win, hover_parent=win, text="Label auto changed",
                  auto_update=True,
                  size_hint_weight=WEIGHT_ZERO, size_hint_align=ALIGN_CENTER)

    bt.item_add("Item 1", "user-trash", ELM_ICON_STANDARD)
    bt.item_add("Item 2", "go-down", ELM_ICON_STANDARD)
    bt.item_add("Item 3", "user-home", ELM_ICON_STANDARD)
    bt.item_add("Item 4", "view-close", ELM_ICON_STANDARD)
    bx.pack_end(bt)
    bt.show()

    win.show()


if __name__ == "__main__":

    hoversel_clicked(None)

    elementary.run()