Fix dark mode

This commit is contained in:
Timmy Welch 2024-12-23 20:10:18 -08:00
parent b1c164add0
commit 4d767f026a
2 changed files with 12 additions and 2 deletions

View File

@ -60,7 +60,7 @@ from comictaggerlib.renamewindow import RenameWindow
from comictaggerlib.resulttypes import OnlineMatchResults
from comictaggerlib.seriesselectionwindow import SeriesSelectionWindow
from comictaggerlib.settingswindow import SettingsWindow
from comictaggerlib.ui import ui_path
from comictaggerlib.ui import qtutils, ui_path
from comictaggerlib.ui.pyqttoast import Toast, ToastPreset
from comictaggerlib.ui.qtutils import center_window_on_parent, enable_widget
from comictaggerlib.versionchecker import VersionChecker
@ -1158,7 +1158,10 @@ class TaggerWindow(QtWidgets.QMainWindow):
toast.setText(
f"Rate limit reached: {full_time:.0f}s until next request. Waiting {sleep_time:.0f}s for ratelimit"
)
toast.applyPreset(ToastPreset.WARNING)
if qtutils.is_dark_mode():
toast.applyPreset(ToastPreset.WARNING_DARK)
else:
toast.applyPreset(ToastPreset.WARNING)
toast.setPositionRelativeToWidget(self)
toast.show()

View File

@ -9,6 +9,7 @@ import webbrowser
from collections.abc import Sequence
from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QPalette
from PyQt5.QtWidgets import QWidget
logger = logging.getLogger(__name__)
@ -122,6 +123,12 @@ if qt_available:
# And the move call repositions the window
window.move(hpos + main_window_size.left(), vpos + main_window_size.top())
def is_dark_mode() -> bool:
palette = QPalette()
text = palette.color(QPalette.WindowText)
window = palette.color(QPalette.Window)
return text.lightness() > window.lightness()
def get_qimage_from_data(image_data: bytes) -> QtGui.QImage:
img = QtGui.QImage()
success = img.loadFromData(image_data)