-
Notifications
You must be signed in to change notification settings - Fork 68
Console Widget: Add PythonSyntaxHighlighter #1651
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: develop
Are you sure you want to change the base?
Console Widget: Add PythonSyntaxHighlighter #1651
Conversation
|
note: the github-dark" style in pygments doesn't seem to exactly match.
|
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.
I quite like it!
But I do feel the darker background color feels off for AYON.
I actually think from your screenshots Github dark without background and Monokai without background are pretty good candidates for a default. @iLLiCiTiT @mkolar thoughts?
I personally like Monokai, but I can see reasons to go for the Github dark one since it may be more popular. Either is fine for me.
Especially nice to give this console some more polish since we're now looking to embed it with a few integrations (e.g. After Effects just got it - based on client request)
All we need next is some good autocomplete and tooltips over functions and it's pretty darn nice.
| if not self.style: | ||
| all_styles = ", ".join(pygments.styles.get_all_styles()) | ||
| msg = f"'{style_name}' not found. Installed styles: {all_styles}" | ||
| raise ValueError(msg) |
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.
Just for the edge cases - I wonder if this should just log a warning or error and continue without any styling?
Not sure why, but the "github-dark" style shiped with pygments uses "Red" for the "Namespace" Tokens. ran a quick test to confirm: imports are tokenized as "Namespace" from pygments.lexers import PythonLexer
lexer = PythonLexer()
for token, value in lexer.get_tokens("import os"):
print(token, value)I guess the best way to fix this would be to provide a custom "AYON" Theme based on this: #1651 (comment) |
… apply no background color Also remove walrus operator for backwards compatibility
|
@iLLiCiTiT can you review? |
|
Where is It should be added to pyproject.toml in client directory. All code that is using |
I just saw its part of the dependency package, so I figured it would be safe to use it :D I will add it to the pyproject.toml. edit: and, but not sure how relevant this is for the client side: it is also part of the backend-dependency stack |
…rove Error handling for invalid style names
| try: | ||
| highlighter = PythonSyntaxHighlighter(self.document()) | ||
| except ValueError as e: | ||
| print(f"Error applying syntax highlighter: {e!s}") |
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.




Changelog Description
adds a syntax highlighting to the Console Widget
Additional info
as for the theme I went with "github-dark" as I figured this might be one of the most common ones used/seen,
but since its a mater of personal preference I added an option to customise it.
background color:
I'm not sure if setting the background color is a good idea.
technically we should as otherwise some styles dont work. for example a light style is very hard to read on the default dark background,
but it also breaks the overall look of the widget.
but then... who even uses light themes anyways? :D
Github Dark

Github Dark (without background)

Monokai:

Monokai (wihtout background)

staroffice (with and without)
