From 306c67a09c9824041d5549585b08bd164d844231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Gosselin?= Date: Tue, 25 Jul 2017 15:08:54 -0400 Subject: [PATCH 01/10] IPython console text highlighting settings - text highlight now use the same color as Spyder main application instead of using the light gray color that was hard-coded. - `matched-bracket` highlight is now set to the color defined in Spyder preferences instead of using the hard coded light gray color. --- spyder/utils/ipython/style.py | 2 -- spyder/widgets/ipythonconsole/shell.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/spyder/utils/ipython/style.py b/spyder/utils/ipython/style.py index 03558be28b9..5b180464b14 100644 --- a/spyder/utils/ipython/style.py +++ b/spyder/utils/ipython/style.py @@ -59,7 +59,6 @@ def give_font_style(is_italic): sheet = """QPlainTextEdit, QTextEdit, ControlWidget {{ color: {} ; background-color: {}; - selection-background-color: {} }} .error {{ color: {}; }} .in-prompt {{ color: {}; }} @@ -70,7 +69,6 @@ def give_font_style(is_italic): """ sheet_formatted = sheet.format(font_color, background_color, - selection_background_color, error_color, in_prompt_color, in_prompt_color, in_prompt_number_font_weight, diff --git a/spyder/widgets/ipythonconsole/shell.py b/spyder/widgets/ipythonconsole/shell.py index bed2d395b6f..c6eb3ebf4ec 100644 --- a/spyder/widgets/ipythonconsole/shell.py +++ b/spyder/widgets/ipythonconsole/shell.py @@ -12,11 +12,13 @@ import uuid from qtpy.QtCore import Signal +from qtpy.QtGui import QColor from qtpy.QtWidgets import QMessageBox from spyder.config.base import _ from spyder.config.gui import config_shortcut from spyder.py3compat import to_text_string from spyder.utils import programs +from spyder.utils import syntaxhighlighters as sh from spyder.utils.ipython.style import create_qss_style, create_style_class from spyder.widgets.ipythonconsole import (ControlWidget, DebuggingWidget, HelpWidget, NamepaceBrowserWidget, @@ -70,6 +72,9 @@ def __init__(self, ipyclient, additional_options, interpreter_versions, # To save kernel replies in silent execution self._kernel_reply = None + color_scheme = kw['config']['JupyterWidget']['syntax_style'] + self.set_bracket_matcher_color_scheme(color_scheme) + #---- Public API ---------------------------------------------------------- def set_exit_callback(self): """Set exit callback for this shell.""" @@ -110,9 +115,15 @@ def get_cwd(self): return else: self.silent_exec_method(code) + + def set_bracket_matcher_color_scheme(self, color_scheme): + bsh = sh.BaseSH(parent=self, color_scheme=color_scheme) + mpcolor = bsh.get_matched_p_color() + self._bracket_matcher.format.setBackground(mpcolor) def set_color_scheme(self, color_scheme): """Set color scheme of the shell.""" + self.set_bracket_matcher_color_scheme(color_scheme) self.style_sheet, dark_color = create_qss_style(color_scheme) self.syntax_style = color_scheme self._style_sheet_changed() From 1c591085aec34bc43fcbe1ea1c76f77da48ac13d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Gosselin?= Date: Tue, 25 Jul 2017 15:31:26 -0400 Subject: [PATCH 02/10] removed unused import --- spyder/widgets/ipythonconsole/shell.py | 1 - 1 file changed, 1 deletion(-) diff --git a/spyder/widgets/ipythonconsole/shell.py b/spyder/widgets/ipythonconsole/shell.py index c6eb3ebf4ec..0dbcced8fff 100644 --- a/spyder/widgets/ipythonconsole/shell.py +++ b/spyder/widgets/ipythonconsole/shell.py @@ -12,7 +12,6 @@ import uuid from qtpy.QtCore import Signal -from qtpy.QtGui import QColor from qtpy.QtWidgets import QMessageBox from spyder.config.base import _ from spyder.config.gui import config_shortcut From 8b17e37592f4a3343054ee6314ed260289febb79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Gosselin?= Date: Tue, 25 Jul 2017 16:13:13 -0400 Subject: [PATCH 03/10] Removed unused variable --- spyder/utils/ipython/style.py | 1 - 1 file changed, 1 deletion(-) diff --git a/spyder/utils/ipython/style.py b/spyder/utils/ipython/style.py index 5b180464b14..d2560ab14b8 100644 --- a/spyder/utils/ipython/style.py +++ b/spyder/utils/ipython/style.py @@ -49,7 +49,6 @@ def give_font_style(is_italic): in_prompt_color = 'lime' out_prompt_color = 'red' background_color = color_scheme['background'] - selection_background_color = '#ccc' error_color = 'red' in_prompt_number_font_weight = 'bold' out_prompt_number_font_weight = 'bold' From 6b8a894c3c8c61927dbda82a16d415bece5f7476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Gosselin?= Date: Wed, 26 Jul 2017 09:42:16 -0400 Subject: [PATCH 04/10] Added comments and simplified the code --- spyder/widgets/ipythonconsole/shell.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spyder/widgets/ipythonconsole/shell.py b/spyder/widgets/ipythonconsole/shell.py index 0dbcced8fff..1d022f042c4 100644 --- a/spyder/widgets/ipythonconsole/shell.py +++ b/spyder/widgets/ipythonconsole/shell.py @@ -71,8 +71,8 @@ def __init__(self, ipyclient, additional_options, interpreter_versions, # To save kernel replies in silent execution self._kernel_reply = None - color_scheme = kw['config']['JupyterWidget']['syntax_style'] - self.set_bracket_matcher_color_scheme(color_scheme) + # To set the color of the matched parentheses + self.set_bracket_matcher_color_scheme(self.syntax_style) #---- Public API ---------------------------------------------------------- def set_exit_callback(self): @@ -116,6 +116,7 @@ def get_cwd(self): self.silent_exec_method(code) def set_bracket_matcher_color_scheme(self, color_scheme): + """Set color scheme for matched parentheses.""" bsh = sh.BaseSH(parent=self, color_scheme=color_scheme) mpcolor = bsh.get_matched_p_color() self._bracket_matcher.format.setBackground(mpcolor) From d611287e7b2ba314e43bf6e2777fcdc9533b0cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Gosselin?= Date: Wed, 26 Jul 2017 21:07:44 -0400 Subject: [PATCH 05/10] Changed a comment to make it more descriptive --- spyder/widgets/ipythonconsole/shell.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spyder/widgets/ipythonconsole/shell.py b/spyder/widgets/ipythonconsole/shell.py index 1d022f042c4..619697e8f64 100644 --- a/spyder/widgets/ipythonconsole/shell.py +++ b/spyder/widgets/ipythonconsole/shell.py @@ -71,7 +71,9 @@ def __init__(self, ipyclient, additional_options, interpreter_versions, # To save kernel replies in silent execution self._kernel_reply = None - # To set the color of the matched parentheses + # Set the color of the matched parentheses here since the qtconsole + # uses a hard-coded value that is not modified when the color scheme is + # set in the qtconsole constructor. See issue #4806. self.set_bracket_matcher_color_scheme(self.syntax_style) #---- Public API ---------------------------------------------------------- From c14007e3256091f6148025235d043a0ba6a6b19d Mon Sep 17 00:00:00 2001 From: dalthviz Date: Thu, 27 Jul 2017 12:58:30 -0500 Subject: [PATCH 06/10] Changes addEnabledOption for setOption when printing selected text. --- spyder/plugins/editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyder/plugins/editor.py b/spyder/plugins/editor.py index bdb20255c20..943e6ebbc06 100644 --- a/spyder/plugins/editor.py +++ b/spyder/plugins/editor.py @@ -1929,7 +1929,7 @@ def print_file(self): header_font=self.get_plugin_font('printer_header')) printDialog = QPrintDialog(printer, editor) if editor.has_selected_text(): - printDialog.addEnabledOption(QAbstractPrintDialog.PrintSelection) + printDialog.setOption(QAbstractPrintDialog.PrintSelection, True) self.redirect_stdio.emit(False) answer = printDialog.exec_() self.redirect_stdio.emit(True) From 2c96d63b98c55b4db6dc83c6d34ae0857745079c Mon Sep 17 00:00:00 2001 From: dalthviz Date: Thu, 27 Jul 2017 15:41:11 -0500 Subject: [PATCH 07/10] Adds a test. --- spyder/app/tests/test_mainwindow.py | 34 ++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index 38571f44cd5..4fa5e2a388f 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -21,7 +21,8 @@ from qtpy import PYQT5, PYQT_VERSION from qtpy.QtCore import Qt, QTimer from qtpy.QtTest import QTest -from qtpy.QtWidgets import QApplication, QFileDialog, QLineEdit +from qtpy.QtWidgets import (QApplication, QFileDialog, QLineEdit, + QPrintDialog, QAbstractPrintDialog) from spyder.app.cli_options import get_options from spyder.app.mainwindow import initialize, run_spyder @@ -72,6 +73,15 @@ def open_file_in_editor(main_window, fname, directory=None): QTest.keyClick(w, Qt.Key_Enter) +def print_file(main_window, selection_option=False): + """Check if the print dialog has the correct option""" + top_level_widgets = QApplication.topLevelWidgets() + for w in top_level_widgets: + if isinstance(w, QPrintDialog): + assert selection_option == w.testOption(QAbstractPrintDialog.PrintSelection) + QTest.keyClick(w, Qt.Key_Escape) + + def reset_run_code(qtbot, shell, code_editor, nsb): """Reset state after a run code test""" with qtbot.waitSignal(shell.executed): @@ -165,6 +175,28 @@ def test_calltip(main_window, qtbot): main_window.editor.close_file() +@flaky(max_runs=3) +def test_print_selected_section(main_window, qtbot, tmpdir): + """Test print funtionality for selected section.""" + # ---- Load test file ---- + test_file = osp.join(LOCATION, 'script.py') + editor = main_window.editor + editor.load(test_file) + code_editor = editor.get_focus_widget() + + # --- Test without selecting text --- + # Set a timer to manipulate the print dialog while it's running + QTimer.singleShot(2000, lambda: print_file(main_window)) + + # --- Test selecting text -- + # Select all the text + code_editor.selectAll() + editor.print_file() + + # Set a timer to manipulate the print dialog while it's running + QTimer.singleShot(2000, lambda: print_file(main_window, selection_option=True)) + + @flaky(max_runs=3) def test_runconfig_workdir(main_window, qtbot, tmpdir): """Test runconfig workdir options.""" From d6869f890ff690e214a7bfb84de6b9622a1df8f2 Mon Sep 17 00:00:00 2001 From: dalthviz Date: Thu, 27 Jul 2017 15:50:17 -0500 Subject: [PATCH 08/10] Fix imports. --- spyder/app/tests/test_mainwindow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index 4fa5e2a388f..172e27494b0 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -20,9 +20,9 @@ import pytest from qtpy import PYQT5, PYQT_VERSION from qtpy.QtCore import Qt, QTimer +from qtpy.QtPrintSupport import QAbstractPrintDialog, QPrintDialog from qtpy.QtTest import QTest -from qtpy.QtWidgets import (QApplication, QFileDialog, QLineEdit, - QPrintDialog, QAbstractPrintDialog) +from qtpy.QtWidgets import QApplication, QFileDialog, QLineEdit from spyder.app.cli_options import get_options from spyder.app.mainwindow import initialize, run_spyder From 3bf9b27aa28f5956803444bce4db7074e65950f7 Mon Sep 17 00:00:00 2001 From: dalthviz Date: Thu, 27 Jul 2017 18:12:52 -0500 Subject: [PATCH 09/10] Fixes in the test. --- spyder/app/tests/test_mainwindow.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index 172e27494b0..36471ac520d 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -73,12 +73,12 @@ def open_file_in_editor(main_window, fname, directory=None): QTest.keyClick(w, Qt.Key_Enter) -def print_file(main_window, selection_option=False): +def print_file(main_window, result, selection_option=False): """Check if the print dialog has the correct option""" top_level_widgets = QApplication.topLevelWidgets() for w in top_level_widgets: if isinstance(w, QPrintDialog): - assert selection_option == w.testOption(QAbstractPrintDialog.PrintSelection) + result.append(selection_option == w.testOption(QAbstractPrintDialog.PrintSelection)) QTest.keyClick(w, Qt.Key_Escape) @@ -176,8 +176,10 @@ def test_calltip(main_window, qtbot): @flaky(max_runs=3) -def test_print_selected_section(main_window, qtbot, tmpdir): - """Test print funtionality for selected section.""" +@pytest.mark.skipif(os.name == 'nt', + reason="QtWarningMsg: QPrintDialog: Cannot be used on non-native printer") +def test_print_file(main_window, qtbot, tmpdir): + """Test print funtionality.""" # ---- Load test file ---- test_file = osp.join(LOCATION, 'script.py') editor = main_window.editor @@ -186,15 +188,18 @@ def test_print_selected_section(main_window, qtbot, tmpdir): # --- Test without selecting text --- # Set a timer to manipulate the print dialog while it's running - QTimer.singleShot(2000, lambda: print_file(main_window)) + result = [] + QTimer.singleShot(2000, lambda: print_file(main_window, result)) + editor.print_file() + assert True in result # --- Test selecting text -- - # Select all the text + # Select all the text and set a timer to manipulate the print dialog while it's running + result = [] code_editor.selectAll() + QTimer.singleShot(2000, lambda: print_file(main_window, result, selection_option=True)) editor.print_file() - - # Set a timer to manipulate the print dialog while it's running - QTimer.singleShot(2000, lambda: print_file(main_window, selection_option=True)) + assert True in result @flaky(max_runs=3) From 0bf80280cab54eb7b4afd13508eead8847a68f18 Mon Sep 17 00:00:00 2001 From: dalthviz Date: Thu, 27 Jul 2017 22:51:42 -0500 Subject: [PATCH 10/10] Deletes print test. --- spyder/app/tests/test_mainwindow.py | 37 ----------------------------- 1 file changed, 37 deletions(-) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index 36471ac520d..38571f44cd5 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -20,7 +20,6 @@ import pytest from qtpy import PYQT5, PYQT_VERSION from qtpy.QtCore import Qt, QTimer -from qtpy.QtPrintSupport import QAbstractPrintDialog, QPrintDialog from qtpy.QtTest import QTest from qtpy.QtWidgets import QApplication, QFileDialog, QLineEdit @@ -73,15 +72,6 @@ def open_file_in_editor(main_window, fname, directory=None): QTest.keyClick(w, Qt.Key_Enter) -def print_file(main_window, result, selection_option=False): - """Check if the print dialog has the correct option""" - top_level_widgets = QApplication.topLevelWidgets() - for w in top_level_widgets: - if isinstance(w, QPrintDialog): - result.append(selection_option == w.testOption(QAbstractPrintDialog.PrintSelection)) - QTest.keyClick(w, Qt.Key_Escape) - - def reset_run_code(qtbot, shell, code_editor, nsb): """Reset state after a run code test""" with qtbot.waitSignal(shell.executed): @@ -175,33 +165,6 @@ def test_calltip(main_window, qtbot): main_window.editor.close_file() -@flaky(max_runs=3) -@pytest.mark.skipif(os.name == 'nt', - reason="QtWarningMsg: QPrintDialog: Cannot be used on non-native printer") -def test_print_file(main_window, qtbot, tmpdir): - """Test print funtionality.""" - # ---- Load test file ---- - test_file = osp.join(LOCATION, 'script.py') - editor = main_window.editor - editor.load(test_file) - code_editor = editor.get_focus_widget() - - # --- Test without selecting text --- - # Set a timer to manipulate the print dialog while it's running - result = [] - QTimer.singleShot(2000, lambda: print_file(main_window, result)) - editor.print_file() - assert True in result - - # --- Test selecting text -- - # Select all the text and set a timer to manipulate the print dialog while it's running - result = [] - code_editor.selectAll() - QTimer.singleShot(2000, lambda: print_file(main_window, result, selection_option=True)) - editor.print_file() - assert True in result - - @flaky(max_runs=3) def test_runconfig_workdir(main_window, qtbot, tmpdir): """Test runconfig workdir options."""