Esempio n. 1
0
def main():
    '''CLI interface'''

    import argparse
    parser = argparse.ArgumentParser(
        prog='UltraSnip',
        description='A desktop snipping tool written in Qt for Python.')
    parser.add_argument(
        '--save',
        '-s',
        type=str,
        help='Path to save capture to for example: output.png',
    )
    parser.add_argument(
        '--measure',
        '-m',
        action='store_true',
        help='Output only the width and height of the region.',
    )
    parser.add_argument(
        '--confirm',
        '-c',
        action='store_true',
        help='Confirm the resulting pixmap using a simple dialog.',
    )

    args = parser.parse_args()

    region = select()
    if args.confirm:
        while not confirm(capture_region(region)):
            region = select(region)

    if region is None:
        sys.exit(1)

    if args.measure:
        print('%sx%s' % (region.width(), region.height()))

    pixmap = capture_region(region)
    if args.save:
        pixmap.save(args.save)
    elif args.measure:
        return
    else:
        from io import BytesIO
        byte_array = QtCore.QByteArray()
        buffer = QtCore.QBuffer(byte_array)
        buffer.open(QtCore.QIODevice.WriteOnly)
        pixmap.save(buffer, 'PNG')
        string_io = BytesIO(byte_array.data())
        string_io.seek(0)
        sys.stdout.buffer.write(string_io.read())
        sys.stdout.flush()

    sys.exit()
Esempio n. 2
0
 def open_file(self, url):
     """
     Open the video file from the url.
     """
     try:
         self.buffer = QtCore.QBuffer()
         with get_file_data_from_url(url) as data:
             self.data = data.content
             self.buffer.setData(self.data)
             self.buffer.open(QtCore.QIODevice.ReadOnly)
     except:
         raise MediaNotSetUp()