Esempio n. 1
0
def buffer_file_cmp(printer, file_name):
    current_data_code("EJ.01.01")
    mesa = Ubicacion.one(codigo="EJ.01.01.01.01")
    boleta = Seleccion(mesa)
    boleta.elegir_lista(Lista.one())
    img = boleta.a_imagen()
    img = img.output()

    img = img.transpose(Image.ROTATE_90)
    data = img.getdata()

    printer.load_buffer_compressed(data)
Esempio n. 2
0
File: test.py Progetto: sunzu/vot.ar
def buffer_file_cmp(printer, file_name):
    current_data_code("EJ.01.01")
    mesa = Ubicacion.one(codigo="EJ.01.01.01.01")
    boleta = Seleccion(mesa)
    boleta.elegir_lista(Lista.one())
    img = boleta.a_imagen()
    img = img.output()

    img = img.transpose(Image.ROTATE_90)
    data = img.getdata()

    printer.load_buffer_compressed(data)
Esempio n. 3
0
    def _consultar(self, datos_tag, force=False):
        if self.estado != E_CONSULTANDO or force:
            self.set_estado(E_CONSULTANDO)

            if datos_tag is not None and len(datos_tag) > 0:
                def _fin():
                    if self.estado == E_CONSULTANDO:
                        sigue = False
                        if self.rampa.tiene_papel:
                            self.rampa.expulsar_boleta()
                        else:
                            tag = sesion.lector.get_tag()
                            if tag is not None:
                                sigue = True
                                self._consultar(tag['datos'], True)
                        if not sigue:
                            # reseteo el estado del tag por si no me llega el evento.
                            self.rampa.datos_tag = None
                            self.pantalla_insercion()

                seleccion_tag = None
                try:
                    seleccion_tag = Seleccion.desde_tag(datos_tag, sesion.mesa)
                except Exception as e:
                    sesion.logger.error("La boleta no contiene datos validos")
                    sesion.logger.exception(e)
                    _fin()
                if seleccion_tag is not None:
                    self.controller.consulta(seleccion_tag)
                    gobject.timeout_add(self.tiempo_verificacion, _fin)
            else:
                self.rampa.expulsar_boleta()
Esempio n. 4
0
    def imprimir_serializado(self, tipo_tag, tag, transpose, only_buffer=False,
                             extra_data=None):
        self._buffering = True
        if tipo_tag == "Seleccion":
            if type(tag) == Seleccion:
                boleta = tag
            else:
                boleta = Seleccion.desde_string(tag)
            image = boleta.a_imagen()
        elif tipo_tag == "Apertura":
            boleta = Apertura.desde_tag(b64decode(tag))
            image = boleta.a_imagen()
        elif tipo_tag == "Recuento":
            boleta = Recuento.desde_tag(b64decode(tag))
            extra_data = loads(extra_data)
            autoridades = extra_data.get('autoridades')
            if autoridades is not None and len(autoridades):
                boleta.autoridades = [Autoridad.desde_dict(aut) for aut
                                      in autoridades]
            boleta.hora = extra_data['hora']
            image = boleta.a_imagen(extra_data['tipo_acta'])
        elif tipo_tag == "Prueba":
            image = ImagenPrueba(hd=True).render_image()

        image = image.convert('L')
        if transpose:
            image = image.transpose(Image.ROTATE_270)
        if only_buffer:
            self.parent.printer.register_load_buffer_compressed()
        else:
            self.parent.printer.register_print_finished()
        data = image.getdata()
        self.parent.printer.load_buffer_compressed(
            data, self.parent._free_page_mem,
            print_immediately=not only_buffer)
Esempio n. 5
0
File: voto.py Progetto: sunzu/vot.ar
    def _consultar(self, datos_tag, force=False):
        if self.estado != E_CONSULTANDO or force:
            self.set_estado(E_CONSULTANDO)

            if datos_tag is not None and len(datos_tag) > 0:

                def _fin():
                    if self.estado == E_CONSULTANDO:
                        sigue = False
                        if self.rampa.tiene_papel:
                            self.rampa.expulsar_boleta()
                        else:
                            tag = sesion.lector.get_tag()
                            if tag is not None:
                                sigue = True
                                self._consultar(tag['datos'], True)
                        if not sigue:
                            # reseteo el estado del tag por si no me llega el evento.
                            self.rampa.datos_tag = None
                            self.pantalla_insercion()

                seleccion_tag = None
                try:
                    seleccion_tag = Seleccion.desde_tag(datos_tag, sesion.mesa)
                except Exception as e:
                    sesion.logger.error("La boleta no contiene datos validos")
                    sesion.logger.exception(e)
                    _fin()
                if seleccion_tag is not None:
                    self.controller.consulta(seleccion_tag)
                    gobject.timeout_add(self.tiempo_verificacion, _fin)
            else:
                self.rampa.expulsar_boleta()
Esempio n. 6
0
    def registrar(self, tag):
        ret = {"status": "OK"}
        marcar_ro = QUEMA

        tag_guardado = self.guardar_tag(TAG_VOTO, tag, marcar_ro)
        if tag_guardado:
            seleccion = Seleccion.desde_string(tag)
            self.imprimir_serializado("Seleccion", seleccion, True)
        else:
            ret['status'] = "TAG_NO_GUARDADO"

        return dumps(ret)
Esempio n. 7
0
    def registrar(self, tag):
        ret = {"status": "OK"}
        marcar_ro = QUEMA

        tag_guardado = self.guardar_tag(TAG_VOTO, tag, marcar_ro)
        if tag_guardado:
            seleccion = Seleccion.desde_string(tag)
            self.imprimir_serializado("Seleccion", seleccion, True)
        else:
            ret['status'] = "TAG_NO_GUARDADO"

        return dumps(ret)
Esempio n. 8
0
    def imprimir_serializado(self,
                             tipo_tag,
                             tag,
                             transpose,
                             only_buffer=False,
                             extra_data=None):
        self._buffering = True
        if tipo_tag == "Seleccion":
            if type(tag) == Seleccion:
                boleta = tag
            else:
                boleta = Seleccion.desde_string(tag)
            image = boleta.a_imagen()
        elif tipo_tag == "Apertura":
            boleta = Apertura.desde_tag(b64decode(tag))
            image = boleta.a_imagen()
        elif tipo_tag == "Recuento":
            boleta = Recuento.desde_tag(b64decode(tag))
            extra_data = loads(extra_data)
            autoridades = extra_data.get('autoridades')
            if autoridades is not None and len(autoridades):
                boleta.autoridades = [
                    Autoridad.desde_dict(aut) for aut in autoridades
                ]
            boleta.hora = extra_data['hora']
            image = boleta.a_imagen(extra_data['tipo_acta'])
        elif tipo_tag == "Prueba":
            image = ImagenPrueba(hd=True).render_image()

        image = image.convert('L')
        if transpose:
            image = image.transpose(Image.ROTATE_270)
        if only_buffer:
            self.parent.printer.register_load_buffer_compressed()
        else:
            self.parent.printer.register_print_finished()
        data = image.getdata()
        self.parent.printer.load_buffer_compressed(
            data,
            self.parent._free_page_mem,
            print_immediately=not only_buffer)
Esempio n. 9
0
def run(args):
    printer = obtener_impresora()
    if args.serialized is None or not args.serialized:
        logger.debug("Corriendo proceso de impresion o cache de impresion")
        logger.debug(args)
        image_file = open(args.filepath)
        data = image_file.read()
        size = [int(num) for num in args.size.split(",")]
        dpi = tuple([int(num) for num in args.dpi.split(",")])
        image = Image.fromstring(args.mode, size, data)
        printer.imprimir_image(image, dpi, args.transpose, args.compress,
                               args.only_buffer)
    else:
        extra_data = loads(b64decode(args.extra_data))
        if args.tipo_tag == "Seleccion":
            boleta = Seleccion.desde_string(args.tag)
            image = boleta.a_imagen()
            dpi = get_dpi_boletas()
        elif args.tipo_tag == "Apertura":
            boleta = Apertura.desde_tag(b64decode(args.tag))
            autoridades = boleta.autoridades
            image = boleta.a_imagen()
            dpi = DPI_VOTO_ALTA if IMPRESION_HD_APERTURA else DPI_VOTO_BAJA
        elif args.tipo_tag == "Recuento":
            boleta = Recuento.desde_tag(b64decode(args.tag))
            autoridades = extra_data.get('autoridades')
            if autoridades is not None:
                for autoridad in autoridades:
                    boleta.autoridades.append(Autoridad.desde_dict(autoridad))
            boleta.hora = extra_data['hora']
            image = boleta.a_imagen(extra_data['tipo_acta'])
            dpi = DPI_VOTO_ALTA if IMPRESION_HD_CIERRE else DPI_VOTO_BAJA
        elif args.tipo_tag == "Prueba":
            dpi = DPI_VOTO_ALTA
            image = ImagenPrueba(hd=True).render_image()

    printer.imprimir_image(image, dpi, args.transpose, args.compress,
                           args.only_buffer)
Esempio n. 10
0
def get_tag():
    mesa = Ubicacion.get(numero="1001")
    recuento = Recuento(mesa)
    seleccion = Seleccion(mesa)
    listas = Lista.all()
    lista = Lista.get(numero="207")
    for i in range(200):
        seleccion.elegir_lista(lista)
        recuento.sumar_seleccion(seleccion)
    lista = Lista.get(numero="38")
    for i in range(100):
        seleccion.elegir_lista(lista)
        recuento.sumar_seleccion(seleccion)
    lista = Lista.get(numero="603")
    for i in range(50):
        seleccion.elegir_lista(lista)
        recuento.sumar_seleccion(seleccion)
    for i in range(46):
        lista = choice(listas)
        seleccion.elegir_lista(lista)
        recuento.sumar_seleccion(seleccion)
    tag = seleccion.a_tag()
    return tag
Esempio n. 11
0
 def _precache_generacion_img(self):
     # Imagen dummy para importar lo relacionado a generar imagenes
     test_seleccion = Seleccion(self.sesion.mesa)
     test_seleccion.rellenar_de_blanco()
     test_seleccion.a_imagen(svg=True)
     del test_seleccion
Esempio n. 12
0
    def procesar_tag(self, tag_dict):
        """ Evento. Procesa el tag recibido por parametro. Cumple la funcion
            del procesar_tag() de PantallaRecuento de recuento Gtk.

            Argumentos:
            tag   -- El objeto TAG recibido.
            datos -- Los datos almacenados en el tag recibido.

            Si el tag no es ICODE se descarta el evento.
            Si su tipo no es voto, o está vacío, se devuelve error.
            Se intenta sumar los datos al recuento, si devuelve False
            es porque el tag ya fue sumado, sino está ok.
        """
        if self.estado == E_RECUENTO:
            serial = tag_dict.get('serial')
            tipo_tag = tag_dict.get('tipo')
            datos = tag_dict.get('datos')
            if None in (serial, tipo_tag, datos) or tipo_tag != TAG_VOTO:
                self.controller.set_panel_estado(RECUENTO_ERROR)
            else:
                self.controller.hide_dialogo()
                try:
                    seleccion = Seleccion.desde_tag(datos,
                                                    sesion.mesa)
                    if not sesion.recuento.serial_sumado(serial):
                        sesion.recuento.sumar_seleccion(seleccion, serial)
                        sesion.recuento.hora_fin = time.time()
                        sesion.ultima_seleccion = seleccion

                        # Dibujo boleta
                        imagen = seleccion.a_imagen(verificador=False,
                                                    solo_mostrar=True,
                                                    svg=True)
                        image_data = quote(imagen.encode("utf-8"))

                        cant_leidas = sesion.recuento.boletas_contadas()
                        self.controller.actualizar_resultados(
                            sesion.ultima_seleccion, cant_leidas, image_data)
                        gobject.timeout_add(200,
                                            self.controller.set_panel_estado,
                                            RECUENTO_OK)
                    else:
                        self.controller.set_panel_estado(
                            RECUENTO_ERROR_REPETIDO)
                except Exception as e:
                    print(e)
                    self.controller.set_panel_estado(RECUENTO_ERROR)
        elif self.controller.__class__.__name__ == "ControllerInteraccion":
            read_only = tag_dict.get("read_only")
            if self.rampa.tiene_papel and not read_only and self.estado not in \
                    (E_SETUP, E_VERIFICACION) and tag_dict['tipo'] in \
                    (TAG_VACIO, [0, 0]):
                self.estado = E_SETUP
                self.controller.estado = E_MESAYPIN
                self.controller.set_pantalla()
                self.posicion_recuento()
            elif self.estado in E_INICIAL and tag_dict['tipo'] == TAG_RECUENTO:
                sesion.recuento = Recuento.desde_tag(tag_dict['datos'])
                sesion.mesa = sesion.recuento.mesa

                def _inner():
                    if self.rampa.tiene_papel:
                        self.rampa.expulsar_boleta()
                    self.revision_recuento()
                gobject.timeout_add(1000, _inner)

            else:
                def _expulsar():
                    if self.rampa.tiene_papel and self.rampa.datos_tag and self.estado != E_SETUP:
                        self.controller.set_mensaje(_("acta_contiene_informacion"))
                        self.rampa.expulsar_boleta()
                gobject.timeout_add(300, _expulsar)
Esempio n. 13
0
File: voto.py Progetto: sunzu/vot.ar
 def reiniciar_seleccion(self):
     """Resetea la seleccion. Elimina lo que el usuario eligió."""
     self.parent.seleccion = Seleccion(self.sesion.mesa)
Esempio n. 14
0
File: voto.py Progetto: sunzu/vot.ar
 def _precache_generacion_img(self):
     #Imagen dummy para importar lo relacionado a generar imagenes
     test_seleccion = Seleccion(self.sesion.mesa)
     test_seleccion.rellenar_de_blanco()
     test_seleccion.a_imagen(svg=True)
     del test_seleccion
Esempio n. 15
0
    def procesar_tag(self, tag_dict):
        """ Evento. Procesa el tag recibido por parametro. Cumple la funcion
            del procesar_tag() de PantallaRecuento de recuento Gtk.

            Argumentos:
            tag   -- El objeto TAG recibido.
            datos -- Los datos almacenados en el tag recibido.

            Si el tag no es ICODE se descarta el evento.
            Si su tipo no es voto, o está vacío, se devuelve error.
            Se intenta sumar los datos al recuento, si devuelve False
            es porque el tag ya fue sumado, sino está ok.
        """
        if self.estado == E_RECUENTO:
            serial = tag_dict.get('serial')
            tipo_tag = tag_dict.get('tipo')
            datos = tag_dict.get('datos')
            if None in (serial, tipo_tag, datos) or tipo_tag != TAG_VOTO:
                self.controller.set_panel_estado(RECUENTO_ERROR)
            else:
                self.controller.hide_dialogo()
                try:
                    seleccion = Seleccion.desde_tag(datos, sesion.mesa)
                    if not sesion.recuento.serial_sumado(serial):
                        sesion.recuento.sumar_seleccion(seleccion, serial)
                        sesion.recuento.hora_fin = time.time()
                        sesion.ultima_seleccion = seleccion

                        # Dibujo boleta
                        imagen = seleccion.a_imagen(verificador=False,
                                                    solo_mostrar=True,
                                                    svg=True)
                        image_data = quote(imagen.encode("utf-8"))

                        cant_leidas = sesion.recuento.boletas_contadas()
                        self.controller.actualizar_resultados(
                            sesion.ultima_seleccion, cant_leidas, image_data)
                        gobject.timeout_add(200,
                                            self.controller.set_panel_estado,
                                            RECUENTO_OK)
                    else:
                        self.controller.set_panel_estado(
                            RECUENTO_ERROR_REPETIDO)
                except Exception as e:
                    print(e)
                    self.controller.set_panel_estado(RECUENTO_ERROR)
        elif self.controller.__class__.__name__ == "ControllerInteraccion":
            read_only = tag_dict.get("read_only")
            if self.rampa.tiene_papel and not read_only and self.estado not in \
                    (E_SETUP, E_VERIFICACION) and tag_dict['tipo'] in \
                    (TAG_VACIO, [0, 0]):
                self.estado = E_SETUP
                self.controller.estado = E_MESAYPIN
                self.controller.set_pantalla()
                self.posicion_recuento()
            elif self.estado in E_INICIAL and tag_dict['tipo'] == TAG_RECUENTO:
                sesion.recuento = Recuento.desde_tag(tag_dict['datos'])
                sesion.mesa = sesion.recuento.mesa

                def _inner():
                    if self.rampa.tiene_papel:
                        self.rampa.expulsar_boleta()
                    self.revision_recuento()

                gobject.timeout_add(1000, _inner)

            else:

                def _expulsar():
                    if self.rampa.tiene_papel and self.rampa.datos_tag and self.estado != E_SETUP:
                        self.controller.set_mensaje(
                            _("acta_contiene_informacion"))
                        self.rampa.expulsar_boleta()

                gobject.timeout_add(300, _expulsar)
Esempio n. 16
0
File: voto.py Progetto: sunzu/vot.ar
 def _comenzar(self):
     # Inicializo la seleccion
     if self.estado != E_VOTANDO:
         self.set_estado(E_VOTANDO)
         self.seleccion = Seleccion(sesion.mesa, sesion.interna)
         self.controller.set_screen(PANTALLA_SELECCION_CANDIDATOS)