~guadalinex-members/hermeshardware/debian

« back to all changes in this revision

Viewing changes to actors/usbwebcam_guadalinfo.py

  • Committer: pchaso
  • Date: 2009-06-01 23:27:10 UTC
  • Revision ID: pchaso@pchaso-laptop-20090601232710-ff4m3gkxg3qql2bn
Separados actores para webcam, el antiguo se deja por compatibilidad con webcams antiguas en centros guadalinfo y se renombra a usbwebcam_guadalinfo

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
 
 
4
#Módulo webcam- Módulo que implementa el "actor hardware" para los dispositivos
 
5
#webcam.
 
6
#
 
7
#Copyright (C) 2005 Junta de Andalucía
 
8
#
 
9
#Autor/es (Author/s):
 
10
#
 
11
#- Gumersindo Coronel Pérez <gcoronel@emergya.info>
 
12
#
 
13
#Este fichero es parte de Detección de Hardware de Guadalinex 2005 
 
14
#
 
15
#Detección de Hardware de Guadalinex 2005  es software libre. Puede redistribuirlo y/o modificarlo 
 
16
#bajo los términos de la Licencia Pública General de GNU según es 
 
17
#publicada por la Free Software Foundation, bien de la versión 2 de dicha
 
18
#Licencia o bien (según su elección) de cualquier versión posterior. 
 
19
#
 
20
#Detección de Hardware de Guadalinex 2005  se distribuye con la esperanza de que sea útil, 
 
21
#pero SIN NINGUNA GARANTÍA, incluso sin la garantía MERCANTIL 
 
22
#implícita o sin garantizar la CONVENIENCIA PARA UN PROPÓSITO 
 
23
#PARTICULAR. Véase la Licencia Pública General de GNU para más detalles. 
 
24
#
 
25
#Debería haber recibido una copia de la Licencia Pública General 
 
26
#junto con Detección de Hardware de Guadalinex 2005 . Si no ha sido así, escriba a la Free Software
 
27
#Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
 
28
#
 
29
#-------------------------------------------------------------------------
 
30
#
 
31
#This file is part of Detección de Hardware de Guadalinex 2005 .
 
32
#
 
33
#Detección de Hardware de Guadalinex 2005  is free software; you can redistribute it and/or modify
 
34
#it under the terms of the GNU General Public License as published by
 
35
#the Free Software Foundation; either version 2 of the License, or
 
36
#at your option) any later version.
 
37
#
 
38
#Detección de Hardware de Guadalinex 2005  is distributed in the hope that it will be useful,
 
39
#but WITHOUT ANY WARRANTY; without even the implied warranty of
 
40
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
41
#GNU General Public License for more details.
 
42
#
 
43
#You should have received a copy of the GNU General Public License
 
44
#along with Foobar; if not, write to the Free Software
 
45
#Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
46
 
 
47
import os.path
 
48
 
 
49
from utils.synaptic import Synaptic
 
50
from deviceactor import PkgDeviceActor
 
51
#from utils.grepmap import UsbGrepMap
 
52
from gettext import gettext as _
 
53
 
 
54
from usbactor import Actor
 
55
 
 
56
WEBCAMICON = os.path.abspath('actors/img/webcam.png')
 
57
WEBCAMICONOFF = os.path.abspath('actors/img/webcamoff.png')
 
58
 
 
59
 
 
60
class UsbWebcamActorHack(object):
 
61
    """
 
62
    This class is a hack for usb_device.Actor
 
63
    """
 
64
    PACKAGES = PkgDeviceActor.get_packages('usbwebcam')
 
65
    DRIVERS = ['quickcam', 'spca5xx', 'ibmcam', 'konicawc', 'ov511', 'pwc', 
 
66
               'se401', 'sn9c102', 'stv680', 'ultracam', 'vicam', 'w9968cf', 'gspca']
 
67
 
 
68
    def __init__(self):
 
69
        # Hacking usb.Actor class
 
70
        Actor.on_added = self.decor(Actor.on_added, self.hack_on_added)
 
71
        Actor.on_removed = self.decor(Actor.on_removed, self.hack_on_removed)
 
72
        Actor.on_modified = self.decor(Actor.on_modified, self.hack_on_modified)
 
73
 
 
74
 
 
75
    def is_webcam(self, usb_actor):
 
76
        if usb_actor.properties.has_key('info.linux.driver'):
 
77
            ldrv = usb_actor.properties['info.linux.driver']
 
78
            return ldrv in UsbWebcamActorHack.DRIVERS
 
79
        
 
80
 
 
81
    def decor(self, oldf, hack_function):
 
82
        "Python Decorator for on_added method."
 
83
 
 
84
        def new_method(usb_actor, *args, **kargs):
 
85
            oldf(usb_actor, *args, **kargs)
 
86
            if self.is_webcam(usb_actor):
 
87
                hack_function(usb_actor)
 
88
 
 
89
        return new_method
 
90
 
 
91
 
 
92
    def hack_on_modified(self, usb_actor, prop_name):
 
93
        usb_actor.logger.debug("UsbWebcamActorHack: hack_on_modified")
 
94
        if prop_name == 'info.linux.driver' and \
 
95
            self.is_webcam(usb_actor):
 
96
            self.hack_on_added(usb_actor)
 
97
 
 
98
 
 
99
    def hack_on_added(self, usb_actor):
 
100
        "usbdevice.Actor.on_added hack"
 
101
        usb_actor.logger.debug("UsbWebcamActorHack: hack_on_added")
 
102
        assert(isinstance(usb_actor, Actor))
 
103
 
 
104
        def run_cheese():
 
105
            os.system('cheese & ')
 
106
 
 
107
        def install_packages():
 
108
            if synaptic.install(UsbWebcamActorHack.PACKAGES):
 
109
                run_cheese()
 
110
 
 
111
        synaptic = Synaptic()
 
112
 
 
113
        actions = {}
 
114
        if synaptic.check(UsbWebcamActorHack.PACKAGES):
 
115
            actions = {_("Run capture program"): run_cheese}
 
116
        else:
 
117
            actions = {_("Install required packages"): install_packages}
 
118
 
 
119
        usb_actor.msg_render.show(_("WEBCAM"), _("Webcam connected"),
 
120
                                WEBCAMICON, actions = actions)
 
121
 
 
122
 
 
123
    def hack_on_removed(self, usb_actor):
 
124
        "usbdevice.Actor.on_removed hack"
 
125
        usb_actor.logger.debug("UsbWebcamActorHack: hack_on_removed")
 
126
        assert(isinstance(usb_actor, Actor))
 
127
 
 
128
        usb_actor.msg_render.show(_("WEBCAM"), _("Webcam disconnected"),
 
129
                                WEBCAMICONOFF)
 
130
 
 
131
 
 
132
ua = UsbWebcamActorHack()
 
133