summaryrefslogtreecommitdiff
path: root/efl/ecore/__init__.pyx
blob: dd7345c4a1c3dfa83259f877474a0b2d8f68555e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
# Copyright (C) 2007-2014 various contributors (see AUTHORS)
#
# This file is part of Python-EFL.
#
# Python-EFL is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# Python-EFL is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this Python-EFL.  If not, see <http://www.gnu.org/licenses/>.

"""

.. _Ecore_Fd_Handler_Flags:

Fd handler flags
================

What to monitor the file descriptor for: reading, writing or error.

.. data:: ECORE_FD_READ

    Fd Read mask

.. data:: ECORE_FD_WRITE

    Fd Write mask

.. data:: ECORE_FD_ERROR

    Fd Error mask


.. _Ecore_Exe_Flags:

Exe flags
=========

Flags for executing a child with its stdin and/or stdout piped back.

.. data:: ECORE_EXE_NONE

    No exe flags at all

.. data:: ECORE_EXE_PIPE_READ

    Exe Pipe Read mask

.. data:: ECORE_EXE_PIPE_WRITE

    Exe Pipe Write mask

.. data:: ECORE_EXE_PIPE_ERROR

    Exe Pipe error mask

.. data:: ECORE_EXE_PIPE_READ_LINE_BUFFERED

    Reads are buffered until a newline and split 1 line per Ecore_Exe_Event_Data_Line

.. data:: ECORE_EXE_PIPE_ERROR_LINE_BUFFERED

    Errors are buffered until a newline and split 1 line per Ecore_Exe_Event_Data_Line

.. data:: ECORE_EXE_PIPE_AUTO

    stdout and stderr are buffered automatically

.. data:: ECORE_EXE_RESPAWN

    FIXME: Exe is restarted if it dies

.. data:: ECORE_EXE_USE_SH

    Use /bin/sh to run the command

.. data:: ECORE_EXE_NOT_LEADER

    Do not use setsid() to have the executed process be its own session leader

.. data:: ECORE_EXE_TERM_WITH_PARENT

    Makes child receive SIGTERM when parent dies


Callback return values
======================

.. data:: ECORE_CALLBACK_CANCEL

    Return value to remove a callback, it will not be called again

.. data:: ECORE_CALLBACK_RENEW

    Return value to keep a callback


Event return values
===================

.. data:: ECORE_CALLBACK_PASS_ON

    Return value to pass event to next handler

.. data:: ECORE_CALLBACK_DONE

    Return value to stop event handling


.. _Ecore_Pos_Map:

Position mappings for the animation
===================================

.. data:: ECORE_POS_MAP_LINEAR

    Linear 0.0 -> 1.0

.. data:: ECORE_POS_MAP_ACCELERATE

    Start slow then speed up

.. data:: ECORE_POS_MAP_DECELERATE

    Start fast then slow down

.. data:: ECORE_POS_MAP_SINUSOIDAL

    Start slow, speed up then slow down at end

.. data:: ECORE_POS_MAP_ACCELERATE_FACTOR

    Start slow then speed up, v1 being a power factor, 0.0 being linear, 1.0 being normal accelerate, 2.0 being much more pronounced accelerate (squared), 3.0 being cubed, etc.

.. data:: ECORE_POS_MAP_DECELERATE_FACTOR

    Start fast then slow down, v1 being a power factor, 0.0 being linear, 1.0 being normal decelerate, 2.0 being much more pronounced decelerate (squared), 3.0 being cubed, etc.

.. data:: ECORE_POS_MAP_SINUSOIDAL_FACTOR

    Start slow, speed up then slow down at end, v1 being a power factor, 0.0 being linear, 1.0 being normal sinusoidal, 2.0 being much more pronounced sinusoidal (squared), 3.0 being cubed, etc.

.. data:: ECORE_POS_MAP_DIVISOR_INTERP

    Start at gradient * v1, interpolated via power of v2 curve

.. data:: ECORE_POS_MAP_BOUNCE

    Start at 0.0 then "drop" like a ball bouncing to the ground at 1.0, and bounce v2 times, with decay factor of v1

.. data:: ECORE_POS_MAP_SPRING

    Start at 0.0 then "wobble" like a spring rest position 1.0, and wobble v2 times, with decay factor of v1


.. _Ecore_Animator_Source:

Timing sources for animators
============================

.. data:: ECORE_ANIMATOR_SOURCE_TIMER

    The default system clock/timer based animator that ticks every "frametime" seconds

.. data:: ECORE_ANIMATOR_SOURCE_CUSTOM

    A custom animator trigger that you need to call ecore_animator_trigger() to make it tick


.. Ecore_File_Event:

File monitor events
===================

.. data:: ECORE_FILE_EVENT_NONE

    No event

.. data:: ECORE_FILE_EVENT_CREATED_FILE

    A file has been created

.. data:: ECORE_FILE_EVENT_CREATED_DIRECTORY

    A directory has been created

.. data:: ECORE_FILE_EVENT_DELETED_FILE

    A file has been deleted

.. data:: ECORE_FILE_EVENT_DELETED_DIRECTORY

    A directory has been deleted

.. data:: ECORE_FILE_EVENT_DELETED_SELF

    The monitored path itself has been deleted

.. data:: ECORE_FILE_EVENT_MODIFIED

    A file has changed

.. data:: ECORE_FILE_EVENT_CLOSED

    A file has been closed


"""

from libc.stdint cimport uintptr_t
import traceback
from efl.eo cimport Eo, PY_REFCOUNT
from efl.utils.conversions cimport _ctouni
from cpython cimport Py_INCREF, Py_DECREF
cimport efl.ecore.enums as enums

ECORE_CALLBACK_CANCEL = enums.ECORE_CALLBACK_CANCEL
ECORE_CALLBACK_RENEW = enums.ECORE_CALLBACK_RENEW

ECORE_CALLBACK_PASS_ON = enums.ECORE_CALLBACK_PASS_ON
ECORE_CALLBACK_DONE = enums.ECORE_CALLBACK_DONE

# Ecore_Fd_Handler_Flags:
ECORE_FD_READ = enums.ECORE_FD_READ
ECORE_FD_WRITE = enums.ECORE_FD_WRITE
ECORE_FD_ERROR = enums.ECORE_FD_ERROR
ECORE_FD_ALL = 7

# Ecore_Exe_Flags:
ECORE_EXE_PIPE_READ = enums.ECORE_EXE_PIPE_READ
ECORE_EXE_PIPE_WRITE = enums.ECORE_EXE_PIPE_WRITE
ECORE_EXE_PIPE_ERROR = enums.ECORE_EXE_PIPE_ERROR
ECORE_EXE_PIPE_READ_LINE_BUFFERED = enums.ECORE_EXE_PIPE_READ_LINE_BUFFERED
ECORE_EXE_PIPE_ERROR_LINE_BUFFERED = enums.ECORE_EXE_PIPE_ERROR_LINE_BUFFERED
ECORE_EXE_PIPE_AUTO = enums.ECORE_EXE_PIPE_AUTO
ECORE_EXE_RESPAWN = enums.ECORE_EXE_RESPAWN
ECORE_EXE_USE_SH = enums.ECORE_EXE_USE_SH
ECORE_EXE_NOT_LEADER = enums.ECORE_EXE_NOT_LEADER
ECORE_EXE_TERM_WITH_PARENT = enums.ECORE_EXE_TERM_WITH_PARENT

ECORE_EXE_PRIORITY_INHERIT = 9999

# Ecore_File_Progress_Return:
ECORE_FILE_PROGRESS_CONTINUE = 0
ECORE_FILE_PROGRESS_ABORT = 1

# Ecore_File_Event
ECORE_FILE_EVENT_NONE = enums.ECORE_FILE_EVENT_NONE
ECORE_FILE_EVENT_CREATED_FILE = enums.ECORE_FILE_EVENT_CREATED_FILE
ECORE_FILE_EVENT_CREATED_DIRECTORY = enums.ECORE_FILE_EVENT_CREATED_DIRECTORY
ECORE_FILE_EVENT_DELETED_FILE = enums.ECORE_FILE_EVENT_DELETED_FILE
ECORE_FILE_EVENT_DELETED_DIRECTORY = enums.ECORE_FILE_EVENT_DELETED_DIRECTORY
ECORE_FILE_EVENT_DELETED_SELF = enums.ECORE_FILE_EVENT_DELETED_SELF
ECORE_FILE_EVENT_MODIFIED = enums.ECORE_FILE_EVENT_MODIFIED
ECORE_FILE_EVENT_CLOSED = enums.ECORE_FILE_EVENT_CLOSED

# Ecore_Poller_Type:
ECORE_POLLER_CORE = enums.ECORE_POLLER_CORE


cdef Eina_Bool _ecore_task_cb(void *data) with gil:
    cdef Eo obj = <Eo>data
    cdef Eina_Bool ret

    try:
        ret = obj._task_exec()
    except Exception:
        traceback.print_exc()
        ret = 0

    if not ret:
        obj.delete()

    return ret


cdef int _ecore_events_registered = 0


def init():
    global _ecore_events_registered

    r = ecore_init()

    if r > 0 and _ecore_events_registered == 0:
        _ecore_events_registered = 1

        global _event_type_mapping
        _event_type_mapping = {
            enums.ECORE_EVENT_SIGNAL_USER: EventSignalUser,
            enums.ECORE_EVENT_SIGNAL_HUP: EventSignalHup,
            enums.ECORE_EVENT_SIGNAL_EXIT: EventSignalExit,
            enums.ECORE_EVENT_SIGNAL_POWER: EventSignalPower,
            enums.ECORE_EVENT_SIGNAL_REALTIME: EventSignalRealtime,
            enums.ECORE_EXE_EVENT_ADD: EventExeAdd,
            enums.ECORE_EXE_EVENT_DEL: EventExeDel,
            enums.ECORE_EXE_EVENT_DATA: EventExeData,
            enums.ECORE_EXE_EVENT_ERROR: EventExeData,
            }

    ecore_file_init()
    return r


def shutdown():
    ecore_file_shutdown()
    return ecore_shutdown()


def main_loop_quit():
    ecore_main_loop_quit()


def main_loop_begin():
    with nogil:
        ecore_main_loop_begin()


def main_loop_iterate():
    with nogil:
        ecore_main_loop_iterate()


def main_loop_glib_integrate():
    if not ecore_main_loop_glib_integrate():
        raise SystemError("failed to integrate GLib main loop into ecore.")

def main_loop_glib_always_integrate_disable():
    ecore_main_loop_glib_always_integrate_disable()

def time_get():
    return ecore_time_get()


def loop_time_get():
    return ecore_loop_time_get()


include "efl.ecore_animator.pxi"
include "efl.ecore_timer.pxi"
include "efl.ecore_poller.pxi"
include "efl.ecore_idler.pxi"
include "efl.ecore_fd_handler.pxi"
include "efl.ecore_events.pxi"
include "efl.ecore_exe.pxi"
include "efl.ecore_file_download.pxi"
include "efl.ecore_file_monitor.pxi"

init()


#---------------------------------------------------------------------------
# let's try to warn users that ecore conflicts with subprocess module
import subprocess

_orig_subprocess = None

def subprocess_warning(*a, **ka):
    print("""    DEVELOPER WARNING:
        Using subprocess (Popen and derivatives) with Ecore is a bad idea.

        Ecore will set some signal handlers subprocess module depends and this
        may cause this module to operate unexpectedly.

        Instead of using subprocess.Popen(), please consider using Ecore's
        Exe() class.
        """)
    return _orig_subprocess(*a, **ka)

if subprocess.Popen is not subprocess_warning:
    _orig_subprocess = subprocess.Popen
    subprocess.Popen = subprocess_warning


#---------------------------------------------------------------------------
# also try to warn that ecore conflicts with signal module
import signal

_orig_signal = None

def signal_warning(sig, action):
    if sig in (signal.SIGPIPE, signal.SIGALRM, signal.SIGCHLD, signal.SIGUSR1,
               signal.SIGUSR2, signal.SIGHUP,  signal.SIGQUIT, signal.SIGINT,
               signal.SIGTERM, signal.SIGPWR):
        print("""    DEVELOPER WARNING:
        Ecore already defines signal handlers for:

        SIGPIPE, SIGALRM, SIGCHLD, SIGUSR1, SIGUSR2
        SIGHUP, SIGQUIT, SIGINT, SIGTERM, SIGPWR, SIGRT*

        Since you're defining a new signal handler, you might collide with
        Ecore and bad things may happen!
        """)
    return _orig_signal(sig, action)

if signal.signal is not signal_warning:
    _orig_signal = signal.signal
    signal.signal = signal_warning