Skip to content

Commit 1c8c168

Browse files
authored
Merge pull request #4541 from ccordoba12/pyconsole-3
PR: Remove connection between the Editor and the Python console
2 parents 4d8528c + f61950f commit 1c8c168

File tree

6 files changed

+33
-115
lines changed

6 files changed

+33
-115
lines changed

Diff for: spyder/app/mainwindow.py

+8-37
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@
143143
from spyder.config.utils import IMPORT_EXT, is_gtk_desktop
144144
from spyder.app.cli_options import get_options
145145
from spyder import dependencies
146-
from spyder.config.ipython import QTCONSOLE_INSTALLED
147146
from spyder.py3compat import (getcwd, is_text_string, to_text_string,
148147
PY3, qbytearray_to_str, configparser as cp)
149148
from spyder.utils import encoding, programs
@@ -477,11 +476,6 @@ def signal_handler(signum, frame=None):
477476
# the window is in fullscreen mode:
478477
self.maximized_flag = None
479478

480-
# Track which console plugin type had last focus
481-
# True: Console plugin
482-
# False: IPython console plugin
483-
self.last_console_plugin_focus_was_python = True
484-
485479
# To keep track of the last focused widget
486480
self.last_focused_widget = None
487481
self.previous_focused_widget = None
@@ -882,11 +876,10 @@ def create_edit_action(text, tr_text, icon):
882876
self.variableexplorer.register_plugin()
883877

884878
# IPython console
885-
if QTCONSOLE_INSTALLED:
886-
self.set_splash(_("Loading IPython console..."))
887-
from spyder.plugins.ipythonconsole import IPythonConsole
888-
self.ipyconsole = IPythonConsole(self)
889-
self.ipyconsole.register_plugin()
879+
self.set_splash(_("Loading IPython console..."))
880+
from spyder.plugins.ipythonconsole import IPythonConsole
881+
self.ipyconsole = IPythonConsole(self)
882+
self.ipyconsole.register_plugin()
890883

891884
self.set_splash(_("Setting up main window..."))
892885

@@ -975,7 +968,7 @@ def trigger(i=i, self=self): # closure needed!
975968
programs.start_file(get_python_doc_path()))
976969
self.help_menu_actions.append(pydoc_act)
977970
# IPython documentation
978-
if self.ipyconsole is not None and self.help is not None:
971+
if self.help is not None:
979972
ipython_menu = QMenu(_("IPython documentation"), self)
980973
intro_action = create_action(self, _("Intro to IPython"),
981974
triggered=self.ipyconsole.show_intro)
@@ -1217,16 +1210,9 @@ def post_visible_setup(self):
12171210
self.console.dockwidget.hide()
12181211

12191212
# Show Help and Consoles by default
1220-
plugins_to_show = []
1213+
plugins_to_show = [self.ipyconsole]
12211214
if self.help is not None:
12221215
plugins_to_show.append(self.help)
1223-
if self.ipyconsole is not None:
1224-
if self.ipyconsole.isvisible:
1225-
plugins_to_show += [self.extconsole, self.ipyconsole]
1226-
else:
1227-
plugins_to_show += [self.ipyconsole, self.extconsole]
1228-
else:
1229-
plugins_to_show += [self.extconsole]
12301216
for plugin in plugins_to_show:
12311217
if plugin.dockwidget.isVisible():
12321218
plugin.dockwidget.raise_()
@@ -1236,8 +1222,7 @@ def post_visible_setup(self):
12361222
self.extconsole.toggle_view_action.setChecked(False)
12371223

12381224
# Show history file if no console is visible
1239-
ipy_visible = self.ipyconsole is not None and self.ipyconsole.isvisible
1240-
if not self.extconsole.isvisible and not ipy_visible:
1225+
if not self.ipyconsole.isvisible:
12411226
self.historylog.add_history(get_conf_path('history.py'))
12421227

12431228
if self.open_project:
@@ -1945,16 +1930,6 @@ def plugin_focus_changed(self):
19451930
self.update_edit_menu()
19461931
self.update_search_menu()
19471932

1948-
# Now deal with Python shell and IPython plugins
1949-
if self.ipyconsole is not None:
1950-
focus_client = self.ipyconsole.get_focus_client()
1951-
if focus_client is not None:
1952-
self.last_console_plugin_focus_was_python = False
1953-
else:
1954-
shell = get_focus_python_shell()
1955-
if shell is not None:
1956-
self.last_console_plugin_focus_was_python = True
1957-
19581933
def show_shortcuts(self, menu):
19591934
"""Show action shortcuts in menu"""
19601935
for element in getattr(self, menu + '_menu_actions'):
@@ -2443,11 +2418,7 @@ def execute_in_external_console(self, lines, focus_to_editor):
24432418
Execute lines in external or IPython console and eventually set focus
24442419
to the editor
24452420
"""
2446-
console = self.extconsole
2447-
if self.ipyconsole is None or self.last_console_plugin_focus_was_python:
2448-
console = self.extconsole
2449-
else:
2450-
console = self.ipyconsole
2421+
console = self.ipyconsole
24512422
console.visibility_changed(True)
24522423
console.raise_()
24532424
console.execute_code(lines)

Diff for: spyder/config/ipython.py

-43
This file was deleted.

Diff for: spyder/plugins/editor.py

+15-22
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
QToolBar, QVBoxLayout, QWidget)
3030

3131
# Local imports
32+
from spyder import dependencies
3233
from spyder.config.base import _, get_conf_path, PYTEST
3334
from spyder.config.main import (CONF, RUN_CELL_SHORTCUT,
3435
RUN_CELL_AND_ADVANCE_SHORTCUT)
@@ -52,6 +53,12 @@
5253
RunConfigDialog, RunConfigOneDialog)
5354

5455

56+
# Dependencies
57+
NBCONVERT_REQVER = ">=4.0"
58+
dependencies.add("nbconvert", _("Manipulate Jupyter notebooks on the Editor"),
59+
required_version=NBCONVERT_REQVER)
60+
61+
5562
def _load_all_breakpoints():
5663
bp_dict = CONF.get('run', 'breakpoints', {})
5764
for filename in list(bp_dict.keys()):
@@ -2324,17 +2331,11 @@ def clear_breakpoint(self, filename, lineno):
23242331

23252332
def debug_command(self, command):
23262333
"""Debug actions"""
2327-
if self.main.ipyconsole is not None:
2328-
if self.main.last_console_plugin_focus_was_python:
2329-
self.main.extconsole.execute_code(command)
2330-
else:
2331-
self.main.ipyconsole.write_to_stdin(command)
2332-
focus_widget = self.main.ipyconsole.get_focus_widget()
2333-
if focus_widget:
2334-
focus_widget.setFocus()
2335-
else:
2336-
self.main.extconsole.execute_code(command)
2337-
2334+
self.main.ipyconsole.write_to_stdin(command)
2335+
focus_widget = self.main.ipyconsole.get_focus_widget()
2336+
if focus_widget:
2337+
focus_widget.setFocus()
2338+
23382339
#------ Run Python script
23392340
@Slot()
23402341
def edit_run_configurations(self):
@@ -2429,17 +2430,9 @@ def re_run_file(self):
24292430
python, python_args, current, systerm,
24302431
post_mortem, clear_namespace) = self.__last_ec_exec
24312432
if current:
2432-
if self.main.ipyconsole is not None:
2433-
if self.main.last_console_plugin_focus_was_python:
2434-
self.run_in_current_extconsole.emit(fname, wdir, args,
2435-
debug, post_mortem)
2436-
else:
2437-
self.run_in_current_ipyclient.emit(fname, wdir, args,
2438-
debug, post_mortem,
2439-
clear_namespace)
2440-
else:
2441-
self.run_in_current_extconsole.emit(fname, wdir, args, debug,
2442-
post_mortem)
2433+
self.run_in_current_ipyclient.emit(fname, wdir, args,
2434+
debug, post_mortem,
2435+
clear_namespace)
24432436
else:
24442437
self.main.open_external_console(fname, wdir, args, interact,
24452438
debug, python, python_args,

Diff for: spyder/plugins/help.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from spyder import dependencies
2525
from spyder.config.base import _, get_conf_path, get_module_source_path
2626
from spyder.config.fonts import DEFAULT_SMALL_DELTA
27-
from spyder.config.ipython import QTCONSOLE_INSTALLED
2827
from spyder.plugins import SpyderPluginWidget
2928
from spyder.plugins.configdialog import PluginConfigPage
3029
from spyder.py3compat import get_meth_class_inst, to_text_string
@@ -125,7 +124,6 @@ def setup_page(self):
125124
editor_box.setToolTip(editor_tip)
126125
ipython_box = self.create_checkbox(_("IPython Console"),
127126
'connect/ipython_console')
128-
ipython_box.setEnabled(QTCONSOLE_INSTALLED)
129127

130128
connections_layout = QVBoxLayout()
131129
connections_layout.addWidget(connections_label)
@@ -544,8 +542,7 @@ def apply_plugin_settings(self, options):
544542

545543
# To make auto-connection changes take place instantly
546544
self.main.editor.apply_plugin_settings(options=[connect_n])
547-
if self.main.ipyconsole is not None:
548-
self.main.ipyconsole.apply_plugin_settings(options=[connect_n])
545+
self.main.ipyconsole.apply_plugin_settings(options=[connect_n])
549546

550547
#------ Public API (related to Help's source) -------------------------
551548
def source_is_console(self):
@@ -893,10 +890,9 @@ def get_shell(self):
893890
"""
894891
if not hasattr(self.shell, 'get_doc') or not self.shell.is_running():
895892
self.shell = None
896-
if self.main.ipyconsole is not None:
897-
shell = self.main.ipyconsole.get_current_shellwidget()
898-
if shell is not None and shell.kernel_client is not None:
899-
self.shell = shell
893+
shell = self.main.ipyconsole.get_current_shellwidget()
894+
if shell is not None and shell.kernel_client is not None:
895+
self.shell = shell
900896
if self.shell is None:
901897
self.shell = self.internal_shell
902898
return self.shell

Diff for: spyder/plugins/ipythonconsole.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,19 @@
6161
from spyder.widgets.tabs import Tabs
6262

6363

64+
# Dependencies
6465
SYMPY_REQVER = '>=0.7.3'
6566
dependencies.add("sympy", _("Symbolic mathematics in the IPython Console"),
6667
required_version=SYMPY_REQVER, optional=True)
6768

68-
6969
CYTHON_REQVER = '>=0.21'
7070
dependencies.add("cython", _("Run Cython files in the IPython Console"),
7171
required_version=CYTHON_REQVER, optional=True)
7272

73+
QTCONSOLE_REQVER = ">=4.2.0"
74+
dependencies.add("qtconsole", _("Integrate the IPython console"),
75+
required_version=QTCONSOLE_REQVER)
76+
7377

7478
#------------------------------------------------------------------------------
7579
# Existing kernels
@@ -744,8 +748,6 @@ def refresh_plugin(self):
744748
sw = client.shellwidget
745749
self.variableexplorer.set_shellwidget_from_id(id(sw))
746750
self.help.set_shell(sw)
747-
if not self.testing:
748-
self.main.last_console_plugin_focus_was_python = False
749751
self.update_plugin_title.emit()
750752

751753
def get_plugin_actions(self):

Diff for: spyder/plugins/projects.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,7 @@ def show_explorer(self):
383383

384384
def restart_consoles(self):
385385
"""Restart consoles when closing, opening and switching projects"""
386-
if self.main.ipyconsole:
387-
self.main.ipyconsole.restart()
386+
self.main.ipyconsole.restart()
388387

389388
def is_valid_project(self, path):
390389
"""Check if a directory is a valid Spyder project"""

0 commit comments

Comments
 (0)