def toggle_wrap_mode(self, checked): """Toggle wrap mode""" if self.tabwidget is None: return for editor in self.editors: editor.toggle_wrap_mode(checked) CONF.set(self.ID, 'wrap', checked)
def toggle_wrap_mode(self, checked): """Toggle wrap mode""" if self.tabwidget is None: return for editor in self.editors: editor.toggle_wrap_mode(checked) CONF.set(self.ID, 'wrap', checked)
def option_changed(self, option, value): """ Change a plugin option in configuration file Use a SIGNAL to call it, e.g.: self.emit(SIGNAL('option_changed'), 'show_all', checked) """ CONF.set(self.ID, option, value)
def toggle_wrap_mode(self, checked): """Toggle wrap mode""" if self.tabwidget is None: return for shell in self.shells: shell.shell.toggle_wrap_mode(checked) CONF.set(self.ID, 'wrap', checked)
def toggle_codecompletion(self, checked): """Toggle automatic code completion""" if self.tabwidget is None: return for shell in self.shells: shell.shell.set_codecompletion_auto(checked) CONF.set(self.ID, 'codecompletion/auto', checked)
def run(self, session): from spyderlib import spyder from spyderlib.config import CONF cs.exit_if_not_exists(session) app = spyder.initialize() # This should come from our command line parser, however, Spyder does # not provide a way to get the argument parser but only the parsed # arguments. opts = { 'working_directory': cs.path(), 'debug': False, 'profile': False, 'multithreaded': False, 'light': False } # The python executable is set explicitly here, because Spyder tends # not to pick up the one used in a virtualenv. This should be set in a # profile in order to not mess with the user's settings. CONF.set('console', 'pythonexecutable', sys.executable) main = spyder.MainWindow(Bunch(opts)) main.setup() main.show() main.open_file(cs.path(session)) app.exec_()
def change_history_depth(self): "Change history max entries" "" depth, valid = QInputDialog.getInteger( self, self.tr('History'), self.tr('Maximum entries'), CONF.get(self.ID, 'max_entries'), 10, 10000) if valid: CONF.set(self.ID, 'max_entries', depth)
def toggle_codecompletion_enter(self, checked): """Toggle Enter key for code completion""" if self.tabwidget is None: return for shell in self.shells: shell.shell.set_codecompletion_enter(checked) CONF.set(self.ID, 'autocompletion/enter-key', checked)
def toggle_codecompletion(self, checked): """Toggle code completion""" if self.tabwidget is None: return for shell in self.shells: shell.shell.set_codecompletion(checked) CONF.set(self.ID, 'autocompletion/enabled', checked)
def toggle_calltips(self, checked): """Toggle calltips""" if self.tabwidget is None: return for shell in self.shells: shell.shell.set_calltips(checked) CONF.set(self.ID, 'calltips', checked)
def run(self, session): from spyderlib import spyder from spyderlib.config import CONF cs.exit_if_not_exists(session) app = spyder.initialize() # This should come from our command line parser, however, Spyder does # not provide a way to get the argument parser but only the parsed # arguments. opts = {'working_directory': cs.path(), 'debug': False, 'profile': False, 'multithreaded': False, 'light': False, 'new_instance': True} # The python executable is set explicitly here, because Spyder tends # not to pick up the one used in a virtualenv. This should be set in a # profile in order to not mess with the user's settings. CONF.set('console', 'pythonexecutable', sys.executable) main = spyder.MainWindow(Bunch(opts)) main.setup() main.show() main.open_file(cs.path(session)) app.exec_()
def set_option(self, option, value): """ Set a plugin option in configuration file Use a SIGNAL to call it, e.g.: plugin.sig_option_changed.emit('show_all', checked) """ CONF.set(self.CONF_SECTION, str(option), value)
def set_option(self, option, value): """ Set a plugin option in configuration file Use a SIGNAL to call it, e.g.: plugin.sig_option_changed.emit('show_all', checked) """ CONF.set(self.CONF_SECTION, str(option), value)
def toggle_wrap_mode(self, checked): """Toggle wrap mode""" if self.tabwidget is None: return for shell in self.shells: shell.shell.toggle_wrap_mode(checked) CONF.set(self.ID, 'wrap', checked)
def setup_api(self): """Load and prepare Python API""" if self.lexer() is None: return self.api = QsciAPIs(self.lexer()) is_api_ready = False api_path = CONF.get('editor', 'api') if not osp.isfile(api_path): from spyderlib.config import DATA_PATH api_path = osp.join(DATA_PATH, 'python.api') if osp.isfile(api_path): CONF.set('editor', 'api', api_path) else: return False api_size = CONF.get('editor', 'api_size', None) current_api_size = os.stat(api_path).st_size if api_size is not None and api_size == current_api_size: if self.api.isPrepared(): is_api_ready = self.api.loadPrepared() else: CONF.set('editor', 'api_size', current_api_size) if not is_api_ready: if self.api.load(api_path): self.api.prepare() self.connect(self.api, SIGNAL("apiPreparationFinished()"), self.api.savePrepared) return is_api_ready
def toggle_calltips(self, checked): """Toggle calltips""" if self.tabwidget is None: return for shell in self.shells: shell.shell.set_calltips(checked) CONF.set(self.ID, 'calltips', checked)
def toggle_codecompletion(self, checked): """Toggle code completion""" if self.tabwidget is None: return for shell in self.shells: shell.shell.set_codecompletion(checked) CONF.set(self.ID, 'autocompletion/enabled', checked)
def toggle_codecompletion_enter(self, checked): """Toggle Enter key for code completion""" if self.tabwidget is None: return for shell in self.shells: shell.shell.set_codecompletion_enter(checked) CONF.set(self.ID, 'autocompletion/enter-key', checked)
def save_config(self): """Save configuration: opened projects & tree widget state""" data = self.get_project_config() cPickle.dump(data, file(self.DATAPATH, 'w')) CONF.set(self.ID, 'expanded_state', self.treewidget.get_expanded_state()) CONF.set(self.ID, 'scrollbar_position', self.treewidget.get_scrollbar_position())
def change_exteditor(self): """Change external editor path""" path, valid = QInputDialog.getText( self, self.tr('External editor'), self.tr('External editor executable path:'), QLineEdit.Normal, CONF.get(self.ID, 'external_editor/path')) if valid: CONF.set(self.ID, 'external_editor/path', unicode(path))
def change_history_depth(self): "Change history max entries""" depth, valid = QInputDialog.getInteger(self, self.tr('History'), self.tr('Maximum entries'), CONF.get(self.ID, 'max_entries'), 10, 10000) if valid: CONF.set(self.ID, 'max_entries', depth)
def change_exteditor(self): """Change external editor path""" path, valid = QInputDialog.getText(self, self.tr('External editor'), self.tr('External editor executable path:'), QLineEdit.Normal, CONF.get(self.ID, 'external_editor/path')) if valid: CONF.set(self.ID, 'external_editor/path', unicode(path))
def change_max_line_count(self): "Change maximum line count""" mlc, valid = QInputDialog.getInteger(self, self.tr('Buffer'), self.tr('Maximum line count'), CONF.get(self.ID, 'max_line_count'), 10, 1000000) if valid: self.shell.setMaximumBlockCount(mlc) CONF.set(self.ID, 'max_line_count', mlc)
def _get_run_configurations(): history_count = CONF.get('run', 'history', 20) try: return [(filename, options) for filename, options in CONF.get('run', 'configurations', []) if osp.isfile(filename)][:history_count] except ValueError: CONF.set('run', 'configurations', []) return []
def _get_run_configurations(): history_count = CONF.get('run', 'history', 20) try: return [(filename, options) for filename, options in CONF.get('run', 'configurations', []) if osp.isfile(filename)][:history_count] except ValueError: CONF.set('run', 'configurations', []) return []
def set_ipython_options(self): """Set IPython interpreter arguments""" arguments, valid = QInputDialog.getText(self, self.tr('IPython'), self.tr('IPython command line options:\n' '(Qt4 support: -q4thread)\n' '(Qt4 and matplotlib support: -q4thread -pylab)'), QLineEdit.Normal, CONF.get(self.ID, 'ipython_options')) if valid: CONF.set(self.ID, 'ipython_options', unicode(arguments))
def toggle_rollbackimporter(self, checked): """Toggle rollback importer""" CONF.set(self.ID, 'rollback_importer', checked) if checked and self.isVisible(): QMessageBox.warning(self, self.get_widget_title(), self.tr("The rollback importer requires a restart " "of Spyder to be fully functionnal " "(otherwise only newly imported modules " "will be reloaded when executing scripts)."), QMessageBox.Ok)
def toggle_rollbackimporter(self, checked): """Toggle rollback importer""" CONF.set(self.ID, 'rollback_importer', checked) if checked and self.isVisible(): QMessageBox.warning( self, self.get_widget_title(), self.tr("The rollback importer requires a restart " "of Spyder to be fully functionnal " "(otherwise only newly imported modules " "will be reloaded when executing scripts)."), QMessageBox.Ok)
def set_color_scheme(name, color_scheme, replace=True): """Set syntax color scheme""" section = "color_schemes" names = CONF.get("color_schemes", "names", []) for key in sh.COLOR_SCHEME_KEYS: option = "%s/%s" % (name, key) value = CONF.get(section, option, default=None) if value is None or replace or name not in names: CONF.set(section, option, color_scheme[key]) names.append(to_text_string(name)) CONF.set(section, "names", sorted(list(set(names))))
def toggle_icontext(self, checked): """Toggle icon text""" CONF.set(self.ID, 'show_icontext', checked) if self.tabwidget is None: return for index in range(self.tabwidget.count()): for widget in self.tabwidget.widget(index).get_toolbar_buttons(): if checked: widget.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) else: widget.setToolButtonStyle(Qt.ToolButtonIconOnly)
def set_color_scheme(name, color_scheme, replace=True): """Set syntax color scheme""" section = "color_schemes" names = CONF.get("color_schemes", "names", []) for key in sh.COLOR_SCHEME_KEYS: option = "%s/%s" % (name, key) value = CONF.get(section, option, default=None) if value is None or replace or name not in names: CONF.set(section, option, color_scheme[key]) names.append(to_text_string(name)) CONF.set(section, "names", sorted(list(set(names))))
def __init__(self, parent=None): QDialog.__init__(self, parent) self.main = parent # Widgets self.pages_widget = QStackedWidget() self.contents_widget = QListWidget() self.button_reset = QPushButton(_('Reset to defaults')) bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Apply | QDialogButtonBox.Cancel) self.apply_btn = bbox.button(QDialogButtonBox.Apply) # Widgets setup # Destroying the C++ object right after closing the dialog box, # otherwise it may be garbage-collected in another QThread # (e.g. the editor's analysis thread in Spyder), thus leading to # a segmentation fault on UNIX or an application crash on Windows self.setAttribute(Qt.WA_DeleteOnClose) self.setWindowTitle(_('Preferences')) self.setWindowIcon(ima.icon('configure')) self.contents_widget.setMovement(QListView.Static) self.contents_widget.setSpacing(1) self.contents_widget.setCurrentRow(0) # Layout hsplitter = QSplitter() hsplitter.addWidget(self.contents_widget) hsplitter.addWidget(self.pages_widget) btnlayout = QHBoxLayout() btnlayout.addWidget(self.button_reset) btnlayout.addStretch(1) btnlayout.addWidget(bbox) vlayout = QVBoxLayout() vlayout.addWidget(hsplitter) vlayout.addLayout(btnlayout) self.setLayout(vlayout) # Signals and slots self.button_reset.clicked.connect(self.main.reset_spyder) self.pages_widget.currentChanged.connect(self.current_page_changed) self.contents_widget.currentRowChanged.connect( self.pages_widget.setCurrentIndex) bbox.accepted.connect(self.accept) bbox.rejected.connect(self.reject) bbox.clicked.connect(self.button_clicked) # Ensures that the config is present on spyder first run CONF.set('main', 'interface_language', load_lang_conf())
def __init__(self, parent=None): QDialog.__init__(self, parent) # Destroying the C++ object right after closing the dialog box, # otherwise it may be garbage-collected in another QThread # (e.g. the editor's analysis thread in Spyder), thus leading to # a segmentation fault on UNIX or an application crash on Windows self.setAttribute(Qt.WA_DeleteOnClose) self.contents_widget = QListWidget() self.contents_widget.setMovement(QListView.Static) self.contents_widget.setSpacing(1) bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Apply | QDialogButtonBox.Cancel) self.apply_btn = bbox.button(QDialogButtonBox.Apply) bbox.accepted.connect(self.accept) bbox.rejected.connect(self.reject) bbox.clicked.connect(self.button_clicked) self.pages_widget = QStackedWidget() self.pages_widget.currentChanged.connect(self.current_page_changed) self.contents_widget.currentRowChanged.connect( self.pages_widget.setCurrentIndex) self.contents_widget.setCurrentRow(0) hsplitter = QSplitter() hsplitter.addWidget(self.contents_widget) hsplitter.addWidget(self.pages_widget) btnlayout = QHBoxLayout() btnlayout.addStretch(1) btnlayout.addWidget(bbox) vlayout = QVBoxLayout() vlayout.addWidget(hsplitter) vlayout.addLayout(btnlayout) self.setLayout(vlayout) self.setWindowTitle(_('Preferences')) self.setWindowIcon(ima.icon('configure')) # Ensures that the config is present on spyder first run CONF.set('main', 'interface_language', load_lang_conf())
def set_font(font, section, option=None): """Set font""" if option is None: option = 'font' else: option += '/font' CONF.set(section, option + '/family', to_text_string(font.family())) CONF.set(section, option + '/size', float(font.pointSize())) CONF.set(section, option + '/italic', int(font.italic())) CONF.set(section, option + '/bold', int(font.bold())) FONT_CACHE[(section, option)] = font
def set_font(font, section, option=None): """Set font""" if option is None: option = 'font' else: option += '/font' CONF.set(section, option+'/family', to_text_string(font.family())) CONF.set(section, option+'/size', float(font.pointSize())) CONF.set(section, option+'/italic', int(font.italic())) CONF.set(section, option+'/bold', int(font.bold())) FONT_CACHE[(section, option)] = font
def __init__(self, parent, light_mode): self.light_mode = light_mode self.commands = [] self.tabwidget = None self.menu_actions = None self.inspector = None self.historylog = None self.variableexplorer = None # variable explorer plugin self.ipython_count = 0 self.python_count = 0 self.terminal_count = 0 if CONF.get(self.ID, 'ipython_options', None) is None: CONF.set(self.ID, 'ipython_options', self.get_default_ipython_options()) self.shells = [] self.filenames = [] self.icons = [] SpyderPluginWidget.__init__(self, parent) layout = QVBoxLayout() self.tabwidget = Tabs(self, self.menu_actions) self.connect(self.tabwidget, SIGNAL('currentChanged(int)'), self.refresh_plugin) self.connect(self.tabwidget, SIGNAL('move_data(int,int)'), self.move_tab) self.tabwidget.set_close_function(self.close_console) layout.addWidget(self.tabwidget) # Find/replace widget self.find_widget = FindReplace(self) self.find_widget.hide() layout.addWidget(self.find_widget) self.setLayout(layout) # Accepting drops self.setAcceptDrops(True)
def save_historylog(self): """Save current history log (all text in console)""" title = _("Save history log") self.emit(SIGNAL('redirect_stdio(bool)'), False) filename, _selfilter = getsavefilename(self, title, self.historylog_filename, "%s (*.log)" % _("History logs")) self.emit(SIGNAL('redirect_stdio(bool)'), True) if filename: filename = osp.normpath(filename) try: encoding.write(unicode(self.get_text_with_eol()), filename) self.historylog_filename = filename CONF.set('main', 'historylog_filename', filename) except EnvironmentError, error: QMessageBox.critical(self, title, _("<b>Unable to save file '%s'</b>" "<br><br>Error message:<br>%s" ) % (osp.basename(filename), unicode(error)))
def save_historylog(self): """Save current history log (all text in console)""" title = translate("ShellBaseWidget", "Save history log") self.emit(SIGNAL('redirect_stdio(bool)'), False) filename = QFileDialog.getSaveFileName(self, title, self.historylog_filename, "History logs (*.log)") self.emit(SIGNAL('redirect_stdio(bool)'), True) if filename: filename = osp.normpath(unicode(filename)) try: encoding.write(unicode(self.text()), filename) self.historylog_filename = filename CONF.set('main', 'historylog_filename', filename) except EnvironmentError, error: QMessageBox.critical(self, title, translate("ShellBaseWidget", "<b>Unable to save file '%1'</b>" "<br><br>Error message:<br>%2") \ .arg(osp.basename(filename)).arg(str(error)))
def save_historylog(self): """Save current history log (all text in console)""" title = translate("ShellBaseWidget", "Save history log") self.emit(SIGNAL('redirect_stdio(bool)'), False) filename = QFileDialog.getSaveFileName(self, title, self.historylog_filename, "History logs (*.log)") self.emit(SIGNAL('redirect_stdio(bool)'), True) if filename: filename = osp.normpath(unicode(filename)) try: encoding.write(unicode(self.text()), filename) self.historylog_filename = filename CONF.set('main', 'historylog_filename', filename) except EnvironmentError, error: QMessageBox.critical(self, title, translate("ShellBaseWidget", "<b>Unable to save file '%1'</b>" "<br><br>Error message:<br>%2") \ .arg(osp.basename(filename)).arg(str(error)))
def save_historylog(self): """Save current history log (all text in console)""" title = _("Save history log") self.redirect_stdio.emit(False) filename, _selfilter = getsavefilename(self, title, self.historylog_filename, "%s (*.log)" % _("History logs")) self.redirect_stdio.emit(True) if filename: filename = osp.normpath(filename) try: encoding.write(to_text_string(self.get_text_with_eol()), filename) self.historylog_filename = filename CONF.set('main', 'historylog_filename', filename) except EnvironmentError as error: QMessageBox.critical(self, title, _("<b>Unable to save file '%s'</b>" "<br><br>Error message:<br>%s" ) % (osp.basename(filename), to_text_string(error)))
def toggle_umd(self, checked): """Toggle UMD""" CONF.set(self.ID, 'umd/enabled', checked) if checked and self.isVisible(): QMessageBox.warning(self, self.get_plugin_title(), self.tr("This option will enable the User Module Deleter (UMD) " "in Python/IPython interpreters. UMD forces Python to " "reload deeply modules during import when running a " "Python script using the Spyder's builtin function " "<b>runfile</b>." "<br><br><b>1.</b> UMD may require to restart the " "Python interpreter in which it will be called " "(otherwise only newly imported modules will be " "reloaded when executing scripts)." "<br><br><b>2.</b> If errors occur when re-running a " "PyQt-based program, please check that the Qt objects " "are properly destroyed (e.g. you may have to use the " "attribute <b>Qt.WA_DeleteOnClose</b> on your main " "window, using the <b>setAttribute</b> method)"), QMessageBox.Ok)
def setup_api(self): """Load and prepare API""" if self.lexer() is None: return self.api = QsciAPIs(self.lexer()) is_api_ready = False api_path = CONF.get('editor', 'api') if not os.path.isfile(api_path): return False api_stat = CONF.get('editor', 'api_stat', None) current_api_stat = os.stat(api_path) if (api_stat is not None) and (api_stat == current_api_stat): if self.api.isPrepared(): is_api_ready = self.api.loadPrepared() else: CONF.set('editor', 'api_stat', current_api_stat) if not is_api_ready: if self.api.load(api_path): self.api.prepare() self.connect(self.api, SIGNAL("apiPreparationFinished()"), self.api.savePrepared) return is_api_ready
def toggle_codecompletion_enter(self, checked): """Toggle Enter key for code completion""" self.shell.set_codecompletion_enter(checked) CONF.set(self.ID, 'autocompletion/enter-key', checked)
def toggle_codecompletion(self, checked): """Toggle code completion""" self.shell.set_codecompletion(checked) CONF.set(self.ID, 'autocompletion/enabled', checked)
def toggle_autosave(self, checked): """Toggle autosave mode""" CONF.set(self.ID, 'autosave', checked)
def toggle_autorefresh(self, checked): """Toggle autorefresh mode""" CONF.set(self.ID, 'autorefresh', checked) self.refresh()
def closing(self, cancelable=False): """Perform actions before parent main window is closed""" options = self.find_options.get_options(all=True) if options is not None: search_text, text_re, search_path, include, \ include_re, exclude, exclude_re = options hist_limit = 15 search_text = search_text[:hist_limit] search_path = search_path[:hist_limit] include = include[:hist_limit] exclude = exclude[:hist_limit] CONF.set(self.ID, 'search_text', search_text) CONF.set(self.ID, 'search_text_regexp', text_re) CONF.set(self.ID, 'search_path', search_path) CONF.set(self.ID, 'include', include) CONF.set(self.ID, 'include_regexp', include_re) CONF.set(self.ID, 'exclude', exclude) CONF.set(self.ID, 'exclude_regexp', exclude_re) return True
def toggle_exclude_private(self, checked): """Toggle exclude private references""" CONF.set(self.ID, 'exclude_private', checked) self.refresh()
def _set_run_configurations(configurations): history_count = CONF.get('run', 'history', 20) CONF.set('run', 'configurations', configurations[:history_count])
def option_changed(self, option, value): CONF.set(self.ID, option, value) self.refresh_table()
def set_firstrun_o(self): CONF.set('run', ALWAYS_OPEN_FIRST_RUN_OPTION, self.firstrun_cb.isChecked())
def toggle_exclude_upper(self, checked): """Toggle exclude upper-case references""" CONF.set(self.ID, 'exclude_upper', checked) self.refresh()
def _set_run_configurations(configurations): history_count = CONF.get('run', 'history', 20) CONF.set('run', 'configurations', configurations[:history_count])
def toggle_exclude_unsupported(self, checked): """Toggle exclude unsupported datatypes""" CONF.set(self.ID, 'exclude_unsupported', checked) self.refresh()
def set_shortcut(context, name, keystr): """Set keyboard shortcut (key sequence string)""" CONF.set('shortcuts', '%s/%s' % (context, name), keystr)
def toggle_calltips(self, checked): """Toggle calltips""" self.shell.set_calltips(checked) CONF.set(self.ID, 'calltips', checked)
def set_firstrun_o(self): CONF.set('run', ALWAYS_OPEN_FIRST_RUN_OPTION, self.firstrun_cb.isChecked())
def toggle_singletab(self, checked): """Toggle single tab mode""" CONF.set(self.ID, 'single_tab', checked)
def set_option(self, option, value): CONF.set(self.CONF_SECTION, option, value)