kuuko pushed a commit to branch master.

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

commit c08888239f30f8bc8f4707650cedd819a9a09b00
Author: Kai Huuhko <kai.huu...@gmail.com>
Date:   Mon Apr 20 06:25:43 2015 +0300

    Elm: Move ecore events registration out of init
---
 efl/elementary/general.pxd |  16 ------
 efl/elementary/general.pyx | 121 +++------------------------------------------
 efl/elementary/need.pxd    |  23 +++++++++
 efl/elementary/need.pyx    | 111 +++++++++++++++++++++++++++++++++++++++--
 4 files changed, 137 insertions(+), 134 deletions(-)

diff --git a/efl/elementary/general.pxd b/efl/elementary/general.pxd
index 134a03d..56de2f7 100644
--- a/efl/elementary/general.pxd
+++ b/efl/elementary/general.pxd
@@ -93,14 +93,6 @@ cdef extern from "Elementary.h":
     ctypedef enum Elm_Policy_Throttle:
         pass
 
-    cpdef enum Elm_Sys_Notify_Closed_Reason:
-        ELM_SYS_NOTIFY_CLOSED_EXPIRED
-        ELM_SYS_NOTIFY_CLOSED_DISMISSED
-        ELM_SYS_NOTIFY_CLOSED_REQUESTED
-        ELM_SYS_NOTIFY_CLOSED_UNDEFINED
-    ctypedef enum Elm_Sys_Notify_Closed_Reason:
-        pass
-
     cpdef enum Elm_Sys_Notify_Urgency:
         ELM_SYS_NOTIFY_URGENCY_LOW
         ELM_SYS_NOTIFY_URGENCY_NORMAL
@@ -208,14 +200,6 @@ cdef extern from "Elementary.h":
     # sys_notify.h
     ctypedef void (*Elm_Sys_Notify_Send_Cb)(void *data, unsigned int id)
 
-    ctypedef struct Elm_Sys_Notify_Notification_Closed:
-        unsigned int id # ID of the notification.
-        Elm_Sys_Notify_Closed_Reason reason # The Reason the notification was 
closed.
-
-    ctypedef struct Elm_Sys_Notify_Action_Invoked:
-        unsigned int id # ID of the notification.
-        char *action_key # The key of the action invoked. These match the keys 
sent over in the list of actions.
-
     void      elm_sys_notify_close(unsigned int id)
     void      elm_sys_notify_send(  unsigned int replaces_id,
                                     const char *icon,
diff --git a/efl/elementary/general.pyx b/efl/elementary/general.pyx
index f2a6c28..f449785 100644
--- a/efl/elementary/general.pyx
+++ b/efl/elementary/general.pyx
@@ -290,8 +290,6 @@ 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, elm_need_systray, \
-    elm_need_ethumb
 
 import sys
 import traceback
@@ -302,86 +300,6 @@ elm_log = add_logger("efl.elementary")
 cdef int PY_EFL_ELM_LOG_DOMAIN = elm_log.eina_log_domain
 
 
-cdef class EventSystrayReady(Event):
-    cdef int _set_obj(self, void *o) except 0:
-        return 1
-
-    def __repr__(self):
-        return "<%s()>" % (self.__class__.__name__,)
-
-
-cdef class SysNotifyNotificationClosed(Event):
-
-    cdef Elm_Sys_Notify_Notification_Closed *obj
-
-    cdef int _set_obj(self, void *o) except 0:
-        self.obj = <Elm_Sys_Notify_Notification_Closed*>o
-        return 1
-
-    def __repr__(self):
-        # TODO: int -> string for 'reason'
-        return "<%s(id=%d, reason=%s)>" % \
-            (type(self).__name__, self.id, self.reason)
-
-    property id:
-        """ID of the notification.
-
-        :type: int
-
-        """
-        def __get__(self):
-            return self.obj.id
-
-    property reason:
-        """The Reason the notification was closed.
-
-        :type: :ref:`Elm_Sys_Notify_Closed_Reason`
-
-        """
-        def __get__(self):
-            return self.obj.reason
-
-
-cdef class SysNotifyActionInvoked(Event):
-
-    cdef Elm_Sys_Notify_Action_Invoked *obj
-
-    cdef int _set_obj(self, void *o) except 0:
-        self.obj = <Elm_Sys_Notify_Action_Invoked*>o
-        return 1
-
-    def __repr__(self):
-        return "<%s(id=%d, action_key=%s)>" % \
-            (type(self).__name__, self.id, self.action_key)
-
-    property id:
-        """ID of the notification.
-
-        :type: int
-
-        """
-        def __get__(self):
-            return self.obj.id
-
-    property action_key:
-        """The key of the action invoked. These match the keys sent over in the
-        list of actions.
-
-        :type: string
-
-        """
-        def __get__(self):
-            return _touni(self.obj.action_key)
-
-
-cdef class EthumbConnect(Event):
-    cdef int _set_obj(self, void *o) except 0:
-        return 1
-
-    def __repr__(self):
-        return "<%s()>" % (self.__class__.__name__,)
-
-
 cdef class ConfigAllChanged(Event):
     cdef int _set_obj(self, void *o) except 0:
         return 1
@@ -463,39 +381,7 @@ def init():
         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
+    return elm_init(argc, argv)
 
 def shutdown():
     """Shut down Elementary
@@ -527,6 +413,11 @@ def shutdown():
 init()
 atexit.register(shutdown)
 
+_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)
+
 
 cdef void py_elm_sys_notify_send_cb(void *data, unsigned int id):
     cdef object func, func_data
diff --git a/efl/elementary/need.pxd b/efl/elementary/need.pxd
index 555be87..8cfd58c 100644
--- a/efl/elementary/need.pxd
+++ b/efl/elementary/need.pxd
@@ -1,6 +1,29 @@
 from efl.evas cimport Eina_Bool
 
 cdef extern from "Elementary.h":
+    cpdef enum:
+        ELM_ECORE_EVENT_ETHUMB_CONNECT
+        ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED
+        ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED
+        ELM_EVENT_SYSTRAY_READY
+
+    ctypedef struct Elm_Sys_Notify_Notification_Closed:
+        unsigned int id # ID of the notification.
+        Elm_Sys_Notify_Closed_Reason reason # The Reason the notification was 
closed.
+
+    ctypedef struct Elm_Sys_Notify_Action_Invoked:
+        unsigned int id # ID of the notification.
+        char *action_key # The key of the action invoked. These match the keys 
sent over in the list of actions.
+
+    cpdef enum Elm_Sys_Notify_Closed_Reason:
+        ELM_SYS_NOTIFY_CLOSED_EXPIRED
+        ELM_SYS_NOTIFY_CLOSED_DISMISSED
+        ELM_SYS_NOTIFY_CLOSED_REQUESTED
+        ELM_SYS_NOTIFY_CLOSED_UNDEFINED
+    ctypedef enum Elm_Sys_Notify_Closed_Reason:
+        pass
+
+
     Eina_Bool                elm_need_efreet()
     Eina_Bool                elm_need_systray()
     Eina_Bool                elm_need_sys_notify()
diff --git a/efl/elementary/need.pyx b/efl/elementary/need.pyx
index 52eeea0..bb9f4dd 100644
--- a/efl/elementary/need.pyx
+++ b/efl/elementary/need.pyx
@@ -29,6 +29,87 @@ This functions are used to tell elementary of optionals 
modules usage.
 
 
 from efl.utils.deprecated cimport DEPRECATED
+from efl.utils.conversions cimport _touni
+from efl.ecore cimport Event, _event_mapping_register
+
+
+cdef class SysNotifyNotificationClosed(Event):
+
+    cdef Elm_Sys_Notify_Notification_Closed *obj
+
+    cdef int _set_obj(self, void *o) except 0:
+        self.obj = <Elm_Sys_Notify_Notification_Closed*>o
+        return 1
+
+    def __repr__(self):
+        # TODO: int -> string for 'reason'
+        return "<%s(id=%d, reason=%s)>" % \
+            (type(self).__name__, self.id, self.reason)
+
+    property id:
+        """ID of the notification.
+
+        :type: int
+
+        """
+        def __get__(self):
+            return self.obj.id
+
+    property reason:
+        """The Reason the notification was closed.
+
+        :type: :ref:`Elm_Sys_Notify_Closed_Reason`
+
+        """
+        def __get__(self):
+            return self.obj.reason
+
+
+cdef class SysNotifyActionInvoked(Event):
+
+    cdef Elm_Sys_Notify_Action_Invoked *obj
+
+    cdef int _set_obj(self, void *o) except 0:
+        self.obj = <Elm_Sys_Notify_Action_Invoked*>o
+        return 1
+
+    def __repr__(self):
+        return "<%s(id=%d, action_key=%s)>" % \
+            (type(self).__name__, self.id, self.action_key)
+
+    property id:
+        """ID of the notification.
+
+        :type: int
+
+        """
+        def __get__(self):
+            return self.obj.id
+
+    property action_key:
+        """The key of the action invoked. These match the keys sent over in the
+        list of actions.
+
+        :type: string
+
+        """
+        def __get__(self):
+            return _touni(self.obj.action_key)
+
+
+cdef class EthumbConnect(Event):
+    cdef int _set_obj(self, void *o) except 0:
+        return 1
+
+    def __repr__(self):
+        return "<%s()>" % (self.__class__.__name__,)
+
+cdef class EventSystrayReady(Event):
+    cdef int _set_obj(self, void *o) except 0:
+        return 1
+
+    def __repr__(self):
+        return "<%s()>" % (self.__class__.__name__,)
 
 
 def need_efreet():
@@ -57,7 +138,13 @@ def need_systray():
     .. versionadded:: 1.8
 
     """
-    return bool(elm_need_systray())
+    cdef bint ret = elm_need_systray()
+    if ret:
+        try:
+            _event_mapping_register(ELM_EVENT_SYSTRAY_READY, EventSystrayReady)
+        except ValueError:
+            pass
+    return ret
 
 def need_sys_notify():
     """Request that your elementary application needs Elm_Sys_Notify
@@ -72,7 +159,20 @@ def need_sys_notify():
     .. versionadded:: 1.8
 
     """
-    return bool(elm_need_sys_notify())
+    cdef bint ret = elm_need_sys_notify()
+    if ret:
+        try:
+            _event_mapping_register(
+                ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED,
+                SysNotifyNotificationClosed
+                )
+            _event_mapping_register(
+                ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED,
+                SysNotifyActionInvoked
+                )
+        except ValueError:
+            pass
+    return ret
 
 @DEPRECATED("1.8", "Use :py:func:`need_eldbus` for eldbus (v2) support. Old 
API is deprecated.")
 def need_e_dbus():
@@ -131,7 +231,12 @@ def need_ethumb():
     :rtype: bool
 
     """
-    return bool(elm_need_ethumb())
+    cdef bint ret = elm_need_ethumb()
+    try:
+        _event_mapping_register(ELM_ECORE_EVENT_ETHUMB_CONNECT, EthumbConnect)
+    except ValueError:
+        pass
+    return ret
 
 def need_web():
     """Request that your elementary application needs web support

-- 


Reply via email to