Example #1
0
def qrcode_save_and_show(itype='png'):
    data = get_example_data(ex=0)
    qrcode = QRCode(data)
    img = qrcode.to_img()
    filename = '/tmp/qr-code.{}'.format(itype)
    img.save(filename)
    open_file(filename)
Example #2
0
def qrcode_example_to_SVGElement():

    # The dimensions of the QR-Code
    width, height = 100, 100

    # Make an SVG root element
    from newskylabs.graphics.svg.svg import SVGElement
    root = SVGElement.root(width=width, height=height, absolute=True)

    # Make an QR-Code SVG element
    data = get_example_data(ex=0)
    qrcode = QRCode(data)
    qrcode_svg_element = qrcode.to_SVGElement(x=0,
                                              y=0,
                                              width=width,
                                              height=height)

    # Append the QR-Code SVG element to the SVG root element
    root.append(qrcode_svg_element)

    # Get a temporary file name
    import tempfile
    _, svgfile = tempfile.mkstemp(suffix='.svg',
                                  prefix='qrcode.',
                                  dir='/tmp',
                                  text=True)

    # Save the SVG file
    root.save(svgfile)

    # And finally open it
    application = 'Google Chrome'
    open_file(svgfile, application=application)
def vcard_example_to_QRCode_jpg():
    data = get_example_data(ex=0)
    vc = VCard(data)
    qr_code = vc.to_QRCode()
    qr_code_img = qr_code.to_img()
    qr_code_file = '/tmp/qr-code.jpg'
    qr_code_img.save(qr_code_file)
    from newskylabs.graphics.utils.general import open_file
    open_file(qr_code_file)
    def show_back(self, application='Google Chrome'):

        # Ensure that the svg has been generated
        if not self._saved_back_as:
            self.save_back()

        # Get the filename
        filename = self._saved_back_as

        # Open the SVG file
        open_file(filepath, application=application)
    def save_back(self, back=None, show=False, pdf=True):

        # Ensure that the svg has been generated
        if not self._svg_back:
            self.generate_back()

        # When no svgfile has been given
        # take it from the data
        if isinstance(back, str):
            svgfile = back

        else:
            svgfile = self.get_data('svgfile.back')

        # Print a message
        print("Saving back side of meishi as {}".format(svgfile))

        # Save as SVG file
        self._svg_back.save(svgfile)

        # Should I show the generated SVG?
        if show:
            application = 'Google Chrome'
            open_file(svgfile, application=application)

        # Remember last file saved to
        self._saved_back_as = svgfile

        # Save as pdf?
        if pdf:

            # Is 'pdf' a string?
            # If so use it as pdf file name
            if isinstance(pdf, str):
                pdffile = pdf

            else:
                pdffile = self.get_data('pdffile.back')

            # Print a message
            print("Saving back side of meishi as {}".format(pdffile))

            # Convert saved svg to pdf
            self.svg2pdf(svgfile, pdffile)

            # Return svg and pdf file name
            return pdffile

        # Default - do not save as pdf
        # Return svg file name
        return svgfile
Example #6
0
def qrcode_to_svg(method=None):
    data = get_example_data(ex=0)
    qrcode = QRCode(data)
    img = qrcode.to_img(itype='svg', method=method)
    if method == None:
        img.show()

    else:
        # The methods 'basic', 'fragment', and 'path'
        # do not have a 'show()' method:
        import tempfile
        _, filename = tempfile.mkstemp(suffix='.svg',
                                       prefix='qrcode.',
                                       dir='/tmp',
                                       text=True)
        img.save(filename)
        application = 'Google Chrome'
        open_file(filename, application=application)
    def show(self,
             filename=None,
             application='Google Chrome',
             pretty_print=False,
             xml_declaration=True):

        if not filename:
            import tempfile
            _, filename = tempfile.mkstemp(suffix='.svg',
                                           prefix='qrcode.',
                                           dir='/tmp',
                                           text=True)

        self.save(filename,
                  pretty_print=pretty_print,
                  xml_declaration=xml_declaration)

        from newskylabs.graphics.utils.general import open_file
        open_file(filename, application=application)

        return filename
    def save(self, front=True, back=True, show=True, pdf=True, merge=True):

        frontfile = self.save_front(front=front, show=show, pdf=pdf)
        backfile = self.save_back(back=back, show=show, pdf=pdf)

        # whould I merge the front and back pdfs into one pdf?
        if front and back and pdf and merge:

            # Is 'merge' a string?
            # If so use it as pdf file name
            if isinstance(merge, str):
                mergedfile = pdf

            else:  # Interpreted as True
                mergedfile = self.get_data('pdffile.merged')

            # Print a message
            print(
                "Saving front and back side combined as {}".format(mergedfile))

            pdfs = [frontfile, backfile]

            merger = PdfFileMerger()

            for pdf in pdfs:
                merger.append(pdf)

            merger.write(mergedfile)
            merger.close()

            # Should I show the generated pdf?
            if show:
                open_file(mergedfile)

            return mergedfile

        return frontfile, backfile