summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2015-04-15 00:12:03 +0300
committerKai Huuhko <kai.huuhko@gmail.com>2015-04-15 00:17:24 +0300
commit75f3f3b70a49072caa2e697dce30c0ecaa73552a (patch)
tree7bbdb1f9a9cf7b92b8ff8132cde59d7eb104cc51
parenteb60fbc01ea31fb3ad9e48c33d7f14aef51db8ae (diff)
Elm: Handle init and shutdown inside the module
-rw-r--r--efl/elementary/general.pyx114
1 files changed, 61 insertions, 53 deletions
diff --git a/efl/elementary/general.pyx b/efl/elementary/general.pyx
index 42bea89..0ba4467 100644
--- a/efl/elementary/general.pyx
+++ b/efl/elementary/general.pyx
@@ -262,6 +262,67 @@ from efl.elementary.need cimport elm_need_sys_notify
262 262
263import sys 263import sys
264import traceback 264import traceback
265import atexit
266
267
268elm_log = add_logger("efl.elementary")
269cdef int PY_EFL_ELM_LOG_DOMAIN = elm_log.eina_log_domain
270
271def init():
272 """Initialize Elementary
273
274 :return int: The init counter value.
275
276 This function initializes Elementary and increments a counter of the number
277 of calls to it. It returns the new counter's value.
278
279 """
280 EINA_LOG_DOM_INFO(PY_EFL_ELM_LOG_DOMAIN,
281 "Initializing efl.elementary", NULL)
282
283 # FIXME: Why are we passing the cl args to elm_init here?
284
285 cdef:
286 int argc, i, arg_len
287 char **argv
288 char *arg
289
290 argc = len(sys.argv)
291 argv = <char **>PyMem_Malloc(argc * sizeof(char *))
292 for i in range(argc):
293 t = sys.argv[i]
294 if isinstance(t, unicode): t = PyUnicode_AsUTF8String(t)
295 arg = t
296 arg_len = len(arg)
297 argv[i] = <char *>PyMem_Malloc(arg_len + 1)
298 memcpy(argv[i], arg, arg_len + 1)
299
300 return elm_init(argc, argv)
301
302def shutdown():
303 """Shut down Elementary
304
305 :return int: The init counter value.
306
307 This should be called at the end of your application, just before it ceases
308 to do any more processing. This will clean up any permanent resources your
309 application may have allocated via Elementary that would otherwise persist.
310
311 .. note::
312
313 shutdown() will iterate main loop until all ecore_evas are freed. There
314 is a possibility to call your ecore callbacks(timer, animator, event,
315 job, and etc.) in shutdown()
316
317 """
318 EINA_LOG_DOM_INFO(PY_EFL_ELM_LOG_DOMAIN,
319 "Shutting down efl.elementary", NULL)
320 return elm_shutdown()
321
322
323init()
324atexit.register(shutdown)
325
265 326
266cdef void py_elm_sys_notify_send_cb(void *data, unsigned int id): 327cdef void py_elm_sys_notify_send_cb(void *data, unsigned int id):
267 cdef object func, func_data 328 cdef object func, func_data
@@ -378,59 +439,6 @@ cdef class FontProperties(object):
378 def __get__(self): 439 def __get__(self):
379 return eina_list_strings_to_python_list(self.efp.styles) 440 return eina_list_strings_to_python_list(self.efp.styles)
380 441
381elm_log = add_logger("efl.elementary")
382cdef int PY_EFL_ELM_LOG_DOMAIN = elm_log.eina_log_domain
383
384def init():
385 """Initialize Elementary
386
387 :return int: The init counter value.
388
389 This function initializes Elementary and increments a counter of the number
390 of calls to it. It returns the new counter's value.
391
392 """
393 EINA_LOG_DOM_INFO(PY_EFL_ELM_LOG_DOMAIN,
394 "Initializing efl.elementary", NULL)
395
396 # FIXME: Why are we passing the cl args to elm_init here?
397
398 cdef:
399 int argc, i, arg_len
400 char **argv
401 char *arg
402
403 argc = len(sys.argv)
404 argv = <char **>PyMem_Malloc(argc * sizeof(char *))
405 for i in range(argc):
406 t = sys.argv[i]
407 if isinstance(t, unicode): t = PyUnicode_AsUTF8String(t)
408 arg = t
409 arg_len = len(arg)
410 argv[i] = <char *>PyMem_Malloc(arg_len + 1)
411 memcpy(argv[i], arg, arg_len + 1)
412
413 return elm_init(argc, argv)
414
415def shutdown():
416 """Shut down Elementary
417
418 :return int: The init counter value.
419
420 This should be called at the end of your application, just before it ceases
421 to do any more processing. This will clean up any permanent resources your
422 application may have allocated via Elementary that would otherwise persist.
423
424 .. note::
425
426 shutdown() will iterate main loop until all ecore_evas are freed. There
427 is a possibility to call your ecore callbacks(timer, animator, event,
428 job, and etc.) in shutdown()
429
430 """
431 EINA_LOG_DOM_INFO(PY_EFL_ELM_LOG_DOMAIN,
432 "Shutting down efl.elementary", NULL)
433 return elm_shutdown()
434 442
435def run(): 443def run():
436 """Run Elementary's main loop 444 """Run Elementary's main loop