summaryrefslogtreecommitdiff
path: root/edje/edje.c_edje.pyx
blob: 18ef5881b6d6ec73b124706ec52352de586fbe3a (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
# Copyright (C) 2007-2008 Gustavo Sverzut Barbieri, Ulisses Furquim
#
# This file is part of Python-Edje.
#
# Python-Edje 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 2.1 of the License, or (at your option) any later version.
#
# Python-Edje 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-Edje.  If not, see <http://www.gnu.org/licenses/>.

from cpython cimport PyObject, Py_INCREF, Py_DECREF
from cpython cimport PyMem_Malloc, PyMem_Free
from cpython cimport bool
cimport libc.stdlib
cimport evas.c_evas
import evas.c_evas

__extra_epydoc_fields__ = (
    ("parm", "Parameter", "Parameters"), # epydoc don't support pyrex properly
    )

cdef int PY_REFCOUNT(object o):
    cdef PyObject *obj = <PyObject *>o
    return obj.ob_refcnt

cdef unicode _touni(char* s):
    return s.decode('UTF-8', 'strict')

cdef char* _fruni(s):
    cdef char* c_string
    if isinstance(s, unicode):
        string = s.encode('UTF-8')
        c_string = string
    elif isinstance(s, str):
        c_string = s
    else:
        raise TypeError("Expected str or unicode object, got %s" % (type(s).__name__))
    return c_string

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):
    "Set time between frames."
    edje_frametime_set(t)


def frametime_get():
    "@rtype: float"
    return edje_frametime_get()


def freeze():
    """Freeze all Edje objects in the current process.

    @see: L{Edje.freeze()}
    """
    edje_freeze()


def thaw():
    """Thaw all Edje objects in the current process.

    @see: L{Edje.thaw()}
    """
    edje_thaw()


def fontset_append_set(char *fonts):
    edje_fontset_append_set(fonts)


def fontset_append_get():
    "@rtype: str"
    cdef const_char_ptr s
    s = edje_fontset_append_get()
    if s != NULL:
        return s


def file_collection_list(char *file):
    "@rtype: list of str"
    cdef evas.c_evas.Eina_List *lst, *itr
    ret = []
    lst = edje_file_collection_list(file)
    itr = lst
    while itr:
        ret.append(<char*>itr.data)
        itr = itr.next
    edje_file_collection_list_free(lst)
    return ret


def file_group_exists(char *file, char *group):
    """Check if file contains the given group.

    @parm: B{file}
    @parm: B{group}
    @rtype: bool
    """
    return bool(edje_file_group_exists(file, group))


def file_data_get(char *file, char *key):
    """Check if file contains the given group.

    @parm: B{file}
    @parm: B{key}
    @rtype: str
    """
    cdef char *s
    s = edje_file_data_get(file, key)
    if s != NULL:
        return s


def file_cache_set(int count):
    edje_file_cache_set(count)


def file_cache_get():
    "@rtype: int"
    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():
    "@rtype: int"
    return edje_collection_cache_get()


def collection_cache_flush():
    edje_collection_cache_flush()


def color_class_set(char *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):
    """Set color class.

    @parm: B{color_class} color class name.
    @parm: B{r}
    @parm: B{g}
    @parm: B{b}
    @parm: B{a}
    @parm: B{r2}
    @parm: B{g2}
    @parm: B{b2}
    @parm: B{a2}
    @parm: B{r3}
    @parm: B{g3}
    @parm: B{b3}
    @parm: B{a3}
    """
    edje_color_class_set(color_class,
                         r, g, b, a,
                         r2, g2, b2, a2,
                         r3, g3, b3, a3)


def color_class_del(char *color_class):
    edje_color_class_del(color_class)


def color_class_list():
    "@rtype: list of str"
    cdef evas.c_evas.Eina_List *lst, *itr
    ret = []
    lst = edje_color_class_list()
    itr = lst
    while itr:
        ret.append(<char*>itr.data)
        libc.stdlib.free(itr.data)
        itr = itr.next
    evas.c_evas.eina_list_free(lst)
    return ret


def text_class_set(char *text_class, char *font, int size):
    """Set text class.

    @parm: B{text_class} text class name.
    @parm: B{font}
    @parm: B{size}
    """
    edje_text_class_set(text_class, font, size)


def text_class_del(char *text_class):
    edje_text_class_del(text_class)


def text_class_list():
    "@rtype: list of str"
    cdef evas.c_evas.Eina_List *lst, *itr
    ret = []
    lst = edje_text_class_list()
    itr = lst
    while itr:
        ret.append(<char*>itr.data)
        libc.stdlib.free(itr.data)
        itr = itr.next
    evas.c_evas.eina_list_free(lst)
    return ret


def message_signal_process():
    "Force iteration of Edje's message system."
    edje_message_signal_process()


def extern_object_min_size_set(evas.c_evas.Object obj, int w, int h):
    """Set minimum size of an external object.

    If this object is already swallowed, it will trigger edje to recalculate
    it's objects geometries.
    """
    edje_extern_object_min_size_set(obj.obj, w, h)


def extern_object_max_size_set(evas.c_evas.Object obj, int w, int h):
    """Set maximum size of an external object.

    If this object is already swallowed, it will trigger edje to recalculate
    it's objects geometries.
    """
    edje_extern_object_max_size_set(obj.obj, w, h)


def extern_object_aspect_set(evas.c_evas.Object obj, int aspect, int w, int h):
    """Set aspect size of an external object.

    This sets the desired aspect ratio to keep an object that will be
    swallowed by Edje. The width and height define a preferred size ASPECT
    and the object may be scaled to be larger or smaller, but retaining the
    relative scale of both aspect width and height.

    Known aspect ratios:
     - 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

    If this object is already swallowed, it will trigger edje to recalculate
    it's objects geometries.
    """
    edje_extern_object_aspect_set(obj.obj, <Edje_Aspect_Control>aspect, w, h)

def available_modules_get():
    cdef evas.c_evas.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(char *name):
    return bool(edje_module_load(name))

class EdjeObjectMeta(evas.c_evas.EvasObjectMeta):
    def __init__(cls, name, bases, dict_):
        evas.c_evas.EvasObjectMeta.__init__(cls, name, bases, dict_)
        cls._fetch_callbacks()

    def _fetch_callbacks(cls):
        if "__edje_signal_callbacks__" in cls.__dict__:
            return

        cls.__edje_signal_callbacks__ = []
        cls.__edje_message_callbacks__ = []
        cls.__edje_text_callbacks__ = []

        sig_append = cls.__edje_signal_callbacks__.append
        msg_append = cls.__edje_message_callbacks__.append
        txt_append = cls.__edje_text_callbacks__.append

        for name in dir(cls):
            val = getattr(cls, name)
            if not callable(val):
                continue

            if hasattr(val, "edje_signal_callback"):
                sig_data = getattr(val, "edje_signal_callback")
                sig_append((name, sig_data))
            elif hasattr(val, "edje_message_handler"):
                msg_append(name)
            elif hasattr(val, "edje_text_change_callback"):
                txt_append(name)

include "edje.c_edje_message.pxi"
include "edje.c_edje_external.pxi"
include "edje.c_edje_object.pxi"