summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2014-05-28 03:38:28 +0300
committerKai Huuhko <kai.huuhko@gmail.com>2014-05-28 03:38:28 +0300
commitab0e868a39432811c9c3882425070c21c9280328 (patch)
treeba4c02e51857a0f972fdac7ead02e5c26f29b3ae
parent3f5a1a7d79785c95c874937948b422aeba3c61ea (diff)
Elementary.general: Add sys_notify. NEEDS TESTING
-rw-r--r--efl/elementary/enums.pxd14
-rw-r--r--efl/elementary/general.pxd23
-rw-r--r--efl/elementary/general.pyx220
3 files changed, 254 insertions, 3 deletions
diff --git a/efl/elementary/enums.pxd b/efl/elementary/enums.pxd
index 343767c..624f01d 100644
--- a/efl/elementary/enums.pxd
+++ b/efl/elementary/enums.pxd
@@ -447,6 +447,20 @@ cdef extern from "Elementary.h":
447 ELM_STORE_ITEM_MAPPING_CUSTOM 447 ELM_STORE_ITEM_MAPPING_CUSTOM
448 ELM_STORE_ITEM_MAPPING_LAST 448 ELM_STORE_ITEM_MAPPING_LAST
449 449
450 ctypedef enum Elm_Sys_Notify_Closed_Reason:
451 ELM_SYS_NOTIFY_CLOSED_EXPIRED # The notification expired.
452 ELM_SYS_NOTIFY_CLOSED_DISMISSED # The notification was dismissed by the user.
453 ELM_SYS_NOTIFY_CLOSED_REQUESTED # The notification was closed by a call to CloseNotification method.
454 ELM_SYS_NOTIFY_CLOSED_UNDEFINED # Undefined/reserved reasons.
455
456 ctypedef enum Elm_Sys_Notify_Urgency:
457 ELM_SYS_NOTIFY_URGENCY_LOW
458 ELM_SYS_NOTIFY_URGENCY_NORMAL
459 ELM_SYS_NOTIFY_URGENCY_CRITICAL
460
461 int ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED
462 int ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED
463
450 ctypedef enum Elm_Text_Format: 464 ctypedef enum Elm_Text_Format:
451 ELM_TEXT_FORMAT_PLAIN_UTF8 465 ELM_TEXT_FORMAT_PLAIN_UTF8
452 ELM_TEXT_FORMAT_MARKUP_UTF8 466 ELM_TEXT_FORMAT_MARKUP_UTF8
diff --git a/efl/elementary/general.pxd b/efl/elementary/general.pxd
index 8025095..afb06a0 100644
--- a/efl/elementary/general.pxd
+++ b/efl/elementary/general.pxd
@@ -19,6 +19,7 @@
19from efl.evas cimport Eina_List, Eina_Bool 19from efl.evas cimport Eina_List, Eina_Bool
20from efl.evas cimport Evas_Object, Evas_Font_Size, Evas_Coord 20from efl.evas cimport Evas_Object, Evas_Font_Size, Evas_Coord
21from efl.evas.enums cimport Evas_Callback_Type 21from efl.evas.enums cimport Evas_Callback_Type
22from enums cimport Elm_Sys_Notify_Closed_Reason, Elm_Sys_Notify_Urgency
22 23
23cdef extern from "time.h": 24cdef extern from "time.h":
24 struct tm: 25 struct tm:
@@ -118,4 +119,26 @@ cdef extern from "Elementary.h":
118 void elm_object_tree_dump(const Evas_Object *top) 119 void elm_object_tree_dump(const Evas_Object *top)
119 void elm_object_tree_dot_dump(const Evas_Object *top, const char *file) 120 void elm_object_tree_dot_dump(const Evas_Object *top, const char *file)
120 121
122 # sys_notify.h
123 ctypedef void (*Elm_Sys_Notify_Send_Cb)(void *data, unsigned int id)
124
125 ctypedef struct Elm_Sys_Notify_Notification_Closed:
126 unsigned int id # ID of the notification.
127 Elm_Sys_Notify_Closed_Reason reason # The Reason the notification was closed.
128
129 ctypedef struct Elm_Sys_Notify_Action_Invoked:
130 unsigned int id # ID of the notification.
131 char *action_key # The key of the action invoked. These match the keys sent over in the list of actions.
132
133 void elm_sys_notify_close(unsigned int id)
134 void elm_sys_notify_send( unsigned int replaces_id,
135 const char *icon,
136 const char *summary,
137 const char *body,
138 Elm_Sys_Notify_Urgency urgency,
139 int timeout,
140 Elm_Sys_Notify_Send_Cb cb,
141 const void *cb_data)
142
143
121cdef int PY_EFL_ELM_LOG_DOMAIN 144cdef int PY_EFL_ELM_LOG_DOMAIN
diff --git a/efl/elementary/general.pyx b/efl/elementary/general.pyx
index cc50b27..8f2e2aa 100644
--- a/efl/elementary/general.pyx
+++ b/efl/elementary/general.pyx
@@ -117,9 +117,56 @@ Possible values for the #ELM_POLICY_THROTTLE policy.
117 Never throttle when windows are all hidden, regardless of config settings. 117 Never throttle when windows are all hidden, regardless of config settings.
118 118
119 119
120.. _Elm_Sys_Notify_Closed_Reason:
121
122Notify close reasons
123--------------------
124
125The reason the notification was closed
126
127.. versionadded:: 1.10
128
129.. data:: ELM_SYS_NOTIFY_CLOSED_EXPIRED
130
131 The notification expired.
132
133.. data:: ELM_SYS_NOTIFY_CLOSED_DISMISSED
134
135 The notification was dismissed by the user.
136
137.. data:: ELM_SYS_NOTIFY_CLOSED_REQUESTED
138
139 The notification was closed by a call to CloseNotification method.
140
141.. data:: ELM_SYS_NOTIFY_CLOSED_UNDEFINED
142
143 Undefined/reserved reasons.
144
145
146.. _Elm_Sys_Notify_Urgency:
147
148Urgency levels of a notification
149
150:see: :py:func:`sys_notify_send`
151
152.. versionadded:: 1.10
153
154.. data:: ELM_SYS_NOTIFY_URGENCY_LOW
155
156 Low
157
158.. data:: ELM_SYS_NOTIFY_URGENCY_NORMAL
159
160 Normal
161
162.. data:: ELM_SYS_NOTIFY_URGENCY_CRITICAL
163
164 Critical
165
166
120""" 167"""
121 168
122from cpython cimport PyUnicode_AsUTF8String, PyMem_Malloc, Py_DECREF 169from cpython cimport PyUnicode_AsUTF8String, PyMem_Malloc, Py_DECREF, Py_INCREF
123from libc.string cimport memcpy 170from libc.string cimport memcpy
124 171
125from efl.evas cimport Object as evasObject 172from efl.evas cimport Object as evasObject
@@ -133,11 +180,14 @@ from efl.utils.logger cimport add_logger
133from efl.eina cimport EINA_LOG_DOM_DBG, EINA_LOG_DOM_INFO, \ 180from efl.eina cimport EINA_LOG_DOM_DBG, EINA_LOG_DOM_INFO, \
134 EINA_LOG_DOM_WARN, EINA_LOG_DOM_ERR, EINA_LOG_DOM_CRIT 181 EINA_LOG_DOM_WARN, EINA_LOG_DOM_ERR, EINA_LOG_DOM_CRIT
135 182
136from enums cimport Elm_Policy 183from efl.ecore cimport Event, EventHandler, _event_mapping_register
137 184
138import sys 185from efl.elementary.need cimport elm_need_sys_notify
139 186
140cimport enums 187cimport enums
188from enums cimport Elm_Policy
189
190import sys
141 191
142ELM_POLICY_QUIT = enums.ELM_POLICY_QUIT 192ELM_POLICY_QUIT = enums.ELM_POLICY_QUIT
143ELM_POLICY_EXIT = enums.ELM_POLICY_EXIT 193ELM_POLICY_EXIT = enums.ELM_POLICY_EXIT
@@ -153,6 +203,112 @@ ELM_POLICY_THROTTLE_CONFIG = enums.ELM_POLICY_THROTTLE_CONFIG
153ELM_POLICY_THROTTLE_HIDDEN_ALWAYS = enums.ELM_POLICY_THROTTLE_HIDDEN_ALWAYS 203ELM_POLICY_THROTTLE_HIDDEN_ALWAYS = enums.ELM_POLICY_THROTTLE_HIDDEN_ALWAYS
154ELM_POLICY_THROTTLE_NEVER = enums.ELM_POLICY_THROTTLE_NEVER 204ELM_POLICY_THROTTLE_NEVER = enums.ELM_POLICY_THROTTLE_NEVER
155 205
206ELM_SYS_NOTIFY_CLOSED_EXPIRED = enums.ELM_SYS_NOTIFY_CLOSED_EXPIRED
207ELM_SYS_NOTIFY_CLOSED_DISMISSED = enums.ELM_SYS_NOTIFY_CLOSED_DISMISSED
208ELM_SYS_NOTIFY_CLOSED_REQUESTED = enums.ELM_SYS_NOTIFY_CLOSED_REQUESTED
209ELM_SYS_NOTIFY_CLOSED_UNDEFINED = enums.ELM_SYS_NOTIFY_CLOSED_UNDEFINED
210
211ELM_SYS_NOTIFY_URGENCY_LOW = enums.ELM_SYS_NOTIFY_URGENCY_LOW
212ELM_SYS_NOTIFY_URGENCY_NORMAL = enums.ELM_SYS_NOTIFY_URGENCY_NORMAL
213ELM_SYS_NOTIFY_URGENCY_CRITICAL = enums.ELM_SYS_NOTIFY_URGENCY_CRITICAL
214
215ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED = enums.ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED
216ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED = enums.ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED
217
218import traceback
219
220cdef void py_elm_sys_notify_send_cb(void *data, unsigned int id):
221 cdef object func, func_data
222 func, func_data = <object>data
223 # FIXME: Is this cb called more than once? Py_DECREF if not.
224 try:
225 func(func_data, id)
226 except Exception:
227 traceback.print_exc()
228
229cdef class SysNotifyNotificationClosed(Event):
230
231 cdef Elm_Sys_Notify_Notification_Closed *obj
232
233 cdef int _set_obj(self, void *o) except 0:
234 self.obj = <Elm_Sys_Notify_Notification_Closed*>o
235 return 1
236
237 def __repr__(self):
238 # TODO: int -> string for 'reason'
239 return "<%s(id=%d, reason=%s)>" % \
240 (type(self).__name__, self.id, self.reason)
241
242 property id:
243 """ID of the notification.
244
245 :type: int
246
247 """
248 def __get__(self):
249 return self.obj.id
250
251 property reason:
252 """The Reason the notification was closed.
253
254 :type: :ref:`Elm_Sys_Notify_Closed_Reason`
255
256 """
257 def __get__(self):
258 return self.obj.reason
259
260cdef class SysNotifyActionInvoked(Event):
261
262 cdef Elm_Sys_Notify_Action_Invoked *obj
263
264 cdef int _set_obj(self, void *o) except 0:
265 self.obj = <Elm_Sys_Notify_Action_Invoked*>o
266 return 1
267
268 def __repr__(self):
269 return "<%s(id=%d, action_key=%s)>" % \
270 (type(self).__name__, self.id, self.action_key)
271
272 property id:
273 """ID of the notification.
274
275 :type: int
276
277 """
278 def __get__(self):
279 return self.obj.id
280
281 property action_key:
282 """The key of the action invoked. These match the keys sent over in the
283 list of actions.
284
285 :type: string
286
287 """
288 def __get__(self):
289 return _touni(self.obj.action_key)
290
291if elm_need_sys_notify():
292 _event_mapping_register(
293 enums.ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED,
294 SysNotifyNotificationClosed
295 )
296
297 def on_sys_notify_notification_closed(func, *args, **kargs):
298 return EventHandler(
299 enums.ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED, func, *args, **kargs
300 )
301
302 _event_mapping_register(
303 enums.ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED,
304 SysNotifyActionInvoked
305 )
306
307 def on_sys_notify_action_invoked(func, *args, **kargs):
308 return EventHandler(
309 enums.ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED, func, *args, **kargs
310 )
311
156cdef class FontProperties(object): 312cdef class FontProperties(object):
157 313
158 """Elementary font properties""" 314 """Elementary font properties"""
@@ -470,3 +626,61 @@ def object_tree_dot_dump(evasObject top, path):
470 """ 626 """
471 if isinstance(path, unicode): path = PyUnicode_AsUTF8String(path) 627 if isinstance(path, unicode): path = PyUnicode_AsUTF8String(path)
472 elm_object_tree_dot_dump(top.obj, <const char *>path) 628 elm_object_tree_dot_dump(top.obj, <const char *>path)
629
630def sys_notify_close(unsigned int id):
631 """Causes a notification to be forcefully closed and removed from the user's
632 view. It can be used, for example, in the event that what the notification
633 pertains to is no longer relevant, or to cancel a notification * with no
634 expiration time.
635
636 :param id: Notification id
637
638 .. note:: If the notification no longer exists,
639 an empty D-BUS Error message is sent back.
640
641 .. versionadded:: 1.10
642
643 """
644 elm_sys_notify_close(id)
645
646def sys_notify_send(
647 unsigned int replaces_id=0,
648 icon=None, summary=None, body=None,
649 Elm_Sys_Notify_Urgency urgency=enums.ELM_SYS_NOTIFY_URGENCY_NORMAL,
650 int timeout=-1, cb=None, cb_data=None
651 ):
652 """Sends a notification to the notification server.
653
654 :param replaces_id: Notification ID that this notification replaces.
655 The value 0 means a new notification.
656 :param icon: The optional program icon of the calling application.
657 :param summary: The summary text briefly describing the notification.
658 :param body: The optional detailed body text. Can be empty.
659 :param urgency: The urgency level.
660 :param timeout: Timeout display in milliseconds.
661 :param cb: Callback used to retrieve the notification id
662 return by the Notification Server.
663 :param cb_data: Optional context data
664
665 .. versionadded:: 1.10
666
667 """
668 if cb is not None:
669 if not callable(cb):
670 raise TypeError("cb must be callable")
671 py_cb_data = (cb, cb_data)
672 Py_INCREF(py_cb_data)
673
674 if isinstance(icon, unicode): icon = PyUnicode_AsUTF8String(icon)
675 if isinstance(summary, unicode): summary = PyUnicode_AsUTF8String(summary)
676 if isinstance(body, unicode): body = PyUnicode_AsUTF8String(body)
677 elm_sys_notify_send(
678 replaces_id,
679 <const char *>icon if icon is not None else NULL,
680 <const char *>summary if summary is not None else NULL,
681 <const char *>body if body is not None else NULL,
682 urgency,
683 timeout,
684 <Elm_Sys_Notify_Send_Cb>py_elm_sys_notify_send_cb if cb is not None else NULL,
685 <const void *>py_cb_data if cb is not None else NULL
686 )