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