Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions botcity/core/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import subprocess
import time
import webbrowser
from typing import Union
from typing import Union, Tuple, Optional


import pyperclip
Expand Down Expand Up @@ -224,13 +224,13 @@ def _fix_retina_element(self, ele):
width=ele.width / 2.0, height=ele.height / 2.0)
return ele

def _fix_display_size(self):
def _fix_display_size(self) -> Tuple[int, int]:
width, height = ImageGrab.grab().size

if not is_retina():
return width, height

return int(width*2), int(height*2)
return int(width * 2), int(height * 2)

def _find_multiple_helper(self, haystack, region, confidence, grayscale, needle):
ele = cv2find.locate_all_opencv(needle, haystack, region=region,
Expand Down Expand Up @@ -488,7 +488,7 @@ def get_last_element(self):
"""
return self.state.element

def display_size(self):
def display_size(self) -> Tuple[int, int]:
"""
Returns the display size in pixels.

Expand All @@ -498,7 +498,8 @@ def display_size(self):
width, height = self._fix_display_size()
return width, height

def screenshot(self, filepath=None, region=None):
def screenshot(self, filepath: Optional[str] = None,
region: Optional[Tuple[int, int, int, int]] = None) -> Image.Image:
"""
Capture a screenshot.

Expand All @@ -520,7 +521,8 @@ def screenshot(self, filepath=None, region=None):
img.save(filepath)
return img

def get_screenshot(self, filepath=None, region=None):
def get_screenshot(self, filepath: Optional[str] = None,
region: Optional[Tuple[int, int, int, int]] = None) -> Image.Image:
"""
Capture a screenshot.

Expand All @@ -533,7 +535,8 @@ def get_screenshot(self, filepath=None, region=None):
"""
return self.screenshot(filepath, region)

def screen_cut(self, x, y, width=None, height=None):
def screen_cut(self, x: int = 0, y: int = 0, width: Optional[int] = None,
height: Optional[int] = None) -> Image.Image:
"""
Capture a screenshot from a region of the screen.

Expand All @@ -547,14 +550,13 @@ def screen_cut(self, x, y, width=None, height=None):
Image: The screenshot Image object
"""
screen_w, screen_h = self._fix_display_size()
x = x or 0
y = y or 0

width = width or screen_w
height = height or screen_h
img = self.screenshot(region=(x, y, width, height))
return img

def save_screenshot(self, path):
def save_screenshot(self, path: str) -> None:
"""
Saves a screenshot in a given path.

Expand Down
Loading