summaryrefslogtreecommitdiff
path: root/efl/elementary/video.pyx
blob: 88d10adccf769c938d42be867fb9cd8d9a49f1a7 (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
# Copyright (C) 2007-2015 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/>.

"""

:mod:`video` Module
###################


Widget description
==================

Display a video by using Emotion.

It embeds the video inside an Edje object, so you can do some
animation depending on the video state change. It also implements a
resource management policy to remove this burden from the application.

These widgets emit the following signals, besides the ones sent from
:py:class:`~efl.elementary.layout_class.LayoutClass`:

- ``focused`` - When the widget has received focus. (since 1.8)
- ``unfocused`` - When the widget has lost focus. (since 1.8)


Inheritance diagram
===================

.. inheritance-diagram:: efl.elementary.video
    :parts: 2

"""

from cpython cimport PyUnicode_AsUTF8String

from efl.eo cimport _object_mapping_register, object_from_instance
from efl.utils.conversions cimport _ctouni
from efl.evas cimport Object as evasObject
from layout_class cimport LayoutClass

cdef class Video(LayoutClass):
    """

    This is the class that actually implements the widget.

    """

    def __init__(self, evasObject parent, *args, **kwargs):
        """Video(...)

        :param parent: The parent object
        :type parent: :py:class:`efl.evas.Object`
        :param \**kwargs: All the remaining keyword arguments are interpreted
                          as properties of the instance

        """
        self._set_obj(elm_video_add(parent.obj))
        self._set_properties_from_keyword_args(kwargs)

    property file:
        """Define the file or URI that will be the video source.

        Setting this property will explicitly define a file or URI as a source
        for the video of the Elm_Video object.

        Local files can be specified using ``file://`` or by using full file
        paths. URI could be remote source of video, like ``http://`` or
        local source like WebCam (``v4l2://``). (You can use Emotion API to
        request and list the available Webcam on your system).

        :type: string
        :raise RuntimeError: when setting the file/uri fails

        .. versionchanged:: 1.8
            Raises RuntimeError if setting the file/uri fails

        """
        def __set__(self, filename):
            if isinstance(filename, unicode): filename = PyUnicode_AsUTF8String(filename)
            if not elm_video_file_set(self.obj,
                <const char *>filename if filename is not None else NULL):
                    raise RuntimeError("Could not set file.")

    # NOTE: clash with layout.file_set
    def file_set(self, filename, group = None):
        if isinstance(filename, unicode): filename = PyUnicode_AsUTF8String(filename)
        if not elm_video_file_set(self.obj,
            <const char *>filename if filename is not None else NULL):
                raise RuntimeError("Could not set file.")

    property emotion:
        """The underlying Emotion object.

        :type: :class:`efl.emotion.Object`

        """
        def __get__(self):
            return object_from_instance(elm_video_emotion_get(self.obj))

    def emotion_get(self):
        return object_from_instance(elm_video_emotion_get(self.obj))

    def play(self):
        """Start to play the video and cancel all suspend state."""
        elm_video_play(self.obj)

    def pause(self):
        """Pause the video and start a timer to trigger suspend mode."""
        elm_video_pause(self.obj)

    def stop(self):
        """Stop the video and put the emotion in deep sleep mode."""
        elm_video_stop(self.obj)

    property is_playing:
        """Is the video actually playing.

        You should consider watching event on the object instead of polling
        the object state.

        :type: bool

        """
        def __get__(self):
            return bool(elm_video_is_playing_get(self.obj))

    def is_playing_get(self):
        return bool(elm_video_is_playing_get(self.obj))

    property is_seekable:
        """Is it possible to seek inside the video.

        :type: bool

        """
        def __get__(self):
            return bool(elm_video_is_seekable_get(self.obj))

    def is_seekable_get(self):
        return bool(elm_video_is_seekable_get(self.obj))

    property audio_mute:
        """Is the audio muted.

        :type: bool

        """
        def __get__(self):
            return bool(elm_video_audio_mute_get(self.obj))

        def __set__(self, mute):
            elm_video_audio_mute_set(self.obj, mute)

    def audio_mute_get(self):
        return bool(elm_video_audio_mute_get(self.obj))
    def audio_mute_set(self, mute):
        elm_video_audio_mute_set(self.obj, mute)

    property audio_level:
        """The audio level of the current video.

        :type: float

        """
        def __get__(self):
            return elm_video_audio_level_get(self.obj)

        def __set__(self, volume):
            elm_video_audio_level_set(self.obj, volume)

    def audio_level_get(self):
        return elm_video_audio_level_get(self.obj)
    def audio_level_set(self, double volume):
        elm_video_audio_level_set(self.obj, volume)

    property play_position:
        """Get the current position (in seconds) being played in the Video
        object.

        :type: float

        """
        def __get__(self):
            return elm_video_play_position_get(self.obj)

        def __set__(self, position):
            elm_video_play_position_set(self.obj, position)

    def play_position_get(self):
        return elm_video_play_position_get(self.obj)
    def play_position_set(self, double position):
        elm_video_play_position_set(self.obj, position)

    property play_length:
        """The total playing time (in seconds) of the Video object.

        :type: float

        """
        def __get__(self):
            return elm_video_play_length_get(self.obj)

    def play_length_get(self):
        return elm_video_play_length_get(self.obj)

    property remember_position:
        """Whether the object can remember the last played position.

        .. note:: This API only serves as indication. System support is required.

        :type: bool

        """
        def __get__(self):
            return bool(elm_video_remember_position_get(self.obj))

        def __set__(self, remember):
            elm_video_remember_position_set(self.obj, remember)

    def remember_position_set(self, remember):
        elm_video_remember_position_set(self.obj, remember)
    def remember_position_get(self):
        return bool(elm_video_remember_position_get(self.obj))

    property title:
        """The title (for instance DVD title) from this emotion object.

        This property is only useful when playing a DVD.

        .. note:: Don't change or free the string returned by this function.

        :type: string

        """
        def __get__(self):
            return _ctouni(elm_video_title_get(self.obj))

    def title_get(self):
        return _ctouni(elm_video_title_get(self.obj))

    def callback_focused_add(self, func, *args, **kwargs):
        """When the video has received focus.

        .. versionadded:: 1.8
        """
        self._callback_add("focused", func, args, kwargs)

    def callback_focused_del(self, func):
        self._callback_del("focused", func)

    def callback_unfocused_add(self, func, *args, **kwargs):
        """When the video has lost focus.

        .. versionadded:: 1.8
        """
        self._callback_add("unfocused", func, args, kwargs)

    def callback_unfocused_del(self, func):
        self._callback_del("unfocused", func)

_object_mapping_register("Elm_Video", Video)


cdef class Player(LayoutClass):
    """

    Player is a video player that need to be linked with a :py:class:`Video`.

    It takes care of updating its content according to Emotion events and
    provides a way to theme itself. It also automatically raises the priority of
    the linked :py:class:`Video` so it will use the video decoder, if available. It also
    activates the "remember" function on the linked :py:class:`Video` object.

    The player widget emits the following signals, besides the ones
    sent from :py:class:`~efl.elementary.layout_class.LayoutClass`:

    - ``forward,clicked`` - the user clicked the forward button.
    - ``info,clicked`` - the user clicked the info button.
    - ``next,clicked`` - the user clicked the next button.
    - ``pause,clicked`` - the user clicked the pause button.
    - ``play,clicked`` - the user clicked the play button.
    - ``prev,clicked`` - the user clicked the prev button.
    - ``rewind,clicked`` - the user clicked the rewind button.
    - ``stop,clicked`` - the user clicked the stop button.

    Default content parts of the player widget that you can use for are:

    - ``video`` - A video of the player

    """

    def __init__(self, evasObject parent, *args, **kwargs):
        """Player(...)

        :param parent: The parent object
        :type parent: :py:class:`efl.evas.Object`
        :param \**kwargs: All the remaining keyword arguments are interpreted
                          as properties of the instance

        """
        self._set_obj(elm_player_add(parent.obj))
        self._set_properties_from_keyword_args(kwargs)

    def callback_forward_clicked_add(self, func, *args, **kwargs):
        """the user clicked the forward button."""
        self._callback_add("forward,clicked", func, args, kwargs)

    def callback_forward_clicked_del(self, func):
        self._callback_del("forward,clicked", func)

    def callback_info_clicked_add(self, func, *args, **kwargs):
        """the user clicked the info button."""
        self._callback_add("info,clicked", func, args, kwargs)

    def callback_info_clicked_del(self, func):
        self._callback_del("info,clicked", func)

    def callback_next_clicked_add(self, func, *args, **kwargs):
        """the user clicked the next button."""
        self._callback_add("next,clicked", func, args, kwargs)

    def callback_next_clicked_del(self, func):
        self._callback_del("next,clicked", func)

    def callback_pause_clicked_add(self, func, *args, **kwargs):
        """the user clicked the pause button."""
        self._callback_add("pause,clicked", func, args, kwargs)

    def callback_pause_clicked_del(self, func):
        self._callback_del("pause,clicked", func)

    def callback_play_clicked_add(self, func, *args, **kwargs):
        """the user clicked the play button."""
        self._callback_add("play,clicked", func, args, kwargs)

    def callback_play_clicked_del(self, func):
        self._callback_del("play,clicked", func)

    def callback_prev_clicked_add(self, func, *args, **kwargs):
        """the user clicked the prev button."""
        self._callback_add("prev,clicked", func, args, kwargs)

    def callback_prev_clicked_del(self, func):
        self._callback_del("prev,clicked", func)

    def callback_rewind_clicked_add(self, func, *args, **kwargs):
        """the user clicked the rewind button."""
        self._callback_add("rewind,clicked", func, args, kwargs)

    def callback_rewind_clicked_del(self, func):
        self._callback_del("rewind,clicked", func)

    def callback_stop_clicked_add(self, func, *args, **kwargs):
        """the user clicked the stop button."""
        self._callback_add("stop,clicked", func, args, kwargs)

    def callback_stop_clicked_del(self, func):
        self._callback_del("stop,clicked", func)

    def callback_focused_add(self, func, *args, **kwargs):
        """When the player has received focus.

        .. versionadded:: 1.8
        """
        self._callback_add("focused", func, args, kwargs)

    def callback_focused_del(self, func):
        self._callback_del("focused", func)

    def callback_unfocused_add(self, func, *args, **kwargs):
        """When the player has lost focus.

        .. versionadded:: 1.8
        """
        self._callback_add("unfocused", func, args, kwargs)

    def callback_unfocused_del(self, func):
        self._callback_del("unfocused", func)

_object_mapping_register("Elm_Player", Player)