-
Notifications
You must be signed in to change notification settings - Fork 0
/
clpimg.py
executable file
·44 lines (33 loc) · 1.15 KB
/
clpimg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
from PyQt5 import QtCore, QtGui
from os import path
import sys
import re
import subprocess as sp
DESC = f"""
{path.basename(__file__)} is a simple script to copy images to clipboard
usage:
{path.basename(__file__)} image.png - copy to clipboard
{path.basename(__file__)} -s - show supported image formats
inspired by:
https://github.com/astrand/xclip/issues/43 (why)
https://github.com/m13253/linux-copy-image (how)
"""
def list_supported():
return sorted(re.findall(
r"b'([a-z]+)'",
str(QtGui.QImageReader.supportedImageFormats())
))
if __name__ == '__main__':
app = QtGui.QGuiApplication(sys.argv)
if '-h' in sys.argv or '--help' in sys.argv:
print(DESC)
sys.exit(0)
if '-s' in sys.argv:
print('\n'.join(list_supported()))
sys.exit(0)
assert len(sys.argv) == 2, f'you forgot an image, see {path.basename(__file__)} -h'
assert path.isfile(sys.argv[1]), 'file does not exist'
reader = QtGui.QImageReader(sys.argv[1])
assert reader.canRead(), f'failed to read image - {reader.errorString()}'
sp.Popen(['clpimg-daemon.py', sys.argv[1]])