summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2015-04-15 00:15:59 +0300
committerKai Huuhko <kai.huuhko@gmail.com>2015-04-15 00:17:24 +0300
commit278fe321107aa6d37e9a14ec957ed2360e09a69f (patch)
tree6211afafc0bb4d23bae2eb5d8d0a5597151edec6
parent75f3f3b70a49072caa2e697dce30c0ecaa73552a (diff)
Elm: Add ecore events defined in elm_general.h
-rw-r--r--efl/elementary/general.pxd11
-rw-r--r--efl/elementary/general.pyx102
-rwxr-xr-xexamples/elementary/test.py2
-rw-r--r--examples/elementary/test_core_ecore_events_in_elm.py85
4 files changed, 200 insertions, 0 deletions
diff --git a/efl/elementary/general.pxd b/efl/elementary/general.pxd
index 8145036..63b653d 100644
--- a/efl/elementary/general.pxd
+++ b/efl/elementary/general.pxd
@@ -46,6 +46,11 @@ cdef extern from "Elementary.h":
46 46
47 #define 47 #define
48 cpdef enum: 48 cpdef enum:
49 ELM_ECORE_EVENT_ETHUMB_CONNECT
50 ELM_EVENT_CONFIG_ALL_CHANGED
51 ELM_EVENT_POLICY_CHANGED
52 ELM_EVENT_PROCESS_BACKGROUND
53 ELM_EVENT_PROCESS_FOREGROUND
49 ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED 54 ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED
50 ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED 55 ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED
51 56
@@ -140,6 +145,12 @@ cdef extern from "Elementary.h":
140 ctypedef Evas_Object * (*Elm_Tooltip_Item_Content_Cb) (void *data, Evas_Object *obj, Evas_Object *tooltip, void *item) 145 ctypedef Evas_Object * (*Elm_Tooltip_Item_Content_Cb) (void *data, Evas_Object *obj, Evas_Object *tooltip, void *item)
141 146
142 # General 147 # General
148 struct _Elm_Event_Policy_Changed:
149 unsigned int policy # the policy identifier
150 int new_value # value the policy had before the change
151 int old_value # new value the policy got
152 ctypedef _Elm_Event_Policy_Changed Elm_Event_Policy_Changed
153
143 int elm_init(int argc, char** argv) 154 int elm_init(int argc, char** argv)
144 int elm_shutdown() 155 int elm_shutdown()
145 void elm_run() nogil 156 void elm_run() nogil
diff --git a/efl/elementary/general.pyx b/efl/elementary/general.pyx
index 0ba4467..12e2ae6 100644
--- a/efl/elementary/general.pyx
+++ b/efl/elementary/general.pyx
@@ -333,6 +333,7 @@ cdef void py_elm_sys_notify_send_cb(void *data, unsigned int id):
333 except Exception: 333 except Exception:
334 traceback.print_exc() 334 traceback.print_exc()
335 335
336
336cdef class SysNotifyNotificationClosed(Event): 337cdef class SysNotifyNotificationClosed(Event):
337 338
338 cdef Elm_Sys_Notify_Notification_Closed *obj 339 cdef Elm_Sys_Notify_Notification_Closed *obj
@@ -364,6 +365,7 @@ cdef class SysNotifyNotificationClosed(Event):
364 def __get__(self): 365 def __get__(self):
365 return self.obj.reason 366 return self.obj.reason
366 367
368
367cdef class SysNotifyActionInvoked(Event): 369cdef class SysNotifyActionInvoked(Event):
368 370
369 cdef Elm_Sys_Notify_Action_Invoked *obj 371 cdef Elm_Sys_Notify_Action_Invoked *obj
@@ -395,6 +397,104 @@ cdef class SysNotifyActionInvoked(Event):
395 def __get__(self): 397 def __get__(self):
396 return _touni(self.obj.action_key) 398 return _touni(self.obj.action_key)
397 399
400
401cdef class EthumbConnect(Event):
402 cdef int _set_obj(self, void *o) except 0:
403 return 1
404
405 def __repr__(self):
406 return "<%s()>" % (self.__class__.__name__,)
407
408_event_mapping_register(ELM_ECORE_EVENT_ETHUMB_CONNECT, EthumbConnect)
409
410def on_ethumb_connect(func, *args, **kwargs):
411 """Use this to set a handler for the ethumb connect event."""
412 return EventHandler(ELM_ECORE_EVENT_ETHUMB_CONNECT, func, *args, **kwargs)
413
414
415cdef class ConfigAllChanged(Event):
416 cdef int _set_obj(self, void *o) except 0:
417 return 1
418
419 def __repr__(self):
420 return "<%s()>" % (self.__class__.__name__,)
421
422_event_mapping_register(ELM_EVENT_CONFIG_ALL_CHANGED, ConfigAllChanged)
423
424def on_config_all_changed(func, *args, **kwargs):
425 """Use this to set a handler for the config all changed event.
426
427 Emitted when the application has reconfigured elementary settings due to an
428 external configuration tool asking it to.
429 """
430 return EventHandler(ELM_EVENT_CONFIG_ALL_CHANGED, func, *args, **kwargs)
431
432
433cdef class PolicyChanged(Event):
434
435 cdef:
436 public unsigned int policy
437 public int new_value
438 public int old_value
439
440 cdef int _set_obj(self, void *o) except 0:
441 cdef Elm_Event_Policy_Changed *obj
442 obj = <Elm_Event_Policy_Changed *>o
443 self.policy = obj.policy
444 self.new_value = obj.new_value
445 self.old_value = obj.old_value
446 return 1
447
448 def __repr__(self):
449 return "<%s(policy=%d, new_value=%d, old_value=%d)>" % (
450 self.__class__.__name__,
451 self.policy, self.new_value, self.old_value)
452
453_event_mapping_register(ELM_EVENT_POLICY_CHANGED, PolicyChanged)
454
455def on_policy_changed(func, *args, **kwargs):
456 """Use this to set a handler for the policy changed event.
457
458 Emitted when any Elementary's policy value is changed."""
459 return EventHandler(ELM_EVENT_POLICY_CHANGED, func, *args, **kwargs)
460
461
462cdef class ProcessBackground(Event):
463 cdef int _set_obj(self, void *o) except 0:
464 return 1
465
466 def __repr__(self):
467 return "<%s()>" % (self.__class__.__name__,)
468
469_event_mapping_register(ELM_EVENT_PROCESS_BACKGROUND, ProcessBackground)
470
471def on_process_background(func, *args, **kwargs):
472 """Use this to set a handler for the process background event.
473
474 Emitted when nothing is visible and the process as a whole should go into a
475 background state.
476 """
477 return EventHandler(ELM_EVENT_PROCESS_BACKGROUND, func, *args, **kwargs)
478
479
480cdef class ProcessForeground(Event):
481 cdef int _set_obj(self, void *o) except 0:
482 return 1
483
484 def __repr__(self):
485 return "<%s()>" % (self.__class__.__name__,)
486
487_event_mapping_register(ELM_EVENT_PROCESS_FOREGROUND, ProcessForeground)
488
489def on_process_background(func, *args, **kwargs):
490 """Use this to set a handler for the process foreground event.
491
492 Emitted when going from nothing being visible to at least one window being
493 visible.
494 """
495 return EventHandler(ELM_EVENT_PROCESS_FOREGROUND, func, *args, **kwargs)
496
497
398if elm_need_sys_notify(): 498if elm_need_sys_notify():
399 _event_mapping_register( 499 _event_mapping_register(
400 ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED, 500 ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED,
@@ -416,6 +516,7 @@ if elm_need_sys_notify():
416 ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED, func, *args, **kargs 516 ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED, func, *args, **kargs
417 ) 517 )
418 518
519
419cdef class FontProperties(object): 520cdef class FontProperties(object):
420 521
421 """Elementary font properties""" 522 """Elementary font properties"""
@@ -755,3 +856,4 @@ def sys_notify_send(
755 <Elm_Sys_Notify_Send_Cb>py_elm_sys_notify_send_cb if cb is not None else NULL, 856 <Elm_Sys_Notify_Send_Cb>py_elm_sys_notify_send_cb if cb is not None else NULL,
756 <const void *>py_cb_data if cb is not None else NULL 857 <const void *>py_cb_data if cb is not None else NULL
757 ) 858 )
859
diff --git a/examples/elementary/test.py b/examples/elementary/test.py
index 4f9bb19..eebfc0f 100755
--- a/examples/elementary/test.py
+++ b/examples/elementary/test.py
@@ -38,6 +38,8 @@ elog.setLevel(logging.DEBUG)
38 38
39items = [ 39items = [
40 ("Core Libs", [ 40 ("Core Libs", [
41 ("Ecore Events In Elm", "test_core_ecore_events_in_elm",
42 "core_ecore_events_in_elm_clicked"),
41 ("Evas Objects", "test_core_evas_objects", "core_evas_objects_clicked"), 43 ("Evas Objects", "test_core_evas_objects", "core_evas_objects_clicked"),
42 ("Evas Canvas Callbacks", "test_core_evas_canvas_callbacks", 44 ("Evas Canvas Callbacks", "test_core_evas_canvas_callbacks",
43 "core_evas_canvas_callbacks_clicked"), 45 "core_evas_canvas_callbacks_clicked"),
diff --git a/examples/elementary/test_core_ecore_events_in_elm.py b/examples/elementary/test_core_ecore_events_in_elm.py
new file mode 100644
index 0000000..10a90a0
--- /dev/null
+++ b/examples/elementary/test_core_ecore_events_in_elm.py
@@ -0,0 +1,85 @@
1#!/usr/bin/env python
2# encoding: utf-8
3
4from __future__ import print_function
5
6from efl.evas import EXPAND_BOTH, FILL_BOTH
7
8from efl import elementary
9from efl.elementary.window import StandardWindow
10from efl.elementary.box import Box
11from efl.elementary.button import Button
12from efl.elementary.notify import Notify
13from efl.elementary.label import Label
14from efl.elementary.general import policy_get, policy_set, on_policy_changed, \
15 ELM_POLICY_QUIT, ELM_POLICY_EXIT, ELM_POLICY_THROTTLE, ELM_POLICY_LAST, \
16 ELM_POLICY_QUIT_NONE, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED
17
18win = None
19
20
21policy_mapping = {
22 ELM_POLICY_QUIT: "ELM_POLICY_QUIT",
23 ELM_POLICY_EXIT: "ELM_POLICY_EXIT",
24 ELM_POLICY_THROTTLE: "ELM_POLICY_THROTTLE",
25 ELM_POLICY_LAST: "ELM_POLICY_LAST"
26}
27
28policy_quit_value_mapping = {
29 ELM_POLICY_QUIT_NONE: "ELM_POLICY_QUIT_NONE",
30 ELM_POLICY_QUIT_LAST_WINDOW_CLOSED: "ELM_POLICY_QUIT_LAST_WINDOW_CLOSED"
31}
32
33
34@on_policy_changed
35def policy_changed(ev):
36 text = "policy changed: %s<br>new value: %s<br>old value: %s" % (
37 policy_mapping[ev.policy],
38 policy_quit_value_mapping[ev.new_value],
39 policy_quit_value_mapping[ev.old_value])
40 n = Notify(win, timeout=5)
41 l = Label(n, text=text)
42 n.content = l
43 l.show()
44 n.show()
45
46
47def core_ecore_events_in_elm_clicked(obj, item=None):
48 global win
49 win = StandardWindow(
50 "ecoreevents", "Ecore events in Elm", autodel=True,
51 size=(480, 240))
52 if obj is None:
53 win.callback_delete_request_add(lambda o: elementary.exit())
54
55 hbox = Box(
56 win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH,
57 horizontal=True)
58 win.resize_object_add(hbox)
59 hbox.show()
60
61 b = Button(win, text="change quit policy", size_hint_align=(0.5, 1.0))
62 hbox.pack_end(b)
63
64 def policy_change(btn):
65 old_value = bool(policy_get(ELM_POLICY_QUIT))
66 new_value = not old_value
67 policy_set(ELM_POLICY_QUIT, new_value)
68 print("changing policy: %s\nnew value: %s\nold value: %s" % (
69 "ELM_POLICY_QUIT",
70 policy_quit_value_mapping[new_value],
71 policy_quit_value_mapping[old_value]))
72
73 b.callback_clicked_add(policy_change)
74 b.show()
75
76 win.show()
77
78
79if __name__ == "__main__":
80 elementary.init()
81
82 core_ecore_events_in_elm_clicked(None)
83
84 elementary.run()
85 elementary.shutdown()