From a74fccda8d998332c437d99b131ae45143e45751 Mon Sep 17 00:00:00 2001 From: Rafael Laverde Date: Thu, 16 Mar 2017 11:20:11 -0500 Subject: [PATCH 1/3] Change default color of panels. --- spyder/api/panel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyder/api/panel.py b/spyder/api/panel.py index 1907cf1efdd..ecbde29548c 100644 --- a/spyder/api/panel.py +++ b/spyder/api/panel.py @@ -100,7 +100,7 @@ def paintEvent(self, event): if self.isVisible(): # fill background self._background_brush = QBrush(QColor( - self.palette().window().color())) + self.editor.sideareas_color)) self._foreground_pen = QPen(QColor( self.palette().windowText().color())) painter = QPainter(self) From ed0f18ac2f641568fa1d3061a1e200604539624e Mon Sep 17 00:00:00 2001 From: Rafael Laverde Date: Thu, 16 Mar 2017 11:48:20 -0500 Subject: [PATCH 2/3] Remove custom color of folding panel. - Replace native_look for native icons. - Delete unused static method get_system_bck_color. --- spyder/widgets/panels/codefolding.py | 96 ++++++++-------------------- 1 file changed, 25 insertions(+), 71 deletions(-) diff --git a/spyder/widgets/panels/codefolding.py b/spyder/widgets/panels/codefolding.py index ec8a29495ed..f3ba1764b9f 100644 --- a/spyder/widgets/panels/codefolding.py +++ b/spyder/widgets/panels/codefolding.py @@ -44,80 +44,59 @@ class FoldingPanel(Panel): expand_all_triggered = Signal() @property - def native_look(self): + def native_icons(self): """ - Defines whether the panel will use native indicator icons and color or - use custom one. + Defines whether the panel will use native indicator icons or + use custom ones. - If you want to use custom indicator icons and color, you must first + If you want to use custom indicator icons, you must first set this flag to False. """ - return self._native + return self.native_icons - @native_look.setter - def native_look(self, value): - self._native = value + @native_icons.setter + def native_icons(self, value): + self._native_icons = value # propagate changes to every clone if self.editor: for clone in self.editor.clones: try: - clone.modes.get(self.__class__).native_look = value + clone.modes.get(self.__class__).native_icons = value except KeyError: # this should never happen since we're working with clones pass @property - def custom_indicators_icons(self): + def indicators_icons(self): """ - Gets/sets the custom icon for the fold indicators. + Gets/sets the icons for the fold indicators. The list of indicators is interpreted as follow:: (COLLAPSED_OFF, COLLAPSED_ON, EXPANDED_OFF, EXPANDED_ON) - To use this property you must first set `native_look` to False. + To use this property you must first set `native_icons` to False. :returns: tuple(str, str, str, str) """ - return self._custom_indicators + return self._indicators_icons - @custom_indicators_icons.setter - def custom_indicators_icons(self, value): + @indicators_icons.setter + def indicators_icons(self, value): if len(value) != 4: raise ValueError('The list of custom indicators must contains 4 ' 'strings') - self._custom_indicators = value + self._indicators_icons = value if self.editor: # propagate changes to every clone for clone in self.editor.clones: try: clone.modes.get( - self.__class__).custom_indicators_icons = value + self.__class__).indicators_icons = value except KeyError: # this should never happen since we're working with clones pass - @property - def custom_fold_region_background(self): - """ - Custom base color for the fold region background. - - :return: QColor - """ - return self._custom_color - - @custom_fold_region_background.setter - def custom_fold_region_background(self, value): - self._custom_color = value - # propagate changes to every clone - if self.editor: - for clone in self.editor.clones: - try: - clone.modes.get( - self.__class__).custom_fold_region_background = value - except KeyError: - # this should never happen since we're working with clones - pass @property def highlight_caret_scope(self): @@ -154,14 +133,13 @@ def highlight_caret_scope(self, value): def __init__(self, highlight_caret_scope=False): Panel.__init__(self) - self._native = False - self._custom_indicators = ( + self._native_icons = False + self._indicators_icons = ( 'folding.arrow_right_off', 'folding.arrow_right_on', 'folding.arrow_down_off', 'folding.arrow_down_on' ) - self._custom_color = QColor('gray') self._block_nbr = -1 self._highlight_caret = False self.highlight_caret_scope = highlight_caret_scope @@ -259,16 +237,13 @@ def _draw_fold_region_background(self, block, painter): def _draw_rect(self, rect, painter): """ - Draw the background rectangle using the current style primitive color - or foldIndicatorBackground if nativeFoldingIndicator is true. + Draw the background rectangle using the current style primitive color. :param rect: The fold zone rect to draw :param painter: The widget's painter. """ - c = self._custom_color - if self._native: - c = self.get_system_bck_color() + c = self.editor.sideareas_color grad = QLinearGradient(rect.topLeft(), rect.topRight()) if sys.platform == 'darwin': @@ -298,27 +273,6 @@ def _draw_rect(self, rect, painter): rect.bottomLeft() - QPointF(0, 1)) - @staticmethod - def get_system_bck_color(): - """Gets a system color for drawing the fold scope background.""" - def merged_colors(colorA, colorB, factor): - maxFactor = 100 - colorA = QColor(colorA) - colorB = QColor(colorB) - tmp = colorA - tmp.setRed((tmp.red() * factor) / maxFactor + - (colorB.red() * (maxFactor - factor)) / maxFactor) - tmp.setGreen((tmp.green() * factor) / maxFactor + - (colorB.green() * (maxFactor - factor)) / maxFactor) - tmp.setBlue((tmp.blue() * factor) / maxFactor + - (colorB.blue() * (maxFactor - factor)) / maxFactor) - return tmp - - pal = QApplication.instance().palette() - b = pal.window().color() - h = pal.highlight().color() - return merged_colors(b, h, 50) - def _draw_fold_indicator(self, top, mouse_over, collapsed, painter): """ Draw the fold indicator/trigger (arrow). @@ -330,7 +284,7 @@ def _draw_fold_indicator(self, top, mouse_over, collapsed, painter): """ rect = QRect(0, top, self.sizeHint().width(), self.sizeHint().height()) - if self._native: + if self._native_icons: opt = QStyleOptionViewItem() opt.rect = rect @@ -354,7 +308,7 @@ def _draw_fold_indicator(self, top, mouse_over, collapsed, painter): index = 2 if mouse_over: index += 1 - ima.icon(self._custom_indicators[index]).paint(painter, rect) + ima.icon(self._indicators_icons[index]).paint(painter, rect) @staticmethod def find_parent_scope(block): @@ -765,8 +719,8 @@ def _highlight_caret_scope(self): self._block_nbr = block_nbr def clone_settings(self, original): - self.native_look = original.native_look - self.custom_indicators_icons = original.custom_indicators_icons + self.native_icons = original.native_icons + self.indicators_icons = original.indicators_icons self.highlight_caret_scope = original.highlight_caret_scope self.custom_fold_region_background = \ original.custom_fold_region_background From cdf27ccbfd7424146c7f4805e4c8f11d9733d005 Mon Sep 17 00:00:00 2001 From: Rafael Laverde Date: Thu, 16 Mar 2017 11:51:23 -0500 Subject: [PATCH 3/3] Delete surronding decorations and instead decorate current scope only. - Use scope_highlight_color based in sideareas_color. --- spyder/widgets/panels/codefolding.py | 103 ++++++--------------------- 1 file changed, 21 insertions(+), 82 deletions(-) diff --git a/spyder/widgets/panels/codefolding.py b/spyder/widgets/panels/codefolding.py index f3ba1764b9f..ddcb1477dd7 100644 --- a/spyder/widgets/panels/codefolding.py +++ b/spyder/widgets/panels/codefolding.py @@ -336,89 +336,29 @@ def _get_scope_highlight_color(self): """ Gets the base scope highlight color (derivated from the editor background) + + For lighter themes will be a darker color, + and for darker ones will be a lighter color """ - color = self.editor.background + color = self.editor.sideareas_color if color.lightness() < 128: color = drift_color(color, 130) else: color = drift_color(color, 105) return color - def _add_scope_deco(self, start, end, parent_start, parent_end, base_color, - factor): - """ - Adds a scope decoration that enclose the current scope. - - :param start: Start of the current scope - :param end: End of the current scope - :param parent_start: Start of the parent scope - :param parent_end: End of the parent scope - :param base_color: base color for scope decoration - :param factor: color factor to apply on the base color (to make it - darker). - """ - color = drift_color(base_color, factor=factor) - # upper part - if start > 0: - d = TextDecoration(self.editor.document(), - start_line=parent_start, end_line=start) - d.set_full_width(True, clear=False) - d.draw_order = 2 - d.set_background(color) - self.editor.decorations.append(d) - self._scope_decos.append(d) - # lower part - if end <= self.editor.document().blockCount(): - d = TextDecoration(self.editor.document(), - start_line=end, end_line=parent_end + 1) - d.set_full_width(True, clear=False) - d.draw_order = 2 - d.set_background(color) - self.editor.decorations.append(d) - self._scope_decos.append(d) - - def _add_scope_decorations(self, block, start, end): - """ - Show a scope decoration on the code editor widget. - - :param start: Start line - :param end: End line - """ - try: - parent = FoldScope(block).parent() - except ValueError: - parent = None - if TextBlockHelper.is_fold_trigger(block): - base_color = self._get_scope_highlight_color() - factor_step = 5 - if base_color.lightness() < 128: - factor_step = 10 - factor = 70 - else: - factor = 100 - while parent: - # highlight parent scope - parent_start, parent_end = parent.get_range() - self._add_scope_deco( - start, end + 1, parent_start, parent_end, - base_color, factor) - # next parent scope - start = parent_start - end = parent_end - parent = parent.parent() - factor += factor_step - # global scope - parent_start = 0 - parent_end = self.editor.document().blockCount() - self._add_scope_deco( - start, end + 1, parent_start, parent_end, base_color, - factor + factor_step) - else: - self._clear_scope_decos() + def _decorate_block(self, start, end): + color = self._get_scope_highlight_color() + d = TextDecoration(self.editor.document(), + start_line=start, end_line=end+1) + d.set_background(color) + d.set_full_width(True, clear=False) + self.editor.decorations.append(d) + self._scope_decos.append(d) - def _highlight_surrounding_scopes(self, block): + def _highlight_block(self, block): """ - Highlights the scopes surrounding the current fold scope. + Highlights the current fold scope. :param block: Block that starts the current fold scope. """ @@ -427,10 +367,10 @@ def _highlight_surrounding_scopes(self, block): self._current_scope.get_range() != scope.get_range()): self._current_scope = scope self._clear_scope_decos() - # highlight surrounding parent scopes with a darker color + # highlight current scope with darker or lighter color start, end = scope.get_range() if not TextBlockHelper.is_collapsed(block): - self._add_scope_decorations(block, start, end) + self._decorate_block(start, end) def mouseMoveEvent(self, event): """ @@ -456,12 +396,12 @@ def mouseMoveEvent(self, event): # fold scope changed, a previous block was highlighter so # we quickly update our highlighting self._mouse_over_line = block.blockNumber() - self._highlight_surrounding_scopes(block) + self._highlight_block(block) else: # same fold scope, request highlight self._mouse_over_line = block.blockNumber() self._highlight_runner.request_job( - self._highlight_surrounding_scopes, block) + self._highlight_block, block) self._highight_block = block else: # no fold scope to highlight, cancel any pending requests @@ -518,8 +458,7 @@ def toggle_fold_trigger(self, block): if region.collapsed: region.unfold() if self._mouse_over_line is not None: - self._add_scope_decorations( - region._trigger, *region.get_range()) + self._decorate_block(*region.get_range()) else: region.fold() self._clear_scope_decos() @@ -698,7 +637,7 @@ def _on_action_expand_all_triggered(self): def _highlight_caret_scope(self): """ - Highlight the scope surrounding the current caret position. + Highlight the scope of the current caret position. This get called only if :attr:` spyder.widgets.panels.FoldingPanel.highlight_care_scope` is True. @@ -715,7 +654,7 @@ def _highlight_caret_scope(self): else: self._mouse_over_line = block.blockNumber() if TextBlockHelper.is_fold_trigger(block): - self._highlight_surrounding_scopes(block) + self._highlight_block(block) self._block_nbr = block_nbr def clone_settings(self, original):