kuuko pushed a commit to branch master. http://git.enlightenment.org/bindings/python/python-efl.git/commit/?id=5f4a46da4b725329495366130b4ef03ebaa1d376
commit 5f4a46da4b725329495366130b4ef03ebaa1d376 Author: Kai Huuhko <[email protected]> Date: Tue Oct 1 04:56:28 2013 +0300 Move common conversion functions from efl.eo to efl.utils.conversions --- efl/ecore/efl.ecore.pyx | 3 +- efl/edje/efl.edje.pyx | 8 ++- efl/edje/efl.edje_edit.pyx | 23 +++---- efl/edje/efl.edje_edit_part.pxi | 2 +- efl/edje/efl.edje_edit_program.pxi | 4 +- efl/elementary/box.pyx | 6 +- efl/elementary/calendar_elm.pyx | 8 +-- efl/elementary/configuration.pyx | 4 +- efl/elementary/dayselector.pyx | 8 +-- efl/elementary/general.pyx | 9 +-- efl/elementary/grid.pyx | 6 +- efl/elementary/object.pyx | 6 +- efl/elementary/object_item.pyx | 8 +-- efl/elementary/slideshow.pyx | 6 +- efl/elementary/theme.pyx | 10 +-- efl/elementary/transit.pyx | 9 +-- efl/elementary/widget_header.pxi | 5 +- efl/elementary/window.pyx | 8 +-- efl/emotion/efl.emotion.pyx | 3 +- efl/eo/efl.eo.pyx | 104 ------------------------------ efl/evas/efl.evas.pyx | 4 +- efl/evas/efl.evas_object_grid.pxi | 2 +- efl/evas/efl.evas_object_table.pxi | 4 +- efl/utils/conversions.pyx | 129 +++++++++++++++++++++++++++++++++++++ include/efl.c_eo.pxd | 16 ++--- include/efl.eo.pxd | 10 --- include/efl.utils.conversions.pxd | 12 ++++ setup.py | 10 ++- 28 files changed, 230 insertions(+), 197 deletions(-) diff --git a/efl/ecore/efl.ecore.pyx b/efl/ecore/efl.ecore.pyx index 6791cd1..8b78681 100644 --- a/efl/ecore/efl.ecore.pyx +++ b/efl/ecore/efl.ecore.pyx @@ -201,7 +201,8 @@ File monitor events """ import traceback -from efl.eo cimport Eo, PY_REFCOUNT, _ctouni +from efl.eo cimport Eo, PY_REFCOUNT +from efl.utils.conversions cimport _ctouni from cpython cimport Py_INCREF, Py_DECREF cimport efl.ecore.enums as enums diff --git a/efl/edje/efl.edje.pyx b/efl/edje/efl.edje.pyx index 92087df..a24f5c1 100644 --- a/efl/edje/efl.edje.pyx +++ b/efl/edje/efl.edje.pyx @@ -22,8 +22,10 @@ from cpython cimport PyMem_Malloc, PyMem_Free, PyUnicode_AsUTF8String cimport libc.stdlib from efl.eo cimport _object_mapping_register, object_from_instance, \ - _register_decorated_callbacks, _ctouni, _touni, \ - convert_eina_list_strings_to_python_list + _register_decorated_callbacks + +from efl.utils.conversions cimport _ctouni, _touni, \ + eina_list_strings_to_python_list # Edje_Message_Type: @@ -166,7 +168,7 @@ def file_collection_list(file): if isinstance(file, unicode): file = PyUnicode_AsUTF8String(file) lst = edje_file_collection_list( <const_char *>file if file is not None else NULL) - ret = convert_eina_list_strings_to_python_list(lst) + ret = eina_list_strings_to_python_list(lst) edje_file_collection_list_free(lst) return ret diff --git a/efl/edje/efl.edje_edit.pyx b/efl/edje/efl.edje_edit.pyx index 20532c2..b9e21bb 100644 --- a/efl/edje/efl.edje_edit.pyx +++ b/efl/edje/efl.edje_edit.pyx @@ -15,7 +15,8 @@ # 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.utils.conversions cimport _touni, _ctouni, \ + eina_list_strings_to_python_list from efl.edje cimport Edje_Part_Type from efl.edje import EDJE_PART_TYPE_EXTERNAL @@ -77,7 +78,7 @@ cdef class EdjeEdit(Edje): Eina_List *lst list ret lst = edje_edit_data_list_get(self.obj) - ret = convert_eina_list_strings_to_python_list(lst) + ret = eina_list_strings_to_python_list(lst) edje_edit_string_list_free(lst) return ret @@ -123,7 +124,7 @@ cdef class EdjeEdit(Edje): Eina_List *lst list ret lst = edje_edit_group_data_list_get(self.obj) - ret = convert_eina_list_strings_to_python_list(lst) + ret = eina_list_strings_to_python_list(lst) edje_edit_string_list_free(lst) return ret @@ -167,7 +168,7 @@ cdef class EdjeEdit(Edje): def __get__(self): cdef Eina_List *lst lst = edje_edit_styles_list_get(self.obj) - ret = convert_eina_list_strings_to_python_list(lst) + ret = eina_list_strings_to_python_list(lst) edje_edit_string_list_free(lst) return ret @@ -190,7 +191,7 @@ cdef class EdjeEdit(Edje): 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) + ret = eina_list_strings_to_python_list(lst) edje_edit_string_list_free(lst) return ret @@ -212,7 +213,7 @@ cdef class EdjeEdit(Edje): def __get__(self): cdef Eina_List *lst lst = edje_edit_externals_list_get(self.obj) - ret = convert_eina_list_strings_to_python_list(lst) + ret = eina_list_strings_to_python_list(lst) edje_edit_string_list_free(lst) return ret @@ -231,7 +232,7 @@ cdef class EdjeEdit(Edje): def __get__(self): cdef Eina_List *lst lst = edje_edit_fonts_list_get(self.obj) - ret = convert_eina_list_strings_to_python_list(lst) + ret = eina_list_strings_to_python_list(lst) edje_edit_string_list_free(lst) return ret @@ -252,7 +253,7 @@ cdef class EdjeEdit(Edje): def __get__(self): cdef Eina_List *lst lst = edje_edit_parts_list_get(self.obj) - ret = convert_eina_list_strings_to_python_list(lst) + ret = eina_list_strings_to_python_list(lst) edje_edit_string_list_free(lst) return ret @@ -285,7 +286,7 @@ cdef class EdjeEdit(Edje): def __get__(self): cdef Eina_List *lst lst = edje_edit_images_list_get(self.obj) - ret = convert_eina_list_strings_to_python_list(lst) + ret = eina_list_strings_to_python_list(lst) edje_edit_string_list_free(lst) return ret @@ -309,7 +310,7 @@ cdef class EdjeEdit(Edje): def __get__(self): cdef Eina_List *lst lst = edje_edit_programs_list_get(self.obj) - ret = convert_eina_list_strings_to_python_list(lst) + ret = eina_list_strings_to_python_list(lst) edje_edit_string_list_free(lst) return ret @@ -397,7 +398,7 @@ cdef class Text_Style(object): def __get__(self): cdef Eina_List *lst lst = edje_edit_style_tags_list_get(self.edje.obj, self.name) - ret = convert_eina_list_strings_to_python_list(lst) + ret = eina_list_strings_to_python_list(lst) edje_edit_string_list_free(lst) return ret diff --git a/efl/edje/efl.edje_edit_part.pxi b/efl/edje/efl.edje_edit_part.pxi index 20b6a16..68562e6 100644 --- a/efl/edje/efl.edje_edit_part.pxi +++ b/efl/edje/efl.edje_edit_part.pxi @@ -77,7 +77,7 @@ cdef class Part(object): def __get__(self): cdef Eina_List *lst lst = edje_edit_part_states_list_get(self.edje.obj, self.name) - ret = convert_eina_list_strings_to_python_list(lst) + ret = eina_list_strings_to_python_list(lst) edje_edit_string_list_free(lst) return ret diff --git a/efl/edje/efl.edje_edit_program.pxi b/efl/edje/efl.edje_edit_program.pxi index 4ccfe90..072d0d0 100644 --- a/efl/edje/efl.edje_edit_program.pxi +++ b/efl/edje/efl.edje_edit_program.pxi @@ -99,7 +99,7 @@ cdef class Program(object): def targets_get(self): cdef Eina_List *lst lst = edje_edit_program_targets_get(self.edje.obj, self.name) - ret = convert_eina_list_strings_to_python_list(lst) + ret = eina_list_strings_to_python_list(lst) edje_edit_string_list_free(lst) return ret @@ -119,7 +119,7 @@ cdef class Program(object): def afters_get(self): cdef Eina_List *lst lst = edje_edit_program_afters_get(self.edje.obj, self.name) - ret = convert_eina_list_strings_to_python_list(lst) + ret = eina_list_strings_to_python_list(lst) edje_edit_string_list_free(lst) return ret diff --git a/efl/elementary/box.pyx b/efl/elementary/box.pyx index 498f516..0576bb3 100644 --- a/efl/elementary/box.pyx +++ b/efl/elementary/box.pyx @@ -129,7 +129,7 @@ include "widget_header.pxi" from object cimport Object -from efl.eo cimport _object_list_to_python +from efl.utils.conversions cimport eina_list_objects_to_python_list #~ ctypedef enum Elm_Box_CLayout: #~ ELM_BOX_LAYOUT_HORIZONTAL @@ -352,7 +352,7 @@ cdef class Box(Object): """ def __get__(self): - return _object_list_to_python(elm_box_children_get(self.obj)) + return eina_list_objects_to_python_list(elm_box_children_get(self.obj)) #def __set__(self, value): #TODO: unpack_all() and then get the objects from value and pack_end() them. @@ -361,7 +361,7 @@ cdef class Box(Object): elm_box_clear(self.obj) def children_get(self): - return _object_list_to_python(elm_box_children_get(self.obj)) + return eina_list_objects_to_python_list(elm_box_children_get(self.obj)) property padding: """The space (padding) between the box's elements. diff --git a/efl/elementary/calendar_elm.pyx b/efl/elementary/calendar_elm.pyx index f8ca34f..ab6b038 100644 --- a/efl/elementary/calendar_elm.pyx +++ b/efl/elementary/calendar_elm.pyx @@ -170,8 +170,8 @@ Days include "widget_header.pxi" from cpython cimport PyMem_Malloc, PyMem_Free -from efl.eo cimport convert_array_of_strings_to_python_list, \ - convert_python_list_strings_to_array_of_strings +from efl.utils.conversions cimport array_of_strings_to_python_list, \ + python_list_strings_to_array_of_strings from layout_class cimport LayoutClass from datetime import date @@ -314,12 +314,12 @@ cdef class Calendar(LayoutClass): """ def __get__(self): - return convert_array_of_strings_to_python_list( + return array_of_strings_to_python_list( <char **>elm_calendar_weekdays_names_get(self.obj), 7) def __set__(self, weekdays): elm_calendar_weekdays_names_set(self.obj, - convert_python_list_strings_to_array_of_strings(weekdays)) + python_list_strings_to_array_of_strings(weekdays)) property min_max_year: """The minimum and maximum values for the year diff --git a/efl/elementary/configuration.pyx b/efl/elementary/configuration.pyx index 83d87de..897c22e 100644 --- a/efl/elementary/configuration.pyx +++ b/efl/elementary/configuration.pyx @@ -103,7 +103,7 @@ Elm_Softcursor_Mode include "widget_header.pxi" -from efl.eo cimport convert_eina_list_strings_to_python_list +from efl.utils.conversions cimport eina_list_strings_to_python_list cimport enums @@ -199,7 +199,7 @@ cdef class Configuration(object): """ def __get__(self): cdef Eina_List *lst = elm_config_profile_list_get() - ret = tuple(convert_eina_list_strings_to_python_list(lst)) + ret = tuple(eina_list_strings_to_python_list(lst)) elm_config_profile_list_free(lst) return ret diff --git a/efl/elementary/dayselector.pyx b/efl/elementary/dayselector.pyx index 23ffbb1..641f391 100644 --- a/efl/elementary/dayselector.pyx +++ b/efl/elementary/dayselector.pyx @@ -109,8 +109,8 @@ Dayselector days include "widget_header.pxi" -from efl.eo cimport convert_python_list_strings_to_array_of_strings, \ - convert_eina_list_strings_to_python_list +from efl.utils.conversions cimport python_list_strings_to_array_of_strings, \ + eina_list_strings_to_python_list from layout_class cimport LayoutClass cimport enums @@ -218,10 +218,10 @@ cdef class Dayselector(LayoutClass): def __set__(self, list weekdays): # TODO: Add checks for list validity (len == 7 etc.) elm_dayselector_weekdays_names_set(self.obj, - convert_python_list_strings_to_array_of_strings(weekdays)) + python_list_strings_to_array_of_strings(weekdays)) def __get__(self): - return convert_eina_list_strings_to_python_list( + return eina_list_strings_to_python_list( elm_dayselector_weekdays_names_get(self.obj) ) diff --git a/efl/elementary/general.pyx b/efl/elementary/general.pyx index 57cd37f..bcd7915 100644 --- a/efl/elementary/general.pyx +++ b/efl/elementary/general.pyx @@ -50,8 +50,9 @@ Quit policy types from cpython cimport PyObject, Py_INCREF, Py_DECREF, PyUnicode_AsUTF8String, \ PyMem_Malloc, PyMem_Free -from efl.eo cimport _touni, _ctouni, convert_python_list_strings_to_eina_list, \ - convert_eina_list_strings_to_python_list +from efl.utils.conversions cimport _touni, _ctouni, \ + python_list_strings_to_eina_list, \ + eina_list_strings_to_python_list import sys import traceback @@ -162,10 +163,10 @@ cdef class FontProperties(object): property styles: """:type: list of strings""" def __set__(self, value): - self.efp.styles = convert_python_list_strings_to_eina_list(value) + self.efp.styles = python_list_strings_to_eina_list(value) def __get__(self): - return convert_eina_list_strings_to_python_list(self.efp.styles) + return eina_list_strings_to_python_list(self.efp.styles) def init(): diff --git a/efl/elementary/grid.pyx b/efl/elementary/grid.pyx index 44ea02c..da8d23b 100644 --- a/efl/elementary/grid.pyx +++ b/efl/elementary/grid.pyx @@ -38,7 +38,7 @@ of the width or height of the grid widget. include "widget_header.pxi" from object cimport Object -from efl.eo cimport _object_list_to_python +from efl.utils.conversions cimport eina_list_objects_to_python_list cdef class Grid(Object): @@ -121,10 +121,10 @@ cdef class Grid(Object): """ def __get__(self): - return _object_list_to_python(elm_grid_children_get(self.obj)) + return eina_list_objects_to_python_list(elm_grid_children_get(self.obj)) def children_get(self): - return _object_list_to_python(elm_grid_children_get(self.obj)) + return eina_list_objects_to_python_list(elm_grid_children_get(self.obj)) def grid_pack_set(evasObject subobj, x, y, w, h): """grid_pack_set(evas.Object subobj, int x, int y, int w, int h) diff --git a/efl/elementary/object.pyx b/efl/elementary/object.pyx index 05c4ac1..b434303 100644 --- a/efl/elementary/object.pyx +++ b/efl/elementary/object.pyx @@ -189,7 +189,7 @@ from cpython cimport PyObject, Py_INCREF, Py_DECREF, PyObject_GetAttr, \ include "widget_header.pxi" include "tooltips.pxi" -from efl.eo cimport _object_list_to_python +from efl.utils.conversions cimport eina_list_objects_to_python_list from efl.utils.deprecated import DEPRECATED from efl.evas cimport EventKeyDown, EventKeyUp, EventMouseWheel @@ -926,7 +926,7 @@ cdef class Object(evasObject): """ def __get__(self): - return _object_list_to_python(elm_object_focus_custom_chain_get(self.obj)) + return eina_list_objects_to_python_list(elm_object_focus_custom_chain_get(self.obj)) def __set__(self, objs): elm_object_focus_custom_chain_unset(self.obj) @@ -945,7 +945,7 @@ cdef class Object(evasObject): def focus_custom_chain_unset(self): elm_object_focus_custom_chain_unset(self.obj) def focus_custom_chain_get(self): - return _object_list_to_python(elm_object_focus_custom_chain_get(self.obj)) + return eina_list_objects_to_python_list(elm_object_focus_custom_chain_get(self.obj)) def focus_custom_chain_append(self, Object child not None, Object relative_child=None): """focus_custom_chain_append(Object child, Object relative_child=None) diff --git a/efl/elementary/object_item.pyx b/efl/elementary/object_item.pyx index cab4cae..a5ec3fb 100644 --- a/efl/elementary/object_item.pyx +++ b/efl/elementary/object_item.pyx @@ -22,8 +22,8 @@ include "tooltips.pxi" # cdef void _tooltip_item_data_del_cb(void *data, Evas_Object *o, void *event_info) with gil: # Py_DECREF(<object>data) -from efl.eo cimport convert_python_list_objects_to_eina_list, \ - _object_list_to_python +from efl.utils.conversions cimport python_list_objects_to_eina_list, \ + eina_list_objects_to_python_list from object cimport Object import traceback @@ -589,10 +589,10 @@ cdef class ObjectItem(object): """ def __set__(self, list value): elm_object_item_access_order_set(self.item, - convert_python_list_objects_to_eina_list(value)) + python_list_objects_to_eina_list(value)) def __get__(self): - _object_list_to_python(elm_object_item_access_order_get(self.item)) + eina_list_objects_to_python_list(elm_object_item_access_order_get(self.item)) def __del__(self): elm_object_item_access_order_unset(self.item) diff --git a/efl/elementary/slideshow.pyx b/efl/elementary/slideshow.pyx index f06fe12..c1d25a2 100644 --- a/efl/elementary/slideshow.pyx +++ b/efl/elementary/slideshow.pyx @@ -81,7 +81,7 @@ This widget emits the following signals, besides the ones sent from include "widget_header.pxi" include "callback_conversions.pxi" -from efl.eo cimport convert_eina_list_strings_to_python_list +from efl.utils.conversions cimport eina_list_strings_to_python_list from layout_class cimport LayoutClass @@ -500,7 +500,7 @@ cdef class Slideshow(LayoutClass): """ def __get__(self): - return tuple(convert_eina_list_strings_to_python_list(elm_slideshow_transitions_get(self.obj))) + return tuple(eina_list_strings_to_python_list(elm_slideshow_transitions_get(self.obj))) property transition: """The slide transition/effect in use for a given slideshow widget @@ -658,7 +658,7 @@ cdef class Slideshow(LayoutClass): """ def __get__(self): - return tuple(convert_eina_list_strings_to_python_list(elm_slideshow_layouts_get(self.obj))) + return tuple(eina_list_strings_to_python_list(elm_slideshow_layouts_get(self.obj))) property cache_before: """The number of items to cache, on a given slideshow widget, diff --git a/efl/elementary/theme.pyx b/efl/elementary/theme.pyx index ef4d300..05ed58e 100644 --- a/efl/elementary/theme.pyx +++ b/efl/elementary/theme.pyx @@ -83,7 +83,7 @@ overlays. Don't use this unless you really know what you are doing. from cpython cimport Py_INCREF, Py_DECREF include "widget_header.pxi" -from efl.eo cimport convert_eina_list_strings_to_python_list +from efl.utils.conversions cimport eina_list_strings_to_python_list cdef class Theme(object): @@ -218,7 +218,7 @@ cdef class Theme(object): """ def __get__(self): - return tuple(convert_eina_list_strings_to_python_list(elm_theme_overlay_list_get(self.th))) + return tuple(eina_list_strings_to_python_list(elm_theme_overlay_list_get(self.th))) def extension_add(self, item): """extension_add(unicode item) @@ -271,7 +271,7 @@ cdef class Theme(object): """ def __get__(self): - return tuple(convert_eina_list_strings_to_python_list(elm_theme_extension_list_get(self.th))) + return tuple(eina_list_strings_to_python_list(elm_theme_extension_list_get(self.th))) property order: """Set the theme search order for the given theme @@ -315,7 +315,7 @@ cdef class Theme(object): """ def __get__(self): - return tuple(convert_eina_list_strings_to_python_list(elm_theme_list_get(self.th))) + return tuple(eina_list_strings_to_python_list(elm_theme_list_get(self.th))) def flush(self): """flush() @@ -404,7 +404,7 @@ def theme_name_available_list(): """ cdef Eina_List *lst = elm_theme_name_available_list_new() - elements = tuple(convert_eina_list_strings_to_python_list(lst)) + elements = tuple(eina_list_strings_to_python_list(lst)) elm_theme_name_available_list_free(lst) return elements diff --git a/efl/elementary/transit.pyx b/efl/elementary/transit.pyx index 592bfb9..fa69bd3 100644 --- a/efl/elementary/transit.pyx +++ b/efl/elementary/transit.pyx @@ -143,7 +143,8 @@ Tween modes """ include "widget_header.pxi" -from efl.eo cimport _object_list_to_python, convert_python_list_strings_to_eina_list +from efl.utils.conversions cimport eina_list_objects_to_python_list, \ + python_list_strings_to_eina_list cimport enums @@ -313,7 +314,7 @@ cdef class Transit(object): """ def __get__(self): - return _object_list_to_python(elm_transit_objects_get(self.obj)) + return eina_list_objects_to_python_list(elm_transit_objects_get(self.obj)) property objects_final_state_keep: """Enable/disable keeping up the objects states. @@ -558,7 +559,7 @@ cdef class Transit(object): """ def __get__(self): - return _object_list_to_python(elm_transit_chain_transits_get(self.obj)) + return eina_list_objects_to_python_list(elm_transit_chain_transits_get(self.obj)) property smooth: """Smooth effect for a transit. @@ -890,4 +891,4 @@ cdef class Transit(object): """ #TODO: can the return value Elm_Transit_Effect be used somehow? - elm_transit_effect_image_animation_add(self.obj, convert_python_list_strings_to_eina_list(images)) + elm_transit_effect_image_animation_add(self.obj, python_list_strings_to_eina_list(images)) diff --git a/efl/elementary/widget_header.pxi b/efl/elementary/widget_header.pxi index b4e49cf..50d23b8 100644 --- a/efl/elementary/widget_header.pxi +++ b/efl/elementary/widget_header.pxi @@ -1,9 +1,8 @@ from cpython cimport Py_INCREF, Py_DECREF, PyUnicode_AsUTF8String from efl.eo cimport PY_REFCOUNT from efl.evas cimport Object as evasObject -from efl.eo cimport object_from_instance -from efl.eo cimport _object_mapping_register -from efl.eo cimport _ctouni, _touni +from efl.eo cimport object_from_instance, _object_mapping_register +from efl.utils.conversions cimport _ctouni, _touni import logging log = logging.getLogger("elementary") diff --git a/efl/elementary/window.pyx b/efl/elementary/window.pyx index e9ae0bb..4ea2290 100644 --- a/efl/elementary/window.pyx +++ b/efl/elementary/window.pyx @@ -357,8 +357,8 @@ from libc.stdlib cimport malloc, free from libc.string cimport memcpy from object cimport Object -from efl.eo cimport convert_python_list_strings_to_array_of_strings, \ - convert_array_of_strings_to_python_list +from efl.utils.conversions cimport python_list_strings_to_array_of_strings, \ + array_of_strings_to_python_list from efl.evas cimport Evas, evas_object_evas_get, Image as evasImage cimport enums @@ -833,7 +833,7 @@ cdef class Window(Object): unsigned int i try: - array = convert_python_list_strings_to_array_of_strings(profiles) + array = python_list_strings_to_array_of_strings(profiles) elm_win_available_profiles_set(self.obj, array, arr_len) finally: for i in range(arr_len): @@ -847,7 +847,7 @@ cdef class Window(Object): ret = elm_win_available_profiles_get(self.obj, &profiles, &count) if ret is 0: raise RuntimeError("No available profiles") - return convert_array_of_strings_to_python_list(profiles, count) + return array_of_strings_to_python_list(profiles, count) property profile: """The profile of a window. diff --git a/efl/emotion/efl.emotion.pyx b/efl/emotion/efl.emotion.pyx index 03547a3..85abd6b 100644 --- a/efl/emotion/efl.emotion.pyx +++ b/efl/emotion/efl.emotion.pyx @@ -17,8 +17,9 @@ from cpython cimport PyUnicode_AsUTF8String -from efl.eo cimport _ctouni, object_from_instance, _object_mapping_register, \ +from efl.eo cimport object_from_instance, _object_mapping_register, \ _register_decorated_callbacks +from efl.utils.conversions cimport _ctouni from efl.evas cimport Canvas, evas_object_smart_callback_add, \ evas_object_smart_callback_del diff --git a/efl/eo/efl.eo.pyx b/efl/eo/efl.eo.pyx index 06bf163..7a1219e 100644 --- a/efl/eo/efl.eo.pyx +++ b/efl/eo/efl.eo.pyx @@ -49,110 +49,6 @@ cdef int PY_REFCOUNT(object o): cdef PyObject *obj = <PyObject *>o return obj.ob_refcnt -cdef unicode _touni(char* s): - """ - - Converts a char * to a python string object - - """ - return s.decode('UTF-8', 'strict') if s else None - - -cdef unicode _ctouni(const_char *s): - """ - - Converts a const_char * to a python string object - - """ - return s.decode('UTF-8', 'strict') if s else None - - -cdef list convert_array_of_strings_to_python_list(char **array, int array_length): - """ - - Converts an array of strings to a python list. - - """ - cdef: - char *string - list ret = list() - int i - - for i in range(array_length): - string = array[i] - ret.append(_touni(string)) - return ret - - -cdef const_char ** convert_python_list_strings_to_array_of_strings(list strings) except NULL: - """ - - Converts a python list to an array of strings. - - Note: Remember to free the array when it's no longer needed. - - """ - cdef: - const_char **array = NULL - const_char *string - unsigned int str_len, i - unsigned int arr_len = len(strings) - - # TODO: Should we just return NULL in this case? - if arr_len == 0: - array = <const_char **>malloc(sizeof(const_char*)) - if not array: - raise MemoryError() - array[0] = NULL - return array - - array = <const_char **>malloc(arr_len * sizeof(const_char*)) - if not array: - raise MemoryError() - - for i in range(arr_len): - s = strings[i] - if isinstance(s, unicode): s = PyUnicode_AsUTF8String(s) - array[i] = <const_char *>strdup(s) - - return array - - -cdef list convert_eina_list_strings_to_python_list(const_Eina_List *lst): - cdef: - const_char *s - list ret = [] - Eina_List *itr = <Eina_List *>lst - while itr: - s = <const_char *>itr.data - ret.append(_ctouni(s)) - itr = itr.next - return ret - - -cdef Eina_List *convert_python_list_strings_to_eina_list(list strings): - cdef Eina_List *lst = NULL - for s in strings: - if isinstance(s, unicode): s = PyUnicode_AsUTF8String(s) - lst = eina_list_append(lst, strdup(s)) - return lst - - -cdef list _object_list_to_python(const_Eina_List *lst): - cdef list ret = list() - while lst: - ret.append(object_from_instance(<cEo *>lst.data)) - lst = lst.next - return ret - - -cdef Eina_List *convert_python_list_objects_to_eina_list(list objects): - cdef: - Eina_List *lst - Eo o - for o in objects: - lst = eina_list_append(lst, o.obj) - return lst ###################################################################### diff --git a/efl/evas/efl.evas.pyx b/efl/evas/efl.evas.pyx index 5edb85c..dfba198 100644 --- a/efl/evas/efl.evas.pyx +++ b/efl/evas/efl.evas.pyx @@ -17,9 +17,9 @@ import traceback from cpython cimport PyUnicode_AsUTF8String -from efl.eina cimport * +#from efl.eina cimport * from efl.eo cimport Eo, object_from_instance, _object_mapping_register -from efl.eo cimport _ctouni, _touni +from efl.utils.conversions cimport _ctouni, _touni cimport efl.evas.enums as enums EVAS_LAYER_MIN = enums.EVAS_LAYER_MIN diff --git a/efl/evas/efl.evas_object_grid.pxi b/efl/evas/efl.evas_object_grid.pxi index 5613837..5f8f4b3 100644 --- a/efl/evas/efl.evas_object_grid.pxi +++ b/efl/evas/efl.evas_object_grid.pxi @@ -130,6 +130,6 @@ cdef class Grid(Object): cpdef children_get(self): cdef: Eina_List *lst = evas_object_grid_children_get(self.obj) - list ret = _object_list_to_python(lst) + list ret = eina_list_objects_to_python_list(lst) eina_list_free(lst) return ret diff --git a/efl/evas/efl.evas_object_table.pxi b/efl/evas/efl.evas_object_table.pxi index c72d3c9..f491d4f 100644 --- a/efl/evas/efl.evas_object_table.pxi +++ b/efl/evas/efl.evas_object_table.pxi @@ -30,7 +30,7 @@ EVAS_OBJECT_TABLE_HOMOGENEOUS_ITEM = 2 """ -from efl.eo cimport _object_list_to_python +from efl.utils.conversions cimport eina_list_objects_to_python_list cdef class Table(Object): @@ -252,7 +252,7 @@ cdef class Table(Object): """ cdef: Eina_List *lst = evas_object_table_children_get(self.obj) - list ret = _object_list_to_python(lst) + list ret = eina_list_objects_to_python_list(lst) eina_list_free(lst) return ret diff --git a/efl/utils/conversions.pyx b/efl/utils/conversions.pyx new file mode 100644 index 0000000..4976c2f --- /dev/null +++ b/efl/utils/conversions.pyx @@ -0,0 +1,129 @@ +# 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 libc.stdlib cimport malloc, free +from libc.string cimport strdup +from cpython cimport PyUnicode_AsUTF8String + +from efl.c_eo cimport Eo as cEo +from efl.eo cimport Eo, object_from_instance +from efl.eina cimport eina_list_append + +cdef unicode _touni(char* s): + """ + + Converts a char * to a python string object + + """ + return s.decode('UTF-8', 'strict') if s else None + + +cdef unicode _ctouni(const_char *s): + """ + + Converts a const_char * to a python string object + + """ + return s.decode('UTF-8', 'strict') if s else None + + +cdef list array_of_strings_to_python_list(char **array, int array_length): + """ + + Converts an array of strings to a python list. + + """ + cdef: + char *string + list ret = list() + int i + + for i in range(array_length): + string = array[i] + ret.append(_touni(string)) + return ret + + +cdef const_char ** python_list_strings_to_array_of_strings(list strings) except NULL: + """ + + Converts a python list to an array of strings. + + Note: Remember to free the array when it's no longer needed. + + """ + cdef: + const_char **array = NULL + const_char *string + unsigned int str_len, i + unsigned int arr_len = len(strings) + + # TODO: Should we just return NULL in this case? + if arr_len == 0: + array = <const_char **>malloc(sizeof(const_char*)) + if not array: + raise MemoryError() + array[0] = NULL + return array + + array = <const_char **>malloc(arr_len * sizeof(const_char*)) + if not array: + raise MemoryError() + + for i in range(arr_len): + s = strings[i] + if isinstance(s, unicode): s = PyUnicode_AsUTF8String(s) + array[i] = <const_char *>strdup(s) + + return array + + +cdef list eina_list_strings_to_python_list(const_Eina_List *lst): + cdef: + const_char *s + list ret = [] + Eina_List *itr = <Eina_List *>lst + while itr: + s = <const_char *>itr.data + ret.append(_ctouni(s)) + itr = itr.next + return ret + + +cdef Eina_List *python_list_strings_to_eina_list(list strings): + cdef Eina_List *lst = NULL + for s in strings: + if isinstance(s, unicode): s = PyUnicode_AsUTF8String(s) + lst = eina_list_append(lst, strdup(s)) + return lst + + +cdef list eina_list_objects_to_python_list(const_Eina_List *lst): + cdef list ret = list() + while lst: + ret.append(object_from_instance(<cEo *>lst.data)) + lst = lst.next + return ret + + +cdef Eina_List *python_list_objects_to_eina_list(list objects): + cdef: + Eina_List *lst + Eo o + for o in objects: + lst = eina_list_append(lst, o.obj) + return lst diff --git a/include/efl.c_eo.pxd b/include/efl.c_eo.pxd index ae554fd..e313bcd 100644 --- a/include/efl.c_eo.pxd +++ b/include/efl.c_eo.pxd @@ -15,19 +15,13 @@ # 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.eina cimport * - -cdef extern from "Eo.h": - #################################################################### - # Basic Types - # - - - #################################################################### - # Enumerations - # +#from efl.eina cimport * +from libc.string cimport const_char +from libc.stdlib cimport const_void +from efl.eina cimport Eina_Bool +cdef extern from "Eo.h": #################################################################### # Structures # diff --git a/include/efl.eo.pxd b/include/efl.eo.pxd index a9020dd..4968829 100644 --- a/include/efl.eo.pxd +++ b/include/efl.eo.pxd @@ -37,13 +37,3 @@ cdef void _object_mapping_register(char *name, object cls) except * cdef void _object_mapping_unregister(char *name) cdef void _register_decorated_callbacks(object obj) - -cdef unicode _touni(char* s) -cdef unicode _ctouni(const_char *s) - -cdef list convert_array_of_strings_to_python_list(char **array, int array_length) -cdef const_char ** convert_python_list_strings_to_array_of_strings(list strings) except NULL -cdef list convert_eina_list_strings_to_python_list(const_Eina_List *lst) -cdef Eina_List * convert_python_list_strings_to_eina_list(list strings) -cdef list _object_list_to_python(const_Eina_List *lst) -cdef Eina_List *convert_python_list_objects_to_eina_list(list objects) diff --git a/include/efl.utils.conversions.pxd b/include/efl.utils.conversions.pxd new file mode 100644 index 0000000..6e01223 --- /dev/null +++ b/include/efl.utils.conversions.pxd @@ -0,0 +1,12 @@ +from libc.string cimport const_char +from efl.eina cimport Eina_List, const_Eina_List + +cdef unicode _touni(char* s) +cdef unicode _ctouni(const_char *s) + +cdef list array_of_strings_to_python_list(char **array, int array_length) +cdef const_char ** python_list_strings_to_array_of_strings(list strings) except NULL +cdef list eina_list_strings_to_python_list(const_Eina_List *lst) +cdef Eina_List * python_list_strings_to_eina_list(list strings) +cdef list eina_list_objects_to_python_list(const_Eina_List *lst) +cdef Eina_List *python_list_objects_to_eina_list(list objects) diff --git a/setup.py b/setup.py index df645d7..9d7d433 100755 --- a/setup.py +++ b/setup.py @@ -83,8 +83,14 @@ if set(("build", "build_ext", "install")) & set(sys.argv): modules.append(eo_ext) # Utilities - utils_ext = Extension("efl.utils.deprecated", ["efl/utils/deprecated.pyx"]) - modules.append(utils_ext) + utils_ext = [ + Extension("efl.utils.deprecated", ["efl/utils/deprecated.pyx"]), + Extension("efl.utils.conversions", ["efl/utils/conversions.pyx"], + include_dirs = ['include/'], + extra_compile_args = eo_cflags, + extra_link_args = eo_libs + eina_libs) + ] + modules += utils_ext # Evas evas_cflags, evas_libs = pkg_config('Evas', 'evas', "1.7.99") --
