kuuko pushed a commit to branch master.

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

commit 278fe321107aa6d37e9a14ec957ed2360e09a69f
Author: Kai Huuhko <kai.huu...@gmail.com>
Date:   Wed Apr 15 00:15:59 2015 +0300

    Elm: Add ecore events defined in elm_general.h
---
 efl/elementary/general.pxd                         |  11 +++
 efl/elementary/general.pyx                         | 102 +++++++++++++++++++++
 examples/elementary/test.py                        |   2 +
 .../elementary/test_core_ecore_events_in_elm.py    |  85 +++++++++++++++++
 4 files changed, 200 insertions(+)

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":
 
     #define
     cpdef enum:
+        ELM_ECORE_EVENT_ETHUMB_CONNECT
+        ELM_EVENT_CONFIG_ALL_CHANGED
+        ELM_EVENT_POLICY_CHANGED
+        ELM_EVENT_PROCESS_BACKGROUND
+        ELM_EVENT_PROCESS_FOREGROUND
         ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED
         ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED
 
@@ -140,6 +145,12 @@ cdef extern from "Elementary.h":
     ctypedef Evas_Object *  (*Elm_Tooltip_Item_Content_Cb)  (void *data, 
Evas_Object *obj, Evas_Object *tooltip, void *item)
 
     # General
+    struct _Elm_Event_Policy_Changed:
+        unsigned int policy # the policy identifier
+        int          new_value # value the policy had before the change
+        int          old_value # new value the policy got
+    ctypedef _Elm_Event_Policy_Changed Elm_Event_Policy_Changed
+
     int                     elm_init(int argc, char** argv)
     int                     elm_shutdown()
     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):
     except Exception:
         traceback.print_exc()
 
+
 cdef class SysNotifyNotificationClosed(Event):
 
     cdef Elm_Sys_Notify_Notification_Closed *obj
@@ -364,6 +365,7 @@ cdef class SysNotifyNotificationClosed(Event):
         def __get__(self):
             return self.obj.reason
 
+
 cdef class SysNotifyActionInvoked(Event):
 
     cdef Elm_Sys_Notify_Action_Invoked *obj
@@ -395,6 +397,104 @@ cdef class SysNotifyActionInvoked(Event):
         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__,)
+
+_event_mapping_register(ELM_ECORE_EVENT_ETHUMB_CONNECT, EthumbConnect)
+
+def on_ethumb_connect(func, *args, **kwargs):
+    """Use this to set a handler for the ethumb connect event."""
+    return EventHandler(ELM_ECORE_EVENT_ETHUMB_CONNECT, func, *args, **kwargs)
+
+
+cdef class ConfigAllChanged(Event):
+    cdef int _set_obj(self, void *o) except 0:
+        return 1
+
+    def __repr__(self):
+        return "<%s()>" % (self.__class__.__name__,)
+
+_event_mapping_register(ELM_EVENT_CONFIG_ALL_CHANGED, ConfigAllChanged)
+
+def on_config_all_changed(func, *args, **kwargs):
+    """Use this to set a handler for the config all changed event.
+
+    Emitted when the application has reconfigured elementary settings due to an
+    external configuration tool asking it to.
+    """
+    return EventHandler(ELM_EVENT_CONFIG_ALL_CHANGED, func, *args, **kwargs)
+
+
+cdef class PolicyChanged(Event):
+
+    cdef:
+        public unsigned int policy
+        public int new_value
+        public int old_value
+
+    cdef int _set_obj(self, void *o) except 0:
+        cdef Elm_Event_Policy_Changed *obj
+        obj = <Elm_Event_Policy_Changed *>o
+        self.policy = obj.policy
+        self.new_value = obj.new_value
+        self.old_value = obj.old_value
+        return 1
+
+    def __repr__(self):
+        return "<%s(policy=%d, new_value=%d, old_value=%d)>" % (
+            self.__class__.__name__,
+            self.policy, self.new_value, self.old_value)
+
+_event_mapping_register(ELM_EVENT_POLICY_CHANGED, PolicyChanged)
+
+def on_policy_changed(func, *args, **kwargs):
+    """Use this to set a handler for the policy changed event.
+
+    Emitted when any Elementary's policy value is changed."""
+    return EventHandler(ELM_EVENT_POLICY_CHANGED, func, *args, **kwargs)
+
+
+cdef class ProcessBackground(Event):
+    cdef int _set_obj(self, void *o) except 0:
+        return 1
+
+    def __repr__(self):
+        return "<%s()>" % (self.__class__.__name__,)
+
+_event_mapping_register(ELM_EVENT_PROCESS_BACKGROUND, ProcessBackground)
+
+def on_process_background(func, *args, **kwargs):
+    """Use this to set a handler for the process background event.
+
+    Emitted when nothing is visible and the process as a whole should go into a
+    background state.
+    """
+    return EventHandler(ELM_EVENT_PROCESS_BACKGROUND, func, *args, **kwargs)
+
+
+cdef class ProcessForeground(Event):
+    cdef int _set_obj(self, void *o) except 0:
+        return 1
+
+    def __repr__(self):
+        return "<%s()>" % (self.__class__.__name__,)
+
+_event_mapping_register(ELM_EVENT_PROCESS_FOREGROUND, ProcessForeground)
+
+def on_process_background(func, *args, **kwargs):
+    """Use this to set a handler for the process foreground event.
+
+    Emitted when going from nothing being visible to at least one window being
+    visible.
+    """
+    return EventHandler(ELM_EVENT_PROCESS_FOREGROUND, func, *args, **kwargs)
+
+
 if elm_need_sys_notify():
     _event_mapping_register(
         ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED,
@@ -416,6 +516,7 @@ if elm_need_sys_notify():
             ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED, func, *args, **kargs
             )
 
+
 cdef class FontProperties(object):
 
     """Elementary font properties"""
@@ -755,3 +856,4 @@ def sys_notify_send(
         <Elm_Sys_Notify_Send_Cb>py_elm_sys_notify_send_cb if cb is not None 
else NULL,
         <const void *>py_cb_data if cb is not None else NULL
         )
+
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)
 
 items = [
     ("Core Libs", [
+        ("Ecore Events In Elm", "test_core_ecore_events_in_elm",
+         "core_ecore_events_in_elm_clicked"),
         ("Evas Objects", "test_core_evas_objects", 
"core_evas_objects_clicked"),
         ("Evas Canvas Callbacks", "test_core_evas_canvas_callbacks",
          "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 @@
+#!/usr/bin/env python
+# encoding: utf-8
+
+from __future__ import print_function
+
+from efl.evas import EXPAND_BOTH, FILL_BOTH
+
+from efl import elementary
+from efl.elementary.window import StandardWindow
+from efl.elementary.box import Box
+from efl.elementary.button import Button
+from efl.elementary.notify import Notify
+from efl.elementary.label import Label
+from efl.elementary.general import policy_get, policy_set, on_policy_changed, \
+    ELM_POLICY_QUIT, ELM_POLICY_EXIT, ELM_POLICY_THROTTLE, ELM_POLICY_LAST, \
+    ELM_POLICY_QUIT_NONE, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED
+
+win = None
+
+
+policy_mapping = {
+    ELM_POLICY_QUIT: "ELM_POLICY_QUIT",
+    ELM_POLICY_EXIT: "ELM_POLICY_EXIT",
+    ELM_POLICY_THROTTLE: "ELM_POLICY_THROTTLE",
+    ELM_POLICY_LAST: "ELM_POLICY_LAST"
+}
+
+policy_quit_value_mapping = {
+    ELM_POLICY_QUIT_NONE: "ELM_POLICY_QUIT_NONE",
+    ELM_POLICY_QUIT_LAST_WINDOW_CLOSED: "ELM_POLICY_QUIT_LAST_WINDOW_CLOSED"
+}
+
+
+@on_policy_changed
+def policy_changed(ev):
+    text = "policy changed: %s<br>new value: %s<br>old value: %s" % (
+        policy_mapping[ev.policy],
+        policy_quit_value_mapping[ev.new_value],
+        policy_quit_value_mapping[ev.old_value])
+    n = Notify(win, timeout=5)
+    l = Label(n, text=text)
+    n.content = l
+    l.show()
+    n.show()
+
+
+def core_ecore_events_in_elm_clicked(obj, item=None):
+    global win
+    win = StandardWindow(
+        "ecoreevents", "Ecore events in Elm", autodel=True,
+        size=(480, 240))
+    if obj is None:
+        win.callback_delete_request_add(lambda o: elementary.exit())
+
+    hbox = Box(
+        win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH,
+        horizontal=True)
+    win.resize_object_add(hbox)
+    hbox.show()
+
+    b = Button(win, text="change quit policy", size_hint_align=(0.5, 1.0))
+    hbox.pack_end(b)
+
+    def policy_change(btn):
+        old_value = bool(policy_get(ELM_POLICY_QUIT))
+        new_value = not old_value
+        policy_set(ELM_POLICY_QUIT, new_value)
+        print("changing policy: %s\nnew value: %s\nold value: %s" % (
+            "ELM_POLICY_QUIT",
+            policy_quit_value_mapping[new_value],
+            policy_quit_value_mapping[old_value]))
+
+    b.callback_clicked_add(policy_change)
+    b.show()
+
+    win.show()
+
+
+if __name__ == "__main__":
+    elementary.init()
+
+    core_ecore_events_in_elm_clicked(None)
+
+    elementary.run()
+    elementary.shutdown()

-- 


Reply via email to