aboutsummaryrefslogtreecommitdiffstats
path: root/tests/elementary/test_colorselector.py
blob: 9d0c79be94ec1bbf6795d60d3fd32b35ff52b50b (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
#!/usr/bin/env python
# encoding: utf-8

from efl import elementary
from efl import evas


def cb_cs_changed(cs, rect):
    print("changed")
    (r, g, b, a) = cs.color
    r = (r * a) / 255
    g = (g * a) / 255
    b = (b * a) / 255
    rect.color = (r, g, b, a)

def cb_cs_item_sel(cs, item, rect):
    print("selected")
    (r, g, b, a) = item.color
    r = (r * a) / 255
    g = (g * a) / 255
    b = (b * a) / 255
    rect.color = (r, g, b, a)

def cb_cs_item_lp(cs, item, rect):
    print("longpressed")
    (r, g, b, a) = item.color
    r = (r * a) / 255
    g = (g * a) / 255
    b = (b * a) / 255
    rect.color = (r, g, b, a)

def colorselector_clicked(obj):
    win = elementary.Window("colorselector", elementary.ELM_WIN_BASIC)
    win.title = "ColorSelector test"
    win.autodel = True
    if obj is None:
        win.callback_delete_request_add(lambda o: elementary.exit())

    bg = elementary.Background(win)
    win.resize_object_add(bg)
    bg.size_hint_weight = (evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND)
    bg.show()

    vbox = elementary.Box(win)
    vbox.size_hint_weight = (evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND)
    win.resize_object_add(vbox)
    vbox.show()

    fr = elementary.Frame(win)
    fr.text = "Color View"
    fr.size_hint_weight = (evas.EVAS_HINT_EXPAND, 0.0)
    fr.size_hint_align = (evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL)
    vbox.pack_end(fr)
    fr.show()

    re = evas.Rectangle(win.evas)
    re.size_hint_min = (1, 100)
    fr.content = re
    re.show()

    fr = elementary.Frame(win)
    fr.text = "Color Selector"
    fr.size_hint_weight = (evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND)
    fr.size_hint_align = (evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL)
    vbox.pack_end(fr)
    fr.show()

    cs = elementary.Colorselector(win)
    cs.size_hint_weight = (evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND)
    cs.size_hint_align = (evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL)
    cs.callback_changed_add(cb_cs_changed, re)
    cs.callback_color_item_selected_add(cb_cs_item_sel, re)
    cs.callback_color_item_longpressed_add(cb_cs_item_lp, re)
    cs.color = (255, 160, 132, 255)
    fr.content = cs
    cs.show()

    re.color = cs.color
    cs.palette_color_add(255, 90, 18, 255)
    cs.palette_color_add(255, 213, 0, 255)
    cs.palette_color_add(146, 255, 11, 255)
    cs.palette_color_add(9, 186, 10, 255)
    cs.palette_color_add(86, 201, 242, 255)
    cs.palette_color_add(18, 83, 128, 255)
    cs.palette_color_add(140, 53, 238, 255)
    cs.palette_color_add(255, 145, 145, 255)
    cs.palette_color_add(255, 59, 119, 255)
    cs.palette_color_add(133, 100, 69, 255)
    cs.palette_color_add(255, 255, 119, 255)
    cs.palette_color_add(133, 100, 255, 255)

    hbox = elementary.Box(win)
    hbox.horizontal = True
    hbox.size_hint_align = (evas.EVAS_HINT_FILL, 0.0)
    hbox.size_hint_weight = (evas.EVAS_HINT_EXPAND, 0.0)
    vbox.pack_end(hbox)
    hbox.show()

    bt = elementary.Button(win)
    bt.text = "Palette"
    bt.size_hint_align = (evas.EVAS_HINT_FILL, 0.0)
    bt.size_hint_weight = (evas.EVAS_HINT_EXPAND, 0.0)
    bt.callback_clicked_add(lambda btn: cs.mode_set(elementary.ELM_COLORSELECTOR_PALETTE))
    hbox.pack_end(bt)
    bt.show()

    bt = elementary.Button(win)
    bt.text = "Components"
    bt.size_hint_align = (evas.EVAS_HINT_FILL, 0.0)
    bt.size_hint_weight = (evas.EVAS_HINT_EXPAND, 0.0)
    bt.callback_clicked_add(lambda btn: cs.mode_set(elementary.ELM_COLORSELECTOR_COMPONENTS))
    hbox.pack_end(bt)
    bt.show()

    bt = elementary.Button(win)
    bt.text = "Both"
    bt.size_hint_align = (evas.EVAS_HINT_FILL, 0.0)
    bt.size_hint_weight = (evas.EVAS_HINT_EXPAND, 0.0)
    bt.callback_clicked_add(lambda btn: cs.mode_set(elementary.ELM_COLORSELECTOR_BOTH))
    hbox.pack_end(bt)
    bt.show()

    win.resize(320, 550)
    win.show()


if __name__ == "__main__":
    elementary.init()

    colorselector_clicked(None)

    elementary.run()
    elementary.shutdown()