kuuko pushed a commit to branch master.

http://git.enlightenment.org/bindings/python/python-efl.git/commit/?id=70fb839813b58c57c6bbfa13e7765ce7e89f61e1

commit 70fb839813b58c57c6bbfa13e7765ce7e89f61e1
Author: Kai Huuhko <kai.huu...@gmail.com>
Date:   Fri Apr 17 11:32:50 2015 +0300

    Elm: Move ecore events registration to init()
    
    Fixes an issue with docs generation
---
 efl/elementary/__init__.py |   1 +
 efl/elementary/general.pxd |   1 +
 efl/elementary/general.pyx | 290 +++++++++++++++++++++++++--------------------
 efl/elementary/systray.pxd |   3 -
 efl/elementary/systray.pyx |  10 --
 5 files changed, 161 insertions(+), 144 deletions(-)

diff --git a/efl/elementary/__init__.py b/efl/elementary/__init__.py
index fde95b3..253abb4 100644
--- a/efl/elementary/__init__.py
+++ b/efl/elementary/__init__.py
@@ -84,6 +84,7 @@ __all__ = (
     "slideshow",
     "spinner",
     #"store",
+    "systray",
     "table",
     "theme",
     "thumb",
diff --git a/efl/elementary/general.pxd b/efl/elementary/general.pxd
index e38bcb0..134a03d 100644
--- a/efl/elementary/general.pxd
+++ b/efl/elementary/general.pxd
@@ -53,6 +53,7 @@ cdef extern from "Elementary.h":
         ELM_EVENT_PROCESS_FOREGROUND
         ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED
         ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED
+        ELM_EVENT_SYSTRAY_READY
 
     #enums
     cpdef enum Elm_Object_Layer:
diff --git a/efl/elementary/general.pyx b/efl/elementary/general.pyx
index 4b1fa2c..f2a6c28 100644
--- a/efl/elementary/general.pyx
+++ b/efl/elementary/general.pyx
@@ -290,7 +290,8 @@ from efl.eina cimport EINA_LOG_DOM_DBG, EINA_LOG_DOM_INFO, \
     EINA_LOG_DOM_WARN, EINA_LOG_DOM_ERR, EINA_LOG_DOM_CRIT
 
 from efl.ecore cimport Event, EventHandler, _event_mapping_register
-from efl.elementary.need cimport elm_need_sys_notify
+from efl.elementary.need cimport elm_need_sys_notify, elm_need_systray, \
+    elm_need_ethumb
 
 import sys
 import traceback
@@ -300,82 +301,13 @@ import atexit
 elm_log = add_logger("efl.elementary")
 cdef int PY_EFL_ELM_LOG_DOMAIN = elm_log.eina_log_domain
 
-def init():
-    """Initialize Elementary
-
-    :return int: The init counter value.
-
-    This function initializes Elementary and increments a counter of the number
-    of calls to it. It returns the new counter's value.
-
-    .. versionchanged:: 1.14
-
-        The Python module calls this function when it is imported so you
-        should no longer have any need to call this manually. Calling it does
-        not carry any penalty though.
-
-    """
-    EINA_LOG_DOM_INFO(PY_EFL_ELM_LOG_DOMAIN,
-        "Initializing efl.elementary", NULL)
-
-    # FIXME: Why are we passing the cl args to elm_init here?
-
-    cdef:
-        int argc, i, arg_len
-        char **argv
-        char *arg
-
-    argc = len(sys.argv)
-    argv = <char **>PyMem_Malloc(argc * sizeof(char *))
-    for i in range(argc):
-        t = sys.argv[i]
-        if isinstance(t, unicode): t = PyUnicode_AsUTF8String(t)
-        arg = t
-        arg_len = len(arg)
-        argv[i] = <char *>PyMem_Malloc(arg_len + 1)
-        memcpy(argv[i], arg, arg_len + 1)
-
-    return elm_init(argc, argv)
-
-def shutdown():
-    """Shut down Elementary
-
-    :return int: The init counter value.
-
-    This should be called at the end of your application, just before it ceases
-    to do any more processing. This will clean up any permanent resources your
-    application may have allocated via Elementary that would otherwise persist.
-
-    .. note::
-
-        shutdown() will iterate main loop until all ecore_evas are freed. There
-        is a possibility to call your ecore callbacks(timer, animator, event,
-        job, and etc.) in shutdown()
-
-    .. versionchanged:: 1.14
-
-        The Python module calls this function when it is exiting so you
-        should no longer have any need to call this manually. Calling it does
-        not carry any penalty though.
-
-    """
-    EINA_LOG_DOM_INFO(PY_EFL_ELM_LOG_DOMAIN,
-        "Shutting down efl.elementary", NULL)
-    return elm_shutdown()
-
-
-init()
-atexit.register(shutdown)
 
+cdef class EventSystrayReady(Event):
+    cdef int _set_obj(self, void *o) except 0:
+        return 1
 
-cdef void py_elm_sys_notify_send_cb(void *data, unsigned int id):
-    cdef object func, func_data
-    func, func_data = <object>data
-    # FIXME: Is this cb called more than once? Py_DECREF if not.
-    try:
-        func(func_data, id)
-    except Exception:
-        traceback.print_exc()
+    def __repr__(self):
+        return "<%s()>" % (self.__class__.__name__,)
 
 
 cdef class SysNotifyNotificationClosed(Event):
@@ -449,15 +381,6 @@ cdef class EthumbConnect(Event):
     def __repr__(self):
         return "<%s()>" % (self.__class__.__name__,)
 
-_event_mapping_register(ELM_ECORE_EVENT_ETHUMB_CONNECT, EthumbConnect)
-
-def on_ethumb_connect(func, *args, **kwargs):
-    """Use this to set a handler for the ethumb connect event.
-
-    .. versionadded:: 1.14
-    """
-    return EventHandler(ELM_ECORE_EVENT_ETHUMB_CONNECT, func, *args, **kwargs)
-
 
 cdef class ConfigAllChanged(Event):
     cdef int _set_obj(self, void *o) except 0:
@@ -466,18 +389,6 @@ cdef class ConfigAllChanged(Event):
     def __repr__(self):
         return "<%s()>" % (self.__class__.__name__,)
 
-_event_mapping_register(ELM_EVENT_CONFIG_ALL_CHANGED, ConfigAllChanged)
-
-def on_config_all_changed(func, *args, **kwargs):
-    """Use this to set a handler for the config all changed event.
-
-    Emitted when the application has reconfigured elementary settings due to an
-    external configuration tool asking it to.
-
-    .. versionadded:: 1.14
-    """
-    return EventHandler(ELM_EVENT_CONFIG_ALL_CHANGED, func, *args, **kwargs)
-
 
 cdef class PolicyChanged(Event):
 
@@ -499,26 +410,162 @@ cdef class PolicyChanged(Event):
             self.__class__.__name__,
             self.policy, self.new_value, self.old_value)
 
-_event_mapping_register(ELM_EVENT_POLICY_CHANGED, PolicyChanged)
 
-def on_policy_changed(func, *args, **kwargs):
-    """Use this to set a handler for the policy changed event.
-
-    Emitted when any Elementary's policy value is changed.
+cdef class ProcessBackground(Event):
+    cdef int _set_obj(self, void *o) except 0:
+        return 1
 
-    .. versionadded:: 1.14
-    """
-    return EventHandler(ELM_EVENT_POLICY_CHANGED, func, *args, **kwargs)
+    def __repr__(self):
+        return "<%s()>" % (self.__class__.__name__,)
 
 
-cdef class ProcessBackground(Event):
+cdef class ProcessForeground(Event):
     cdef int _set_obj(self, void *o) except 0:
         return 1
 
     def __repr__(self):
         return "<%s()>" % (self.__class__.__name__,)
 
-_event_mapping_register(ELM_EVENT_PROCESS_BACKGROUND, ProcessBackground)
+
+def init():
+    """Initialize Elementary
+
+    :return int: The init counter value.
+
+    This function initializes Elementary and increments a counter of the number
+    of calls to it. It returns the new counter's value.
+
+    .. versionchanged:: 1.14
+
+        The Python module calls this function when it is imported so you
+        should no longer have any need to call this manually. Calling it does
+        not carry any penalty though.
+
+    """
+    EINA_LOG_DOM_INFO(PY_EFL_ELM_LOG_DOMAIN,
+        "Initializing efl.elementary", NULL)
+
+    # FIXME: Why are we passing the cl args to elm_init here?
+
+    cdef:
+        int argc, i, arg_len
+        char **argv
+        char *arg
+        int ret
+
+    argc = len(sys.argv)
+    argv = <char **>PyMem_Malloc(argc * sizeof(char *))
+    for i in range(argc):
+        t = sys.argv[i]
+        if isinstance(t, unicode): t = PyUnicode_AsUTF8String(t)
+        arg = t
+        arg_len = len(arg)
+        argv[i] = <char *>PyMem_Malloc(arg_len + 1)
+        memcpy(argv[i], arg, arg_len + 1)
+
+    ret = elm_init(argc, argv)
+
+    if ret != 1:
+        return ret
+
+    if elm_need_ethumb():
+        _event_mapping_register(ELM_ECORE_EVENT_ETHUMB_CONNECT, EthumbConnect)
+    else:
+        EINA_LOG_DOM_WARN(PY_EFL_ELM_LOG_DOMAIN, "Ethumb not available", NULL)
+
+    _event_mapping_register(ELM_EVENT_CONFIG_ALL_CHANGED, ConfigAllChanged)
+    _event_mapping_register(ELM_EVENT_POLICY_CHANGED, PolicyChanged)
+    _event_mapping_register(ELM_EVENT_PROCESS_BACKGROUND, ProcessBackground)
+    _event_mapping_register(ELM_EVENT_PROCESS_FOREGROUND, ProcessForeground)
+
+    if elm_need_systray():
+        _event_mapping_register(ELM_EVENT_SYSTRAY_READY, EventSystrayReady)
+    else:
+        EINA_LOG_DOM_WARN(PY_EFL_ELM_LOG_DOMAIN, "Systray not available", NULL)
+
+    if elm_need_sys_notify():
+        _event_mapping_register(
+            ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED,
+            SysNotifyNotificationClosed
+            )
+        _event_mapping_register(
+            ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED,
+            SysNotifyActionInvoked
+            )
+    else:
+        EINA_LOG_DOM_WARN(PY_EFL_ELM_LOG_DOMAIN, "Sys notify not available", 
NULL)
+
+    return ret
+
+def shutdown():
+    """Shut down Elementary
+
+    :return int: The init counter value.
+
+    This should be called at the end of your application, just before it ceases
+    to do any more processing. This will clean up any permanent resources your
+    application may have allocated via Elementary that would otherwise persist.
+
+    .. note::
+
+        shutdown() will iterate main loop until all ecore_evas are freed. There
+        is a possibility to call your ecore callbacks(timer, animator, event,
+        job, and etc.) in shutdown()
+
+    .. versionchanged:: 1.14
+
+        The Python module calls this function when it is exiting so you
+        should no longer have any need to call this manually. Calling it does
+        not carry any penalty though.
+
+    """
+    EINA_LOG_DOM_INFO(PY_EFL_ELM_LOG_DOMAIN,
+        "Shutting down efl.elementary", NULL)
+    return elm_shutdown()
+
+
+init()
+atexit.register(shutdown)
+
+
+cdef void py_elm_sys_notify_send_cb(void *data, unsigned int id):
+    cdef object func, func_data
+    func, func_data = <object>data
+    # FIXME: Is this cb called more than once? Py_DECREF if not.
+    try:
+        func(func_data, id)
+    except Exception:
+        traceback.print_exc()
+
+
+def on_ethumb_connect(func, *args, **kwargs):
+    """Use this to set a handler for the ethumb connect event.
+
+    .. versionadded:: 1.14
+    """
+    return EventHandler(ELM_ECORE_EVENT_ETHUMB_CONNECT, func, *args, **kwargs)
+
+
+def on_config_all_changed(func, *args, **kwargs):
+    """Use this to set a handler for the config all changed event.
+
+    Emitted when the application has reconfigured elementary settings due to an
+    external configuration tool asking it to.
+
+    .. versionadded:: 1.14
+    """
+    return EventHandler(ELM_EVENT_CONFIG_ALL_CHANGED, func, *args, **kwargs)
+
+
+def on_policy_changed(func, *args, **kwargs):
+    """Use this to set a handler for the policy changed event.
+
+    Emitted when any Elementary's policy value is changed.
+
+    .. versionadded:: 1.14
+    """
+    return EventHandler(ELM_EVENT_POLICY_CHANGED, func, *args, **kwargs)
+
 
 def on_process_background(func, *args, **kwargs):
     """Use this to set a handler for the process background event.
@@ -531,15 +578,6 @@ def on_process_background(func, *args, **kwargs):
     return EventHandler(ELM_EVENT_PROCESS_BACKGROUND, func, *args, **kwargs)
 
 
-cdef class ProcessForeground(Event):
-    cdef int _set_obj(self, void *o) except 0:
-        return 1
-
-    def __repr__(self):
-        return "<%s()>" % (self.__class__.__name__,)
-
-_event_mapping_register(ELM_EVENT_PROCESS_FOREGROUND, ProcessForeground)
-
 def on_process_background(func, *args, **kwargs):
     """Use this to set a handler for the process foreground event.
 
@@ -551,27 +589,17 @@ def on_process_background(func, *args, **kwargs):
     return EventHandler(ELM_EVENT_PROCESS_FOREGROUND, func, *args, **kwargs)
 
 
-if elm_need_sys_notify():
-    _event_mapping_register(
-        ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED,
-        SysNotifyNotificationClosed
+def on_sys_notify_notification_closed(func, *args, **kargs):
+    return EventHandler(
+        ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED, func, *args, **kargs
         )
 
-    def on_sys_notify_notification_closed(func, *args, **kargs):
-        return EventHandler(
-            ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED, func, *args, **kargs
-            )
 
-    _event_mapping_register(
-        ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED,
-        SysNotifyActionInvoked
+def on_sys_notify_action_invoked(func, *args, **kargs):
+    return EventHandler(
+        ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED, func, *args, **kargs
         )
 
-    def on_sys_notify_action_invoked(func, *args, **kargs):
-        return EventHandler(
-            ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED, func, *args, **kargs
-            )
-
 
 cdef class FontProperties(object):
 
diff --git a/efl/elementary/systray.pxd b/efl/elementary/systray.pxd
index f5b9f83..7b634a5 100644
--- a/efl/elementary/systray.pxd
+++ b/efl/elementary/systray.pxd
@@ -6,9 +6,6 @@ cdef extern from "Elementary.h":
 
     ctypedef Eo Elm_Systray
 
-    cpdef enum:
-        ELM_EVENT_SYSTRAY_READY
-
     cpdef enum _Elm_Systray_Category:
         ELM_SYSTRAY_CATEGORY_APP_STATUS
         ELM_SYSTRAY_CATEGORY_COMMUNICATIONS
diff --git a/efl/elementary/systray.pyx b/efl/elementary/systray.pyx
index c79997f..be57906 100644
--- a/efl/elementary/systray.pyx
+++ b/efl/elementary/systray.pyx
@@ -84,16 +84,6 @@ from efl.ecore cimport Event, EventHandler, 
_event_mapping_register
 from efl.utils.conversions cimport _ctouni
 
 
-cdef class EventSystrayReady(Event):
-    cdef int _set_obj(self, void *o) except 0:
-        return 1
-
-    def __repr__(self):
-        return "<%s()>" % (self.__class__.__name__,)
-
-_event_mapping_register(ELM_EVENT_SYSTRAY_READY, EventSystrayReady)
-
-
 cdef class Systray(Eo):
 
     """

-- 


Reply via email to