def test(): from spyderlib.widgets.externalshell.pythonshell import ExternalPythonShell from spyderlib.widgets.externalshell.systemshell import ExternalSystemShell app = QApplication(sys.argv) import spyderlib shell = ExternalPythonShell(wdir=osp.dirname(spyderlib.__file__), interact=True) # shell = ExternalSystemShell(wdir=osp.dirname(spyderlib.__file__)) shell.shell.toggle_wrap_mode(True) shell.start(False) from PyQt4.QtGui import QFont font = QFont("Lucida console") font.setPointSize(10) shell.shell.set_font(font) shell.show() sys.exit(app.exec_())
def test(): from spyderlib.utils.qthelpers import qapplication app = qapplication() from spyderlib.widgets.externalshell.pythonshell import ExternalPythonShell from spyderlib.widgets.externalshell.systemshell import ExternalSystemShell import spyderlib # shell = ExternalPythonShell(wdir=osp.dirname(spyderlib.__file__), # ipython=True, stand_alone=True, # arguments="-q4thread -pylab -colors LightBG") shell = ExternalPythonShell(wdir=osp.dirname(spyderlib.__file__), interact=True, umd_enabled=True, umd_namelist=['guidata', 'guiqwt'], umd_verbose=True) # shell = ExternalSystemShell(wdir=osp.dirname(spyderlib.__file__)) shell.shell.toggle_wrap_mode(True) shell.start(False) from PyQt4.QtGui import QFont font = QFont("Lucida console") font.setPointSize(10) shell.shell.set_font(font) shell.show() sys.exit(app.exec_())
def start(self, fname, wdir=None, ask_for_arguments=False, interact=False, debug=False, python=True): """Start new console""" # Note: fname is None <=> Python interpreter fname = unicode(fname) if isinstance(fname, QString) else fname wdir = unicode(wdir) if isinstance(wdir, QString) else wdir if fname is not None and fname in self.filenames: index = self.filenames.index(fname) if CONF.get(self.ID, 'single_tab'): old_shell = self.shells[index] if old_shell.is_running(): answer = QMessageBox.question(self, self.get_widget_title(), self.tr("%1 is already running in a separate process.\n" "Do you want to kill the process before starting " "a new one?").arg(osp.basename(fname)), QMessageBox.Yes | QMessageBox.Cancel) if answer == QMessageBox.Yes: old_shell.process.kill() old_shell.process.waitForFinished() else: return self.close_console(index) else: index = 0 # Creating a new external shell if python: shell = ExternalPythonShell(self, fname, wdir, self.commands, interact, debug, path=self.main.path) else: shell = ExternalSystemShell(self, wdir) shell.shell.set_font( get_font(self.ID) ) shell.shell.toggle_wrap_mode( CONF.get(self.ID, 'wrap') ) shell.shell.set_calltips( CONF.get(self.ID, 'calltips') ) shell.shell.set_codecompletion( CONF.get(self.ID, 'autocompletion/enabled') ) shell.shell.set_codecompletion_enter(CONF.get(self.ID, 'autocompletion/enter-key')) if python: shell.shell.set_docviewer(self.docviewer) self.historylog.add_history(shell.shell.history_filename) self.connect(shell.shell, SIGNAL('append_to_history(QString,QString)'), self.historylog.append_to_history) self.connect(shell.shell, SIGNAL("go_to_error(QString)"), self.go_to_error) self.connect(shell.shell, SIGNAL("focus_changed()"), lambda: self.emit(SIGNAL("focus_changed()"))) if python: if fname is None: name = "Python" icon = get_icon('python.png') else: name = osp.basename(fname) icon = get_icon('run.png') else: name = "Command Window" icon = get_icon('cmdprompt.png') self.shells.insert(index, shell) self.filenames.insert(index, fname) self.icons.insert(index, icon) if index is None: index = self.tabwidget.addTab(shell, name) else: self.tabwidget.insertTab(index, shell, name) self.connect(shell, SIGNAL("started()"), lambda sid=id(shell): self.process_started(sid)) self.connect(shell, SIGNAL("finished()"), lambda sid=id(shell): self.process_finished(sid)) self.find_widget.set_editor(shell.shell) self.tabwidget.setTabToolTip(index, fname if wdir is None else wdir) self.tabwidget.setCurrentIndex(index) if self.dockwidget and not self.ismaximized: self.dockwidget.setVisible(True) self.dockwidget.raise_() # Start process and give focus to console shell.start(ask_for_arguments) shell.shell.setFocus()
def start(self, fname, wdir=None, ask_for_arguments=False, interact=False, debug=False, python=True, ipython=False, arguments=None, current=False): """Start new console""" # Note: fname is None <=> Python interpreter fname = unicode(fname) if isinstance(fname, QString) else fname wdir = unicode(wdir) if isinstance(wdir, QString) else wdir if fname is not None and fname in self.filenames: index = self.filenames.index(fname) if CONF.get(self.ID, 'single_tab'): old_shell = self.shells[index] if old_shell.is_running(): answer = QMessageBox.question(self, self.get_plugin_title(), self.tr("%1 is already running in a separate process.\n" "Do you want to kill the process before starting " "a new one?").arg(osp.basename(fname)), QMessageBox.Yes | QMessageBox.Cancel) if answer == QMessageBox.Yes: old_shell.process.kill() old_shell.process.waitForFinished() else: return self.close_console(index) else: index = 0 # Creating a new external shell pythonpath = self.main.get_spyder_pythonpath() if python: umd_enabled = CONF.get(self.ID, 'umd/enabled') umd_namelist = CONF.get(self.ID, 'umd/namelist') umd_verbose = CONF.get(self.ID, 'umd/verbose') shellwidget = ExternalPythonShell(self, fname, wdir, self.commands, interact, debug, path=pythonpath, ipython=ipython, arguments=arguments, stand_alone=self.light_mode, umd_enabled=umd_enabled, umd_namelist=umd_namelist, umd_verbose=umd_verbose) if self.variableexplorer is not None: self.variableexplorer.add_shellwidget(shellwidget) else: shellwidget = ExternalSystemShell(self, wdir, path=pythonpath) # Code completion / calltips case_sensitive = CONF.get(self.ID, 'codecompletion/case-sensitivity') show_single = CONF.get(self.ID, 'codecompletion/select-single') from_document = CONF.get(self.ID, 'codecompletion/from-document') shellwidget.shell.setup_code_completion(case_sensitive, show_single, from_document) shellwidget.shell.setMaximumBlockCount( CONF.get(self.ID, 'max_line_count') ) shellwidget.shell.set_font( get_font(self.ID) ) shellwidget.shell.toggle_wrap_mode( CONF.get(self.ID, 'wrap') ) shellwidget.shell.set_calltips( CONF.get(self.ID, 'calltips') ) shellwidget.shell.set_codecompletion_auto( CONF.get(self.ID, 'codecompletion/auto') ) shellwidget.shell.set_codecompletion_enter(CONF.get(self.ID, 'codecompletion/enter-key')) if python and self.inspector is not None: shellwidget.shell.set_inspector(self.inspector) if self.historylog is not None: self.historylog.add_history(shellwidget.shell.history_filename) self.connect(shellwidget.shell, SIGNAL('append_to_history(QString,QString)'), self.historylog.append_to_history) self.connect(shellwidget.shell, SIGNAL("go_to_error(QString)"), self.go_to_error) self.connect(shellwidget.shell, SIGNAL("focus_changed()"), lambda: self.emit(SIGNAL("focus_changed()"))) if python: if fname is None: if ipython: self.ipython_count += 1 tab_name = "IPython %d" % self.ipython_count tab_icon1 = get_icon('ipython.png') tab_icon2 = get_icon('ipython_t.png') else: self.python_count += 1 tab_name = "Python %d" % self.python_count tab_icon1 = get_icon('python.png') tab_icon2 = get_icon('python_t.png') else: tab_name = osp.basename(fname) tab_icon1 = get_icon('run.png') tab_icon2 = get_icon('terminated.png') else: fname = id(shellwidget) if os.name == 'nt': tab_name = self.tr("Command Window") else: tab_name = self.tr("Terminal") self.terminal_count += 1 tab_name += (" %d" % self.terminal_count) tab_icon1 = get_icon('cmdprompt.png') tab_icon2 = get_icon('cmdprompt_t.png') self.shells.insert(index, shellwidget) self.filenames.insert(index, fname) self.icons.insert(index, (tab_icon1, tab_icon2)) if index is None: index = self.tabwidget.addTab(shellwidget, tab_name) else: self.tabwidget.insertTab(index, shellwidget, tab_name) self.connect(shellwidget, SIGNAL("started()"), lambda sid=id(shellwidget): self.process_started(sid)) self.connect(shellwidget, SIGNAL("finished()"), lambda sid=id(shellwidget): self.process_finished(sid)) self.find_widget.set_editor(shellwidget.shell) self.tabwidget.setTabToolTip(index, fname if wdir is None else wdir) self.tabwidget.setCurrentIndex(index) if self.dockwidget and not self.ismaximized: self.dockwidget.setVisible(True) self.dockwidget.raise_() self.toggle_icontext(CONF.get(self.ID, 'show_icontext')) # Start process and give focus to console shellwidget.start(ask_for_arguments) shellwidget.shell.setFocus()
def start(self, fname, wdir=None, ask_for_arguments=False, interact=False, debug=False, python=True): """Start new console""" # Note: fname is None <=> Python interpreter fname = unicode(fname) if isinstance(fname, QString) else fname wdir = unicode(wdir) if isinstance(wdir, QString) else wdir if fname is not None and fname in self.filenames: index = self.filenames.index(fname) if CONF.get(self.ID, 'single_tab'): old_shell = self.shells[index] if old_shell.is_running(): answer = QMessageBox.question( self, self.get_widget_title(), self.tr( "%1 is already running in a separate process.\n" "Do you want to kill the process before starting " "a new one?").arg(osp.basename(fname)), QMessageBox.Yes | QMessageBox.Cancel) if answer == QMessageBox.Yes: old_shell.process.kill() old_shell.process.waitForFinished() else: return self.close_console(index) else: index = 0 # Creating a new external shell if python: shell = ExternalPythonShell(self, fname, wdir, self.commands, interact, debug, path=self.main.path) else: shell = ExternalSystemShell(self, wdir) shell.shell.set_font(get_font(self.ID)) shell.shell.toggle_wrap_mode(CONF.get(self.ID, 'wrap')) shell.shell.set_calltips(CONF.get(self.ID, 'calltips')) shell.shell.set_codecompletion( CONF.get(self.ID, 'autocompletion/enabled')) shell.shell.set_codecompletion_enter( CONF.get(self.ID, 'autocompletion/enter-key')) if python: shell.shell.set_docviewer(self.docviewer) self.historylog.add_history(shell.shell.history_filename) self.connect(shell.shell, SIGNAL('append_to_history(QString,QString)'), self.historylog.append_to_history) self.connect(shell.shell, SIGNAL("go_to_error(QString)"), self.go_to_error) self.connect(shell.shell, SIGNAL("focus_changed()"), lambda: self.emit(SIGNAL("focus_changed()"))) if python: if fname is None: name = "Python" icon = get_icon('python.png') else: name = osp.basename(fname) icon = get_icon('run.png') else: name = "Command Window" icon = get_icon('cmdprompt.png') self.shells.insert(index, shell) self.filenames.insert(index, fname) self.icons.insert(index, icon) if index is None: index = self.tabwidget.addTab(shell, name) else: self.tabwidget.insertTab(index, shell, name) self.connect(shell, SIGNAL("started()"), lambda sid=id(shell): self.process_started(sid)) self.connect(shell, SIGNAL("finished()"), lambda sid=id(shell): self.process_finished(sid)) self.find_widget.set_editor(shell.shell) self.tabwidget.setTabToolTip(index, fname if wdir is None else wdir) self.tabwidget.setCurrentIndex(index) if self.dockwidget and not self.ismaximized: self.dockwidget.setVisible(True) self.dockwidget.raise_() # Start process and give focus to console shell.start(ask_for_arguments) shell.shell.setFocus()