Skip to content

Commit

Permalink
typing
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Sep 3, 2024
1 parent 88da5fc commit 1378c84
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 89 deletions.
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ source = ["sikuli"]
[tool.mypy]
files = "sikuli"

[[tool.mypy.overrides]]
module = "autopy.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "pyperclip.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "pytesseract.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "pudb.*"
ignore_missing_imports = true

[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
Expand Down
2 changes: 1 addition & 1 deletion sikuli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def run(folder: str) -> None:
sys.path.append(os.path.dirname(folder)) # FIXME: adding parent is unofficial
Settings.ImagePaths.append(folder)
try:
runpy._run_module_as_main(module)
runpy._run_module_as_main(module) # type: ignore
# mod = __import__(module)
except KeyboardInterrupt:
pass
Expand Down
10 changes: 7 additions & 3 deletions sikuli/script/app.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import typing as t

from .region import Region
from .robot import Robot


class App(object):
@staticmethod
def open(application: str = None) -> "App":
def open(application: t.Optional[str] = None) -> "App":
raise NotImplementedError("App.open(%r) not implemented" % application) # FIXME

@staticmethod
def focus(application: str = None) -> "App":
def focus(application: t.Optional[str] = None) -> "App":
assert application is not None
Robot.focus(application)
return App()

@staticmethod
def close(application: str = None) -> None:
def close(application: t.Optional[str] = None) -> None:
raise NotImplementedError(
"App.close(%r) not implemented" % application
) # FIXME
Expand Down
6 changes: 3 additions & 3 deletions sikuli/script/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def __init__(self, filename: str):
self.filename = filename

def find(self, filename: str, similarity: float = 0.7):
pass
raise NotImplementedError("Finder.find(%r, %r) not implemented" % (filename, similarity)) # FIXME

def hasNext(self) -> bool:
pass
raise NotImplementedError("Finder.hasNext() not implemented") # FIXME

def next(self) -> Match:
pass
raise NotImplementedError("Finder.next() not implemented") # FIXME
2 changes: 1 addition & 1 deletion sikuli/script/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, base: Union[PILImage.Image, str]) -> None:
if not full_path:
raise Exception("Couldn't find %r in %r" % (base, Settings.ImagePaths))

i = PILImage.open(full_path)
i: PILImage.Image = PILImage.open(full_path)
if Settings.Scale != 1.0:
# resize to multiple of 1/scale
# eg scale=0.5, round to a multiple of 2
Expand Down
8 changes: 4 additions & 4 deletions sikuli/script/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
http://doc.sikuli.org/location.html
"""

from typing import Tuple
import typing as t

from .sikulpy import unofficial

Expand All @@ -15,8 +15,8 @@ def __init__(self, x: float, y: float) -> None:
def __repr__(self) -> str:
return "Location(%r, %r)" % (self.x, self.y)

def __eq__(self, other: "Location") -> bool:
return self.x == other.x and self.y == other.y
def __eq__(self, other: object) -> bool:
return isinstance(other, Location) and self.x == other.x and self.y == other.y

def __add__(self, other: "Location") -> "Location":
return Location(self.x + other.x, self.y + other.y)
Expand All @@ -30,7 +30,7 @@ def __mul__(self, factor: float) -> "Location":
return Location(self.x * factor, self.y * factor)

@unofficial
def getXY(self) -> Tuple[float, float]:
def getXY(self) -> t.Tuple[float, float]:
return self.getX(), self.getY()

def getX(self) -> float:
Expand Down
3 changes: 2 additions & 1 deletion sikuli/script/match.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
http://doc.sikuli.org/match.html
"""
import typing as t

from .region import Region
from .rectangle import Rectangle
Expand All @@ -10,7 +11,7 @@
class Match(Region):
def __init__(self, rect: Rectangle, sim: float, targetOffset: Location):
Region.__init__(self, rect)
self._name = None
self._name: t.Optional[str] = None
self._score = sim
self._targetOffset = targetOffset

Expand Down
27 changes: 14 additions & 13 deletions sikuli/script/rectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class Rectangle(object):
def __init__(self, x: int = 0, y: int = 0, w: int = 0, h: int = 0) -> None:
def __init__(self, x: float = 0, y: float = 0, w: float = 0, h: float = 0) -> None:
self.x = x
self.y = y
self.w = w
Expand All @@ -22,24 +22,24 @@ def __repr__(self) -> str:
self.h,
)

def __eq__(self, b: "Rectangle") -> bool:
return self.x == b.x and self.y == b.y and self.w == b.w and self.h == b.h
def __eq__(self, b: object) -> bool:
return isinstance(b, Rectangle) and self.x == b.x and self.y == b.y and self.w == b.w and self.h == b.h

def __ne__(self, b: "Rectangle") -> bool:
def __ne__(self, b: object) -> bool:
return not self.__eq__(b)

# set

def setX(self, x: int) -> None:
def setX(self, x: float) -> None:
self.x = x

def setY(self, y: int) -> None:
def setY(self, y: float) -> None:
self.y = y

def setW(self, w: int) -> None:
def setW(self, w: float) -> None:
self.w = w

def setH(self, h: int) -> None:
def setH(self, h: float) -> None:
self.h = h

def moveTo(self, location: Location) -> "Rectangle":
Expand All @@ -60,16 +60,16 @@ def morphTo(self, reg: "Region") -> "Rectangle":

# get

def getX(self) -> int:
def getX(self) -> float:
return self.x

def getY(self) -> int:
def getY(self) -> float:
return self.y

def getW(self) -> int:
def getW(self) -> float:
return self.w

def getH(self) -> int:
def getH(self) -> float:
return self.h

def getRect(self) -> "Rectangle":
Expand All @@ -78,7 +78,8 @@ def getRect(self) -> "Rectangle":
def getCenter(self) -> Location:
return Location(self.x + self.w // 2, self.y + self.h // 2)

getTarget = getCenter
def getTarget(self) -> Location:
return self.getCenter()

def getTopLeft(self) -> Location:
return Location(self.x, self.y)
Expand Down
Loading

0 comments on commit 1378c84

Please sign in to comment.