def sympy_config(): """Sympy configuration""" from SMlib.utils.programs import is_module_installed lines_new = """ from sympy.interactive import init_session init_session() """ lines_old = """ from __future__ import division from sympy import * x, y, z, t = symbols('x y z t') k, m, n = symbols('k m n', integer=True) f, g, h = symbols('f g h', cls=Function) """ if is_module_installed('sympy', '>=0.7.3'): extension = None return lines_new, extension elif is_module_installed('sympy', '=0.7.2'): extension = 'sympy.interactive.ipythonprinting' return lines_old, extension elif is_module_installed('sympy', '>=0.7.0;<0.7.2'): extension = 'sympyprinting' return lines_old, extension else: return None, None
def show_banner(self): """Banner for IPython widgets with pylab message""" from IPython.core.usage import default_gui_banner banner = default_gui_banner pylab_o = CONF.get('ipython_console', 'pylab', True) autoload_pylab_o = CONF.get('ipython_console', 'pylab/autoload', True) mpl_installed = programs.is_module_installed('matplotlib') if mpl_installed and (pylab_o and autoload_pylab_o): backend_o = CONF.get('ipython_console', 'pylab/backend', 0) backends = {0: 'module://IPython.zmq.pylab.backend_inline', 1: 'Qt4Agg', 2: 'Qt4Agg', 3: 'MacOSX', 4: 'GTKAgg', 5: 'WXAgg', 6: 'TKAgg'} pylab_013_message = """ Welcome to pylab, a matplotlib-based Python environment [backend: %s]. For more information, type 'help(pylab)'.\n""" % backends[backend_o] pylab_1_message = """ Populating the interactive namespace from numpy and matplotlib""" if programs.is_module_installed('IPython', '>=1.0'): banner = banner + pylab_1_message else: banner = banner + pylab_013_message sympy_o = CONF.get('ipython_console', 'symbolic_math', True) if sympy_o: lines = """ These commands were executed: >>> from __future__ import division >>> from sympy import * >>> x, y, z, t = symbols('x y z t') >>> k, m, n = symbols('k m n', integer=True) >>> f, g, h = symbols('f g h', cls=Function) """ banner = banner + lines return banner
def import_test(self): """Raise ImportError if feature is not supported""" from SMlib.utils import programs if not programs.is_module_installed('psutil', '>=0.2.0'): # The `interval` argument in `psutil.cpu_percent` function # was introduced in v0.2.0 raise ImportError
def setup_page(self): ar_group = QGroupBox(_("Autorefresh")) ar_box = self.create_checkbox(_("Enable autorefresh"), 'autorefresh') ar_spin = self.create_spinbox(_("Refresh interval: "), _(" ms"), 'autorefresh/timeout', min_=100, max_=1000000, step=100) filter_group = QGroupBox(_("Filter")) filter_data = [ ('exclude_private', _("Exclude private references")), ('exclude_capitalized', _("Exclude capitalized references")), ('exclude_uppercase', _("Exclude all-uppercase references")), ('exclude_unsupported', _("Exclude unsupported data types")), ] filter_boxes = [self.create_checkbox(text, option) for option, text in filter_data] display_group = QGroupBox(_("Display")) display_data = [ ('truncate', _("Truncate values"), ''), ('inplace', _("Always edit in-place"), ''), ('collvalue', _("Show collection contents"), ''), ] if programs.is_module_installed('numpy'): display_data.append(('minmax', _("Show arrays min/max"), '')) display_data.append( ('remote_editing', _("Edit data in the remote process"), _("Editors are opened in the remote process for NumPy " "arrays, PIL images, lists, tuples and dictionaries.\n" "This avoids transfering large amount of data between " "the remote process and Spyder (through the socket).")) ) display_boxes = [self.create_checkbox(text, option, tip=tip) for option, text, tip in display_data] ar_layout = QVBoxLayout() ar_layout.addWidget(ar_box) ar_layout.addWidget(ar_spin) ar_group.setLayout(ar_layout) filter_layout = QVBoxLayout() for box in filter_boxes: filter_layout.addWidget(box) filter_group.setLayout(filter_layout) display_layout = QVBoxLayout() for box in display_boxes: display_layout.addWidget(box) display_group.setLayout(display_layout) vlayout = QVBoxLayout() vlayout.addWidget(ar_group) vlayout.addWidget(filter_group) vlayout.addWidget(display_group) vlayout.addStretch(1) self.setLayout(vlayout)
def write_to_stdin(self, line): """ Send raw characters to the IPython kernel through stdin but only if the kernel is currently looking for raw input. """ if self._reading: if programs.is_module_installed('IPython', '>=1.0'): self.kernel_client.stdin_channel.input(line) else: self.kernel_manager.stdin_channel.input(line)
def create_module_bookmark_actions(parent, bookmarks): """ Create bookmark actions depending on module installation: bookmarks = ((module_name, url, title), ...) """ actions = [] for key, url, title in bookmarks: if programs.is_module_installed(key): act = create_bookmark_action(parent, url, title) actions.append(act) return actions
def show_banner(self): """Banner for IPython widgets with pylab message""" from IPython.core.usage import default_gui_banner banner = default_gui_banner pylab_o = CONF.get('ipython_console', 'pylab', True) autoload_pylab_o = CONF.get('ipython_console', 'pylab/autoload', True) mpl_installed = programs.is_module_installed('matplotlib') if mpl_installed and (pylab_o and autoload_pylab_o): backend_o = CONF.get('ipython_console', 'pylab/backend', 0) backends = { 0: 'module://IPython.zmq.pylab.backend_inline', 1: 'Qt4Agg', 2: 'Qt4Agg', 3: 'MacOSX', 4: 'GTKAgg', 5: 'WXAgg', 6: 'TKAgg' } pylab_013_message = """ Welcome to pylab, a matplotlib-based Python environment [backend: %s]. For more information, type 'help(pylab)'.\n""" % backends[backend_o] pylab_1_message = """ Populating the interactive namespace from numpy and matplotlib""" if programs.is_module_installed('IPython', '>=1.0'): banner = banner + pylab_1_message else: banner = banner + pylab_013_message sympy_o = CONF.get('ipython_console', 'symbolic_math', True) if sympy_o: lines = """ These commands were executed: >>> from __future__ import division >>> from sympy import * >>> x, y, z, t = symbols('x y z t') >>> k, m, n = symbols('k m n', integer=True) >>> f, g, h = symbols('f g h', cls=Function) """ banner = banner + lines return banner
def setup_page(self): sourcecode_group = QGroupBox(_("Source code")) wrap_mode_box = self.create_checkbox(_("Wrap lines"), 'wrap') names = CONF.get('color_schemes', 'names') choices = zip(names, names) cs_combo = self.create_combobox(_("Syntax color scheme: "), choices, 'color_scheme_name') sourcecode_layout = QVBoxLayout() sourcecode_layout.addWidget(wrap_mode_box) sourcecode_layout.addWidget(cs_combo) sourcecode_group.setLayout(sourcecode_layout) plain_text_font_group = self.create_fontgroup(option=None, text=_("Plain text font style"), fontfilters=QFontComboBox.MonospacedFonts) rich_text_font_group = self.create_fontgroup(option='rich_text', text=_("Rich text font style")) features_group = QGroupBox(_("Additional features")) math_box = self.create_checkbox(_("Render mathematical equations"), 'math') req_sphinx = sphinx_version is not None and \ programs.is_module_installed('sphinx', '>=1.1') math_box.setEnabled(req_sphinx) if not req_sphinx: sphinx_tip = _("This feature requires Sphinx 1.1 or superior.") if sphinx_version is not None: sphinx_tip += "\n" + _("Sphinx %s is currently installed." ) % sphinx_version math_box.setToolTip(sphinx_tip) features_layout = QVBoxLayout() features_layout.addWidget(math_box) features_group.setLayout(features_layout) vlayout = QVBoxLayout() vlayout.addWidget(rich_text_font_group) vlayout.addWidget(plain_text_font_group) vlayout.addWidget(features_group) vlayout.addWidget(sourcecode_group) vlayout.addStretch(1) self.setLayout(vlayout)
def setup_page(self): sourcecode_group = QGroupBox(_("Source code")) wrap_mode_box = self.create_checkbox(_("Wrap lines"), "wrap") names = CONF.get("color_schemes", "names") choices = zip(names, names) cs_combo = self.create_combobox(_("Syntax color scheme: "), choices, "color_scheme_name") sourcecode_layout = QVBoxLayout() sourcecode_layout.addWidget(wrap_mode_box) sourcecode_layout.addWidget(cs_combo) sourcecode_group.setLayout(sourcecode_layout) plain_text_font_group = self.create_fontgroup( option=None, text=_("Plain text font style"), fontfilters=QFontComboBox.MonospacedFonts ) rich_text_font_group = self.create_fontgroup(option="rich_text", text=_("Rich text font style")) features_group = QGroupBox(_("Additional features")) math_box = self.create_checkbox(_("Render mathematical equations"), "math") req_sphinx = sphinx_version is not None and programs.is_module_installed("sphinx", ">=1.1") math_box.setEnabled(req_sphinx) if not req_sphinx: sphinx_tip = _("This feature requires Sphinx 1.1 or superior.") if sphinx_version is not None: sphinx_tip += "\n" + _("Sphinx %s is currently installed.") % sphinx_version math_box.setToolTip(sphinx_tip) features_layout = QVBoxLayout() features_layout.addWidget(math_box) features_group.setLayout(features_layout) vlayout = QVBoxLayout() vlayout.addWidget(rich_text_font_group) vlayout.addWidget(plain_text_font_group) vlayout.addWidget(features_group) vlayout.addWidget(sourcecode_group) vlayout.addStretch(1) self.setLayout(vlayout)
def check(self): """Check if dependency is installed""" return programs.is_module_installed(self.modname, self.required_version, self.installed_version)
from SMlib.configs.baseconfig import get_conf_path, _ from SMlib.configs.ipythonconfig import IPYTHON_QT_MODULE, SUPPORTED_IPYTHON from SMlib.config import CONF from SMlib.configs.guiconfig import get_color_scheme, get_font, set_font from SMlib.utils import programs from SMlib.utils.qthelpers import get_icon, create_toolbutton, add_actions, create_action from SMlib.widgets.comboboxes import EditableComboBox from SMlib.widgets.sourcecode import codeeditor from SMlib.widgets.findreplace import FindReplace from SMlib.widgets.browser import WebView from SMlib.widgets.externalshell.pythonshell import ExtPythonShellWidget from SMlib.plugins import SMPluginWidget, PluginConfigPage # XXX: Hardcoded dependency on optional IPython plugin component # that requires the hack to make this work without IPython if programs.is_module_installed(IPYTHON_QT_MODULE, SUPPORTED_IPYTHON): from SMlib.widgets.ipython import IPythonControlWidget else: IPythonControlWidget = None # analysis:ignore # Check for Sphinx presence to activate rich text mode if programs.is_module_installed("sphinx", ">=0.6.6"): sphinx_version = programs.get_module_version("sphinx") from SMlib.utils.inspector.sphinxify import CSS_PATH, sphinxify, warning, generate_context else: sphinxify = sphinx_version = None # analysis:ignore # To add sphinx dependency to the Dependencies dialog SPHINX_REQVER = ">=0.6.6" dependencies.add("sphinx", _("Rich text help on the Object Inspector"), required_version=SPHINX_REQVER)
def is_pyflakes_installed(): """Return True if pyflakes required version is installed""" return programs.is_module_installed('pyflakes', PYFLAKES_REQVER)
def kernel_config(): """Create a config object with IPython kernel options""" from IPython.config.loader import Config, load_pyconfig_files from IPython.core.application import get_ipython_dir from SMlib.config import CONF from SMlib.utils.programs import is_module_installed # ---- IPython config ---- try: profile_path = osp.join(get_ipython_dir(), 'profile_default') ip_cfg = load_pyconfig_files( ['ipython_config.py', 'ipython_qtconsole_config.py'], profile_path) except: ip_cfg = Config() # ---- Spyder config ---- spy_cfg = Config() # Until we implement Issue 1052: # http://code.google.com/p/SMlib/issues/detail?id=1052 spy_cfg.InteractiveShell.xmode = 'Plain' # Pylab configuration mpl_installed = is_module_installed('matplotlib') pylab_o = CONF.get('ipython_console', 'pylab') if mpl_installed and pylab_o: backend_o = CONF.get('ipython_console', 'pylab/backend', 0) backends = { 0: 'inline', 1: 'auto', 2: 'qt', 3: 'osx', 4: 'gtk', 5: 'wx', 6: 'tk' } spy_cfg.IPKernelApp.pylab = backends[backend_o] # Automatically load Pylab and Numpy autoload_pylab_o = CONF.get('ipython_console', 'pylab/autoload') spy_cfg.IPKernelApp.pylab_import_all = autoload_pylab_o # Inline backend configuration if backends[backend_o] == 'inline': # Figure format format_o = CONF.get('ipython_console', 'pylab/inline/figure_format', 0) formats = {0: 'png', 1: 'svg'} spy_cfg.InlineBackend.figure_format = formats[format_o] # Resolution spy_cfg.InlineBackend.rc = { 'figure.figsize': (6.0, 4.0), 'savefig.dpi': 72, 'font.size': 10, 'figure.subplot.bottom': .125, 'figure.facecolor': 'white', 'figure.edgecolor': 'white' } resolution_o = CONF.get('ipython_console', 'pylab/inline/resolution') spy_cfg.InlineBackend.rc['savefig.dpi'] = resolution_o # Figure size width_o = float(CONF.get('ipython_console', 'pylab/inline/width')) height_o = float(CONF.get('ipython_console', 'pylab/inline/height')) spy_cfg.InlineBackend.rc['figure.figsize'] = (width_o, height_o) # Run lines of code at startup run_lines_o = CONF.get('ipython_console', 'startup/run_lines') if run_lines_o: spy_cfg.IPKernelApp.exec_lines = map(lambda x: x.strip(), run_lines_o.split(',')) # Run a file at startup use_file_o = CONF.get('ipython_console', 'startup/use_run_file') run_file_o = CONF.get('ipython_console', 'startup/run_file') if use_file_o and run_file_o: spy_cfg.IPKernelApp.file_to_run = run_file_o # Autocall autocall_o = CONF.get('ipython_console', 'autocall') spy_cfg.ZMQInteractiveShell.autocall = autocall_o # Greedy completer greedy_o = CONF.get('ipython_console', 'greedy_completer') spy_cfg.IPCompleter.greedy = greedy_o # Sympy loading sympy_o = CONF.get('ipython_console', 'symbolic_math') if sympy_o: lines, extension = sympy_config() if lines is not None: if run_lines_o: spy_cfg.IPKernelApp.exec_lines.append(lines) else: spy_cfg.IPKernelApp.exec_lines = [lines] if extension: spy_cfg.IPKernelApp.extra_extension = extension spy_cfg.LaTeXTool.backends = ['dvipng', 'matplotlib'] # Merge IPython and Spyder configs. Spyder prefs will have prevalence # over IPython ones ip_cfg._merge(spy_cfg) return ip_cfg
def setup_toolbar(self, exclude_private, exclude_uppercase, exclude_capitalized, exclude_unsupported, autorefresh): """Setup toolbar""" self.setup_in_progress = True toolbar = [] refresh_button = create_toolbutton(self, text=_("Refresh"), icon=get_icon('reload.png'), triggered=self.refresh_table) self.auto_refresh_button = create_toolbutton(self, text=_("Refresh periodically"), icon=get_icon('auto_reload.png'), toggled=self.toggle_auto_refresh) self.auto_refresh_button.setChecked(autorefresh) load_button = create_toolbutton(self, text=_("Import data"), icon=get_icon('fileimport.png'), triggered=self.import_data) self.save_button = create_toolbutton(self, text=_("Save data"), icon=get_icon('filesave.png'), triggered=lambda: self.save_data(self.filename)) self.save_button.setEnabled(False) save_as_button = create_toolbutton(self, text=_("Save data as..."), icon=get_icon('filesaveas.png'), triggered=self.save_data) toolbar += [refresh_button, self.auto_refresh_button, load_button, self.save_button, save_as_button] self.exclude_private_action = create_action(self, _("Exclude private references"), tip=_("Exclude references which name starts" " with an underscore"), toggled=lambda state: self.sig_option_changed.emit('exclude_private', state)) self.exclude_private_action.setChecked(exclude_private) self.exclude_uppercase_action = create_action(self, _("Exclude all-uppercase references"), tip=_("Exclude references which name is uppercase"), toggled=lambda state: self.sig_option_changed.emit('exclude_uppercase', state)) self.exclude_uppercase_action.setChecked(exclude_uppercase) self.exclude_capitalized_action = create_action(self, _("Exclude capitalized references"), tip=_("Exclude references which name starts with an " "uppercase character"), toggled=lambda state: self.sig_option_changed.emit('exclude_capitalized', state)) self.exclude_capitalized_action.setChecked(exclude_capitalized) self.exclude_unsupported_action = create_action(self, _("Exclude unsupported data types"), tip=_("Exclude references to unsupported data types" " (i.e. which won't be handled/saved correctly)"), toggled=lambda state: self.sig_option_changed.emit('exclude_unsupported', state)) self.exclude_unsupported_action.setChecked(exclude_unsupported) options_button = create_toolbutton(self, text=_("Options"), icon=get_icon('tooloptions.png')) toolbar.append(options_button) options_button.setPopupMode(QToolButton.InstantPopup) menu = QMenu(self) editor = self.editor actions = [self.exclude_private_action, self.exclude_uppercase_action, self.exclude_capitalized_action, self.exclude_unsupported_action, None, editor.truncate_action, editor.inplace_action, editor.collvalue_action] if is_module_installed('numpy'): actions.append(editor.minmax_action) if not self.is_internal_shell: actions.append(editor.remote_editing_action) add_actions(menu, actions) options_button.setMenu(menu) self.setup_in_progress = False return toolbar
# -*- coding: utf-8 -*- # # Copyright © 2013 The Spyder Development Team # Licensed under the terms of the MIT License # (see spyderlib/__init__.py for details) """ IPython configuration variables needed by Spyder """ from SMlib.utils import programs #============================================================================== # Constants #============================================================================== SUPPORTED_IPYTHON = '>=0.13' if programs.is_module_installed('IPython', '>=1.0'): IPYTHON_QT_MODULE = 'IPython.qt' else: IPYTHON_QT_MODULE = 'IPython.frontend.qt'
def __init__(self, parent): SMPluginWidget.__init__(self, parent) self.internal_shell = None # Initialize plugin self.initialize_plugin() self.no_doc_string = _("No documentation available") self._last_console_cb = None self._last_editor_cb = None self.set_default_color_scheme() self.plain_text = PlainText(self) self.rich_text = RichText(self) color_scheme = get_color_scheme(self.get_option('color_scheme_name')) self.set_plain_text_font(self.get_plugin_font(), color_scheme) self.plain_text.editor.toggle_wrap_mode(self.get_option('wrap')) # Add entries to read-only editor context-menu font_action = create_action(self, _("&Font..."), None, 'font.png', _("Set font style"), triggered=self.change_font) self.wrap_action = create_action(self, _("Wrap lines"), toggled=self.toggle_wrap_mode) self.wrap_action.setChecked(self.get_option('wrap')) self.plain_text.editor.readonly_menu.addSeparator() add_actions(self.plain_text.editor.readonly_menu, (font_action, self.wrap_action)) self.set_rich_text_font(self.get_plugin_font('rich_text')) self.shell = None self.external_console = None # locked = disable link with Console self.locked = False self._last_texts = [None, None] self._last_rope_data = None # Object name layout_edit = QHBoxLayout() layout_edit.setContentsMargins(0, 0, 0, 0) txt = _("Source") if sys.platform == 'darwin': source_label = QLabel(" " + txt) else: source_label = QLabel(txt) layout_edit.addWidget(source_label) self.source_combo = QComboBox(self) self.source_combo.addItems([_("Console"), _("Editor")]) self.connect(self.source_combo, SIGNAL('currentIndexChanged(int)'), self.source_changed) if not programs.is_module_installed('rope'): self.source_combo.hide() source_label.hide() layout_edit.addWidget(self.source_combo) layout_edit.addSpacing(10) layout_edit.addWidget(QLabel(_("Object"))) self.combo = ObjectComboBox(self) layout_edit.addWidget(self.combo) self.object_edit = QLineEdit(self) self.object_edit.setReadOnly(True) layout_edit.addWidget(self.object_edit) self.combo.setMaxCount(self.get_option('max_history_entries')) self.combo.addItems( self.load_history() ) self.connect(self.combo, SIGNAL("valid(bool)"), lambda valid: self.force_refresh()) # Plain text docstring option self.docstring = True self.rich_help = sphinxify is not None \ and self.get_option('rich_mode', True) self.plain_text_action = create_action(self, _("Plain Text"), toggled=self.toggle_plain_text) # Source code option self.show_source_action = create_action(self, _("Show Source"), toggled=self.toggle_show_source) # Rich text option self.rich_text_action = create_action(self, _("Rich Text"), toggled=self.toggle_rich_text) # Add the help actions to an exclusive QActionGroup help_actions = QActionGroup(self) help_actions.setExclusive(True) help_actions.addAction(self.plain_text_action) help_actions.addAction(self.rich_text_action) # Automatic import option self.auto_import_action = create_action(self, _("Automatic import"), toggled=self.toggle_auto_import) auto_import_state = self.get_option('automatic_import') self.auto_import_action.setChecked(auto_import_state) # Lock checkbox self.locked_button = create_toolbutton(self, triggered=self.toggle_locked) layout_edit.addWidget(self.locked_button) self._update_lock_icon() # Option menu options_button = create_toolbutton(self, text=_("Options"), icon=get_icon('tooloptions.png')) options_button.setPopupMode(QToolButton.InstantPopup) menu = QMenu(self) add_actions(menu, [self.rich_text_action, self.plain_text_action, self.show_source_action, None, self.auto_import_action]) options_button.setMenu(menu) layout_edit.addWidget(options_button) if self.rich_help: self.switch_to_rich_text() else: self.switch_to_plain_text() self.plain_text_action.setChecked(not self.rich_help) self.rich_text_action.setChecked(self.rich_help) self.rich_text_action.setEnabled(sphinxify is not None) self.source_changed() # Main layout layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addLayout(layout_edit) layout.addWidget(self.plain_text) layout.addWidget(self.rich_text) self.setLayout(layout) # Add worker thread for handling rich text rendering if sphinxify is None: self._sphinx_thread = None else: self._sphinx_thread = SphinxThread(text={}, html_text_no_doc=warning(self.no_doc_string), math_option=self.get_option('math')) self.connect(self._sphinx_thread, SIGNAL('html_ready(QString)'), self._on_sphinx_thread_html_ready) self.connect(self._sphinx_thread, SIGNAL('error_msg(QString)'), self._on_sphinx_thread_error_msg) self._starting_up = True
def setup_toolbar(self, exclude_private, exclude_uppercase, exclude_capitalized, exclude_unsupported, autorefresh): """Setup toolbar""" self.setup_in_progress = True toolbar = [] refresh_button = create_toolbutton(self, text=_("Refresh"), icon=get_icon('reload.png'), triggered=self.refresh_table) self.auto_refresh_button = create_toolbutton( self, text=_("Refresh periodically"), icon=get_icon('auto_reload.png'), toggled=self.toggle_auto_refresh) self.auto_refresh_button.setChecked(autorefresh) load_button = create_toolbutton(self, text=_("Import data"), icon=get_icon('fileimport.png'), triggered=self.import_data) self.save_button = create_toolbutton( self, text=_("Save data"), icon=get_icon('filesave.png'), triggered=lambda: self.save_data(self.filename)) self.save_button.setEnabled(False) save_as_button = create_toolbutton(self, text=_("Save data as..."), icon=get_icon('filesaveas.png'), triggered=self.save_data) toolbar += [ refresh_button, self.auto_refresh_button, load_button, self.save_button, save_as_button ] self.exclude_private_action = create_action( self, _("Exclude private references"), tip=_("Exclude references which name starts" " with an underscore"), toggled=lambda state: self.sig_option_changed.emit( 'exclude_private', state)) self.exclude_private_action.setChecked(exclude_private) self.exclude_uppercase_action = create_action( self, _("Exclude all-uppercase references"), tip=_("Exclude references which name is uppercase"), toggled=lambda state: self.sig_option_changed.emit( 'exclude_uppercase', state)) self.exclude_uppercase_action.setChecked(exclude_uppercase) self.exclude_capitalized_action = create_action( self, _("Exclude capitalized references"), tip=_("Exclude references which name starts with an " "uppercase character"), toggled=lambda state: self.sig_option_changed.emit( 'exclude_capitalized', state)) self.exclude_capitalized_action.setChecked(exclude_capitalized) self.exclude_unsupported_action = create_action( self, _("Exclude unsupported data types"), tip=_("Exclude references to unsupported data types" " (i.e. which won't be handled/saved correctly)"), toggled=lambda state: self.sig_option_changed.emit( 'exclude_unsupported', state)) self.exclude_unsupported_action.setChecked(exclude_unsupported) options_button = create_toolbutton(self, text=_("Options"), icon=get_icon('tooloptions.png')) toolbar.append(options_button) options_button.setPopupMode(QToolButton.InstantPopup) menu = QMenu(self) editor = self.editor actions = [ self.exclude_private_action, self.exclude_uppercase_action, self.exclude_capitalized_action, self.exclude_unsupported_action, None, editor.truncate_action, editor.inplace_action, editor.collvalue_action ] if is_module_installed('numpy'): actions.append(editor.minmax_action) if not self.is_internal_shell: actions.append(editor.remote_editing_action) add_actions(menu, actions) options_button.setMenu(menu) self.setup_in_progress = False return toolbar
from SMlib.configs.ipythonconfig import IPYTHON_QT_MODULE, SUPPORTED_IPYTHON from SMlib.config import CONF from SMlib.configs.guiconfig import get_color_scheme, get_font, set_font from SMlib.utils import programs from SMlib.utils.qthelpers import (get_icon, create_toolbutton, add_actions, create_action) from SMlib.widgets.comboboxes import EditableComboBox from SMlib.widgets.sourcecode import codeeditor from SMlib.widgets.findreplace import FindReplace from SMlib.widgets.browser import WebView from SMlib.widgets.externalshell.pythonshell import ExtPythonShellWidget from SMlib.plugins import SMPluginWidget, PluginConfigPage #XXX: Hardcoded dependency on optional IPython plugin component # that requires the hack to make this work without IPython if programs.is_module_installed(IPYTHON_QT_MODULE, SUPPORTED_IPYTHON): from SMlib.widgets.ipython import IPythonControlWidget else: IPythonControlWidget = None # analysis:ignore # Check for Sphinx presence to activate rich text mode if programs.is_module_installed('sphinx', '>=0.6.6'): sphinx_version = programs.get_module_version('sphinx') from SMlib.utils.inspector.sphinxify import (CSS_PATH, sphinxify, warning, generate_context) else: sphinxify = sphinx_version = None # analysis:ignore # To add sphinx dependency to the Dependencies dialog SPHINX_REQVER = '>=0.6.6' dependencies.add("sphinx", _("Rich text help on the Object Inspector"),
def setup_page(self): newcb = self.create_checkbox # --- Interface interface_group = QGroupBox(_("Interface")) styles = [str(txt) for txt in QStyleFactory.keys()] choices = zip(styles, [style.lower() for style in styles]) style_combo = self.create_combobox(_('Qt windows style'), choices, 'windows_style', default=self.main.default_style) single_instance_box = newcb(_("Use a single instance"), 'single_instance', tip=_("Set this to open external<br> " "Python files in an already running " "instance (Requires a restart)")) vertdock_box = newcb(_("Vertical dockwidget title bars"), 'vertical_dockwidget_titlebars') verttabs_box = newcb(_("Vertical dockwidget tabs"), 'vertical_tabs') animated_box = newcb(_("Animated toolbars and dockwidgets"), 'animated_docks') tear_off_box = newcb(_("Tear off menus"), 'tear_off_menus', tip=_("Set this to detach any<br> " "menu from the main window")) margin_box = newcb(_("Custom dockwidget margin:"), 'use_custom_margin') margin_spin = self.create_spinbox("", "pixels", 'custom_margin', 0, 0, 30) self.connect(margin_box, SIGNAL("toggled(bool)"), margin_spin.setEnabled) margin_spin.setEnabled(self.get_option('use_custom_margin')) margins_layout = QHBoxLayout() margins_layout.addWidget(margin_box) margins_layout.addWidget(margin_spin) # Decide if it's possible to activate or not singie instance mode if os.name == 'nt': pywin32_present = programs.is_module_installed('win32api') if not pywin32_present: self.set_option("single_instance", False) single_instance_box.setEnabled(False) tip = _("This feature requires the pywin32 module.\n" "It seems you don't have it installed.") single_instance_box.setToolTip(tip) elif sys.platform == "darwin" and 'Spyder.app' in __file__: self.set_option("single_instance", True) single_instance_box.setEnabled(False) interface_layout = QVBoxLayout() interface_layout.addWidget(style_combo) interface_layout.addWidget(single_instance_box) interface_layout.addWidget(vertdock_box) interface_layout.addWidget(verttabs_box) interface_layout.addWidget(animated_box) interface_layout.addWidget(tear_off_box) interface_layout.addLayout(margins_layout) interface_group.setLayout(interface_layout) # --- Status bar sbar_group = QGroupBox(_("Status bar")) memory_box = newcb(_("Show memory usage every"), 'memory_usage/enable', tip=self.main.mem_status.toolTip()) memory_spin = self.create_spinbox("", " ms", 'memory_usage/timeout', min_=100, max_=1000000, step=100) self.connect(memory_box, SIGNAL("toggled(bool)"), memory_spin.setEnabled) memory_spin.setEnabled(self.get_option('memory_usage/enable')) memory_layout = QHBoxLayout() memory_layout.addWidget(memory_box) memory_layout.addWidget(memory_spin) memory_layout.setEnabled(self.main.mem_status.is_supported()) cpu_box = newcb(_("Show CPU usage every"), 'cpu_usage/enable', tip=self.main.cpu_status.toolTip()) cpu_spin = self.create_spinbox("", " ms", 'cpu_usage/timeout', min_=100, max_=1000000, step=100) self.connect(cpu_box, SIGNAL("toggled(bool)"), cpu_spin.setEnabled) cpu_spin.setEnabled(self.get_option('cpu_usage/enable')) cpu_layout = QHBoxLayout() cpu_layout.addWidget(cpu_box) cpu_layout.addWidget(cpu_spin) cpu_layout.setEnabled(self.main.cpu_status.is_supported()) sbar_layout = QVBoxLayout() sbar_layout.addLayout(memory_layout) sbar_layout.addLayout(cpu_layout) sbar_group.setLayout(sbar_layout) # --- Debugging debug_group = QGroupBox(_("Debugging")) popup_console_box = newcb(_("Pop up internal console when internal " "errors appear"), 'show_internal_console_if_traceback', default=True) debug_layout = QVBoxLayout() debug_layout.addWidget(popup_console_box) debug_group.setLayout(debug_layout) vlayout = QVBoxLayout() vlayout.addWidget(interface_group) vlayout.addWidget(sbar_group) vlayout.addWidget(debug_group) vlayout.addStretch(1) self.setLayout(vlayout)
def kernel_config(): """Create a config object with IPython kernel options""" from IPython.config.loader import Config, load_pyconfig_files from IPython.core.application import get_ipython_dir from SMlib.config import CONF from SMlib.utils.programs import is_module_installed # ---- IPython config ---- try: profile_path = osp.join(get_ipython_dir(), 'profile_default') ip_cfg = load_pyconfig_files(['ipython_config.py', 'ipython_qtconsole_config.py'], profile_path) except: ip_cfg = Config() # ---- Spyder config ---- spy_cfg = Config() # Until we implement Issue 1052: # http://code.google.com/p/SMlib/issues/detail?id=1052 spy_cfg.InteractiveShell.xmode = 'Plain' # Pylab configuration mpl_installed = is_module_installed('matplotlib') pylab_o = CONF.get('ipython_console', 'pylab') if mpl_installed and pylab_o: backend_o = CONF.get('ipython_console', 'pylab/backend', 0) backends = {0: 'inline', 1: 'auto', 2: 'qt', 3: 'osx', 4: 'gtk', 5: 'wx', 6: 'tk'} spy_cfg.IPKernelApp.pylab = backends[backend_o] # Automatically load Pylab and Numpy autoload_pylab_o = CONF.get('ipython_console', 'pylab/autoload') spy_cfg.IPKernelApp.pylab_import_all = autoload_pylab_o # Inline backend configuration if backends[backend_o] == 'inline': # Figure format format_o = CONF.get('ipython_console', 'pylab/inline/figure_format', 0) formats = {0: 'png', 1: 'svg'} spy_cfg.InlineBackend.figure_format = formats[format_o] # Resolution spy_cfg.InlineBackend.rc = {'figure.figsize': (6.0, 4.0), 'savefig.dpi': 72, 'font.size': 10, 'figure.subplot.bottom': .125, 'figure.facecolor': 'white', 'figure.edgecolor': 'white' } resolution_o = CONF.get('ipython_console', 'pylab/inline/resolution') spy_cfg.InlineBackend.rc['savefig.dpi'] = resolution_o # Figure size width_o = float(CONF.get('ipython_console', 'pylab/inline/width')) height_o = float(CONF.get('ipython_console', 'pylab/inline/height')) spy_cfg.InlineBackend.rc['figure.figsize'] = (width_o, height_o) # Run lines of code at startup run_lines_o = CONF.get('ipython_console', 'startup/run_lines') if run_lines_o: spy_cfg.IPKernelApp.exec_lines = map(lambda x: x.strip(), run_lines_o.split(',')) # Run a file at startup use_file_o = CONF.get('ipython_console', 'startup/use_run_file') run_file_o = CONF.get('ipython_console', 'startup/run_file') if use_file_o and run_file_o: spy_cfg.IPKernelApp.file_to_run = run_file_o # Autocall autocall_o = CONF.get('ipython_console', 'autocall') spy_cfg.ZMQInteractiveShell.autocall = autocall_o # Greedy completer greedy_o = CONF.get('ipython_console', 'greedy_completer') spy_cfg.IPCompleter.greedy = greedy_o # Sympy loading sympy_o = CONF.get('ipython_console', 'symbolic_math') if sympy_o: lines, extension = sympy_config() if lines is not None: if run_lines_o: spy_cfg.IPKernelApp.exec_lines.append(lines) else: spy_cfg.IPKernelApp.exec_lines = [lines] if extension: spy_cfg.IPKernelApp.extra_extension = extension spy_cfg.LaTeXTool.backends = ['dvipng', 'matplotlib'] # Merge IPython and Spyder configs. Spyder prefs will have prevalence # over IPython ones ip_cfg._merge(spy_cfg) return ip_cfg
def setup_page(self): ar_group = QGroupBox(_("Autorefresh")) ar_box = self.create_checkbox(_("Enable autorefresh"), 'autorefresh') ar_spin = self.create_spinbox(_("Refresh interval: "), _(" ms"), 'autorefresh/timeout', min_=100, max_=1000000, step=100) filter_group = QGroupBox(_("Filter")) filter_data = [ ('exclude_private', _("Exclude private references")), ('exclude_capitalized', _("Exclude capitalized references")), ('exclude_uppercase', _("Exclude all-uppercase references")), ('exclude_unsupported', _("Exclude unsupported data types")), ] filter_boxes = [ self.create_checkbox(text, option) for option, text in filter_data ] display_group = QGroupBox(_("Display")) display_data = [ ('truncate', _("Truncate values"), ''), ('inplace', _("Always edit in-place"), ''), ('collvalue', _("Show collection contents"), ''), ] if programs.is_module_installed('numpy'): display_data.append(('minmax', _("Show arrays min/max"), '')) display_data.append( ('remote_editing', _("Edit data in the remote process"), _("Editors are opened in the remote process for NumPy " "arrays, PIL images, lists, tuples and dictionaries.\n" "This avoids transfering large amount of data between " "the remote process and Spyder (through the socket)."))) display_boxes = [ self.create_checkbox(text, option, tip=tip) for option, text, tip in display_data ] ar_layout = QVBoxLayout() ar_layout.addWidget(ar_box) ar_layout.addWidget(ar_spin) ar_group.setLayout(ar_layout) filter_layout = QVBoxLayout() for box in filter_boxes: filter_layout.addWidget(box) filter_group.setLayout(filter_layout) display_layout = QVBoxLayout() for box in display_boxes: display_layout.addWidget(box) display_group.setLayout(display_layout) vlayout = QVBoxLayout() vlayout.addWidget(ar_group) vlayout.addWidget(filter_group) vlayout.addWidget(display_group) vlayout.addStretch(1) self.setLayout(vlayout)
def __init__(self, parent): SMPluginWidget.__init__(self, parent) self.internal_shell = None # Initialize plugin self.initialize_plugin() self.no_doc_string = _("No documentation available") self._last_console_cb = None self._last_editor_cb = None self.set_default_color_scheme() self.plain_text = PlainText(self) self.rich_text = RichText(self) color_scheme = get_color_scheme(self.get_option("color_scheme_name")) self.set_plain_text_font(self.get_plugin_font(), color_scheme) self.plain_text.editor.toggle_wrap_mode(self.get_option("wrap")) # Add entries to read-only editor context-menu font_action = create_action( self, _("&Font..."), None, "font.png", _("Set font style"), triggered=self.change_font ) self.wrap_action = create_action(self, _("Wrap lines"), toggled=self.toggle_wrap_mode) self.wrap_action.setChecked(self.get_option("wrap")) self.plain_text.editor.readonly_menu.addSeparator() add_actions(self.plain_text.editor.readonly_menu, (font_action, self.wrap_action)) self.set_rich_text_font(self.get_plugin_font("rich_text")) self.shell = None self.external_console = None # locked = disable link with Console self.locked = False self._last_texts = [None, None] self._last_rope_data = None # Object name layout_edit = QHBoxLayout() layout_edit.setContentsMargins(0, 0, 0, 0) txt = _("Source") if sys.platform == "darwin": source_label = QLabel(" " + txt) else: source_label = QLabel(txt) layout_edit.addWidget(source_label) self.source_combo = QComboBox(self) self.source_combo.addItems([_("Console"), _("Editor")]) self.connect(self.source_combo, SIGNAL("currentIndexChanged(int)"), self.source_changed) if not programs.is_module_installed("rope"): self.source_combo.hide() source_label.hide() layout_edit.addWidget(self.source_combo) layout_edit.addSpacing(10) layout_edit.addWidget(QLabel(_("Object"))) self.combo = ObjectComboBox(self) layout_edit.addWidget(self.combo) self.object_edit = QLineEdit(self) self.object_edit.setReadOnly(True) layout_edit.addWidget(self.object_edit) self.combo.setMaxCount(self.get_option("max_history_entries")) self.combo.addItems(self.load_history()) self.connect(self.combo, SIGNAL("valid(bool)"), lambda valid: self.force_refresh()) # Plain text docstring option self.docstring = True self.rich_help = sphinxify is not None and self.get_option("rich_mode", True) self.plain_text_action = create_action(self, _("Plain Text"), toggled=self.toggle_plain_text) # Source code option self.show_source_action = create_action(self, _("Show Source"), toggled=self.toggle_show_source) # Rich text option self.rich_text_action = create_action(self, _("Rich Text"), toggled=self.toggle_rich_text) # Add the help actions to an exclusive QActionGroup help_actions = QActionGroup(self) help_actions.setExclusive(True) help_actions.addAction(self.plain_text_action) help_actions.addAction(self.rich_text_action) # Automatic import option self.auto_import_action = create_action(self, _("Automatic import"), toggled=self.toggle_auto_import) auto_import_state = self.get_option("automatic_import") self.auto_import_action.setChecked(auto_import_state) # Lock checkbox self.locked_button = create_toolbutton(self, triggered=self.toggle_locked) layout_edit.addWidget(self.locked_button) self._update_lock_icon() # Option menu options_button = create_toolbutton(self, text=_("Options"), icon=get_icon("tooloptions.png")) options_button.setPopupMode(QToolButton.InstantPopup) menu = QMenu(self) add_actions( menu, [self.rich_text_action, self.plain_text_action, self.show_source_action, None, self.auto_import_action], ) options_button.setMenu(menu) layout_edit.addWidget(options_button) if self.rich_help: self.switch_to_rich_text() else: self.switch_to_plain_text() self.plain_text_action.setChecked(not self.rich_help) self.rich_text_action.setChecked(self.rich_help) self.rich_text_action.setEnabled(sphinxify is not None) self.source_changed() # Main layout layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addLayout(layout_edit) layout.addWidget(self.plain_text) layout.addWidget(self.rich_text) self.setLayout(layout) # Add worker thread for handling rich text rendering if sphinxify is None: self._sphinx_thread = None else: self._sphinx_thread = SphinxThread( text={}, html_text_no_doc=warning(self.no_doc_string), math_option=self.get_option("math") ) self.connect(self._sphinx_thread, SIGNAL("html_ready(QString)"), self._on_sphinx_thread_html_ready) self.connect(self._sphinx_thread, SIGNAL("error_msg(QString)"), self._on_sphinx_thread_error_msg) self._starting_up = True