Skip to content

Commit

Permalink
__main__: Implement basic darkmode provisions (#5526)
Browse files Browse the repository at this point in the history
* __main__: Add darkMode property to QApplication

* __main__: Set pyqtgraph colors from QPalette

* owpalette: Remove pyqtgraph colors set on global import

* pylint
  • Loading branch information
irgolic authored Aug 6, 2021
1 parent 376530d commit c326cea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 18 additions & 1 deletion Orange/canvas/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def send_statistics(url):
r = requests.post(url, files={'file': json.dumps(data)})
if r.status_code != 200:
log.warning("Error communicating with server while attempting to send "
"usage statistics. Status code " + str(r.status_code))
"usage statistics. Status code %d", r.status_code)
return
# success - wipe statistics file
log.info("Usage statistics sent.")
Expand Down Expand Up @@ -457,6 +457,20 @@ def main(argv=None):
app.setPalette(breeze_dark())
defaultstylesheet = "darkorange.qss"

# set pyqtgraph colors
def onPaletteChange():
p = app.palette()
bg = p.base().color().name()
fg = p.windowText().color().name()

log.info('Setting pyqtgraph background to %s', bg)
pyqtgraph.setConfigOption('background', bg)
log.info('Setting pyqtgraph foreground to %s', fg)
pyqtgraph.setConfigOption('foreground', fg)

app.paletteChanged.connect(onPaletteChange)
onPaletteChange()

palette = app.palette()
if style is None and palette.color(QPalette.Window).value() < 127:
log.info("Switching default stylesheet to darkorange")
Expand Down Expand Up @@ -560,6 +574,9 @@ def onrequest(url):

stylesheet_string = pattern.sub("", stylesheet_string)

if 'dark' in stylesheet:
app.setProperty('darkMode', True)

else:
log.info("%r style sheet not found.", stylesheet)

Expand Down
2 changes: 0 additions & 2 deletions Orange/widgets/utils/plot/owpalette.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
__all__ = ["create_palette", "OWPalette"]


pg.setConfigOption('background', 'w')
pg.setConfigOption('foreground', 'k')
pg.setConfigOptions(antialias=True)


Expand Down

0 comments on commit c326cea

Please sign in to comment.