Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# then set them again as floating windows here.
for widget in self.floating_dockwidgets:
widget.setFloating(True)
# In MacOS X 10.7 our app is not displayed after initialized (I don't
# know why because this doesn't happen when started from the terminal),
# so we need to resort to this hack to make it appear.
if running_in_mac_app():
idx = __file__.index(MAC_APP_NAME)
app_path = __file__[:idx]
subprocess.call(['open', app_path + MAC_APP_NAME])
# Server to maintain just one Spyder instance and open files in it if
# the user tries to start other instances with
# $ spyder foo.py
if CONF.get('main', 'single_instance') and not self.new_instance:
t = threading.Thread(target=self.start_open_files_server)
t.setDaemon(True)
t.start()
# Connect the window to the signal emmited by the previous server
# when it gets a client connected to it
self.sig_open_external_file.connect(self.open_external_file)
# Create Plugins and toolbars submenus
self.create_plugins_menu()
self.create_toolbars_menu()
self.extconsole.setMinimumHeight(0)
# Update toolbar visibility status
self.toolbars_visible = CONF.get('main', 'toolbars_visible')
def apply_statusbar_settings(self):
"""Update status bar widgets settings"""
show_status_bar = CONF.get('main', 'show_status_bar')
self.statusBar().setVisible(show_status_bar)
if show_status_bar:
for widget, name in ((self.mem_status, 'memory_usage'),
(self.cpu_status, 'cpu_usage')):
if widget is not None:
widget.setVisible(CONF.get('main', '%s/enable' % name))
widget.set_interval(CONF.get('main', '%s/timeout' % name))
else:
return
def load_connection_settings(self):
"""Load the user's previously-saved kernel connection settings."""
existing_kernel = CONF.get("existing-kernel", "settings", {})
connection_file_path = existing_kernel.get("json_file_path", "")
is_remote = existing_kernel.get("is_remote", False)
username = existing_kernel.get("username", "")
hostname = existing_kernel.get("hostname", "")
port = str(existing_kernel.get("port", 22))
is_ssh_kf = existing_kernel.get("is_ssh_keyfile", False)
ssh_kf = existing_kernel.get("ssh_key_file_path", "")
if connection_file_path != "":
self.cf.setText(connection_file_path)
if username != "":
self.un.setText(username)
if hostname != "":
self.hn.setText(hostname)
if ssh_kf != "":
if self.get_option('pythonstartup/default'):
pythonstartup = None
else:
pythonstartup = self.get_option('pythonstartup', None)
monitor_enabled = self.get_option('monitor/enabled')
mpl_backend = self.get_option('matplotlib/backend/value')
ets_backend = self.get_option('ets_backend')
qt_api = self.get_option('qt/api')
if qt_api not in ('pyqt', 'pyside', 'pyqt5'):
qt_api = None
merge_output_channels = self.get_option('merge_output_channels')
colorize_sys_stderr = self.get_option('colorize_sys_stderr')
umr_enabled = CONF.get('main_interpreter', 'umr/enabled')
umr_namelist = CONF.get('main_interpreter', 'umr/namelist')
umr_verbose = CONF.get('main_interpreter', 'umr/verbose')
ar_timeout = CONF.get('variable_explorer', 'autorefresh/timeout')
ar_state = CONF.get('variable_explorer', 'autorefresh')
sa_settings = None
shellwidget = ExternalPythonShell(self, fname, wdir,
interact, debug, post_mortem=post_mortem,
path=pythonpath,
python_args=python_args,
arguments=args, stand_alone=sa_settings,
pythonstartup=pythonstartup,
pythonexecutable=pythonexecutable,
external_interpreter=external_interpreter,
umr_enabled=umr_enabled, umr_namelist=umr_namelist,
umr_verbose=umr_verbose, ets_backend=ets_backend,
monitor_enabled=monitor_enabled,
mpl_backend=mpl_backend, qt_api=qt_api,
merge_output_channels=merge_output_channels,
pythonexecutable = CONF.get('main_interpreter', 'executable')
external_interpreter = True
if self.get_option('pythonstartup/default'):
pythonstartup = None
else:
pythonstartup = self.get_option('pythonstartup', None)
monitor_enabled = self.get_option('monitor/enabled')
mpl_backend = self.get_option('matplotlib/backend/value')
ets_backend = self.get_option('ets_backend')
qt_api = self.get_option('qt/api')
if qt_api not in ('pyqt', 'pyside', 'pyqt5'):
qt_api = None
merge_output_channels = self.get_option('merge_output_channels')
colorize_sys_stderr = self.get_option('colorize_sys_stderr')
umr_enabled = CONF.get('main_interpreter', 'umr/enabled')
umr_namelist = CONF.get('main_interpreter', 'umr/namelist')
umr_verbose = CONF.get('main_interpreter', 'umr/verbose')
ar_timeout = CONF.get('variable_explorer', 'autorefresh/timeout')
ar_state = CONF.get('variable_explorer', 'autorefresh')
sa_settings = None
shellwidget = ExternalPythonShell(self, fname, wdir,
interact, debug, post_mortem=post_mortem,
path=pythonpath,
python_args=python_args,
arguments=args, stand_alone=sa_settings,
pythonstartup=pythonstartup,
pythonexecutable=pythonexecutable,
external_interpreter=external_interpreter,
umr_enabled=umr_enabled, umr_namelist=umr_namelist,
umr_verbose=umr_verbose, ets_backend=ets_backend,
monitor_enabled=monitor_enabled,
def apply_settings(self):
"""Apply settings changed in 'Preferences' dialog box"""
qapp = QApplication.instance()
# Set 'gtk+' as the default theme in Gtk-based desktops
# Fixes Issue 2036
if is_gtk_desktop() and ('GTK+' in QStyleFactory.keys()):
try:
qapp.setStyle('gtk+')
except:
pass
else:
qapp.setStyle(CONF.get('main', 'windows_style',
self.default_style))
default = self.DOCKOPTIONS
if CONF.get('main', 'vertical_tabs'):
default = default|QMainWindow.VerticalTabs
if CONF.get('main', 'animated_docks'):
default = default|QMainWindow.AnimatedDocks
self.setDockOptions(default)
self.apply_panes_settings()
self.apply_statusbar_settings()
if CONF.get('main', 'use_custom_caret_blinking') is True:
qapp.setCursorFlashTime(CONF.get('main', 'custom_caret_blinking'))
else:
qapp.setCursorFlashTime(QApplication.cursorFlashTime())
mpl_backend = backends[backend_o]
# Automatically load Pylab and Numpy, or only set Matplotlib
# backend
autoload_pylab_o = CONF.get('ipython_console', 'pylab/autoload')
if autoload_pylab_o:
spy_cfg.IPKernelApp.exec_lines.append(
"%pylab {0}".format(mpl_backend))
else:
spy_cfg.IPKernelApp.exec_lines.append(
"%matplotlib {0}".format(mpl_backend))
# Inline backend configuration
if mpl_backend == '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
if is_module_installed('ipykernel', '<4.5'):
dpi_option = 'savefig.dpi'
else:
dpi_option = 'figure.dpi'
spy_cfg.InlineBackend.rc = {'figure.figsize': (6.0, 4.0),
dpi_option: 72,
'font.size': 10,
'figure.subplot.bottom': .125,
'figure.facecolor': 'white',
'figure.edgecolor': 'white'}
def load_last_visible_toolbars(self):
"""Loads the last visible toolbars from the .ini file."""
toolbars_names = CONF.get('main', 'last_visible_toolbars', default=[])
if toolbars_names:
dic = {}
for toolbar in self.toolbarslist:
dic[toolbar.objectName()] = toolbar
toolbars = []
for name in toolbars_names:
if name in dic:
toolbars.append(dic[name])
self.visible_toolbars = toolbars
else:
self.get_visible_toolbars()
self._update_show_toolbars_action()
def apply_statusbar_settings(self):
"""Update status bar widgets settings"""
show_status_bar = CONF.get('main', 'show_status_bar')
self.statusBar().setVisible(show_status_bar)
if show_status_bar:
for widget, name in ((self.mem_status, 'memory_usage'),
(self.cpu_status, 'cpu_usage')):
if widget is not None:
widget.setVisible(CONF.get('main', '%s/enable' % name))
widget.set_interval(CONF.get('main', '%s/timeout' % name))
else:
return