~ubuntu-branches/debian/experimental/spyder/experimental

« back to all changes in this revision

Viewing changes to spyderlib/plugins/ipython.py

  • Committer: Package Import Robot
  • Author(s): Picca Frédéric-Emmanuel
  • Date: 2013-01-20 12:19:54 UTC
  • mfrom: (1.1.16)
  • Revision ID: package-import@ubuntu.com-20130120121954-1jt1xa924bshhvh0
Tags: 2.2.0~beta1+dfsg-2
fix typo ipython-qtconsol -> ipython-qtconsole

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
#
3
 
# Copyright © 2011 Pierre Raybaut
4
 
# Licensed under the terms of the MIT License
5
 
# (see spyderlib/__init__.py for details)
6
 
 
7
 
"""IPython v0.12+ Plugin"""
8
 
 
9
 
from spyderlib.qt.QtGui import QHBoxLayout, QMessageBox
10
 
from spyderlib.qt.QtCore import SIGNAL
11
 
 
12
 
# Local imports
13
 
from spyderlib.baseconfig import _
14
 
from spyderlib.widgets.ipython import IPythonApp
15
 
from spyderlib.plugins import SpyderPluginWidget
16
 
 
17
 
 
18
 
class IPythonPlugin(SpyderPluginWidget):
19
 
    """Find in files DockWidget"""
20
 
    CONF_SECTION = 'ipython'
21
 
    def __init__(self, parent, connection_file, kernel_widget_id, kernel_name):
22
 
        super(IPythonPlugin, self).__init__(parent)
23
 
        
24
 
        self.already_closed = False
25
 
 
26
 
        self.connection_file = connection_file
27
 
        self.kernel_widget_id = kernel_widget_id
28
 
        self.kernel_name = kernel_name
29
 
        
30
 
        self.ipython_widget = None
31
 
        
32
 
        # Initialize plugin
33
 
        self.initialize_plugin()
34
 
        
35
 
    def toggle(self, state):
36
 
        """Toggle widget visibility"""
37
 
        if self.dockwidget:
38
 
            self.dockwidget.setVisible(state)
39
 
        
40
 
    #------ SpyderPluginWidget API ---------------------------------------------
41
 
    def get_plugin_title(self):
42
 
        """Return widget title"""
43
 
        return _("IPython client (%s)") % self.kernel_name
44
 
    
45
 
    def get_focus_widget(self):
46
 
        """
47
 
        Return the widget to give focus to when
48
 
        this plugin's dockwidget is raised on top-level
49
 
        """
50
 
        return self.ipython_widget._control
51
 
    
52
 
    def get_plugin_actions(self):
53
 
        """Return a list of actions related to plugin"""
54
 
        return []
55
 
    
56
 
    def register_plugin(self):
57
 
        """Register plugin in Spyder's main window"""
58
 
        argv = ['--existing']+[self.connection_file]
59
 
 
60
 
        iapp = self.main.ipython_app
61
 
        if iapp is None:
62
 
            self.main.ipython_app = iapp = IPythonApp()
63
 
            iapp.initialize_all_except_qt(argv=argv)
64
 
 
65
 
        iapp.parse_command_line(argv=argv)
66
 
        exit_callback = self.close_client
67
 
        self.ipython_widget = iapp.new_frontend_from_existing(exit_callback)
68
 
 
69
 
        layout = QHBoxLayout()
70
 
        layout.addWidget(self.ipython_widget)
71
 
        self.setLayout(layout)
72
 
 
73
 
        self.main.add_ipython_frontend(self)
74
 
 
75
 
        self.connect(self.dockwidget, SIGNAL('visibilityChanged(bool)'),
76
 
                     lambda state: self.main.plugin_focus_changed())
77
 
    
78
 
    def refresh_plugin(self):
79
 
        """Refresh widget"""
80
 
        pass
81
 
        
82
 
    def closing_plugin(self, cancelable=False):
83
 
        """Perform actions before parent main window is closed"""
84
 
        return True
85
 
 
86
 
    #------ Public API --------------------------------------------------------
87
 
    def close_client(self):
88
 
        """Closing IPython client and eventually the associated kernel"""
89
 
        if self.already_closed:
90
 
            return
91
 
        console = self.main.extconsole
92
 
        index = console.get_shell_index_from_id(self.kernel_widget_id)
93
 
        if index is not None:
94
 
            answer = QMessageBox.question(self, self.get_plugin_title(),
95
 
                            _("This IPython frontend will be closed.\n"
96
 
                              "Do you want to kill the associated kernel and "
97
 
                              "the all of its clients?"),
98
 
                            QMessageBox.Yes|QMessageBox.No|QMessageBox.Cancel)
99
 
            if answer == QMessageBox.Yes:
100
 
                console.close_console(index=index)
101
 
                self.main.close_related_ipython_frontends(self)
102
 
            elif answer == QMessageBox.Cancel:
103
 
                return
104
 
        self.already_closed = True
105
 
        
106
 
        self.main.remove_ipython_frontend(self)