Skip to content

Commit

Permalink
Merge pull request #251 from AsadNizami/main
Browse files Browse the repository at this point in the history
str and repr implementation for the py5 class.
  • Loading branch information
hx2A authored Mar 11, 2023
2 parents 8eab021 + 37fa8b8 commit 44d3217
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions py5_resources/py5_module/py5/create_font_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def __init__(self, font_name, font_size, filename=None, characters=None, pause=T
self.filename = filename or f'{font_name}-{font_size}.vlw'
self.characters = characters

def __str__(self) -> str:
return f"CreateFontTool(font_name='" + self.font_name + "', font_size=" + str(self.font_size) + ")"

def __repr__(self) -> str:
return self.__str__()

def settings(self):
self.size(400, 100, self.P2D)

Expand Down
6 changes: 6 additions & 0 deletions py5_resources/py5_module/py5/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,11 @@ def __new__(cls, pfont):
cls._py5_object_cache.add(o)
return o

def __str__(self) -> str:
return "Py5Font(font_name='" + self.get_name() + "', font_size=" + str(self.get_size()) + ")"

def __repr__(self) -> str:
return self.__str__()


{py5font_class_members_code}
6 changes: 6 additions & 0 deletions py5_resources/py5_module/py5/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ def __init__(self, pgraphics):
self._instance = pgraphics
super().__init__(instance=pgraphics)

def __str__(self) -> str:
return f"Py5Graphics(width=" + str(self._get_width()) + ", height=" + str(self._get_height()) + ")"

def __repr__(self) -> str:
return self.__str__()

def _activate_context_manager(self, exit_function, exit_args):
self._context_manager_exit_function = exit_function
self._context_manager_exit_args = exit_args
Expand Down
6 changes: 6 additions & 0 deletions py5_resources/py5_module/py5/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,11 @@ def __init__(self, pimage):
self._instance = pimage
super().__init__(instance=pimage)

def __str__(self) -> str:
return f"Py5Image(width=" + str(self._get_width()) + ", height=" + str(self._get_height()) + ")"

def __repr__(self) -> str:
return self.__str__()


{py5image_class_members_code}
6 changes: 6 additions & 0 deletions py5_resources/py5_module/py5/shader.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,11 @@ def __new__(cls, pshader):
cls._py5_object_cache.add(o)
return o

def __str__(self) -> str:
return f"Py5Shader(id=" + str(id(self)) + ")"

def __repr__(self) -> str:
return self.__str__()


{py5shader_class_members_code}
7 changes: 7 additions & 0 deletions py5_resources/py5_module/py5/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,12 @@ def __new__(cls, pshape):
cls._py5_object_cache.add(o)
return o

def __str__(self):
name = "'" + self.get_name() + "'" if self.get_name() else str(None)
return f"Py5Shape(name=" + name + ")"

def __repr__(self):
return self.__str__()


{py5shape_class_members_code}
6 changes: 6 additions & 0 deletions py5_resources/py5_module/py5/sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ def __init__(self, *args, **kwargs):
except Exception:
pass

def __str__(self):
return f"Sketch(width=" + str(self._get_width()) + ", height=" + str(self._get_height()) + ")"

def __repr__(self):
return self.__str__()

def run_sketch(self, block: bool = None, *,
py5_options: list = None, sketch_args: list = None,
_osx_alt_run_method: bool = True) -> None:
Expand Down
6 changes: 6 additions & 0 deletions py5_resources/py5_module/py5/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,11 @@ def __new__(cls, psurface):
cls._py5_object_cache.add(o)
return o

def __str__(self) -> str:
return f"Py5Surface(id=" + str(id(self)) + ")"

def __repr__(self) -> str:
return self.__str__()


{py5surface_class_members_code}

0 comments on commit 44d3217

Please sign in to comment.