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

« back to all changes in this revision

Viewing changes to spyderlib/widgets/internalshell.py

  • Committer: Package Import Robot
  • Author(s): Picca Frédéric-Emmanuel
  • Date: 2014-05-29 09:06:26 UTC
  • mfrom: (1.1.21) (18.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20140529090626-f58t82g0n5iewaxu
Tags: 2.3.0~rc+dfsg-1~experimental2
* Add spyder-common binary package for all the python2,3 common files
* debian/path
  - 0001-fix-documentation-installation.patch (deleted)
  + 0001-fix-spyderlib-path.patch (new)

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
#FIXME: Internal shell MT: for i in range(100000): print i -> bug
15
15
 
16
 
#----Builtins
17
 
import __builtin__
 
16
#----Builtins*
 
17
from spyderlib.py3compat import builtins
18
18
from spyderlib.widgets.objecteditor import oedit
19
 
__builtin__.oedit = oedit
 
19
builtins.oedit = oedit
20
20
 
21
21
import os
22
22
import threading
38
38
from spyderlib.baseconfig import get_conf_path, _, DEBUG
39
39
from spyderlib.config import CONF
40
40
from spyderlib.widgets.shell import PythonShellWidget
 
41
from spyderlib.py3compat import to_text_string, getcwd, to_binary_string, u
41
42
 
42
43
 
43
44
def create_banner(message):
44
45
    """Create internal shell banner"""
45
 
    versions = get_versions()
46
 
    return 'Spyder %s internal shell on Python %s %dbits [%s]\n%s'\
47
 
           % (versions['spyder'], versions['python'], versions['bitness'],
48
 
              versions['system'], message)
 
46
    if message is None:
 
47
        versions = get_versions()
 
48
        return 'Python %s %dbits [%s]'\
 
49
               % (versions['python'], versions['bitness'], versions['system'])
 
50
    else:
 
51
        return message
49
52
 
50
53
 
51
54
class SysOutput(QObject):
104
107
 
105
108
class InternalShell(PythonShellWidget):
106
109
    """Shell base widget: link between PythonShellWidget and Interpreter"""
107
 
    def __init__(self, parent=None, namespace=None, commands=[], message="",
 
110
    def __init__(self, parent=None, namespace=None, commands=[], message=None,
108
111
                 max_line_count=300, font=None, exitfunc=None, profile=False,
109
112
                 multithreaded=True, light_background=True):
110
113
        PythonShellWidget.__init__(self, parent,
111
 
                                   get_conf_path('.history_internal.py'),
 
114
                                   get_conf_path('history_internal.py'),
112
115
                                   profile)
113
116
        
114
117
        self.set_light_background(light_background)
115
 
        
116
118
        self.multithreaded = multithreaded
117
 
        
118
119
        self.setMaximumBlockCount(max_line_count)
119
120
        
 
121
        # For compatibility with ExtPythonShellWidget
 
122
        self.is_ipykernel = False
 
123
        
120
124
        if font is not None:
121
125
            self.set_font(font)
122
126
        
132
136
        # Code completion / calltips
133
137
        getcfg = lambda option: CONF.get('internal_console', option)
134
138
        case_sensitive = getcfg('codecompletion/case_sensitive')
135
 
        show_single = getcfg('codecompletion/show_single')
136
139
        self.set_codecompletion_case(case_sensitive)
137
 
        self.set_codecompletion_single(show_single)
138
140
        
139
141
        # keyboard events management
140
142
        self.eventqueue = []
151
153
        
152
154
        # Embedded shell -- requires the monitor (which installs the
153
155
        # 'open_in_spyder' function in builtins)
154
 
        if hasattr(__builtin__, 'open_in_spyder'):
 
156
        if hasattr(builtins, 'open_in_spyder'):
155
157
            self.connect(self, SIGNAL("go_to_error(QString)"),
156
158
                         self.open_with_external_spyder)
157
159
 
202
204
        self.interpreter.restore_stds()
203
205
        
204
206
    def edit_script(self, filename, external_editor):
205
 
        filename = unicode(filename)
 
207
        filename = to_text_string(filename)
206
208
        if external_editor:
207
209
            self.external_editor(filename)
208
210
        else:
274
276
        """Load file in external Spyder's editor, if available
275
277
        This method is used only for embedded consoles
276
278
        (could also be useful if we ever implement the magic %edit command)"""
277
 
        match = get_error_match(unicode(text))
 
279
        match = get_error_match(to_text_string(text))
278
280
        if match:
279
281
            fname, lnb = match.groups()
280
 
            __builtin__.open_in_spyder(fname, int(lnb))
 
282
            builtins.open_in_spyder(fname, int(lnb))
281
283
 
282
284
    def external_editor(self, filename, goto=-1):
283
285
        """Edit in an external editor
319
321
            t0 = time()
320
322
            for _ in range(10):
321
323
                self.execute_command(command)
322
 
            self.insert_text(u"\n<Δt>=%dms\n" % (1e2*(time()-t0)))
 
324
            self.insert_text(u("\n<Δt>=%dms\n") % (1e2*(time()-t0)))
323
325
            self.new_prompt(self.interpreter.p1)
324
326
        else:
325
327
            self.execute_command(command)
391
393
        else:
392
394
            if history:
393
395
                self.add_to_history(cmd)
394
 
        self.interpreter.stdin_write.write(cmd.encode("utf-8") + '\n')
 
396
        self.interpreter.stdin_write.write(to_binary_string(cmd + '\n'))
395
397
        if not self.multithreaded:
396
398
            self.interpreter.run_line()
397
399
            self.emit(SIGNAL("refresh()"))
410
412
        
411
413
    def get_globals_keys(self):
412
414
        """Return shell globals() keys"""
413
 
        return self.interpreter.namespace.keys()
 
415
        return list(self.interpreter.namespace.keys())
414
416
        
415
417
    def get_cdlistdir(self):
416
418
        """Return shell current directory list dir"""
417
 
        return os.listdir(os.getcwdu())
 
419
        return os.listdir(getcwd())
418
420
                
419
421
    def iscallable(self, objtxt):
420
422
        """Is object callable?"""
435
437
            return obj.__doc__
436
438
    
437
439
    def get_doc(self, objtxt):
438
 
        """Get object documentation"""
 
440
        """Get object documentation dictionary"""
439
441
        obj, valid = self._eval(objtxt)
440
442
        if valid:
441
443
            return getdoc(obj)