-
Notifications
You must be signed in to change notification settings - Fork 0
Add drawImage method for rendering images to screen #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Adds a drawImage API to the Graphik class to support rendering image files onto the pygame display surface with explicit positioning and scaling.
Changes:
- Add
Graphik.drawImage(...)that loads an image from disk, scales it to(width, height), and blits it to the display surface. - Add error handling for image load/transform failures with a more descriptive exception message.
- Update
.gitignoreto ignore Python bytecode artifacts (__pycache__,*.pyc).
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/main/python/preponderous/graphik/graphik.py |
Introduces the new drawImage method for loading/scaling/blitting images. |
.gitignore |
Adds Python cache/bytecode ignore patterns. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def drawImage(self, file_path, xpos, ypos, width, height): | ||
| try: | ||
| image = pygame.image.load(file_path) | ||
| image = pygame.transform.scale(image, (width, height)) | ||
| self.gameDisplay.blit(image, (xpos, ypos)) | ||
| except (pygame.error, FileNotFoundError) as e: | ||
| raise type(e)(f"Failed to load image from '{file_path}': {e}") No newline at end of file |
Copilot
AI
Feb 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file_path is the only snake_case parameter name in this class (others use xpos, ypos, colorBox, etc.). To keep the public API consistent, consider renaming it to match the existing style (e.g., filepath or filePath).
| def drawImage(self, file_path, xpos, ypos, width, height): | |
| try: | |
| image = pygame.image.load(file_path) | |
| image = pygame.transform.scale(image, (width, height)) | |
| self.gameDisplay.blit(image, (xpos, ypos)) | |
| except (pygame.error, FileNotFoundError) as e: | |
| raise type(e)(f"Failed to load image from '{file_path}': {e}") | |
| def drawImage(self, filePath, xpos, ypos, width, height): | |
| try: | |
| image = pygame.image.load(filePath) | |
| image = pygame.transform.scale(image, (width, height)) | |
| self.gameDisplay.blit(image, (xpos, ypos)) | |
| except (pygame.error, FileNotFoundError) as e: | |
| raise type(e)(f"Failed to load image from '{filePath}': {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed parameter to filePath in commit 9ace29f for consistent naming with other methods in the class.
| image = pygame.transform.scale(image, (width, height)) | ||
| self.gameDisplay.blit(image, (xpos, ypos)) | ||
| except (pygame.error, FileNotFoundError) as e: | ||
| raise type(e)(f"Failed to load image from '{file_path}': {e}") No newline at end of file |
Copilot
AI
Feb 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-raising with raise type(e)(...) drops important exception details (e.g., FileNotFoundError's errno/filename) and loses the original traceback context. Prefer raising with explicit exception construction per type and chaining with from e so callers keep the original context and error metadata.
| raise type(e)(f"Failed to load image from '{file_path}': {e}") | |
| if isinstance(e, FileNotFoundError): | |
| # Preserve errno and filename while adding context, and keep traceback via exception chaining. | |
| message = f"Failed to load image from '{file_path}': {e.strerror}" | |
| raise FileNotFoundError(e.errno, message, e.filename) from e | |
| else: | |
| # Preserve the original exception type and chain to keep traceback. | |
| raise pygame.error(f"Failed to load image from '{file_path}': {e}") from e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated exception handling to use from e for proper exception chaining in commit 9ace29f. This preserves the original traceback context while providing descriptive error messages.
|
@copilot address comments |
…on handling Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Plan to Add Image Drawing Support
drawImagemethod to Graphik classdrawImage(self, filePath, xpos, ypos, width, height)from efile_pathtofilePathfor naming consistencyChanges Addressing PR Feedback
Comment 2752287803 - Parameter Naming Consistency
file_pathparameter tofilePathto match existing naming style in the class (e.g.,colorBox,colorText,sizeText)Comment 2752287807 - Exception Handling Improvements
from eImplementation Summary
The
drawImagemethod:filePath,xpos,ypos,width,heightSecurity Summary
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.