Skip to content
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

feat: Improve CodeSyntaxHighlight object #268

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tlambert03
Copy link
Member

This PR improves a number of things and fixes some slight issues with CodeSyntaxHighlight:

  • adds full type hinting, including KnownStyle for IDE suggestions of valid pygments names
  • prevents Formatter from overriding all font selections on the parent object. I tried to apply fonts and found that get_text_char_format was always clobbering whatever I did. Furthermore, it wasn't successfully applying "Monospace", instead I get: WARNING: Populating font family aliases took 75 ms. Replace uses of missing font family "Monospace" with one that exists to avoid this cost.. So this adds a full font family tree that should work on any system, and it only applies it if the style explicitly sets the "mono" flag. This means that most users will now need to set Monospace themselves (but since it already wasn't working on, macos for example, this is probably a good thing).
  • allows the user to pass in any QObject that supports document(), simplifying the usage, and also allowing allowing us to automatically set the background color on objects that support setPalette.
  • adds setTheme and setLanguage methods that allow you to change the style on an existing formatter, including updating the background color on supported objects.
  • adds lots of docstrings to explain what's going on

@tlambert03 tlambert03 requested a review from Czaki December 23, 2024 17:14
Copy link

codecov bot commented Dec 23, 2024

Codecov Report

Attention: Patch coverage is 96.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 87.01%. Comparing base (4da5ac2) to head (3893947).

Files with missing lines Patch % Lines
src/superqt/utils/_code_syntax_highlight.py 96.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #268      +/-   ##
==========================================
- Coverage   87.12%   87.01%   -0.12%     
==========================================
  Files          46       46              
  Lines        3441     3465      +24     
==========================================
+ Hits         2998     3015      +17     
- Misses        443      450       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tlambert03
Copy link
Member Author

I assume the two failing napari tests are unrelated, but @Czaki could you confirm?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant