27
27
from IPython.qt.console.rich_ipython_widget import RichIPythonWidget
28
28
except ImportError: # 0.13
29
29
from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget
30
from IPython.core.application import get_ipython_dir
30
31
from IPython.core.oinspect import call_tip
32
from IPython.config.loader import Config, load_pyconfig_files
33
35
from spyderlib.baseconfig import (get_conf_path, get_image_path,
327
329
SEPARATOR = '%s##---(%s)---' % (os.linesep*2, time.ctime())
329
def __init__(self, plugin, history_filename, connection_file=None,
331
def __init__(self, plugin, history_filename, connection_file=None,
332
hostname=None, sshkey=None, password=None,
330
333
kernel_widget_id=None, menu_actions=None):
331
334
super(IPythonClient, self).__init__(plugin)
332
335
SaveHistoryMixin.__init__(self)
333
336
self.options_button = None
335
337
self.connection_file = connection_file
336
338
self.kernel_widget_id = kernel_widget_id
339
self.hostname = hostname
341
self.password = password
338
self.shellwidget = IPythonShellWidget(config=plugin.ipywidget_config(),
343
self.get_option = plugin.get_option
344
self.shellwidget = IPythonShellWidget(config=self.shellwidget_config(),
339
345
local_kernel=False)
340
346
self.shellwidget.hide()
341
347
self.infowidget = WebView(self)
359
365
vlayout.addWidget(self.infowidget)
360
366
self.setLayout(vlayout)
362
self.exit_callback = lambda: plugin.close_console(client=self)
368
self.exit_callback = lambda: plugin.close_client(client=self)
364
370
#------ Public API --------------------------------------------------------
365
371
def show_shellwidget(self, give_focus=True):
374
380
self.shellwidget.set_ipyclient(self)
376
382
# To save history
377
self.shellwidget.executing.connect(
378
lambda c: self.add_to_history(command=c))
383
self.shellwidget.executing.connect(self.add_to_history)
385
# For Mayavi to run correctly
386
self.shellwidget.executing.connect(self.set_backend_for_mayavi)
380
388
# To update history after execution
381
389
self.shellwidget.executed.connect(self.update_history)
526
535
def update_history(self):
527
536
self.history = self.shellwidget._history
538
def set_backend_for_mayavi(self, command):
539
calling_mayavi = False
540
lines = command.splitlines()
542
if not l.startswith('#'):
543
if 'import mayavi' in l or 'from mayavi' in l:
544
calling_mayavi = True
547
message = _("Changing backend to Qt for Mayavi")
548
self.shellwidget._append_plain_text(message + '\n')
549
self.shellwidget.execute("%gui inline\n%gui qt")
529
551
def interrupt_message(self):
531
553
Print an interrupt message when the client is connected to an external
553
575
if self.namespacebrowser:
554
576
self.namespacebrowser.refresh_table()
578
def shellwidget_config(self):
579
"""Generate a Config instance for shell widgets using our config
582
This lets us create each widget with its own config (as opposed to
583
IPythonQtConsoleApp, where all widgets have the same config)
585
# ---- IPython config ----
587
profile_path = osp.join(get_ipython_dir(), 'profile_default')
588
full_ip_cfg = load_pyconfig_files(['ipython_qtconsole_config.py'],
591
# From the full config we only select the IPythonWidget section
592
# because the others have no effect here.
593
ip_cfg = Config({'IPythonWidget': full_ip_cfg.IPythonWidget})
597
# ---- Spyder config ----
600
# Make the pager widget a rich one (i.e a QTextEdit)
601
spy_cfg.IPythonWidget.kind = 'rich'
603
# Gui completion widget
604
gui_comp_o = self.get_option('use_gui_completion')
605
completions = {True: 'droplist', False: 'ncurses'}
606
spy_cfg.IPythonWidget.gui_completion = completions[gui_comp_o]
609
pager_o = self.get_option('use_pager')
611
spy_cfg.IPythonWidget.paging = 'inside'
613
spy_cfg.IPythonWidget.paging = 'none'
616
calltips_o = self.get_option('show_calltips')
617
spy_cfg.IPythonWidget.enable_calltips = calltips_o
620
buffer_size_o = self.get_option('buffer_size')
621
spy_cfg.IPythonWidget.buffer_size = buffer_size_o
624
in_prompt_o = self.get_option('in_prompt')
625
out_prompt_o = self.get_option('out_prompt')
627
spy_cfg.IPythonWidget.in_prompt = in_prompt_o
629
spy_cfg.IPythonWidget.out_prompt = out_prompt_o
631
# Merge IPython and Spyder configs. Spyder prefs will have prevalence
633
ip_cfg._merge(spy_cfg)
556
636
#------ Private API -------------------------------------------------------
557
637
def _create_loading_page(self):
558
638
loading_template = Template(LOADING)