Skip to content

Commit

Permalink
feat(Line/LineF): add __repr__ and __iter__
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Aug 24, 2020
1 parent b330a7f commit 73b0b77
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
22 changes: 20 additions & 2 deletions prettyqt/core/line.py
Expand Up @@ -4,14 +4,32 @@


class Line(QtCore.QLine):
def __repr__(self):
return f"Line({repr(self.get_p1())}, {repr(self.get_p2())})"

def __iter__(self):
yield self.get_p1()
yield self.get_p2()

def __getitem__(self, index):
if index == 0:
return core.Point(self.p1())
return self.get_p1()
elif index == 1:
return core.Point(self.p2())
return self.get_p2()

def __setitem__(self, index, value):
if index == 0:
self.setP1(value)
elif index == 1:
self.setP2(value)

def get_p1(self):
return core.Point(self.p1())

def get_p2(self):
return core.Point(self.p2())


if __name__ == "__main__":
line = Line(core.Point(0, 0), core.Point(2, 2))
print(repr(line))
22 changes: 20 additions & 2 deletions prettyqt/core/linef.py
Expand Up @@ -4,14 +4,32 @@


class LineF(QtCore.QLineF):
def __repr__(self):
return f"LineF({repr(self.get_p1())}, {repr(self.get_p1())})"

def __iter__(self):
yield self.get_p1()
yield self.get_p2()

def __getitem__(self, index):
if index == 0:
return core.PointF(self.p1())
return self.get_p1()
elif index == 1:
return core.PointF(self.p2())
return self.get_p2()

def __setitem__(self, index, value):
if index == 0:
self.setP1(value)
elif index == 1:
self.setP2(value)

def get_p1(self):
return core.PointF(self.p1())

def get_p2(self):
return core.PointF(self.p2())


if __name__ == "__main__":
line = LineF(core.Point(0, 0), core.Point(2, 2))
print(repr(line))
5 changes: 5 additions & 0 deletions prettyqt/core/rect.py
Expand Up @@ -6,3 +6,8 @@
class Rect(QtCore.QRect):
def __repr__(self):
return f"Rect({self.x()}, {self.y()}, {self.width()}, {self.height()})"


if __name__ == "__main__":
rect = Rect(0, 2, 5, 5)
print(repr(rect))
5 changes: 5 additions & 0 deletions prettyqt/core/rectf.py
Expand Up @@ -6,3 +6,8 @@
class RectF(QtCore.QRectF):
def __repr__(self):
return f"RectF({self.x()}, {self.y()}, {self.width()}, {self.height()})"


if __name__ == "__main__":
rect = RectF(0, 2, 5, 5)
print(repr(rect))

0 comments on commit 73b0b77

Please sign in to comment.