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

from efl.ecore import Timer
from efl.evas import EVAS_HINT_EXPAND, EVAS_HINT_FILL, \
    EXPAND_BOTH, FILL_BOTH, EXPAND_HORIZ, FILL_HORIZ, FILL_VERT
from efl import elementary
from efl.elementary.window import Window, ELM_WIN_BASIC
from efl.elementary.background import Background
from efl.elementary.box import Box
from efl.elementary.button import Button
from efl.elementary.check import Check
from efl.elementary.slider import Slider


def cb_alpha(ck, win, bg):
    win.alpha = ck.state
    print("alpha: %s" % win.alpha)
    bg.hide() if ck.state is True else bg.show()

def cb_rot(bt, win, ck, rot):
    if ck.state:
        win.rotation_with_resize_set(rot)
    else:
        win.rotation = rot

def cb_iconify_and_activate(bt, win):
    win.iconified = True
    Timer(3.0, lambda: win.activate())

def cb_iconify_and_deiconify(bt, win):
    win.iconified = True
    Timer(3.0, lambda: win.iconified_set(False))

def cb_win_moved(win):
    print("MOVE - win geom: x %d, y %d, w %d, h %d" % win.geometry)

def set_and_report(win, prop, val):
    setattr(win, prop, val)
    print("Property: '%s' is now: '%s'" % (prop, getattr(win, prop)))

def window_states_clicked(obj):
    win = Window("window-states", ELM_WIN_BASIC, autodel=True,
                 title="Window States test", size=(280, 400))
    win.callback_moved_add(cb_win_moved)
    if obj is None:
        win.callback_delete_request_add(lambda o: elementary.exit())

    print(win.available_profiles)

    bg = Background(win, size_hint_weight=EXPAND_BOTH)
    win.resize_object_add(bg)
    bg.show()

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

    hbox = Box(win, horizontal=True, size_hint_align=FILL_HORIZ,
               size_hint_weight=EXPAND_HORIZ)
    vbox.pack_end(hbox)
    hbox.show()

    hbox = Box(win, horizontal=True, size_hint_align=FILL_HORIZ,
               size_hint_weight=EXPAND_HORIZ)
    vbox.pack_end(hbox)
    hbox.show()

    bt = Button(win, text="Lower", size_hint_align=FILL_HORIZ,
                size_hint_weight=EXPAND_HORIZ)
    bt.callback_clicked_add(lambda b: win.lower())
    hbox.pack_end(bt)
    bt.show()

    bt = Button(win, text="Iconify and Activate", size_hint_align=FILL_HORIZ,
                size_hint_weight=EXPAND_HORIZ)
    bt.callback_clicked_add(cb_iconify_and_activate, win)
    hbox.pack_end(bt)
    bt.show()

    bt = Button(win, text="Iconify and Deiconify", size_hint_align=FILL_HORIZ,
                size_hint_weight=EXPAND_HORIZ)
    bt.callback_clicked_add(cb_iconify_and_deiconify, win)
    hbox.pack_end(bt)
    bt.show()

    hbox = Box(win, horizontal=True, size_hint_align=FILL_HORIZ,
               size_hint_weight=EXPAND_HORIZ)
    vbox.pack_end(hbox)
    hbox.show()

    bt = Button(win, text="Move 0 0", size_hint_align=FILL_HORIZ,
                size_hint_weight=EXPAND_HORIZ)
    bt.callback_clicked_add(lambda b: win.move(0,0))
    hbox.pack_end(bt)
    bt.show()

    bt = Button(win, text="Move 20 20", size_hint_align=FILL_HORIZ,
                size_hint_weight=EXPAND_HORIZ)
    bt.callback_clicked_add(lambda b: win.move(20,20))
    hbox.pack_end(bt)
    bt.show()

    bt = Button(win, text="Center", size_hint_align=FILL_HORIZ,
                size_hint_weight=EXPAND_HORIZ)
    bt.callback_clicked_add(lambda b: win.center(True, True))
    hbox.pack_end(bt)
    bt.show()

    hbox = Box(win, horizontal=True, size_hint_align=FILL_HORIZ,
               size_hint_weight=EXPAND_HORIZ)
    vbox.pack_end(hbox)
    hbox.show()

    ck = Check(win, text="Alpha")
    ck.callback_changed_add(cb_alpha, win, bg)
    hbox.pack_end(ck)
    ck.show()

    ck = Check(win, text="Borderless")
    ck.callback_changed_add(lambda c: set_and_report(win, 'borderless', c.state))
    hbox.pack_end(ck)
    ck.show()

    ck = Check(win, text="Fullscreen")
    ck.callback_changed_add(lambda c: set_and_report(win, 'fullscreen', c.state))
    hbox.pack_end(ck)
    ck.show()

    ck = Check(win, text="NoBlank")
    ck.callback_changed_add(lambda c: set_and_report(win, 'noblank', c.state))
    hbox.pack_end(ck)
    ck.show()

    sl = Slider(win, text="Visual test", indicator_format="%3.0f",
                min_max=(50, 150), value=50, inverted=True,
                size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_HORIZ)
    vbox.pack_end(sl)
    sl.show()

    ck = Check(win, text="Resize on rotate", size_hint_align=(0.0, 0.0))
    vbox.pack_end(ck)
    ck.show()

    hbox = Box(win, horizontal=True, size_hint_align=FILL_HORIZ,
        size_hint_weight=EXPAND_HORIZ)
    vbox.pack_end(hbox)
    hbox.show()

    for rot in [0, 90, 180, 270]:
        bt = Button(win, text="Rot " + str(rot), size_hint_align=FILL_HORIZ,
                    size_hint_weight=EXPAND_HORIZ)
        bt.callback_clicked_add(cb_rot, win, ck, rot)
        hbox.pack_end(bt)
        bt.show()

    win.show()


if __name__ == "__main__":

    window_states_clicked(None)

    elementary.run()