summaryrefslogtreecommitdiff
path: root/efl/edje/efl.edje_edit.pyx
blob: 224f12a596f8792226b2682c91bd2701f70597cf (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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# 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 2.1 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/>.

from efl.eo cimport _touni, _ctouni, convert_eina_list_strings_to_python_list
from efl.edje cimport Edje_Part_Type
from efl.edje import EDJE_PART_TYPE_EXTERNAL


# Edje_Edit_Image_Comp
EDJE_EDIT_IMAGE_COMP_RAW   = 0
EDJE_EDIT_IMAGE_COMP_USER  = 1
EDJE_EDIT_IMAGE_COMP_COMP  = 2
EDJE_EDIT_IMAGE_COMP_LOSSY = 3


cdef class EdjeEdit(Edje):

    def __init__(self, Canvas canvas not None, **kargs):
        self._set_obj(edje_edit_object_add(canvas.obj))
        self._set_common_params(**kargs)

    # General
    def compiler_get(self):
        cdef const_char *s = edje_edit_compiler_get(self.obj)
        r = _ctouni(s)
        if s != NULL:
            edje_edit_string_free(s)
        return r

    def save(self):
        return bool(edje_edit_save(self.obj))

    def save_all(self):
        return bool(edje_edit_save_all(self.obj))

    def print_internal_status(self):
        edje_edit_print_internal_status(self.obj)

    # Group
    property current_group:
        def __get__(self):
            return Group(self)

    def group_add(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        return bool(edje_edit_group_add(self.obj,
                        <const_char *>name if name is not None else NULL))

    def group_del(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        return bool(edje_edit_group_del(self.obj,
                        <const_char *>name if name is not None else NULL))

    def group_exist(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        return bool(edje_edit_group_exist(self.obj,
                        <const_char *>name if name is not None else NULL))

    # Data
    property data:
        def __get__(self):
            cdef:
                Eina_List *lst
                list ret
            lst = edje_edit_data_list_get(self.obj)
            ret = convert_eina_list_strings_to_python_list(lst)
            edje_edit_string_list_free(lst)
            return ret

    def data_get(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        cdef const_char *val = edje_edit_data_value_get(self.obj,
                               <const_char *>name if name is not None else NULL)
        r = _ctouni(val)
        edje_edit_string_free(val)
        return r

    def data_set(self, name, value):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        if isinstance(value, unicode): value = value.encode("UTF-8")

        return bool(edje_edit_data_value_set(self.obj,
                        <const_char *>name if name is not None else NULL,
                        <const_char *>value if value is not None else NULL))

    def data_add(self, name, value):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        if isinstance(value, unicode): value = value.encode("UTF-8")
        return bool(edje_edit_data_add(self.obj,
                        <const_char *>name if name is not None else NULL,
                        <const_char *>value if value is not None else NULL))

    def data_rename(self, old, new):
        if isinstance(old, unicode): old = old.encode("UTF-8")
        if isinstance(new, unicode): new = new.encode("UTF-8")
        return bool(edje_edit_data_name_set(self.obj,
                        <const_char *>old if old is not None else NULL,
                        <const_char *>new if new is not None else NULL))

    def data_del(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        return bool(edje_edit_data_del(self.obj,
                        <const_char *>name if name is not None else NULL))

    # Group Data
    property group_data:
        def __get__(self):
            cdef:
                Eina_List *lst
                list ret
            lst = edje_edit_group_data_list_get(self.obj)
            ret = convert_eina_list_strings_to_python_list(lst)
            edje_edit_string_list_free(lst)
            return ret

    def group_data_get(self, name):
        cdef const_char *val
        if isinstance(name, unicode): name = name.encode("UTF-8")
        val = edje_edit_group_data_value_get(self.obj,
                    <const_char *>name if name is not None else NULL)
        r = _ctouni(val)
        edje_edit_string_free(val)
        return r

    def group_data_set(self, name, value):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        if isinstance(value, unicode): value = value.encode("UTF-8")
        return bool(edje_edit_group_data_value_set(self.obj,
                        <const_char *>name if name is not None else NULL,
                        <const_char *>value if value is not None else NULL))

    def group_data_add(self, name, value):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        if isinstance(value, unicode): value = value.encode("UTF-8")
        return bool(edje_edit_group_data_add(self.obj,
                        <const_char *>name if name is not None else NULL,
                        <const_char *>value if value is not None else NULL))

    def group_data_rename(self, old, new):
        if isinstance(old, unicode): old = old.encode("UTF-8")
        if isinstance(new, unicode): new = new.encode("UTF-8")
        return bool(edje_edit_group_data_name_set(self.obj,
                        <const_char *>old if old is not None else NULL,
                        <const_char *>new if new is not None else NULL))

    def group_data_del(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        return bool(edje_edit_group_data_del(self.obj,
                        <const_char *>name if name is not None else NULL))

    # Text Style
    property text_styles:
        def __get__(self):
            cdef Eina_List *lst
            lst = edje_edit_styles_list_get(self.obj)
            ret = convert_eina_list_strings_to_python_list(lst)
            edje_edit_string_list_free(lst)
            return ret

    def text_style_get(self, name):
        return Text_Style(self, name)

    def text_style_add(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        return bool(edje_edit_style_add(self.obj,
                        <const_char *>name if name is not None else NULL))

    def text_style_del(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        edje_edit_style_del(self.obj,
                            <const_char *>name if name is not None else NULL)
        return True

    # Color Classes
    property color_classes:
        def __get__(self):
            cdef Eina_List *lst
            lst = edje_edit_color_classes_list_get(self.obj)
            ret = convert_eina_list_strings_to_python_list(lst)
            edje_edit_string_list_free(lst)
            return ret

    def color_class_get(self, name):
        return Color_Class(self, name)

    def color_class_add(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        return bool(edje_edit_color_class_add(self.obj,
                            <const_char *>name if name is not None else NULL))

    def color_class_del(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        return bool(edje_edit_color_class_del(self.obj,
                            <const_char *>name if name is not None else NULL))

    # Externals
    property externals:
        def __get__(self):
            cdef Eina_List *lst
            lst = edje_edit_externals_list_get(self.obj)
            ret = convert_eina_list_strings_to_python_list(lst)
            edje_edit_string_list_free(lst)
            return ret

    def external_add(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        return bool(edje_edit_external_add(self.obj,
                            <const_char *>name if name is not None else NULL))

    def external_del(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        return bool(edje_edit_external_del(self.obj,
                            <const_char *>name if name is not None else NULL))

    # Fonts
    property fonts:
        def __get__(self):
            cdef Eina_List *lst
            lst = edje_edit_fonts_list_get(self.obj)
            ret = convert_eina_list_strings_to_python_list(lst)
            edje_edit_string_list_free(lst)
            return ret

    def font_add(self, font, alias=None):
        if isinstance(font, unicode): font = font.encode("UTF-8")
        if isinstance(alias, unicode): alias = alias.encode("UTF-8")
        return bool(edje_edit_font_add(self.obj,
                        <const_char *>font if font is not None else NULL,
                        <const_char *>alias if alias is not None else NULL))

    def font_del(self, alias):
        if isinstance(alias, unicode): alias = alias.encode("UTF-8")
        return bool(edje_edit_font_del(self.obj,
                        <const_char *>alias if alias is not None else NULL))

    # Parts
    property parts:
        def __get__(self):
            cdef Eina_List *lst
            lst = edje_edit_parts_list_get(self.obj)
            ret = convert_eina_list_strings_to_python_list(lst)
            edje_edit_string_list_free(lst)
            return ret

    def part_get(self, name):
        if self.part_exist(name):
            return Part(self, name)
        return None

    def part_add(self, name, int type, char *source=""):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        if type != EDJE_PART_TYPE_EXTERNAL:
            return bool(edje_edit_part_add(self.obj,
                               <const_char *>name if name is not None else NULL,
                               <Edje_Part_Type>type))
        else:
            return bool(edje_edit_part_external_add(self.obj, name, source))

    def part_del(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        return bool(edje_edit_part_del(self.obj,
                            <const_char *>name if name is not None else NULL))

    def part_exist(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        return bool(edje_edit_part_exist(self.obj,
                            <const_char *>name if name is not None else NULL))

    # Images
    property images:
        def __get__(self):
            cdef Eina_List *lst
            lst = edje_edit_images_list_get(self.obj)
            ret = convert_eina_list_strings_to_python_list(lst)
            edje_edit_string_list_free(lst)
            return ret

    def image_id_get(self, image):
        if isinstance(image, unicode): image = image.encode("UTF-8")
        return edje_edit_image_id_get(self.obj,
                    <const_char *>image if image is not None else NULL)

    def image_add(self, path):
        if isinstance(path, unicode): path = path.encode("UTF-8")
        return bool(edje_edit_image_add(self.obj,
                    <const_char *>path if path is not None else NULL))

    def image_del(self, image):
        if isinstance(image, unicode): image = image.encode("UTF-8")
        return bool(edje_edit_image_del(self.obj,
                    <const_char *>image if image is not None else NULL))

    # Programs
    property programs:
        def __get__(self):
            cdef Eina_List *lst
            lst = edje_edit_programs_list_get(self.obj)
            ret = convert_eina_list_strings_to_python_list(lst)
            edje_edit_string_list_free(lst)
            return ret

    def program_get(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        if self.program_exist(name):
            return Program(self, name)
        return None

    def program_add(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        return bool(edje_edit_program_add(self.obj,
                            <const_char *>name if name is not None else NULL))

    def program_del(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        return bool(edje_edit_program_del(self.obj,
                            <const_char *>name if name is not None else NULL))

    def program_exist(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        return bool(edje_edit_program_exist(self.obj,
                            <const_char *>name if name is not None else NULL))
    """
    property error:
        def __get__(self):
            last_error = c_evas.eina_error_get()
            if last_error:
               return c_evas.eina_error_msg_get(last_error)

            return None
    """

    # Scripts
    property script:
        def __get__(self):
            cdef char *code
            code = edje_edit_script_get(self.obj)
            ret = _touni(code)
            free(code)
            return ret

        def __set__(self, code):
            if isinstance(code, unicode): code = code.encode("UTF-8")
            edje_edit_script_set(self.obj,
                            <char *>code if code is not None else NULL)

        def __del__(self):
            edje_edit_script_set(self.obj, NULL)

    def script_compile(self):
        return bool(edje_edit_script_compile(self.obj))

    property script_errors:
        def __get__(self):
            cdef const_Eina_List *lst
            cdef Edje_Edit_Script_Error *se
            ret = []
            lst = edje_edit_script_error_list_get(self.obj)
            while lst:
                se = <Edje_Edit_Script_Error*>lst.data
                if se.program_name != NULL:
                    pr = se.program_name
                else:
                    pr = ''
                err = (pr, _ctouni(se.error_str))
                ret.append(err)
                lst = lst.next
            return ret


cdef class Text_Style(object):
    cdef EdjeEdit edje
    cdef object name

    def __init__(self, EdjeEdit e, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        self.edje = e
        self.name = name

    property tags:
        def __get__(self):
            cdef Eina_List *lst
            lst = edje_edit_style_tags_list_get(self.edje.obj,
                    <const_char *>self.name if self.name is not None else NULL)
            ret = convert_eina_list_strings_to_python_list(lst)
            edje_edit_string_list_free(lst)
            return ret

    def tag_get(self, name):
        return Text_Style_Tag(self, name)

    def tag_add(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        return bool(edje_edit_style_tag_add(self.edje.obj, self.name,
                              <const_char *>name if name is not None else NULL))

    def tag_del(self, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        edje_edit_style_tag_del(self.edje.obj, self.name,
                               <const_char *>name if name is not None else NULL)
        return True


cdef class Text_Style_Tag(object):
    cdef Text_Style text_style
    cdef object name

    def __init__(self, Text_Style text_style, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        self.text_style = text_style
        self.name = name

    property value:
        def __get__(self):
            cdef const_char *val
            val =  edje_edit_style_tag_value_get(self.text_style.edje.obj,
                    self.text_style.name,
                    <const_char *>self.name if self.name is not None else NULL)
            ret = _ctouni(val)
            edje_edit_string_free(val)
            return ret
        def __set__(self, value):
            if isinstance(value, unicode): value = value.encode("UTF-8")
            edje_edit_style_tag_value_set(self.text_style.edje.obj,
                            self.text_style.name, self.name,
                            <const_char *>value if value is not None else NULL)

    def rename(self, newname):
        if isinstance(newname, unicode): newname = newname.encode("UTF-8")
        edje_edit_style_tag_name_set(self.text_style.edje.obj,
                        self.text_style.name,
                        <const_char *>self.name if self.name is not None else NULL,
                        <const_char *>newname if newname is not None else NULL)
        self.name = <const_char *>newname if newname is not None else NULL
        return True


cdef class Color_Class(object):
    cdef EdjeEdit edje
    cdef object name

    def __init__(self, EdjeEdit e, name):
        if isinstance(name, unicode): name = name.encode("UTF-8")
        self.edje = e
        self.name = name

    property name:
        def __get__(self):
            return self.name.decode('UTF-8', 'strict')

        def __set__(self, newname):
            self.rename(newname)

    def rename(self, newname):
        cdef Eina_Bool ret
        if isinstance(newname, unicode): newname = newname.encode("UTF-8")
        ret = edje_edit_color_class_name_set(self.edje.obj,
                        <const_char *>self.name if self.name is not None else NULL,
                        <const_char *>newname if newname is not None else NULL)
        if ret == 0:
            return False
        self.name = newname
        return True

    def colors_get(self):
        cdef int r, g, b, a, r2, g2, b2, a2, r3, g3, b3, a3
        edje_edit_color_class_colors_get(self.edje.obj, self.name,
                        &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 colors_set(self, int r, int g, int b, int a,
                         int r2, int g2, int b2, int a2,
                         int r3, int g3, int b3, int a3):
        edje_edit_color_class_colors_set(self.edje.obj, self.name,
                                    r, g, b, a, r2, g2, b2, a2, r3, g3, b3, a3)


include "efl.edje_edit_group.pxi"
include "efl.edje_edit_part.pxi"
include "efl.edje_edit_part_state.pxi"
include "efl.edje_edit_program.pxi"