Skip to content

Conversation

@stbenjam
Copy link
Contributor

@stbenjam stbenjam commented Apr 18, 2022

Extracted and improved my coloring code from #23.

This introduces a default bg and fg color setting exposed to the user. It
also allows specifying an HTML color as well as the existing hard coded
shades for any reader that wants to.

When an annotation highlight is an HTML color, it's lightness is calculated
and then either black or white is chosen to allow readability.

Video: https://www.youtube.com/watch?v=TVRstBtsMl8

I still need to update docs, but it requires new screenshots. I do not
have access to a mac, for consistency, would you like to take the
screen shot? Or are you OK with showing it from Linux?

annotations.py Outdated
Comment on lines 204 to 211
# Currently, annotations only store the foreground color. If it's not a known color, then
# we should pick the background color as black or white based on the overall lightness of
# the color.
color = QColor(dt_bgcolor)
if color.lightness() > 128:
dt_fgcolor = "#000000"
else:
dt_fgcolor = "#FFFFFF"
Copy link
Contributor Author

@stbenjam stbenjam Apr 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of how this works:

image

As you can see, white gets a black foreground. The others get white.

@stbenjam stbenjam mentioned this pull request Apr 18, 2022
2 tasks
This introduces a default bg and fg color setting, and also allows
specifying an HTML color as well as the existing hard coded shades.
@aik099
Copy link
Contributor

aik099 commented Apr 19, 2022

Actually, I like that. But I'm not 100% sure if we should allow selecting custom foreground color since we have a nice auto-detection code now.


@stbenjam , you'd better also post a link to every PR you create to the https://www.mobileread.com/forums/showthread.php?t=241206 as well, because @davidfor isn't getting notifications from the GitHub.

Comment on lines +25 to +28
try:
from PyQt5.QtGui import QColor
except ImportError:
from PyQt4.QtGui import QColor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this support for different Python versions used by Calibre now or in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, this is how all Qt dependencies are imported in this plugin, not just here.


COLOR_MAP = {
'Blue': {'bg': '#b1ccf3', 'fg': 'black'},
'Default': {'bg': 'transparent', 'fg': 'black'},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this removed entry isn't used anywhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Comment on lines -191 to -194
if agroup.highlightcolor is None:
msg = "No highlight color specified, using Default"
else:
msg = "Unknown color '%s' specified" % agroup.highlightcolor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the case with if agroup.highlightcolor is None: is still possible, then we should keep the original logging code (the one being highlighted here) instead of new msg = "Unknown color '%s' specified, using default" % agroup.highlightcolor code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure I added the specific None case back

@stbenjam
Copy link
Contributor Author

Actually, I like that. But I'm not 100% sure if we should allow selecting custom foreground color since we have a nice auto-detection code now.

The calculated foreground is only white or black, I think I'd rather give the user an option in case for whatever reason they want burgundy on yellow.

@stbenjam stbenjam closed this May 15, 2022
@stbenjam stbenjam deleted the colors branch May 15, 2022 21:05
@aik099
Copy link
Contributor

aik099 commented May 16, 2022

@stbenjam , I completely understand you. Please be patient. We're not in a hurry here with @davidfor being very occupied with other projects and not being able to timely review any PR coming in.

I'm glad, that you're able to implement a Moon+ Reader integration, that works for you. Please don't let it disappear and not make any other Moon+ Reader + Calibre user happy.

It will be reviewed eventually I guess.

@stbenjam stbenjam restored the colors branch June 19, 2022 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants