~ubuntu-branches/ubuntu/wily/spyder/wily-proposed

« back to all changes in this revision

Viewing changes to spyderlib/widgets/ipython.py

  • Committer: Package Import Robot
  • Author(s): Ghislain Antony Vaillant, Ghislain Antony Vaillant, Picca Frédéric-Emmanuel
  • Date: 2014-10-19 11:42:57 UTC
  • mfrom: (1.2.8)
  • Revision ID: package-import@ubuntu.com-20141019114257-st1rz4fmmscgphhm
Tags: 2.3.1+dfsg-1
* Team upload

[Ghislain Antony Vaillant]
* New upstream release. (Closes: #765963)
* Bump Standards-Version to 3.9.6 (no changes required).
* d/control: fix pedantic lintian warning regarding capitalization in
  packages' description.

[Picca Frédéric-Emmanuel]
* Update the homepage now that upstream moved to bitbucket.
* debian/copyright
  - updated for 2.3.1 version
* debian/control
  + Recommends: python-pandas and python3-pandas

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
31
33
 
32
34
# Local imports
33
35
from spyderlib.baseconfig import (get_conf_path, get_image_path,
326
328
    
327
329
    SEPARATOR = '%s##---(%s)---' % (os.linesep*2, time.ctime())
328
330
    
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
334
 
 
335
337
        self.connection_file = connection_file
336
338
        self.kernel_widget_id = kernel_widget_id
 
339
        self.hostname = hostname
 
340
        self.sshkey = sshkey
 
341
        self.password = password
337
342
        self.name = ''
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)
361
367
        
362
 
        self.exit_callback = lambda: plugin.close_console(client=self)
 
368
        self.exit_callback = lambda: plugin.close_client(client=self)
363
369
        
364
370
    #------ Public API --------------------------------------------------------
365
371
    def show_shellwidget(self, give_focus=True):
374
380
        self.shellwidget.set_ipyclient(self)
375
381
        
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)
 
384
        
 
385
        # For Mayavi to run correctly
 
386
        self.shellwidget.executing.connect(self.set_backend_for_mayavi)
379
387
        
380
388
        # To update history after execution
381
389
        self.shellwidget.executed.connect(self.update_history)
416
424
    
417
425
    def get_name(self):
418
426
        """Return client name"""
419
 
        return _("Console") + " " + self.name
 
427
        return ((_("Console") if self.hostname is None else self.hostname)
 
428
            + " " + self.name)
420
429
    
421
430
    def get_control(self):
422
431
        """Return the text widget (or similar) to give focus to"""
526
535
    def update_history(self):
527
536
        self.history = self.shellwidget._history
528
537
    
 
538
    def set_backend_for_mayavi(self, command):
 
539
        calling_mayavi = False
 
540
        lines = command.splitlines()
 
541
        for l in lines:
 
542
            if not l.startswith('#'):
 
543
                if 'import mayavi' in l or 'from mayavi' in l:
 
544
                    calling_mayavi = True
 
545
                    break
 
546
        if calling_mayavi:
 
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")
 
550
    
529
551
    def interrupt_message(self):
530
552
        """
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()
555
577
    
 
578
    def shellwidget_config(self):
 
579
        """Generate a Config instance for shell widgets using our config
 
580
        system
 
581
        
 
582
        This lets us create each widget with its own config (as opposed to
 
583
        IPythonQtConsoleApp, where all widgets have the same config)
 
584
        """
 
585
        # ---- IPython config ----
 
586
        try:
 
587
            profile_path = osp.join(get_ipython_dir(), 'profile_default')
 
588
            full_ip_cfg = load_pyconfig_files(['ipython_qtconsole_config.py'],
 
589
                                              profile_path)
 
590
            
 
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})
 
594
        except:
 
595
            ip_cfg = Config()
 
596
       
 
597
        # ---- Spyder config ----
 
598
        spy_cfg = Config()
 
599
        
 
600
        # Make the pager widget a rich one (i.e a QTextEdit)
 
601
        spy_cfg.IPythonWidget.kind = 'rich'
 
602
        
 
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]
 
607
 
 
608
        # Pager
 
609
        pager_o = self.get_option('use_pager')
 
610
        if pager_o:
 
611
            spy_cfg.IPythonWidget.paging = 'inside'
 
612
        else:
 
613
            spy_cfg.IPythonWidget.paging = 'none'
 
614
        
 
615
        # Calltips
 
616
        calltips_o = self.get_option('show_calltips')
 
617
        spy_cfg.IPythonWidget.enable_calltips = calltips_o
 
618
 
 
619
        # Buffer size
 
620
        buffer_size_o = self.get_option('buffer_size')
 
621
        spy_cfg.IPythonWidget.buffer_size = buffer_size_o
 
622
        
 
623
        # Prompts
 
624
        in_prompt_o = self.get_option('in_prompt')
 
625
        out_prompt_o = self.get_option('out_prompt')
 
626
        if in_prompt_o:
 
627
            spy_cfg.IPythonWidget.in_prompt = in_prompt_o
 
628
        if out_prompt_o:
 
629
            spy_cfg.IPythonWidget.out_prompt = out_prompt_o
 
630
        
 
631
        # Merge IPython and Spyder configs. Spyder prefs will have prevalence
 
632
        # over IPython ones
 
633
        ip_cfg._merge(spy_cfg)
 
634
        return ip_cfg
 
635
    
556
636
    #------ Private API -------------------------------------------------------
557
637
    def _create_loading_page(self):
558
638
        loading_template = Template(LOADING)