Merge pull request #1 from radarhere/init

Call init() if mimetype is not found with preinit()
This commit is contained in:
Carl Weaver 2023-04-21 08:14:45 +08:00 committed by GitHub
commit 5a0c431c46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 17 deletions

View File

@ -84,13 +84,7 @@ jobs:
python3 -m pip install pytest-reverse python3 -m pip install pytest-reverse
fi fi
if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
export XDG_RUNTIME_DIR="/tmp/headless-sway" xvfb-run -s '-screen 0 1024x768x24' sway&
export SWAYSOCK="$XDG_RUNTIME_DIR/sway.sock"
export WLR_BACKENDS=headless
export WLR_LIBINPUT_NO_DEVICES=1
mkdir "$XDG_RUNTIME_DIR"
xvfb-run -s '-screen 0 1024x768x24'\
sway -V -d -c /dev/null&
export WAYLAND_DISPLAY=wayland-1 export WAYLAND_DISPLAY=wayland-1
.ci/test.sh .ci/test.sh
else else

View File

@ -106,11 +106,10 @@ $ms = new-object System.IO.MemoryStream(, $bytes)
), ),
reason="Linux with wl-clipboard only", reason="Linux with wl-clipboard only",
) )
@pytest.mark.parametrize( @pytest.mark.parametrize("ext", ("gif", "png", "ico"))
"image_path", ["Tests/images/hopper.gif", "Tests/images/hopper.png"] def test_grabclipboard_wl_clipboard(self, ext):
) image_path = "Tests/images/hopper." + ext
def test_grabclipboard_wl_clipboard(self, image_path): with open(image_path, "rb") as fp:
with open(image_path, mode="rb") as raw_image: subprocess.call(["wl-copy"], stdin=fp)
subprocess.call(["wl-copy"], stdin=raw_image)
im = ImageGrab.grabclipboard() im = ImageGrab.grabclipboard()
assert_image_equal_tofile(im, image_path) assert_image_equal_tofile(im, image_path)

View File

@ -137,11 +137,19 @@ def grabclipboard():
args = ["wl-paste"] args = ["wl-paste"]
output = subprocess.check_output(["wl-paste", "-l"]).decode() output = subprocess.check_output(["wl-paste", "-l"]).decode()
clipboard_mimetypes = output.splitlines() clipboard_mimetypes = output.splitlines()
def find_mimetype():
for mime in Image.MIME.values():
if mime in clipboard_mimetypes:
return mime
Image.preinit() Image.preinit()
for mimetype in Image.MIME.values(): mimetype = find_mimetype()
if mimetype in clipboard_mimetypes: if not mimetype:
args.extend(["-t", mimetype]) Image.init()
break mimetype = find_mimetype()
if mimetype:
args.extend(["-t", mimetype])
elif shutil.which("xclip"): elif shutil.which("xclip"):
args = ["xclip", "-selection", "clipboard", "-t", "image/png", "-o"] args = ["xclip", "-selection", "clipboard", "-t", "image/png", "-o"]
else: else: