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()
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)
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)