From: Enlightenment S. <no-...@en...> - 2009-11-08 19:24:46
|
Log: pyelm: fix list Author: billiob Date: 2009-11-08 11:24:33 -0800 (Sun, 08 Nov 2009) New Revision: 43534 Modified: trunk/BINDINGS/python/python-elementary/elementary/elementary.c_elementary_list.pxi trunk/BINDINGS/python/python-elementary/elementary/elementary.c_elementary_window.pxi trunk/BINDINGS/python/python-elementary/include/elementary/c_elementary.pxd Modified: trunk/BINDINGS/python/python-elementary/elementary/elementary.c_elementary_list.pxi =================================================================== --- trunk/BINDINGS/python/python-elementary/elementary/elementary.c_elementary_list.pxi 2009-11-08 19:02:42 UTC (rev 43533) +++ trunk/BINDINGS/python/python-elementary/elementary/elementary.c_elementary_list.pxi 2009-11-08 19:24:33 UTC (rev 43534) @@ -19,36 +19,51 @@ cdef void _list_callback(void *cbt, c_evas.Evas_Object *o, void *event_info) with gil: try: - (obj, callback, data, it) = <object>cbt - if not callable(callback): - raise TypeError("callback is not callable") + (obj, callback, data, self) = <object>cbt callback(obj, "clicked" , data) except Exception, e: traceback.print_exc() +cdef void _list_item_del_cb(void *data, c_evas.Evas_Object *o, void *event_info) with gil: + (obj, callback, d, it) = <object>data + + it.__del_cb() + +cdef enum Elm_List_Item_Insert_Kind: + ELM_LIST_ITEM_INSERT_APPEND + ELM_LIST_ITEM_INSERT_PREPEND + ELM_LIST_ITEM_INSERT_BEFORE + ELM_LIST_ITEM_INSERT_AFTER + cdef class ListItem: """ An item for the list widget """ cdef Elm_List_Item *item - cdef c_evas.Evas_Object *list cdef object cbt def __new__(self): self.item = NULL - def __init__(self): - pass + def __del_cb(self): + self.item = NULL - def append(self, c_evas.Object list, label, c_evas.Object icon = None, - c_evas.Object end = None, callback = None, data = None): - if not self.item == NULL: - raise Exception("Item was already created!") + self.cbt = None + Py_DECREF(self) + + def __init__(self, kind, c_evas.Object list, label, c_evas.Object icon = None, + c_evas.Object end = None, callback = None, data = None, + ListItem before_after = None): cdef c_evas.Evas_Object* icon_obj cdef c_evas.Evas_Object* end_obj + cdef void* cbdata + cdef void (*cb) (void *, c_evas.Evas_Object *, void *) + icon_obj = NULL end_obj = NULL + cbdata = NULL + cb = NULL if icon is not None: icon_obj = icon.obj @@ -56,101 +71,44 @@ end_obj = end.obj if callback is not None: - self.cbt = (list, callback, data, self) + if not callable(callback): + raise TypeError("callback is not callable") + cb = _list_callback + self.cbt = (list, callback, data, self) + cbdata = <void*>self.cbt + + if kind == ELM_LIST_ITEM_INSERT_APPEND: self.item = elm_list_item_append(list.obj, label, icon_obj, end_obj, - _list_callback, <void*>self.cbt) - else: - self.item = elm_list_item_append(list.obj, label, icon_obj, end_obj, - NULL, NULL) - - def prepend(self, c_evas.Object list, label, c_evas.Object icon = None, - c_evas.Object end = None, callback = None, data = None): - if not self.item == NULL: - raise Exception("Item was already created!") - - cdef c_evas.Evas_Object* icon_obj - cdef c_evas.Evas_Object* end_obj - icon_obj = NULL - end_obj = NULL - - if icon is not None: - icon_obj = icon.obj - if end is not None: - end_obj = end.obj - - if callback is not None: - self.cbt = (list, callback, data, self) + cb, cbdata) + elif kind == ELM_LIST_ITEM_INSERT_PREPEND: self.item = elm_list_item_prepend(list.obj, label, icon_obj, end_obj, - _list_callback, <void*>self.cbt) + cb, cbdata) else: - self.item = elm_list_item_prepend(list.obj, label, icon_obj, end_obj, - NULL, NULL) + if before_after == None: + raise ValueError("need a valid after object to add an item before/after another item") + if kind == ELM_LIST_ITEM_INSERT_BEFORE: + self.item = elm_list_item_insert_before(list.obj, before_after.item, label, + icon_obj, end_obj, + cb, cbdata) + else: + self.item = elm_list_item_insert_after(list.obj, before_after.item, label, + icon_obj, end_obj, + cb, cbdata) - def insert_before(self, c_evas.Object list, ListItem before, label, - c_evas.Object icon = None, c_evas.Object end = None, - callback = None, data = None): - if not self.item == NULL: - raise Exception("Item was already created!") + Py_INCREF(self) + elm_list_item_del_cb_set(self.item, _list_item_del_cb) - if before == None: - raise ValueError("need a valid before object to add an item before another item") + def delete(self): + if self.item == NULL: + raise ValueError("Object already deleted") + elm_list_item_del(self.item) - cdef c_evas.Evas_Object* icon_obj - cdef c_evas.Evas_Object* end_obj - icon_obj = NULL - end_obj = NULL - - if icon is not None: - icon_obj = icon.obj - if end is not None: - end_obj = end.obj - - if callback is not None: - self.cbt = (list, callback, data, self) - self.item = elm_list_item_insert_before(list.obj, before.item, label, - icon_obj, end_obj, - _list_callback, <void*>self.cbt) - else: - self.item = elm_list_item_insert_before(list.obj, before.item, label, - icon_obj, end_obj, NULL, NULL) - - def insert_after(self, c_evas.Object list, ListItem after, label, - c_evas.Object icon = None, c_evas.Object end = None, - callback = None, data = None): - if not self.item == NULL: - raise Exception("Item was already created!") - - if after == None: - raise ValueError("need a valid after object to add an item after another item") - - cdef c_evas.Evas_Object* icon_obj - cdef c_evas.Evas_Object* end_obj - icon_obj = NULL - end_obj = NULL - - if icon is not None: - icon_obj = icon.obj - if end is not None: - end_obj = end.obj - - if callback is not None: - self.cbt = (list, callback, data, self) - self.item = elm_list_item_insert_after(list.obj, after.item, label, - icon_obj, end_obj, - _list_callback, <void*>self.cbt) - else: - self.item = elm_list_item_insert_after(list.obj, after.item, label, - icon_obj, end_obj, NULL, NULL) - def selected_set(self, selected): elm_list_item_selected_set(self.item, selected) def show(self): elm_list_item_show(self.item) - def delete(self): - elm_list_item_del(self.item) - def data_get(self): cdef void* data data = elm_list_item_data_get(self.item) @@ -164,14 +122,6 @@ icon = elm_list_item_icon_get(self.item) return evas.c_evas._Object_from_instance(<long> icon) - # TODO - def end_get(self): - return None - - # TODO - def base_get(self): - return None - def label_get(self): return elm_list_item_label_get(self.item) @@ -179,11 +129,68 @@ elm_list_item_label_set(self.item, label) def prev(self): + import warnings + warnings.warn("use prev_get() instead.", DeprecationWarning) self.item = elm_list_item_prev(self.item) + def prev_get(self): + cdef Elm_List_Item *item + cdef void *data + + item = elm_list_item_prev(self.item) + + if item == NULL: + return None + data = elm_list_item_data_get(item) + if data == NULL: + return None + (obj, callback, d, it) = <object>data + return it + def next(self): + import warnings + warnings.warn("use next_get() instead.", DeprecationWarning) self.item = elm_list_item_next(self.item) + def next_get(self): + cdef Elm_List_Item *item + cdef void *data + + item = elm_list_item_next(self.item) + + if item == NULL: + return None + data = elm_list_item_data_get(item) + if data == NULL: + return None + (obj, callback, d, it) = <object>data + return it + + def end_get(self): + cdef c_evas.Evas_Object *obj + cdef void *data + + obj = elm_list_item_end_get(self.item) + if obj == NULL: + return None + data = c_evas.evas_object_data_get(obj, "python-evas") + if data == NULL: + return None + return <Object>data + + def base_get(self): + cdef c_evas.Evas_Object *obj + cdef void *data + + obj = elm_list_item_base_get(self.item) + if obj == NULL: + return None + data = c_evas.evas_object_data_get(obj, "python-evas") + if data == NULL: + return None + return <Object>data + + cdef class List(Object): def __init__(self, c_evas.Object parent): Object.__init__(self, parent.evas) @@ -191,27 +198,23 @@ def item_append(self, label, c_evas.Object icon = None, c_evas.Object end = None, callback = None, data = None): - item = ListItem() - item.append(self, label, icon, end, callback, data) - return item + return ListItem(ELM_LIST_ITEM_INSERT_APPEND, self, label, icon, end, + callback, data) def item_prepend(self, label, c_evas.Object icon = None, c_evas.Object end = None, callback = None, data = None): - item = ListItem() - item.prepend(self, label, icon, end, data) - return item + return ListItem(ELM_LIST_ITEM_INSERT_PREPEND, self, label, icon, end, + callback, data) def item_insert_before(self, ListItem before, label, c_evas.Object icon = None, c_evas.Object end = None, callback = None, data = None): - item = ListItem() - item.insert_before(self, before, label, icon, end, callback, data) - return item + return ListItem(ELM_LIST_ITEM_INSERT_BEFORE, self, label, icon, end, + callback, data, before) def item_insert_after(self, ListItem after, label, c_evas.Object icon = None, c_evas.Object end = None, callback = None, data = None): - item = ListItem() - item.insert_after(self, after, label, icon, end, callback, data) - return item + return ListItem(ELM_LIST_ITEM_INSERT_AFTER, self, label, icon, end, + callback, data, after) def clear(self): elm_list_clear(self.obj) @@ -230,17 +233,17 @@ def selected_item_get(self): cdef Elm_List_Item *obj - cdef void *eo + cdef void *data obj = elm_list_selected_item_get(self.obj) if obj == NULL: return None - eo = evas.c_evas.evas_object_data_get( - <evas.c_evas.Evas_Object*>obj, "python-evas") - if eo == NULL: + data = elm_list_item_data_get(obj) + if data == NULL: return None else: - return <Object>eo + (o, callback, d, it) = <object>data + return it property clicked: def __set__(self, value): Modified: trunk/BINDINGS/python/python-elementary/elementary/elementary.c_elementary_window.pxi =================================================================== --- trunk/BINDINGS/python/python-elementary/elementary/elementary.c_elementary_window.pxi 2009-11-08 19:02:42 UTC (rev 43533) +++ trunk/BINDINGS/python/python-elementary/elementary/elementary.c_elementary_window.pxi 2009-11-08 19:24:33 UTC (rev 43534) @@ -18,8 +18,8 @@ cdef class Window(Object): """ - Elementary Wind ow class - + Elementary Window class + This class represents a basic window. """ @@ -57,7 +57,7 @@ property focus_out: def __set__(self, value): self._callback_add("focus-out", value) - + def resize_object_add(self,c_evas.Object obj): """ Sets an object which sould be resized, when the window changes his size @@ -73,7 +73,7 @@ @parm: B{obj} Widget object """ elm_win_resize_object_del(self.obj, obj.obj) - + def title_set(self,title): """ Sets the title of the window @@ -85,7 +85,7 @@ def activate(self): """Activates the window""" elm_win_activate(self.obj) - + def autodel_set(self,autodel): """ Set the auto deletion property of the window @@ -128,7 +128,7 @@ elm_win_alpha_set(self.obj, 1) else: elm_win_alpha_set(self.obj, 0) - + def override_set(self, override): """ Set the override property @@ -150,7 +150,7 @@ elm_win_fullscreen_set(self.obj, 1) else: elm_win_fullscreen_set(self.obj, 0) - + def maximized_set(self, maximized): """ Maximize the window @@ -231,7 +231,6 @@ def xwindow_get(self): cdef Ecore_X_Window xwin xwin = elm_win_xwindow_get(self.obj) - return Null """ Modified: trunk/BINDINGS/python/python-elementary/include/elementary/c_elementary.pxd =================================================================== --- trunk/BINDINGS/python/python-elementary/include/elementary/c_elementary.pxd 2009-11-08 19:02:42 UTC (rev 43533) +++ trunk/BINDINGS/python/python-elementary/include/elementary/c_elementary.pxd 2009-11-08 19:24:33 UTC (rev 43534) @@ -26,6 +26,10 @@ void PyMem_Free(void *p) void memcpy(void *source, void *dest, size_t nbytes) + # object.h + void Py_INCREF(object) + void Py_DECREF(object) + cdef enum Elm_Win_Type: ELM_WIN_BASIC ELM_WIN_DIALOG_BASIC |