summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2015-04-20 06:25:43 +0300
committerKai Huuhko <kai.huuhko@gmail.com>2015-04-20 06:27:10 +0300
commitc08888239f30f8bc8f4707650cedd819a9a09b00 (patch)
treed9462accc1ed0c0fb2f43030054cbacc6934a023
parent6532ef85f6ef2118b0fcf59edbf7417ed17aceed (diff)
Elm: Move ecore events registration out of init
-rw-r--r--efl/elementary/general.pxd16
-rw-r--r--efl/elementary/general.pyx121
-rw-r--r--efl/elementary/need.pxd23
-rw-r--r--efl/elementary/need.pyx111
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":
93 ctypedef enum Elm_Policy_Throttle: 93 ctypedef enum Elm_Policy_Throttle:
94 pass 94 pass
95 95
96 cpdef enum Elm_Sys_Notify_Closed_Reason:
97 ELM_SYS_NOTIFY_CLOSED_EXPIRED
98 ELM_SYS_NOTIFY_CLOSED_DISMISSED
99 ELM_SYS_NOTIFY_CLOSED_REQUESTED
100 ELM_SYS_NOTIFY_CLOSED_UNDEFINED
101 ctypedef enum Elm_Sys_Notify_Closed_Reason:
102 pass
103
104 cpdef enum Elm_Sys_Notify_Urgency: 96 cpdef enum Elm_Sys_Notify_Urgency:
105 ELM_SYS_NOTIFY_URGENCY_LOW 97 ELM_SYS_NOTIFY_URGENCY_LOW
106 ELM_SYS_NOTIFY_URGENCY_NORMAL 98 ELM_SYS_NOTIFY_URGENCY_NORMAL
@@ -208,14 +200,6 @@ cdef extern from "Elementary.h":
208 # sys_notify.h 200 # sys_notify.h
209 ctypedef void (*Elm_Sys_Notify_Send_Cb)(void *data, unsigned int id) 201 ctypedef void (*Elm_Sys_Notify_Send_Cb)(void *data, unsigned int id)
210 202
211 ctypedef struct Elm_Sys_Notify_Notification_Closed:
212 unsigned int id # ID of the notification.
213 Elm_Sys_Notify_Closed_Reason reason # The Reason the notification was closed.
214
215 ctypedef struct Elm_Sys_Notify_Action_Invoked:
216 unsigned int id # ID of the notification.
217 char *action_key # The key of the action invoked. These match the keys sent over in the list of actions.
218
219 void elm_sys_notify_close(unsigned int id) 203 void elm_sys_notify_close(unsigned int id)
220 void elm_sys_notify_send( unsigned int replaces_id, 204 void elm_sys_notify_send( unsigned int replaces_id,
221 const char *icon, 205 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, \
290 EINA_LOG_DOM_WARN, EINA_LOG_DOM_ERR, EINA_LOG_DOM_CRIT 290 EINA_LOG_DOM_WARN, EINA_LOG_DOM_ERR, EINA_LOG_DOM_CRIT
291 291
292from efl.ecore cimport Event, EventHandler, _event_mapping_register 292from efl.ecore cimport Event, EventHandler, _event_mapping_register
293from efl.elementary.need cimport elm_need_sys_notify, elm_need_systray, \
294 elm_need_ethumb
295 293
296import sys 294import sys
297import traceback 295import traceback
@@ -302,86 +300,6 @@ elm_log = add_logger("efl.elementary")
302cdef int PY_EFL_ELM_LOG_DOMAIN = elm_log.eina_log_domain 300cdef int PY_EFL_ELM_LOG_DOMAIN = elm_log.eina_log_domain
303 301
304 302
305cdef class EventSystrayReady(Event):
306 cdef int _set_obj(self, void *o) except 0:
307 return 1
308
309 def __repr__(self):
310 return "<%s()>" % (self.__class__.__name__,)
311
312
313cdef class SysNotifyNotificationClosed(Event):
314
315 cdef Elm_Sys_Notify_Notification_Closed *obj
316
317 cdef int _set_obj(self, void *o) except 0:
318 self.obj = <Elm_Sys_Notify_Notification_Closed*>o
319 return 1
320
321 def __repr__(self):
322 # TODO: int -> string for 'reason'
323 return "<%s(id=%d, reason=%s)>" % \
324 (type(self).__name__, self.id, self.reason)
325
326 property id:
327 """ID of the notification.
328
329 :type: int
330
331 """
332 def __get__(self):
333 return self.obj.id
334
335 property reason:
336 """The Reason the notification was closed.
337
338 :type: :ref:`Elm_Sys_Notify_Closed_Reason`
339
340 """
341 def __get__(self):
342 return self.obj.reason
343
344
345cdef class SysNotifyActionInvoked(Event):
346
347 cdef Elm_Sys_Notify_Action_Invoked *obj
348
349 cdef int _set_obj(self, void *o) except 0:
350 self.obj = <Elm_Sys_Notify_Action_Invoked*>o
351 return 1
352
353 def __repr__(self):
354 return "<%s(id=%d, action_key=%s)>" % \
355 (type(self).__name__, self.id, self.action_key)
356
357 property id:
358 """ID of the notification.
359
360 :type: int
361
362 """
363 def __get__(self):
364 return self.obj.id
365
366 property action_key:
367 """The key of the action invoked. These match the keys sent over in the
368 list of actions.
369
370 :type: string
371
372 """
373 def __get__(self):
374 return _touni(self.obj.action_key)
375
376
377cdef class EthumbConnect(Event):
378 cdef int _set_obj(self, void *o) except 0:
379 return 1
380
381 def __repr__(self):
382 return "<%s()>" % (self.__class__.__name__,)
383
384
385cdef class ConfigAllChanged(Event): 303cdef class ConfigAllChanged(Event):
386 cdef int _set_obj(self, void *o) except 0: 304 cdef int _set_obj(self, void *o) except 0:
387 return 1 305 return 1
@@ -463,39 +381,7 @@ def init():
463 argv[i] = <char *>PyMem_Malloc(arg_len + 1) 381 argv[i] = <char *>PyMem_Malloc(arg_len + 1)
464 memcpy(argv[i], arg, arg_len + 1) 382 memcpy(argv[i], arg, arg_len + 1)
465 383
466 ret = elm_init(argc, argv) 384 return elm_init(argc, argv)
467
468 if ret != 1:
469 return ret
470
471 if elm_need_ethumb():
472 _event_mapping_register(ELM_ECORE_EVENT_ETHUMB_CONNECT, EthumbConnect)
473 else:
474 EINA_LOG_DOM_WARN(PY_EFL_ELM_LOG_DOMAIN, "Ethumb not available", NULL)
475
476 _event_mapping_register(ELM_EVENT_CONFIG_ALL_CHANGED, ConfigAllChanged)
477 _event_mapping_register(ELM_EVENT_POLICY_CHANGED, PolicyChanged)
478 _event_mapping_register(ELM_EVENT_PROCESS_BACKGROUND, ProcessBackground)
479 _event_mapping_register(ELM_EVENT_PROCESS_FOREGROUND, ProcessForeground)
480
481 if elm_need_systray():
482 _event_mapping_register(ELM_EVENT_SYSTRAY_READY, EventSystrayReady)
483 else:
484 EINA_LOG_DOM_WARN(PY_EFL_ELM_LOG_DOMAIN, "Systray not available", NULL)
485
486 if elm_need_sys_notify():
487 _event_mapping_register(
488 ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED,
489 SysNotifyNotificationClosed
490 )
491 _event_mapping_register(
492 ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED,
493 SysNotifyActionInvoked
494 )
495 else:
496 EINA_LOG_DOM_WARN(PY_EFL_ELM_LOG_DOMAIN, "Sys notify not available", NULL)
497
498 return ret
499 385
500def shutdown(): 386def shutdown():
501 """Shut down Elementary 387 """Shut down Elementary
@@ -527,6 +413,11 @@ def shutdown():
527init() 413init()
528atexit.register(shutdown) 414atexit.register(shutdown)
529 415
416_event_mapping_register(ELM_EVENT_CONFIG_ALL_CHANGED, ConfigAllChanged)
417_event_mapping_register(ELM_EVENT_POLICY_CHANGED, PolicyChanged)
418_event_mapping_register(ELM_EVENT_PROCESS_BACKGROUND, ProcessBackground)
419_event_mapping_register(ELM_EVENT_PROCESS_FOREGROUND, ProcessForeground)
420
530 421
531cdef void py_elm_sys_notify_send_cb(void *data, unsigned int id): 422cdef void py_elm_sys_notify_send_cb(void *data, unsigned int id):
532 cdef object func, func_data 423 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 @@
1from efl.evas cimport Eina_Bool 1from efl.evas cimport Eina_Bool
2 2
3cdef extern from "Elementary.h": 3cdef extern from "Elementary.h":
4 cpdef enum:
5 ELM_ECORE_EVENT_ETHUMB_CONNECT
6 ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED
7 ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED
8 ELM_EVENT_SYSTRAY_READY
9
10 ctypedef struct Elm_Sys_Notify_Notification_Closed:
11 unsigned int id # ID of the notification.
12 Elm_Sys_Notify_Closed_Reason reason # The Reason the notification was closed.
13
14 ctypedef struct Elm_Sys_Notify_Action_Invoked:
15 unsigned int id # ID of the notification.
16 char *action_key # The key of the action invoked. These match the keys sent over in the list of actions.
17
18 cpdef enum Elm_Sys_Notify_Closed_Reason:
19 ELM_SYS_NOTIFY_CLOSED_EXPIRED
20 ELM_SYS_NOTIFY_CLOSED_DISMISSED
21 ELM_SYS_NOTIFY_CLOSED_REQUESTED
22 ELM_SYS_NOTIFY_CLOSED_UNDEFINED
23 ctypedef enum Elm_Sys_Notify_Closed_Reason:
24 pass
25
26
4 Eina_Bool elm_need_efreet() 27 Eina_Bool elm_need_efreet()
5 Eina_Bool elm_need_systray() 28 Eina_Bool elm_need_systray()
6 Eina_Bool elm_need_sys_notify() 29 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.
29 29
30 30
31from efl.utils.deprecated cimport DEPRECATED 31from efl.utils.deprecated cimport DEPRECATED
32from efl.utils.conversions cimport _touni
33from efl.ecore cimport Event, _event_mapping_register
34
35
36cdef class SysNotifyNotificationClosed(Event):
37
38 cdef Elm_Sys_Notify_Notification_Closed *obj
39
40 cdef int _set_obj(self, void *o) except 0:
41 self.obj = <Elm_Sys_Notify_Notification_Closed*>o
42 return 1
43
44 def __repr__(self):
45 # TODO: int -> string for 'reason'
46 return "<%s(id=%d, reason=%s)>" % \
47 (type(self).__name__, self.id, self.reason)
48
49 property id:
50 """ID of the notification.
51
52 :type: int
53
54 """
55 def __get__(self):
56 return self.obj.id
57
58 property reason:
59 """The Reason the notification was closed.
60
61 :type: :ref:`Elm_Sys_Notify_Closed_Reason`
62
63 """
64 def __get__(self):
65 return self.obj.reason
66
67
68cdef class SysNotifyActionInvoked(Event):
69
70 cdef Elm_Sys_Notify_Action_Invoked *obj
71
72 cdef int _set_obj(self, void *o) except 0:
73 self.obj = <Elm_Sys_Notify_Action_Invoked*>o
74 return 1
75
76 def __repr__(self):
77 return "<%s(id=%d, action_key=%s)>" % \
78 (type(self).__name__, self.id, self.action_key)
79
80 property id:
81 """ID of the notification.
82
83 :type: int
84
85 """
86 def __get__(self):
87 return self.obj.id
88
89 property action_key:
90 """The key of the action invoked. These match the keys sent over in the
91 list of actions.
92
93 :type: string
94
95 """
96 def __get__(self):
97 return _touni(self.obj.action_key)
98
99
100cdef class EthumbConnect(Event):
101 cdef int _set_obj(self, void *o) except 0:
102 return 1
103
104 def __repr__(self):
105 return "<%s()>" % (self.__class__.__name__,)
106
107cdef class EventSystrayReady(Event):
108 cdef int _set_obj(self, void *o) except 0:
109 return 1
110
111 def __repr__(self):
112 return "<%s()>" % (self.__class__.__name__,)
32 113
33 114
34def need_efreet(): 115def need_efreet():
@@ -57,7 +138,13 @@ def need_systray():
57 .. versionadded:: 1.8 138 .. versionadded:: 1.8
58 139
59 """ 140 """
60 return bool(elm_need_systray()) 141 cdef bint ret = elm_need_systray()
142 if ret:
143 try:
144 _event_mapping_register(ELM_EVENT_SYSTRAY_READY, EventSystrayReady)
145 except ValueError:
146 pass
147 return ret
61 148
62def need_sys_notify(): 149def need_sys_notify():
63 """Request that your elementary application needs Elm_Sys_Notify 150 """Request that your elementary application needs Elm_Sys_Notify
@@ -72,7 +159,20 @@ def need_sys_notify():
72 .. versionadded:: 1.8 159 .. versionadded:: 1.8
73 160
74 """ 161 """
75 return bool(elm_need_sys_notify()) 162 cdef bint ret = elm_need_sys_notify()
163 if ret:
164 try:
165 _event_mapping_register(
166 ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED,
167 SysNotifyNotificationClosed
168 )
169 _event_mapping_register(
170 ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED,
171 SysNotifyActionInvoked
172 )
173 except ValueError:
174 pass
175 return ret
76 176
77@DEPRECATED("1.8", "Use :py:func:`need_eldbus` for eldbus (v2) support. Old API is deprecated.") 177@DEPRECATED("1.8", "Use :py:func:`need_eldbus` for eldbus (v2) support. Old API is deprecated.")
78def need_e_dbus(): 178def need_e_dbus():
@@ -131,7 +231,12 @@ def need_ethumb():
131 :rtype: bool 231 :rtype: bool
132 232
133 """ 233 """
134 return bool(elm_need_ethumb()) 234 cdef bint ret = elm_need_ethumb()
235 try:
236 _event_mapping_register(ELM_ECORE_EVENT_ETHUMB_CONNECT, EthumbConnect)
237 except ValueError:
238 pass
239 return ret
135 240
136def need_web(): 241def need_web():
137 """Request that your elementary application needs web support 242 """Request that your elementary application needs web support