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

« back to all changes in this revision

Viewing changes to spyderlib/widgets/ipython.py

  • Committer: Package Import Robot
  • Author(s): Benjamin Drung
  • Date: 2015-01-15 12:20:11 UTC
  • mfrom: (18.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20150115122011-cc7j5dhy2h9uo13m
Tags: 2.3.2+dfsg-1ubuntu1
Backport patch to support pylint3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
import os
15
15
import os.path as osp
16
16
from string import Template
 
17
import sys
17
18
import time
18
19
 
19
20
# Qt imports
22
23
                                QMessageBox)
23
24
from spyderlib.qt.QtCore import SIGNAL, Qt
24
25
 
 
26
from spyderlib import pygments_patch
 
27
pygments_patch.apply()
 
28
 
25
29
# IPython imports
26
30
try:  # 1.0
27
31
    from IPython.qt.console.rich_ipython_widget import RichIPythonWidget
78
82
        self.calltip_widget = CallTipWidget(self, hide_timer_on=True)
79
83
        # To not use Spyder calltips obtained through the monitor
80
84
        self.calltips = False
 
85
        
81
86
    
82
87
    def showEvent(self, event):
83
88
        """Reimplement Qt Method"""
185
190
        self.ipyclient = ipyclient
186
191
        self.exit_requested.connect(ipyclient.exit_callback)
187
192
    
188
 
    def show_banner(self):
 
193
    def long_banner(self):
189
194
        """Banner for IPython widgets with pylab message"""
190
195
        from IPython.core.usage import default_gui_banner
191
196
        banner = default_gui_banner
221
226
            banner = banner + lines
222
227
        return banner
223
228
    
 
229
    def short_banner(self):
 
230
        """Short banner with Python and IPython versions"""
 
231
        from IPython.core.release import version
 
232
        py_ver = '%d.%d.%d' % (sys.version_info[0], sys.version_info[1],
 
233
                               sys.version_info[2])
 
234
        banner = 'Python %s on %s -- IPython %s' % (py_ver, sys.platform,
 
235
                                                    version)
 
236
        return banner
 
237
    
224
238
    def clear_console(self):
225
239
        self.execute("%clear")
226
240
        
261
275
        """
262
276
        banner_o = CONF.get('ipython_console', 'show_banner', True)
263
277
        if banner_o:
264
 
            return self.show_banner()
 
278
            return self.long_banner()
265
279
        else:
266
 
            return ''
 
280
            return self.short_banner()
267
281
    
268
282
    def _handle_object_info_reply(self, rep):
269
283
        """
334
348
        super(IPythonClient, self).__init__(plugin)
335
349
        SaveHistoryMixin.__init__(self)
336
350
        self.options_button = None
 
351
        
 
352
        # stop button and icon
 
353
        self.stop_button = None
 
354
        self.stop_icon = get_icon("stop.png")
 
355
        
337
356
        self.connection_file = connection_file
338
357
        self.kernel_widget_id = kernel_widget_id
339
358
        self.hostname = hostname
390
409
        
391
410
        # To update the Variable Explorer after execution
392
411
        self.shellwidget.executed.connect(self.auto_refresh_namespacebrowser)
 
412
        
 
413
        # To show a stop button, when executing a process
 
414
        self.shellwidget.executing.connect(self.enable_stop_button)
 
415
        
 
416
        # To hide a stop button after execution stopped
 
417
        self.shellwidget.executed.connect(self.disable_stop_button)
393
418
    
 
419
    def enable_stop_button(self):
 
420
        self.stop_button.setEnabled(True)
 
421
   
 
422
    def disable_stop_button(self):
 
423
        self.stop_button.setDisabled(True)
 
424
        
 
425
    def stop_button_click_handler(self):
 
426
        self.stop_button.setDisabled(True)
 
427
        self.interrupt_kernel()
 
428
 
394
429
    def show_kernel_error(self, error):
395
430
        """Show kernel initialization errors in infowidget"""
396
431
        # Remove explanation about how to kill the kernel (doesn't apply to us)
438
473
 
439
474
    def get_options_menu(self):
440
475
        """Return options menu"""
441
 
        # Kernel
442
 
        self.interrupt_action = create_action(self, _("Interrupt kernel"),
443
 
                                              icon=get_icon('terminate.png'),
444
 
                                              triggered=self.interrupt_kernel)
445
476
        self.restart_action = create_action(self, _("Restart kernel"),
446
477
                                            icon=get_icon('restart.png'),
447
478
                                            triggered=self.restart_kernel)
448
479
        # Main menu
449
480
        if self.menu_actions is not None:
450
 
            actions = [self.interrupt_action, self.restart_action, None] +\
451
 
                      self.menu_actions
 
481
            actions = [self.restart_action, None] + self.menu_actions
452
482
        else:
453
 
            actions = [self.interrupt_action, self.restart_action]
 
483
            actions = [self.restart_action]
454
484
        return actions
455
485
    
456
486
    def get_toolbar_buttons(self):
458
488
        #TODO: Eventually add some buttons (Empty for now)
459
489
        # (see for example: spyderlib/widgets/externalshell/baseshell.py)
460
490
        buttons = []
 
491
        # Code to add the stop button 
 
492
        if self.stop_button is None:
 
493
            self.stop_button = create_toolbutton(self, text=_("Stop"),
 
494
                                             icon=self.stop_icon,
 
495
                                             tip=_("Stop the current command"))
 
496
            self.disable_stop_button()
 
497
            # set click event handler
 
498
            self.stop_button.clicked.connect(self.stop_button_click_handler)
 
499
        if self.stop_button is not None:
 
500
            buttons.append(self.stop_button)
 
501
            
461
502
        if self.options_button is None:
462
503
            options = self.get_options_menu()
463
504
            if options:
469
510
                self.options_button.setMenu(menu)
470
511
        if self.options_button is not None:
471
512
            buttons.append(self.options_button)
 
513
 
472
514
        return buttons
473
 
    
 
515
 
474
516
    def add_actions_to_context_menu(self, menu):
475
517
        """Add actions to IPython widget context menu"""
476
518
        # See spyderlib/widgets/ipython.py for more details on this method