File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -64,9 +64,13 @@ def test_grabclipboard(self):
6464 )
6565 p .communicate ()
6666 else :
67- with pytest .raises (NotImplementedError ) as e :
68- ImageGrab .grabclipboard ()
69- assert str (e .value ) == "ImageGrab.grabclipboard() is macOS and Windows only"
67+ if not shutil .which ("wl-paste" ):
68+ with pytest .raises (NotImplementedError ) as e :
69+ ImageGrab .grabclipboard ()
70+ assert (
71+ str (e .value )
72+ == "ImageGrab.grabclipboard() is macOS and Windows only"
73+ )
7074 return
7175
7276 ImageGrab .grabclipboard ()
Original file line number Diff line number Diff line change @@ -132,4 +132,14 @@ def grabclipboard():
132132 return BmpImagePlugin .DibImageFile (data )
133133 return None
134134 else :
135- raise NotImplementedError ("ImageGrab.grabclipboard() is macOS and Windows only" )
135+ if not shutil .which ("wl-paste" ):
136+ raise NotImplementedError (
137+ "wl-paste is required for ImageGrab.grabclipboard() on Linux"
138+ )
139+ fh , filepath = tempfile .mkstemp ()
140+ subprocess .call (["wl-paste" ], stdout = fh )
141+ os .close (fh )
142+ im = Image .open (filepath )
143+ im .load ()
144+ os .unlink (filepath )
145+ return im
You can’t perform that action at this time.
0 commit comments