66import subprocess
77import time
88import webbrowser
9- from typing import Union
9+ from typing import Union , Tuple , Optional
1010
1111
1212import pyperclip
@@ -224,13 +224,13 @@ def _fix_retina_element(self, ele):
224224 width = ele .width / 2.0 , height = ele .height / 2.0 )
225225 return ele
226226
227- def _fix_display_size (self ):
227+ def _fix_display_size (self ) -> Tuple [ int , int ] :
228228 width , height = ImageGrab .grab ().size
229229
230230 if not is_retina ():
231231 return width , height
232232
233- return int (width * 2 ), int (height * 2 )
233+ return int (width * 2 ), int (height * 2 )
234234
235235 def _find_multiple_helper (self , haystack , region , confidence , grayscale , needle ):
236236 ele = cv2find .locate_all_opencv (needle , haystack , region = region ,
@@ -488,7 +488,7 @@ def get_last_element(self):
488488 """
489489 return self .state .element
490490
491- def display_size (self ):
491+ def display_size (self ) -> Tuple [ int , int ] :
492492 """
493493 Returns the display size in pixels.
494494
@@ -498,7 +498,8 @@ def display_size(self):
498498 width , height = self ._fix_display_size ()
499499 return width , height
500500
501- def screenshot (self , filepath = None , region = None ):
501+ def screenshot (self , filepath : Optional [str ] = None ,
502+ region : Optional [Tuple [int , int , int , int ]] = None ) -> Image .Image :
502503 """
503504 Capture a screenshot.
504505
@@ -520,7 +521,8 @@ def screenshot(self, filepath=None, region=None):
520521 img .save (filepath )
521522 return img
522523
523- def get_screenshot (self , filepath = None , region = None ):
524+ def get_screenshot (self , filepath : Optional [str ] = None ,
525+ region : Optional [Tuple [int , int , int , int ]] = None ) -> Image .Image :
524526 """
525527 Capture a screenshot.
526528
@@ -533,7 +535,8 @@ def get_screenshot(self, filepath=None, region=None):
533535 """
534536 return self .screenshot (filepath , region )
535537
536- def screen_cut (self , x , y , width = None , height = None ):
538+ def screen_cut (self , x : int = 0 , y : int = 0 , width : Optional [int ] = None ,
539+ height : Optional [int ] = None ) -> Image .Image :
537540 """
538541 Capture a screenshot from a region of the screen.
539542
@@ -547,14 +550,13 @@ def screen_cut(self, x, y, width=None, height=None):
547550 Image: The screenshot Image object
548551 """
549552 screen_w , screen_h = self ._fix_display_size ()
550- x = x or 0
551- y = y or 0
553+
552554 width = width or screen_w
553555 height = height or screen_h
554556 img = self .screenshot (region = (x , y , width , height ))
555557 return img
556558
557- def save_screenshot (self , path ) :
559+ def save_screenshot (self , path : str ) -> None :
558560 """
559561 Saves a screenshot in a given path.
560562
0 commit comments