def imprimir_boleta(self): selec = Seleccion(self.controlador.mesa) selec.rellenar_de_blanco() registrador = Registrador(self.controlador.fin_boleta_demo, self, self.controlador.fin_boleta_demo_error) registrador.seleccion = selec registrador._registrar_voto() self.rampa.datos_tag = None
def _consultar(self, datos_tag, serial, force=False): """Cuando se apolla una boleta con datos. Mostramos el contenido.""" # si no estamos ya consultando un voto o no forzamos la muestra. if self.estado != E_CONSULTANDO or force: # si ese tag tiene datos if datos_tag is not None and len(datos_tag) > 0: def _fin(): """Se llama en el final de la consulta.""" if self.estado == E_CONSULTANDO: sigue = False # Si el papel esta insertado se expulsa, sin embargo # si está apoyada el acta hacemos que siga consultando # nuevamente if self.rampa.tiene_papel: self.rampa.expulsar_boleta() else: tag = self.sesion.lector.get_tag() if tag is not None: # ok, vamos de nuevo por que la persona esta # todavia chequeando. lo forzamos para que # renueve sigue = True self._consultar(tag['datos'], tag['serial'], 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, self.sesion.mesa) if seleccion_tag is not None \ and not len(seleccion_tag.candidatos_elegidos()): # Si el tag no esta vacio pero no tiene candidatos. seleccion_tag = None elif seleccion_tag is not None and \ seleccion_tag.serial != bytes(serial, "utf8"): seleccion_tag = None except Exception as e: # Esto maneja la instancia de que alguien quiera meter # un voto que no cumple con las condiciones requeridas. self.logger.error("La boleta no contiene datos validos") self.logger.exception(e) self.rampa.expulsar_boleta() _fin() # Si el tag es validos arrancamos la consulta del voto. if seleccion_tag is not None: self.set_estado(E_CONSULTANDO) self.controlador.consulta(seleccion_tag) timeout_add(self.tiempo_verificacion, _fin) else: # si la boleta que se ingresó no es un voto la expulsamos. self.rampa.expulsar_boleta()
def imprimir_serializado(self, tipo_tag, tag, transpose, only_buffer=False, extra_data=None): """Registra un documento que fue enviado serializado via d-bus. Argumentos: tipo_tag -- el tipo de documento que queremos registrar. Puede ser: (Seleccion, Apertura, Recuento o Prueba) tag -- Contenido del tag serializado. transpose -- transpone la imagen. only_buffer -- Solo guarda en el buffer, no imprime. extra_data -- datos extra que queremos imprimir pero que no se guardan en el chip. """ 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().render_image() image = image.convert('L') if transpose: image = image.transpose(Image.ROTATE_270) if only_buffer: if self.parent.impresion_v2: self.parent.printer.register_load_buffer_compressed_full() else: self.parent.printer.register_load_buffer_compressed() else: self.parent.printer.register_print_finished() data = image.getdata() if self.parent.impresion_v2: width, height = image.size self.parent.printer.load_buffer_compressed_full( data, self.parent._free_page_mem, width, height, print_immediately=not only_buffer) else: self.parent.printer.load_buffer_compressed( data, self.parent._free_page_mem, print_immediately=not only_buffer)
def procesar_voto(self, serial, tipo_tag, datos): tipo_actualizacion = ACT_ERROR seleccion = None if self.estado == E_RECUENTO: try: seleccion = Seleccion.desde_tag(datos, self.sesion.mesa) # Si el serial no fue ya sumado if not self.sesion.recuento.serial_sumado(serial): # Si el voto no fue ya contado vemos. if seleccion.serial == serial: self._sumar_voto(seleccion, serial) tipo_actualizacion = ACT_BOLETA_NUEVA else: tipo_actualizacion = ACT_ERROR seleccion = None else: # En caso de estar ya somado se avisa y no se cuenta. tipo_actualizacion = ACT_BOLETA_REPETIDA except Exception as e: # cualquier circunstancia extraña se translada en un error. print(e) seleccion = None self.controlador.actualizar(tipo_actualizacion, seleccion)
def reiniciar_seleccion(self, data=None): """Resetea la seleccion. Elimina lo que el usuario eligió.""" self.modulo.seleccion = Seleccion(self.sesion.mesa)
def _inner(): seleccion = Seleccion.desde_string(tag) self.imprimir_serializado("Seleccion", seleccion, True)
def imprimir_serializado(self, tipo_tag, tag, transpose, only_buffer=False, extra_data=None): """Registra un documento que fue enviado serializado via d-bus. Argumentos: tipo_tag -- el tipo de documento que queremos registrar. Puede ser: (Seleccion, Apertura, Recuento o Prueba) tag -- Contenido del tag serializado. transpose -- transpone la imagen. only_buffer -- Solo guarda en el buffer, no imprime. extra_data -- datos extra que queremos imprimir pero que no se guardan en el chip. """ 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().render_image() image = image.convert('L') if transpose: image = image.transpose(Image.ROTATE_270) if only_buffer: if self.parent.impresion_v2: self.parent.printer.register_load_buffer_compressed_full() else: self.parent.printer.register_load_buffer_compressed() else: self.parent.printer.register_print_finished() data = image.getdata() if self.parent.impresion_v2: width, height = image.size self.parent.printer.load_buffer_compressed_full( data, self.parent._free_page_mem, width, height, print_immediately=not only_buffer) else: self.parent.printer.load_buffer_compressed( data, self.parent._free_page_mem, print_immediately=not only_buffer)
def _comenzar(self): """Inicializo la seleccion.""" if self.estado != E_VOTANDO: self.set_estado(E_VOTANDO) self.seleccion = Seleccion(self.sesion.mesa, self.sesion.interna) self.controlador.send_command("cargar_pantalla_inicial")