-
Notifications
You must be signed in to change notification settings - Fork 12
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
Update theme/style sheet handling to enable napari-console to use napari font_size
setting
#33
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #33 +/- ##
==========================================
+ Coverage 96.69% 96.77% +0.07%
==========================================
Files 4 4
Lines 121 124 +3
==========================================
+ Hits 117 120 +3
Misses 4 4 ☔ View full report in Codecov by Sentry. |
font_size
settingfont_size
setting
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.
This is not correct approach. You either need to disconnect _update_theme
from self.viewer.events.theme
event or update _update_theme
to read font size from settings
I just installed this PR and I do not see any changes when update theme or font size. I do not see connection to any proper signal in the code |
Did you check this alongside napari/napari#6753 @Czaki ? I checked again and works for me on Windows 🤔 (although as mentioned I see a deprecation warning related with the Anyhow, maybe the work over napari/napari#6753 and here is not the correct approach and these PRs should be closed? |
@Czaki do you want to have another look at this after Daniel's last comment? Should this PR be closed or is it the right approach? |
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.
Looks ok.
Minor change to not require napari import if styleshhet is provided.
napari_console/qt_console.py
Outdated
from napari.qt import get_stylesheet | ||
from napari.utils.theme import get_theme, template | ||
|
||
# qtconsole unfortunately won't inherit the parent stylesheet | ||
# so it needs to be directly set | ||
raw_stylesheet = get_stylesheet() | ||
# template and apply the primary stylesheet | ||
# (should probably be done by napari) | ||
# After napari 0.4.11, themes are evented models rather than | ||
# dicts. | ||
# After napari 0.5.0 the `as_dict` kwarg has been deprecated | ||
# and will be removed in a future version. | ||
theme = get_theme(self.viewer.theme, as_dict=True) | ||
self.style_sheet = template(raw_stylesheet, **theme) | ||
|
||
# After napari 0.4.6 the following syntax will be allowed | ||
# self.style_sheet = get_stylesheet(self.viewer.theme) | ||
# In the future, with napari 0.5.0+, the following syntax will be allowed | ||
# theme = get_theme(self.viewer.theme).to_rgb_dict() | ||
|
||
# qtconsole unfortunately won't inherit the parent stylesheet | ||
# so it needs to be directly set when required. | ||
if style_sheet: | ||
# napari 0.5.x uses the `style_sheet` kwarg | ||
self.style_sheet = style_sheet | ||
else: | ||
# napari 0.4.x doesn't use the `style_sheet` kwarg | ||
raw_stylesheet = get_stylesheet() | ||
# template and apply the primary stylesheet | ||
# (should probably be done by napari) | ||
# After napari 0.4.11, themes are evented models rather than | ||
# dicts. | ||
self.style_sheet = template(raw_stylesheet, **theme) | ||
|
||
# After napari 0.4.6 the following syntax will be allowed | ||
# self.style_sheet = get_stylesheet(self.viewer.theme) |
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.
The imports and get_theme
call should move int else clause.
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.
Thanks for rechecking this! Latests commits should change the imports placement. Also noticed that still there was a need to connect to the viewer theme events when no style sheet is being passed (napari <0.5.5/without the changes done over napari/napari#6753). Re-added that event connection logic in case no style sheet is detected over the constructor.
Let me know if there is something else that needs to be done here!
…nnect to theme event if no stylesheet is passed on initialization
…anching to handle theme retrieval
Amazing! Thanks both! |
# References and relevant issues See napari/napari-console#32 and napari/napari-console#33 # Description Enable `napari-console` to react to the changes over the font size setting from napari. This needs some changes over `napari-console` too. See napari/napari-console#33 A preview: ![console_font_size](https://github.com/napari/napari/assets/16781833/1e7a328e-d333-4fd6-8834-835fa441df26) --------- Co-authored-by: Grzegorz Bokota <[email protected]>
References and relevant issues
Closes #32
Description
Depends on/related to napari/napari#6753
A preview:
Notes
as_dict
kwarg from theget_theme
function). Added a note about that here.style_sheet
kwarg added to the_update_theme
method defines if the previous logic needs to be used (napari 0.5.0 will use the newstyle_sheet
kwarg, see Usefont_size
setting to controlnapari-console
font-size napari#6753)