/usr/share/pyshared/kivy/uix/camera.py is in python-kivy 1.7.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | '''
Camera
======
The :class:`Camera` widget is used to capture and display video from a camera.
Once the widget is created, the texture inside the widget will be automatically
updated. Our :class:`~kivy.core.camera.CameraBase` implementation is used under
the hood::
cam = Camera()
By default the first camera found on your system is used. To use a different
camera, set the index property::
cam = Camera(index=1)
You can also select the camera resolution::
cam = Camera(resolution=(320, 240))
.. warning::
The camera texture is not updated as soon as you have created the object.
The camera initialization is asynchronous, it may take a little bit before
the texture is created.
'''
__all__ = ('Camera', )
from kivy.uix.image import Image
from kivy.core.camera import Camera as CoreCamera
from kivy.properties import NumericProperty, ListProperty, \
BooleanProperty
class Camera(Image):
'''Camera class. See module documentation for more information.
'''
play = BooleanProperty(True)
'''Boolean indicate if the camera is playing.
You can start/stop the camera by setting this property::
# start the camera playing at creation (default)
cam = Camera(play=True)
# create the camera, and start later
cam = Camera(play=False)
# and later
cam.play = True
:data:`play` is a :class:`~kivy.properties.BooleanProperty`, default to
True.
'''
index = NumericProperty(-1)
'''Index of the used camera, starting from 0.
:data:`index` is a :class:`~kivy.properties.NumericProperty`, default to -1
to allow auto selection.
'''
resolution = ListProperty([-1, -1])
'''Preferred resolution to use when invoking the camera. If you are using
[-1, -1], the resolution will be the default one::
# create a camera object with the best image available
cam = Camera()
# create a camera object with an image of 320x240 if possible
cam = Camera(resolution=(320, 240))
.. warning::
Depending on the implementation, the camera may not respect this
property.
:data:`resolution` is a :class:`~kivy.properties.ListProperty`, default to
[-1, -1]
'''
def __init__(self, **kwargs):
self._camera = None
super(Camera, self).__init__(**kwargs)
if self.index == -1:
self.index = 0
self.bind(index=self._on_index,
resolution=self._on_index)
self._on_index()
def on_tex(self, *l):
self.canvas.ask_update()
def _on_index(self, *largs):
self._camera = None
if self.index < 0:
return
if self.resolution[0] < 0 or self.resolution[1] < 0:
return
self._camera = CoreCamera(index=self.index,
resolution=self.resolution, stopped=True)
self._camera.bind(on_load=self._camera_loaded)
if self.play:
self._camera.start()
self._camera.bind(on_texture=self.on_tex)
def _camera_loaded(self, *largs):
self.texture = self._camera.texture
self.texture_size = list(self.texture.size)
def on_play(self, instance, value):
if not self._camera:
return
if value:
self._camera.start()
else:
self._camera.stop()
|