Commits

Yuya Nishihara committed 5457c07

qtlib: extract utility function to test if dark theme (refs #810)

Comments (0)

Files changed (1)

tortoisehg/hgqt/qtlib.py

         InfoMsgBox(_('No shell configured'),
                    _('A terminal shell must be configured'))
 
+
+def isdarktheme(palette=None):
+    """True if white-on-black color scheme is preferable"""
+    if not palette:
+        palette = QApplication.palette()
+    return palette.color(QPalette.Base).black() >= 0x80
+
 # _styles maps from ui labels to effects
 # _effects maps an effect to font style properties.  We define a limited
 # set of _effects, since we convert color effect names to font style
     def __init__(self, targetwidget):
         self._targetwref = weakref.ref(targetwidget)  # avoid circular ref
         self._defaultpalette = targetwidget.palette()
-        bgcolor = self._defaultpalette.color(QPalette.Base)
-        if bgcolor.black() <= 128:
-            # Light theme
+        if not isdarktheme(self._defaultpalette):
             filterbgcolor = QColor('#FFFFB7')
         else:
-            # Dark theme
             filterbgcolor = QColor('darkgrey')
         self._filterpalette = QPalette()
         self._filterpalette.setColor(QPalette.Base, filterbgcolor)