-
Notifications
You must be signed in to change notification settings - Fork 6
Implement on-demand debug screen creation. #11
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
Open
tymzd
wants to merge
9
commits into
master
Choose a base branch
from
debug-screen
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a812a15
Merge branch 'debug-screen' of https://github.com/Tymotex/InkMemories…
tymzd 611a32a
Fix invocation of push debugger screen.
tymzd fde9631
Enter debug mode only when screen is not busy.
lin8231 b894b96
Implement on-demand debug screen creation.
tymzd c9d88d0
Document the debug screen's usage.
tymzd cedda8e
Update displayer_service/common/screen_manager.py
tymzd e4104d2
Document the debug screen's usage.
tymzd 16ba7d3
Merge branch 'debug-screen' of https://github.com/Tymotex/InkMemories…
tymzd 7d73d5e
Merge branch 'debug-screen' of https://github.com/Tymotex/InkMemories…
lin8231 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ __pycache__/ | |
| current_image.png | ||
| .ink-memories-log | ||
| venv/ | ||
| tmp-images/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #!/usr/bin/python3 | ||
|
|
||
| """Module for creating the debug screen.""" | ||
|
|
||
| from PIL import Image, ImageDraw, ImageFont | ||
| from PIL.Image import Image as ImageType | ||
|
|
||
| # At font size 20 and a screen size of 600x448, we can fit: | ||
| # - 59 characters horizontally. | ||
| # - 22 lines vertically. | ||
| CHARS_PER_LINE = 59 | ||
| MAX_LINES = 22 | ||
|
|
||
| # Font path relative to the root folder, `displayer_service`. | ||
| FONT_PATH = "fonts/Mono.ttf" | ||
| FONT_SIZE = 20 | ||
|
|
||
|
|
||
| def transform_logs_to_image(logs_path: str) -> ImageType: | ||
| """Returns a PIL Image of the debug screen. | ||
|
|
||
| Writes the most recent few logs to an in-memory PIL image with readable font | ||
| style and size. | ||
| """ | ||
| # Create a blank white image | ||
| debug_screen_img = Image.new('RGB', (600, 448), 'white') | ||
| draw = ImageDraw.Draw(debug_screen_img) | ||
| font = ImageFont.truetype(FONT_PATH, FONT_SIZE) | ||
|
|
||
| # Extract last MAX_LINES lines from the log file and reverse. | ||
| lines = [] | ||
| with open(logs_path, "r", encoding='utf-8') as logs_file: | ||
| lines = logs_file.read().splitlines() | ||
| # Get only the last MAX_LINES items and reverse the list so most recent logs | ||
| # are first. | ||
| lines = lines[-MAX_LINES:] | ||
| lines = lines[::-1] | ||
|
|
||
| # Write out each line into a PIL image, accounting for text-wrapping. Stop | ||
| # if we exceed the max number of lines permitted on the screen. | ||
| line_index = 0 | ||
| lines_consumed = 0 | ||
| while lines_consumed < MAX_LINES and line_index < len(lines): | ||
| curr_line = lines[line_index] | ||
| # Truncate logs if they're beyond 3 lines, i.e. 67 * 3 characters. | ||
| curr_line = (curr_line[:CHARS_PER_LINE * 3 - 3] + | ||
| "...") if len(curr_line) > CHARS_PER_LINE else curr_line | ||
| while curr_line and lines_consumed < MAX_LINES: | ||
| # Write out the first CHARS_PER_LINE characters, then slice it out. | ||
| line_to_write = curr_line[:CHARS_PER_LINE].strip() | ||
| draw.text((0, lines_consumed * FONT_SIZE), line_to_write, | ||
| font=font, fill=(0, 0, 0)) | ||
| curr_line = curr_line[CHARS_PER_LINE:] | ||
| lines_consumed += 1 | ||
| line_index += 1 | ||
|
|
||
| return debug_screen_img |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.