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

import os

from efl.evas import EVAS_HINT_EXPAND, EVAS_HINT_FILL, \
    EXPAND_BOTH, FILL_BOTH, EXPAND_HORIZ
from efl import elementary
from efl.elementary.window import StandardWindow, Window, ELM_WIN_BASIC
from efl.elementary.box import Box
from efl.elementary.button import Button
from efl.elementary.frame import Frame
from efl.elementary.label import Label
from efl.elementary.check import Check
from efl.elementary.list import List
from efl.elementary.icon import Icon, ELM_ICON_LOOKUP_FDO_THEME, \
    ELM_ICON_LOOKUP_THEME_FDO, ELM_ICON_LOOKUP_THEME, ELM_ICON_LOOKUP_FDO
from efl.elementary.radio import Radio
from efl.elementary.theme import Theme


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

def aspect_fixed_cb(obj, ic):
    ic.aspect_fixed = obj.state

def fill_outside_cb(obj, ic):
    ic.fill_outside = obj.state

def smooth_cb(obj, ic):
    ic.smooth = obj.state

def bt_clicked(obj):
    win = StandardWindow("preload-prescale", "Preload & Prescale", autodel=True,
        size=(350, 350))

    ic = Icon(win, file=os.path.join(img_path, "insanely_huge_test_image.jpg"),
        size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH,
        resizable=(True, True), aspect_fixed=True, preload_disabled=True,
        prescale=True)
    win.resize_object_add(ic)
    ic.show()

    win.show()


def icon_clicked(obj, item=None):
    win = StandardWindow("icon test", "Icon Test", autodel=True,
        size=(400, 400))
    win.show()

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

    ic = Icon(box, file=os.path.join(img_path, "logo.png"),
        resizable=(True, True), size_hint_weight=EXPAND_BOTH,
        size_hint_align=FILL_BOTH)
    box.pack_end(ic)
    ic.show()

    hbox = Box(box, horizontal=True, size_hint_weight=EXPAND_HORIZ)
    box.pack_end(hbox)
    hbox.show()

    # Test Aspect Fixed
    tg = Check(hbox, text="Aspect Fixed", state=True)
    tg.callback_changed_add(aspect_fixed_cb, ic)
    hbox.pack_end(tg)
    tg.show()

    # Test Fill Outside
    tg = Check(hbox, text="Fill Outside")
    tg.callback_changed_add(fill_outside_cb, ic)
    hbox.pack_end(tg)
    tg.show()

    # Test Smooth
    tg = Check(hbox, text="Smooth", state=True)
    tg.callback_changed_add(smooth_cb, ic)
    hbox.pack_end(tg)
    tg.show()

    # Test Preload, Prescale
    bt = Button(hbox, text="Preload & Prescale")
    bt.callback_clicked_add(bt_clicked)
    hbox.pack_end(bt)
    bt.show()


def icon_transparent_clicked(obj, item=None):
    win = Window("icon-transparent", ELM_WIN_BASIC, title="Icon Transparent",
        autodel=True, alpha=True)
    if obj is None:
        win.callback_delete_request_add(lambda o: elementary.exit())

    icon = Icon(win, file=os.path.join(img_path, "logo.png"),
        resizable=(False, False))
    win.resize_object_add(icon)
    icon.show()

    win.show()


def standard_list_populate(li, order):
    li.clear()
    for group in Theme(default=True).group_base_list_get("elm/icon"):
        name = '/'.join(group.split('/')[2:-1])
        if '-' in name or name == 'folder':
            try:
                ic = Icon(li, standard=name, order_lookup=order,
                          size_hint_min=(32,32))
            except:
                ic = None
            li.item_append(name, ic)
    li.go()

def icon_standard_clicked(obj, item=None):
    win = StandardWindow("icon-standard", "Icon Standard",
                         autodel=True, size=(300,400))
    if obj is None:
        win.callback_delete_request_add(lambda o: elementary.exit())
    
    vbox = Box(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
    win.resize_object_add(vbox)
    vbox.show()

    fr = Frame(vbox, text="standard icon order lookup", size_hint_align=FILL_BOTH)
    vbox.pack_end(fr)
    fr.show()

    hbox = Box(fr, horizontal=True)
    fr.content = hbox
    hbox.show()

    li = List(vbox, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
    vbox.pack_end(li)
    li.show()

    rdg = Radio(hbox, text="fdo, theme", state_value=ELM_ICON_LOOKUP_FDO_THEME)
    rdg.callback_changed_add(lambda r: standard_list_populate(li, r.state_value))
    hbox.pack_end(rdg)
    rdg.show()

    rd = Radio(hbox, text="theme, fdo", state_value=ELM_ICON_LOOKUP_THEME_FDO)
    rd.group_add(rdg)
    rd.callback_changed_add(lambda r: standard_list_populate(li, r.state_value))
    hbox.pack_end(rd)
    rd.show()

    rd = Radio(hbox, text="fdo only", state_value=ELM_ICON_LOOKUP_FDO)
    rd.group_add(rdg)
    rd.callback_changed_add(lambda r: standard_list_populate(li, r.state_value))
    hbox.pack_end(rd)
    rd.show()

    rd = Radio(hbox, text="theme only", state_value=ELM_ICON_LOOKUP_THEME)
    rd.group_add(rdg)
    rd.callback_changed_add(lambda r: standard_list_populate(li, r.state_value))
    hbox.pack_end(rd)
    rd.show()

    rdg.value = ELM_ICON_LOOKUP_THEME_FDO
    standard_list_populate(li, ELM_ICON_LOOKUP_THEME_FDO)

    win.show()


if __name__ == "__main__":
    win = StandardWindow("test", "python-elementary test application",
        size=(320,520))
    win.callback_delete_request_add(lambda o: elementary.exit())

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

    lb = Label(win)
    lb.text_set("Please select a test from the list below<br>"
                 "by clicking the test button to show the<br>"
                 "test window.")
    lb.show()

    fr = Frame(win, text="Information", content=lb)
    box0.pack_end(fr)
    fr.show()

    items = [("Icon", icon_clicked),
             ("Icon transparent", icon_transparent_clicked),
             ("Icon standard", icon_standard_clicked)]

    li = List(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
    box0.pack_end(li)
    li.show()

    for item in items:
        li.item_append(item[0], callback=item[1])

    li.go()

    win.show()
    elementary.run()