summaryrefslogtreecommitdiff
path: root/efl/edje/efl.edje.pyx
blob: 1203f0215aea62bf08aa0e80548ab66d2466960b (plain)
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
# Copyright (C) 2007-2013 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 this Python-EFL.  If not, see <http://www.gnu.org/licenses/>.

import traceback
import warnings

from cpython cimport PyMem_Malloc, PyMem_Free, PyUnicode_AsUTF8String
cimport libc.stdlib
from libc.stdint cimport uintptr_t

from efl.eo cimport _object_mapping_register, object_from_instance, \
    _register_decorated_callbacks

from efl.utils.conversions cimport _ctouni, _touni, \
    eina_list_strings_to_python_list


# Edje_Message_Type:
EDJE_MESSAGE_NONE             = 0
EDJE_MESSAGE_SIGNAL           = 1
EDJE_MESSAGE_STRING           = 2
EDJE_MESSAGE_INT              = 3
EDJE_MESSAGE_FLOAT            = 4
EDJE_MESSAGE_STRING_SET       = 5
EDJE_MESSAGE_INT_SET          = 6
EDJE_MESSAGE_FLOAT_SET        = 7
EDJE_MESSAGE_STRING_INT       = 8
EDJE_MESSAGE_STRING_FLOAT     = 9
EDJE_MESSAGE_STRING_INT_SET   = 10
EDJE_MESSAGE_STRING_FLOAT_SET = 11

# Edje_Aspect_Control:
EDJE_ASPECT_CONTROL_NONE       = 0
EDJE_ASPECT_CONTROL_NEITHER    = 1
EDJE_ASPECT_CONTROL_HORIZONTAL = 2
EDJE_ASPECT_CONTROL_VERTICAL   = 3
EDJE_ASPECT_CONTROL_BOTH       = 4

# Edje_Drag_Dir:
EDJE_DRAG_DIR_NONE = 0
EDJE_DRAG_DIR_X    = 1
EDJE_DRAG_DIR_Y    = 2
EDJE_DRAG_DIR_XY   = 3

# Edje_Load_Error:
EDJE_LOAD_ERROR_NONE                       = 0
EDJE_LOAD_ERROR_GENERIC                    = 1
EDJE_LOAD_ERROR_DOES_NOT_EXIST             = 2
EDJE_LOAD_ERROR_PERMISSION_DENIED          = 3
EDJE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED = 4
EDJE_LOAD_ERROR_CORRUPT_FILE               = 5
EDJE_LOAD_ERROR_UNKNOWN_FORMAT             = 6
EDJE_LOAD_ERROR_INCOMPATIBLE_FILE          = 7
EDJE_LOAD_ERROR_UNKNOWN_COLLECTION         = 8

# Edje_Part_Type:
EDJE_PART_TYPE_NONE      = 0
EDJE_PART_TYPE_RECTANGLE = 1
EDJE_PART_TYPE_TEXT      = 2
EDJE_PART_TYPE_IMAGE     = 3
EDJE_PART_TYPE_SWALLOW   = 4
EDJE_PART_TYPE_TEXTBLOCK = 5
EDJE_PART_TYPE_GRADIENT  = 6
EDJE_PART_TYPE_GROUP     = 7
EDJE_PART_TYPE_BOX       = 8
EDJE_PART_TYPE_TABLE     = 9
EDJE_PART_TYPE_EXTERNAL  = 10
EDJE_PART_TYPE_LAST      = 11

# Edje_Text_Effect:
EDJE_TEXT_EFFECT_NONE                = 0
EDJE_TEXT_EFFECT_PLAIN               = 1
EDJE_TEXT_EFFECT_OUTLINE             = 2
EDJE_TEXT_EFFECT_SOFT_OUTLINE        = 3
EDJE_TEXT_EFFECT_SHADOW              = 4
EDJE_TEXT_EFFECT_SOFT_SHADOW         = 5
EDJE_TEXT_EFFECT_OUTLINE_SHADOW      = 6
EDJE_TEXT_EFFECT_OUTLINE_SOFT_SHADOW = 7
EDJE_TEXT_EFFECT_FAR_SHADOW          = 8
EDJE_TEXT_EFFECT_FAR_SOFT_SHADOW     = 9
EDJE_TEXT_EFFECT_GLOW                = 10
EDJE_TEXT_EFFECT_LAST                = 11

# Edje_Action_Type:
EDJE_ACTION_TYPE_NONE          = 0
EDJE_ACTION_TYPE_STATE_SET     = 1
EDJE_ACTION_TYPE_ACTION_STOP   = 2
EDJE_ACTION_TYPE_SIGNAL_EMIT   = 3
EDJE_ACTION_TYPE_DRAG_VAL_SET  = 4
EDJE_ACTION_TYPE_DRAG_VAL_STEP = 5
EDJE_ACTION_TYPE_DRAG_VAL_PAGE = 6
EDJE_ACTION_TYPE_SCRIPT        = 7
EDJE_ACTION_TYPE_FOCUS_SET     = 8
EDJE_ACTION_TYPE_LUA_SCRIPT    = 9
EDJE_ACTION_TYPE_LAST          = 10

# Edje_Tween_Mode:
EDJE_TWEEN_MODE_NONE       = 0
EDJE_TWEEN_MODE_LINEAR     = 1
EDJE_TWEEN_MODE_SINUSOIDAL = 2
EDJE_TWEEN_MODE_ACCELERATE = 3
EDJE_TWEEN_MODE_DECELERATE = 4
EDJE_TWEEN_MODE_LAST       = 5

# Edje_External_Param_Type:
EDJE_EXTERNAL_PARAM_TYPE_INT    = 0
EDJE_EXTERNAL_PARAM_TYPE_DOUBLE = 1
EDJE_EXTERNAL_PARAM_TYPE_STRING = 2
EDJE_EXTERNAL_PARAM_TYPE_BOOL   = 3
EDJE_EXTERNAL_PARAM_TYPE_CHOICE = 4
EDJE_EXTERNAL_PARAM_TYPE_MAX    = 5



def init():
    cdef int r = edje_init()

    if edje_external_type_abi_version_get() != EDJE_EXTERNAL_TYPE_ABI_VERSION:
        raise TypeError("python-edje Edje_External_Type abi_version differs "
                        "from libedje.so. Recompile python-edje!")
    return r


def shutdown():
    return edje_shutdown()


def frametime_set(double t):
    edje_frametime_set(t)


def frametime_get():
    return edje_frametime_get()


def freeze():
    edje_freeze()


def thaw():
    edje_thaw()


def fontset_append_set(fonts):
    if isinstance(fonts, unicode): fonts = PyUnicode_AsUTF8String(fonts)
    edje_fontset_append_set(<const char *>fonts if fonts is not None else NULL)


def fontset_append_get():
    return _ctouni(edje_fontset_append_get())


def file_collection_list(file):
    cdef Eina_List *lst
    if isinstance(file, unicode): file = PyUnicode_AsUTF8String(file)
    lst = edje_file_collection_list(
                <const char *>file if file is not None else NULL)
    ret = eina_list_strings_to_python_list(lst)
    edje_file_collection_list_free(lst)
    return ret


def file_group_exists(file, group):
    if isinstance(file, unicode): file = PyUnicode_AsUTF8String(file)
    if isinstance(group, unicode): group = PyUnicode_AsUTF8String(group)
    return bool(edje_file_group_exists(
            <const char *>file if file is not None else NULL,
            <const char *>group if group is not None else NULL))


def file_data_get(file, key):
    cdef char *s
    if isinstance(file, unicode): file = PyUnicode_AsUTF8String(file)
    if isinstance(key, unicode): key = PyUnicode_AsUTF8String(key)
    s = edje_file_data_get(
                <const char *>file if file is not None else NULL,
                <const char *>key if key is not None else NULL)
    ret = _touni(s)
    libc.stdlib.free(s)
    return ret


def file_cache_set(int count):
    edje_file_cache_set(count)


def file_cache_get():
    return edje_file_cache_get()


def file_cache_flush():
    edje_file_cache_flush()


def collection_cache_set(int count):
    edje_collection_cache_set(count)


def collection_cache_get():
    return edje_collection_cache_get()


def collection_cache_flush():
    edje_collection_cache_flush()

def scale_set(double scale):
    edje_scale_set(scale)

def scale_get():
    return edje_scale_get()

def password_show_last_set(int show_last):
    edje_password_show_last_set(show_last)

def password_show_last_timeout_set(double timeout):
    edje_password_show_last_timeout_set(timeout)

def color_class_set(color_class,
                    int r, int g, int b, int a,
                    int r2, int g2, int b2, int a2,
                    int r3, int g3, int b3, int a3):
    if isinstance(color_class, unicode):
        color_class = PyUnicode_AsUTF8String(color_class)
    edje_color_class_set(
            <const char *>color_class if color_class is not None else NULL,
            r, g, b, a, r2, g2, b2, a2, r3, g3, b3, a3)


def color_class_get(color_class):
    cdef int r, g, b, a
    cdef int r2, g2, b2, a2
    cdef int r3, g3, b3, a3
    if isinstance(color_class, unicode):
        color_class = PyUnicode_AsUTF8String(color_class)
    edje_color_class_get(
            <const char *>color_class if color_class is not None else NULL,
            &r, &g, &b, &a, &r2, &g2, &b2, &a2, &r3, &g3, &b3, &a3)
    return (r, g, b, a, r2, g2, b2, a2, r3, g3, b3, a3)


def color_class_del(color_class):
    if isinstance(color_class, unicode):
        color_class = PyUnicode_AsUTF8String(color_class)
    edje_color_class_del(
        <const char *>color_class if color_class is not None else NULL)


def color_class_list():
    cdef:
        Eina_List *lst
        Eina_List *itr
    ret = []
    lst = edje_color_class_list()
    itr = lst
    while itr:
        ret.append(_touni(<char*>itr.data))
        libc.stdlib.free(itr.data)
        itr = itr.next
    eina_list_free(lst)
    return ret


def text_class_set(text_class, font, int size):
    if isinstance(text_class, unicode):
        text_class = PyUnicode_AsUTF8String(text_class)
    if isinstance(font, unicode):
        font = PyUnicode_AsUTF8String(font)
    edje_text_class_set(
        <const char *>text_class if text_class is not None else NULL,
        <const char *>font if font is not None else NULL,
        size)


def text_class_del(text_class):
    if isinstance(text_class, unicode): text_class = PyUnicode_AsUTF8String(text_class)
    edje_text_class_del(
        <const char *>text_class if text_class is not None else NULL)


def text_class_list():
    cdef:
        Eina_List *lst
        Eina_List *itr
    ret = []
    lst = edje_text_class_list()
    itr = lst
    while itr:
        ret.append(_touni(<char*>itr.data))
        eina_stringshare_del(<Eina_Stringshare*>itr.data)
        itr = itr.next
    eina_list_free(lst)
    return ret


def message_signal_process():
    edje_message_signal_process()


def extern_object_min_size_set(Object obj, int w, int h):
    edje_extern_object_min_size_set(obj.obj, w, h)


def extern_object_max_size_set(Object obj, int w, int h):
    edje_extern_object_max_size_set(obj.obj, w, h)


def extern_object_aspect_set(Object obj, int aspect, int w, int h):
    edje_extern_object_aspect_set(obj.obj, <Edje_Aspect_Control>aspect, w, h)


def available_modules_get():
    cdef const Eina_List *lst
    lst = edje_available_modules_get()
    ret = []
    while lst:
        ret.append(<char*>lst.data)
        lst = lst.next
    return ret


def module_load(name):
    if isinstance(name, unicode): name = PyUnicode_AsUTF8String(name)
    return bool(edje_module_load(
                    <const char *>name if name is not None else NULL))


include "efl.edje_message.pxi"
include "efl.edje_external.pxi"
include "efl.edje_object.pxi"


init()