Skip to content

Commit

Permalink
DarkDetails: Manage color for the DataFrameEditor and FigureViewer
Browse files Browse the repository at this point in the history
  • Loading branch information
dalthviz committed Nov 6, 2018
1 parent 4bb8ebb commit 38cae91
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
27 changes: 26 additions & 1 deletion spyder/plugins/plots/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,36 @@

# Local imports
from spyder.config.base import _
from spyder.config.main import CONF
from spyder.config.gui import is_dark_font_color
from spyder.api.plugins import SpyderPluginWidget
from spyder.api.preferences import PluginConfigPage
from spyder.utils import icon_manager as ima
from spyder.plugins.plots.widgets.figurebrowser import FigureBrowser


def get_background_color():
"""
Get background color for the plots plugin based on the color theme
and color scheme currently selected.
"""
ui_theme = CONF.get('color_schemes', 'ui_theme')
color_scheme = CONF.get('color_schemes', 'selected')
if ui_theme == 'dark':
background_color = '#232629'
elif ui_theme == 'automatic':
if not is_dark_font_color(color_scheme):
background_color = '#232629'
else:
background_color = 'white'
else:
background_color = 'white'
return background_color


MAIN_BG_COLOR = get_background_color()


class PlotsConfigPage(PluginConfigPage):

def setup_page(self):
Expand Down Expand Up @@ -89,7 +113,8 @@ def add_shellwidget(self, shellwidget):
if shellwidget_id not in self.shellwidgets:
self.options_button.setVisible(True)
fig_browser = FigureBrowser(
self, options_button=self.options_button)
self, options_button=self.options_button,
background_color=MAIN_BG_COLOR)
fig_browser.set_shellwidget(shellwidget)
fig_browser.setup(**self.get_settings())
fig_browser.sig_option_changed.connect(
Expand Down
10 changes: 6 additions & 4 deletions spyder/plugins/plots/widgets/figurebrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ class FigureBrowser(QWidget):
sig_option_changed = Signal(str, object)
sig_collapse = Signal()

def __init__(self, parent, options_button=None, plugin_actions=[]):
def __init__(self, parent, options_button=None, plugin_actions=[],
background_color=None):
super(FigureBrowser, self).__init__(parent)

self.shellwidget = None
self.is_visible = True
self.figviewer = None
self.setup_in_progress = False
self.background_color = background_color

# Options :
self.mute_inline_plotting = None
Expand All @@ -101,7 +103,7 @@ def setup(self, mute_inline_plotting=None, show_plot_outline=None):
self.show_plot_outline_action.setChecked(show_plot_outline)
return

self.figviewer = FigureViewer()
self.figviewer = FigureViewer(background_color=self.background_color)
self.figviewer.setStyleSheet("FigureViewer{"
"border: 1px solid lightgrey;"
"border-top-width: 0px;"
Expand Down Expand Up @@ -311,10 +313,10 @@ class FigureViewer(QScrollArea):

sig_zoom_changed = Signal(float)

def __init__(self, parent=None):
def __init__(self, parent=None, background_color=None):
super(FigureViewer, self).__init__(parent)
self.setAlignment(Qt.AlignCenter)
self.viewport().setStyleSheet("background-color: white")
self.viewport().setStyleSheet("background-color: " + background_color)
self.setFrameStyle(0)

self._scalefactor = 0
Expand Down
4 changes: 0 additions & 4 deletions spyder/plugins/variableexplorer/widgets/dataframeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,10 +705,6 @@ def data(self, index, role):
return None
row, col = ((index.row(), index.column()) if self.axis == 0
else (index.column(), index.row()))
if role == Qt.BackgroundRole:
prev = self.model.header(self.axis, col - 1, row) if col else None
cur = self.model.header(self.axis, col, row)
return self._palette.midlight() if prev != cur else None
if role != Qt.DisplayRole:
return None
if self.axis == 0 and self._shape[0] <= 1:
Expand Down

0 comments on commit 38cae91

Please sign in to comment.