summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2015-04-17 11:32:50 +0300
committerKai Huuhko <kai.huuhko@gmail.com>2015-04-17 11:35:43 +0300
commit70fb839813b58c57c6bbfa13e7765ce7e89f61e1 (patch)
tree76abb475d7f667bc909f873505dd33206f70cd6a
parent9ffa09d72948cb86140b250afd66404305317dda (diff)
Elm: Move ecore events registration to init()
Fixes an issue with docs generation
-rw-r--r--efl/elementary/__init__.py1
-rw-r--r--efl/elementary/general.pxd1
-rw-r--r--efl/elementary/general.pyx290
-rw-r--r--efl/elementary/systray.pxd3
-rw-r--r--efl/elementary/systray.pyx10
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__ = (
84 "slideshow", 84 "slideshow",
85 "spinner", 85 "spinner",
86 #"store", 86 #"store",
87 "systray",
87 "table", 88 "table",
88 "theme", 89 "theme",
89 "thumb", 90 "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":
53 ELM_EVENT_PROCESS_FOREGROUND 53 ELM_EVENT_PROCESS_FOREGROUND
54 ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED 54 ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED
55 ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED 55 ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED
56 ELM_EVENT_SYSTRAY_READY
56 57
57 #enums 58 #enums
58 cpdef enum Elm_Object_Layer: 59 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, \
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 293from efl.elementary.need cimport elm_need_sys_notify, elm_need_systray, \
294 elm_need_ethumb
294 295
295import sys 296import sys
296import traceback 297import traceback
@@ -300,82 +301,13 @@ import atexit
300elm_log = add_logger("efl.elementary") 301elm_log = add_logger("efl.elementary")
301cdef int PY_EFL_ELM_LOG_DOMAIN = elm_log.eina_log_domain 302cdef int PY_EFL_ELM_LOG_DOMAIN = elm_log.eina_log_domain
302 303
303def init():
304 """Initialize Elementary
305
306 :return int: The init counter value.
307
308 This function initializes Elementary and increments a counter of the number
309 of calls to it. It returns the new counter's value.
310
311 .. versionchanged:: 1.14
312
313 The Python module calls this function when it is imported so you
314 should no longer have any need to call this manually. Calling it does
315 not carry any penalty though.
316
317 """
318 EINA_LOG_DOM_INFO(PY_EFL_ELM_LOG_DOMAIN,
319 "Initializing efl.elementary", NULL)
320
321 # FIXME: Why are we passing the cl args to elm_init here?
322
323 cdef:
324 int argc, i, arg_len
325 char **argv
326 char *arg
327
328 argc = len(sys.argv)
329 argv = <char **>PyMem_Malloc(argc * sizeof(char *))
330 for i in range(argc):
331 t = sys.argv[i]
332 if isinstance(t, unicode): t = PyUnicode_AsUTF8String(t)
333 arg = t
334 arg_len = len(arg)
335 argv[i] = <char *>PyMem_Malloc(arg_len + 1)
336 memcpy(argv[i], arg, arg_len + 1)
337
338 return elm_init(argc, argv)
339
340def shutdown():
341 """Shut down Elementary
342
343 :return int: The init counter value.
344
345 This should be called at the end of your application, just before it ceases
346 to do any more processing. This will clean up any permanent resources your
347 application may have allocated via Elementary that would otherwise persist.
348
349 .. note::
350
351 shutdown() will iterate main loop until all ecore_evas are freed. There
352 is a possibility to call your ecore callbacks(timer, animator, event,
353 job, and etc.) in shutdown()
354
355 .. versionchanged:: 1.14
356
357 The Python module calls this function when it is exiting so you
358 should no longer have any need to call this manually. Calling it does
359 not carry any penalty though.
360
361 """
362 EINA_LOG_DOM_INFO(PY_EFL_ELM_LOG_DOMAIN,
363 "Shutting down efl.elementary", NULL)
364 return elm_shutdown()
365
366
367init()
368atexit.register(shutdown)
369 304
305cdef class EventSystrayReady(Event):
306 cdef int _set_obj(self, void *o) except 0:
307 return 1
370 308
371cdef void py_elm_sys_notify_send_cb(void *data, unsigned int id): 309 def __repr__(self):
372 cdef object func, func_data 310 return "<%s()>" % (self.__class__.__name__,)
373 func, func_data = <object>data
374 # FIXME: Is this cb called more than once? Py_DECREF if not.
375 try:
376 func(func_data, id)
377 except Exception:
378 traceback.print_exc()
379 311
380 312
381cdef class SysNotifyNotificationClosed(Event): 313cdef class SysNotifyNotificationClosed(Event):
@@ -449,15 +381,6 @@ cdef class EthumbConnect(Event):
449 def __repr__(self): 381 def __repr__(self):
450 return "<%s()>" % (self.__class__.__name__,) 382 return "<%s()>" % (self.__class__.__name__,)
451 383
452_event_mapping_register(ELM_ECORE_EVENT_ETHUMB_CONNECT, EthumbConnect)
453
454def on_ethumb_connect(func, *args, **kwargs):
455 """Use this to set a handler for the ethumb connect event.
456
457 .. versionadded:: 1.14
458 """
459 return EventHandler(ELM_ECORE_EVENT_ETHUMB_CONNECT, func, *args, **kwargs)
460
461 384
462cdef class ConfigAllChanged(Event): 385cdef class ConfigAllChanged(Event):
463 cdef int _set_obj(self, void *o) except 0: 386 cdef int _set_obj(self, void *o) except 0:
@@ -466,18 +389,6 @@ cdef class ConfigAllChanged(Event):
466 def __repr__(self): 389 def __repr__(self):
467 return "<%s()>" % (self.__class__.__name__,) 390 return "<%s()>" % (self.__class__.__name__,)
468 391
469_event_mapping_register(ELM_EVENT_CONFIG_ALL_CHANGED, ConfigAllChanged)
470
471def on_config_all_changed(func, *args, **kwargs):
472 """Use this to set a handler for the config all changed event.
473
474 Emitted when the application has reconfigured elementary settings due to an
475 external configuration tool asking it to.
476
477 .. versionadded:: 1.14
478 """
479 return EventHandler(ELM_EVENT_CONFIG_ALL_CHANGED, func, *args, **kwargs)
480
481 392
482cdef class PolicyChanged(Event): 393cdef class PolicyChanged(Event):
483 394
@@ -499,26 +410,162 @@ cdef class PolicyChanged(Event):
499 self.__class__.__name__, 410 self.__class__.__name__,
500 self.policy, self.new_value, self.old_value) 411 self.policy, self.new_value, self.old_value)
501 412
502_event_mapping_register(ELM_EVENT_POLICY_CHANGED, PolicyChanged)
503 413
504def on_policy_changed(func, *args, **kwargs): 414cdef class ProcessBackground(Event):
505 """Use this to set a handler for the policy changed event. 415 cdef int _set_obj(self, void *o) except 0:
506 416 return 1
507 Emitted when any Elementary's policy value is changed.
508 417
509 .. versionadded:: 1.14 418 def __repr__(self):
510 """ 419 return "<%s()>" % (self.__class__.__name__,)
511 return EventHandler(ELM_EVENT_POLICY_CHANGED, func, *args, **kwargs)
512 420
513 421
514cdef class ProcessBackground(Event): 422cdef class ProcessForeground(Event):
515 cdef int _set_obj(self, void *o) except 0: 423 cdef int _set_obj(self, void *o) except 0:
516 return 1 424 return 1
517 425
518 def __repr__(self): 426 def __repr__(self):
519 return "<%s()>" % (self.__class__.__name__,) 427 return "<%s()>" % (self.__class__.__name__,)
520 428
521_event_mapping_register(ELM_EVENT_PROCESS_BACKGROUND, ProcessBackground) 429
430def init():
431 """Initialize Elementary
432
433 :return int: The init counter value.
434
435 This function initializes Elementary and increments a counter of the number
436 of calls to it. It returns the new counter's value.
437
438 .. versionchanged:: 1.14
439
440 The Python module calls this function when it is imported so you
441 should no longer have any need to call this manually. Calling it does
442 not carry any penalty though.
443
444 """
445 EINA_LOG_DOM_INFO(PY_EFL_ELM_LOG_DOMAIN,
446 "Initializing efl.elementary", NULL)
447
448 # FIXME: Why are we passing the cl args to elm_init here?
449
450 cdef:
451 int argc, i, arg_len
452 char **argv
453 char *arg
454 int ret
455
456 argc = len(sys.argv)
457 argv = <char **>PyMem_Malloc(argc * sizeof(char *))
458 for i in range(argc):
459 t = sys.argv[i]
460 if isinstance(t, unicode): t = PyUnicode_AsUTF8String(t)
461 arg = t
462 arg_len = len(arg)
463 argv[i] = <char *>PyMem_Malloc(arg_len + 1)
464 memcpy(argv[i], arg, arg_len + 1)
465
466 ret = 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
500def shutdown():
501 """Shut down Elementary
502
503 :return int: The init counter value.
504
505 This should be called at the end of your application, just before it ceases
506 to do any more processing. This will clean up any permanent resources your
507 application may have allocated via Elementary that would otherwise persist.
508
509 .. note::
510
511 shutdown() will iterate main loop until all ecore_evas are freed. There
512 is a possibility to call your ecore callbacks(timer, animator, event,
513 job, and etc.) in shutdown()
514
515 .. versionchanged:: 1.14
516
517 The Python module calls this function when it is exiting so you
518 should no longer have any need to call this manually. Calling it does
519 not carry any penalty though.
520
521 """
522 EINA_LOG_DOM_INFO(PY_EFL_ELM_LOG_DOMAIN,
523 "Shutting down efl.elementary", NULL)
524 return elm_shutdown()
525
526
527init()
528atexit.register(shutdown)
529
530
531cdef void py_elm_sys_notify_send_cb(void *data, unsigned int id):
532 cdef object func, func_data
533 func, func_data = <object>data
534 # FIXME: Is this cb called more than once? Py_DECREF if not.
535 try:
536 func(func_data, id)
537 except Exception:
538 traceback.print_exc()
539
540
541def on_ethumb_connect(func, *args, **kwargs):
542 """Use this to set a handler for the ethumb connect event.
543
544 .. versionadded:: 1.14
545 """
546 return EventHandler(ELM_ECORE_EVENT_ETHUMB_CONNECT, func, *args, **kwargs)
547
548
549def on_config_all_changed(func, *args, **kwargs):
550 """Use this to set a handler for the config all changed event.
551
552 Emitted when the application has reconfigured elementary settings due to an
553 external configuration tool asking it to.
554
555 .. versionadded:: 1.14
556 """
557 return EventHandler(ELM_EVENT_CONFIG_ALL_CHANGED, func, *args, **kwargs)
558
559
560def on_policy_changed(func, *args, **kwargs):
561 """Use this to set a handler for the policy changed event.
562
563 Emitted when any Elementary's policy value is changed.
564
565 .. versionadded:: 1.14
566 """
567 return EventHandler(ELM_EVENT_POLICY_CHANGED, func, *args, **kwargs)
568
522 569
523def on_process_background(func, *args, **kwargs): 570def on_process_background(func, *args, **kwargs):
524 """Use this to set a handler for the process background event. 571 """Use this to set a handler for the process background event.
@@ -531,15 +578,6 @@ def on_process_background(func, *args, **kwargs):
531 return EventHandler(ELM_EVENT_PROCESS_BACKGROUND, func, *args, **kwargs) 578 return EventHandler(ELM_EVENT_PROCESS_BACKGROUND, func, *args, **kwargs)
532 579
533 580
534cdef class ProcessForeground(Event):
535 cdef int _set_obj(self, void *o) except 0:
536 return 1
537
538 def __repr__(self):
539 return "<%s()>" % (self.__class__.__name__,)
540
541_event_mapping_register(ELM_EVENT_PROCESS_FOREGROUND, ProcessForeground)
542
543def on_process_background(func, *args, **kwargs): 581def on_process_background(func, *args, **kwargs):
544 """Use this to set a handler for the process foreground event. 582 """Use this to set a handler for the process foreground event.
545 583
@@ -551,27 +589,17 @@ def on_process_background(func, *args, **kwargs):
551 return EventHandler(ELM_EVENT_PROCESS_FOREGROUND, func, *args, **kwargs) 589 return EventHandler(ELM_EVENT_PROCESS_FOREGROUND, func, *args, **kwargs)
552 590
553 591
554if elm_need_sys_notify(): 592def on_sys_notify_notification_closed(func, *args, **kargs):
555 _event_mapping_register( 593 return EventHandler(
556 ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED, 594 ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED, func, *args, **kargs
557 SysNotifyNotificationClosed
558 ) 595 )
559 596
560 def on_sys_notify_notification_closed(func, *args, **kargs):
561 return EventHandler(
562 ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED, func, *args, **kargs
563 )
564 597
565 _event_mapping_register( 598def on_sys_notify_action_invoked(func, *args, **kargs):
566 ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED, 599 return EventHandler(
567 SysNotifyActionInvoked 600 ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED, func, *args, **kargs
568 ) 601 )
569 602
570 def on_sys_notify_action_invoked(func, *args, **kargs):
571 return EventHandler(
572 ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED, func, *args, **kargs
573 )
574
575 603
576cdef class FontProperties(object): 604cdef class FontProperties(object):
577 605
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":
6 6
7 ctypedef Eo Elm_Systray 7 ctypedef Eo Elm_Systray
8 8
9 cpdef enum:
10 ELM_EVENT_SYSTRAY_READY
11
12 cpdef enum _Elm_Systray_Category: 9 cpdef enum _Elm_Systray_Category:
13 ELM_SYSTRAY_CATEGORY_APP_STATUS 10 ELM_SYSTRAY_CATEGORY_APP_STATUS
14 ELM_SYSTRAY_CATEGORY_COMMUNICATIONS 11 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
84from efl.utils.conversions cimport _ctouni 84from efl.utils.conversions cimport _ctouni
85 85
86 86
87cdef class EventSystrayReady(Event):
88 cdef int _set_obj(self, void *o) except 0:
89 return 1
90
91 def __repr__(self):
92 return "<%s()>" % (self.__class__.__name__,)
93
94_event_mapping_register(ELM_EVENT_SYSTRAY_READY, EventSystrayReady)
95
96
97cdef class Systray(Eo): 87cdef class Systray(Eo):
98 88
99 """ 89 """