Skip to content

Commit

Permalink
Remove # type: ignore from AppKit module calls
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-arista committed Aug 21, 2024
1 parent 8518cbb commit c41c63b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
32 changes: 16 additions & 16 deletions drawBot/context/tools/imageObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,21 @@ def open(self, path: SomePath):
"""
Open an image with a given `path`.
"""
if isinstance(path, AppKit.NSImage): # type: ignore
if isinstance(path, AppKit.NSImage):
im = path
elif isinstance(path, (str, os.PathLike)):
path = optimizePath(path)
if isinstance(path, str) and path.startswith("http"):
url = AppKit.NSURL.URLWithString_(path) # type: ignore
url = AppKit.NSURL.URLWithString_(path)
else:
if not os.path.exists(path):
raise DrawBotError("Image path '%s' does not exists." % path)
url = AppKit.NSURL.fileURLWithPath_(path) # type: ignore
im = AppKit.NSImage.alloc().initByReferencingURL_(url) # type: ignore
url = AppKit.NSURL.fileURLWithPath_(path)
im = AppKit.NSImage.alloc().initByReferencingURL_(url)
else:
raise DrawBotError("Cannot read image path '%s'." % path)
rep = _makeBitmapImageRep(im)
ciImage = AppKit.CIImage.alloc().initWithBitmapImageRep_(rep) # type: ignore
ciImage = AppKit.CIImage.alloc().initWithBitmapImageRep_(rep)
self._merge(ciImage, doCrop=True)

def copy(self) -> Self:
Expand Down Expand Up @@ -158,10 +158,10 @@ def unlockFocus(self):
pageCount = data.pageCount()
page = data.pageAtIndex_(pageCount - 1)
# create an image
im = AppKit.NSImage.alloc().initWithData_(page.dataRepresentation()) # type: ignore
im = AppKit.NSImage.alloc().initWithData_(page.dataRepresentation())
# create an CIImage object
rep = _makeBitmapImageRep(im)
ciImage = AppKit.CIImage.alloc().initWithBitmapImageRep_(rep) # type: ignore
ciImage = AppKit.CIImage.alloc().initWithBitmapImageRep_(rep)
# merge it with the already set data, if there already an image
self._merge(ciImage)

Expand All @@ -184,8 +184,8 @@ def _nsImage(self):
"""
Return the NSImage object.
"""
rep = AppKit.NSCIImageRep.imageRepWithCIImage_(self._ciImage()) # type: ignore
nsImage = AppKit.NSImage.alloc().initWithSize_(rep.size()) # type: ignore
rep = AppKit.NSCIImageRep.imageRepWithCIImage_(self._ciImage())
nsImage = AppKit.NSImage.alloc().initWithSize_(rep.size())
nsImage.addRepresentation_(rep)
return nsImage

Expand Down Expand Up @@ -223,7 +223,7 @@ def _applyFilters(self):
sourceSize = self.size()
for filterDict in self._filters:
filterName = filterDict.get("name")
ciFilter = AppKit.CIFilter.filterWithName_(filterName) # type: ignore
ciFilter = AppKit.CIFilter.filterWithName_(filterName)
ciFilter.setDefaults()

for key, value in filterDict.get("attributes", {}).items():
Expand All @@ -233,24 +233,24 @@ def _applyFilters(self):
generator = ciFilter.valueForKey_("outputImage")
extent = generator.extent()
w, h = filterDict.get("size", extent.size)
dummy = AppKit.NSImage.alloc().initWithSize_((w, h)) # type: ignore
dummy = AppKit.NSImage.alloc().initWithSize_((w, h))

scaleX = w / extent.size.width
scaleY = h / extent.size.height
dummy.lockFocus()
ctx = AppKit.NSGraphicsContext.currentContext() # type: ignore
ctx = AppKit.NSGraphicsContext.currentContext()
ctx.setShouldAntialias_(False)
ctx.setImageInterpolation_(AppKit.NSImageInterpolationNone) # type: ignore
ctx.setImageInterpolation_(AppKit.NSImageInterpolationNone)
fromRect = (0, 0), (w, h)
if filterDict.get("fitImage", False):
transform = AppKit.NSAffineTransform.transform() # type: ignore
transform = AppKit.NSAffineTransform.transform()
transform.scaleXBy_yBy_(scaleX, scaleY)
transform.concat()
fromRect = extent
generator.drawAtPoint_fromRect_operation_fraction_((0, 0), fromRect, AppKit.NSCompositeCopy, 1) # type: ignore
generator.drawAtPoint_fromRect_operation_fraction_((0, 0), fromRect, AppKit.NSCompositeCopy, 1)
dummy.unlockFocus()
rep = _makeBitmapImageRep(dummy)
self._cachedImage = AppKit.CIImage.alloc().initWithBitmapImageRep_(rep) # type: ignore # type: ignore
self._cachedImage = AppKit.CIImage.alloc().initWithBitmapImageRep_(rep)
del dummy
elif hasattr(self, "_cachedImage"):
ciFilter.setValue_forKey_(self._cachedImage, "inputImage")
Expand Down
20 changes: 10 additions & 10 deletions scripting/imageObjectCodeExtractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def getVariableValue(key, fallback=None):

ignoreInputKeys = ["inputImage"]

generators = list(AppKit.CIFilter.filterNamesInCategory_("CICategoryGenerator")) # type: ignore
generators = list(AppKit.CIFilter.filterNamesInCategory_("CICategoryGenerator"))
generators.extend(
[
"CIPDF417BarcodeGenerator",
Expand All @@ -309,7 +309,7 @@ def getVariableValue(key, fallback=None):
]
)

allFilterNames = AppKit.CIFilter.filterNamesInCategory_(None) # type: ignore
allFilterNames = AppKit.CIFilter.filterNamesInCategory_(None)

excludeFilterNames = [
"CIBarcodeGenerator",
Expand Down Expand Up @@ -350,10 +350,10 @@ def generateImageObjectCode() -> tuple[str, str]:
for filterName in allFilterNames:
if filterName in excludeFilterNames:
continue
ciFilter = AppKit.CIFilter.filterWithName_(filterName) # type: ignore
ciFilter = AppKit.CIFilter.filterWithName_(filterName)
ciFilterAttributes = ciFilter.attributes()
doc = CodeWriter()
doc.add(AppKit.CIFilter.localizedDescriptionForFilterName_(filterName)) # type: ignore
doc.add(AppKit.CIFilter.localizedDescriptionForFilterName_(filterName))

args = []
unitTestsArgs = []
Expand Down Expand Up @@ -402,7 +402,7 @@ def generateImageObjectCode() -> tuple[str, str]:
# print(ciFilterAttributes)

if default is not None:
if isinstance(default, AppKit.CIVector): # type: ignore
if isinstance(default, AppKit.CIVector):
if default.count() == 2:
default = default.X(), default.Y()
arg += ": Point"
Expand All @@ -418,19 +418,19 @@ def generateImageObjectCode() -> tuple[str, str]:
elif isinstance(default, bool):
arg += ": bool"

elif isinstance(default, (AppKit.NSString, str)): # type: ignore
elif isinstance(default, (AppKit.NSString, str)):
default = f"'{default}'"
arg += ": str"

elif isinstance(default, AppKit.NSNumber): # type: ignore
elif isinstance(default, AppKit.NSNumber):
default = float(default)
arg += ": float"

elif isinstance(default, AppKit.NSAffineTransform): # type: ignore
elif isinstance(default, AppKit.NSAffineTransform):
default = tuple(default.transformStruct())
arg += ": TransformTuple"

elif isinstance(default, AppKit.CIColor): # type: ignore
elif isinstance(default, AppKit.CIColor):
default = (
default.red(),
default.green(),
Expand All @@ -439,7 +439,7 @@ def generateImageObjectCode() -> tuple[str, str]:
)
arg += ": RGBAColorTuple"

elif isinstance(default, AppKit.NSData): # type: ignore
elif isinstance(default, AppKit.NSData):
default = None
arg += ": bytes | None"

Expand Down

0 comments on commit c41c63b

Please sign in to comment.