Skip to content
This repository was archived by the owner on Mar 9, 2024. It is now read-only.
Open
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
10 changes: 6 additions & 4 deletions atomacos/_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
from CoreFoundation import CFArrayGetTypeID, CFGetTypeID, CFStringGetTypeID


CGRect = namedtuple("CGRect", ["x", "y", "width", "height"])
CFRange = namedtuple("CFRange", ["location", "length"])
CGPoint = namedtuple("CGPoint", ["x", "y"])
CGSize = namedtuple("CGSize", ["width", "height"])


class Converter:
def __init__(self, axuielementclass=None):
self.app_ref_class = axuielementclass
Expand Down Expand Up @@ -49,28 +55,24 @@ def convert_app_ref(self, value):

def convert_size(self, value):
repr_searched = re.search("{.*}", str(value)).group()
CGSize = namedtuple("CGSize", ["width", "height"])
size = NSSizeFromString(repr_searched)

return CGSize(size.width, size.height)

def convert_point(self, value):
repr_searched = re.search("{.*}", str(value)).group()
CGPoint = namedtuple("CGPoint", ["x", "y"])
point = NSPointFromString(repr_searched)

return CGPoint(point.x, point.y)

def convert_range(self, value):
repr_searched = re.search("{.*}", str(value)).group()
CFRange = namedtuple("CFRange", ["location", "length"])
range = NSRangeFromString(repr_searched)

return CFRange(range.location, range.length)

def convert_rect(self, value):
repr_searched = re.search("{.*}", str(value)).group()
CGRect = namedtuple("CGRect", ["x", "y", "width", "height"])
rect = NSRectFromString(repr_searched)

return CGRect(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)