repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1 value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
spyder-ide/spyder | spyder/app/mainwindow.py | setup_logging | def setup_logging(cli_options):
"""Setup logging with cli options defined by the user."""
if cli_options.debug_info or get_debug_level() > 0:
levels = {2: logging.INFO, 3: logging.DEBUG}
log_level = levels[get_debug_level()]
log_format = '%(asctime)s [%(levelname)s] [%(name)s] -> %(message)s'
if cli_options.debug_output == 'file':
log_file = 'spyder-debug.log'
else:
log_file = None
logging.basicConfig(level=log_level,
format=log_format,
filename=log_file,
filemode='w+') | python | def setup_logging(cli_options):
"""Setup logging with cli options defined by the user."""
if cli_options.debug_info or get_debug_level() > 0:
levels = {2: logging.INFO, 3: logging.DEBUG}
log_level = levels[get_debug_level()]
log_format = '%(asctime)s [%(levelname)s] [%(name)s] -> %(message)s'
if cli_options.debug_output == 'file':
log_file = 'spyder-debug.log'
else:
log_file = None
logging.basicConfig(level=log_level,
format=log_format,
filename=log_file,
filemode='w+') | [
"def",
"setup_logging",
"(",
"cli_options",
")",
":",
"if",
"cli_options",
".",
"debug_info",
"or",
"get_debug_level",
"(",
")",
">",
"0",
":",
"levels",
"=",
"{",
"2",
":",
"logging",
".",
"INFO",
",",
"3",
":",
"logging",
".",
"DEBUG",
"}",
"log_level",
"=",
"levels",
"[",
"get_debug_level",
"(",
")",
"]",
"log_format",
"=",
"'%(asctime)s [%(levelname)s] [%(name)s] -> %(message)s'",
"if",
"cli_options",
".",
"debug_output",
"==",
"'file'",
":",
"log_file",
"=",
"'spyder-debug.log'",
"else",
":",
"log_file",
"=",
"None",
"logging",
".",
"basicConfig",
"(",
"level",
"=",
"log_level",
",",
"format",
"=",
"log_format",
",",
"filename",
"=",
"log_file",
",",
"filemode",
"=",
"'w+'",
")"
] | Setup logging with cli options defined by the user. | [
"Setup",
"logging",
"with",
"cli",
"options",
"defined",
"by",
"the",
"user",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L233-L248 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | qt_message_handler | def qt_message_handler(msg_type, msg_log_context, msg_string):
"""
Qt warning messages are intercepted by this handler.
On some operating systems, warning messages might be displayed
even if the actual message does not apply. This filter adds a
blacklist for messages that are being printed for no apparent
reason. Anything else will get printed in the internal console.
In DEV mode, all messages are printed.
"""
BLACKLIST = [
'QMainWidget::resizeDocks: all sizes need to be larger than 0',
]
if DEV or msg_string not in BLACKLIST:
print(msg_string) | python | def qt_message_handler(msg_type, msg_log_context, msg_string):
"""
Qt warning messages are intercepted by this handler.
On some operating systems, warning messages might be displayed
even if the actual message does not apply. This filter adds a
blacklist for messages that are being printed for no apparent
reason. Anything else will get printed in the internal console.
In DEV mode, all messages are printed.
"""
BLACKLIST = [
'QMainWidget::resizeDocks: all sizes need to be larger than 0',
]
if DEV or msg_string not in BLACKLIST:
print(msg_string) | [
"def",
"qt_message_handler",
"(",
"msg_type",
",",
"msg_log_context",
",",
"msg_string",
")",
":",
"BLACKLIST",
"=",
"[",
"'QMainWidget::resizeDocks: all sizes need to be larger than 0'",
",",
"]",
"if",
"DEV",
"or",
"msg_string",
"not",
"in",
"BLACKLIST",
":",
"print",
"(",
"msg_string",
")"
] | Qt warning messages are intercepted by this handler.
On some operating systems, warning messages might be displayed
even if the actual message does not apply. This filter adds a
blacklist for messages that are being printed for no apparent
reason. Anything else will get printed in the internal console.
In DEV mode, all messages are printed. | [
"Qt",
"warning",
"messages",
"are",
"intercepted",
"by",
"this",
"handler",
".",
"On",
"some",
"operating",
"systems",
"warning",
"messages",
"might",
"be",
"displayed",
"even",
"if",
"the",
"actual",
"message",
"does",
"not",
"apply",
".",
"This",
"filter",
"adds",
"a",
"blacklist",
"for",
"messages",
"that",
"are",
"being",
"printed",
"for",
"no",
"apparent",
"reason",
".",
"Anything",
"else",
"will",
"get",
"printed",
"in",
"the",
"internal",
"console",
".",
"In",
"DEV",
"mode",
"all",
"messages",
"are",
"printed",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L251-L266 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | initialize | def initialize():
"""Initialize Qt, patching sys.exit and eventually setting up ETS"""
# This doesn't create our QApplication, just holds a reference to
# MAIN_APP, created above to show our splash screen as early as
# possible
app = qapplication()
# --- Set application icon
app.setWindowIcon(APP_ICON)
#----Monkey patching QApplication
class FakeQApplication(QApplication):
"""Spyder's fake QApplication"""
def __init__(self, args):
self = app # analysis:ignore
@staticmethod
def exec_():
"""Do nothing because the Qt mainloop is already running"""
pass
from qtpy import QtWidgets
QtWidgets.QApplication = FakeQApplication
# ----Monkey patching sys.exit
def fake_sys_exit(arg=[]):
pass
sys.exit = fake_sys_exit
# ----Monkey patching sys.excepthook to avoid crashes in PyQt 5.5+
if PYQT5:
def spy_excepthook(type_, value, tback):
sys.__excepthook__(type_, value, tback)
sys.excepthook = spy_excepthook
# Removing arguments from sys.argv as in standard Python interpreter
sys.argv = ['']
# Selecting Qt4 backend for Enthought Tool Suite (if installed)
try:
from enthought.etsconfig.api import ETSConfig
ETSConfig.toolkit = 'qt4'
except ImportError:
pass
return app | python | def initialize():
"""Initialize Qt, patching sys.exit and eventually setting up ETS"""
# This doesn't create our QApplication, just holds a reference to
# MAIN_APP, created above to show our splash screen as early as
# possible
app = qapplication()
# --- Set application icon
app.setWindowIcon(APP_ICON)
#----Monkey patching QApplication
class FakeQApplication(QApplication):
"""Spyder's fake QApplication"""
def __init__(self, args):
self = app # analysis:ignore
@staticmethod
def exec_():
"""Do nothing because the Qt mainloop is already running"""
pass
from qtpy import QtWidgets
QtWidgets.QApplication = FakeQApplication
# ----Monkey patching sys.exit
def fake_sys_exit(arg=[]):
pass
sys.exit = fake_sys_exit
# ----Monkey patching sys.excepthook to avoid crashes in PyQt 5.5+
if PYQT5:
def spy_excepthook(type_, value, tback):
sys.__excepthook__(type_, value, tback)
sys.excepthook = spy_excepthook
# Removing arguments from sys.argv as in standard Python interpreter
sys.argv = ['']
# Selecting Qt4 backend for Enthought Tool Suite (if installed)
try:
from enthought.etsconfig.api import ETSConfig
ETSConfig.toolkit = 'qt4'
except ImportError:
pass
return app | [
"def",
"initialize",
"(",
")",
":",
"# This doesn't create our QApplication, just holds a reference to\r",
"# MAIN_APP, created above to show our splash screen as early as\r",
"# possible\r",
"app",
"=",
"qapplication",
"(",
")",
"# --- Set application icon\r",
"app",
".",
"setWindowIcon",
"(",
"APP_ICON",
")",
"#----Monkey patching QApplication\r",
"class",
"FakeQApplication",
"(",
"QApplication",
")",
":",
"\"\"\"Spyder's fake QApplication\"\"\"",
"def",
"__init__",
"(",
"self",
",",
"args",
")",
":",
"self",
"=",
"app",
"# analysis:ignore\r",
"@",
"staticmethod",
"def",
"exec_",
"(",
")",
":",
"\"\"\"Do nothing because the Qt mainloop is already running\"\"\"",
"pass",
"from",
"qtpy",
"import",
"QtWidgets",
"QtWidgets",
".",
"QApplication",
"=",
"FakeQApplication",
"# ----Monkey patching sys.exit\r",
"def",
"fake_sys_exit",
"(",
"arg",
"=",
"[",
"]",
")",
":",
"pass",
"sys",
".",
"exit",
"=",
"fake_sys_exit",
"# ----Monkey patching sys.excepthook to avoid crashes in PyQt 5.5+\r",
"if",
"PYQT5",
":",
"def",
"spy_excepthook",
"(",
"type_",
",",
"value",
",",
"tback",
")",
":",
"sys",
".",
"__excepthook__",
"(",
"type_",
",",
"value",
",",
"tback",
")",
"sys",
".",
"excepthook",
"=",
"spy_excepthook",
"# Removing arguments from sys.argv as in standard Python interpreter\r",
"sys",
".",
"argv",
"=",
"[",
"''",
"]",
"# Selecting Qt4 backend for Enthought Tool Suite (if installed)\r",
"try",
":",
"from",
"enthought",
".",
"etsconfig",
".",
"api",
"import",
"ETSConfig",
"ETSConfig",
".",
"toolkit",
"=",
"'qt4'",
"except",
"ImportError",
":",
"pass",
"return",
"app"
] | Initialize Qt, patching sys.exit and eventually setting up ETS | [
"Initialize",
"Qt",
"patching",
"sys",
".",
"exit",
"and",
"eventually",
"setting",
"up",
"ETS"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L3210-L3253 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | run_spyder | def run_spyder(app, options, args):
"""
Create and show Spyder's main window
Start QApplication event loop
"""
#TODO: insert here
# Main window
main = MainWindow(options)
try:
main.setup()
except BaseException:
if main.console is not None:
try:
main.console.shell.exit_interpreter()
except BaseException:
pass
raise
main.show()
main.post_visible_setup()
if main.console:
main.console.shell.interpreter.namespace['spy'] = \
Spy(app=app, window=main)
# Open external files passed as args
if args:
for a in args:
main.open_external_file(a)
# Don't show icons in menus for Mac
if sys.platform == 'darwin':
QCoreApplication.setAttribute(Qt.AA_DontShowIconsInMenus, True)
# Open external files with our Mac app
if running_in_mac_app():
app.sig_open_external_file.connect(main.open_external_file)
# To give focus again to the last focused widget after restoring
# the window
app.focusChanged.connect(main.change_last_focused_widget)
if not running_under_pytest():
app.exec_()
return main | python | def run_spyder(app, options, args):
"""
Create and show Spyder's main window
Start QApplication event loop
"""
#TODO: insert here
# Main window
main = MainWindow(options)
try:
main.setup()
except BaseException:
if main.console is not None:
try:
main.console.shell.exit_interpreter()
except BaseException:
pass
raise
main.show()
main.post_visible_setup()
if main.console:
main.console.shell.interpreter.namespace['spy'] = \
Spy(app=app, window=main)
# Open external files passed as args
if args:
for a in args:
main.open_external_file(a)
# Don't show icons in menus for Mac
if sys.platform == 'darwin':
QCoreApplication.setAttribute(Qt.AA_DontShowIconsInMenus, True)
# Open external files with our Mac app
if running_in_mac_app():
app.sig_open_external_file.connect(main.open_external_file)
# To give focus again to the last focused widget after restoring
# the window
app.focusChanged.connect(main.change_last_focused_widget)
if not running_under_pytest():
app.exec_()
return main | [
"def",
"run_spyder",
"(",
"app",
",",
"options",
",",
"args",
")",
":",
"#TODO: insert here\r",
"# Main window\r",
"main",
"=",
"MainWindow",
"(",
"options",
")",
"try",
":",
"main",
".",
"setup",
"(",
")",
"except",
"BaseException",
":",
"if",
"main",
".",
"console",
"is",
"not",
"None",
":",
"try",
":",
"main",
".",
"console",
".",
"shell",
".",
"exit_interpreter",
"(",
")",
"except",
"BaseException",
":",
"pass",
"raise",
"main",
".",
"show",
"(",
")",
"main",
".",
"post_visible_setup",
"(",
")",
"if",
"main",
".",
"console",
":",
"main",
".",
"console",
".",
"shell",
".",
"interpreter",
".",
"namespace",
"[",
"'spy'",
"]",
"=",
"Spy",
"(",
"app",
"=",
"app",
",",
"window",
"=",
"main",
")",
"# Open external files passed as args\r",
"if",
"args",
":",
"for",
"a",
"in",
"args",
":",
"main",
".",
"open_external_file",
"(",
"a",
")",
"# Don't show icons in menus for Mac\r",
"if",
"sys",
".",
"platform",
"==",
"'darwin'",
":",
"QCoreApplication",
".",
"setAttribute",
"(",
"Qt",
".",
"AA_DontShowIconsInMenus",
",",
"True",
")",
"# Open external files with our Mac app\r",
"if",
"running_in_mac_app",
"(",
")",
":",
"app",
".",
"sig_open_external_file",
".",
"connect",
"(",
"main",
".",
"open_external_file",
")",
"# To give focus again to the last focused widget after restoring\r",
"# the window\r",
"app",
".",
"focusChanged",
".",
"connect",
"(",
"main",
".",
"change_last_focused_widget",
")",
"if",
"not",
"running_under_pytest",
"(",
")",
":",
"app",
".",
"exec_",
"(",
")",
"return",
"main"
] | Create and show Spyder's main window
Start QApplication event loop | [
"Create",
"and",
"show",
"Spyder",
"s",
"main",
"window",
"Start",
"QApplication",
"event",
"loop"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L3274-L3318 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | main | def main():
"""Main function"""
# **** For Pytest ****
# We need to create MainWindow **here** to avoid passing pytest
# options to Spyder
if running_under_pytest():
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock # Python 2
options = Mock()
options.working_directory = None
options.profile = False
options.multithreaded = False
options.new_instance = False
options.project = None
options.window_title = None
options.opengl_implementation = None
options.debug_info = None
options.debug_output = None
if CONF.get('main', 'opengl') != 'automatic':
option = CONF.get('main', 'opengl')
set_opengl_implementation(option)
app = initialize()
window = run_spyder(app, options, None)
return window
# **** Collect command line options ****
# Note regarding Options:
# It's important to collect options before monkey patching sys.exit,
# otherwise, argparse won't be able to exit if --help option is passed
options, args = get_options()
# **** Set OpenGL implementation to use ****
if options.opengl_implementation:
option = options.opengl_implementation
set_opengl_implementation(option)
else:
if CONF.get('main', 'opengl') != 'automatic':
option = CONF.get('main', 'opengl')
set_opengl_implementation(option)
# **** Handle hide_console option ****
if options.show_console:
print("(Deprecated) --show console does nothing, now the default "
" behavior is to show the console, use --hide-console if you "
"want to hide it")
if set_attached_console_visible is not None:
set_attached_console_visible(not options.hide_console
or options.reset_config_files
or options.reset_to_defaults
or options.optimize
or bool(get_debug_level()))
# **** Set debugging info ****
setup_logging(options)
# **** Create the application ****
app = initialize()
# **** Handle other options ****
if options.reset_config_files:
# <!> Remove all configuration files!
reset_config_files()
return
elif options.reset_to_defaults:
# Reset Spyder settings to defaults
CONF.reset_to_defaults(save=True)
return
elif options.optimize:
# Optimize the whole Spyder's source code directory
import spyder
programs.run_python_script(module="compileall",
args=[spyder.__path__[0]], p_args=['-O'])
return
# **** Show crash dialog ****
if CONF.get('main', 'crash', False) and not DEV:
CONF.set('main', 'crash', False)
if SPLASH is not None:
SPLASH.hide()
QMessageBox.information(
None, "Spyder",
"Spyder crashed during last session.<br><br>"
"If Spyder does not start at all and <u>before submitting a "
"bug report</u>, please try to reset settings to defaults by "
"running Spyder with the command line option '--reset':<br>"
"<span style=\'color: #555555\'><b>spyder --reset</b></span>"
"<br><br>"
"<span style=\'color: #ff5555\'><b>Warning:</b></span> "
"this command will remove all your Spyder configuration files "
"located in '%s').<br><br>"
"If Spyder still fails to launch, you should consult our "
"comprehensive <b><a href=\"%s\">Troubleshooting Guide</a></b>, "
"which when followed carefully solves the vast majority of "
"crashes; also, take "
"the time to search for <a href=\"%s\">known bugs</a> or "
"<a href=\"%s\">discussions</a> matching your situation before "
"submitting a report to our <a href=\"%s\">issue tracker</a>. "
"Your feedback will always be greatly appreciated."
"" % (get_conf_path(), __trouble_url__, __project_url__,
__forum_url__, __project_url__))
# **** Create main window ****
mainwindow = None
try:
mainwindow = run_spyder(app, options, args)
except FontError as fontError:
QMessageBox.information(None, "Spyder",
"Spyder was unable to load the <i>Spyder 3</i> "
"icon theme. That's why it's going to fallback to the "
"theme used in Spyder 2.<br><br>"
"For that, please close this window and start Spyder again.")
CONF.set('appearance', 'icon_theme', 'spyder 2')
except BaseException:
CONF.set('main', 'crash', True)
import traceback
traceback.print_exc(file=STDERR)
traceback.print_exc(file=open('spyder_crash.log', 'w'))
if mainwindow is None:
# An exception occured
if SPLASH is not None:
SPLASH.hide()
return
ORIGINAL_SYS_EXIT() | python | def main():
"""Main function"""
# **** For Pytest ****
# We need to create MainWindow **here** to avoid passing pytest
# options to Spyder
if running_under_pytest():
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock # Python 2
options = Mock()
options.working_directory = None
options.profile = False
options.multithreaded = False
options.new_instance = False
options.project = None
options.window_title = None
options.opengl_implementation = None
options.debug_info = None
options.debug_output = None
if CONF.get('main', 'opengl') != 'automatic':
option = CONF.get('main', 'opengl')
set_opengl_implementation(option)
app = initialize()
window = run_spyder(app, options, None)
return window
# **** Collect command line options ****
# Note regarding Options:
# It's important to collect options before monkey patching sys.exit,
# otherwise, argparse won't be able to exit if --help option is passed
options, args = get_options()
# **** Set OpenGL implementation to use ****
if options.opengl_implementation:
option = options.opengl_implementation
set_opengl_implementation(option)
else:
if CONF.get('main', 'opengl') != 'automatic':
option = CONF.get('main', 'opengl')
set_opengl_implementation(option)
# **** Handle hide_console option ****
if options.show_console:
print("(Deprecated) --show console does nothing, now the default "
" behavior is to show the console, use --hide-console if you "
"want to hide it")
if set_attached_console_visible is not None:
set_attached_console_visible(not options.hide_console
or options.reset_config_files
or options.reset_to_defaults
or options.optimize
or bool(get_debug_level()))
# **** Set debugging info ****
setup_logging(options)
# **** Create the application ****
app = initialize()
# **** Handle other options ****
if options.reset_config_files:
# <!> Remove all configuration files!
reset_config_files()
return
elif options.reset_to_defaults:
# Reset Spyder settings to defaults
CONF.reset_to_defaults(save=True)
return
elif options.optimize:
# Optimize the whole Spyder's source code directory
import spyder
programs.run_python_script(module="compileall",
args=[spyder.__path__[0]], p_args=['-O'])
return
# **** Show crash dialog ****
if CONF.get('main', 'crash', False) and not DEV:
CONF.set('main', 'crash', False)
if SPLASH is not None:
SPLASH.hide()
QMessageBox.information(
None, "Spyder",
"Spyder crashed during last session.<br><br>"
"If Spyder does not start at all and <u>before submitting a "
"bug report</u>, please try to reset settings to defaults by "
"running Spyder with the command line option '--reset':<br>"
"<span style=\'color: #555555\'><b>spyder --reset</b></span>"
"<br><br>"
"<span style=\'color: #ff5555\'><b>Warning:</b></span> "
"this command will remove all your Spyder configuration files "
"located in '%s').<br><br>"
"If Spyder still fails to launch, you should consult our "
"comprehensive <b><a href=\"%s\">Troubleshooting Guide</a></b>, "
"which when followed carefully solves the vast majority of "
"crashes; also, take "
"the time to search for <a href=\"%s\">known bugs</a> or "
"<a href=\"%s\">discussions</a> matching your situation before "
"submitting a report to our <a href=\"%s\">issue tracker</a>. "
"Your feedback will always be greatly appreciated."
"" % (get_conf_path(), __trouble_url__, __project_url__,
__forum_url__, __project_url__))
# **** Create main window ****
mainwindow = None
try:
mainwindow = run_spyder(app, options, args)
except FontError as fontError:
QMessageBox.information(None, "Spyder",
"Spyder was unable to load the <i>Spyder 3</i> "
"icon theme. That's why it's going to fallback to the "
"theme used in Spyder 2.<br><br>"
"For that, please close this window and start Spyder again.")
CONF.set('appearance', 'icon_theme', 'spyder 2')
except BaseException:
CONF.set('main', 'crash', True)
import traceback
traceback.print_exc(file=STDERR)
traceback.print_exc(file=open('spyder_crash.log', 'w'))
if mainwindow is None:
# An exception occured
if SPLASH is not None:
SPLASH.hide()
return
ORIGINAL_SYS_EXIT() | [
"def",
"main",
"(",
")",
":",
"# **** For Pytest ****\r",
"# We need to create MainWindow **here** to avoid passing pytest\r",
"# options to Spyder\r",
"if",
"running_under_pytest",
"(",
")",
":",
"try",
":",
"from",
"unittest",
".",
"mock",
"import",
"Mock",
"except",
"ImportError",
":",
"from",
"mock",
"import",
"Mock",
"# Python 2\r",
"options",
"=",
"Mock",
"(",
")",
"options",
".",
"working_directory",
"=",
"None",
"options",
".",
"profile",
"=",
"False",
"options",
".",
"multithreaded",
"=",
"False",
"options",
".",
"new_instance",
"=",
"False",
"options",
".",
"project",
"=",
"None",
"options",
".",
"window_title",
"=",
"None",
"options",
".",
"opengl_implementation",
"=",
"None",
"options",
".",
"debug_info",
"=",
"None",
"options",
".",
"debug_output",
"=",
"None",
"if",
"CONF",
".",
"get",
"(",
"'main'",
",",
"'opengl'",
")",
"!=",
"'automatic'",
":",
"option",
"=",
"CONF",
".",
"get",
"(",
"'main'",
",",
"'opengl'",
")",
"set_opengl_implementation",
"(",
"option",
")",
"app",
"=",
"initialize",
"(",
")",
"window",
"=",
"run_spyder",
"(",
"app",
",",
"options",
",",
"None",
")",
"return",
"window",
"# **** Collect command line options ****\r",
"# Note regarding Options:\r",
"# It's important to collect options before monkey patching sys.exit,\r",
"# otherwise, argparse won't be able to exit if --help option is passed\r",
"options",
",",
"args",
"=",
"get_options",
"(",
")",
"# **** Set OpenGL implementation to use ****\r",
"if",
"options",
".",
"opengl_implementation",
":",
"option",
"=",
"options",
".",
"opengl_implementation",
"set_opengl_implementation",
"(",
"option",
")",
"else",
":",
"if",
"CONF",
".",
"get",
"(",
"'main'",
",",
"'opengl'",
")",
"!=",
"'automatic'",
":",
"option",
"=",
"CONF",
".",
"get",
"(",
"'main'",
",",
"'opengl'",
")",
"set_opengl_implementation",
"(",
"option",
")",
"# **** Handle hide_console option ****\r",
"if",
"options",
".",
"show_console",
":",
"print",
"(",
"\"(Deprecated) --show console does nothing, now the default \"",
"\" behavior is to show the console, use --hide-console if you \"",
"\"want to hide it\"",
")",
"if",
"set_attached_console_visible",
"is",
"not",
"None",
":",
"set_attached_console_visible",
"(",
"not",
"options",
".",
"hide_console",
"or",
"options",
".",
"reset_config_files",
"or",
"options",
".",
"reset_to_defaults",
"or",
"options",
".",
"optimize",
"or",
"bool",
"(",
"get_debug_level",
"(",
")",
")",
")",
"# **** Set debugging info ****\r",
"setup_logging",
"(",
"options",
")",
"# **** Create the application ****\r",
"app",
"=",
"initialize",
"(",
")",
"# **** Handle other options ****\r",
"if",
"options",
".",
"reset_config_files",
":",
"# <!> Remove all configuration files!\r",
"reset_config_files",
"(",
")",
"return",
"elif",
"options",
".",
"reset_to_defaults",
":",
"# Reset Spyder settings to defaults\r",
"CONF",
".",
"reset_to_defaults",
"(",
"save",
"=",
"True",
")",
"return",
"elif",
"options",
".",
"optimize",
":",
"# Optimize the whole Spyder's source code directory\r",
"import",
"spyder",
"programs",
".",
"run_python_script",
"(",
"module",
"=",
"\"compileall\"",
",",
"args",
"=",
"[",
"spyder",
".",
"__path__",
"[",
"0",
"]",
"]",
",",
"p_args",
"=",
"[",
"'-O'",
"]",
")",
"return",
"# **** Show crash dialog ****\r",
"if",
"CONF",
".",
"get",
"(",
"'main'",
",",
"'crash'",
",",
"False",
")",
"and",
"not",
"DEV",
":",
"CONF",
".",
"set",
"(",
"'main'",
",",
"'crash'",
",",
"False",
")",
"if",
"SPLASH",
"is",
"not",
"None",
":",
"SPLASH",
".",
"hide",
"(",
")",
"QMessageBox",
".",
"information",
"(",
"None",
",",
"\"Spyder\"",
",",
"\"Spyder crashed during last session.<br><br>\"",
"\"If Spyder does not start at all and <u>before submitting a \"",
"\"bug report</u>, please try to reset settings to defaults by \"",
"\"running Spyder with the command line option '--reset':<br>\"",
"\"<span style=\\'color: #555555\\'><b>spyder --reset</b></span>\"",
"\"<br><br>\"",
"\"<span style=\\'color: #ff5555\\'><b>Warning:</b></span> \"",
"\"this command will remove all your Spyder configuration files \"",
"\"located in '%s').<br><br>\"",
"\"If Spyder still fails to launch, you should consult our \"",
"\"comprehensive <b><a href=\\\"%s\\\">Troubleshooting Guide</a></b>, \"",
"\"which when followed carefully solves the vast majority of \"",
"\"crashes; also, take \"",
"\"the time to search for <a href=\\\"%s\\\">known bugs</a> or \"",
"\"<a href=\\\"%s\\\">discussions</a> matching your situation before \"",
"\"submitting a report to our <a href=\\\"%s\\\">issue tracker</a>. \"",
"\"Your feedback will always be greatly appreciated.\"",
"\"\"",
"%",
"(",
"get_conf_path",
"(",
")",
",",
"__trouble_url__",
",",
"__project_url__",
",",
"__forum_url__",
",",
"__project_url__",
")",
")",
"# **** Create main window ****\r",
"mainwindow",
"=",
"None",
"try",
":",
"mainwindow",
"=",
"run_spyder",
"(",
"app",
",",
"options",
",",
"args",
")",
"except",
"FontError",
"as",
"fontError",
":",
"QMessageBox",
".",
"information",
"(",
"None",
",",
"\"Spyder\"",
",",
"\"Spyder was unable to load the <i>Spyder 3</i> \"",
"\"icon theme. That's why it's going to fallback to the \"",
"\"theme used in Spyder 2.<br><br>\"",
"\"For that, please close this window and start Spyder again.\"",
")",
"CONF",
".",
"set",
"(",
"'appearance'",
",",
"'icon_theme'",
",",
"'spyder 2'",
")",
"except",
"BaseException",
":",
"CONF",
".",
"set",
"(",
"'main'",
",",
"'crash'",
",",
"True",
")",
"import",
"traceback",
"traceback",
".",
"print_exc",
"(",
"file",
"=",
"STDERR",
")",
"traceback",
".",
"print_exc",
"(",
"file",
"=",
"open",
"(",
"'spyder_crash.log'",
",",
"'w'",
")",
")",
"if",
"mainwindow",
"is",
"None",
":",
"# An exception occured\r",
"if",
"SPLASH",
"is",
"not",
"None",
":",
"SPLASH",
".",
"hide",
"(",
")",
"return",
"ORIGINAL_SYS_EXIT",
"(",
")"
] | Main function | [
"Main",
"function"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L3324-L3453 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.create_toolbar | def create_toolbar(self, title, object_name, iconsize=24):
"""Create and return toolbar with *title* and *object_name*"""
toolbar = self.addToolBar(title)
toolbar.setObjectName(object_name)
toolbar.setIconSize(QSize(iconsize, iconsize))
self.toolbarslist.append(toolbar)
return toolbar | python | def create_toolbar(self, title, object_name, iconsize=24):
"""Create and return toolbar with *title* and *object_name*"""
toolbar = self.addToolBar(title)
toolbar.setObjectName(object_name)
toolbar.setIconSize(QSize(iconsize, iconsize))
self.toolbarslist.append(toolbar)
return toolbar | [
"def",
"create_toolbar",
"(",
"self",
",",
"title",
",",
"object_name",
",",
"iconsize",
"=",
"24",
")",
":",
"toolbar",
"=",
"self",
".",
"addToolBar",
"(",
"title",
")",
"toolbar",
".",
"setObjectName",
"(",
"object_name",
")",
"toolbar",
".",
"setIconSize",
"(",
"QSize",
"(",
"iconsize",
",",
"iconsize",
")",
")",
"self",
".",
"toolbarslist",
".",
"append",
"(",
"toolbar",
")",
"return",
"toolbar"
] | Create and return toolbar with *title* and *object_name* | [
"Create",
"and",
"return",
"toolbar",
"with",
"*",
"title",
"*",
"and",
"*",
"object_name",
"*"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L585-L591 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.setup | def setup(self):
"""Setup main window"""
logger.info("*** Start of MainWindow setup ***")
logger.info("Applying theme configuration...")
ui_theme = CONF.get('appearance', 'ui_theme')
color_scheme = CONF.get('appearance', 'selected')
if ui_theme == 'dark':
dark_qss = qdarkstyle.load_stylesheet_from_environment()
self.setStyleSheet(dark_qss)
self.statusBar().setStyleSheet(dark_qss)
css_path = DARK_CSS_PATH
elif ui_theme == 'automatic':
if not is_dark_font_color(color_scheme):
dark_qss = qdarkstyle.load_stylesheet_from_environment()
self.setStyleSheet(dark_qss)
self.statusBar().setStyleSheet(dark_qss)
css_path = DARK_CSS_PATH
else:
css_path = CSS_PATH
else:
css_path = CSS_PATH
logger.info("Creating core actions...")
self.close_dockwidget_action = create_action(
self, icon=ima.icon('close_pane'),
text=_("Close current pane"),
triggered=self.close_current_dockwidget,
context=Qt.ApplicationShortcut
)
self.register_shortcut(self.close_dockwidget_action, "_",
"Close pane")
self.lock_interface_action = create_action(
self,
_("Lock panes and toolbars"),
toggled=self.toggle_lock,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.lock_interface_action, "_",
"Lock unlock panes")
# custom layouts shortcuts
self.toggle_next_layout_action = create_action(self,
_("Use next layout"),
triggered=self.toggle_next_layout,
context=Qt.ApplicationShortcut)
self.toggle_previous_layout_action = create_action(self,
_("Use previous layout"),
triggered=self.toggle_previous_layout,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.toggle_next_layout_action, "_",
"Use next layout")
self.register_shortcut(self.toggle_previous_layout_action, "_",
"Use previous layout")
# File switcher shortcuts
self.file_switcher_action = create_action(
self,
_('File switcher...'),
icon=ima.icon('filelist'),
tip=_('Fast switch between files'),
triggered=self.open_fileswitcher,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.file_switcher_action, context="_",
name="File switcher")
self.symbol_finder_action = create_action(
self, _('Symbol finder...'),
icon=ima.icon('symbol_find'),
tip=_('Fast symbol search in file'),
triggered=self.open_symbolfinder,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.symbol_finder_action, context="_",
name="symbol finder", add_sc_to_tip=True)
self.file_toolbar_actions = [self.file_switcher_action,
self.symbol_finder_action]
def create_edit_action(text, tr_text, icon):
textseq = text.split(' ')
method_name = textseq[0].lower()+"".join(textseq[1:])
action = create_action(self, tr_text,
icon=icon,
triggered=self.global_callback,
data=method_name,
context=Qt.WidgetShortcut)
self.register_shortcut(action, "Editor", text)
return action
self.undo_action = create_edit_action('Undo', _('Undo'),
ima.icon('undo'))
self.redo_action = create_edit_action('Redo', _('Redo'),
ima.icon('redo'))
self.copy_action = create_edit_action('Copy', _('Copy'),
ima.icon('editcopy'))
self.cut_action = create_edit_action('Cut', _('Cut'),
ima.icon('editcut'))
self.paste_action = create_edit_action('Paste', _('Paste'),
ima.icon('editpaste'))
self.selectall_action = create_edit_action("Select All",
_("Select All"),
ima.icon('selectall'))
self.edit_menu_actions = [self.undo_action, self.redo_action,
None, self.cut_action, self.copy_action,
self.paste_action, self.selectall_action]
namespace = None
logger.info("Creating toolbars...")
# File menu/toolbar
self.file_menu = self.menuBar().addMenu(_("&File"))
self.file_toolbar = self.create_toolbar(_("File toolbar"),
"file_toolbar")
# Edit menu/toolbar
self.edit_menu = self.menuBar().addMenu(_("&Edit"))
self.edit_toolbar = self.create_toolbar(_("Edit toolbar"),
"edit_toolbar")
# Search menu/toolbar
self.search_menu = self.menuBar().addMenu(_("&Search"))
self.search_toolbar = self.create_toolbar(_("Search toolbar"),
"search_toolbar")
# Source menu/toolbar
self.source_menu = self.menuBar().addMenu(_("Sour&ce"))
self.source_toolbar = self.create_toolbar(_("Source toolbar"),
"source_toolbar")
# Run menu/toolbar
self.run_menu = self.menuBar().addMenu(_("&Run"))
self.run_toolbar = self.create_toolbar(_("Run toolbar"),
"run_toolbar")
# Debug menu/toolbar
self.debug_menu = self.menuBar().addMenu(_("&Debug"))
self.debug_toolbar = self.create_toolbar(_("Debug toolbar"),
"debug_toolbar")
# Consoles menu/toolbar
self.consoles_menu = self.menuBar().addMenu(_("C&onsoles"))
self.consoles_menu.aboutToShow.connect(
self.update_execution_state_kernel)
# Projects menu
self.projects_menu = self.menuBar().addMenu(_("&Projects"))
self.projects_menu.aboutToShow.connect(self.valid_project)
# Tools menu
self.tools_menu = self.menuBar().addMenu(_("&Tools"))
# View menu
self.view_menu = self.menuBar().addMenu(_("&View"))
# Help menu
self.help_menu = self.menuBar().addMenu(_("&Help"))
# Status bar
status = self.statusBar()
status.setObjectName("StatusBar")
status.showMessage(_("Welcome to Spyder!"), 5000)
logger.info("Creating Tools menu...")
# Tools + External Tools
prefs_action = create_action(self, _("Pre&ferences"),
icon=ima.icon('configure'),
triggered=self.edit_preferences,
context=Qt.ApplicationShortcut)
self.register_shortcut(prefs_action, "_", "Preferences",
add_sc_to_tip=True)
spyder_path_action = create_action(self,
_("PYTHONPATH manager"),
None, icon=ima.icon('pythonpath'),
triggered=self.path_manager_callback,
tip=_("Python Path Manager"),
menurole=QAction.ApplicationSpecificRole)
reset_spyder_action = create_action(
self, _("Reset Spyder to factory defaults"),
triggered=self.reset_spyder)
self.tools_menu_actions = [prefs_action, spyder_path_action]
if WinUserEnvDialog is not None:
winenv_action = create_action(self,
_("Current user environment variables..."),
icon='win_env.png',
tip=_("Show and edit current user environment "
"variables in Windows registry "
"(i.e. for all sessions)"),
triggered=self.win_env)
self.tools_menu_actions.append(winenv_action)
self.tools_menu_actions += [MENU_SEPARATOR, reset_spyder_action]
# External Tools submenu
self.external_tools_menu = QMenu(_("External Tools"))
self.external_tools_menu_actions = []
# WinPython control panel
self.wp_action = create_action(self, _("WinPython control panel"),
icon=get_icon('winpython.svg'),
triggered=lambda:
programs.run_python_script('winpython', 'controlpanel'))
if os.name == 'nt' and is_module_installed('winpython'):
self.external_tools_menu_actions.append(self.wp_action)
# Qt-related tools
additact = []
for name in ("designer-qt4", "designer"):
qtdact = create_program_action(self, _("Qt Designer"), name)
if qtdact:
break
for name in ("linguist-qt4", "linguist"):
qtlact = create_program_action(self, _("Qt Linguist"), "linguist")
if qtlact:
break
args = ['-no-opengl'] if os.name == 'nt' else []
for act in (qtdact, qtlact):
if act:
additact.append(act)
if additact and is_module_installed('winpython'):
self.external_tools_menu_actions += [None] + additact
# Guidata and Sift
logger.info("Creating guidata and sift entries...")
gdgq_act = []
# Guidata and Guiqwt don't support PyQt5 yet and they fail
# with an AssertionError when imported using those bindings
# (see issue 2274)
try:
from guidata import configtools
from guidata import config # analysis:ignore
guidata_icon = configtools.get_icon('guidata.svg')
guidata_act = create_python_script_action(self,
_("guidata examples"), guidata_icon,
"guidata",
osp.join("tests", "__init__"))
gdgq_act += [guidata_act]
except:
pass
try:
from guidata import configtools
from guiqwt import config # analysis:ignore
guiqwt_icon = configtools.get_icon('guiqwt.svg')
guiqwt_act = create_python_script_action(self,
_("guiqwt examples"), guiqwt_icon, "guiqwt",
osp.join("tests", "__init__"))
if guiqwt_act:
gdgq_act += [guiqwt_act]
sift_icon = configtools.get_icon('sift.svg')
sift_act = create_python_script_action(self, _("Sift"),
sift_icon, "guiqwt", osp.join("tests", "sift"))
if sift_act:
gdgq_act += [sift_act]
except:
pass
if gdgq_act:
self.external_tools_menu_actions += [None] + gdgq_act
# Maximize current plugin
self.maximize_action = create_action(self, '',
triggered=self.maximize_dockwidget,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.maximize_action, "_", "Maximize pane")
self.__update_maximize_action()
# Fullscreen mode
self.fullscreen_action = create_action(self,
_("Fullscreen mode"),
triggered=self.toggle_fullscreen,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.fullscreen_action, "_",
"Fullscreen mode", add_sc_to_tip=True)
# Main toolbar
self.main_toolbar_actions = [self.maximize_action,
self.fullscreen_action,
None,
prefs_action, spyder_path_action]
self.main_toolbar = self.create_toolbar(_("Main toolbar"),
"main_toolbar")
# Internal console plugin
logger.info("Loading internal console...")
from spyder.plugins.console.plugin import Console
self.console = Console(self, namespace, exitfunc=self.closing,
profile=self.profile,
multithreaded=self.multithreaded,
message=_("Spyder Internal Console\n\n"
"This console is used to report application\n"
"internal errors and to inspect Spyder\n"
"internals with the following commands:\n"
" spy.app, spy.window, dir(spy)\n\n"
"Please don't use it to run your code\n\n"))
self.console.register_plugin()
# Language Server Protocol Client initialization
self.set_splash(_("Starting Language Server Protocol manager..."))
from spyder.plugins.editor.lsp.manager import LSPManager
self.lspmanager = LSPManager(self)
# Working directory plugin
logger.info("Loading working directory...")
from spyder.plugins.workingdirectory.plugin import WorkingDirectory
self.workingdirectory = WorkingDirectory(self, self.init_workdir, main=self)
self.workingdirectory.register_plugin()
self.toolbarslist.append(self.workingdirectory.toolbar)
# Help plugin
if CONF.get('help', 'enable'):
self.set_splash(_("Loading help..."))
from spyder.plugins.help.plugin import Help
self.help = Help(self, css_path=css_path)
self.help.register_plugin()
# Outline explorer widget
if CONF.get('outline_explorer', 'enable'):
self.set_splash(_("Loading outline explorer..."))
from spyder.plugins.outlineexplorer.plugin import OutlineExplorer
self.outlineexplorer = OutlineExplorer(self)
self.outlineexplorer.register_plugin()
# Editor plugin
self.set_splash(_("Loading editor..."))
from spyder.plugins.editor.plugin import Editor
self.editor = Editor(self)
self.editor.register_plugin()
# Start LSP client
self.set_splash(_("Launching LSP Client for Python..."))
self.lspmanager.start_client(language='python')
# Populating file menu entries
quit_action = create_action(self, _("&Quit"),
icon=ima.icon('exit'),
tip=_("Quit"),
triggered=self.console.quit,
context=Qt.ApplicationShortcut)
self.register_shortcut(quit_action, "_", "Quit")
restart_action = create_action(self, _("&Restart"),
icon=ima.icon('restart'),
tip=_("Restart"),
triggered=self.restart,
context=Qt.ApplicationShortcut)
self.register_shortcut(restart_action, "_", "Restart")
self.file_menu_actions += [self.file_switcher_action,
self.symbol_finder_action, None,
restart_action, quit_action]
self.set_splash("")
# Namespace browser
self.set_splash(_("Loading namespace browser..."))
from spyder.plugins.variableexplorer.plugin import VariableExplorer
self.variableexplorer = VariableExplorer(self)
self.variableexplorer.register_plugin()
# Figure browser
self.set_splash(_("Loading figure browser..."))
from spyder.plugins.plots.plugin import Plots
self.plots = Plots(self)
self.plots.register_plugin()
# History log widget
if CONF.get('historylog', 'enable'):
self.set_splash(_("Loading history plugin..."))
from spyder.plugins.history.plugin import HistoryLog
self.historylog = HistoryLog(self)
self.historylog.register_plugin()
# IPython console
self.set_splash(_("Loading IPython console..."))
from spyder.plugins.ipythonconsole.plugin import IPythonConsole
self.ipyconsole = IPythonConsole(self, css_path=css_path)
self.ipyconsole.register_plugin()
# Explorer
if CONF.get('explorer', 'enable'):
self.set_splash(_("Loading file explorer..."))
from spyder.plugins.explorer.plugin import Explorer
self.explorer = Explorer(self)
self.explorer.register_plugin()
# Online help widget
try: # Qt >= v4.4
from spyder.plugins.onlinehelp.plugin import OnlineHelp
except ImportError: # Qt < v4.4
OnlineHelp = None # analysis:ignore
if CONF.get('onlinehelp', 'enable') and OnlineHelp is not None:
self.set_splash(_("Loading online help..."))
self.onlinehelp = OnlineHelp(self)
self.onlinehelp.register_plugin()
# Project explorer widget
self.set_splash(_("Loading project explorer..."))
from spyder.plugins.projects.plugin import Projects
self.projects = Projects(self)
self.projects.register_plugin()
self.project_path = self.projects.get_pythonpath(at_start=True)
# Find in files
if CONF.get('find_in_files', 'enable'):
from spyder.plugins.findinfiles.plugin import FindInFiles
self.findinfiles = FindInFiles(self)
self.findinfiles.register_plugin()
# Load other plugins (former external plugins)
# TODO: Use this bucle to load all internall plugins and remove
# duplicated code
other_plugins = ['breakpoints', 'profiler', 'pylint']
for plugin_name in other_plugins:
if CONF.get(plugin_name, 'enable'):
module = importlib.import_module(
'spyder.plugins.{}'.format(plugin_name))
plugin = module.PLUGIN_CLASS(self)
if plugin.check_compatibility()[0]:
self.thirdparty_plugins.append(plugin)
plugin.register_plugin()
# Third-party plugins
self.set_splash(_("Loading third-party plugins..."))
for mod in get_spyderplugins_mods():
try:
plugin = mod.PLUGIN_CLASS(self)
if plugin.check_compatibility()[0]:
self.thirdparty_plugins.append(plugin)
plugin.register_plugin()
except Exception as error:
print("%s: %s" % (mod, str(error)), file=STDERR)
traceback.print_exc(file=STDERR)
self.set_splash(_("Setting up main window..."))
# Help menu
trouble_action = create_action(self,
_("Troubleshooting..."),
triggered=self.trouble_guide)
dep_action = create_action(self, _("Dependencies..."),
triggered=self.show_dependencies,
icon=ima.icon('advanced'))
report_action = create_action(self,
_("Report issue..."),
icon=ima.icon('bug'),
triggered=self.report_issue)
support_action = create_action(self,
_("Spyder support..."),
triggered=self.google_group)
self.check_updates_action = create_action(self,
_("Check for updates..."),
triggered=self.check_updates)
# Spyder documentation
spyder_doc = 'https://docs.spyder-ide.org/'
doc_action = create_action(self, _("Spyder documentation"),
icon=ima.icon('DialogHelpButton'),
triggered=lambda:
programs.start_file(spyder_doc))
self.register_shortcut(doc_action, "_",
"spyder documentation")
if self.help is not None:
tut_action = create_action(self, _("Spyder tutorial"),
triggered=self.help.show_tutorial)
else:
tut_action = None
shortcuts_action = create_action(self, _("Shortcuts Summary"),
shortcut="Meta+F1",
triggered=self.show_shortcuts_dialog)
#----- Tours
self.tour = tour.AnimatedTour(self)
self.tours_menu = QMenu(_("Interactive tours"), self)
self.tour_menu_actions = []
# TODO: Only show intro tour for now. When we are close to finish
# 3.0, we will finish and show the other tour
self.tours_available = tour.get_tours(0)
for i, tour_available in enumerate(self.tours_available):
self.tours_available[i]['last'] = 0
tour_name = tour_available['name']
def trigger(i=i, self=self): # closure needed!
return lambda: self.show_tour(i)
temp_action = create_action(self, tour_name, tip="",
triggered=trigger())
self.tour_menu_actions += [temp_action]
self.tours_menu.addActions(self.tour_menu_actions)
self.help_menu_actions = [doc_action, tut_action, shortcuts_action,
self.tours_menu,
MENU_SEPARATOR, trouble_action,
report_action, dep_action,
self.check_updates_action, support_action,
MENU_SEPARATOR]
# Python documentation
if get_python_doc_path() is not None:
pydoc_act = create_action(self, _("Python documentation"),
triggered=lambda:
programs.start_file(get_python_doc_path()))
self.help_menu_actions.append(pydoc_act)
# IPython documentation
if self.help is not None:
ipython_menu = QMenu(_("IPython documentation"), self)
intro_action = create_action(self, _("Intro to IPython"),
triggered=self.ipyconsole.show_intro)
quickref_action = create_action(self, _("Quick reference"),
triggered=self.ipyconsole.show_quickref)
guiref_action = create_action(self, _("Console help"),
triggered=self.ipyconsole.show_guiref)
add_actions(ipython_menu, (intro_action, guiref_action,
quickref_action))
self.help_menu_actions.append(ipython_menu)
# Windows-only: documentation located in sys.prefix/Doc
ipm_actions = []
def add_ipm_action(text, path):
"""Add installed Python module doc action to help submenu"""
# QAction.triggered works differently for PySide and PyQt
path = file_uri(path)
if not API == 'pyside':
slot=lambda _checked, path=path: programs.start_file(path)
else:
slot=lambda path=path: programs.start_file(path)
action = create_action(self, text,
icon='%s.png' % osp.splitext(path)[1][1:],
triggered=slot)
ipm_actions.append(action)
sysdocpth = osp.join(sys.prefix, 'Doc')
if osp.isdir(sysdocpth): # exists on Windows, except frozen dist.
for docfn in os.listdir(sysdocpth):
pt = r'([a-zA-Z\_]*)(doc)?(-dev)?(-ref)?(-user)?.(chm|pdf)'
match = re.match(pt, docfn)
if match is not None:
pname = match.groups()[0]
if pname not in ('Python', ):
add_ipm_action(pname, osp.join(sysdocpth, docfn))
# Installed Python modules submenu (Windows only)
if ipm_actions:
pymods_menu = QMenu(_("Installed Python modules"), self)
add_actions(pymods_menu, ipm_actions)
self.help_menu_actions.append(pymods_menu)
# Online documentation
web_resources = QMenu(_("Online documentation"), self)
webres_actions = create_module_bookmark_actions(self,
self.BOOKMARKS)
webres_actions.insert(2, None)
webres_actions.insert(5, None)
webres_actions.insert(8, None)
add_actions(web_resources, webres_actions)
self.help_menu_actions.append(web_resources)
# Qt assistant link
if sys.platform.startswith('linux') and not PYQT5:
qta_exe = "assistant-qt4"
else:
qta_exe = "assistant"
qta_act = create_program_action(self, _("Qt documentation"),
qta_exe)
if qta_act:
self.help_menu_actions += [qta_act, None]
# About Spyder
about_action = create_action(self,
_("About %s...") % "Spyder",
icon=ima.icon('MessageBoxInformation'),
triggered=self.about)
self.help_menu_actions += [MENU_SEPARATOR, about_action]
# Status bar widgets
from spyder.widgets.status import MemoryStatus, CPUStatus
self.mem_status = MemoryStatus(self, status)
self.cpu_status = CPUStatus(self, status)
self.apply_statusbar_settings()
# ----- View
# View menu
self.plugins_menu = QMenu(_("Panes"), self)
self.toolbars_menu = QMenu(_("Toolbars"), self)
self.quick_layout_menu = QMenu(_("Window layouts"), self)
self.quick_layout_set_menu()
self.view_menu.addMenu(self.plugins_menu) # Panes
add_actions(self.view_menu, (self.lock_interface_action,
self.close_dockwidget_action,
self.maximize_action,
MENU_SEPARATOR))
self.show_toolbars_action = create_action(self,
_("Show toolbars"),
triggered=self.show_toolbars,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.show_toolbars_action, "_",
"Show toolbars")
self.view_menu.addMenu(self.toolbars_menu)
self.view_menu.addAction(self.show_toolbars_action)
add_actions(self.view_menu, (MENU_SEPARATOR,
self.quick_layout_menu,
self.toggle_previous_layout_action,
self.toggle_next_layout_action,
MENU_SEPARATOR,
self.fullscreen_action))
if set_attached_console_visible is not None:
cmd_act = create_action(self,
_("Attached console window (debugging)"),
toggled=set_attached_console_visible)
cmd_act.setChecked(is_attached_console_visible())
add_actions(self.view_menu, (MENU_SEPARATOR, cmd_act))
# Adding external tools action to "Tools" menu
if self.external_tools_menu_actions:
external_tools_act = create_action(self, _("External Tools"))
external_tools_act.setMenu(self.external_tools_menu)
self.tools_menu_actions += [None, external_tools_act]
# Filling out menu/toolbar entries:
add_actions(self.file_menu, self.file_menu_actions)
add_actions(self.edit_menu, self.edit_menu_actions)
add_actions(self.search_menu, self.search_menu_actions)
add_actions(self.source_menu, self.source_menu_actions)
add_actions(self.run_menu, self.run_menu_actions)
add_actions(self.debug_menu, self.debug_menu_actions)
add_actions(self.consoles_menu, self.consoles_menu_actions)
add_actions(self.projects_menu, self.projects_menu_actions)
add_actions(self.tools_menu, self.tools_menu_actions)
add_actions(self.external_tools_menu,
self.external_tools_menu_actions)
add_actions(self.help_menu, self.help_menu_actions)
add_actions(self.main_toolbar, self.main_toolbar_actions)
add_actions(self.file_toolbar, self.file_toolbar_actions)
add_actions(self.edit_toolbar, self.edit_toolbar_actions)
add_actions(self.search_toolbar, self.search_toolbar_actions)
add_actions(self.source_toolbar, self.source_toolbar_actions)
add_actions(self.debug_toolbar, self.debug_toolbar_actions)
add_actions(self.run_toolbar, self.run_toolbar_actions)
# Apply all defined shortcuts (plugins + 3rd-party plugins)
self.apply_shortcuts()
# Emitting the signal notifying plugins that main window menu and
# toolbar actions are all defined:
self.all_actions_defined.emit()
# Window set-up
logger.info("Setting up window...")
self.setup_layout(default=False)
# Show and hide shortcuts in menus for Mac.
# This is a workaround because we can't disable shortcuts
# by setting context=Qt.WidgetShortcut there
if sys.platform == 'darwin':
for name in ['file', 'edit', 'search', 'source', 'run', 'debug',
'projects', 'tools', 'plugins']:
menu_object = getattr(self, name + '_menu')
menu_object.aboutToShow.connect(
lambda name=name: self.show_shortcuts(name))
menu_object.aboutToHide.connect(
lambda name=name: self.hide_shortcuts(name))
if self.splash is not None:
self.splash.hide()
# Enabling tear off for all menus except help menu
if CONF.get('main', 'tear_off_menus'):
for child in self.menuBar().children():
if isinstance(child, QMenu) and child != self.help_menu:
child.setTearOffEnabled(True)
# Menu about to show
for child in self.menuBar().children():
if isinstance(child, QMenu):
try:
child.aboutToShow.connect(self.update_edit_menu)
child.aboutToShow.connect(self.update_search_menu)
except TypeError:
pass
logger.info("*** End of MainWindow setup ***")
self.is_starting_up = False | python | def setup(self):
"""Setup main window"""
logger.info("*** Start of MainWindow setup ***")
logger.info("Applying theme configuration...")
ui_theme = CONF.get('appearance', 'ui_theme')
color_scheme = CONF.get('appearance', 'selected')
if ui_theme == 'dark':
dark_qss = qdarkstyle.load_stylesheet_from_environment()
self.setStyleSheet(dark_qss)
self.statusBar().setStyleSheet(dark_qss)
css_path = DARK_CSS_PATH
elif ui_theme == 'automatic':
if not is_dark_font_color(color_scheme):
dark_qss = qdarkstyle.load_stylesheet_from_environment()
self.setStyleSheet(dark_qss)
self.statusBar().setStyleSheet(dark_qss)
css_path = DARK_CSS_PATH
else:
css_path = CSS_PATH
else:
css_path = CSS_PATH
logger.info("Creating core actions...")
self.close_dockwidget_action = create_action(
self, icon=ima.icon('close_pane'),
text=_("Close current pane"),
triggered=self.close_current_dockwidget,
context=Qt.ApplicationShortcut
)
self.register_shortcut(self.close_dockwidget_action, "_",
"Close pane")
self.lock_interface_action = create_action(
self,
_("Lock panes and toolbars"),
toggled=self.toggle_lock,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.lock_interface_action, "_",
"Lock unlock panes")
# custom layouts shortcuts
self.toggle_next_layout_action = create_action(self,
_("Use next layout"),
triggered=self.toggle_next_layout,
context=Qt.ApplicationShortcut)
self.toggle_previous_layout_action = create_action(self,
_("Use previous layout"),
triggered=self.toggle_previous_layout,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.toggle_next_layout_action, "_",
"Use next layout")
self.register_shortcut(self.toggle_previous_layout_action, "_",
"Use previous layout")
# File switcher shortcuts
self.file_switcher_action = create_action(
self,
_('File switcher...'),
icon=ima.icon('filelist'),
tip=_('Fast switch between files'),
triggered=self.open_fileswitcher,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.file_switcher_action, context="_",
name="File switcher")
self.symbol_finder_action = create_action(
self, _('Symbol finder...'),
icon=ima.icon('symbol_find'),
tip=_('Fast symbol search in file'),
triggered=self.open_symbolfinder,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.symbol_finder_action, context="_",
name="symbol finder", add_sc_to_tip=True)
self.file_toolbar_actions = [self.file_switcher_action,
self.symbol_finder_action]
def create_edit_action(text, tr_text, icon):
textseq = text.split(' ')
method_name = textseq[0].lower()+"".join(textseq[1:])
action = create_action(self, tr_text,
icon=icon,
triggered=self.global_callback,
data=method_name,
context=Qt.WidgetShortcut)
self.register_shortcut(action, "Editor", text)
return action
self.undo_action = create_edit_action('Undo', _('Undo'),
ima.icon('undo'))
self.redo_action = create_edit_action('Redo', _('Redo'),
ima.icon('redo'))
self.copy_action = create_edit_action('Copy', _('Copy'),
ima.icon('editcopy'))
self.cut_action = create_edit_action('Cut', _('Cut'),
ima.icon('editcut'))
self.paste_action = create_edit_action('Paste', _('Paste'),
ima.icon('editpaste'))
self.selectall_action = create_edit_action("Select All",
_("Select All"),
ima.icon('selectall'))
self.edit_menu_actions = [self.undo_action, self.redo_action,
None, self.cut_action, self.copy_action,
self.paste_action, self.selectall_action]
namespace = None
logger.info("Creating toolbars...")
# File menu/toolbar
self.file_menu = self.menuBar().addMenu(_("&File"))
self.file_toolbar = self.create_toolbar(_("File toolbar"),
"file_toolbar")
# Edit menu/toolbar
self.edit_menu = self.menuBar().addMenu(_("&Edit"))
self.edit_toolbar = self.create_toolbar(_("Edit toolbar"),
"edit_toolbar")
# Search menu/toolbar
self.search_menu = self.menuBar().addMenu(_("&Search"))
self.search_toolbar = self.create_toolbar(_("Search toolbar"),
"search_toolbar")
# Source menu/toolbar
self.source_menu = self.menuBar().addMenu(_("Sour&ce"))
self.source_toolbar = self.create_toolbar(_("Source toolbar"),
"source_toolbar")
# Run menu/toolbar
self.run_menu = self.menuBar().addMenu(_("&Run"))
self.run_toolbar = self.create_toolbar(_("Run toolbar"),
"run_toolbar")
# Debug menu/toolbar
self.debug_menu = self.menuBar().addMenu(_("&Debug"))
self.debug_toolbar = self.create_toolbar(_("Debug toolbar"),
"debug_toolbar")
# Consoles menu/toolbar
self.consoles_menu = self.menuBar().addMenu(_("C&onsoles"))
self.consoles_menu.aboutToShow.connect(
self.update_execution_state_kernel)
# Projects menu
self.projects_menu = self.menuBar().addMenu(_("&Projects"))
self.projects_menu.aboutToShow.connect(self.valid_project)
# Tools menu
self.tools_menu = self.menuBar().addMenu(_("&Tools"))
# View menu
self.view_menu = self.menuBar().addMenu(_("&View"))
# Help menu
self.help_menu = self.menuBar().addMenu(_("&Help"))
# Status bar
status = self.statusBar()
status.setObjectName("StatusBar")
status.showMessage(_("Welcome to Spyder!"), 5000)
logger.info("Creating Tools menu...")
# Tools + External Tools
prefs_action = create_action(self, _("Pre&ferences"),
icon=ima.icon('configure'),
triggered=self.edit_preferences,
context=Qt.ApplicationShortcut)
self.register_shortcut(prefs_action, "_", "Preferences",
add_sc_to_tip=True)
spyder_path_action = create_action(self,
_("PYTHONPATH manager"),
None, icon=ima.icon('pythonpath'),
triggered=self.path_manager_callback,
tip=_("Python Path Manager"),
menurole=QAction.ApplicationSpecificRole)
reset_spyder_action = create_action(
self, _("Reset Spyder to factory defaults"),
triggered=self.reset_spyder)
self.tools_menu_actions = [prefs_action, spyder_path_action]
if WinUserEnvDialog is not None:
winenv_action = create_action(self,
_("Current user environment variables..."),
icon='win_env.png',
tip=_("Show and edit current user environment "
"variables in Windows registry "
"(i.e. for all sessions)"),
triggered=self.win_env)
self.tools_menu_actions.append(winenv_action)
self.tools_menu_actions += [MENU_SEPARATOR, reset_spyder_action]
# External Tools submenu
self.external_tools_menu = QMenu(_("External Tools"))
self.external_tools_menu_actions = []
# WinPython control panel
self.wp_action = create_action(self, _("WinPython control panel"),
icon=get_icon('winpython.svg'),
triggered=lambda:
programs.run_python_script('winpython', 'controlpanel'))
if os.name == 'nt' and is_module_installed('winpython'):
self.external_tools_menu_actions.append(self.wp_action)
# Qt-related tools
additact = []
for name in ("designer-qt4", "designer"):
qtdact = create_program_action(self, _("Qt Designer"), name)
if qtdact:
break
for name in ("linguist-qt4", "linguist"):
qtlact = create_program_action(self, _("Qt Linguist"), "linguist")
if qtlact:
break
args = ['-no-opengl'] if os.name == 'nt' else []
for act in (qtdact, qtlact):
if act:
additact.append(act)
if additact and is_module_installed('winpython'):
self.external_tools_menu_actions += [None] + additact
# Guidata and Sift
logger.info("Creating guidata and sift entries...")
gdgq_act = []
# Guidata and Guiqwt don't support PyQt5 yet and they fail
# with an AssertionError when imported using those bindings
# (see issue 2274)
try:
from guidata import configtools
from guidata import config # analysis:ignore
guidata_icon = configtools.get_icon('guidata.svg')
guidata_act = create_python_script_action(self,
_("guidata examples"), guidata_icon,
"guidata",
osp.join("tests", "__init__"))
gdgq_act += [guidata_act]
except:
pass
try:
from guidata import configtools
from guiqwt import config # analysis:ignore
guiqwt_icon = configtools.get_icon('guiqwt.svg')
guiqwt_act = create_python_script_action(self,
_("guiqwt examples"), guiqwt_icon, "guiqwt",
osp.join("tests", "__init__"))
if guiqwt_act:
gdgq_act += [guiqwt_act]
sift_icon = configtools.get_icon('sift.svg')
sift_act = create_python_script_action(self, _("Sift"),
sift_icon, "guiqwt", osp.join("tests", "sift"))
if sift_act:
gdgq_act += [sift_act]
except:
pass
if gdgq_act:
self.external_tools_menu_actions += [None] + gdgq_act
# Maximize current plugin
self.maximize_action = create_action(self, '',
triggered=self.maximize_dockwidget,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.maximize_action, "_", "Maximize pane")
self.__update_maximize_action()
# Fullscreen mode
self.fullscreen_action = create_action(self,
_("Fullscreen mode"),
triggered=self.toggle_fullscreen,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.fullscreen_action, "_",
"Fullscreen mode", add_sc_to_tip=True)
# Main toolbar
self.main_toolbar_actions = [self.maximize_action,
self.fullscreen_action,
None,
prefs_action, spyder_path_action]
self.main_toolbar = self.create_toolbar(_("Main toolbar"),
"main_toolbar")
# Internal console plugin
logger.info("Loading internal console...")
from spyder.plugins.console.plugin import Console
self.console = Console(self, namespace, exitfunc=self.closing,
profile=self.profile,
multithreaded=self.multithreaded,
message=_("Spyder Internal Console\n\n"
"This console is used to report application\n"
"internal errors and to inspect Spyder\n"
"internals with the following commands:\n"
" spy.app, spy.window, dir(spy)\n\n"
"Please don't use it to run your code\n\n"))
self.console.register_plugin()
# Language Server Protocol Client initialization
self.set_splash(_("Starting Language Server Protocol manager..."))
from spyder.plugins.editor.lsp.manager import LSPManager
self.lspmanager = LSPManager(self)
# Working directory plugin
logger.info("Loading working directory...")
from spyder.plugins.workingdirectory.plugin import WorkingDirectory
self.workingdirectory = WorkingDirectory(self, self.init_workdir, main=self)
self.workingdirectory.register_plugin()
self.toolbarslist.append(self.workingdirectory.toolbar)
# Help plugin
if CONF.get('help', 'enable'):
self.set_splash(_("Loading help..."))
from spyder.plugins.help.plugin import Help
self.help = Help(self, css_path=css_path)
self.help.register_plugin()
# Outline explorer widget
if CONF.get('outline_explorer', 'enable'):
self.set_splash(_("Loading outline explorer..."))
from spyder.plugins.outlineexplorer.plugin import OutlineExplorer
self.outlineexplorer = OutlineExplorer(self)
self.outlineexplorer.register_plugin()
# Editor plugin
self.set_splash(_("Loading editor..."))
from spyder.plugins.editor.plugin import Editor
self.editor = Editor(self)
self.editor.register_plugin()
# Start LSP client
self.set_splash(_("Launching LSP Client for Python..."))
self.lspmanager.start_client(language='python')
# Populating file menu entries
quit_action = create_action(self, _("&Quit"),
icon=ima.icon('exit'),
tip=_("Quit"),
triggered=self.console.quit,
context=Qt.ApplicationShortcut)
self.register_shortcut(quit_action, "_", "Quit")
restart_action = create_action(self, _("&Restart"),
icon=ima.icon('restart'),
tip=_("Restart"),
triggered=self.restart,
context=Qt.ApplicationShortcut)
self.register_shortcut(restart_action, "_", "Restart")
self.file_menu_actions += [self.file_switcher_action,
self.symbol_finder_action, None,
restart_action, quit_action]
self.set_splash("")
# Namespace browser
self.set_splash(_("Loading namespace browser..."))
from spyder.plugins.variableexplorer.plugin import VariableExplorer
self.variableexplorer = VariableExplorer(self)
self.variableexplorer.register_plugin()
# Figure browser
self.set_splash(_("Loading figure browser..."))
from spyder.plugins.plots.plugin import Plots
self.plots = Plots(self)
self.plots.register_plugin()
# History log widget
if CONF.get('historylog', 'enable'):
self.set_splash(_("Loading history plugin..."))
from spyder.plugins.history.plugin import HistoryLog
self.historylog = HistoryLog(self)
self.historylog.register_plugin()
# IPython console
self.set_splash(_("Loading IPython console..."))
from spyder.plugins.ipythonconsole.plugin import IPythonConsole
self.ipyconsole = IPythonConsole(self, css_path=css_path)
self.ipyconsole.register_plugin()
# Explorer
if CONF.get('explorer', 'enable'):
self.set_splash(_("Loading file explorer..."))
from spyder.plugins.explorer.plugin import Explorer
self.explorer = Explorer(self)
self.explorer.register_plugin()
# Online help widget
try: # Qt >= v4.4
from spyder.plugins.onlinehelp.plugin import OnlineHelp
except ImportError: # Qt < v4.4
OnlineHelp = None # analysis:ignore
if CONF.get('onlinehelp', 'enable') and OnlineHelp is not None:
self.set_splash(_("Loading online help..."))
self.onlinehelp = OnlineHelp(self)
self.onlinehelp.register_plugin()
# Project explorer widget
self.set_splash(_("Loading project explorer..."))
from spyder.plugins.projects.plugin import Projects
self.projects = Projects(self)
self.projects.register_plugin()
self.project_path = self.projects.get_pythonpath(at_start=True)
# Find in files
if CONF.get('find_in_files', 'enable'):
from spyder.plugins.findinfiles.plugin import FindInFiles
self.findinfiles = FindInFiles(self)
self.findinfiles.register_plugin()
# Load other plugins (former external plugins)
# TODO: Use this bucle to load all internall plugins and remove
# duplicated code
other_plugins = ['breakpoints', 'profiler', 'pylint']
for plugin_name in other_plugins:
if CONF.get(plugin_name, 'enable'):
module = importlib.import_module(
'spyder.plugins.{}'.format(plugin_name))
plugin = module.PLUGIN_CLASS(self)
if plugin.check_compatibility()[0]:
self.thirdparty_plugins.append(plugin)
plugin.register_plugin()
# Third-party plugins
self.set_splash(_("Loading third-party plugins..."))
for mod in get_spyderplugins_mods():
try:
plugin = mod.PLUGIN_CLASS(self)
if plugin.check_compatibility()[0]:
self.thirdparty_plugins.append(plugin)
plugin.register_plugin()
except Exception as error:
print("%s: %s" % (mod, str(error)), file=STDERR)
traceback.print_exc(file=STDERR)
self.set_splash(_("Setting up main window..."))
# Help menu
trouble_action = create_action(self,
_("Troubleshooting..."),
triggered=self.trouble_guide)
dep_action = create_action(self, _("Dependencies..."),
triggered=self.show_dependencies,
icon=ima.icon('advanced'))
report_action = create_action(self,
_("Report issue..."),
icon=ima.icon('bug'),
triggered=self.report_issue)
support_action = create_action(self,
_("Spyder support..."),
triggered=self.google_group)
self.check_updates_action = create_action(self,
_("Check for updates..."),
triggered=self.check_updates)
# Spyder documentation
spyder_doc = 'https://docs.spyder-ide.org/'
doc_action = create_action(self, _("Spyder documentation"),
icon=ima.icon('DialogHelpButton'),
triggered=lambda:
programs.start_file(spyder_doc))
self.register_shortcut(doc_action, "_",
"spyder documentation")
if self.help is not None:
tut_action = create_action(self, _("Spyder tutorial"),
triggered=self.help.show_tutorial)
else:
tut_action = None
shortcuts_action = create_action(self, _("Shortcuts Summary"),
shortcut="Meta+F1",
triggered=self.show_shortcuts_dialog)
#----- Tours
self.tour = tour.AnimatedTour(self)
self.tours_menu = QMenu(_("Interactive tours"), self)
self.tour_menu_actions = []
# TODO: Only show intro tour for now. When we are close to finish
# 3.0, we will finish and show the other tour
self.tours_available = tour.get_tours(0)
for i, tour_available in enumerate(self.tours_available):
self.tours_available[i]['last'] = 0
tour_name = tour_available['name']
def trigger(i=i, self=self): # closure needed!
return lambda: self.show_tour(i)
temp_action = create_action(self, tour_name, tip="",
triggered=trigger())
self.tour_menu_actions += [temp_action]
self.tours_menu.addActions(self.tour_menu_actions)
self.help_menu_actions = [doc_action, tut_action, shortcuts_action,
self.tours_menu,
MENU_SEPARATOR, trouble_action,
report_action, dep_action,
self.check_updates_action, support_action,
MENU_SEPARATOR]
# Python documentation
if get_python_doc_path() is not None:
pydoc_act = create_action(self, _("Python documentation"),
triggered=lambda:
programs.start_file(get_python_doc_path()))
self.help_menu_actions.append(pydoc_act)
# IPython documentation
if self.help is not None:
ipython_menu = QMenu(_("IPython documentation"), self)
intro_action = create_action(self, _("Intro to IPython"),
triggered=self.ipyconsole.show_intro)
quickref_action = create_action(self, _("Quick reference"),
triggered=self.ipyconsole.show_quickref)
guiref_action = create_action(self, _("Console help"),
triggered=self.ipyconsole.show_guiref)
add_actions(ipython_menu, (intro_action, guiref_action,
quickref_action))
self.help_menu_actions.append(ipython_menu)
# Windows-only: documentation located in sys.prefix/Doc
ipm_actions = []
def add_ipm_action(text, path):
"""Add installed Python module doc action to help submenu"""
# QAction.triggered works differently for PySide and PyQt
path = file_uri(path)
if not API == 'pyside':
slot=lambda _checked, path=path: programs.start_file(path)
else:
slot=lambda path=path: programs.start_file(path)
action = create_action(self, text,
icon='%s.png' % osp.splitext(path)[1][1:],
triggered=slot)
ipm_actions.append(action)
sysdocpth = osp.join(sys.prefix, 'Doc')
if osp.isdir(sysdocpth): # exists on Windows, except frozen dist.
for docfn in os.listdir(sysdocpth):
pt = r'([a-zA-Z\_]*)(doc)?(-dev)?(-ref)?(-user)?.(chm|pdf)'
match = re.match(pt, docfn)
if match is not None:
pname = match.groups()[0]
if pname not in ('Python', ):
add_ipm_action(pname, osp.join(sysdocpth, docfn))
# Installed Python modules submenu (Windows only)
if ipm_actions:
pymods_menu = QMenu(_("Installed Python modules"), self)
add_actions(pymods_menu, ipm_actions)
self.help_menu_actions.append(pymods_menu)
# Online documentation
web_resources = QMenu(_("Online documentation"), self)
webres_actions = create_module_bookmark_actions(self,
self.BOOKMARKS)
webres_actions.insert(2, None)
webres_actions.insert(5, None)
webres_actions.insert(8, None)
add_actions(web_resources, webres_actions)
self.help_menu_actions.append(web_resources)
# Qt assistant link
if sys.platform.startswith('linux') and not PYQT5:
qta_exe = "assistant-qt4"
else:
qta_exe = "assistant"
qta_act = create_program_action(self, _("Qt documentation"),
qta_exe)
if qta_act:
self.help_menu_actions += [qta_act, None]
# About Spyder
about_action = create_action(self,
_("About %s...") % "Spyder",
icon=ima.icon('MessageBoxInformation'),
triggered=self.about)
self.help_menu_actions += [MENU_SEPARATOR, about_action]
# Status bar widgets
from spyder.widgets.status import MemoryStatus, CPUStatus
self.mem_status = MemoryStatus(self, status)
self.cpu_status = CPUStatus(self, status)
self.apply_statusbar_settings()
# ----- View
# View menu
self.plugins_menu = QMenu(_("Panes"), self)
self.toolbars_menu = QMenu(_("Toolbars"), self)
self.quick_layout_menu = QMenu(_("Window layouts"), self)
self.quick_layout_set_menu()
self.view_menu.addMenu(self.plugins_menu) # Panes
add_actions(self.view_menu, (self.lock_interface_action,
self.close_dockwidget_action,
self.maximize_action,
MENU_SEPARATOR))
self.show_toolbars_action = create_action(self,
_("Show toolbars"),
triggered=self.show_toolbars,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.show_toolbars_action, "_",
"Show toolbars")
self.view_menu.addMenu(self.toolbars_menu)
self.view_menu.addAction(self.show_toolbars_action)
add_actions(self.view_menu, (MENU_SEPARATOR,
self.quick_layout_menu,
self.toggle_previous_layout_action,
self.toggle_next_layout_action,
MENU_SEPARATOR,
self.fullscreen_action))
if set_attached_console_visible is not None:
cmd_act = create_action(self,
_("Attached console window (debugging)"),
toggled=set_attached_console_visible)
cmd_act.setChecked(is_attached_console_visible())
add_actions(self.view_menu, (MENU_SEPARATOR, cmd_act))
# Adding external tools action to "Tools" menu
if self.external_tools_menu_actions:
external_tools_act = create_action(self, _("External Tools"))
external_tools_act.setMenu(self.external_tools_menu)
self.tools_menu_actions += [None, external_tools_act]
# Filling out menu/toolbar entries:
add_actions(self.file_menu, self.file_menu_actions)
add_actions(self.edit_menu, self.edit_menu_actions)
add_actions(self.search_menu, self.search_menu_actions)
add_actions(self.source_menu, self.source_menu_actions)
add_actions(self.run_menu, self.run_menu_actions)
add_actions(self.debug_menu, self.debug_menu_actions)
add_actions(self.consoles_menu, self.consoles_menu_actions)
add_actions(self.projects_menu, self.projects_menu_actions)
add_actions(self.tools_menu, self.tools_menu_actions)
add_actions(self.external_tools_menu,
self.external_tools_menu_actions)
add_actions(self.help_menu, self.help_menu_actions)
add_actions(self.main_toolbar, self.main_toolbar_actions)
add_actions(self.file_toolbar, self.file_toolbar_actions)
add_actions(self.edit_toolbar, self.edit_toolbar_actions)
add_actions(self.search_toolbar, self.search_toolbar_actions)
add_actions(self.source_toolbar, self.source_toolbar_actions)
add_actions(self.debug_toolbar, self.debug_toolbar_actions)
add_actions(self.run_toolbar, self.run_toolbar_actions)
# Apply all defined shortcuts (plugins + 3rd-party plugins)
self.apply_shortcuts()
# Emitting the signal notifying plugins that main window menu and
# toolbar actions are all defined:
self.all_actions_defined.emit()
# Window set-up
logger.info("Setting up window...")
self.setup_layout(default=False)
# Show and hide shortcuts in menus for Mac.
# This is a workaround because we can't disable shortcuts
# by setting context=Qt.WidgetShortcut there
if sys.platform == 'darwin':
for name in ['file', 'edit', 'search', 'source', 'run', 'debug',
'projects', 'tools', 'plugins']:
menu_object = getattr(self, name + '_menu')
menu_object.aboutToShow.connect(
lambda name=name: self.show_shortcuts(name))
menu_object.aboutToHide.connect(
lambda name=name: self.hide_shortcuts(name))
if self.splash is not None:
self.splash.hide()
# Enabling tear off for all menus except help menu
if CONF.get('main', 'tear_off_menus'):
for child in self.menuBar().children():
if isinstance(child, QMenu) and child != self.help_menu:
child.setTearOffEnabled(True)
# Menu about to show
for child in self.menuBar().children():
if isinstance(child, QMenu):
try:
child.aboutToShow.connect(self.update_edit_menu)
child.aboutToShow.connect(self.update_search_menu)
except TypeError:
pass
logger.info("*** End of MainWindow setup ***")
self.is_starting_up = False | [
"def",
"setup",
"(",
"self",
")",
":",
"logger",
".",
"info",
"(",
"\"*** Start of MainWindow setup ***\"",
")",
"logger",
".",
"info",
"(",
"\"Applying theme configuration...\"",
")",
"ui_theme",
"=",
"CONF",
".",
"get",
"(",
"'appearance'",
",",
"'ui_theme'",
")",
"color_scheme",
"=",
"CONF",
".",
"get",
"(",
"'appearance'",
",",
"'selected'",
")",
"if",
"ui_theme",
"==",
"'dark'",
":",
"dark_qss",
"=",
"qdarkstyle",
".",
"load_stylesheet_from_environment",
"(",
")",
"self",
".",
"setStyleSheet",
"(",
"dark_qss",
")",
"self",
".",
"statusBar",
"(",
")",
".",
"setStyleSheet",
"(",
"dark_qss",
")",
"css_path",
"=",
"DARK_CSS_PATH",
"elif",
"ui_theme",
"==",
"'automatic'",
":",
"if",
"not",
"is_dark_font_color",
"(",
"color_scheme",
")",
":",
"dark_qss",
"=",
"qdarkstyle",
".",
"load_stylesheet_from_environment",
"(",
")",
"self",
".",
"setStyleSheet",
"(",
"dark_qss",
")",
"self",
".",
"statusBar",
"(",
")",
".",
"setStyleSheet",
"(",
"dark_qss",
")",
"css_path",
"=",
"DARK_CSS_PATH",
"else",
":",
"css_path",
"=",
"CSS_PATH",
"else",
":",
"css_path",
"=",
"CSS_PATH",
"logger",
".",
"info",
"(",
"\"Creating core actions...\"",
")",
"self",
".",
"close_dockwidget_action",
"=",
"create_action",
"(",
"self",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'close_pane'",
")",
",",
"text",
"=",
"_",
"(",
"\"Close current pane\"",
")",
",",
"triggered",
"=",
"self",
".",
"close_current_dockwidget",
",",
"context",
"=",
"Qt",
".",
"ApplicationShortcut",
")",
"self",
".",
"register_shortcut",
"(",
"self",
".",
"close_dockwidget_action",
",",
"\"_\"",
",",
"\"Close pane\"",
")",
"self",
".",
"lock_interface_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Lock panes and toolbars\"",
")",
",",
"toggled",
"=",
"self",
".",
"toggle_lock",
",",
"context",
"=",
"Qt",
".",
"ApplicationShortcut",
")",
"self",
".",
"register_shortcut",
"(",
"self",
".",
"lock_interface_action",
",",
"\"_\"",
",",
"\"Lock unlock panes\"",
")",
"# custom layouts shortcuts\r",
"self",
".",
"toggle_next_layout_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Use next layout\"",
")",
",",
"triggered",
"=",
"self",
".",
"toggle_next_layout",
",",
"context",
"=",
"Qt",
".",
"ApplicationShortcut",
")",
"self",
".",
"toggle_previous_layout_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Use previous layout\"",
")",
",",
"triggered",
"=",
"self",
".",
"toggle_previous_layout",
",",
"context",
"=",
"Qt",
".",
"ApplicationShortcut",
")",
"self",
".",
"register_shortcut",
"(",
"self",
".",
"toggle_next_layout_action",
",",
"\"_\"",
",",
"\"Use next layout\"",
")",
"self",
".",
"register_shortcut",
"(",
"self",
".",
"toggle_previous_layout_action",
",",
"\"_\"",
",",
"\"Use previous layout\"",
")",
"# File switcher shortcuts\r",
"self",
".",
"file_switcher_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"'File switcher...'",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'filelist'",
")",
",",
"tip",
"=",
"_",
"(",
"'Fast switch between files'",
")",
",",
"triggered",
"=",
"self",
".",
"open_fileswitcher",
",",
"context",
"=",
"Qt",
".",
"ApplicationShortcut",
")",
"self",
".",
"register_shortcut",
"(",
"self",
".",
"file_switcher_action",
",",
"context",
"=",
"\"_\"",
",",
"name",
"=",
"\"File switcher\"",
")",
"self",
".",
"symbol_finder_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"'Symbol finder...'",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'symbol_find'",
")",
",",
"tip",
"=",
"_",
"(",
"'Fast symbol search in file'",
")",
",",
"triggered",
"=",
"self",
".",
"open_symbolfinder",
",",
"context",
"=",
"Qt",
".",
"ApplicationShortcut",
")",
"self",
".",
"register_shortcut",
"(",
"self",
".",
"symbol_finder_action",
",",
"context",
"=",
"\"_\"",
",",
"name",
"=",
"\"symbol finder\"",
",",
"add_sc_to_tip",
"=",
"True",
")",
"self",
".",
"file_toolbar_actions",
"=",
"[",
"self",
".",
"file_switcher_action",
",",
"self",
".",
"symbol_finder_action",
"]",
"def",
"create_edit_action",
"(",
"text",
",",
"tr_text",
",",
"icon",
")",
":",
"textseq",
"=",
"text",
".",
"split",
"(",
"' '",
")",
"method_name",
"=",
"textseq",
"[",
"0",
"]",
".",
"lower",
"(",
")",
"+",
"\"\"",
".",
"join",
"(",
"textseq",
"[",
"1",
":",
"]",
")",
"action",
"=",
"create_action",
"(",
"self",
",",
"tr_text",
",",
"icon",
"=",
"icon",
",",
"triggered",
"=",
"self",
".",
"global_callback",
",",
"data",
"=",
"method_name",
",",
"context",
"=",
"Qt",
".",
"WidgetShortcut",
")",
"self",
".",
"register_shortcut",
"(",
"action",
",",
"\"Editor\"",
",",
"text",
")",
"return",
"action",
"self",
".",
"undo_action",
"=",
"create_edit_action",
"(",
"'Undo'",
",",
"_",
"(",
"'Undo'",
")",
",",
"ima",
".",
"icon",
"(",
"'undo'",
")",
")",
"self",
".",
"redo_action",
"=",
"create_edit_action",
"(",
"'Redo'",
",",
"_",
"(",
"'Redo'",
")",
",",
"ima",
".",
"icon",
"(",
"'redo'",
")",
")",
"self",
".",
"copy_action",
"=",
"create_edit_action",
"(",
"'Copy'",
",",
"_",
"(",
"'Copy'",
")",
",",
"ima",
".",
"icon",
"(",
"'editcopy'",
")",
")",
"self",
".",
"cut_action",
"=",
"create_edit_action",
"(",
"'Cut'",
",",
"_",
"(",
"'Cut'",
")",
",",
"ima",
".",
"icon",
"(",
"'editcut'",
")",
")",
"self",
".",
"paste_action",
"=",
"create_edit_action",
"(",
"'Paste'",
",",
"_",
"(",
"'Paste'",
")",
",",
"ima",
".",
"icon",
"(",
"'editpaste'",
")",
")",
"self",
".",
"selectall_action",
"=",
"create_edit_action",
"(",
"\"Select All\"",
",",
"_",
"(",
"\"Select All\"",
")",
",",
"ima",
".",
"icon",
"(",
"'selectall'",
")",
")",
"self",
".",
"edit_menu_actions",
"=",
"[",
"self",
".",
"undo_action",
",",
"self",
".",
"redo_action",
",",
"None",
",",
"self",
".",
"cut_action",
",",
"self",
".",
"copy_action",
",",
"self",
".",
"paste_action",
",",
"self",
".",
"selectall_action",
"]",
"namespace",
"=",
"None",
"logger",
".",
"info",
"(",
"\"Creating toolbars...\"",
")",
"# File menu/toolbar\r",
"self",
".",
"file_menu",
"=",
"self",
".",
"menuBar",
"(",
")",
".",
"addMenu",
"(",
"_",
"(",
"\"&File\"",
")",
")",
"self",
".",
"file_toolbar",
"=",
"self",
".",
"create_toolbar",
"(",
"_",
"(",
"\"File toolbar\"",
")",
",",
"\"file_toolbar\"",
")",
"# Edit menu/toolbar\r",
"self",
".",
"edit_menu",
"=",
"self",
".",
"menuBar",
"(",
")",
".",
"addMenu",
"(",
"_",
"(",
"\"&Edit\"",
")",
")",
"self",
".",
"edit_toolbar",
"=",
"self",
".",
"create_toolbar",
"(",
"_",
"(",
"\"Edit toolbar\"",
")",
",",
"\"edit_toolbar\"",
")",
"# Search menu/toolbar\r",
"self",
".",
"search_menu",
"=",
"self",
".",
"menuBar",
"(",
")",
".",
"addMenu",
"(",
"_",
"(",
"\"&Search\"",
")",
")",
"self",
".",
"search_toolbar",
"=",
"self",
".",
"create_toolbar",
"(",
"_",
"(",
"\"Search toolbar\"",
")",
",",
"\"search_toolbar\"",
")",
"# Source menu/toolbar\r",
"self",
".",
"source_menu",
"=",
"self",
".",
"menuBar",
"(",
")",
".",
"addMenu",
"(",
"_",
"(",
"\"Sour&ce\"",
")",
")",
"self",
".",
"source_toolbar",
"=",
"self",
".",
"create_toolbar",
"(",
"_",
"(",
"\"Source toolbar\"",
")",
",",
"\"source_toolbar\"",
")",
"# Run menu/toolbar\r",
"self",
".",
"run_menu",
"=",
"self",
".",
"menuBar",
"(",
")",
".",
"addMenu",
"(",
"_",
"(",
"\"&Run\"",
")",
")",
"self",
".",
"run_toolbar",
"=",
"self",
".",
"create_toolbar",
"(",
"_",
"(",
"\"Run toolbar\"",
")",
",",
"\"run_toolbar\"",
")",
"# Debug menu/toolbar\r",
"self",
".",
"debug_menu",
"=",
"self",
".",
"menuBar",
"(",
")",
".",
"addMenu",
"(",
"_",
"(",
"\"&Debug\"",
")",
")",
"self",
".",
"debug_toolbar",
"=",
"self",
".",
"create_toolbar",
"(",
"_",
"(",
"\"Debug toolbar\"",
")",
",",
"\"debug_toolbar\"",
")",
"# Consoles menu/toolbar\r",
"self",
".",
"consoles_menu",
"=",
"self",
".",
"menuBar",
"(",
")",
".",
"addMenu",
"(",
"_",
"(",
"\"C&onsoles\"",
")",
")",
"self",
".",
"consoles_menu",
".",
"aboutToShow",
".",
"connect",
"(",
"self",
".",
"update_execution_state_kernel",
")",
"# Projects menu\r",
"self",
".",
"projects_menu",
"=",
"self",
".",
"menuBar",
"(",
")",
".",
"addMenu",
"(",
"_",
"(",
"\"&Projects\"",
")",
")",
"self",
".",
"projects_menu",
".",
"aboutToShow",
".",
"connect",
"(",
"self",
".",
"valid_project",
")",
"# Tools menu\r",
"self",
".",
"tools_menu",
"=",
"self",
".",
"menuBar",
"(",
")",
".",
"addMenu",
"(",
"_",
"(",
"\"&Tools\"",
")",
")",
"# View menu\r",
"self",
".",
"view_menu",
"=",
"self",
".",
"menuBar",
"(",
")",
".",
"addMenu",
"(",
"_",
"(",
"\"&View\"",
")",
")",
"# Help menu\r",
"self",
".",
"help_menu",
"=",
"self",
".",
"menuBar",
"(",
")",
".",
"addMenu",
"(",
"_",
"(",
"\"&Help\"",
")",
")",
"# Status bar\r",
"status",
"=",
"self",
".",
"statusBar",
"(",
")",
"status",
".",
"setObjectName",
"(",
"\"StatusBar\"",
")",
"status",
".",
"showMessage",
"(",
"_",
"(",
"\"Welcome to Spyder!\"",
")",
",",
"5000",
")",
"logger",
".",
"info",
"(",
"\"Creating Tools menu...\"",
")",
"# Tools + External Tools\r",
"prefs_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Pre&ferences\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'configure'",
")",
",",
"triggered",
"=",
"self",
".",
"edit_preferences",
",",
"context",
"=",
"Qt",
".",
"ApplicationShortcut",
")",
"self",
".",
"register_shortcut",
"(",
"prefs_action",
",",
"\"_\"",
",",
"\"Preferences\"",
",",
"add_sc_to_tip",
"=",
"True",
")",
"spyder_path_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"PYTHONPATH manager\"",
")",
",",
"None",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'pythonpath'",
")",
",",
"triggered",
"=",
"self",
".",
"path_manager_callback",
",",
"tip",
"=",
"_",
"(",
"\"Python Path Manager\"",
")",
",",
"menurole",
"=",
"QAction",
".",
"ApplicationSpecificRole",
")",
"reset_spyder_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Reset Spyder to factory defaults\"",
")",
",",
"triggered",
"=",
"self",
".",
"reset_spyder",
")",
"self",
".",
"tools_menu_actions",
"=",
"[",
"prefs_action",
",",
"spyder_path_action",
"]",
"if",
"WinUserEnvDialog",
"is",
"not",
"None",
":",
"winenv_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Current user environment variables...\"",
")",
",",
"icon",
"=",
"'win_env.png'",
",",
"tip",
"=",
"_",
"(",
"\"Show and edit current user environment \"",
"\"variables in Windows registry \"",
"\"(i.e. for all sessions)\"",
")",
",",
"triggered",
"=",
"self",
".",
"win_env",
")",
"self",
".",
"tools_menu_actions",
".",
"append",
"(",
"winenv_action",
")",
"self",
".",
"tools_menu_actions",
"+=",
"[",
"MENU_SEPARATOR",
",",
"reset_spyder_action",
"]",
"# External Tools submenu\r",
"self",
".",
"external_tools_menu",
"=",
"QMenu",
"(",
"_",
"(",
"\"External Tools\"",
")",
")",
"self",
".",
"external_tools_menu_actions",
"=",
"[",
"]",
"# WinPython control panel\r",
"self",
".",
"wp_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"WinPython control panel\"",
")",
",",
"icon",
"=",
"get_icon",
"(",
"'winpython.svg'",
")",
",",
"triggered",
"=",
"lambda",
":",
"programs",
".",
"run_python_script",
"(",
"'winpython'",
",",
"'controlpanel'",
")",
")",
"if",
"os",
".",
"name",
"==",
"'nt'",
"and",
"is_module_installed",
"(",
"'winpython'",
")",
":",
"self",
".",
"external_tools_menu_actions",
".",
"append",
"(",
"self",
".",
"wp_action",
")",
"# Qt-related tools\r",
"additact",
"=",
"[",
"]",
"for",
"name",
"in",
"(",
"\"designer-qt4\"",
",",
"\"designer\"",
")",
":",
"qtdact",
"=",
"create_program_action",
"(",
"self",
",",
"_",
"(",
"\"Qt Designer\"",
")",
",",
"name",
")",
"if",
"qtdact",
":",
"break",
"for",
"name",
"in",
"(",
"\"linguist-qt4\"",
",",
"\"linguist\"",
")",
":",
"qtlact",
"=",
"create_program_action",
"(",
"self",
",",
"_",
"(",
"\"Qt Linguist\"",
")",
",",
"\"linguist\"",
")",
"if",
"qtlact",
":",
"break",
"args",
"=",
"[",
"'-no-opengl'",
"]",
"if",
"os",
".",
"name",
"==",
"'nt'",
"else",
"[",
"]",
"for",
"act",
"in",
"(",
"qtdact",
",",
"qtlact",
")",
":",
"if",
"act",
":",
"additact",
".",
"append",
"(",
"act",
")",
"if",
"additact",
"and",
"is_module_installed",
"(",
"'winpython'",
")",
":",
"self",
".",
"external_tools_menu_actions",
"+=",
"[",
"None",
"]",
"+",
"additact",
"# Guidata and Sift\r",
"logger",
".",
"info",
"(",
"\"Creating guidata and sift entries...\"",
")",
"gdgq_act",
"=",
"[",
"]",
"# Guidata and Guiqwt don't support PyQt5 yet and they fail\r",
"# with an AssertionError when imported using those bindings\r",
"# (see issue 2274)\r",
"try",
":",
"from",
"guidata",
"import",
"configtools",
"from",
"guidata",
"import",
"config",
"# analysis:ignore\r",
"guidata_icon",
"=",
"configtools",
".",
"get_icon",
"(",
"'guidata.svg'",
")",
"guidata_act",
"=",
"create_python_script_action",
"(",
"self",
",",
"_",
"(",
"\"guidata examples\"",
")",
",",
"guidata_icon",
",",
"\"guidata\"",
",",
"osp",
".",
"join",
"(",
"\"tests\"",
",",
"\"__init__\"",
")",
")",
"gdgq_act",
"+=",
"[",
"guidata_act",
"]",
"except",
":",
"pass",
"try",
":",
"from",
"guidata",
"import",
"configtools",
"from",
"guiqwt",
"import",
"config",
"# analysis:ignore\r",
"guiqwt_icon",
"=",
"configtools",
".",
"get_icon",
"(",
"'guiqwt.svg'",
")",
"guiqwt_act",
"=",
"create_python_script_action",
"(",
"self",
",",
"_",
"(",
"\"guiqwt examples\"",
")",
",",
"guiqwt_icon",
",",
"\"guiqwt\"",
",",
"osp",
".",
"join",
"(",
"\"tests\"",
",",
"\"__init__\"",
")",
")",
"if",
"guiqwt_act",
":",
"gdgq_act",
"+=",
"[",
"guiqwt_act",
"]",
"sift_icon",
"=",
"configtools",
".",
"get_icon",
"(",
"'sift.svg'",
")",
"sift_act",
"=",
"create_python_script_action",
"(",
"self",
",",
"_",
"(",
"\"Sift\"",
")",
",",
"sift_icon",
",",
"\"guiqwt\"",
",",
"osp",
".",
"join",
"(",
"\"tests\"",
",",
"\"sift\"",
")",
")",
"if",
"sift_act",
":",
"gdgq_act",
"+=",
"[",
"sift_act",
"]",
"except",
":",
"pass",
"if",
"gdgq_act",
":",
"self",
".",
"external_tools_menu_actions",
"+=",
"[",
"None",
"]",
"+",
"gdgq_act",
"# Maximize current plugin\r",
"self",
".",
"maximize_action",
"=",
"create_action",
"(",
"self",
",",
"''",
",",
"triggered",
"=",
"self",
".",
"maximize_dockwidget",
",",
"context",
"=",
"Qt",
".",
"ApplicationShortcut",
")",
"self",
".",
"register_shortcut",
"(",
"self",
".",
"maximize_action",
",",
"\"_\"",
",",
"\"Maximize pane\"",
")",
"self",
".",
"__update_maximize_action",
"(",
")",
"# Fullscreen mode\r",
"self",
".",
"fullscreen_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Fullscreen mode\"",
")",
",",
"triggered",
"=",
"self",
".",
"toggle_fullscreen",
",",
"context",
"=",
"Qt",
".",
"ApplicationShortcut",
")",
"self",
".",
"register_shortcut",
"(",
"self",
".",
"fullscreen_action",
",",
"\"_\"",
",",
"\"Fullscreen mode\"",
",",
"add_sc_to_tip",
"=",
"True",
")",
"# Main toolbar\r",
"self",
".",
"main_toolbar_actions",
"=",
"[",
"self",
".",
"maximize_action",
",",
"self",
".",
"fullscreen_action",
",",
"None",
",",
"prefs_action",
",",
"spyder_path_action",
"]",
"self",
".",
"main_toolbar",
"=",
"self",
".",
"create_toolbar",
"(",
"_",
"(",
"\"Main toolbar\"",
")",
",",
"\"main_toolbar\"",
")",
"# Internal console plugin\r",
"logger",
".",
"info",
"(",
"\"Loading internal console...\"",
")",
"from",
"spyder",
".",
"plugins",
".",
"console",
".",
"plugin",
"import",
"Console",
"self",
".",
"console",
"=",
"Console",
"(",
"self",
",",
"namespace",
",",
"exitfunc",
"=",
"self",
".",
"closing",
",",
"profile",
"=",
"self",
".",
"profile",
",",
"multithreaded",
"=",
"self",
".",
"multithreaded",
",",
"message",
"=",
"_",
"(",
"\"Spyder Internal Console\\n\\n\"",
"\"This console is used to report application\\n\"",
"\"internal errors and to inspect Spyder\\n\"",
"\"internals with the following commands:\\n\"",
"\" spy.app, spy.window, dir(spy)\\n\\n\"",
"\"Please don't use it to run your code\\n\\n\"",
")",
")",
"self",
".",
"console",
".",
"register_plugin",
"(",
")",
"# Language Server Protocol Client initialization\r",
"self",
".",
"set_splash",
"(",
"_",
"(",
"\"Starting Language Server Protocol manager...\"",
")",
")",
"from",
"spyder",
".",
"plugins",
".",
"editor",
".",
"lsp",
".",
"manager",
"import",
"LSPManager",
"self",
".",
"lspmanager",
"=",
"LSPManager",
"(",
"self",
")",
"# Working directory plugin\r",
"logger",
".",
"info",
"(",
"\"Loading working directory...\"",
")",
"from",
"spyder",
".",
"plugins",
".",
"workingdirectory",
".",
"plugin",
"import",
"WorkingDirectory",
"self",
".",
"workingdirectory",
"=",
"WorkingDirectory",
"(",
"self",
",",
"self",
".",
"init_workdir",
",",
"main",
"=",
"self",
")",
"self",
".",
"workingdirectory",
".",
"register_plugin",
"(",
")",
"self",
".",
"toolbarslist",
".",
"append",
"(",
"self",
".",
"workingdirectory",
".",
"toolbar",
")",
"# Help plugin\r",
"if",
"CONF",
".",
"get",
"(",
"'help'",
",",
"'enable'",
")",
":",
"self",
".",
"set_splash",
"(",
"_",
"(",
"\"Loading help...\"",
")",
")",
"from",
"spyder",
".",
"plugins",
".",
"help",
".",
"plugin",
"import",
"Help",
"self",
".",
"help",
"=",
"Help",
"(",
"self",
",",
"css_path",
"=",
"css_path",
")",
"self",
".",
"help",
".",
"register_plugin",
"(",
")",
"# Outline explorer widget\r",
"if",
"CONF",
".",
"get",
"(",
"'outline_explorer'",
",",
"'enable'",
")",
":",
"self",
".",
"set_splash",
"(",
"_",
"(",
"\"Loading outline explorer...\"",
")",
")",
"from",
"spyder",
".",
"plugins",
".",
"outlineexplorer",
".",
"plugin",
"import",
"OutlineExplorer",
"self",
".",
"outlineexplorer",
"=",
"OutlineExplorer",
"(",
"self",
")",
"self",
".",
"outlineexplorer",
".",
"register_plugin",
"(",
")",
"# Editor plugin\r",
"self",
".",
"set_splash",
"(",
"_",
"(",
"\"Loading editor...\"",
")",
")",
"from",
"spyder",
".",
"plugins",
".",
"editor",
".",
"plugin",
"import",
"Editor",
"self",
".",
"editor",
"=",
"Editor",
"(",
"self",
")",
"self",
".",
"editor",
".",
"register_plugin",
"(",
")",
"# Start LSP client\r",
"self",
".",
"set_splash",
"(",
"_",
"(",
"\"Launching LSP Client for Python...\"",
")",
")",
"self",
".",
"lspmanager",
".",
"start_client",
"(",
"language",
"=",
"'python'",
")",
"# Populating file menu entries\r",
"quit_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"&Quit\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'exit'",
")",
",",
"tip",
"=",
"_",
"(",
"\"Quit\"",
")",
",",
"triggered",
"=",
"self",
".",
"console",
".",
"quit",
",",
"context",
"=",
"Qt",
".",
"ApplicationShortcut",
")",
"self",
".",
"register_shortcut",
"(",
"quit_action",
",",
"\"_\"",
",",
"\"Quit\"",
")",
"restart_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"&Restart\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'restart'",
")",
",",
"tip",
"=",
"_",
"(",
"\"Restart\"",
")",
",",
"triggered",
"=",
"self",
".",
"restart",
",",
"context",
"=",
"Qt",
".",
"ApplicationShortcut",
")",
"self",
".",
"register_shortcut",
"(",
"restart_action",
",",
"\"_\"",
",",
"\"Restart\"",
")",
"self",
".",
"file_menu_actions",
"+=",
"[",
"self",
".",
"file_switcher_action",
",",
"self",
".",
"symbol_finder_action",
",",
"None",
",",
"restart_action",
",",
"quit_action",
"]",
"self",
".",
"set_splash",
"(",
"\"\"",
")",
"# Namespace browser\r",
"self",
".",
"set_splash",
"(",
"_",
"(",
"\"Loading namespace browser...\"",
")",
")",
"from",
"spyder",
".",
"plugins",
".",
"variableexplorer",
".",
"plugin",
"import",
"VariableExplorer",
"self",
".",
"variableexplorer",
"=",
"VariableExplorer",
"(",
"self",
")",
"self",
".",
"variableexplorer",
".",
"register_plugin",
"(",
")",
"# Figure browser\r",
"self",
".",
"set_splash",
"(",
"_",
"(",
"\"Loading figure browser...\"",
")",
")",
"from",
"spyder",
".",
"plugins",
".",
"plots",
".",
"plugin",
"import",
"Plots",
"self",
".",
"plots",
"=",
"Plots",
"(",
"self",
")",
"self",
".",
"plots",
".",
"register_plugin",
"(",
")",
"# History log widget\r",
"if",
"CONF",
".",
"get",
"(",
"'historylog'",
",",
"'enable'",
")",
":",
"self",
".",
"set_splash",
"(",
"_",
"(",
"\"Loading history plugin...\"",
")",
")",
"from",
"spyder",
".",
"plugins",
".",
"history",
".",
"plugin",
"import",
"HistoryLog",
"self",
".",
"historylog",
"=",
"HistoryLog",
"(",
"self",
")",
"self",
".",
"historylog",
".",
"register_plugin",
"(",
")",
"# IPython console\r",
"self",
".",
"set_splash",
"(",
"_",
"(",
"\"Loading IPython console...\"",
")",
")",
"from",
"spyder",
".",
"plugins",
".",
"ipythonconsole",
".",
"plugin",
"import",
"IPythonConsole",
"self",
".",
"ipyconsole",
"=",
"IPythonConsole",
"(",
"self",
",",
"css_path",
"=",
"css_path",
")",
"self",
".",
"ipyconsole",
".",
"register_plugin",
"(",
")",
"# Explorer\r",
"if",
"CONF",
".",
"get",
"(",
"'explorer'",
",",
"'enable'",
")",
":",
"self",
".",
"set_splash",
"(",
"_",
"(",
"\"Loading file explorer...\"",
")",
")",
"from",
"spyder",
".",
"plugins",
".",
"explorer",
".",
"plugin",
"import",
"Explorer",
"self",
".",
"explorer",
"=",
"Explorer",
"(",
"self",
")",
"self",
".",
"explorer",
".",
"register_plugin",
"(",
")",
"# Online help widget\r",
"try",
":",
"# Qt >= v4.4\r",
"from",
"spyder",
".",
"plugins",
".",
"onlinehelp",
".",
"plugin",
"import",
"OnlineHelp",
"except",
"ImportError",
":",
"# Qt < v4.4\r",
"OnlineHelp",
"=",
"None",
"# analysis:ignore\r",
"if",
"CONF",
".",
"get",
"(",
"'onlinehelp'",
",",
"'enable'",
")",
"and",
"OnlineHelp",
"is",
"not",
"None",
":",
"self",
".",
"set_splash",
"(",
"_",
"(",
"\"Loading online help...\"",
")",
")",
"self",
".",
"onlinehelp",
"=",
"OnlineHelp",
"(",
"self",
")",
"self",
".",
"onlinehelp",
".",
"register_plugin",
"(",
")",
"# Project explorer widget\r",
"self",
".",
"set_splash",
"(",
"_",
"(",
"\"Loading project explorer...\"",
")",
")",
"from",
"spyder",
".",
"plugins",
".",
"projects",
".",
"plugin",
"import",
"Projects",
"self",
".",
"projects",
"=",
"Projects",
"(",
"self",
")",
"self",
".",
"projects",
".",
"register_plugin",
"(",
")",
"self",
".",
"project_path",
"=",
"self",
".",
"projects",
".",
"get_pythonpath",
"(",
"at_start",
"=",
"True",
")",
"# Find in files\r",
"if",
"CONF",
".",
"get",
"(",
"'find_in_files'",
",",
"'enable'",
")",
":",
"from",
"spyder",
".",
"plugins",
".",
"findinfiles",
".",
"plugin",
"import",
"FindInFiles",
"self",
".",
"findinfiles",
"=",
"FindInFiles",
"(",
"self",
")",
"self",
".",
"findinfiles",
".",
"register_plugin",
"(",
")",
"# Load other plugins (former external plugins)\r",
"# TODO: Use this bucle to load all internall plugins and remove\r",
"# duplicated code\r",
"other_plugins",
"=",
"[",
"'breakpoints'",
",",
"'profiler'",
",",
"'pylint'",
"]",
"for",
"plugin_name",
"in",
"other_plugins",
":",
"if",
"CONF",
".",
"get",
"(",
"plugin_name",
",",
"'enable'",
")",
":",
"module",
"=",
"importlib",
".",
"import_module",
"(",
"'spyder.plugins.{}'",
".",
"format",
"(",
"plugin_name",
")",
")",
"plugin",
"=",
"module",
".",
"PLUGIN_CLASS",
"(",
"self",
")",
"if",
"plugin",
".",
"check_compatibility",
"(",
")",
"[",
"0",
"]",
":",
"self",
".",
"thirdparty_plugins",
".",
"append",
"(",
"plugin",
")",
"plugin",
".",
"register_plugin",
"(",
")",
"# Third-party plugins\r",
"self",
".",
"set_splash",
"(",
"_",
"(",
"\"Loading third-party plugins...\"",
")",
")",
"for",
"mod",
"in",
"get_spyderplugins_mods",
"(",
")",
":",
"try",
":",
"plugin",
"=",
"mod",
".",
"PLUGIN_CLASS",
"(",
"self",
")",
"if",
"plugin",
".",
"check_compatibility",
"(",
")",
"[",
"0",
"]",
":",
"self",
".",
"thirdparty_plugins",
".",
"append",
"(",
"plugin",
")",
"plugin",
".",
"register_plugin",
"(",
")",
"except",
"Exception",
"as",
"error",
":",
"print",
"(",
"\"%s: %s\"",
"%",
"(",
"mod",
",",
"str",
"(",
"error",
")",
")",
",",
"file",
"=",
"STDERR",
")",
"traceback",
".",
"print_exc",
"(",
"file",
"=",
"STDERR",
")",
"self",
".",
"set_splash",
"(",
"_",
"(",
"\"Setting up main window...\"",
")",
")",
"# Help menu\r",
"trouble_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Troubleshooting...\"",
")",
",",
"triggered",
"=",
"self",
".",
"trouble_guide",
")",
"dep_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Dependencies...\"",
")",
",",
"triggered",
"=",
"self",
".",
"show_dependencies",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'advanced'",
")",
")",
"report_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Report issue...\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'bug'",
")",
",",
"triggered",
"=",
"self",
".",
"report_issue",
")",
"support_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Spyder support...\"",
")",
",",
"triggered",
"=",
"self",
".",
"google_group",
")",
"self",
".",
"check_updates_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Check for updates...\"",
")",
",",
"triggered",
"=",
"self",
".",
"check_updates",
")",
"# Spyder documentation\r",
"spyder_doc",
"=",
"'https://docs.spyder-ide.org/'",
"doc_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Spyder documentation\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'DialogHelpButton'",
")",
",",
"triggered",
"=",
"lambda",
":",
"programs",
".",
"start_file",
"(",
"spyder_doc",
")",
")",
"self",
".",
"register_shortcut",
"(",
"doc_action",
",",
"\"_\"",
",",
"\"spyder documentation\"",
")",
"if",
"self",
".",
"help",
"is",
"not",
"None",
":",
"tut_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Spyder tutorial\"",
")",
",",
"triggered",
"=",
"self",
".",
"help",
".",
"show_tutorial",
")",
"else",
":",
"tut_action",
"=",
"None",
"shortcuts_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Shortcuts Summary\"",
")",
",",
"shortcut",
"=",
"\"Meta+F1\"",
",",
"triggered",
"=",
"self",
".",
"show_shortcuts_dialog",
")",
"#----- Tours\r",
"self",
".",
"tour",
"=",
"tour",
".",
"AnimatedTour",
"(",
"self",
")",
"self",
".",
"tours_menu",
"=",
"QMenu",
"(",
"_",
"(",
"\"Interactive tours\"",
")",
",",
"self",
")",
"self",
".",
"tour_menu_actions",
"=",
"[",
"]",
"# TODO: Only show intro tour for now. When we are close to finish\r",
"# 3.0, we will finish and show the other tour\r",
"self",
".",
"tours_available",
"=",
"tour",
".",
"get_tours",
"(",
"0",
")",
"for",
"i",
",",
"tour_available",
"in",
"enumerate",
"(",
"self",
".",
"tours_available",
")",
":",
"self",
".",
"tours_available",
"[",
"i",
"]",
"[",
"'last'",
"]",
"=",
"0",
"tour_name",
"=",
"tour_available",
"[",
"'name'",
"]",
"def",
"trigger",
"(",
"i",
"=",
"i",
",",
"self",
"=",
"self",
")",
":",
"# closure needed!\r",
"return",
"lambda",
":",
"self",
".",
"show_tour",
"(",
"i",
")",
"temp_action",
"=",
"create_action",
"(",
"self",
",",
"tour_name",
",",
"tip",
"=",
"\"\"",
",",
"triggered",
"=",
"trigger",
"(",
")",
")",
"self",
".",
"tour_menu_actions",
"+=",
"[",
"temp_action",
"]",
"self",
".",
"tours_menu",
".",
"addActions",
"(",
"self",
".",
"tour_menu_actions",
")",
"self",
".",
"help_menu_actions",
"=",
"[",
"doc_action",
",",
"tut_action",
",",
"shortcuts_action",
",",
"self",
".",
"tours_menu",
",",
"MENU_SEPARATOR",
",",
"trouble_action",
",",
"report_action",
",",
"dep_action",
",",
"self",
".",
"check_updates_action",
",",
"support_action",
",",
"MENU_SEPARATOR",
"]",
"# Python documentation\r",
"if",
"get_python_doc_path",
"(",
")",
"is",
"not",
"None",
":",
"pydoc_act",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Python documentation\"",
")",
",",
"triggered",
"=",
"lambda",
":",
"programs",
".",
"start_file",
"(",
"get_python_doc_path",
"(",
")",
")",
")",
"self",
".",
"help_menu_actions",
".",
"append",
"(",
"pydoc_act",
")",
"# IPython documentation\r",
"if",
"self",
".",
"help",
"is",
"not",
"None",
":",
"ipython_menu",
"=",
"QMenu",
"(",
"_",
"(",
"\"IPython documentation\"",
")",
",",
"self",
")",
"intro_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Intro to IPython\"",
")",
",",
"triggered",
"=",
"self",
".",
"ipyconsole",
".",
"show_intro",
")",
"quickref_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Quick reference\"",
")",
",",
"triggered",
"=",
"self",
".",
"ipyconsole",
".",
"show_quickref",
")",
"guiref_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Console help\"",
")",
",",
"triggered",
"=",
"self",
".",
"ipyconsole",
".",
"show_guiref",
")",
"add_actions",
"(",
"ipython_menu",
",",
"(",
"intro_action",
",",
"guiref_action",
",",
"quickref_action",
")",
")",
"self",
".",
"help_menu_actions",
".",
"append",
"(",
"ipython_menu",
")",
"# Windows-only: documentation located in sys.prefix/Doc\r",
"ipm_actions",
"=",
"[",
"]",
"def",
"add_ipm_action",
"(",
"text",
",",
"path",
")",
":",
"\"\"\"Add installed Python module doc action to help submenu\"\"\"",
"# QAction.triggered works differently for PySide and PyQt\r",
"path",
"=",
"file_uri",
"(",
"path",
")",
"if",
"not",
"API",
"==",
"'pyside'",
":",
"slot",
"=",
"lambda",
"_checked",
",",
"path",
"=",
"path",
":",
"programs",
".",
"start_file",
"(",
"path",
")",
"else",
":",
"slot",
"=",
"lambda",
"path",
"=",
"path",
":",
"programs",
".",
"start_file",
"(",
"path",
")",
"action",
"=",
"create_action",
"(",
"self",
",",
"text",
",",
"icon",
"=",
"'%s.png'",
"%",
"osp",
".",
"splitext",
"(",
"path",
")",
"[",
"1",
"]",
"[",
"1",
":",
"]",
",",
"triggered",
"=",
"slot",
")",
"ipm_actions",
".",
"append",
"(",
"action",
")",
"sysdocpth",
"=",
"osp",
".",
"join",
"(",
"sys",
".",
"prefix",
",",
"'Doc'",
")",
"if",
"osp",
".",
"isdir",
"(",
"sysdocpth",
")",
":",
"# exists on Windows, except frozen dist.\r",
"for",
"docfn",
"in",
"os",
".",
"listdir",
"(",
"sysdocpth",
")",
":",
"pt",
"=",
"r'([a-zA-Z\\_]*)(doc)?(-dev)?(-ref)?(-user)?.(chm|pdf)'",
"match",
"=",
"re",
".",
"match",
"(",
"pt",
",",
"docfn",
")",
"if",
"match",
"is",
"not",
"None",
":",
"pname",
"=",
"match",
".",
"groups",
"(",
")",
"[",
"0",
"]",
"if",
"pname",
"not",
"in",
"(",
"'Python'",
",",
")",
":",
"add_ipm_action",
"(",
"pname",
",",
"osp",
".",
"join",
"(",
"sysdocpth",
",",
"docfn",
")",
")",
"# Installed Python modules submenu (Windows only)\r",
"if",
"ipm_actions",
":",
"pymods_menu",
"=",
"QMenu",
"(",
"_",
"(",
"\"Installed Python modules\"",
")",
",",
"self",
")",
"add_actions",
"(",
"pymods_menu",
",",
"ipm_actions",
")",
"self",
".",
"help_menu_actions",
".",
"append",
"(",
"pymods_menu",
")",
"# Online documentation\r",
"web_resources",
"=",
"QMenu",
"(",
"_",
"(",
"\"Online documentation\"",
")",
",",
"self",
")",
"webres_actions",
"=",
"create_module_bookmark_actions",
"(",
"self",
",",
"self",
".",
"BOOKMARKS",
")",
"webres_actions",
".",
"insert",
"(",
"2",
",",
"None",
")",
"webres_actions",
".",
"insert",
"(",
"5",
",",
"None",
")",
"webres_actions",
".",
"insert",
"(",
"8",
",",
"None",
")",
"add_actions",
"(",
"web_resources",
",",
"webres_actions",
")",
"self",
".",
"help_menu_actions",
".",
"append",
"(",
"web_resources",
")",
"# Qt assistant link\r",
"if",
"sys",
".",
"platform",
".",
"startswith",
"(",
"'linux'",
")",
"and",
"not",
"PYQT5",
":",
"qta_exe",
"=",
"\"assistant-qt4\"",
"else",
":",
"qta_exe",
"=",
"\"assistant\"",
"qta_act",
"=",
"create_program_action",
"(",
"self",
",",
"_",
"(",
"\"Qt documentation\"",
")",
",",
"qta_exe",
")",
"if",
"qta_act",
":",
"self",
".",
"help_menu_actions",
"+=",
"[",
"qta_act",
",",
"None",
"]",
"# About Spyder\r",
"about_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"About %s...\"",
")",
"%",
"\"Spyder\"",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'MessageBoxInformation'",
")",
",",
"triggered",
"=",
"self",
".",
"about",
")",
"self",
".",
"help_menu_actions",
"+=",
"[",
"MENU_SEPARATOR",
",",
"about_action",
"]",
"# Status bar widgets\r",
"from",
"spyder",
".",
"widgets",
".",
"status",
"import",
"MemoryStatus",
",",
"CPUStatus",
"self",
".",
"mem_status",
"=",
"MemoryStatus",
"(",
"self",
",",
"status",
")",
"self",
".",
"cpu_status",
"=",
"CPUStatus",
"(",
"self",
",",
"status",
")",
"self",
".",
"apply_statusbar_settings",
"(",
")",
"# ----- View\r",
"# View menu\r",
"self",
".",
"plugins_menu",
"=",
"QMenu",
"(",
"_",
"(",
"\"Panes\"",
")",
",",
"self",
")",
"self",
".",
"toolbars_menu",
"=",
"QMenu",
"(",
"_",
"(",
"\"Toolbars\"",
")",
",",
"self",
")",
"self",
".",
"quick_layout_menu",
"=",
"QMenu",
"(",
"_",
"(",
"\"Window layouts\"",
")",
",",
"self",
")",
"self",
".",
"quick_layout_set_menu",
"(",
")",
"self",
".",
"view_menu",
".",
"addMenu",
"(",
"self",
".",
"plugins_menu",
")",
"# Panes\r",
"add_actions",
"(",
"self",
".",
"view_menu",
",",
"(",
"self",
".",
"lock_interface_action",
",",
"self",
".",
"close_dockwidget_action",
",",
"self",
".",
"maximize_action",
",",
"MENU_SEPARATOR",
")",
")",
"self",
".",
"show_toolbars_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Show toolbars\"",
")",
",",
"triggered",
"=",
"self",
".",
"show_toolbars",
",",
"context",
"=",
"Qt",
".",
"ApplicationShortcut",
")",
"self",
".",
"register_shortcut",
"(",
"self",
".",
"show_toolbars_action",
",",
"\"_\"",
",",
"\"Show toolbars\"",
")",
"self",
".",
"view_menu",
".",
"addMenu",
"(",
"self",
".",
"toolbars_menu",
")",
"self",
".",
"view_menu",
".",
"addAction",
"(",
"self",
".",
"show_toolbars_action",
")",
"add_actions",
"(",
"self",
".",
"view_menu",
",",
"(",
"MENU_SEPARATOR",
",",
"self",
".",
"quick_layout_menu",
",",
"self",
".",
"toggle_previous_layout_action",
",",
"self",
".",
"toggle_next_layout_action",
",",
"MENU_SEPARATOR",
",",
"self",
".",
"fullscreen_action",
")",
")",
"if",
"set_attached_console_visible",
"is",
"not",
"None",
":",
"cmd_act",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Attached console window (debugging)\"",
")",
",",
"toggled",
"=",
"set_attached_console_visible",
")",
"cmd_act",
".",
"setChecked",
"(",
"is_attached_console_visible",
"(",
")",
")",
"add_actions",
"(",
"self",
".",
"view_menu",
",",
"(",
"MENU_SEPARATOR",
",",
"cmd_act",
")",
")",
"# Adding external tools action to \"Tools\" menu\r",
"if",
"self",
".",
"external_tools_menu_actions",
":",
"external_tools_act",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"External Tools\"",
")",
")",
"external_tools_act",
".",
"setMenu",
"(",
"self",
".",
"external_tools_menu",
")",
"self",
".",
"tools_menu_actions",
"+=",
"[",
"None",
",",
"external_tools_act",
"]",
"# Filling out menu/toolbar entries:\r",
"add_actions",
"(",
"self",
".",
"file_menu",
",",
"self",
".",
"file_menu_actions",
")",
"add_actions",
"(",
"self",
".",
"edit_menu",
",",
"self",
".",
"edit_menu_actions",
")",
"add_actions",
"(",
"self",
".",
"search_menu",
",",
"self",
".",
"search_menu_actions",
")",
"add_actions",
"(",
"self",
".",
"source_menu",
",",
"self",
".",
"source_menu_actions",
")",
"add_actions",
"(",
"self",
".",
"run_menu",
",",
"self",
".",
"run_menu_actions",
")",
"add_actions",
"(",
"self",
".",
"debug_menu",
",",
"self",
".",
"debug_menu_actions",
")",
"add_actions",
"(",
"self",
".",
"consoles_menu",
",",
"self",
".",
"consoles_menu_actions",
")",
"add_actions",
"(",
"self",
".",
"projects_menu",
",",
"self",
".",
"projects_menu_actions",
")",
"add_actions",
"(",
"self",
".",
"tools_menu",
",",
"self",
".",
"tools_menu_actions",
")",
"add_actions",
"(",
"self",
".",
"external_tools_menu",
",",
"self",
".",
"external_tools_menu_actions",
")",
"add_actions",
"(",
"self",
".",
"help_menu",
",",
"self",
".",
"help_menu_actions",
")",
"add_actions",
"(",
"self",
".",
"main_toolbar",
",",
"self",
".",
"main_toolbar_actions",
")",
"add_actions",
"(",
"self",
".",
"file_toolbar",
",",
"self",
".",
"file_toolbar_actions",
")",
"add_actions",
"(",
"self",
".",
"edit_toolbar",
",",
"self",
".",
"edit_toolbar_actions",
")",
"add_actions",
"(",
"self",
".",
"search_toolbar",
",",
"self",
".",
"search_toolbar_actions",
")",
"add_actions",
"(",
"self",
".",
"source_toolbar",
",",
"self",
".",
"source_toolbar_actions",
")",
"add_actions",
"(",
"self",
".",
"debug_toolbar",
",",
"self",
".",
"debug_toolbar_actions",
")",
"add_actions",
"(",
"self",
".",
"run_toolbar",
",",
"self",
".",
"run_toolbar_actions",
")",
"# Apply all defined shortcuts (plugins + 3rd-party plugins)\r",
"self",
".",
"apply_shortcuts",
"(",
")",
"# Emitting the signal notifying plugins that main window menu and\r",
"# toolbar actions are all defined:\r",
"self",
".",
"all_actions_defined",
".",
"emit",
"(",
")",
"# Window set-up\r",
"logger",
".",
"info",
"(",
"\"Setting up window...\"",
")",
"self",
".",
"setup_layout",
"(",
"default",
"=",
"False",
")",
"# Show and hide shortcuts in menus for Mac.\r",
"# This is a workaround because we can't disable shortcuts\r",
"# by setting context=Qt.WidgetShortcut there\r",
"if",
"sys",
".",
"platform",
"==",
"'darwin'",
":",
"for",
"name",
"in",
"[",
"'file'",
",",
"'edit'",
",",
"'search'",
",",
"'source'",
",",
"'run'",
",",
"'debug'",
",",
"'projects'",
",",
"'tools'",
",",
"'plugins'",
"]",
":",
"menu_object",
"=",
"getattr",
"(",
"self",
",",
"name",
"+",
"'_menu'",
")",
"menu_object",
".",
"aboutToShow",
".",
"connect",
"(",
"lambda",
"name",
"=",
"name",
":",
"self",
".",
"show_shortcuts",
"(",
"name",
")",
")",
"menu_object",
".",
"aboutToHide",
".",
"connect",
"(",
"lambda",
"name",
"=",
"name",
":",
"self",
".",
"hide_shortcuts",
"(",
"name",
")",
")",
"if",
"self",
".",
"splash",
"is",
"not",
"None",
":",
"self",
".",
"splash",
".",
"hide",
"(",
")",
"# Enabling tear off for all menus except help menu\r",
"if",
"CONF",
".",
"get",
"(",
"'main'",
",",
"'tear_off_menus'",
")",
":",
"for",
"child",
"in",
"self",
".",
"menuBar",
"(",
")",
".",
"children",
"(",
")",
":",
"if",
"isinstance",
"(",
"child",
",",
"QMenu",
")",
"and",
"child",
"!=",
"self",
".",
"help_menu",
":",
"child",
".",
"setTearOffEnabled",
"(",
"True",
")",
"# Menu about to show\r",
"for",
"child",
"in",
"self",
".",
"menuBar",
"(",
")",
".",
"children",
"(",
")",
":",
"if",
"isinstance",
"(",
"child",
",",
"QMenu",
")",
":",
"try",
":",
"child",
".",
"aboutToShow",
".",
"connect",
"(",
"self",
".",
"update_edit_menu",
")",
"child",
".",
"aboutToShow",
".",
"connect",
"(",
"self",
".",
"update_search_menu",
")",
"except",
"TypeError",
":",
"pass",
"logger",
".",
"info",
"(",
"\"*** End of MainWindow setup ***\"",
")",
"self",
".",
"is_starting_up",
"=",
"False"
] | Setup main window | [
"Setup",
"main",
"window"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L593-L1263 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.post_visible_setup | def post_visible_setup(self):
"""Actions to be performed only after the main window's `show` method
was triggered"""
self.restore_scrollbar_position.emit()
# [Workaround for Issue 880]
# QDockWidget objects are not painted if restored as floating
# windows, so we must dock them before showing the mainwindow,
# 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
and self.open_files_server):
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()
# Update toolbar visibility status
self.toolbars_visible = CONF.get('main', 'toolbars_visible')
self.load_last_visible_toolbars()
# Update lock status
self.lock_interface_action.setChecked(self.interface_locked)
# Hide Internal Console so that people don't use it instead of
# the External or IPython ones
if self.console.dockwidget.isVisible() and DEV is None:
self.console.toggle_view_action.setChecked(False)
self.console.dockwidget.hide()
# Show Help and Consoles by default
plugins_to_show = [self.ipyconsole]
if self.help is not None:
plugins_to_show.append(self.help)
for plugin in plugins_to_show:
if plugin.dockwidget.isVisible():
plugin.dockwidget.raise_()
# Show history file if no console is visible
if not self.ipyconsole.isvisible:
self.historylog.add_history(get_conf_path('history.py'))
if self.open_project:
self.projects.open_project(self.open_project)
else:
# Load last project if a project was active when Spyder
# was closed
self.projects.reopen_last_project()
# If no project is active, load last session
if self.projects.get_active_project() is None:
self.editor.setup_open_files()
# Check for spyder updates
if DEV is None and CONF.get('main', 'check_updates_on_startup'):
self.give_updates_feedback = False
self.check_updates(startup=True)
# Show dialog with missing dependencies
self.report_missing_dependencies()
# Raise the menuBar to the top of the main window widget's stack
# (Fixes issue 3887)
self.menuBar().raise_()
self.is_setting_up = False | python | def post_visible_setup(self):
"""Actions to be performed only after the main window's `show` method
was triggered"""
self.restore_scrollbar_position.emit()
# [Workaround for Issue 880]
# QDockWidget objects are not painted if restored as floating
# windows, so we must dock them before showing the mainwindow,
# 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
and self.open_files_server):
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()
# Update toolbar visibility status
self.toolbars_visible = CONF.get('main', 'toolbars_visible')
self.load_last_visible_toolbars()
# Update lock status
self.lock_interface_action.setChecked(self.interface_locked)
# Hide Internal Console so that people don't use it instead of
# the External or IPython ones
if self.console.dockwidget.isVisible() and DEV is None:
self.console.toggle_view_action.setChecked(False)
self.console.dockwidget.hide()
# Show Help and Consoles by default
plugins_to_show = [self.ipyconsole]
if self.help is not None:
plugins_to_show.append(self.help)
for plugin in plugins_to_show:
if plugin.dockwidget.isVisible():
plugin.dockwidget.raise_()
# Show history file if no console is visible
if not self.ipyconsole.isvisible:
self.historylog.add_history(get_conf_path('history.py'))
if self.open_project:
self.projects.open_project(self.open_project)
else:
# Load last project if a project was active when Spyder
# was closed
self.projects.reopen_last_project()
# If no project is active, load last session
if self.projects.get_active_project() is None:
self.editor.setup_open_files()
# Check for spyder updates
if DEV is None and CONF.get('main', 'check_updates_on_startup'):
self.give_updates_feedback = False
self.check_updates(startup=True)
# Show dialog with missing dependencies
self.report_missing_dependencies()
# Raise the menuBar to the top of the main window widget's stack
# (Fixes issue 3887)
self.menuBar().raise_()
self.is_setting_up = False | [
"def",
"post_visible_setup",
"(",
"self",
")",
":",
"self",
".",
"restore_scrollbar_position",
".",
"emit",
"(",
")",
"# [Workaround for Issue 880]\r",
"# QDockWidget objects are not painted if restored as floating\r",
"# windows, so we must dock them before showing the mainwindow,\r",
"# then set them again as floating windows here.\r",
"for",
"widget",
"in",
"self",
".",
"floating_dockwidgets",
":",
"widget",
".",
"setFloating",
"(",
"True",
")",
"# In MacOS X 10.7 our app is not displayed after initialized (I don't\r",
"# know why because this doesn't happen when started from the terminal),\r",
"# so we need to resort to this hack to make it appear.\r",
"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\r",
"# the user tries to start other instances with\r",
"# $ spyder foo.py\r",
"if",
"(",
"CONF",
".",
"get",
"(",
"'main'",
",",
"'single_instance'",
")",
"and",
"not",
"self",
".",
"new_instance",
"and",
"self",
".",
"open_files_server",
")",
":",
"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\r",
"# when it gets a client connected to it\r",
"self",
".",
"sig_open_external_file",
".",
"connect",
"(",
"self",
".",
"open_external_file",
")",
"# Create Plugins and toolbars submenus\r",
"self",
".",
"create_plugins_menu",
"(",
")",
"self",
".",
"create_toolbars_menu",
"(",
")",
"# Update toolbar visibility status\r",
"self",
".",
"toolbars_visible",
"=",
"CONF",
".",
"get",
"(",
"'main'",
",",
"'toolbars_visible'",
")",
"self",
".",
"load_last_visible_toolbars",
"(",
")",
"# Update lock status\r",
"self",
".",
"lock_interface_action",
".",
"setChecked",
"(",
"self",
".",
"interface_locked",
")",
"# Hide Internal Console so that people don't use it instead of\r",
"# the External or IPython ones\r",
"if",
"self",
".",
"console",
".",
"dockwidget",
".",
"isVisible",
"(",
")",
"and",
"DEV",
"is",
"None",
":",
"self",
".",
"console",
".",
"toggle_view_action",
".",
"setChecked",
"(",
"False",
")",
"self",
".",
"console",
".",
"dockwidget",
".",
"hide",
"(",
")",
"# Show Help and Consoles by default\r",
"plugins_to_show",
"=",
"[",
"self",
".",
"ipyconsole",
"]",
"if",
"self",
".",
"help",
"is",
"not",
"None",
":",
"plugins_to_show",
".",
"append",
"(",
"self",
".",
"help",
")",
"for",
"plugin",
"in",
"plugins_to_show",
":",
"if",
"plugin",
".",
"dockwidget",
".",
"isVisible",
"(",
")",
":",
"plugin",
".",
"dockwidget",
".",
"raise_",
"(",
")",
"# Show history file if no console is visible\r",
"if",
"not",
"self",
".",
"ipyconsole",
".",
"isvisible",
":",
"self",
".",
"historylog",
".",
"add_history",
"(",
"get_conf_path",
"(",
"'history.py'",
")",
")",
"if",
"self",
".",
"open_project",
":",
"self",
".",
"projects",
".",
"open_project",
"(",
"self",
".",
"open_project",
")",
"else",
":",
"# Load last project if a project was active when Spyder\r",
"# was closed\r",
"self",
".",
"projects",
".",
"reopen_last_project",
"(",
")",
"# If no project is active, load last session\r",
"if",
"self",
".",
"projects",
".",
"get_active_project",
"(",
")",
"is",
"None",
":",
"self",
".",
"editor",
".",
"setup_open_files",
"(",
")",
"# Check for spyder updates\r",
"if",
"DEV",
"is",
"None",
"and",
"CONF",
".",
"get",
"(",
"'main'",
",",
"'check_updates_on_startup'",
")",
":",
"self",
".",
"give_updates_feedback",
"=",
"False",
"self",
".",
"check_updates",
"(",
"startup",
"=",
"True",
")",
"# Show dialog with missing dependencies\r",
"self",
".",
"report_missing_dependencies",
"(",
")",
"# Raise the menuBar to the top of the main window widget's stack\r",
"# (Fixes issue 3887)\r",
"self",
".",
"menuBar",
"(",
")",
".",
"raise_",
"(",
")",
"self",
".",
"is_setting_up",
"=",
"False"
] | Actions to be performed only after the main window's `show` method
was triggered | [
"Actions",
"to",
"be",
"performed",
"only",
"after",
"the",
"main",
"window",
"s",
"show",
"method",
"was",
"triggered"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L1265-L1349 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.set_window_title | def set_window_title(self):
"""Set window title."""
if DEV is not None:
title = u"Spyder %s (Python %s.%s)" % (__version__,
sys.version_info[0],
sys.version_info[1])
else:
title = u"Spyder (Python %s.%s)" % (sys.version_info[0],
sys.version_info[1])
if get_debug_level():
title += u" [DEBUG MODE %d]" % get_debug_level()
if self.window_title is not None:
title += u' -- ' + to_text_string(self.window_title)
if self.projects is not None:
path = self.projects.get_active_project_path()
if path:
path = path.replace(get_home_dir(), u'~')
title = u'{0} - {1}'.format(path, title)
self.base_title = title
self.setWindowTitle(self.base_title) | python | def set_window_title(self):
"""Set window title."""
if DEV is not None:
title = u"Spyder %s (Python %s.%s)" % (__version__,
sys.version_info[0],
sys.version_info[1])
else:
title = u"Spyder (Python %s.%s)" % (sys.version_info[0],
sys.version_info[1])
if get_debug_level():
title += u" [DEBUG MODE %d]" % get_debug_level()
if self.window_title is not None:
title += u' -- ' + to_text_string(self.window_title)
if self.projects is not None:
path = self.projects.get_active_project_path()
if path:
path = path.replace(get_home_dir(), u'~')
title = u'{0} - {1}'.format(path, title)
self.base_title = title
self.setWindowTitle(self.base_title) | [
"def",
"set_window_title",
"(",
"self",
")",
":",
"if",
"DEV",
"is",
"not",
"None",
":",
"title",
"=",
"u\"Spyder %s (Python %s.%s)\"",
"%",
"(",
"__version__",
",",
"sys",
".",
"version_info",
"[",
"0",
"]",
",",
"sys",
".",
"version_info",
"[",
"1",
"]",
")",
"else",
":",
"title",
"=",
"u\"Spyder (Python %s.%s)\"",
"%",
"(",
"sys",
".",
"version_info",
"[",
"0",
"]",
",",
"sys",
".",
"version_info",
"[",
"1",
"]",
")",
"if",
"get_debug_level",
"(",
")",
":",
"title",
"+=",
"u\" [DEBUG MODE %d]\"",
"%",
"get_debug_level",
"(",
")",
"if",
"self",
".",
"window_title",
"is",
"not",
"None",
":",
"title",
"+=",
"u' -- '",
"+",
"to_text_string",
"(",
"self",
".",
"window_title",
")",
"if",
"self",
".",
"projects",
"is",
"not",
"None",
":",
"path",
"=",
"self",
".",
"projects",
".",
"get_active_project_path",
"(",
")",
"if",
"path",
":",
"path",
"=",
"path",
".",
"replace",
"(",
"get_home_dir",
"(",
")",
",",
"u'~'",
")",
"title",
"=",
"u'{0} - {1}'",
".",
"format",
"(",
"path",
",",
"title",
")",
"self",
".",
"base_title",
"=",
"title",
"self",
".",
"setWindowTitle",
"(",
"self",
".",
"base_title",
")"
] | Set window title. | [
"Set",
"window",
"title",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L1351-L1374 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.report_missing_dependencies | def report_missing_dependencies(self):
"""Show a QMessageBox with a list of missing hard dependencies"""
missing_deps = dependencies.missing_dependencies()
if missing_deps:
QMessageBox.critical(self, _('Error'),
_("<b>You have missing dependencies!</b>"
"<br><br><tt>%s</tt><br><br>"
"<b>Please install them to avoid this message.</b>"
"<br><br>"
"<i>Note</i>: Spyder could work without some of these "
"dependencies, however to have a smooth experience when "
"using Spyder we <i>strongly</i> recommend you to install "
"all the listed missing dependencies.<br><br>"
"Failing to install these dependencies might result in bugs. "
"Please be sure that any found bugs are not the direct "
"result of missing dependencies, prior to reporting a new "
"issue."
) % missing_deps, QMessageBox.Ok) | python | def report_missing_dependencies(self):
"""Show a QMessageBox with a list of missing hard dependencies"""
missing_deps = dependencies.missing_dependencies()
if missing_deps:
QMessageBox.critical(self, _('Error'),
_("<b>You have missing dependencies!</b>"
"<br><br><tt>%s</tt><br><br>"
"<b>Please install them to avoid this message.</b>"
"<br><br>"
"<i>Note</i>: Spyder could work without some of these "
"dependencies, however to have a smooth experience when "
"using Spyder we <i>strongly</i> recommend you to install "
"all the listed missing dependencies.<br><br>"
"Failing to install these dependencies might result in bugs. "
"Please be sure that any found bugs are not the direct "
"result of missing dependencies, prior to reporting a new "
"issue."
) % missing_deps, QMessageBox.Ok) | [
"def",
"report_missing_dependencies",
"(",
"self",
")",
":",
"missing_deps",
"=",
"dependencies",
".",
"missing_dependencies",
"(",
")",
"if",
"missing_deps",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"'Error'",
")",
",",
"_",
"(",
"\"<b>You have missing dependencies!</b>\"",
"\"<br><br><tt>%s</tt><br><br>\"",
"\"<b>Please install them to avoid this message.</b>\"",
"\"<br><br>\"",
"\"<i>Note</i>: Spyder could work without some of these \"",
"\"dependencies, however to have a smooth experience when \"",
"\"using Spyder we <i>strongly</i> recommend you to install \"",
"\"all the listed missing dependencies.<br><br>\"",
"\"Failing to install these dependencies might result in bugs. \"",
"\"Please be sure that any found bugs are not the direct \"",
"\"result of missing dependencies, prior to reporting a new \"",
"\"issue.\"",
")",
"%",
"missing_deps",
",",
"QMessageBox",
".",
"Ok",
")"
] | Show a QMessageBox with a list of missing hard dependencies | [
"Show",
"a",
"QMessageBox",
"with",
"a",
"list",
"of",
"missing",
"hard",
"dependencies"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L1376-L1393 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.load_window_settings | def load_window_settings(self, prefix, default=False, section='main'):
"""Load window layout settings from userconfig-based configuration
with *prefix*, under *section*
default: if True, do not restore inner layout"""
get_func = CONF.get_default if default else CONF.get
window_size = get_func(section, prefix+'size')
prefs_dialog_size = get_func(section, prefix+'prefs_dialog_size')
if default:
hexstate = None
else:
hexstate = get_func(section, prefix+'state', None)
pos = get_func(section, prefix+'position')
# It's necessary to verify if the window/position value is valid
# with the current screen. See issue 3748
width = pos[0]
height = pos[1]
screen_shape = QApplication.desktop().geometry()
current_width = screen_shape.width()
current_height = screen_shape.height()
if current_width < width or current_height < height:
pos = CONF.get_default(section, prefix+'position')
is_maximized = get_func(section, prefix+'is_maximized')
is_fullscreen = get_func(section, prefix+'is_fullscreen')
return hexstate, window_size, prefs_dialog_size, pos, is_maximized, \
is_fullscreen | python | def load_window_settings(self, prefix, default=False, section='main'):
"""Load window layout settings from userconfig-based configuration
with *prefix*, under *section*
default: if True, do not restore inner layout"""
get_func = CONF.get_default if default else CONF.get
window_size = get_func(section, prefix+'size')
prefs_dialog_size = get_func(section, prefix+'prefs_dialog_size')
if default:
hexstate = None
else:
hexstate = get_func(section, prefix+'state', None)
pos = get_func(section, prefix+'position')
# It's necessary to verify if the window/position value is valid
# with the current screen. See issue 3748
width = pos[0]
height = pos[1]
screen_shape = QApplication.desktop().geometry()
current_width = screen_shape.width()
current_height = screen_shape.height()
if current_width < width or current_height < height:
pos = CONF.get_default(section, prefix+'position')
is_maximized = get_func(section, prefix+'is_maximized')
is_fullscreen = get_func(section, prefix+'is_fullscreen')
return hexstate, window_size, prefs_dialog_size, pos, is_maximized, \
is_fullscreen | [
"def",
"load_window_settings",
"(",
"self",
",",
"prefix",
",",
"default",
"=",
"False",
",",
"section",
"=",
"'main'",
")",
":",
"get_func",
"=",
"CONF",
".",
"get_default",
"if",
"default",
"else",
"CONF",
".",
"get",
"window_size",
"=",
"get_func",
"(",
"section",
",",
"prefix",
"+",
"'size'",
")",
"prefs_dialog_size",
"=",
"get_func",
"(",
"section",
",",
"prefix",
"+",
"'prefs_dialog_size'",
")",
"if",
"default",
":",
"hexstate",
"=",
"None",
"else",
":",
"hexstate",
"=",
"get_func",
"(",
"section",
",",
"prefix",
"+",
"'state'",
",",
"None",
")",
"pos",
"=",
"get_func",
"(",
"section",
",",
"prefix",
"+",
"'position'",
")",
"# It's necessary to verify if the window/position value is valid\r",
"# with the current screen. See issue 3748\r",
"width",
"=",
"pos",
"[",
"0",
"]",
"height",
"=",
"pos",
"[",
"1",
"]",
"screen_shape",
"=",
"QApplication",
".",
"desktop",
"(",
")",
".",
"geometry",
"(",
")",
"current_width",
"=",
"screen_shape",
".",
"width",
"(",
")",
"current_height",
"=",
"screen_shape",
".",
"height",
"(",
")",
"if",
"current_width",
"<",
"width",
"or",
"current_height",
"<",
"height",
":",
"pos",
"=",
"CONF",
".",
"get_default",
"(",
"section",
",",
"prefix",
"+",
"'position'",
")",
"is_maximized",
"=",
"get_func",
"(",
"section",
",",
"prefix",
"+",
"'is_maximized'",
")",
"is_fullscreen",
"=",
"get_func",
"(",
"section",
",",
"prefix",
"+",
"'is_fullscreen'",
")",
"return",
"hexstate",
",",
"window_size",
",",
"prefs_dialog_size",
",",
"pos",
",",
"is_maximized",
",",
"is_fullscreen"
] | Load window layout settings from userconfig-based configuration
with *prefix*, under *section*
default: if True, do not restore inner layout | [
"Load",
"window",
"layout",
"settings",
"from",
"userconfig",
"-",
"based",
"configuration",
"with",
"*",
"prefix",
"*",
"under",
"*",
"section",
"*",
"default",
":",
"if",
"True",
"do",
"not",
"restore",
"inner",
"layout"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L1395-L1421 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.get_window_settings | def get_window_settings(self):
"""Return current window settings
Symetric to the 'set_window_settings' setter"""
window_size = (self.window_size.width(), self.window_size.height())
is_fullscreen = self.isFullScreen()
if is_fullscreen:
is_maximized = self.maximized_flag
else:
is_maximized = self.isMaximized()
pos = (self.window_position.x(), self.window_position.y())
prefs_dialog_size = (self.prefs_dialog_size.width(),
self.prefs_dialog_size.height())
hexstate = qbytearray_to_str(self.saveState())
return (hexstate, window_size, prefs_dialog_size, pos, is_maximized,
is_fullscreen) | python | def get_window_settings(self):
"""Return current window settings
Symetric to the 'set_window_settings' setter"""
window_size = (self.window_size.width(), self.window_size.height())
is_fullscreen = self.isFullScreen()
if is_fullscreen:
is_maximized = self.maximized_flag
else:
is_maximized = self.isMaximized()
pos = (self.window_position.x(), self.window_position.y())
prefs_dialog_size = (self.prefs_dialog_size.width(),
self.prefs_dialog_size.height())
hexstate = qbytearray_to_str(self.saveState())
return (hexstate, window_size, prefs_dialog_size, pos, is_maximized,
is_fullscreen) | [
"def",
"get_window_settings",
"(",
"self",
")",
":",
"window_size",
"=",
"(",
"self",
".",
"window_size",
".",
"width",
"(",
")",
",",
"self",
".",
"window_size",
".",
"height",
"(",
")",
")",
"is_fullscreen",
"=",
"self",
".",
"isFullScreen",
"(",
")",
"if",
"is_fullscreen",
":",
"is_maximized",
"=",
"self",
".",
"maximized_flag",
"else",
":",
"is_maximized",
"=",
"self",
".",
"isMaximized",
"(",
")",
"pos",
"=",
"(",
"self",
".",
"window_position",
".",
"x",
"(",
")",
",",
"self",
".",
"window_position",
".",
"y",
"(",
")",
")",
"prefs_dialog_size",
"=",
"(",
"self",
".",
"prefs_dialog_size",
".",
"width",
"(",
")",
",",
"self",
".",
"prefs_dialog_size",
".",
"height",
"(",
")",
")",
"hexstate",
"=",
"qbytearray_to_str",
"(",
"self",
".",
"saveState",
"(",
")",
")",
"return",
"(",
"hexstate",
",",
"window_size",
",",
"prefs_dialog_size",
",",
"pos",
",",
"is_maximized",
",",
"is_fullscreen",
")"
] | Return current window settings
Symetric to the 'set_window_settings' setter | [
"Return",
"current",
"window",
"settings",
"Symetric",
"to",
"the",
"set_window_settings",
"setter"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L1423-L1437 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.set_window_settings | def set_window_settings(self, hexstate, window_size, prefs_dialog_size,
pos, is_maximized, is_fullscreen):
"""Set window settings
Symetric to the 'get_window_settings' accessor"""
self.setUpdatesEnabled(False)
self.window_size = QSize(window_size[0], window_size[1]) # width,height
self.prefs_dialog_size = QSize(prefs_dialog_size[0],
prefs_dialog_size[1]) # width,height
self.window_position = QPoint(pos[0], pos[1]) # x,y
self.setWindowState(Qt.WindowNoState)
self.resize(self.window_size)
self.move(self.window_position)
# Window layout
if hexstate:
self.restoreState( QByteArray().fromHex(
str(hexstate).encode('utf-8')) )
# [Workaround for Issue 880]
# QDockWidget objects are not painted if restored as floating
# windows, so we must dock them before showing the mainwindow.
for widget in self.children():
if isinstance(widget, QDockWidget) and widget.isFloating():
self.floating_dockwidgets.append(widget)
widget.setFloating(False)
# Is fullscreen?
if is_fullscreen:
self.setWindowState(Qt.WindowFullScreen)
self.__update_fullscreen_action()
# Is maximized?
if is_fullscreen:
self.maximized_flag = is_maximized
elif is_maximized:
self.setWindowState(Qt.WindowMaximized)
self.setUpdatesEnabled(True) | python | def set_window_settings(self, hexstate, window_size, prefs_dialog_size,
pos, is_maximized, is_fullscreen):
"""Set window settings
Symetric to the 'get_window_settings' accessor"""
self.setUpdatesEnabled(False)
self.window_size = QSize(window_size[0], window_size[1]) # width,height
self.prefs_dialog_size = QSize(prefs_dialog_size[0],
prefs_dialog_size[1]) # width,height
self.window_position = QPoint(pos[0], pos[1]) # x,y
self.setWindowState(Qt.WindowNoState)
self.resize(self.window_size)
self.move(self.window_position)
# Window layout
if hexstate:
self.restoreState( QByteArray().fromHex(
str(hexstate).encode('utf-8')) )
# [Workaround for Issue 880]
# QDockWidget objects are not painted if restored as floating
# windows, so we must dock them before showing the mainwindow.
for widget in self.children():
if isinstance(widget, QDockWidget) and widget.isFloating():
self.floating_dockwidgets.append(widget)
widget.setFloating(False)
# Is fullscreen?
if is_fullscreen:
self.setWindowState(Qt.WindowFullScreen)
self.__update_fullscreen_action()
# Is maximized?
if is_fullscreen:
self.maximized_flag = is_maximized
elif is_maximized:
self.setWindowState(Qt.WindowMaximized)
self.setUpdatesEnabled(True) | [
"def",
"set_window_settings",
"(",
"self",
",",
"hexstate",
",",
"window_size",
",",
"prefs_dialog_size",
",",
"pos",
",",
"is_maximized",
",",
"is_fullscreen",
")",
":",
"self",
".",
"setUpdatesEnabled",
"(",
"False",
")",
"self",
".",
"window_size",
"=",
"QSize",
"(",
"window_size",
"[",
"0",
"]",
",",
"window_size",
"[",
"1",
"]",
")",
"# width,height\r",
"self",
".",
"prefs_dialog_size",
"=",
"QSize",
"(",
"prefs_dialog_size",
"[",
"0",
"]",
",",
"prefs_dialog_size",
"[",
"1",
"]",
")",
"# width,height\r",
"self",
".",
"window_position",
"=",
"QPoint",
"(",
"pos",
"[",
"0",
"]",
",",
"pos",
"[",
"1",
"]",
")",
"# x,y\r",
"self",
".",
"setWindowState",
"(",
"Qt",
".",
"WindowNoState",
")",
"self",
".",
"resize",
"(",
"self",
".",
"window_size",
")",
"self",
".",
"move",
"(",
"self",
".",
"window_position",
")",
"# Window layout\r",
"if",
"hexstate",
":",
"self",
".",
"restoreState",
"(",
"QByteArray",
"(",
")",
".",
"fromHex",
"(",
"str",
"(",
"hexstate",
")",
".",
"encode",
"(",
"'utf-8'",
")",
")",
")",
"# [Workaround for Issue 880]\r",
"# QDockWidget objects are not painted if restored as floating\r",
"# windows, so we must dock them before showing the mainwindow.\r",
"for",
"widget",
"in",
"self",
".",
"children",
"(",
")",
":",
"if",
"isinstance",
"(",
"widget",
",",
"QDockWidget",
")",
"and",
"widget",
".",
"isFloating",
"(",
")",
":",
"self",
".",
"floating_dockwidgets",
".",
"append",
"(",
"widget",
")",
"widget",
".",
"setFloating",
"(",
"False",
")",
"# Is fullscreen?\r",
"if",
"is_fullscreen",
":",
"self",
".",
"setWindowState",
"(",
"Qt",
".",
"WindowFullScreen",
")",
"self",
".",
"__update_fullscreen_action",
"(",
")",
"# Is maximized?\r",
"if",
"is_fullscreen",
":",
"self",
".",
"maximized_flag",
"=",
"is_maximized",
"elif",
"is_maximized",
":",
"self",
".",
"setWindowState",
"(",
"Qt",
".",
"WindowMaximized",
")",
"self",
".",
"setUpdatesEnabled",
"(",
"True",
")"
] | Set window settings
Symetric to the 'get_window_settings' accessor | [
"Set",
"window",
"settings",
"Symetric",
"to",
"the",
"get_window_settings",
"accessor"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L1439-L1474 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.save_current_window_settings | def save_current_window_settings(self, prefix, section='main',
none_state=False):
"""Save current window settings with *prefix* in
the userconfig-based configuration, under *section*"""
win_size = self.window_size
prefs_size = self.prefs_dialog_size
CONF.set(section, prefix+'size', (win_size.width(), win_size.height()))
CONF.set(section, prefix+'prefs_dialog_size',
(prefs_size.width(), prefs_size.height()))
CONF.set(section, prefix+'is_maximized', self.isMaximized())
CONF.set(section, prefix+'is_fullscreen', self.isFullScreen())
pos = self.window_position
CONF.set(section, prefix+'position', (pos.x(), pos.y()))
self.maximize_dockwidget(restore=True)# Restore non-maximized layout
if none_state:
CONF.set(section, prefix + 'state', None)
else:
qba = self.saveState()
CONF.set(section, prefix + 'state', qbytearray_to_str(qba))
CONF.set(section, prefix+'statusbar',
not self.statusBar().isHidden()) | python | def save_current_window_settings(self, prefix, section='main',
none_state=False):
"""Save current window settings with *prefix* in
the userconfig-based configuration, under *section*"""
win_size = self.window_size
prefs_size = self.prefs_dialog_size
CONF.set(section, prefix+'size', (win_size.width(), win_size.height()))
CONF.set(section, prefix+'prefs_dialog_size',
(prefs_size.width(), prefs_size.height()))
CONF.set(section, prefix+'is_maximized', self.isMaximized())
CONF.set(section, prefix+'is_fullscreen', self.isFullScreen())
pos = self.window_position
CONF.set(section, prefix+'position', (pos.x(), pos.y()))
self.maximize_dockwidget(restore=True)# Restore non-maximized layout
if none_state:
CONF.set(section, prefix + 'state', None)
else:
qba = self.saveState()
CONF.set(section, prefix + 'state', qbytearray_to_str(qba))
CONF.set(section, prefix+'statusbar',
not self.statusBar().isHidden()) | [
"def",
"save_current_window_settings",
"(",
"self",
",",
"prefix",
",",
"section",
"=",
"'main'",
",",
"none_state",
"=",
"False",
")",
":",
"win_size",
"=",
"self",
".",
"window_size",
"prefs_size",
"=",
"self",
".",
"prefs_dialog_size",
"CONF",
".",
"set",
"(",
"section",
",",
"prefix",
"+",
"'size'",
",",
"(",
"win_size",
".",
"width",
"(",
")",
",",
"win_size",
".",
"height",
"(",
")",
")",
")",
"CONF",
".",
"set",
"(",
"section",
",",
"prefix",
"+",
"'prefs_dialog_size'",
",",
"(",
"prefs_size",
".",
"width",
"(",
")",
",",
"prefs_size",
".",
"height",
"(",
")",
")",
")",
"CONF",
".",
"set",
"(",
"section",
",",
"prefix",
"+",
"'is_maximized'",
",",
"self",
".",
"isMaximized",
"(",
")",
")",
"CONF",
".",
"set",
"(",
"section",
",",
"prefix",
"+",
"'is_fullscreen'",
",",
"self",
".",
"isFullScreen",
"(",
")",
")",
"pos",
"=",
"self",
".",
"window_position",
"CONF",
".",
"set",
"(",
"section",
",",
"prefix",
"+",
"'position'",
",",
"(",
"pos",
".",
"x",
"(",
")",
",",
"pos",
".",
"y",
"(",
")",
")",
")",
"self",
".",
"maximize_dockwidget",
"(",
"restore",
"=",
"True",
")",
"# Restore non-maximized layout\r",
"if",
"none_state",
":",
"CONF",
".",
"set",
"(",
"section",
",",
"prefix",
"+",
"'state'",
",",
"None",
")",
"else",
":",
"qba",
"=",
"self",
".",
"saveState",
"(",
")",
"CONF",
".",
"set",
"(",
"section",
",",
"prefix",
"+",
"'state'",
",",
"qbytearray_to_str",
"(",
"qba",
")",
")",
"CONF",
".",
"set",
"(",
"section",
",",
"prefix",
"+",
"'statusbar'",
",",
"not",
"self",
".",
"statusBar",
"(",
")",
".",
"isHidden",
"(",
")",
")"
] | Save current window settings with *prefix* in
the userconfig-based configuration, under *section* | [
"Save",
"current",
"window",
"settings",
"with",
"*",
"prefix",
"*",
"in",
"the",
"userconfig",
"-",
"based",
"configuration",
"under",
"*",
"section",
"*"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L1476-L1497 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.tabify_plugins | def tabify_plugins(self, first, second):
"""Tabify plugin dockwigdets"""
self.tabifyDockWidget(first.dockwidget, second.dockwidget) | python | def tabify_plugins(self, first, second):
"""Tabify plugin dockwigdets"""
self.tabifyDockWidget(first.dockwidget, second.dockwidget) | [
"def",
"tabify_plugins",
"(",
"self",
",",
"first",
",",
"second",
")",
":",
"self",
".",
"tabifyDockWidget",
"(",
"first",
".",
"dockwidget",
",",
"second",
".",
"dockwidget",
")"
] | Tabify plugin dockwigdets | [
"Tabify",
"plugin",
"dockwigdets"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L1499-L1501 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.setup_layout | def setup_layout(self, default=False):
"""Setup window layout"""
prefix = 'window' + '/'
settings = self.load_window_settings(prefix, default)
hexstate = settings[0]
self.first_spyder_run = False
if hexstate is None:
# First Spyder execution:
self.setWindowState(Qt.WindowMaximized)
self.first_spyder_run = True
self.setup_default_layouts('default', settings)
# Now that the initial setup is done, copy the window settings,
# except for the hexstate in the quick layouts sections for the
# default layouts.
# Order and name of the default layouts is found in config.py
section = 'quick_layouts'
get_func = CONF.get_default if default else CONF.get
order = get_func(section, 'order')
# restore the original defaults if reset layouts is called
if default:
CONF.set(section, 'active', order)
CONF.set(section, 'order', order)
CONF.set(section, 'names', order)
for index, name, in enumerate(order):
prefix = 'layout_{0}/'.format(index)
self.save_current_window_settings(prefix, section,
none_state=True)
# store the initial layout as the default in spyder
prefix = 'layout_default/'
section = 'quick_layouts'
self.save_current_window_settings(prefix, section, none_state=True)
self.current_quick_layout = 'default'
# Regenerate menu
self.quick_layout_set_menu()
self.set_window_settings(*settings)
for plugin in (self.widgetlist + self.thirdparty_plugins):
try:
plugin.initialize_plugin_in_mainwindow_layout()
except Exception as error:
print("%s: %s" % (plugin, str(error)), file=STDERR)
traceback.print_exc(file=STDERR) | python | def setup_layout(self, default=False):
"""Setup window layout"""
prefix = 'window' + '/'
settings = self.load_window_settings(prefix, default)
hexstate = settings[0]
self.first_spyder_run = False
if hexstate is None:
# First Spyder execution:
self.setWindowState(Qt.WindowMaximized)
self.first_spyder_run = True
self.setup_default_layouts('default', settings)
# Now that the initial setup is done, copy the window settings,
# except for the hexstate in the quick layouts sections for the
# default layouts.
# Order and name of the default layouts is found in config.py
section = 'quick_layouts'
get_func = CONF.get_default if default else CONF.get
order = get_func(section, 'order')
# restore the original defaults if reset layouts is called
if default:
CONF.set(section, 'active', order)
CONF.set(section, 'order', order)
CONF.set(section, 'names', order)
for index, name, in enumerate(order):
prefix = 'layout_{0}/'.format(index)
self.save_current_window_settings(prefix, section,
none_state=True)
# store the initial layout as the default in spyder
prefix = 'layout_default/'
section = 'quick_layouts'
self.save_current_window_settings(prefix, section, none_state=True)
self.current_quick_layout = 'default'
# Regenerate menu
self.quick_layout_set_menu()
self.set_window_settings(*settings)
for plugin in (self.widgetlist + self.thirdparty_plugins):
try:
plugin.initialize_plugin_in_mainwindow_layout()
except Exception as error:
print("%s: %s" % (plugin, str(error)), file=STDERR)
traceback.print_exc(file=STDERR) | [
"def",
"setup_layout",
"(",
"self",
",",
"default",
"=",
"False",
")",
":",
"prefix",
"=",
"'window'",
"+",
"'/'",
"settings",
"=",
"self",
".",
"load_window_settings",
"(",
"prefix",
",",
"default",
")",
"hexstate",
"=",
"settings",
"[",
"0",
"]",
"self",
".",
"first_spyder_run",
"=",
"False",
"if",
"hexstate",
"is",
"None",
":",
"# First Spyder execution:\r",
"self",
".",
"setWindowState",
"(",
"Qt",
".",
"WindowMaximized",
")",
"self",
".",
"first_spyder_run",
"=",
"True",
"self",
".",
"setup_default_layouts",
"(",
"'default'",
",",
"settings",
")",
"# Now that the initial setup is done, copy the window settings,\r",
"# except for the hexstate in the quick layouts sections for the\r",
"# default layouts.\r",
"# Order and name of the default layouts is found in config.py\r",
"section",
"=",
"'quick_layouts'",
"get_func",
"=",
"CONF",
".",
"get_default",
"if",
"default",
"else",
"CONF",
".",
"get",
"order",
"=",
"get_func",
"(",
"section",
",",
"'order'",
")",
"# restore the original defaults if reset layouts is called\r",
"if",
"default",
":",
"CONF",
".",
"set",
"(",
"section",
",",
"'active'",
",",
"order",
")",
"CONF",
".",
"set",
"(",
"section",
",",
"'order'",
",",
"order",
")",
"CONF",
".",
"set",
"(",
"section",
",",
"'names'",
",",
"order",
")",
"for",
"index",
",",
"name",
",",
"in",
"enumerate",
"(",
"order",
")",
":",
"prefix",
"=",
"'layout_{0}/'",
".",
"format",
"(",
"index",
")",
"self",
".",
"save_current_window_settings",
"(",
"prefix",
",",
"section",
",",
"none_state",
"=",
"True",
")",
"# store the initial layout as the default in spyder\r",
"prefix",
"=",
"'layout_default/'",
"section",
"=",
"'quick_layouts'",
"self",
".",
"save_current_window_settings",
"(",
"prefix",
",",
"section",
",",
"none_state",
"=",
"True",
")",
"self",
".",
"current_quick_layout",
"=",
"'default'",
"# Regenerate menu\r",
"self",
".",
"quick_layout_set_menu",
"(",
")",
"self",
".",
"set_window_settings",
"(",
"*",
"settings",
")",
"for",
"plugin",
"in",
"(",
"self",
".",
"widgetlist",
"+",
"self",
".",
"thirdparty_plugins",
")",
":",
"try",
":",
"plugin",
".",
"initialize_plugin_in_mainwindow_layout",
"(",
")",
"except",
"Exception",
"as",
"error",
":",
"print",
"(",
"\"%s: %s\"",
"%",
"(",
"plugin",
",",
"str",
"(",
"error",
")",
")",
",",
"file",
"=",
"STDERR",
")",
"traceback",
".",
"print_exc",
"(",
"file",
"=",
"STDERR",
")"
] | Setup window layout | [
"Setup",
"window",
"layout"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L1504-L1551 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.setup_default_layouts | def setup_default_layouts(self, index, settings):
"""Setup default layouts when run for the first time."""
self.setUpdatesEnabled(False)
first_spyder_run = bool(self.first_spyder_run) # Store copy
if first_spyder_run:
self.set_window_settings(*settings)
else:
if self.last_plugin:
if self.last_plugin.ismaximized:
self.maximize_dockwidget(restore=True)
if not (self.isMaximized() or self.maximized_flag):
self.showMaximized()
min_width = self.minimumWidth()
max_width = self.maximumWidth()
base_width = self.width()
self.setFixedWidth(base_width)
# IMPORTANT: order has to be the same as defined in the config file
MATLAB, RSTUDIO, VERTICAL, HORIZONTAL = range(self.DEFAULT_LAYOUTS)
# Define widgets locally
editor = self.editor
console_ipy = self.ipyconsole
console_int = self.console
outline = self.outlineexplorer
explorer_project = self.projects
explorer_file = self.explorer
explorer_variable = self.variableexplorer
plots = self.plots
history = self.historylog
finder = self.findinfiles
help_plugin = self.help
helper = self.onlinehelp
plugins = self.thirdparty_plugins
# Stored for tests
global_hidden_widgets = [finder, console_int, explorer_project,
helper] + plugins
global_hidden_toolbars = [self.source_toolbar, self.edit_toolbar,
self.search_toolbar]
# Layout definition
# --------------------------------------------------------------------
# Layouts are organized by columns, each column is organized by rows.
# Widths have to add 1.0 (except if hidden), height per column has to
# add 1.0 as well
# Spyder Default Initial Layout
s_layout = {
'widgets': [
# Column 0
[[explorer_project]],
# Column 1
[[editor]],
# Column 2
[[outline]],
# Column 3
[[help_plugin, explorer_variable, plots, # Row 0
helper, explorer_file, finder] + plugins,
[console_int, console_ipy, history]] # Row 1
],
'width fraction': [0.05, # Column 0 width
0.55, # Column 1 width
0.05, # Column 2 width
0.45], # Column 3 width
'height fraction': [[1.0], # Column 0, row heights
[1.0], # Column 1, row heights
[1.0], # Column 2, row heights
[0.46, 0.54]], # Column 3, row heights
'hidden widgets': [outline] + global_hidden_widgets,
'hidden toolbars': [],
}
# RStudio
r_layout = {
'widgets': [
# column 0
[[editor], # Row 0
[console_ipy, console_int]], # Row 1
# column 1
[[explorer_variable, plots, history, # Row 0
outline, finder] + plugins,
[explorer_file, explorer_project, # Row 1
help_plugin, helper]]
],
'width fraction': [0.55, # Column 0 width
0.45], # Column 1 width
'height fraction': [[0.55, 0.45], # Column 0, row heights
[0.55, 0.45]], # Column 1, row heights
'hidden widgets': [outline] + global_hidden_widgets,
'hidden toolbars': [],
}
# Matlab
m_layout = {
'widgets': [
# column 0
[[explorer_file, explorer_project],
[outline]],
# column 1
[[editor],
[console_ipy, console_int]],
# column 2
[[explorer_variable, plots, finder] + plugins,
[history, help_plugin, helper]]
],
'width fraction': [0.10, # Column 0 width
0.45, # Column 1 width
0.45], # Column 2 width
'height fraction': [[0.55, 0.45], # Column 0, row heights
[0.55, 0.45], # Column 1, row heights
[0.55, 0.45]], # Column 2, row heights
'hidden widgets': global_hidden_widgets,
'hidden toolbars': [],
}
# Vertically split
v_layout = {
'widgets': [
# column 0
[[editor], # Row 0
[console_ipy, console_int, explorer_file, # Row 1
explorer_project, help_plugin, explorer_variable, plots,
history, outline, finder, helper] + plugins]
],
'width fraction': [1.0], # Column 0 width
'height fraction': [[0.55, 0.45]], # Column 0, row heights
'hidden widgets': [outline] + global_hidden_widgets,
'hidden toolbars': [],
}
# Horizontally split
h_layout = {
'widgets': [
# column 0
[[editor]], # Row 0
# column 1
[[console_ipy, console_int, explorer_file, # Row 0
explorer_project, help_plugin, explorer_variable, plots,
history, outline, finder, helper] + plugins]
],
'width fraction': [0.55, # Column 0 width
0.45], # Column 1 width
'height fraction': [[1.0], # Column 0, row heights
[1.0]], # Column 1, row heights
'hidden widgets': [outline] + global_hidden_widgets,
'hidden toolbars': []
}
# Layout selection
layouts = {
'default': s_layout,
RSTUDIO: r_layout,
MATLAB: m_layout,
VERTICAL: v_layout,
HORIZONTAL: h_layout,
}
layout = layouts[index]
# Remove None from widgets layout
widgets_layout = layout['widgets']
widgets_layout_clean = []
for column in widgets_layout:
clean_col = []
for row in column:
clean_row = [w for w in row if w is not None]
if clean_row:
clean_col.append(clean_row)
if clean_col:
widgets_layout_clean.append(clean_col)
# Flatten widgets list
widgets = []
for column in widgets_layout_clean:
for row in column:
for widget in row:
widgets.append(widget)
# Make every widget visible
for widget in widgets:
widget.toggle_view(True)
widget.toggle_view_action.setChecked(True)
# We use both directions to ensure proper update when moving from
# 'Horizontal Split' to 'Spyder Default'
# This also seems to help on random cases where the display seems
# 'empty'
for direction in (Qt.Vertical, Qt.Horizontal):
# Arrange the widgets in one direction
for idx in range(len(widgets) - 1):
first, second = widgets[idx], widgets[idx+1]
if first is not None and second is not None:
self.splitDockWidget(first.dockwidget, second.dockwidget,
direction)
# Arrange the widgets in the other direction
for column in widgets_layout_clean:
for idx in range(len(column) - 1):
first_row, second_row = column[idx], column[idx+1]
self.splitDockWidget(first_row[0].dockwidget,
second_row[0].dockwidget,
Qt.Vertical)
# Tabify
for column in widgets_layout_clean:
for row in column:
for idx in range(len(row) - 1):
first, second = row[idx], row[idx+1]
self.tabify_plugins(first, second)
# Raise front widget per row
row[0].dockwidget.show()
row[0].dockwidget.raise_()
# Set dockwidget widths
width_fractions = layout['width fraction']
if len(width_fractions) > 1:
_widgets = [col[0][0].dockwidget for col in widgets_layout]
self.resizeDocks(_widgets, width_fractions, Qt.Horizontal)
# Set dockwidget heights
height_fractions = layout['height fraction']
for idx, column in enumerate(widgets_layout_clean):
if len(column) > 1:
_widgets = [row[0].dockwidget for row in column]
self.resizeDocks(_widgets, height_fractions[idx], Qt.Vertical)
# Hide toolbars
hidden_toolbars = global_hidden_toolbars + layout['hidden toolbars']
for toolbar in hidden_toolbars:
if toolbar is not None:
toolbar.close()
# Hide widgets
hidden_widgets = layout['hidden widgets']
for widget in hidden_widgets:
if widget is not None:
widget.dockwidget.close()
if first_spyder_run:
self.first_spyder_run = False
else:
self.setMinimumWidth(min_width)
self.setMaximumWidth(max_width)
if not (self.isMaximized() or self.maximized_flag):
self.showMaximized()
self.setUpdatesEnabled(True)
self.sig_layout_setup_ready.emit(layout)
return layout | python | def setup_default_layouts(self, index, settings):
"""Setup default layouts when run for the first time."""
self.setUpdatesEnabled(False)
first_spyder_run = bool(self.first_spyder_run) # Store copy
if first_spyder_run:
self.set_window_settings(*settings)
else:
if self.last_plugin:
if self.last_plugin.ismaximized:
self.maximize_dockwidget(restore=True)
if not (self.isMaximized() or self.maximized_flag):
self.showMaximized()
min_width = self.minimumWidth()
max_width = self.maximumWidth()
base_width = self.width()
self.setFixedWidth(base_width)
# IMPORTANT: order has to be the same as defined in the config file
MATLAB, RSTUDIO, VERTICAL, HORIZONTAL = range(self.DEFAULT_LAYOUTS)
# Define widgets locally
editor = self.editor
console_ipy = self.ipyconsole
console_int = self.console
outline = self.outlineexplorer
explorer_project = self.projects
explorer_file = self.explorer
explorer_variable = self.variableexplorer
plots = self.plots
history = self.historylog
finder = self.findinfiles
help_plugin = self.help
helper = self.onlinehelp
plugins = self.thirdparty_plugins
# Stored for tests
global_hidden_widgets = [finder, console_int, explorer_project,
helper] + plugins
global_hidden_toolbars = [self.source_toolbar, self.edit_toolbar,
self.search_toolbar]
# Layout definition
# --------------------------------------------------------------------
# Layouts are organized by columns, each column is organized by rows.
# Widths have to add 1.0 (except if hidden), height per column has to
# add 1.0 as well
# Spyder Default Initial Layout
s_layout = {
'widgets': [
# Column 0
[[explorer_project]],
# Column 1
[[editor]],
# Column 2
[[outline]],
# Column 3
[[help_plugin, explorer_variable, plots, # Row 0
helper, explorer_file, finder] + plugins,
[console_int, console_ipy, history]] # Row 1
],
'width fraction': [0.05, # Column 0 width
0.55, # Column 1 width
0.05, # Column 2 width
0.45], # Column 3 width
'height fraction': [[1.0], # Column 0, row heights
[1.0], # Column 1, row heights
[1.0], # Column 2, row heights
[0.46, 0.54]], # Column 3, row heights
'hidden widgets': [outline] + global_hidden_widgets,
'hidden toolbars': [],
}
# RStudio
r_layout = {
'widgets': [
# column 0
[[editor], # Row 0
[console_ipy, console_int]], # Row 1
# column 1
[[explorer_variable, plots, history, # Row 0
outline, finder] + plugins,
[explorer_file, explorer_project, # Row 1
help_plugin, helper]]
],
'width fraction': [0.55, # Column 0 width
0.45], # Column 1 width
'height fraction': [[0.55, 0.45], # Column 0, row heights
[0.55, 0.45]], # Column 1, row heights
'hidden widgets': [outline] + global_hidden_widgets,
'hidden toolbars': [],
}
# Matlab
m_layout = {
'widgets': [
# column 0
[[explorer_file, explorer_project],
[outline]],
# column 1
[[editor],
[console_ipy, console_int]],
# column 2
[[explorer_variable, plots, finder] + plugins,
[history, help_plugin, helper]]
],
'width fraction': [0.10, # Column 0 width
0.45, # Column 1 width
0.45], # Column 2 width
'height fraction': [[0.55, 0.45], # Column 0, row heights
[0.55, 0.45], # Column 1, row heights
[0.55, 0.45]], # Column 2, row heights
'hidden widgets': global_hidden_widgets,
'hidden toolbars': [],
}
# Vertically split
v_layout = {
'widgets': [
# column 0
[[editor], # Row 0
[console_ipy, console_int, explorer_file, # Row 1
explorer_project, help_plugin, explorer_variable, plots,
history, outline, finder, helper] + plugins]
],
'width fraction': [1.0], # Column 0 width
'height fraction': [[0.55, 0.45]], # Column 0, row heights
'hidden widgets': [outline] + global_hidden_widgets,
'hidden toolbars': [],
}
# Horizontally split
h_layout = {
'widgets': [
# column 0
[[editor]], # Row 0
# column 1
[[console_ipy, console_int, explorer_file, # Row 0
explorer_project, help_plugin, explorer_variable, plots,
history, outline, finder, helper] + plugins]
],
'width fraction': [0.55, # Column 0 width
0.45], # Column 1 width
'height fraction': [[1.0], # Column 0, row heights
[1.0]], # Column 1, row heights
'hidden widgets': [outline] + global_hidden_widgets,
'hidden toolbars': []
}
# Layout selection
layouts = {
'default': s_layout,
RSTUDIO: r_layout,
MATLAB: m_layout,
VERTICAL: v_layout,
HORIZONTAL: h_layout,
}
layout = layouts[index]
# Remove None from widgets layout
widgets_layout = layout['widgets']
widgets_layout_clean = []
for column in widgets_layout:
clean_col = []
for row in column:
clean_row = [w for w in row if w is not None]
if clean_row:
clean_col.append(clean_row)
if clean_col:
widgets_layout_clean.append(clean_col)
# Flatten widgets list
widgets = []
for column in widgets_layout_clean:
for row in column:
for widget in row:
widgets.append(widget)
# Make every widget visible
for widget in widgets:
widget.toggle_view(True)
widget.toggle_view_action.setChecked(True)
# We use both directions to ensure proper update when moving from
# 'Horizontal Split' to 'Spyder Default'
# This also seems to help on random cases where the display seems
# 'empty'
for direction in (Qt.Vertical, Qt.Horizontal):
# Arrange the widgets in one direction
for idx in range(len(widgets) - 1):
first, second = widgets[idx], widgets[idx+1]
if first is not None and second is not None:
self.splitDockWidget(first.dockwidget, second.dockwidget,
direction)
# Arrange the widgets in the other direction
for column in widgets_layout_clean:
for idx in range(len(column) - 1):
first_row, second_row = column[idx], column[idx+1]
self.splitDockWidget(first_row[0].dockwidget,
second_row[0].dockwidget,
Qt.Vertical)
# Tabify
for column in widgets_layout_clean:
for row in column:
for idx in range(len(row) - 1):
first, second = row[idx], row[idx+1]
self.tabify_plugins(first, second)
# Raise front widget per row
row[0].dockwidget.show()
row[0].dockwidget.raise_()
# Set dockwidget widths
width_fractions = layout['width fraction']
if len(width_fractions) > 1:
_widgets = [col[0][0].dockwidget for col in widgets_layout]
self.resizeDocks(_widgets, width_fractions, Qt.Horizontal)
# Set dockwidget heights
height_fractions = layout['height fraction']
for idx, column in enumerate(widgets_layout_clean):
if len(column) > 1:
_widgets = [row[0].dockwidget for row in column]
self.resizeDocks(_widgets, height_fractions[idx], Qt.Vertical)
# Hide toolbars
hidden_toolbars = global_hidden_toolbars + layout['hidden toolbars']
for toolbar in hidden_toolbars:
if toolbar is not None:
toolbar.close()
# Hide widgets
hidden_widgets = layout['hidden widgets']
for widget in hidden_widgets:
if widget is not None:
widget.dockwidget.close()
if first_spyder_run:
self.first_spyder_run = False
else:
self.setMinimumWidth(min_width)
self.setMaximumWidth(max_width)
if not (self.isMaximized() or self.maximized_flag):
self.showMaximized()
self.setUpdatesEnabled(True)
self.sig_layout_setup_ready.emit(layout)
return layout | [
"def",
"setup_default_layouts",
"(",
"self",
",",
"index",
",",
"settings",
")",
":",
"self",
".",
"setUpdatesEnabled",
"(",
"False",
")",
"first_spyder_run",
"=",
"bool",
"(",
"self",
".",
"first_spyder_run",
")",
"# Store copy\r",
"if",
"first_spyder_run",
":",
"self",
".",
"set_window_settings",
"(",
"*",
"settings",
")",
"else",
":",
"if",
"self",
".",
"last_plugin",
":",
"if",
"self",
".",
"last_plugin",
".",
"ismaximized",
":",
"self",
".",
"maximize_dockwidget",
"(",
"restore",
"=",
"True",
")",
"if",
"not",
"(",
"self",
".",
"isMaximized",
"(",
")",
"or",
"self",
".",
"maximized_flag",
")",
":",
"self",
".",
"showMaximized",
"(",
")",
"min_width",
"=",
"self",
".",
"minimumWidth",
"(",
")",
"max_width",
"=",
"self",
".",
"maximumWidth",
"(",
")",
"base_width",
"=",
"self",
".",
"width",
"(",
")",
"self",
".",
"setFixedWidth",
"(",
"base_width",
")",
"# IMPORTANT: order has to be the same as defined in the config file\r",
"MATLAB",
",",
"RSTUDIO",
",",
"VERTICAL",
",",
"HORIZONTAL",
"=",
"range",
"(",
"self",
".",
"DEFAULT_LAYOUTS",
")",
"# Define widgets locally\r",
"editor",
"=",
"self",
".",
"editor",
"console_ipy",
"=",
"self",
".",
"ipyconsole",
"console_int",
"=",
"self",
".",
"console",
"outline",
"=",
"self",
".",
"outlineexplorer",
"explorer_project",
"=",
"self",
".",
"projects",
"explorer_file",
"=",
"self",
".",
"explorer",
"explorer_variable",
"=",
"self",
".",
"variableexplorer",
"plots",
"=",
"self",
".",
"plots",
"history",
"=",
"self",
".",
"historylog",
"finder",
"=",
"self",
".",
"findinfiles",
"help_plugin",
"=",
"self",
".",
"help",
"helper",
"=",
"self",
".",
"onlinehelp",
"plugins",
"=",
"self",
".",
"thirdparty_plugins",
"# Stored for tests\r",
"global_hidden_widgets",
"=",
"[",
"finder",
",",
"console_int",
",",
"explorer_project",
",",
"helper",
"]",
"+",
"plugins",
"global_hidden_toolbars",
"=",
"[",
"self",
".",
"source_toolbar",
",",
"self",
".",
"edit_toolbar",
",",
"self",
".",
"search_toolbar",
"]",
"# Layout definition\r",
"# --------------------------------------------------------------------\r",
"# Layouts are organized by columns, each column is organized by rows.\r",
"# Widths have to add 1.0 (except if hidden), height per column has to\r",
"# add 1.0 as well\r",
"# Spyder Default Initial Layout\r",
"s_layout",
"=",
"{",
"'widgets'",
":",
"[",
"# Column 0\r",
"[",
"[",
"explorer_project",
"]",
"]",
",",
"# Column 1\r",
"[",
"[",
"editor",
"]",
"]",
",",
"# Column 2\r",
"[",
"[",
"outline",
"]",
"]",
",",
"# Column 3\r",
"[",
"[",
"help_plugin",
",",
"explorer_variable",
",",
"plots",
",",
"# Row 0\r",
"helper",
",",
"explorer_file",
",",
"finder",
"]",
"+",
"plugins",
",",
"[",
"console_int",
",",
"console_ipy",
",",
"history",
"]",
"]",
"# Row 1\r",
"]",
",",
"'width fraction'",
":",
"[",
"0.05",
",",
"# Column 0 width\r",
"0.55",
",",
"# Column 1 width\r",
"0.05",
",",
"# Column 2 width\r",
"0.45",
"]",
",",
"# Column 3 width\r",
"'height fraction'",
":",
"[",
"[",
"1.0",
"]",
",",
"# Column 0, row heights\r",
"[",
"1.0",
"]",
",",
"# Column 1, row heights\r",
"[",
"1.0",
"]",
",",
"# Column 2, row heights\r",
"[",
"0.46",
",",
"0.54",
"]",
"]",
",",
"# Column 3, row heights\r",
"'hidden widgets'",
":",
"[",
"outline",
"]",
"+",
"global_hidden_widgets",
",",
"'hidden toolbars'",
":",
"[",
"]",
",",
"}",
"# RStudio\r",
"r_layout",
"=",
"{",
"'widgets'",
":",
"[",
"# column 0\r",
"[",
"[",
"editor",
"]",
",",
"# Row 0\r",
"[",
"console_ipy",
",",
"console_int",
"]",
"]",
",",
"# Row 1\r",
"# column 1\r",
"[",
"[",
"explorer_variable",
",",
"plots",
",",
"history",
",",
"# Row 0\r",
"outline",
",",
"finder",
"]",
"+",
"plugins",
",",
"[",
"explorer_file",
",",
"explorer_project",
",",
"# Row 1\r",
"help_plugin",
",",
"helper",
"]",
"]",
"]",
",",
"'width fraction'",
":",
"[",
"0.55",
",",
"# Column 0 width\r",
"0.45",
"]",
",",
"# Column 1 width\r",
"'height fraction'",
":",
"[",
"[",
"0.55",
",",
"0.45",
"]",
",",
"# Column 0, row heights\r",
"[",
"0.55",
",",
"0.45",
"]",
"]",
",",
"# Column 1, row heights\r",
"'hidden widgets'",
":",
"[",
"outline",
"]",
"+",
"global_hidden_widgets",
",",
"'hidden toolbars'",
":",
"[",
"]",
",",
"}",
"# Matlab\r",
"m_layout",
"=",
"{",
"'widgets'",
":",
"[",
"# column 0\r",
"[",
"[",
"explorer_file",
",",
"explorer_project",
"]",
",",
"[",
"outline",
"]",
"]",
",",
"# column 1\r",
"[",
"[",
"editor",
"]",
",",
"[",
"console_ipy",
",",
"console_int",
"]",
"]",
",",
"# column 2\r",
"[",
"[",
"explorer_variable",
",",
"plots",
",",
"finder",
"]",
"+",
"plugins",
",",
"[",
"history",
",",
"help_plugin",
",",
"helper",
"]",
"]",
"]",
",",
"'width fraction'",
":",
"[",
"0.10",
",",
"# Column 0 width\r",
"0.45",
",",
"# Column 1 width\r",
"0.45",
"]",
",",
"# Column 2 width\r",
"'height fraction'",
":",
"[",
"[",
"0.55",
",",
"0.45",
"]",
",",
"# Column 0, row heights\r",
"[",
"0.55",
",",
"0.45",
"]",
",",
"# Column 1, row heights\r",
"[",
"0.55",
",",
"0.45",
"]",
"]",
",",
"# Column 2, row heights\r",
"'hidden widgets'",
":",
"global_hidden_widgets",
",",
"'hidden toolbars'",
":",
"[",
"]",
",",
"}",
"# Vertically split\r",
"v_layout",
"=",
"{",
"'widgets'",
":",
"[",
"# column 0\r",
"[",
"[",
"editor",
"]",
",",
"# Row 0\r",
"[",
"console_ipy",
",",
"console_int",
",",
"explorer_file",
",",
"# Row 1\r",
"explorer_project",
",",
"help_plugin",
",",
"explorer_variable",
",",
"plots",
",",
"history",
",",
"outline",
",",
"finder",
",",
"helper",
"]",
"+",
"plugins",
"]",
"]",
",",
"'width fraction'",
":",
"[",
"1.0",
"]",
",",
"# Column 0 width\r",
"'height fraction'",
":",
"[",
"[",
"0.55",
",",
"0.45",
"]",
"]",
",",
"# Column 0, row heights\r",
"'hidden widgets'",
":",
"[",
"outline",
"]",
"+",
"global_hidden_widgets",
",",
"'hidden toolbars'",
":",
"[",
"]",
",",
"}",
"# Horizontally split\r",
"h_layout",
"=",
"{",
"'widgets'",
":",
"[",
"# column 0\r",
"[",
"[",
"editor",
"]",
"]",
",",
"# Row 0\r",
"# column 1\r",
"[",
"[",
"console_ipy",
",",
"console_int",
",",
"explorer_file",
",",
"# Row 0\r",
"explorer_project",
",",
"help_plugin",
",",
"explorer_variable",
",",
"plots",
",",
"history",
",",
"outline",
",",
"finder",
",",
"helper",
"]",
"+",
"plugins",
"]",
"]",
",",
"'width fraction'",
":",
"[",
"0.55",
",",
"# Column 0 width\r",
"0.45",
"]",
",",
"# Column 1 width\r",
"'height fraction'",
":",
"[",
"[",
"1.0",
"]",
",",
"# Column 0, row heights\r",
"[",
"1.0",
"]",
"]",
",",
"# Column 1, row heights\r",
"'hidden widgets'",
":",
"[",
"outline",
"]",
"+",
"global_hidden_widgets",
",",
"'hidden toolbars'",
":",
"[",
"]",
"}",
"# Layout selection\r",
"layouts",
"=",
"{",
"'default'",
":",
"s_layout",
",",
"RSTUDIO",
":",
"r_layout",
",",
"MATLAB",
":",
"m_layout",
",",
"VERTICAL",
":",
"v_layout",
",",
"HORIZONTAL",
":",
"h_layout",
",",
"}",
"layout",
"=",
"layouts",
"[",
"index",
"]",
"# Remove None from widgets layout\r",
"widgets_layout",
"=",
"layout",
"[",
"'widgets'",
"]",
"widgets_layout_clean",
"=",
"[",
"]",
"for",
"column",
"in",
"widgets_layout",
":",
"clean_col",
"=",
"[",
"]",
"for",
"row",
"in",
"column",
":",
"clean_row",
"=",
"[",
"w",
"for",
"w",
"in",
"row",
"if",
"w",
"is",
"not",
"None",
"]",
"if",
"clean_row",
":",
"clean_col",
".",
"append",
"(",
"clean_row",
")",
"if",
"clean_col",
":",
"widgets_layout_clean",
".",
"append",
"(",
"clean_col",
")",
"# Flatten widgets list\r",
"widgets",
"=",
"[",
"]",
"for",
"column",
"in",
"widgets_layout_clean",
":",
"for",
"row",
"in",
"column",
":",
"for",
"widget",
"in",
"row",
":",
"widgets",
".",
"append",
"(",
"widget",
")",
"# Make every widget visible\r",
"for",
"widget",
"in",
"widgets",
":",
"widget",
".",
"toggle_view",
"(",
"True",
")",
"widget",
".",
"toggle_view_action",
".",
"setChecked",
"(",
"True",
")",
"# We use both directions to ensure proper update when moving from\r",
"# 'Horizontal Split' to 'Spyder Default'\r",
"# This also seems to help on random cases where the display seems\r",
"# 'empty'\r",
"for",
"direction",
"in",
"(",
"Qt",
".",
"Vertical",
",",
"Qt",
".",
"Horizontal",
")",
":",
"# Arrange the widgets in one direction\r",
"for",
"idx",
"in",
"range",
"(",
"len",
"(",
"widgets",
")",
"-",
"1",
")",
":",
"first",
",",
"second",
"=",
"widgets",
"[",
"idx",
"]",
",",
"widgets",
"[",
"idx",
"+",
"1",
"]",
"if",
"first",
"is",
"not",
"None",
"and",
"second",
"is",
"not",
"None",
":",
"self",
".",
"splitDockWidget",
"(",
"first",
".",
"dockwidget",
",",
"second",
".",
"dockwidget",
",",
"direction",
")",
"# Arrange the widgets in the other direction\r",
"for",
"column",
"in",
"widgets_layout_clean",
":",
"for",
"idx",
"in",
"range",
"(",
"len",
"(",
"column",
")",
"-",
"1",
")",
":",
"first_row",
",",
"second_row",
"=",
"column",
"[",
"idx",
"]",
",",
"column",
"[",
"idx",
"+",
"1",
"]",
"self",
".",
"splitDockWidget",
"(",
"first_row",
"[",
"0",
"]",
".",
"dockwidget",
",",
"second_row",
"[",
"0",
"]",
".",
"dockwidget",
",",
"Qt",
".",
"Vertical",
")",
"# Tabify\r",
"for",
"column",
"in",
"widgets_layout_clean",
":",
"for",
"row",
"in",
"column",
":",
"for",
"idx",
"in",
"range",
"(",
"len",
"(",
"row",
")",
"-",
"1",
")",
":",
"first",
",",
"second",
"=",
"row",
"[",
"idx",
"]",
",",
"row",
"[",
"idx",
"+",
"1",
"]",
"self",
".",
"tabify_plugins",
"(",
"first",
",",
"second",
")",
"# Raise front widget per row\r",
"row",
"[",
"0",
"]",
".",
"dockwidget",
".",
"show",
"(",
")",
"row",
"[",
"0",
"]",
".",
"dockwidget",
".",
"raise_",
"(",
")",
"# Set dockwidget widths\r",
"width_fractions",
"=",
"layout",
"[",
"'width fraction'",
"]",
"if",
"len",
"(",
"width_fractions",
")",
">",
"1",
":",
"_widgets",
"=",
"[",
"col",
"[",
"0",
"]",
"[",
"0",
"]",
".",
"dockwidget",
"for",
"col",
"in",
"widgets_layout",
"]",
"self",
".",
"resizeDocks",
"(",
"_widgets",
",",
"width_fractions",
",",
"Qt",
".",
"Horizontal",
")",
"# Set dockwidget heights\r",
"height_fractions",
"=",
"layout",
"[",
"'height fraction'",
"]",
"for",
"idx",
",",
"column",
"in",
"enumerate",
"(",
"widgets_layout_clean",
")",
":",
"if",
"len",
"(",
"column",
")",
">",
"1",
":",
"_widgets",
"=",
"[",
"row",
"[",
"0",
"]",
".",
"dockwidget",
"for",
"row",
"in",
"column",
"]",
"self",
".",
"resizeDocks",
"(",
"_widgets",
",",
"height_fractions",
"[",
"idx",
"]",
",",
"Qt",
".",
"Vertical",
")",
"# Hide toolbars\r",
"hidden_toolbars",
"=",
"global_hidden_toolbars",
"+",
"layout",
"[",
"'hidden toolbars'",
"]",
"for",
"toolbar",
"in",
"hidden_toolbars",
":",
"if",
"toolbar",
"is",
"not",
"None",
":",
"toolbar",
".",
"close",
"(",
")",
"# Hide widgets\r",
"hidden_widgets",
"=",
"layout",
"[",
"'hidden widgets'",
"]",
"for",
"widget",
"in",
"hidden_widgets",
":",
"if",
"widget",
"is",
"not",
"None",
":",
"widget",
".",
"dockwidget",
".",
"close",
"(",
")",
"if",
"first_spyder_run",
":",
"self",
".",
"first_spyder_run",
"=",
"False",
"else",
":",
"self",
".",
"setMinimumWidth",
"(",
"min_width",
")",
"self",
".",
"setMaximumWidth",
"(",
"max_width",
")",
"if",
"not",
"(",
"self",
".",
"isMaximized",
"(",
")",
"or",
"self",
".",
"maximized_flag",
")",
":",
"self",
".",
"showMaximized",
"(",
")",
"self",
".",
"setUpdatesEnabled",
"(",
"True",
")",
"self",
".",
"sig_layout_setup_ready",
".",
"emit",
"(",
"layout",
")",
"return",
"layout"
] | Setup default layouts when run for the first time. | [
"Setup",
"default",
"layouts",
"when",
"run",
"for",
"the",
"first",
"time",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L1553-L1808 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.reset_window_layout | def reset_window_layout(self):
"""Reset window layout to default"""
answer = QMessageBox.warning(self, _("Warning"),
_("Window layout will be reset to default settings: "
"this affects window position, size and dockwidgets.\n"
"Do you want to continue?"),
QMessageBox.Yes | QMessageBox.No)
if answer == QMessageBox.Yes:
self.setup_layout(default=True) | python | def reset_window_layout(self):
"""Reset window layout to default"""
answer = QMessageBox.warning(self, _("Warning"),
_("Window layout will be reset to default settings: "
"this affects window position, size and dockwidgets.\n"
"Do you want to continue?"),
QMessageBox.Yes | QMessageBox.No)
if answer == QMessageBox.Yes:
self.setup_layout(default=True) | [
"def",
"reset_window_layout",
"(",
"self",
")",
":",
"answer",
"=",
"QMessageBox",
".",
"warning",
"(",
"self",
",",
"_",
"(",
"\"Warning\"",
")",
",",
"_",
"(",
"\"Window layout will be reset to default settings: \"",
"\"this affects window position, size and dockwidgets.\\n\"",
"\"Do you want to continue?\"",
")",
",",
"QMessageBox",
".",
"Yes",
"|",
"QMessageBox",
".",
"No",
")",
"if",
"answer",
"==",
"QMessageBox",
".",
"Yes",
":",
"self",
".",
"setup_layout",
"(",
"default",
"=",
"True",
")"
] | Reset window layout to default | [
"Reset",
"window",
"layout",
"to",
"default"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L1903-L1911 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.quick_layout_save | def quick_layout_save(self):
"""Save layout dialog"""
get = CONF.get
set_ = CONF.set
names = get('quick_layouts', 'names')
order = get('quick_layouts', 'order')
active = get('quick_layouts', 'active')
dlg = self.dialog_layout_save(self, names)
if dlg.exec_():
name = dlg.combo_box.currentText()
if name in names:
answer = QMessageBox.warning(self, _("Warning"),
_("Layout <b>%s</b> will be \
overwritten. Do you want to \
continue?") % name,
QMessageBox.Yes | QMessageBox.No)
index = order.index(name)
else:
answer = True
if None in names:
index = names.index(None)
names[index] = name
else:
index = len(names)
names.append(name)
order.append(name)
# Always make active a new layout even if it overwrites an inactive
# layout
if name not in active:
active.append(name)
if answer:
self.save_current_window_settings('layout_{}/'.format(index),
section='quick_layouts')
set_('quick_layouts', 'names', names)
set_('quick_layouts', 'order', order)
set_('quick_layouts', 'active', active)
self.quick_layout_set_menu() | python | def quick_layout_save(self):
"""Save layout dialog"""
get = CONF.get
set_ = CONF.set
names = get('quick_layouts', 'names')
order = get('quick_layouts', 'order')
active = get('quick_layouts', 'active')
dlg = self.dialog_layout_save(self, names)
if dlg.exec_():
name = dlg.combo_box.currentText()
if name in names:
answer = QMessageBox.warning(self, _("Warning"),
_("Layout <b>%s</b> will be \
overwritten. Do you want to \
continue?") % name,
QMessageBox.Yes | QMessageBox.No)
index = order.index(name)
else:
answer = True
if None in names:
index = names.index(None)
names[index] = name
else:
index = len(names)
names.append(name)
order.append(name)
# Always make active a new layout even if it overwrites an inactive
# layout
if name not in active:
active.append(name)
if answer:
self.save_current_window_settings('layout_{}/'.format(index),
section='quick_layouts')
set_('quick_layouts', 'names', names)
set_('quick_layouts', 'order', order)
set_('quick_layouts', 'active', active)
self.quick_layout_set_menu() | [
"def",
"quick_layout_save",
"(",
"self",
")",
":",
"get",
"=",
"CONF",
".",
"get",
"set_",
"=",
"CONF",
".",
"set",
"names",
"=",
"get",
"(",
"'quick_layouts'",
",",
"'names'",
")",
"order",
"=",
"get",
"(",
"'quick_layouts'",
",",
"'order'",
")",
"active",
"=",
"get",
"(",
"'quick_layouts'",
",",
"'active'",
")",
"dlg",
"=",
"self",
".",
"dialog_layout_save",
"(",
"self",
",",
"names",
")",
"if",
"dlg",
".",
"exec_",
"(",
")",
":",
"name",
"=",
"dlg",
".",
"combo_box",
".",
"currentText",
"(",
")",
"if",
"name",
"in",
"names",
":",
"answer",
"=",
"QMessageBox",
".",
"warning",
"(",
"self",
",",
"_",
"(",
"\"Warning\"",
")",
",",
"_",
"(",
"\"Layout <b>%s</b> will be \\\r\n overwritten. Do you want to \\\r\n continue?\"",
")",
"%",
"name",
",",
"QMessageBox",
".",
"Yes",
"|",
"QMessageBox",
".",
"No",
")",
"index",
"=",
"order",
".",
"index",
"(",
"name",
")",
"else",
":",
"answer",
"=",
"True",
"if",
"None",
"in",
"names",
":",
"index",
"=",
"names",
".",
"index",
"(",
"None",
")",
"names",
"[",
"index",
"]",
"=",
"name",
"else",
":",
"index",
"=",
"len",
"(",
"names",
")",
"names",
".",
"append",
"(",
"name",
")",
"order",
".",
"append",
"(",
"name",
")",
"# Always make active a new layout even if it overwrites an inactive\r",
"# layout\r",
"if",
"name",
"not",
"in",
"active",
":",
"active",
".",
"append",
"(",
"name",
")",
"if",
"answer",
":",
"self",
".",
"save_current_window_settings",
"(",
"'layout_{}/'",
".",
"format",
"(",
"index",
")",
",",
"section",
"=",
"'quick_layouts'",
")",
"set_",
"(",
"'quick_layouts'",
",",
"'names'",
",",
"names",
")",
"set_",
"(",
"'quick_layouts'",
",",
"'order'",
",",
"order",
")",
"set_",
"(",
"'quick_layouts'",
",",
"'active'",
",",
"active",
")",
"self",
".",
"quick_layout_set_menu",
"(",
")"
] | Save layout dialog | [
"Save",
"layout",
"dialog"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L1913-L1954 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.quick_layout_settings | def quick_layout_settings(self):
"""Layout settings dialog"""
get = CONF.get
set_ = CONF.set
section = 'quick_layouts'
names = get(section, 'names')
order = get(section, 'order')
active = get(section, 'active')
dlg = self.dialog_layout_settings(self, names, order, active)
if dlg.exec_():
set_(section, 'names', dlg.names)
set_(section, 'order', dlg.order)
set_(section, 'active', dlg.active)
self.quick_layout_set_menu() | python | def quick_layout_settings(self):
"""Layout settings dialog"""
get = CONF.get
set_ = CONF.set
section = 'quick_layouts'
names = get(section, 'names')
order = get(section, 'order')
active = get(section, 'active')
dlg = self.dialog_layout_settings(self, names, order, active)
if dlg.exec_():
set_(section, 'names', dlg.names)
set_(section, 'order', dlg.order)
set_(section, 'active', dlg.active)
self.quick_layout_set_menu() | [
"def",
"quick_layout_settings",
"(",
"self",
")",
":",
"get",
"=",
"CONF",
".",
"get",
"set_",
"=",
"CONF",
".",
"set",
"section",
"=",
"'quick_layouts'",
"names",
"=",
"get",
"(",
"section",
",",
"'names'",
")",
"order",
"=",
"get",
"(",
"section",
",",
"'order'",
")",
"active",
"=",
"get",
"(",
"section",
",",
"'active'",
")",
"dlg",
"=",
"self",
".",
"dialog_layout_settings",
"(",
"self",
",",
"names",
",",
"order",
",",
"active",
")",
"if",
"dlg",
".",
"exec_",
"(",
")",
":",
"set_",
"(",
"section",
",",
"'names'",
",",
"dlg",
".",
"names",
")",
"set_",
"(",
"section",
",",
"'order'",
",",
"dlg",
".",
"order",
")",
"set_",
"(",
"section",
",",
"'active'",
",",
"dlg",
".",
"active",
")",
"self",
".",
"quick_layout_set_menu",
"(",
")"
] | Layout settings dialog | [
"Layout",
"settings",
"dialog"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L1956-L1972 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.quick_layout_switch | def quick_layout_switch(self, index):
"""Switch to quick layout number *index*"""
section = 'quick_layouts'
try:
settings = self.load_window_settings('layout_{}/'.format(index),
section=section)
(hexstate, window_size, prefs_dialog_size, pos, is_maximized,
is_fullscreen) = settings
# The defaults layouts will always be regenerated unless there was
# an overwrite, either by rewriting with same name, or by deleting
# and then creating a new one
if hexstate is None:
# The value for hexstate shouldn't be None for a custom saved
# layout (ie, where the index is greater than the number of
# defaults). See issue 6202.
if index != 'default' and index >= self.DEFAULT_LAYOUTS:
QMessageBox.critical(
self, _("Warning"),
_("Error opening the custom layout. Please close"
" Spyder and try again. If the issue persists,"
" then you must use 'Reset to Spyder default' "
"from the layout menu."))
return
self.setup_default_layouts(index, settings)
except cp.NoOptionError:
QMessageBox.critical(self, _("Warning"),
_("Quick switch layout #%s has not yet "
"been defined.") % str(index))
return
# TODO: is there any real use in calling the previous layout
# setting?
# self.previous_layout_settings = self.get_window_settings()
self.set_window_settings(*settings)
self.current_quick_layout = index
# make sure the flags are correctly set for visible panes
for plugin in (self.widgetlist + self.thirdparty_plugins):
action = plugin.toggle_view_action
action.setChecked(plugin.dockwidget.isVisible()) | python | def quick_layout_switch(self, index):
"""Switch to quick layout number *index*"""
section = 'quick_layouts'
try:
settings = self.load_window_settings('layout_{}/'.format(index),
section=section)
(hexstate, window_size, prefs_dialog_size, pos, is_maximized,
is_fullscreen) = settings
# The defaults layouts will always be regenerated unless there was
# an overwrite, either by rewriting with same name, or by deleting
# and then creating a new one
if hexstate is None:
# The value for hexstate shouldn't be None for a custom saved
# layout (ie, where the index is greater than the number of
# defaults). See issue 6202.
if index != 'default' and index >= self.DEFAULT_LAYOUTS:
QMessageBox.critical(
self, _("Warning"),
_("Error opening the custom layout. Please close"
" Spyder and try again. If the issue persists,"
" then you must use 'Reset to Spyder default' "
"from the layout menu."))
return
self.setup_default_layouts(index, settings)
except cp.NoOptionError:
QMessageBox.critical(self, _("Warning"),
_("Quick switch layout #%s has not yet "
"been defined.") % str(index))
return
# TODO: is there any real use in calling the previous layout
# setting?
# self.previous_layout_settings = self.get_window_settings()
self.set_window_settings(*settings)
self.current_quick_layout = index
# make sure the flags are correctly set for visible panes
for plugin in (self.widgetlist + self.thirdparty_plugins):
action = plugin.toggle_view_action
action.setChecked(plugin.dockwidget.isVisible()) | [
"def",
"quick_layout_switch",
"(",
"self",
",",
"index",
")",
":",
"section",
"=",
"'quick_layouts'",
"try",
":",
"settings",
"=",
"self",
".",
"load_window_settings",
"(",
"'layout_{}/'",
".",
"format",
"(",
"index",
")",
",",
"section",
"=",
"section",
")",
"(",
"hexstate",
",",
"window_size",
",",
"prefs_dialog_size",
",",
"pos",
",",
"is_maximized",
",",
"is_fullscreen",
")",
"=",
"settings",
"# The defaults layouts will always be regenerated unless there was\r",
"# an overwrite, either by rewriting with same name, or by deleting\r",
"# and then creating a new one\r",
"if",
"hexstate",
"is",
"None",
":",
"# The value for hexstate shouldn't be None for a custom saved\r",
"# layout (ie, where the index is greater than the number of\r",
"# defaults). See issue 6202.\r",
"if",
"index",
"!=",
"'default'",
"and",
"index",
">=",
"self",
".",
"DEFAULT_LAYOUTS",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"\"Warning\"",
")",
",",
"_",
"(",
"\"Error opening the custom layout. Please close\"",
"\" Spyder and try again. If the issue persists,\"",
"\" then you must use 'Reset to Spyder default' \"",
"\"from the layout menu.\"",
")",
")",
"return",
"self",
".",
"setup_default_layouts",
"(",
"index",
",",
"settings",
")",
"except",
"cp",
".",
"NoOptionError",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"\"Warning\"",
")",
",",
"_",
"(",
"\"Quick switch layout #%s has not yet \"",
"\"been defined.\"",
")",
"%",
"str",
"(",
"index",
")",
")",
"return",
"# TODO: is there any real use in calling the previous layout\r",
"# setting?\r",
"# self.previous_layout_settings = self.get_window_settings()\r",
"self",
".",
"set_window_settings",
"(",
"*",
"settings",
")",
"self",
".",
"current_quick_layout",
"=",
"index",
"# make sure the flags are correctly set for visible panes\r",
"for",
"plugin",
"in",
"(",
"self",
".",
"widgetlist",
"+",
"self",
".",
"thirdparty_plugins",
")",
":",
"action",
"=",
"plugin",
".",
"toggle_view_action",
"action",
".",
"setChecked",
"(",
"plugin",
".",
"dockwidget",
".",
"isVisible",
"(",
")",
")"
] | Switch to quick layout number *index* | [
"Switch",
"to",
"quick",
"layout",
"number",
"*",
"index",
"*"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L1974-L2014 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow._update_show_toolbars_action | def _update_show_toolbars_action(self):
"""Update the text displayed in the menu entry."""
if self.toolbars_visible:
text = _("Hide toolbars")
tip = _("Hide toolbars")
else:
text = _("Show toolbars")
tip = _("Show toolbars")
self.show_toolbars_action.setText(text)
self.show_toolbars_action.setToolTip(tip) | python | def _update_show_toolbars_action(self):
"""Update the text displayed in the menu entry."""
if self.toolbars_visible:
text = _("Hide toolbars")
tip = _("Hide toolbars")
else:
text = _("Show toolbars")
tip = _("Show toolbars")
self.show_toolbars_action.setText(text)
self.show_toolbars_action.setToolTip(tip) | [
"def",
"_update_show_toolbars_action",
"(",
"self",
")",
":",
"if",
"self",
".",
"toolbars_visible",
":",
"text",
"=",
"_",
"(",
"\"Hide toolbars\"",
")",
"tip",
"=",
"_",
"(",
"\"Hide toolbars\"",
")",
"else",
":",
"text",
"=",
"_",
"(",
"\"Show toolbars\"",
")",
"tip",
"=",
"_",
"(",
"\"Show toolbars\"",
")",
"self",
".",
"show_toolbars_action",
".",
"setText",
"(",
"text",
")",
"self",
".",
"show_toolbars_action",
".",
"setToolTip",
"(",
"tip",
")"
] | Update the text displayed in the menu entry. | [
"Update",
"the",
"text",
"displayed",
"in",
"the",
"menu",
"entry",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2017-L2026 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.save_visible_toolbars | def save_visible_toolbars(self):
"""Saves the name of the visible toolbars in the .ini file."""
toolbars = []
for toolbar in self.visible_toolbars:
toolbars.append(toolbar.objectName())
CONF.set('main', 'last_visible_toolbars', toolbars) | python | def save_visible_toolbars(self):
"""Saves the name of the visible toolbars in the .ini file."""
toolbars = []
for toolbar in self.visible_toolbars:
toolbars.append(toolbar.objectName())
CONF.set('main', 'last_visible_toolbars', toolbars) | [
"def",
"save_visible_toolbars",
"(",
"self",
")",
":",
"toolbars",
"=",
"[",
"]",
"for",
"toolbar",
"in",
"self",
".",
"visible_toolbars",
":",
"toolbars",
".",
"append",
"(",
"toolbar",
".",
"objectName",
"(",
")",
")",
"CONF",
".",
"set",
"(",
"'main'",
",",
"'last_visible_toolbars'",
",",
"toolbars",
")"
] | Saves the name of the visible toolbars in the .ini file. | [
"Saves",
"the",
"name",
"of",
"the",
"visible",
"toolbars",
"in",
"the",
".",
"ini",
"file",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2028-L2033 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.get_visible_toolbars | def get_visible_toolbars(self):
"""Collects the visible toolbars."""
toolbars = []
for toolbar in self.toolbarslist:
if toolbar.toggleViewAction().isChecked():
toolbars.append(toolbar)
self.visible_toolbars = toolbars | python | def get_visible_toolbars(self):
"""Collects the visible toolbars."""
toolbars = []
for toolbar in self.toolbarslist:
if toolbar.toggleViewAction().isChecked():
toolbars.append(toolbar)
self.visible_toolbars = toolbars | [
"def",
"get_visible_toolbars",
"(",
"self",
")",
":",
"toolbars",
"=",
"[",
"]",
"for",
"toolbar",
"in",
"self",
".",
"toolbarslist",
":",
"if",
"toolbar",
".",
"toggleViewAction",
"(",
")",
".",
"isChecked",
"(",
")",
":",
"toolbars",
".",
"append",
"(",
"toolbar",
")",
"self",
".",
"visible_toolbars",
"=",
"toolbars"
] | Collects the visible toolbars. | [
"Collects",
"the",
"visible",
"toolbars",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2035-L2041 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.load_last_visible_toolbars | 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() | python | 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",
"load_last_visible_toolbars",
"(",
"self",
")",
":",
"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",
"(",
")"
] | Loads the last visible toolbars from the .ini file. | [
"Loads",
"the",
"last",
"visible",
"toolbars",
"from",
"the",
".",
"ini",
"file",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2043-L2059 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.show_toolbars | def show_toolbars(self):
"""Show/Hides toolbars."""
value = not self.toolbars_visible
CONF.set('main', 'toolbars_visible', value)
if value:
self.save_visible_toolbars()
else:
self.get_visible_toolbars()
for toolbar in self.visible_toolbars:
toolbar.toggleViewAction().setChecked(value)
toolbar.setVisible(value)
self.toolbars_visible = value
self._update_show_toolbars_action() | python | def show_toolbars(self):
"""Show/Hides toolbars."""
value = not self.toolbars_visible
CONF.set('main', 'toolbars_visible', value)
if value:
self.save_visible_toolbars()
else:
self.get_visible_toolbars()
for toolbar in self.visible_toolbars:
toolbar.toggleViewAction().setChecked(value)
toolbar.setVisible(value)
self.toolbars_visible = value
self._update_show_toolbars_action() | [
"def",
"show_toolbars",
"(",
"self",
")",
":",
"value",
"=",
"not",
"self",
".",
"toolbars_visible",
"CONF",
".",
"set",
"(",
"'main'",
",",
"'toolbars_visible'",
",",
"value",
")",
"if",
"value",
":",
"self",
".",
"save_visible_toolbars",
"(",
")",
"else",
":",
"self",
".",
"get_visible_toolbars",
"(",
")",
"for",
"toolbar",
"in",
"self",
".",
"visible_toolbars",
":",
"toolbar",
".",
"toggleViewAction",
"(",
")",
".",
"setChecked",
"(",
"value",
")",
"toolbar",
".",
"setVisible",
"(",
"value",
")",
"self",
".",
"toolbars_visible",
"=",
"value",
"self",
".",
"_update_show_toolbars_action",
"(",
")"
] | Show/Hides toolbars. | [
"Show",
"/",
"Hides",
"toolbars",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2062-L2076 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.valid_project | def valid_project(self):
"""Handle an invalid active project."""
try:
path = self.projects.get_active_project_path()
except AttributeError:
return
if bool(path):
if not self.projects.is_valid_project(path):
if path:
QMessageBox.critical(
self,
_('Error'),
_("<b>{}</b> is no longer a valid Spyder project! "
"Since it is the current active project, it will "
"be closed automatically.").format(path))
self.projects.close_project() | python | def valid_project(self):
"""Handle an invalid active project."""
try:
path = self.projects.get_active_project_path()
except AttributeError:
return
if bool(path):
if not self.projects.is_valid_project(path):
if path:
QMessageBox.critical(
self,
_('Error'),
_("<b>{}</b> is no longer a valid Spyder project! "
"Since it is the current active project, it will "
"be closed automatically.").format(path))
self.projects.close_project() | [
"def",
"valid_project",
"(",
"self",
")",
":",
"try",
":",
"path",
"=",
"self",
".",
"projects",
".",
"get_active_project_path",
"(",
")",
"except",
"AttributeError",
":",
"return",
"if",
"bool",
"(",
"path",
")",
":",
"if",
"not",
"self",
".",
"projects",
".",
"is_valid_project",
"(",
"path",
")",
":",
"if",
"path",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"'Error'",
")",
",",
"_",
"(",
"\"<b>{}</b> is no longer a valid Spyder project! \"",
"\"Since it is the current active project, it will \"",
"\"be closed automatically.\"",
")",
".",
"format",
"(",
"path",
")",
")",
"self",
".",
"projects",
".",
"close_project",
"(",
")"
] | Handle an invalid active project. | [
"Handle",
"an",
"invalid",
"active",
"project",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2086-L2102 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.show_shortcuts | def show_shortcuts(self, menu):
"""Show action shortcuts in menu"""
for element in getattr(self, menu + '_menu_actions'):
if element and isinstance(element, QAction):
if element._shown_shortcut is not None:
element.setShortcut(element._shown_shortcut) | python | def show_shortcuts(self, menu):
"""Show action shortcuts in menu"""
for element in getattr(self, menu + '_menu_actions'):
if element and isinstance(element, QAction):
if element._shown_shortcut is not None:
element.setShortcut(element._shown_shortcut) | [
"def",
"show_shortcuts",
"(",
"self",
",",
"menu",
")",
":",
"for",
"element",
"in",
"getattr",
"(",
"self",
",",
"menu",
"+",
"'_menu_actions'",
")",
":",
"if",
"element",
"and",
"isinstance",
"(",
"element",
",",
"QAction",
")",
":",
"if",
"element",
".",
"_shown_shortcut",
"is",
"not",
"None",
":",
"element",
".",
"setShortcut",
"(",
"element",
".",
"_shown_shortcut",
")"
] | Show action shortcuts in menu | [
"Show",
"action",
"shortcuts",
"in",
"menu"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2113-L2118 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.hide_shortcuts | def hide_shortcuts(self, menu):
"""Hide action shortcuts in menu"""
for element in getattr(self, menu + '_menu_actions'):
if element and isinstance(element, QAction):
if element._shown_shortcut is not None:
element.setShortcut(QKeySequence()) | python | def hide_shortcuts(self, menu):
"""Hide action shortcuts in menu"""
for element in getattr(self, menu + '_menu_actions'):
if element and isinstance(element, QAction):
if element._shown_shortcut is not None:
element.setShortcut(QKeySequence()) | [
"def",
"hide_shortcuts",
"(",
"self",
",",
"menu",
")",
":",
"for",
"element",
"in",
"getattr",
"(",
"self",
",",
"menu",
"+",
"'_menu_actions'",
")",
":",
"if",
"element",
"and",
"isinstance",
"(",
"element",
",",
"QAction",
")",
":",
"if",
"element",
".",
"_shown_shortcut",
"is",
"not",
"None",
":",
"element",
".",
"setShortcut",
"(",
"QKeySequence",
"(",
")",
")"
] | Hide action shortcuts in menu | [
"Hide",
"action",
"shortcuts",
"in",
"menu"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2120-L2125 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.get_focus_widget_properties | def get_focus_widget_properties(self):
"""Get properties of focus widget
Returns tuple (widget, properties) where properties is a tuple of
booleans: (is_console, not_readonly, readwrite_editor)"""
from spyder.plugins.editor.widgets.editor import TextEditBaseWidget
from spyder.plugins.ipythonconsole.widgets import ControlWidget
widget = QApplication.focusWidget()
textedit_properties = None
if isinstance(widget, (TextEditBaseWidget, ControlWidget)):
console = isinstance(widget, ControlWidget)
not_readonly = not widget.isReadOnly()
readwrite_editor = not_readonly and not console
textedit_properties = (console, not_readonly, readwrite_editor)
return widget, textedit_properties | python | def get_focus_widget_properties(self):
"""Get properties of focus widget
Returns tuple (widget, properties) where properties is a tuple of
booleans: (is_console, not_readonly, readwrite_editor)"""
from spyder.plugins.editor.widgets.editor import TextEditBaseWidget
from spyder.plugins.ipythonconsole.widgets import ControlWidget
widget = QApplication.focusWidget()
textedit_properties = None
if isinstance(widget, (TextEditBaseWidget, ControlWidget)):
console = isinstance(widget, ControlWidget)
not_readonly = not widget.isReadOnly()
readwrite_editor = not_readonly and not console
textedit_properties = (console, not_readonly, readwrite_editor)
return widget, textedit_properties | [
"def",
"get_focus_widget_properties",
"(",
"self",
")",
":",
"from",
"spyder",
".",
"plugins",
".",
"editor",
".",
"widgets",
".",
"editor",
"import",
"TextEditBaseWidget",
"from",
"spyder",
".",
"plugins",
".",
"ipythonconsole",
".",
"widgets",
"import",
"ControlWidget",
"widget",
"=",
"QApplication",
".",
"focusWidget",
"(",
")",
"textedit_properties",
"=",
"None",
"if",
"isinstance",
"(",
"widget",
",",
"(",
"TextEditBaseWidget",
",",
"ControlWidget",
")",
")",
":",
"console",
"=",
"isinstance",
"(",
"widget",
",",
"ControlWidget",
")",
"not_readonly",
"=",
"not",
"widget",
".",
"isReadOnly",
"(",
")",
"readwrite_editor",
"=",
"not_readonly",
"and",
"not",
"console",
"textedit_properties",
"=",
"(",
"console",
",",
"not_readonly",
",",
"readwrite_editor",
")",
"return",
"widget",
",",
"textedit_properties"
] | Get properties of focus widget
Returns tuple (widget, properties) where properties is a tuple of
booleans: (is_console, not_readonly, readwrite_editor) | [
"Get",
"properties",
"of",
"focus",
"widget",
"Returns",
"tuple",
"(",
"widget",
"properties",
")",
"where",
"properties",
"is",
"a",
"tuple",
"of",
"booleans",
":",
"(",
"is_console",
"not_readonly",
"readwrite_editor",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2127-L2141 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.update_edit_menu | def update_edit_menu(self):
"""Update edit menu"""
widget, textedit_properties = self.get_focus_widget_properties()
if textedit_properties is None: # widget is not an editor/console
return
# !!! Below this line, widget is expected to be a QPlainTextEdit
# instance
console, not_readonly, readwrite_editor = textedit_properties
# Editor has focus and there is no file opened in it
if not console and not_readonly and not self.editor.is_file_opened():
return
# Disabling all actions to begin with
for child in self.edit_menu.actions():
child.setEnabled(False)
self.selectall_action.setEnabled(True)
# Undo, redo
self.undo_action.setEnabled( readwrite_editor \
and widget.document().isUndoAvailable() )
self.redo_action.setEnabled( readwrite_editor \
and widget.document().isRedoAvailable() )
# Copy, cut, paste, delete
has_selection = widget.has_selected_text()
self.copy_action.setEnabled(has_selection)
self.cut_action.setEnabled(has_selection and not_readonly)
self.paste_action.setEnabled(not_readonly)
# Comment, uncomment, indent, unindent...
if not console and not_readonly:
# This is the editor and current file is writable
for action in self.editor.edit_menu_actions:
action.setEnabled(True) | python | def update_edit_menu(self):
"""Update edit menu"""
widget, textedit_properties = self.get_focus_widget_properties()
if textedit_properties is None: # widget is not an editor/console
return
# !!! Below this line, widget is expected to be a QPlainTextEdit
# instance
console, not_readonly, readwrite_editor = textedit_properties
# Editor has focus and there is no file opened in it
if not console and not_readonly and not self.editor.is_file_opened():
return
# Disabling all actions to begin with
for child in self.edit_menu.actions():
child.setEnabled(False)
self.selectall_action.setEnabled(True)
# Undo, redo
self.undo_action.setEnabled( readwrite_editor \
and widget.document().isUndoAvailable() )
self.redo_action.setEnabled( readwrite_editor \
and widget.document().isRedoAvailable() )
# Copy, cut, paste, delete
has_selection = widget.has_selected_text()
self.copy_action.setEnabled(has_selection)
self.cut_action.setEnabled(has_selection and not_readonly)
self.paste_action.setEnabled(not_readonly)
# Comment, uncomment, indent, unindent...
if not console and not_readonly:
# This is the editor and current file is writable
for action in self.editor.edit_menu_actions:
action.setEnabled(True) | [
"def",
"update_edit_menu",
"(",
"self",
")",
":",
"widget",
",",
"textedit_properties",
"=",
"self",
".",
"get_focus_widget_properties",
"(",
")",
"if",
"textedit_properties",
"is",
"None",
":",
"# widget is not an editor/console\r",
"return",
"# !!! Below this line, widget is expected to be a QPlainTextEdit\r",
"# instance\r",
"console",
",",
"not_readonly",
",",
"readwrite_editor",
"=",
"textedit_properties",
"# Editor has focus and there is no file opened in it\r",
"if",
"not",
"console",
"and",
"not_readonly",
"and",
"not",
"self",
".",
"editor",
".",
"is_file_opened",
"(",
")",
":",
"return",
"# Disabling all actions to begin with\r",
"for",
"child",
"in",
"self",
".",
"edit_menu",
".",
"actions",
"(",
")",
":",
"child",
".",
"setEnabled",
"(",
"False",
")",
"self",
".",
"selectall_action",
".",
"setEnabled",
"(",
"True",
")",
"# Undo, redo\r",
"self",
".",
"undo_action",
".",
"setEnabled",
"(",
"readwrite_editor",
"and",
"widget",
".",
"document",
"(",
")",
".",
"isUndoAvailable",
"(",
")",
")",
"self",
".",
"redo_action",
".",
"setEnabled",
"(",
"readwrite_editor",
"and",
"widget",
".",
"document",
"(",
")",
".",
"isRedoAvailable",
"(",
")",
")",
"# Copy, cut, paste, delete\r",
"has_selection",
"=",
"widget",
".",
"has_selected_text",
"(",
")",
"self",
".",
"copy_action",
".",
"setEnabled",
"(",
"has_selection",
")",
"self",
".",
"cut_action",
".",
"setEnabled",
"(",
"has_selection",
"and",
"not_readonly",
")",
"self",
".",
"paste_action",
".",
"setEnabled",
"(",
"not_readonly",
")",
"# Comment, uncomment, indent, unindent...\r",
"if",
"not",
"console",
"and",
"not_readonly",
":",
"# This is the editor and current file is writable\r",
"for",
"action",
"in",
"self",
".",
"editor",
".",
"edit_menu_actions",
":",
"action",
".",
"setEnabled",
"(",
"True",
")"
] | Update edit menu | [
"Update",
"edit",
"menu"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2143-L2178 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.update_search_menu | def update_search_menu(self):
"""Update search menu"""
# Disabling all actions except the last one
# (which is Find in files) to begin with
for child in self.search_menu.actions()[:-1]:
child.setEnabled(False)
widget, textedit_properties = self.get_focus_widget_properties()
if textedit_properties is None: # widget is not an editor/console
return
# !!! Below this line, widget is expected to be a QPlainTextEdit
# instance
console, not_readonly, readwrite_editor = textedit_properties
# Find actions only trigger an effect in the Editor
if not console:
for action in self.search_menu.actions():
try:
action.setEnabled(True)
except RuntimeError:
pass
# Disable the replace action for read-only files
self.search_menu_actions[3].setEnabled(readwrite_editor) | python | def update_search_menu(self):
"""Update search menu"""
# Disabling all actions except the last one
# (which is Find in files) to begin with
for child in self.search_menu.actions()[:-1]:
child.setEnabled(False)
widget, textedit_properties = self.get_focus_widget_properties()
if textedit_properties is None: # widget is not an editor/console
return
# !!! Below this line, widget is expected to be a QPlainTextEdit
# instance
console, not_readonly, readwrite_editor = textedit_properties
# Find actions only trigger an effect in the Editor
if not console:
for action in self.search_menu.actions():
try:
action.setEnabled(True)
except RuntimeError:
pass
# Disable the replace action for read-only files
self.search_menu_actions[3].setEnabled(readwrite_editor) | [
"def",
"update_search_menu",
"(",
"self",
")",
":",
"# Disabling all actions except the last one\r",
"# (which is Find in files) to begin with\r",
"for",
"child",
"in",
"self",
".",
"search_menu",
".",
"actions",
"(",
")",
"[",
":",
"-",
"1",
"]",
":",
"child",
".",
"setEnabled",
"(",
"False",
")",
"widget",
",",
"textedit_properties",
"=",
"self",
".",
"get_focus_widget_properties",
"(",
")",
"if",
"textedit_properties",
"is",
"None",
":",
"# widget is not an editor/console\r",
"return",
"# !!! Below this line, widget is expected to be a QPlainTextEdit\r",
"# instance\r",
"console",
",",
"not_readonly",
",",
"readwrite_editor",
"=",
"textedit_properties",
"# Find actions only trigger an effect in the Editor\r",
"if",
"not",
"console",
":",
"for",
"action",
"in",
"self",
".",
"search_menu",
".",
"actions",
"(",
")",
":",
"try",
":",
"action",
".",
"setEnabled",
"(",
"True",
")",
"except",
"RuntimeError",
":",
"pass",
"# Disable the replace action for read-only files\r",
"self",
".",
"search_menu_actions",
"[",
"3",
"]",
".",
"setEnabled",
"(",
"readwrite_editor",
")"
] | Update search menu | [
"Update",
"search",
"menu"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2180-L2204 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.set_splash | def set_splash(self, message):
"""Set splash message"""
if self.splash is None:
return
if message:
logger.info(message)
self.splash.show()
self.splash.showMessage(message, Qt.AlignBottom | Qt.AlignCenter |
Qt.AlignAbsolute, QColor(Qt.white))
QApplication.processEvents() | python | def set_splash(self, message):
"""Set splash message"""
if self.splash is None:
return
if message:
logger.info(message)
self.splash.show()
self.splash.showMessage(message, Qt.AlignBottom | Qt.AlignCenter |
Qt.AlignAbsolute, QColor(Qt.white))
QApplication.processEvents() | [
"def",
"set_splash",
"(",
"self",
",",
"message",
")",
":",
"if",
"self",
".",
"splash",
"is",
"None",
":",
"return",
"if",
"message",
":",
"logger",
".",
"info",
"(",
"message",
")",
"self",
".",
"splash",
".",
"show",
"(",
")",
"self",
".",
"splash",
".",
"showMessage",
"(",
"message",
",",
"Qt",
".",
"AlignBottom",
"|",
"Qt",
".",
"AlignCenter",
"|",
"Qt",
".",
"AlignAbsolute",
",",
"QColor",
"(",
"Qt",
".",
"white",
")",
")",
"QApplication",
".",
"processEvents",
"(",
")"
] | Set splash message | [
"Set",
"splash",
"message"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2255-L2264 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.closeEvent | def closeEvent(self, event):
"""closeEvent reimplementation"""
if self.closing(True):
event.accept()
else:
event.ignore() | python | def closeEvent(self, event):
"""closeEvent reimplementation"""
if self.closing(True):
event.accept()
else:
event.ignore() | [
"def",
"closeEvent",
"(",
"self",
",",
"event",
")",
":",
"if",
"self",
".",
"closing",
"(",
"True",
")",
":",
"event",
".",
"accept",
"(",
")",
"else",
":",
"event",
".",
"ignore",
"(",
")"
] | closeEvent reimplementation | [
"closeEvent",
"reimplementation"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2266-L2271 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.resizeEvent | def resizeEvent(self, event):
"""Reimplement Qt method"""
if not self.isMaximized() and not self.fullscreen_flag:
self.window_size = self.size()
QMainWindow.resizeEvent(self, event)
# To be used by the tour to be able to resize
self.sig_resized.emit(event) | python | def resizeEvent(self, event):
"""Reimplement Qt method"""
if not self.isMaximized() and not self.fullscreen_flag:
self.window_size = self.size()
QMainWindow.resizeEvent(self, event)
# To be used by the tour to be able to resize
self.sig_resized.emit(event) | [
"def",
"resizeEvent",
"(",
"self",
",",
"event",
")",
":",
"if",
"not",
"self",
".",
"isMaximized",
"(",
")",
"and",
"not",
"self",
".",
"fullscreen_flag",
":",
"self",
".",
"window_size",
"=",
"self",
".",
"size",
"(",
")",
"QMainWindow",
".",
"resizeEvent",
"(",
"self",
",",
"event",
")",
"# To be used by the tour to be able to resize\r",
"self",
".",
"sig_resized",
".",
"emit",
"(",
"event",
")"
] | Reimplement Qt method | [
"Reimplement",
"Qt",
"method"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2273-L2280 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.moveEvent | def moveEvent(self, event):
"""Reimplement Qt method"""
if not self.isMaximized() and not self.fullscreen_flag:
self.window_position = self.pos()
QMainWindow.moveEvent(self, event)
# To be used by the tour to be able to move
self.sig_moved.emit(event) | python | def moveEvent(self, event):
"""Reimplement Qt method"""
if not self.isMaximized() and not self.fullscreen_flag:
self.window_position = self.pos()
QMainWindow.moveEvent(self, event)
# To be used by the tour to be able to move
self.sig_moved.emit(event) | [
"def",
"moveEvent",
"(",
"self",
",",
"event",
")",
":",
"if",
"not",
"self",
".",
"isMaximized",
"(",
")",
"and",
"not",
"self",
".",
"fullscreen_flag",
":",
"self",
".",
"window_position",
"=",
"self",
".",
"pos",
"(",
")",
"QMainWindow",
".",
"moveEvent",
"(",
"self",
",",
"event",
")",
"# To be used by the tour to be able to move\r",
"self",
".",
"sig_moved",
".",
"emit",
"(",
"event",
")"
] | Reimplement Qt method | [
"Reimplement",
"Qt",
"method"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2282-L2289 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.hideEvent | def hideEvent(self, event):
"""Reimplement Qt method"""
try:
for plugin in (self.widgetlist + self.thirdparty_plugins):
if plugin.isAncestorOf(self.last_focused_widget):
plugin.visibility_changed(True)
QMainWindow.hideEvent(self, event)
except RuntimeError:
QMainWindow.hideEvent(self, event) | python | def hideEvent(self, event):
"""Reimplement Qt method"""
try:
for plugin in (self.widgetlist + self.thirdparty_plugins):
if plugin.isAncestorOf(self.last_focused_widget):
plugin.visibility_changed(True)
QMainWindow.hideEvent(self, event)
except RuntimeError:
QMainWindow.hideEvent(self, event) | [
"def",
"hideEvent",
"(",
"self",
",",
"event",
")",
":",
"try",
":",
"for",
"plugin",
"in",
"(",
"self",
".",
"widgetlist",
"+",
"self",
".",
"thirdparty_plugins",
")",
":",
"if",
"plugin",
".",
"isAncestorOf",
"(",
"self",
".",
"last_focused_widget",
")",
":",
"plugin",
".",
"visibility_changed",
"(",
"True",
")",
"QMainWindow",
".",
"hideEvent",
"(",
"self",
",",
"event",
")",
"except",
"RuntimeError",
":",
"QMainWindow",
".",
"hideEvent",
"(",
"self",
",",
"event",
")"
] | Reimplement Qt method | [
"Reimplement",
"Qt",
"method"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2291-L2299 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.change_last_focused_widget | def change_last_focused_widget(self, old, now):
"""To keep track of to the last focused widget"""
if (now is None and QApplication.activeWindow() is not None):
QApplication.activeWindow().setFocus()
self.last_focused_widget = QApplication.focusWidget()
elif now is not None:
self.last_focused_widget = now
self.previous_focused_widget = old | python | def change_last_focused_widget(self, old, now):
"""To keep track of to the last focused widget"""
if (now is None and QApplication.activeWindow() is not None):
QApplication.activeWindow().setFocus()
self.last_focused_widget = QApplication.focusWidget()
elif now is not None:
self.last_focused_widget = now
self.previous_focused_widget = old | [
"def",
"change_last_focused_widget",
"(",
"self",
",",
"old",
",",
"now",
")",
":",
"if",
"(",
"now",
"is",
"None",
"and",
"QApplication",
".",
"activeWindow",
"(",
")",
"is",
"not",
"None",
")",
":",
"QApplication",
".",
"activeWindow",
"(",
")",
".",
"setFocus",
"(",
")",
"self",
".",
"last_focused_widget",
"=",
"QApplication",
".",
"focusWidget",
"(",
")",
"elif",
"now",
"is",
"not",
"None",
":",
"self",
".",
"last_focused_widget",
"=",
"now",
"self",
".",
"previous_focused_widget",
"=",
"old"
] | To keep track of to the last focused widget | [
"To",
"keep",
"track",
"of",
"to",
"the",
"last",
"focused",
"widget"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2301-L2309 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.closing | def closing(self, cancelable=False):
"""Exit tasks"""
if self.already_closed or self.is_starting_up:
return True
if cancelable and CONF.get('main', 'prompt_on_exit'):
reply = QMessageBox.critical(self, 'Spyder',
'Do you really want to exit?',
QMessageBox.Yes, QMessageBox.No)
if reply == QMessageBox.No:
return False
prefix = 'window' + '/'
self.save_current_window_settings(prefix)
if CONF.get('main', 'single_instance') and self.open_files_server:
self.open_files_server.close()
for plugin in (self.widgetlist + self.thirdparty_plugins):
plugin.close_window()
if not plugin.closing_plugin(cancelable):
return False
self.dialog_manager.close_all()
if self.toolbars_visible:
self.save_visible_toolbars()
self.lspmanager.shutdown()
self.already_closed = True
return True | python | def closing(self, cancelable=False):
"""Exit tasks"""
if self.already_closed or self.is_starting_up:
return True
if cancelable and CONF.get('main', 'prompt_on_exit'):
reply = QMessageBox.critical(self, 'Spyder',
'Do you really want to exit?',
QMessageBox.Yes, QMessageBox.No)
if reply == QMessageBox.No:
return False
prefix = 'window' + '/'
self.save_current_window_settings(prefix)
if CONF.get('main', 'single_instance') and self.open_files_server:
self.open_files_server.close()
for plugin in (self.widgetlist + self.thirdparty_plugins):
plugin.close_window()
if not plugin.closing_plugin(cancelable):
return False
self.dialog_manager.close_all()
if self.toolbars_visible:
self.save_visible_toolbars()
self.lspmanager.shutdown()
self.already_closed = True
return True | [
"def",
"closing",
"(",
"self",
",",
"cancelable",
"=",
"False",
")",
":",
"if",
"self",
".",
"already_closed",
"or",
"self",
".",
"is_starting_up",
":",
"return",
"True",
"if",
"cancelable",
"and",
"CONF",
".",
"get",
"(",
"'main'",
",",
"'prompt_on_exit'",
")",
":",
"reply",
"=",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"'Spyder'",
",",
"'Do you really want to exit?'",
",",
"QMessageBox",
".",
"Yes",
",",
"QMessageBox",
".",
"No",
")",
"if",
"reply",
"==",
"QMessageBox",
".",
"No",
":",
"return",
"False",
"prefix",
"=",
"'window'",
"+",
"'/'",
"self",
".",
"save_current_window_settings",
"(",
"prefix",
")",
"if",
"CONF",
".",
"get",
"(",
"'main'",
",",
"'single_instance'",
")",
"and",
"self",
".",
"open_files_server",
":",
"self",
".",
"open_files_server",
".",
"close",
"(",
")",
"for",
"plugin",
"in",
"(",
"self",
".",
"widgetlist",
"+",
"self",
".",
"thirdparty_plugins",
")",
":",
"plugin",
".",
"close_window",
"(",
")",
"if",
"not",
"plugin",
".",
"closing_plugin",
"(",
"cancelable",
")",
":",
"return",
"False",
"self",
".",
"dialog_manager",
".",
"close_all",
"(",
")",
"if",
"self",
".",
"toolbars_visible",
":",
"self",
".",
"save_visible_toolbars",
"(",
")",
"self",
".",
"lspmanager",
".",
"shutdown",
"(",
")",
"self",
".",
"already_closed",
"=",
"True",
"return",
"True"
] | Exit tasks | [
"Exit",
"tasks"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2311-L2334 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.add_dockwidget | def add_dockwidget(self, child):
"""Add QDockWidget and toggleViewAction"""
dockwidget, location = child.create_dockwidget()
if CONF.get('main', 'vertical_dockwidget_titlebars'):
dockwidget.setFeatures(dockwidget.features()|
QDockWidget.DockWidgetVerticalTitleBar)
self.addDockWidget(location, dockwidget)
self.widgetlist.append(child) | python | def add_dockwidget(self, child):
"""Add QDockWidget and toggleViewAction"""
dockwidget, location = child.create_dockwidget()
if CONF.get('main', 'vertical_dockwidget_titlebars'):
dockwidget.setFeatures(dockwidget.features()|
QDockWidget.DockWidgetVerticalTitleBar)
self.addDockWidget(location, dockwidget)
self.widgetlist.append(child) | [
"def",
"add_dockwidget",
"(",
"self",
",",
"child",
")",
":",
"dockwidget",
",",
"location",
"=",
"child",
".",
"create_dockwidget",
"(",
")",
"if",
"CONF",
".",
"get",
"(",
"'main'",
",",
"'vertical_dockwidget_titlebars'",
")",
":",
"dockwidget",
".",
"setFeatures",
"(",
"dockwidget",
".",
"features",
"(",
")",
"|",
"QDockWidget",
".",
"DockWidgetVerticalTitleBar",
")",
"self",
".",
"addDockWidget",
"(",
"location",
",",
"dockwidget",
")",
"self",
".",
"widgetlist",
".",
"append",
"(",
"child",
")"
] | Add QDockWidget and toggleViewAction | [
"Add",
"QDockWidget",
"and",
"toggleViewAction"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2336-L2343 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.toggle_lock | def toggle_lock(self, value):
"""Lock/Unlock dockwidgets and toolbars"""
self.interface_locked = value
CONF.set('main', 'panes_locked', value)
# Apply lock to panes
for plugin in (self.widgetlist + self.thirdparty_plugins):
if self.interface_locked:
if plugin.dockwidget.isFloating():
plugin.dockwidget.setFloating(False)
plugin.dockwidget.setTitleBarWidget(QWidget())
else:
plugin.dockwidget.set_title_bar()
# Apply lock to toolbars
for toolbar in self.toolbarslist:
if self.interface_locked:
toolbar.setMovable(False)
else:
toolbar.setMovable(True) | python | def toggle_lock(self, value):
"""Lock/Unlock dockwidgets and toolbars"""
self.interface_locked = value
CONF.set('main', 'panes_locked', value)
# Apply lock to panes
for plugin in (self.widgetlist + self.thirdparty_plugins):
if self.interface_locked:
if plugin.dockwidget.isFloating():
plugin.dockwidget.setFloating(False)
plugin.dockwidget.setTitleBarWidget(QWidget())
else:
plugin.dockwidget.set_title_bar()
# Apply lock to toolbars
for toolbar in self.toolbarslist:
if self.interface_locked:
toolbar.setMovable(False)
else:
toolbar.setMovable(True) | [
"def",
"toggle_lock",
"(",
"self",
",",
"value",
")",
":",
"self",
".",
"interface_locked",
"=",
"value",
"CONF",
".",
"set",
"(",
"'main'",
",",
"'panes_locked'",
",",
"value",
")",
"# Apply lock to panes\r",
"for",
"plugin",
"in",
"(",
"self",
".",
"widgetlist",
"+",
"self",
".",
"thirdparty_plugins",
")",
":",
"if",
"self",
".",
"interface_locked",
":",
"if",
"plugin",
".",
"dockwidget",
".",
"isFloating",
"(",
")",
":",
"plugin",
".",
"dockwidget",
".",
"setFloating",
"(",
"False",
")",
"plugin",
".",
"dockwidget",
".",
"setTitleBarWidget",
"(",
"QWidget",
"(",
")",
")",
"else",
":",
"plugin",
".",
"dockwidget",
".",
"set_title_bar",
"(",
")",
"# Apply lock to toolbars\r",
"for",
"toolbar",
"in",
"self",
".",
"toolbarslist",
":",
"if",
"self",
".",
"interface_locked",
":",
"toolbar",
".",
"setMovable",
"(",
"False",
")",
"else",
":",
"toolbar",
".",
"setMovable",
"(",
"True",
")"
] | Lock/Unlock dockwidgets and toolbars | [
"Lock",
"/",
"Unlock",
"dockwidgets",
"and",
"toolbars"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2353-L2372 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.maximize_dockwidget | def maximize_dockwidget(self, restore=False):
"""Shortcut: Ctrl+Alt+Shift+M
First call: maximize current dockwidget
Second call (or restore=True): restore original window layout"""
if self.state_before_maximizing is None:
if restore:
return
# Select plugin to maximize
self.state_before_maximizing = self.saveState()
focus_widget = QApplication.focusWidget()
for plugin in (self.widgetlist + self.thirdparty_plugins):
plugin.dockwidget.hide()
if plugin.isAncestorOf(focus_widget):
self.last_plugin = plugin
# Only plugins that have a dockwidget are part of widgetlist,
# so last_plugin can be None after the above "for" cycle.
# For example, this happens if, after Spyder has started, focus
# is set to the Working directory toolbar (which doesn't have
# a dockwidget) and then you press the Maximize button
if self.last_plugin is None:
# Using the Editor as default plugin to maximize
self.last_plugin = self.editor
# Maximize last_plugin
self.last_plugin.dockwidget.toggleViewAction().setDisabled(True)
self.setCentralWidget(self.last_plugin)
self.last_plugin.ismaximized = True
# Workaround to solve an issue with editor's outline explorer:
# (otherwise the whole plugin is hidden and so is the outline explorer
# and the latter won't be refreshed if not visible)
self.last_plugin.show()
self.last_plugin.visibility_changed(True)
if self.last_plugin is self.editor:
# Automatically show the outline if the editor was maximized:
self.addDockWidget(Qt.RightDockWidgetArea,
self.outlineexplorer.dockwidget)
self.outlineexplorer.dockwidget.show()
else:
# Restore original layout (before maximizing current dockwidget)
self.last_plugin.dockwidget.setWidget(self.last_plugin)
self.last_plugin.dockwidget.toggleViewAction().setEnabled(True)
self.setCentralWidget(None)
self.last_plugin.ismaximized = False
self.restoreState(self.state_before_maximizing)
self.state_before_maximizing = None
self.last_plugin.get_focus_widget().setFocus()
self.__update_maximize_action() | python | def maximize_dockwidget(self, restore=False):
"""Shortcut: Ctrl+Alt+Shift+M
First call: maximize current dockwidget
Second call (or restore=True): restore original window layout"""
if self.state_before_maximizing is None:
if restore:
return
# Select plugin to maximize
self.state_before_maximizing = self.saveState()
focus_widget = QApplication.focusWidget()
for plugin in (self.widgetlist + self.thirdparty_plugins):
plugin.dockwidget.hide()
if plugin.isAncestorOf(focus_widget):
self.last_plugin = plugin
# Only plugins that have a dockwidget are part of widgetlist,
# so last_plugin can be None after the above "for" cycle.
# For example, this happens if, after Spyder has started, focus
# is set to the Working directory toolbar (which doesn't have
# a dockwidget) and then you press the Maximize button
if self.last_plugin is None:
# Using the Editor as default plugin to maximize
self.last_plugin = self.editor
# Maximize last_plugin
self.last_plugin.dockwidget.toggleViewAction().setDisabled(True)
self.setCentralWidget(self.last_plugin)
self.last_plugin.ismaximized = True
# Workaround to solve an issue with editor's outline explorer:
# (otherwise the whole plugin is hidden and so is the outline explorer
# and the latter won't be refreshed if not visible)
self.last_plugin.show()
self.last_plugin.visibility_changed(True)
if self.last_plugin is self.editor:
# Automatically show the outline if the editor was maximized:
self.addDockWidget(Qt.RightDockWidgetArea,
self.outlineexplorer.dockwidget)
self.outlineexplorer.dockwidget.show()
else:
# Restore original layout (before maximizing current dockwidget)
self.last_plugin.dockwidget.setWidget(self.last_plugin)
self.last_plugin.dockwidget.toggleViewAction().setEnabled(True)
self.setCentralWidget(None)
self.last_plugin.ismaximized = False
self.restoreState(self.state_before_maximizing)
self.state_before_maximizing = None
self.last_plugin.get_focus_widget().setFocus()
self.__update_maximize_action() | [
"def",
"maximize_dockwidget",
"(",
"self",
",",
"restore",
"=",
"False",
")",
":",
"if",
"self",
".",
"state_before_maximizing",
"is",
"None",
":",
"if",
"restore",
":",
"return",
"# Select plugin to maximize\r",
"self",
".",
"state_before_maximizing",
"=",
"self",
".",
"saveState",
"(",
")",
"focus_widget",
"=",
"QApplication",
".",
"focusWidget",
"(",
")",
"for",
"plugin",
"in",
"(",
"self",
".",
"widgetlist",
"+",
"self",
".",
"thirdparty_plugins",
")",
":",
"plugin",
".",
"dockwidget",
".",
"hide",
"(",
")",
"if",
"plugin",
".",
"isAncestorOf",
"(",
"focus_widget",
")",
":",
"self",
".",
"last_plugin",
"=",
"plugin",
"# Only plugins that have a dockwidget are part of widgetlist,\r",
"# so last_plugin can be None after the above \"for\" cycle.\r",
"# For example, this happens if, after Spyder has started, focus\r",
"# is set to the Working directory toolbar (which doesn't have\r",
"# a dockwidget) and then you press the Maximize button\r",
"if",
"self",
".",
"last_plugin",
"is",
"None",
":",
"# Using the Editor as default plugin to maximize\r",
"self",
".",
"last_plugin",
"=",
"self",
".",
"editor",
"# Maximize last_plugin\r",
"self",
".",
"last_plugin",
".",
"dockwidget",
".",
"toggleViewAction",
"(",
")",
".",
"setDisabled",
"(",
"True",
")",
"self",
".",
"setCentralWidget",
"(",
"self",
".",
"last_plugin",
")",
"self",
".",
"last_plugin",
".",
"ismaximized",
"=",
"True",
"# Workaround to solve an issue with editor's outline explorer:\r",
"# (otherwise the whole plugin is hidden and so is the outline explorer\r",
"# and the latter won't be refreshed if not visible)\r",
"self",
".",
"last_plugin",
".",
"show",
"(",
")",
"self",
".",
"last_plugin",
".",
"visibility_changed",
"(",
"True",
")",
"if",
"self",
".",
"last_plugin",
"is",
"self",
".",
"editor",
":",
"# Automatically show the outline if the editor was maximized:\r",
"self",
".",
"addDockWidget",
"(",
"Qt",
".",
"RightDockWidgetArea",
",",
"self",
".",
"outlineexplorer",
".",
"dockwidget",
")",
"self",
".",
"outlineexplorer",
".",
"dockwidget",
".",
"show",
"(",
")",
"else",
":",
"# Restore original layout (before maximizing current dockwidget)\r",
"self",
".",
"last_plugin",
".",
"dockwidget",
".",
"setWidget",
"(",
"self",
".",
"last_plugin",
")",
"self",
".",
"last_plugin",
".",
"dockwidget",
".",
"toggleViewAction",
"(",
")",
".",
"setEnabled",
"(",
"True",
")",
"self",
".",
"setCentralWidget",
"(",
"None",
")",
"self",
".",
"last_plugin",
".",
"ismaximized",
"=",
"False",
"self",
".",
"restoreState",
"(",
"self",
".",
"state_before_maximizing",
")",
"self",
".",
"state_before_maximizing",
"=",
"None",
"self",
".",
"last_plugin",
".",
"get_focus_widget",
"(",
")",
".",
"setFocus",
"(",
")",
"self",
".",
"__update_maximize_action",
"(",
")"
] | Shortcut: Ctrl+Alt+Shift+M
First call: maximize current dockwidget
Second call (or restore=True): restore original window layout | [
"Shortcut",
":",
"Ctrl",
"+",
"Alt",
"+",
"Shift",
"+",
"M",
"First",
"call",
":",
"maximize",
"current",
"dockwidget",
"Second",
"call",
"(",
"or",
"restore",
"=",
"True",
")",
":",
"restore",
"original",
"window",
"layout"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2389-L2438 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.add_to_toolbar | def add_to_toolbar(self, toolbar, widget):
"""Add widget actions to toolbar"""
actions = widget.toolbar_actions
if actions is not None:
add_actions(toolbar, actions) | python | def add_to_toolbar(self, toolbar, widget):
"""Add widget actions to toolbar"""
actions = widget.toolbar_actions
if actions is not None:
add_actions(toolbar, actions) | [
"def",
"add_to_toolbar",
"(",
"self",
",",
"toolbar",
",",
"widget",
")",
":",
"actions",
"=",
"widget",
".",
"toolbar_actions",
"if",
"actions",
"is",
"not",
"None",
":",
"add_actions",
"(",
"toolbar",
",",
"actions",
")"
] | Add widget actions to toolbar | [
"Add",
"widget",
"actions",
"to",
"toolbar"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2486-L2490 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.about | def about(self):
"""Create About Spyder dialog with general information."""
versions = get_versions()
# Show Git revision for development version
revlink = ''
if versions['revision']:
rev = versions['revision']
revlink = " (<a href='https://github.com/spyder-ide/spyder/"\
"commit/%s'>Commit: %s</a>)" % (rev, rev)
msgBox = QMessageBox(self)
msgBox.setText(
"""
<b>Spyder {spyder_ver}</b> {revision}
<br>The Scientific Python Development Environment |
<a href="{website_url}">Spyder-IDE.org</a>
<br>Copyright © 2009-2019 Spyder Project Contributors and
<a href="{github_url}/blob/master/AUTHORS.txt">others</a>
<br>Distributed under the terms of the
<a href="{github_url}/blob/master/LICENSE.txt">MIT License</a>.
<p>Created by Pierre Raybaut; current maintainer is Carlos Cordoba.
<br>Developed by the
<a href="{github_url}/graphs/contributors">international
Spyder community</a>.
<br>Many thanks to all the Spyder beta testers and dedicated users.
<p>For help with Spyder errors and crashes, please read our
<a href="{trouble_url}">Troubleshooting Guide</a>, and for bug
reports and feature requests, visit our
<a href="{github_url}">Github site</a>.
For project discussion, see our
<a href="{forum_url}">Google Group</a>.
<p>This project is part of a larger effort to promote and
facilitate the use of Python for scientific and engineering
software development.
The popular Python distributions
<a href="https://www.anaconda.com/download/">Anaconda</a> and
<a href="https://winpython.github.io/">WinPython</a>
also contribute to this plan.
<p>Python {python_ver} {bitness}-bit | Qt {qt_ver} |
{qt_api} {qt_api_ver} | {os_name} {os_ver}
<small><p>Certain source files under other compatible permissive
licenses and/or originally by other authors.
Spyder 3 theme icons derived from
<a href="https://fontawesome.com/">Font Awesome</a> 4.7
(© 2016 David Gandy; SIL OFL 1.1) and
<a href="http://materialdesignicons.com/">Material Design</a>
(© 2014 Austin Andrews; SIL OFL 1.1).
Most Spyder 2 theme icons sourced from the
<a href="https://www.everaldo.com">Crystal Project iconset</a>
(© 2006-2007 Everaldo Coelho; LGPL 2.1+).
Other icons from
<a href="http://p.yusukekamiyamane.com/">Yusuke Kamiyamane</a>
(© 2013 Yusuke Kamiyamane; CC-BY 3.0),
the <a href="http://www.famfamfam.com/lab/icons/silk/">FamFamFam
Silk icon set</a> 1.3 (© 2006 Mark James; CC-BY 2.5), and
the <a href="https://www.kde.org/">KDE Oxygen icons</a>
(© 2007 KDE Artists; LGPL 3.0+).</small>
<p>See the <a href="{github_url}/blob/master/NOTICE.txt">NOTICE</a>
file for full legal information.
"""
.format(spyder_ver=versions['spyder'],
revision=revlink,
website_url=__website_url__,
github_url=__project_url__,
trouble_url=__trouble_url__,
forum_url=__forum_url__,
python_ver=versions['python'],
bitness=versions['bitness'],
qt_ver=versions['qt'],
qt_api=versions['qt_api'],
qt_api_ver=versions['qt_api_ver'],
os_name=versions['system'],
os_ver=versions['release'])
)
msgBox.setWindowTitle(_("About %s") % "Spyder")
msgBox.setStandardButtons(QMessageBox.Ok)
from spyder.config.gui import is_dark_interface
if PYQT5:
if is_dark_interface():
icon_filename = "spyder.svg"
else:
icon_filename = "spyder_dark.svg"
else:
if is_dark_interface():
icon_filename = "spyder.png"
else:
icon_filename = "spyder_dark.png"
app_icon = QIcon(get_image_path(icon_filename))
msgBox.setIconPixmap(app_icon.pixmap(QSize(64, 64)))
msgBox.setTextInteractionFlags(
Qt.LinksAccessibleByMouse | Qt.TextSelectableByMouse)
msgBox.exec_() | python | def about(self):
"""Create About Spyder dialog with general information."""
versions = get_versions()
# Show Git revision for development version
revlink = ''
if versions['revision']:
rev = versions['revision']
revlink = " (<a href='https://github.com/spyder-ide/spyder/"\
"commit/%s'>Commit: %s</a>)" % (rev, rev)
msgBox = QMessageBox(self)
msgBox.setText(
"""
<b>Spyder {spyder_ver}</b> {revision}
<br>The Scientific Python Development Environment |
<a href="{website_url}">Spyder-IDE.org</a>
<br>Copyright © 2009-2019 Spyder Project Contributors and
<a href="{github_url}/blob/master/AUTHORS.txt">others</a>
<br>Distributed under the terms of the
<a href="{github_url}/blob/master/LICENSE.txt">MIT License</a>.
<p>Created by Pierre Raybaut; current maintainer is Carlos Cordoba.
<br>Developed by the
<a href="{github_url}/graphs/contributors">international
Spyder community</a>.
<br>Many thanks to all the Spyder beta testers and dedicated users.
<p>For help with Spyder errors and crashes, please read our
<a href="{trouble_url}">Troubleshooting Guide</a>, and for bug
reports and feature requests, visit our
<a href="{github_url}">Github site</a>.
For project discussion, see our
<a href="{forum_url}">Google Group</a>.
<p>This project is part of a larger effort to promote and
facilitate the use of Python for scientific and engineering
software development.
The popular Python distributions
<a href="https://www.anaconda.com/download/">Anaconda</a> and
<a href="https://winpython.github.io/">WinPython</a>
also contribute to this plan.
<p>Python {python_ver} {bitness}-bit | Qt {qt_ver} |
{qt_api} {qt_api_ver} | {os_name} {os_ver}
<small><p>Certain source files under other compatible permissive
licenses and/or originally by other authors.
Spyder 3 theme icons derived from
<a href="https://fontawesome.com/">Font Awesome</a> 4.7
(© 2016 David Gandy; SIL OFL 1.1) and
<a href="http://materialdesignicons.com/">Material Design</a>
(© 2014 Austin Andrews; SIL OFL 1.1).
Most Spyder 2 theme icons sourced from the
<a href="https://www.everaldo.com">Crystal Project iconset</a>
(© 2006-2007 Everaldo Coelho; LGPL 2.1+).
Other icons from
<a href="http://p.yusukekamiyamane.com/">Yusuke Kamiyamane</a>
(© 2013 Yusuke Kamiyamane; CC-BY 3.0),
the <a href="http://www.famfamfam.com/lab/icons/silk/">FamFamFam
Silk icon set</a> 1.3 (© 2006 Mark James; CC-BY 2.5), and
the <a href="https://www.kde.org/">KDE Oxygen icons</a>
(© 2007 KDE Artists; LGPL 3.0+).</small>
<p>See the <a href="{github_url}/blob/master/NOTICE.txt">NOTICE</a>
file for full legal information.
"""
.format(spyder_ver=versions['spyder'],
revision=revlink,
website_url=__website_url__,
github_url=__project_url__,
trouble_url=__trouble_url__,
forum_url=__forum_url__,
python_ver=versions['python'],
bitness=versions['bitness'],
qt_ver=versions['qt'],
qt_api=versions['qt_api'],
qt_api_ver=versions['qt_api_ver'],
os_name=versions['system'],
os_ver=versions['release'])
)
msgBox.setWindowTitle(_("About %s") % "Spyder")
msgBox.setStandardButtons(QMessageBox.Ok)
from spyder.config.gui import is_dark_interface
if PYQT5:
if is_dark_interface():
icon_filename = "spyder.svg"
else:
icon_filename = "spyder_dark.svg"
else:
if is_dark_interface():
icon_filename = "spyder.png"
else:
icon_filename = "spyder_dark.png"
app_icon = QIcon(get_image_path(icon_filename))
msgBox.setIconPixmap(app_icon.pixmap(QSize(64, 64)))
msgBox.setTextInteractionFlags(
Qt.LinksAccessibleByMouse | Qt.TextSelectableByMouse)
msgBox.exec_() | [
"def",
"about",
"(",
"self",
")",
":",
"versions",
"=",
"get_versions",
"(",
")",
"# Show Git revision for development version\r",
"revlink",
"=",
"''",
"if",
"versions",
"[",
"'revision'",
"]",
":",
"rev",
"=",
"versions",
"[",
"'revision'",
"]",
"revlink",
"=",
"\" (<a href='https://github.com/spyder-ide/spyder/\"",
"\"commit/%s'>Commit: %s</a>)\"",
"%",
"(",
"rev",
",",
"rev",
")",
"msgBox",
"=",
"QMessageBox",
"(",
"self",
")",
"msgBox",
".",
"setText",
"(",
"\"\"\"\r\n <b>Spyder {spyder_ver}</b> {revision}\r\n <br>The Scientific Python Development Environment |\r\n <a href=\"{website_url}\">Spyder-IDE.org</a>\r\n <br>Copyright © 2009-2019 Spyder Project Contributors and\r\n <a href=\"{github_url}/blob/master/AUTHORS.txt\">others</a>\r\n <br>Distributed under the terms of the\r\n <a href=\"{github_url}/blob/master/LICENSE.txt\">MIT License</a>.\r\n\r\n <p>Created by Pierre Raybaut; current maintainer is Carlos Cordoba.\r\n <br>Developed by the\r\n <a href=\"{github_url}/graphs/contributors\">international\r\n Spyder community</a>.\r\n <br>Many thanks to all the Spyder beta testers and dedicated users.\r\n\r\n <p>For help with Spyder errors and crashes, please read our\r\n <a href=\"{trouble_url}\">Troubleshooting Guide</a>, and for bug\r\n reports and feature requests, visit our\r\n <a href=\"{github_url}\">Github site</a>.\r\n For project discussion, see our\r\n <a href=\"{forum_url}\">Google Group</a>.\r\n <p>This project is part of a larger effort to promote and\r\n facilitate the use of Python for scientific and engineering\r\n software development.\r\n The popular Python distributions\r\n <a href=\"https://www.anaconda.com/download/\">Anaconda</a> and\r\n <a href=\"https://winpython.github.io/\">WinPython</a>\r\n also contribute to this plan.\r\n\r\n <p>Python {python_ver} {bitness}-bit | Qt {qt_ver} |\r\n {qt_api} {qt_api_ver} | {os_name} {os_ver}\r\n\r\n <small><p>Certain source files under other compatible permissive\r\n licenses and/or originally by other authors.\r\n Spyder 3 theme icons derived from\r\n <a href=\"https://fontawesome.com/\">Font Awesome</a> 4.7\r\n (© 2016 David Gandy; SIL OFL 1.1) and\r\n <a href=\"http://materialdesignicons.com/\">Material Design</a>\r\n (© 2014 Austin Andrews; SIL OFL 1.1).\r\n Most Spyder 2 theme icons sourced from the\r\n <a href=\"https://www.everaldo.com\">Crystal Project iconset</a>\r\n (© 2006-2007 Everaldo Coelho; LGPL 2.1+).\r\n Other icons from\r\n <a href=\"http://p.yusukekamiyamane.com/\">Yusuke Kamiyamane</a>\r\n (© 2013 Yusuke Kamiyamane; CC-BY 3.0),\r\n the <a href=\"http://www.famfamfam.com/lab/icons/silk/\">FamFamFam\r\n Silk icon set</a> 1.3 (© 2006 Mark James; CC-BY 2.5), and\r\n the <a href=\"https://www.kde.org/\">KDE Oxygen icons</a>\r\n (© 2007 KDE Artists; LGPL 3.0+).</small>\r\n\r\n <p>See the <a href=\"{github_url}/blob/master/NOTICE.txt\">NOTICE</a>\r\n file for full legal information.\r\n \"\"\"",
".",
"format",
"(",
"spyder_ver",
"=",
"versions",
"[",
"'spyder'",
"]",
",",
"revision",
"=",
"revlink",
",",
"website_url",
"=",
"__website_url__",
",",
"github_url",
"=",
"__project_url__",
",",
"trouble_url",
"=",
"__trouble_url__",
",",
"forum_url",
"=",
"__forum_url__",
",",
"python_ver",
"=",
"versions",
"[",
"'python'",
"]",
",",
"bitness",
"=",
"versions",
"[",
"'bitness'",
"]",
",",
"qt_ver",
"=",
"versions",
"[",
"'qt'",
"]",
",",
"qt_api",
"=",
"versions",
"[",
"'qt_api'",
"]",
",",
"qt_api_ver",
"=",
"versions",
"[",
"'qt_api_ver'",
"]",
",",
"os_name",
"=",
"versions",
"[",
"'system'",
"]",
",",
"os_ver",
"=",
"versions",
"[",
"'release'",
"]",
")",
")",
"msgBox",
".",
"setWindowTitle",
"(",
"_",
"(",
"\"About %s\"",
")",
"%",
"\"Spyder\"",
")",
"msgBox",
".",
"setStandardButtons",
"(",
"QMessageBox",
".",
"Ok",
")",
"from",
"spyder",
".",
"config",
".",
"gui",
"import",
"is_dark_interface",
"if",
"PYQT5",
":",
"if",
"is_dark_interface",
"(",
")",
":",
"icon_filename",
"=",
"\"spyder.svg\"",
"else",
":",
"icon_filename",
"=",
"\"spyder_dark.svg\"",
"else",
":",
"if",
"is_dark_interface",
"(",
")",
":",
"icon_filename",
"=",
"\"spyder.png\"",
"else",
":",
"icon_filename",
"=",
"\"spyder_dark.png\"",
"app_icon",
"=",
"QIcon",
"(",
"get_image_path",
"(",
"icon_filename",
")",
")",
"msgBox",
".",
"setIconPixmap",
"(",
"app_icon",
".",
"pixmap",
"(",
"QSize",
"(",
"64",
",",
"64",
")",
")",
")",
"msgBox",
".",
"setTextInteractionFlags",
"(",
"Qt",
".",
"LinksAccessibleByMouse",
"|",
"Qt",
".",
"TextSelectableByMouse",
")",
"msgBox",
".",
"exec_",
"(",
")"
] | Create About Spyder dialog with general information. | [
"Create",
"About",
"Spyder",
"dialog",
"with",
"general",
"information",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2493-L2590 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.show_dependencies | def show_dependencies(self):
"""Show Spyder's Dependencies dialog box"""
from spyder.widgets.dependencies import DependenciesDialog
dlg = DependenciesDialog(self)
dlg.set_data(dependencies.DEPENDENCIES)
dlg.exec_() | python | def show_dependencies(self):
"""Show Spyder's Dependencies dialog box"""
from spyder.widgets.dependencies import DependenciesDialog
dlg = DependenciesDialog(self)
dlg.set_data(dependencies.DEPENDENCIES)
dlg.exec_() | [
"def",
"show_dependencies",
"(",
"self",
")",
":",
"from",
"spyder",
".",
"widgets",
".",
"dependencies",
"import",
"DependenciesDialog",
"dlg",
"=",
"DependenciesDialog",
"(",
"self",
")",
"dlg",
".",
"set_data",
"(",
"dependencies",
".",
"DEPENDENCIES",
")",
"dlg",
".",
"exec_",
"(",
")"
] | Show Spyder's Dependencies dialog box | [
"Show",
"Spyder",
"s",
"Dependencies",
"dialog",
"box"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2593-L2598 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.render_issue | def render_issue(self, description='', traceback=''):
"""Render issue before sending it to Github"""
# Get component versions
versions = get_versions()
# Get git revision for development version
revision = ''
if versions['revision']:
revision = versions['revision']
# Make a description header in case no description is supplied
if not description:
description = "### What steps reproduce the problem?"
# Make error section from traceback and add appropriate reminder header
if traceback:
error_section = ("### Traceback\n"
"```python-traceback\n"
"{}\n"
"```".format(traceback))
else:
error_section = ''
issue_template = """\
## Description
{description}
{error_section}
## Versions
* Spyder version: {spyder_version} {commit}
* Python version: {python_version}
* Qt version: {qt_version}
* {qt_api_name} version: {qt_api_version}
* Operating System: {os_name} {os_version}
### Dependencies
```
{dependencies}
```
""".format(description=description,
error_section=error_section,
spyder_version=versions['spyder'],
commit=revision,
python_version=versions['python'],
qt_version=versions['qt'],
qt_api_name=versions['qt_api'],
qt_api_version=versions['qt_api_ver'],
os_name=versions['system'],
os_version=versions['release'],
dependencies=dependencies.status())
return issue_template | python | def render_issue(self, description='', traceback=''):
"""Render issue before sending it to Github"""
# Get component versions
versions = get_versions()
# Get git revision for development version
revision = ''
if versions['revision']:
revision = versions['revision']
# Make a description header in case no description is supplied
if not description:
description = "### What steps reproduce the problem?"
# Make error section from traceback and add appropriate reminder header
if traceback:
error_section = ("### Traceback\n"
"```python-traceback\n"
"{}\n"
"```".format(traceback))
else:
error_section = ''
issue_template = """\
## Description
{description}
{error_section}
## Versions
* Spyder version: {spyder_version} {commit}
* Python version: {python_version}
* Qt version: {qt_version}
* {qt_api_name} version: {qt_api_version}
* Operating System: {os_name} {os_version}
### Dependencies
```
{dependencies}
```
""".format(description=description,
error_section=error_section,
spyder_version=versions['spyder'],
commit=revision,
python_version=versions['python'],
qt_version=versions['qt'],
qt_api_name=versions['qt_api'],
qt_api_version=versions['qt_api_ver'],
os_name=versions['system'],
os_version=versions['release'],
dependencies=dependencies.status())
return issue_template | [
"def",
"render_issue",
"(",
"self",
",",
"description",
"=",
"''",
",",
"traceback",
"=",
"''",
")",
":",
"# Get component versions\r",
"versions",
"=",
"get_versions",
"(",
")",
"# Get git revision for development version\r",
"revision",
"=",
"''",
"if",
"versions",
"[",
"'revision'",
"]",
":",
"revision",
"=",
"versions",
"[",
"'revision'",
"]",
"# Make a description header in case no description is supplied\r",
"if",
"not",
"description",
":",
"description",
"=",
"\"### What steps reproduce the problem?\"",
"# Make error section from traceback and add appropriate reminder header\r",
"if",
"traceback",
":",
"error_section",
"=",
"(",
"\"### Traceback\\n\"",
"\"```python-traceback\\n\"",
"\"{}\\n\"",
"\"```\"",
".",
"format",
"(",
"traceback",
")",
")",
"else",
":",
"error_section",
"=",
"''",
"issue_template",
"=",
"\"\"\"\\\r\n## Description\r\n\r\n{description}\r\n\r\n{error_section}\r\n\r\n## Versions\r\n\r\n* Spyder version: {spyder_version} {commit}\r\n* Python version: {python_version}\r\n* Qt version: {qt_version}\r\n* {qt_api_name} version: {qt_api_version}\r\n* Operating System: {os_name} {os_version}\r\n\r\n### Dependencies\r\n\r\n```\r\n{dependencies}\r\n```\r\n\"\"\"",
".",
"format",
"(",
"description",
"=",
"description",
",",
"error_section",
"=",
"error_section",
",",
"spyder_version",
"=",
"versions",
"[",
"'spyder'",
"]",
",",
"commit",
"=",
"revision",
",",
"python_version",
"=",
"versions",
"[",
"'python'",
"]",
",",
"qt_version",
"=",
"versions",
"[",
"'qt'",
"]",
",",
"qt_api_name",
"=",
"versions",
"[",
"'qt_api'",
"]",
",",
"qt_api_version",
"=",
"versions",
"[",
"'qt_api_ver'",
"]",
",",
"os_name",
"=",
"versions",
"[",
"'system'",
"]",
",",
"os_version",
"=",
"versions",
"[",
"'release'",
"]",
",",
"dependencies",
"=",
"dependencies",
".",
"status",
"(",
")",
")",
"return",
"issue_template"
] | Render issue before sending it to Github | [
"Render",
"issue",
"before",
"sending",
"it",
"to",
"Github"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2600-L2654 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.report_issue | def report_issue(self, body=None, title=None, open_webpage=False):
"""Report a Spyder issue to github, generating body text if needed."""
if body is None:
from spyder.widgets.reporterror import SpyderErrorDialog
report_dlg = SpyderErrorDialog(self, is_report=True)
report_dlg.show()
else:
if open_webpage:
if PY3:
from urllib.parse import quote
else:
from urllib import quote # analysis:ignore
from qtpy.QtCore import QUrlQuery
url = QUrl(__project_url__ + '/issues/new')
query = QUrlQuery()
query.addQueryItem("body", quote(body))
if title:
query.addQueryItem("title", quote(title))
url.setQuery(query)
QDesktopServices.openUrl(url) | python | def report_issue(self, body=None, title=None, open_webpage=False):
"""Report a Spyder issue to github, generating body text if needed."""
if body is None:
from spyder.widgets.reporterror import SpyderErrorDialog
report_dlg = SpyderErrorDialog(self, is_report=True)
report_dlg.show()
else:
if open_webpage:
if PY3:
from urllib.parse import quote
else:
from urllib import quote # analysis:ignore
from qtpy.QtCore import QUrlQuery
url = QUrl(__project_url__ + '/issues/new')
query = QUrlQuery()
query.addQueryItem("body", quote(body))
if title:
query.addQueryItem("title", quote(title))
url.setQuery(query)
QDesktopServices.openUrl(url) | [
"def",
"report_issue",
"(",
"self",
",",
"body",
"=",
"None",
",",
"title",
"=",
"None",
",",
"open_webpage",
"=",
"False",
")",
":",
"if",
"body",
"is",
"None",
":",
"from",
"spyder",
".",
"widgets",
".",
"reporterror",
"import",
"SpyderErrorDialog",
"report_dlg",
"=",
"SpyderErrorDialog",
"(",
"self",
",",
"is_report",
"=",
"True",
")",
"report_dlg",
".",
"show",
"(",
")",
"else",
":",
"if",
"open_webpage",
":",
"if",
"PY3",
":",
"from",
"urllib",
".",
"parse",
"import",
"quote",
"else",
":",
"from",
"urllib",
"import",
"quote",
"# analysis:ignore\r",
"from",
"qtpy",
".",
"QtCore",
"import",
"QUrlQuery",
"url",
"=",
"QUrl",
"(",
"__project_url__",
"+",
"'/issues/new'",
")",
"query",
"=",
"QUrlQuery",
"(",
")",
"query",
".",
"addQueryItem",
"(",
"\"body\"",
",",
"quote",
"(",
"body",
")",
")",
"if",
"title",
":",
"query",
".",
"addQueryItem",
"(",
"\"title\"",
",",
"quote",
"(",
"title",
")",
")",
"url",
".",
"setQuery",
"(",
"query",
")",
"QDesktopServices",
".",
"openUrl",
"(",
"url",
")"
] | Report a Spyder issue to github, generating body text if needed. | [
"Report",
"a",
"Spyder",
"issue",
"to",
"github",
"generating",
"body",
"text",
"if",
"needed",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2657-L2677 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.global_callback | def global_callback(self):
"""Global callback"""
widget = QApplication.focusWidget()
action = self.sender()
callback = from_qvariant(action.data(), to_text_string)
from spyder.plugins.editor.widgets.editor import TextEditBaseWidget
from spyder.plugins.ipythonconsole.widgets import ControlWidget
if isinstance(widget, (TextEditBaseWidget, ControlWidget)):
getattr(widget, callback)()
else:
return | python | def global_callback(self):
"""Global callback"""
widget = QApplication.focusWidget()
action = self.sender()
callback = from_qvariant(action.data(), to_text_string)
from spyder.plugins.editor.widgets.editor import TextEditBaseWidget
from spyder.plugins.ipythonconsole.widgets import ControlWidget
if isinstance(widget, (TextEditBaseWidget, ControlWidget)):
getattr(widget, callback)()
else:
return | [
"def",
"global_callback",
"(",
"self",
")",
":",
"widget",
"=",
"QApplication",
".",
"focusWidget",
"(",
")",
"action",
"=",
"self",
".",
"sender",
"(",
")",
"callback",
"=",
"from_qvariant",
"(",
"action",
".",
"data",
"(",
")",
",",
"to_text_string",
")",
"from",
"spyder",
".",
"plugins",
".",
"editor",
".",
"widgets",
".",
"editor",
"import",
"TextEditBaseWidget",
"from",
"spyder",
".",
"plugins",
".",
"ipythonconsole",
".",
"widgets",
"import",
"ControlWidget",
"if",
"isinstance",
"(",
"widget",
",",
"(",
"TextEditBaseWidget",
",",
"ControlWidget",
")",
")",
":",
"getattr",
"(",
"widget",
",",
"callback",
")",
"(",
")",
"else",
":",
"return"
] | Global callback | [
"Global",
"callback"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2692-L2703 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.open_external_console | def open_external_console(self, fname, wdir, args, interact, debug, python,
python_args, systerm, post_mortem=False):
"""Open external console"""
if systerm:
# Running script in an external system terminal
try:
if CONF.get('main_interpreter', 'default'):
executable = get_python_executable()
else:
executable = CONF.get('main_interpreter', 'executable')
programs.run_python_script_in_terminal(
fname, wdir, args, interact, debug, python_args,
executable)
except NotImplementedError:
QMessageBox.critical(self, _("Run"),
_("Running an external system terminal "
"is not supported on platform %s."
) % os.name) | python | def open_external_console(self, fname, wdir, args, interact, debug, python,
python_args, systerm, post_mortem=False):
"""Open external console"""
if systerm:
# Running script in an external system terminal
try:
if CONF.get('main_interpreter', 'default'):
executable = get_python_executable()
else:
executable = CONF.get('main_interpreter', 'executable')
programs.run_python_script_in_terminal(
fname, wdir, args, interact, debug, python_args,
executable)
except NotImplementedError:
QMessageBox.critical(self, _("Run"),
_("Running an external system terminal "
"is not supported on platform %s."
) % os.name) | [
"def",
"open_external_console",
"(",
"self",
",",
"fname",
",",
"wdir",
",",
"args",
",",
"interact",
",",
"debug",
",",
"python",
",",
"python_args",
",",
"systerm",
",",
"post_mortem",
"=",
"False",
")",
":",
"if",
"systerm",
":",
"# Running script in an external system terminal\r",
"try",
":",
"if",
"CONF",
".",
"get",
"(",
"'main_interpreter'",
",",
"'default'",
")",
":",
"executable",
"=",
"get_python_executable",
"(",
")",
"else",
":",
"executable",
"=",
"CONF",
".",
"get",
"(",
"'main_interpreter'",
",",
"'executable'",
")",
"programs",
".",
"run_python_script_in_terminal",
"(",
"fname",
",",
"wdir",
",",
"args",
",",
"interact",
",",
"debug",
",",
"python_args",
",",
"executable",
")",
"except",
"NotImplementedError",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"\"Run\"",
")",
",",
"_",
"(",
"\"Running an external system terminal \"",
"\"is not supported on platform %s.\"",
")",
"%",
"os",
".",
"name",
")"
] | Open external console | [
"Open",
"external",
"console"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2711-L2728 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.execute_in_external_console | def execute_in_external_console(self, lines, focus_to_editor):
"""
Execute lines in IPython console and eventually set focus
to the Editor.
"""
console = self.ipyconsole
console.switch_to_plugin()
console.execute_code(lines)
if focus_to_editor:
self.editor.switch_to_plugin() | python | def execute_in_external_console(self, lines, focus_to_editor):
"""
Execute lines in IPython console and eventually set focus
to the Editor.
"""
console = self.ipyconsole
console.switch_to_plugin()
console.execute_code(lines)
if focus_to_editor:
self.editor.switch_to_plugin() | [
"def",
"execute_in_external_console",
"(",
"self",
",",
"lines",
",",
"focus_to_editor",
")",
":",
"console",
"=",
"self",
".",
"ipyconsole",
"console",
".",
"switch_to_plugin",
"(",
")",
"console",
".",
"execute_code",
"(",
"lines",
")",
"if",
"focus_to_editor",
":",
"self",
".",
"editor",
".",
"switch_to_plugin",
"(",
")"
] | Execute lines in IPython console and eventually set focus
to the Editor. | [
"Execute",
"lines",
"in",
"IPython",
"console",
"and",
"eventually",
"set",
"focus",
"to",
"the",
"Editor",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2730-L2739 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.open_file | def open_file(self, fname, external=False):
"""
Open filename with the appropriate application
Redirect to the right widget (txt -> editor, spydata -> workspace, ...)
or open file outside Spyder (if extension is not supported)
"""
fname = to_text_string(fname)
ext = osp.splitext(fname)[1]
if encoding.is_text_file(fname):
self.editor.load(fname)
elif self.variableexplorer is not None and ext in IMPORT_EXT:
self.variableexplorer.import_data(fname)
elif not external:
fname = file_uri(fname)
programs.start_file(fname) | python | def open_file(self, fname, external=False):
"""
Open filename with the appropriate application
Redirect to the right widget (txt -> editor, spydata -> workspace, ...)
or open file outside Spyder (if extension is not supported)
"""
fname = to_text_string(fname)
ext = osp.splitext(fname)[1]
if encoding.is_text_file(fname):
self.editor.load(fname)
elif self.variableexplorer is not None and ext in IMPORT_EXT:
self.variableexplorer.import_data(fname)
elif not external:
fname = file_uri(fname)
programs.start_file(fname) | [
"def",
"open_file",
"(",
"self",
",",
"fname",
",",
"external",
"=",
"False",
")",
":",
"fname",
"=",
"to_text_string",
"(",
"fname",
")",
"ext",
"=",
"osp",
".",
"splitext",
"(",
"fname",
")",
"[",
"1",
"]",
"if",
"encoding",
".",
"is_text_file",
"(",
"fname",
")",
":",
"self",
".",
"editor",
".",
"load",
"(",
"fname",
")",
"elif",
"self",
".",
"variableexplorer",
"is",
"not",
"None",
"and",
"ext",
"in",
"IMPORT_EXT",
":",
"self",
".",
"variableexplorer",
".",
"import_data",
"(",
"fname",
")",
"elif",
"not",
"external",
":",
"fname",
"=",
"file_uri",
"(",
"fname",
")",
"programs",
".",
"start_file",
"(",
"fname",
")"
] | Open filename with the appropriate application
Redirect to the right widget (txt -> editor, spydata -> workspace, ...)
or open file outside Spyder (if extension is not supported) | [
"Open",
"filename",
"with",
"the",
"appropriate",
"application",
"Redirect",
"to",
"the",
"right",
"widget",
"(",
"txt",
"-",
">",
"editor",
"spydata",
"-",
">",
"workspace",
"...",
")",
"or",
"open",
"file",
"outside",
"Spyder",
"(",
"if",
"extension",
"is",
"not",
"supported",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2741-L2755 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.open_external_file | def open_external_file(self, fname):
"""
Open external files that can be handled either by the Editor or the
variable explorer inside Spyder.
"""
fname = encoding.to_unicode_from_fs(fname)
if osp.isfile(fname):
self.open_file(fname, external=True)
elif osp.isfile(osp.join(CWD, fname)):
self.open_file(osp.join(CWD, fname), external=True) | python | def open_external_file(self, fname):
"""
Open external files that can be handled either by the Editor or the
variable explorer inside Spyder.
"""
fname = encoding.to_unicode_from_fs(fname)
if osp.isfile(fname):
self.open_file(fname, external=True)
elif osp.isfile(osp.join(CWD, fname)):
self.open_file(osp.join(CWD, fname), external=True) | [
"def",
"open_external_file",
"(",
"self",
",",
"fname",
")",
":",
"fname",
"=",
"encoding",
".",
"to_unicode_from_fs",
"(",
"fname",
")",
"if",
"osp",
".",
"isfile",
"(",
"fname",
")",
":",
"self",
".",
"open_file",
"(",
"fname",
",",
"external",
"=",
"True",
")",
"elif",
"osp",
".",
"isfile",
"(",
"osp",
".",
"join",
"(",
"CWD",
",",
"fname",
")",
")",
":",
"self",
".",
"open_file",
"(",
"osp",
".",
"join",
"(",
"CWD",
",",
"fname",
")",
",",
"external",
"=",
"True",
")"
] | Open external files that can be handled either by the Editor or the
variable explorer inside Spyder. | [
"Open",
"external",
"files",
"that",
"can",
"be",
"handled",
"either",
"by",
"the",
"Editor",
"or",
"the",
"variable",
"explorer",
"inside",
"Spyder",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2757-L2766 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.get_spyder_pythonpath | def get_spyder_pythonpath(self):
"""Return Spyder PYTHONPATH"""
active_path = [p for p in self.path if p not in self.not_active_path]
return active_path + self.project_path | python | def get_spyder_pythonpath(self):
"""Return Spyder PYTHONPATH"""
active_path = [p for p in self.path if p not in self.not_active_path]
return active_path + self.project_path | [
"def",
"get_spyder_pythonpath",
"(",
"self",
")",
":",
"active_path",
"=",
"[",
"p",
"for",
"p",
"in",
"self",
".",
"path",
"if",
"p",
"not",
"in",
"self",
".",
"not_active_path",
"]",
"return",
"active_path",
"+",
"self",
".",
"project_path"
] | Return Spyder PYTHONPATH | [
"Return",
"Spyder",
"PYTHONPATH"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2769-L2772 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.add_path_to_sys_path | def add_path_to_sys_path(self):
"""Add Spyder path to sys.path"""
for path in reversed(self.get_spyder_pythonpath()):
sys.path.insert(1, path) | python | def add_path_to_sys_path(self):
"""Add Spyder path to sys.path"""
for path in reversed(self.get_spyder_pythonpath()):
sys.path.insert(1, path) | [
"def",
"add_path_to_sys_path",
"(",
"self",
")",
":",
"for",
"path",
"in",
"reversed",
"(",
"self",
".",
"get_spyder_pythonpath",
"(",
")",
")",
":",
"sys",
".",
"path",
".",
"insert",
"(",
"1",
",",
"path",
")"
] | Add Spyder path to sys.path | [
"Add",
"Spyder",
"path",
"to",
"sys",
".",
"path"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2774-L2777 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.remove_path_from_sys_path | def remove_path_from_sys_path(self):
"""Remove Spyder path from sys.path"""
for path in self.path + self.project_path:
while path in sys.path:
sys.path.remove(path) | python | def remove_path_from_sys_path(self):
"""Remove Spyder path from sys.path"""
for path in self.path + self.project_path:
while path in sys.path:
sys.path.remove(path) | [
"def",
"remove_path_from_sys_path",
"(",
"self",
")",
":",
"for",
"path",
"in",
"self",
".",
"path",
"+",
"self",
".",
"project_path",
":",
"while",
"path",
"in",
"sys",
".",
"path",
":",
"sys",
".",
"path",
".",
"remove",
"(",
"path",
")"
] | Remove Spyder path from sys.path | [
"Remove",
"Spyder",
"path",
"from",
"sys",
".",
"path"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2779-L2783 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.path_manager_callback | def path_manager_callback(self):
"""Spyder path manager"""
from spyder.widgets.pathmanager import PathManager
self.remove_path_from_sys_path()
project_path = self.projects.get_pythonpath()
dialog = PathManager(self, self.path, project_path,
self.not_active_path, sync=True)
dialog.redirect_stdio.connect(self.redirect_internalshell_stdio)
dialog.exec_()
self.add_path_to_sys_path()
try:
encoding.writelines(self.path, self.SPYDER_PATH) # Saving path
encoding.writelines(self.not_active_path,
self.SPYDER_NOT_ACTIVE_PATH)
except EnvironmentError:
pass
self.sig_pythonpath_changed.emit() | python | def path_manager_callback(self):
"""Spyder path manager"""
from spyder.widgets.pathmanager import PathManager
self.remove_path_from_sys_path()
project_path = self.projects.get_pythonpath()
dialog = PathManager(self, self.path, project_path,
self.not_active_path, sync=True)
dialog.redirect_stdio.connect(self.redirect_internalshell_stdio)
dialog.exec_()
self.add_path_to_sys_path()
try:
encoding.writelines(self.path, self.SPYDER_PATH) # Saving path
encoding.writelines(self.not_active_path,
self.SPYDER_NOT_ACTIVE_PATH)
except EnvironmentError:
pass
self.sig_pythonpath_changed.emit() | [
"def",
"path_manager_callback",
"(",
"self",
")",
":",
"from",
"spyder",
".",
"widgets",
".",
"pathmanager",
"import",
"PathManager",
"self",
".",
"remove_path_from_sys_path",
"(",
")",
"project_path",
"=",
"self",
".",
"projects",
".",
"get_pythonpath",
"(",
")",
"dialog",
"=",
"PathManager",
"(",
"self",
",",
"self",
".",
"path",
",",
"project_path",
",",
"self",
".",
"not_active_path",
",",
"sync",
"=",
"True",
")",
"dialog",
".",
"redirect_stdio",
".",
"connect",
"(",
"self",
".",
"redirect_internalshell_stdio",
")",
"dialog",
".",
"exec_",
"(",
")",
"self",
".",
"add_path_to_sys_path",
"(",
")",
"try",
":",
"encoding",
".",
"writelines",
"(",
"self",
".",
"path",
",",
"self",
".",
"SPYDER_PATH",
")",
"# Saving path\r",
"encoding",
".",
"writelines",
"(",
"self",
".",
"not_active_path",
",",
"self",
".",
"SPYDER_NOT_ACTIVE_PATH",
")",
"except",
"EnvironmentError",
":",
"pass",
"self",
".",
"sig_pythonpath_changed",
".",
"emit",
"(",
")"
] | Spyder path manager | [
"Spyder",
"path",
"manager"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2786-L2802 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.pythonpath_changed | def pythonpath_changed(self):
"""Projects PYTHONPATH contribution has changed"""
self.remove_path_from_sys_path()
self.project_path = self.projects.get_pythonpath()
self.add_path_to_sys_path()
self.sig_pythonpath_changed.emit() | python | def pythonpath_changed(self):
"""Projects PYTHONPATH contribution has changed"""
self.remove_path_from_sys_path()
self.project_path = self.projects.get_pythonpath()
self.add_path_to_sys_path()
self.sig_pythonpath_changed.emit() | [
"def",
"pythonpath_changed",
"(",
"self",
")",
":",
"self",
".",
"remove_path_from_sys_path",
"(",
")",
"self",
".",
"project_path",
"=",
"self",
".",
"projects",
".",
"get_pythonpath",
"(",
")",
"self",
".",
"add_path_to_sys_path",
"(",
")",
"self",
".",
"sig_pythonpath_changed",
".",
"emit",
"(",
")"
] | Projects PYTHONPATH contribution has changed | [
"Projects",
"PYTHONPATH",
"contribution",
"has",
"changed"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2804-L2809 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.apply_settings | 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:
style_name = CONF.get('appearance', 'windows_style',
self.default_style)
style = QStyleFactory.create(style_name)
if style is not None:
style.setProperty('name', style_name)
qapp.setStyle(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_cursor_blinking'):
qapp.setCursorFlashTime(CONF.get('main', 'custom_cursor_blinking'))
else:
qapp.setCursorFlashTime(self.CURSORBLINK_OSDEFAULT) | python | 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:
style_name = CONF.get('appearance', 'windows_style',
self.default_style)
style = QStyleFactory.create(style_name)
if style is not None:
style.setProperty('name', style_name)
qapp.setStyle(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_cursor_blinking'):
qapp.setCursorFlashTime(CONF.get('main', 'custom_cursor_blinking'))
else:
qapp.setCursorFlashTime(self.CURSORBLINK_OSDEFAULT) | [
"def",
"apply_settings",
"(",
"self",
")",
":",
"qapp",
"=",
"QApplication",
".",
"instance",
"(",
")",
"# Set 'gtk+' as the default theme in Gtk-based desktops\r",
"# Fixes Issue 2036\r",
"if",
"is_gtk_desktop",
"(",
")",
"and",
"(",
"'GTK+'",
"in",
"QStyleFactory",
".",
"keys",
"(",
")",
")",
":",
"try",
":",
"qapp",
".",
"setStyle",
"(",
"'gtk+'",
")",
"except",
":",
"pass",
"else",
":",
"style_name",
"=",
"CONF",
".",
"get",
"(",
"'appearance'",
",",
"'windows_style'",
",",
"self",
".",
"default_style",
")",
"style",
"=",
"QStyleFactory",
".",
"create",
"(",
"style_name",
")",
"if",
"style",
"is",
"not",
"None",
":",
"style",
".",
"setProperty",
"(",
"'name'",
",",
"style_name",
")",
"qapp",
".",
"setStyle",
"(",
"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_cursor_blinking'",
")",
":",
"qapp",
".",
"setCursorFlashTime",
"(",
"CONF",
".",
"get",
"(",
"'main'",
",",
"'custom_cursor_blinking'",
")",
")",
"else",
":",
"qapp",
".",
"setCursorFlashTime",
"(",
"self",
".",
"CURSORBLINK_OSDEFAULT",
")"
] | Apply settings changed in 'Preferences' dialog box | [
"Apply",
"settings",
"changed",
"in",
"Preferences",
"dialog",
"box"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2817-L2848 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.apply_panes_settings | def apply_panes_settings(self):
"""Update dockwidgets features settings"""
for plugin in (self.widgetlist + self.thirdparty_plugins):
features = plugin.FEATURES
if CONF.get('main', 'vertical_dockwidget_titlebars'):
features = features | QDockWidget.DockWidgetVerticalTitleBar
plugin.dockwidget.setFeatures(features)
plugin.update_margins() | python | def apply_panes_settings(self):
"""Update dockwidgets features settings"""
for plugin in (self.widgetlist + self.thirdparty_plugins):
features = plugin.FEATURES
if CONF.get('main', 'vertical_dockwidget_titlebars'):
features = features | QDockWidget.DockWidgetVerticalTitleBar
plugin.dockwidget.setFeatures(features)
plugin.update_margins() | [
"def",
"apply_panes_settings",
"(",
"self",
")",
":",
"for",
"plugin",
"in",
"(",
"self",
".",
"widgetlist",
"+",
"self",
".",
"thirdparty_plugins",
")",
":",
"features",
"=",
"plugin",
".",
"FEATURES",
"if",
"CONF",
".",
"get",
"(",
"'main'",
",",
"'vertical_dockwidget_titlebars'",
")",
":",
"features",
"=",
"features",
"|",
"QDockWidget",
".",
"DockWidgetVerticalTitleBar",
"plugin",
".",
"dockwidget",
".",
"setFeatures",
"(",
"features",
")",
"plugin",
".",
"update_margins",
"(",
")"
] | Update dockwidgets features settings | [
"Update",
"dockwidgets",
"features",
"settings"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2850-L2857 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.apply_statusbar_settings | 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 | python | 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",
"apply_statusbar_settings",
"(",
"self",
")",
":",
"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"
] | Update status bar widgets settings | [
"Update",
"status",
"bar",
"widgets",
"settings"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2859-L2871 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.edit_preferences | def edit_preferences(self):
"""Edit Spyder preferences"""
from spyder.preferences.configdialog import ConfigDialog
dlg = ConfigDialog(self)
dlg.size_change.connect(self.set_prefs_size)
if self.prefs_dialog_size is not None:
dlg.resize(self.prefs_dialog_size)
for PrefPageClass in self.general_prefs:
widget = PrefPageClass(dlg, main=self)
widget.initialize()
dlg.add_page(widget)
for plugin in [self.workingdirectory, self.editor,
self.projects, self.ipyconsole,
self.historylog, self.help, self.variableexplorer,
self.onlinehelp, self.explorer, self.findinfiles
]+self.thirdparty_plugins:
if plugin is not None:
try:
widget = plugin.create_configwidget(dlg)
if widget is not None:
dlg.add_page(widget)
except Exception:
traceback.print_exc(file=sys.stderr)
if self.prefs_index is not None:
dlg.set_current_index(self.prefs_index)
dlg.show()
dlg.check_all_settings()
dlg.pages_widget.currentChanged.connect(self.__preference_page_changed)
dlg.exec_() | python | def edit_preferences(self):
"""Edit Spyder preferences"""
from spyder.preferences.configdialog import ConfigDialog
dlg = ConfigDialog(self)
dlg.size_change.connect(self.set_prefs_size)
if self.prefs_dialog_size is not None:
dlg.resize(self.prefs_dialog_size)
for PrefPageClass in self.general_prefs:
widget = PrefPageClass(dlg, main=self)
widget.initialize()
dlg.add_page(widget)
for plugin in [self.workingdirectory, self.editor,
self.projects, self.ipyconsole,
self.historylog, self.help, self.variableexplorer,
self.onlinehelp, self.explorer, self.findinfiles
]+self.thirdparty_plugins:
if plugin is not None:
try:
widget = plugin.create_configwidget(dlg)
if widget is not None:
dlg.add_page(widget)
except Exception:
traceback.print_exc(file=sys.stderr)
if self.prefs_index is not None:
dlg.set_current_index(self.prefs_index)
dlg.show()
dlg.check_all_settings()
dlg.pages_widget.currentChanged.connect(self.__preference_page_changed)
dlg.exec_() | [
"def",
"edit_preferences",
"(",
"self",
")",
":",
"from",
"spyder",
".",
"preferences",
".",
"configdialog",
"import",
"ConfigDialog",
"dlg",
"=",
"ConfigDialog",
"(",
"self",
")",
"dlg",
".",
"size_change",
".",
"connect",
"(",
"self",
".",
"set_prefs_size",
")",
"if",
"self",
".",
"prefs_dialog_size",
"is",
"not",
"None",
":",
"dlg",
".",
"resize",
"(",
"self",
".",
"prefs_dialog_size",
")",
"for",
"PrefPageClass",
"in",
"self",
".",
"general_prefs",
":",
"widget",
"=",
"PrefPageClass",
"(",
"dlg",
",",
"main",
"=",
"self",
")",
"widget",
".",
"initialize",
"(",
")",
"dlg",
".",
"add_page",
"(",
"widget",
")",
"for",
"plugin",
"in",
"[",
"self",
".",
"workingdirectory",
",",
"self",
".",
"editor",
",",
"self",
".",
"projects",
",",
"self",
".",
"ipyconsole",
",",
"self",
".",
"historylog",
",",
"self",
".",
"help",
",",
"self",
".",
"variableexplorer",
",",
"self",
".",
"onlinehelp",
",",
"self",
".",
"explorer",
",",
"self",
".",
"findinfiles",
"]",
"+",
"self",
".",
"thirdparty_plugins",
":",
"if",
"plugin",
"is",
"not",
"None",
":",
"try",
":",
"widget",
"=",
"plugin",
".",
"create_configwidget",
"(",
"dlg",
")",
"if",
"widget",
"is",
"not",
"None",
":",
"dlg",
".",
"add_page",
"(",
"widget",
")",
"except",
"Exception",
":",
"traceback",
".",
"print_exc",
"(",
"file",
"=",
"sys",
".",
"stderr",
")",
"if",
"self",
".",
"prefs_index",
"is",
"not",
"None",
":",
"dlg",
".",
"set_current_index",
"(",
"self",
".",
"prefs_index",
")",
"dlg",
".",
"show",
"(",
")",
"dlg",
".",
"check_all_settings",
"(",
")",
"dlg",
".",
"pages_widget",
".",
"currentChanged",
".",
"connect",
"(",
"self",
".",
"__preference_page_changed",
")",
"dlg",
".",
"exec_",
"(",
")"
] | Edit Spyder preferences | [
"Edit",
"Spyder",
"preferences"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2874-L2902 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.register_shortcut | def register_shortcut(self, qaction_or_qshortcut, context, name,
add_sc_to_tip=False):
"""
Register QAction or QShortcut to Spyder main application,
with shortcut (context, name, default)
"""
self.shortcut_data.append( (qaction_or_qshortcut, context,
name, add_sc_to_tip) ) | python | def register_shortcut(self, qaction_or_qshortcut, context, name,
add_sc_to_tip=False):
"""
Register QAction or QShortcut to Spyder main application,
with shortcut (context, name, default)
"""
self.shortcut_data.append( (qaction_or_qshortcut, context,
name, add_sc_to_tip) ) | [
"def",
"register_shortcut",
"(",
"self",
",",
"qaction_or_qshortcut",
",",
"context",
",",
"name",
",",
"add_sc_to_tip",
"=",
"False",
")",
":",
"self",
".",
"shortcut_data",
".",
"append",
"(",
"(",
"qaction_or_qshortcut",
",",
"context",
",",
"name",
",",
"add_sc_to_tip",
")",
")"
] | Register QAction or QShortcut to Spyder main application,
with shortcut (context, name, default) | [
"Register",
"QAction",
"or",
"QShortcut",
"to",
"Spyder",
"main",
"application",
"with",
"shortcut",
"(",
"context",
"name",
"default",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2913-L2920 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.apply_shortcuts | def apply_shortcuts(self):
"""Apply shortcuts settings to all widgets/plugins"""
toberemoved = []
for index, (qobject, context, name,
add_sc_to_tip) in enumerate(self.shortcut_data):
keyseq = QKeySequence( get_shortcut(context, name) )
try:
if isinstance(qobject, QAction):
if sys.platform == 'darwin' and \
qobject._shown_shortcut == 'missing':
qobject._shown_shortcut = keyseq
else:
qobject.setShortcut(keyseq)
if add_sc_to_tip:
add_shortcut_to_tooltip(qobject, context, name)
elif isinstance(qobject, QShortcut):
qobject.setKey(keyseq)
except RuntimeError:
# Object has been deleted
toberemoved.append(index)
for index in sorted(toberemoved, reverse=True):
self.shortcut_data.pop(index) | python | def apply_shortcuts(self):
"""Apply shortcuts settings to all widgets/plugins"""
toberemoved = []
for index, (qobject, context, name,
add_sc_to_tip) in enumerate(self.shortcut_data):
keyseq = QKeySequence( get_shortcut(context, name) )
try:
if isinstance(qobject, QAction):
if sys.platform == 'darwin' and \
qobject._shown_shortcut == 'missing':
qobject._shown_shortcut = keyseq
else:
qobject.setShortcut(keyseq)
if add_sc_to_tip:
add_shortcut_to_tooltip(qobject, context, name)
elif isinstance(qobject, QShortcut):
qobject.setKey(keyseq)
except RuntimeError:
# Object has been deleted
toberemoved.append(index)
for index in sorted(toberemoved, reverse=True):
self.shortcut_data.pop(index) | [
"def",
"apply_shortcuts",
"(",
"self",
")",
":",
"toberemoved",
"=",
"[",
"]",
"for",
"index",
",",
"(",
"qobject",
",",
"context",
",",
"name",
",",
"add_sc_to_tip",
")",
"in",
"enumerate",
"(",
"self",
".",
"shortcut_data",
")",
":",
"keyseq",
"=",
"QKeySequence",
"(",
"get_shortcut",
"(",
"context",
",",
"name",
")",
")",
"try",
":",
"if",
"isinstance",
"(",
"qobject",
",",
"QAction",
")",
":",
"if",
"sys",
".",
"platform",
"==",
"'darwin'",
"and",
"qobject",
".",
"_shown_shortcut",
"==",
"'missing'",
":",
"qobject",
".",
"_shown_shortcut",
"=",
"keyseq",
"else",
":",
"qobject",
".",
"setShortcut",
"(",
"keyseq",
")",
"if",
"add_sc_to_tip",
":",
"add_shortcut_to_tooltip",
"(",
"qobject",
",",
"context",
",",
"name",
")",
"elif",
"isinstance",
"(",
"qobject",
",",
"QShortcut",
")",
":",
"qobject",
".",
"setKey",
"(",
"keyseq",
")",
"except",
"RuntimeError",
":",
"# Object has been deleted\r",
"toberemoved",
".",
"append",
"(",
"index",
")",
"for",
"index",
"in",
"sorted",
"(",
"toberemoved",
",",
"reverse",
"=",
"True",
")",
":",
"self",
".",
"shortcut_data",
".",
"pop",
"(",
"index",
")"
] | Apply shortcuts settings to all widgets/plugins | [
"Apply",
"shortcuts",
"settings",
"to",
"all",
"widgets",
"/",
"plugins"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2922-L2943 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.reset_spyder | def reset_spyder(self):
"""
Quit and reset Spyder and then Restart application.
"""
answer = QMessageBox.warning(self, _("Warning"),
_("Spyder will restart and reset to default settings: <br><br>"
"Do you want to continue?"),
QMessageBox.Yes | QMessageBox.No)
if answer == QMessageBox.Yes:
self.restart(reset=True) | python | def reset_spyder(self):
"""
Quit and reset Spyder and then Restart application.
"""
answer = QMessageBox.warning(self, _("Warning"),
_("Spyder will restart and reset to default settings: <br><br>"
"Do you want to continue?"),
QMessageBox.Yes | QMessageBox.No)
if answer == QMessageBox.Yes:
self.restart(reset=True) | [
"def",
"reset_spyder",
"(",
"self",
")",
":",
"answer",
"=",
"QMessageBox",
".",
"warning",
"(",
"self",
",",
"_",
"(",
"\"Warning\"",
")",
",",
"_",
"(",
"\"Spyder will restart and reset to default settings: <br><br>\"",
"\"Do you want to continue?\"",
")",
",",
"QMessageBox",
".",
"Yes",
"|",
"QMessageBox",
".",
"No",
")",
"if",
"answer",
"==",
"QMessageBox",
".",
"Yes",
":",
"self",
".",
"restart",
"(",
"reset",
"=",
"True",
")"
] | Quit and reset Spyder and then Restart application. | [
"Quit",
"and",
"reset",
"Spyder",
"and",
"then",
"Restart",
"application",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2982-L2991 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.restart | def restart(self, reset=False):
"""
Quit and Restart Spyder application.
If reset True it allows to reset spyder on restart.
"""
# Get start path to use in restart script
spyder_start_directory = get_module_path('spyder')
restart_script = osp.join(spyder_start_directory, 'app', 'restart.py')
# Get any initial argument passed when spyder was started
# Note: Variables defined in bootstrap.py and spyder/app/start.py
env = os.environ.copy()
bootstrap_args = env.pop('SPYDER_BOOTSTRAP_ARGS', None)
spyder_args = env.pop('SPYDER_ARGS')
# Get current process and python running spyder
pid = os.getpid()
python = sys.executable
# Check if started with bootstrap.py
if bootstrap_args is not None:
spyder_args = bootstrap_args
is_bootstrap = True
else:
is_bootstrap = False
# Pass variables as environment variables (str) to restarter subprocess
env['SPYDER_ARGS'] = spyder_args
env['SPYDER_PID'] = str(pid)
env['SPYDER_IS_BOOTSTRAP'] = str(is_bootstrap)
env['SPYDER_RESET'] = str(reset)
if DEV:
if os.name == 'nt':
env['PYTHONPATH'] = ';'.join(sys.path)
else:
env['PYTHONPATH'] = ':'.join(sys.path)
# Build the command and popen arguments depending on the OS
if os.name == 'nt':
# Hide flashing command prompt
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
shell = False
else:
startupinfo = None
shell = True
command = '"{0}" "{1}"'
command = command.format(python, restart_script)
try:
if self.closing(True):
subprocess.Popen(command, shell=shell, env=env,
startupinfo=startupinfo)
self.console.quit()
except Exception as error:
# If there is an error with subprocess, Spyder should not quit and
# the error can be inspected in the internal console
print(error) # spyder: test-skip
print(command) | python | def restart(self, reset=False):
"""
Quit and Restart Spyder application.
If reset True it allows to reset spyder on restart.
"""
# Get start path to use in restart script
spyder_start_directory = get_module_path('spyder')
restart_script = osp.join(spyder_start_directory, 'app', 'restart.py')
# Get any initial argument passed when spyder was started
# Note: Variables defined in bootstrap.py and spyder/app/start.py
env = os.environ.copy()
bootstrap_args = env.pop('SPYDER_BOOTSTRAP_ARGS', None)
spyder_args = env.pop('SPYDER_ARGS')
# Get current process and python running spyder
pid = os.getpid()
python = sys.executable
# Check if started with bootstrap.py
if bootstrap_args is not None:
spyder_args = bootstrap_args
is_bootstrap = True
else:
is_bootstrap = False
# Pass variables as environment variables (str) to restarter subprocess
env['SPYDER_ARGS'] = spyder_args
env['SPYDER_PID'] = str(pid)
env['SPYDER_IS_BOOTSTRAP'] = str(is_bootstrap)
env['SPYDER_RESET'] = str(reset)
if DEV:
if os.name == 'nt':
env['PYTHONPATH'] = ';'.join(sys.path)
else:
env['PYTHONPATH'] = ':'.join(sys.path)
# Build the command and popen arguments depending on the OS
if os.name == 'nt':
# Hide flashing command prompt
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
shell = False
else:
startupinfo = None
shell = True
command = '"{0}" "{1}"'
command = command.format(python, restart_script)
try:
if self.closing(True):
subprocess.Popen(command, shell=shell, env=env,
startupinfo=startupinfo)
self.console.quit()
except Exception as error:
# If there is an error with subprocess, Spyder should not quit and
# the error can be inspected in the internal console
print(error) # spyder: test-skip
print(command) | [
"def",
"restart",
"(",
"self",
",",
"reset",
"=",
"False",
")",
":",
"# Get start path to use in restart script\r",
"spyder_start_directory",
"=",
"get_module_path",
"(",
"'spyder'",
")",
"restart_script",
"=",
"osp",
".",
"join",
"(",
"spyder_start_directory",
",",
"'app'",
",",
"'restart.py'",
")",
"# Get any initial argument passed when spyder was started\r",
"# Note: Variables defined in bootstrap.py and spyder/app/start.py\r",
"env",
"=",
"os",
".",
"environ",
".",
"copy",
"(",
")",
"bootstrap_args",
"=",
"env",
".",
"pop",
"(",
"'SPYDER_BOOTSTRAP_ARGS'",
",",
"None",
")",
"spyder_args",
"=",
"env",
".",
"pop",
"(",
"'SPYDER_ARGS'",
")",
"# Get current process and python running spyder\r",
"pid",
"=",
"os",
".",
"getpid",
"(",
")",
"python",
"=",
"sys",
".",
"executable",
"# Check if started with bootstrap.py\r",
"if",
"bootstrap_args",
"is",
"not",
"None",
":",
"spyder_args",
"=",
"bootstrap_args",
"is_bootstrap",
"=",
"True",
"else",
":",
"is_bootstrap",
"=",
"False",
"# Pass variables as environment variables (str) to restarter subprocess\r",
"env",
"[",
"'SPYDER_ARGS'",
"]",
"=",
"spyder_args",
"env",
"[",
"'SPYDER_PID'",
"]",
"=",
"str",
"(",
"pid",
")",
"env",
"[",
"'SPYDER_IS_BOOTSTRAP'",
"]",
"=",
"str",
"(",
"is_bootstrap",
")",
"env",
"[",
"'SPYDER_RESET'",
"]",
"=",
"str",
"(",
"reset",
")",
"if",
"DEV",
":",
"if",
"os",
".",
"name",
"==",
"'nt'",
":",
"env",
"[",
"'PYTHONPATH'",
"]",
"=",
"';'",
".",
"join",
"(",
"sys",
".",
"path",
")",
"else",
":",
"env",
"[",
"'PYTHONPATH'",
"]",
"=",
"':'",
".",
"join",
"(",
"sys",
".",
"path",
")",
"# Build the command and popen arguments depending on the OS\r",
"if",
"os",
".",
"name",
"==",
"'nt'",
":",
"# Hide flashing command prompt\r",
"startupinfo",
"=",
"subprocess",
".",
"STARTUPINFO",
"(",
")",
"startupinfo",
".",
"dwFlags",
"|=",
"subprocess",
".",
"STARTF_USESHOWWINDOW",
"shell",
"=",
"False",
"else",
":",
"startupinfo",
"=",
"None",
"shell",
"=",
"True",
"command",
"=",
"'\"{0}\" \"{1}\"'",
"command",
"=",
"command",
".",
"format",
"(",
"python",
",",
"restart_script",
")",
"try",
":",
"if",
"self",
".",
"closing",
"(",
"True",
")",
":",
"subprocess",
".",
"Popen",
"(",
"command",
",",
"shell",
"=",
"shell",
",",
"env",
"=",
"env",
",",
"startupinfo",
"=",
"startupinfo",
")",
"self",
".",
"console",
".",
"quit",
"(",
")",
"except",
"Exception",
"as",
"error",
":",
"# If there is an error with subprocess, Spyder should not quit and\r",
"# the error can be inspected in the internal console\r",
"print",
"(",
"error",
")",
"# spyder: test-skip\r",
"print",
"(",
"command",
")"
] | Quit and Restart Spyder application.
If reset True it allows to reset spyder on restart. | [
"Quit",
"and",
"Restart",
"Spyder",
"application",
".",
"If",
"reset",
"True",
"it",
"allows",
"to",
"reset",
"spyder",
"on",
"restart",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2994-L3055 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.show_tour | def show_tour(self, index):
"""Show interactive tour."""
self.maximize_dockwidget(restore=True)
frames = self.tours_available[index]
self.tour.set_tour(index, frames, self)
self.tour.start_tour() | python | def show_tour(self, index):
"""Show interactive tour."""
self.maximize_dockwidget(restore=True)
frames = self.tours_available[index]
self.tour.set_tour(index, frames, self)
self.tour.start_tour() | [
"def",
"show_tour",
"(",
"self",
",",
"index",
")",
":",
"self",
".",
"maximize_dockwidget",
"(",
"restore",
"=",
"True",
")",
"frames",
"=",
"self",
".",
"tours_available",
"[",
"index",
"]",
"self",
".",
"tour",
".",
"set_tour",
"(",
"index",
",",
"frames",
",",
"self",
")",
"self",
".",
"tour",
".",
"start_tour",
"(",
")"
] | Show interactive tour. | [
"Show",
"interactive",
"tour",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L3058-L3063 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.open_fileswitcher | def open_fileswitcher(self, symbol=False):
"""Open file list management dialog box."""
if self.fileswitcher is not None and \
self.fileswitcher.is_visible:
self.fileswitcher.hide()
self.fileswitcher.is_visible = False
return
if symbol:
self.fileswitcher.plugin = self.editor
self.fileswitcher.set_search_text('@')
else:
self.fileswitcher.set_search_text('')
self.fileswitcher.show()
self.fileswitcher.is_visible = True | python | def open_fileswitcher(self, symbol=False):
"""Open file list management dialog box."""
if self.fileswitcher is not None and \
self.fileswitcher.is_visible:
self.fileswitcher.hide()
self.fileswitcher.is_visible = False
return
if symbol:
self.fileswitcher.plugin = self.editor
self.fileswitcher.set_search_text('@')
else:
self.fileswitcher.set_search_text('')
self.fileswitcher.show()
self.fileswitcher.is_visible = True | [
"def",
"open_fileswitcher",
"(",
"self",
",",
"symbol",
"=",
"False",
")",
":",
"if",
"self",
".",
"fileswitcher",
"is",
"not",
"None",
"and",
"self",
".",
"fileswitcher",
".",
"is_visible",
":",
"self",
".",
"fileswitcher",
".",
"hide",
"(",
")",
"self",
".",
"fileswitcher",
".",
"is_visible",
"=",
"False",
"return",
"if",
"symbol",
":",
"self",
".",
"fileswitcher",
".",
"plugin",
"=",
"self",
".",
"editor",
"self",
".",
"fileswitcher",
".",
"set_search_text",
"(",
"'@'",
")",
"else",
":",
"self",
".",
"fileswitcher",
".",
"set_search_text",
"(",
"''",
")",
"self",
".",
"fileswitcher",
".",
"show",
"(",
")",
"self",
".",
"fileswitcher",
".",
"is_visible",
"=",
"True"
] | Open file list management dialog box. | [
"Open",
"file",
"list",
"management",
"dialog",
"box",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L3066-L3079 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.add_to_fileswitcher | def add_to_fileswitcher(self, plugin, tabs, data, icon):
"""Add a plugin to the File Switcher."""
if self.fileswitcher is None:
from spyder.widgets.fileswitcher import FileSwitcher
self.fileswitcher = FileSwitcher(self, plugin, tabs, data, icon)
else:
self.fileswitcher.add_plugin(plugin, tabs, data, icon)
self.fileswitcher.sig_goto_file.connect(
plugin.get_current_tab_manager().set_stack_index) | python | def add_to_fileswitcher(self, plugin, tabs, data, icon):
"""Add a plugin to the File Switcher."""
if self.fileswitcher is None:
from spyder.widgets.fileswitcher import FileSwitcher
self.fileswitcher = FileSwitcher(self, plugin, tabs, data, icon)
else:
self.fileswitcher.add_plugin(plugin, tabs, data, icon)
self.fileswitcher.sig_goto_file.connect(
plugin.get_current_tab_manager().set_stack_index) | [
"def",
"add_to_fileswitcher",
"(",
"self",
",",
"plugin",
",",
"tabs",
",",
"data",
",",
"icon",
")",
":",
"if",
"self",
".",
"fileswitcher",
"is",
"None",
":",
"from",
"spyder",
".",
"widgets",
".",
"fileswitcher",
"import",
"FileSwitcher",
"self",
".",
"fileswitcher",
"=",
"FileSwitcher",
"(",
"self",
",",
"plugin",
",",
"tabs",
",",
"data",
",",
"icon",
")",
"else",
":",
"self",
".",
"fileswitcher",
".",
"add_plugin",
"(",
"plugin",
",",
"tabs",
",",
"data",
",",
"icon",
")",
"self",
".",
"fileswitcher",
".",
"sig_goto_file",
".",
"connect",
"(",
"plugin",
".",
"get_current_tab_manager",
"(",
")",
".",
"set_stack_index",
")"
] | Add a plugin to the File Switcher. | [
"Add",
"a",
"plugin",
"to",
"the",
"File",
"Switcher",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L3085-L3094 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow._check_updates_ready | def _check_updates_ready(self):
"""Called by WorkerUpdates when ready"""
from spyder.widgets.helperwidgets import MessageCheckBox
# feedback` = False is used on startup, so only positive feedback is
# given. `feedback` = True is used when after startup (when using the
# menu action, and gives feeback if updates are, or are not found.
feedback = self.give_updates_feedback
# Get results from worker
update_available = self.worker_updates.update_available
latest_release = self.worker_updates.latest_release
error_msg = self.worker_updates.error
url_r = __project_url__ + '/releases'
url_i = 'https://docs.spyder-ide.org/installation.html'
# Define the custom QMessageBox
box = MessageCheckBox(icon=QMessageBox.Information,
parent=self)
box.setWindowTitle(_("Spyder updates"))
box.set_checkbox_text(_("Check for updates on startup"))
box.setStandardButtons(QMessageBox.Ok)
box.setDefaultButton(QMessageBox.Ok)
# Adjust the checkbox depending on the stored configuration
section, option = 'main', 'check_updates_on_startup'
check_updates = CONF.get(section, option)
box.set_checked(check_updates)
if error_msg is not None:
msg = error_msg
box.setText(msg)
box.set_check_visible(False)
box.exec_()
check_updates = box.is_checked()
else:
if update_available:
anaconda_msg = ''
if 'Anaconda' in sys.version or 'conda-forge' in sys.version:
anaconda_msg = _("<hr><b>IMPORTANT NOTE:</b> It seems "
"that you are using Spyder with "
"<b>Anaconda/Miniconda</b>. Please "
"<b>don't</b> use <code>pip</code> to "
"update it as that will probably break "
"your installation.<br><br>"
"Instead, please wait until new conda "
"packages are available and use "
"<code>conda</code> to perform the "
"update.<hr>")
msg = _("<b>Spyder %s is available!</b> <br><br>Please use "
"your package manager to update Spyder or go to our "
"<a href=\"%s\">Releases</a> page to download this "
"new version. <br><br>If you are not sure how to "
"proceed to update Spyder please refer to our "
" <a href=\"%s\">Installation</a> instructions."
"") % (latest_release, url_r, url_i)
msg += '<br>' + anaconda_msg
box.setText(msg)
box.set_check_visible(True)
box.exec_()
check_updates = box.is_checked()
elif feedback:
msg = _("Spyder is up to date.")
box.setText(msg)
box.set_check_visible(False)
box.exec_()
check_updates = box.is_checked()
# Update checkbox based on user interaction
CONF.set(section, option, check_updates)
# Enable check_updates_action after the thread has finished
self.check_updates_action.setDisabled(False)
# Provide feeback when clicking menu if check on startup is on
self.give_updates_feedback = True | python | def _check_updates_ready(self):
"""Called by WorkerUpdates when ready"""
from spyder.widgets.helperwidgets import MessageCheckBox
# feedback` = False is used on startup, so only positive feedback is
# given. `feedback` = True is used when after startup (when using the
# menu action, and gives feeback if updates are, or are not found.
feedback = self.give_updates_feedback
# Get results from worker
update_available = self.worker_updates.update_available
latest_release = self.worker_updates.latest_release
error_msg = self.worker_updates.error
url_r = __project_url__ + '/releases'
url_i = 'https://docs.spyder-ide.org/installation.html'
# Define the custom QMessageBox
box = MessageCheckBox(icon=QMessageBox.Information,
parent=self)
box.setWindowTitle(_("Spyder updates"))
box.set_checkbox_text(_("Check for updates on startup"))
box.setStandardButtons(QMessageBox.Ok)
box.setDefaultButton(QMessageBox.Ok)
# Adjust the checkbox depending on the stored configuration
section, option = 'main', 'check_updates_on_startup'
check_updates = CONF.get(section, option)
box.set_checked(check_updates)
if error_msg is not None:
msg = error_msg
box.setText(msg)
box.set_check_visible(False)
box.exec_()
check_updates = box.is_checked()
else:
if update_available:
anaconda_msg = ''
if 'Anaconda' in sys.version or 'conda-forge' in sys.version:
anaconda_msg = _("<hr><b>IMPORTANT NOTE:</b> It seems "
"that you are using Spyder with "
"<b>Anaconda/Miniconda</b>. Please "
"<b>don't</b> use <code>pip</code> to "
"update it as that will probably break "
"your installation.<br><br>"
"Instead, please wait until new conda "
"packages are available and use "
"<code>conda</code> to perform the "
"update.<hr>")
msg = _("<b>Spyder %s is available!</b> <br><br>Please use "
"your package manager to update Spyder or go to our "
"<a href=\"%s\">Releases</a> page to download this "
"new version. <br><br>If you are not sure how to "
"proceed to update Spyder please refer to our "
" <a href=\"%s\">Installation</a> instructions."
"") % (latest_release, url_r, url_i)
msg += '<br>' + anaconda_msg
box.setText(msg)
box.set_check_visible(True)
box.exec_()
check_updates = box.is_checked()
elif feedback:
msg = _("Spyder is up to date.")
box.setText(msg)
box.set_check_visible(False)
box.exec_()
check_updates = box.is_checked()
# Update checkbox based on user interaction
CONF.set(section, option, check_updates)
# Enable check_updates_action after the thread has finished
self.check_updates_action.setDisabled(False)
# Provide feeback when clicking menu if check on startup is on
self.give_updates_feedback = True | [
"def",
"_check_updates_ready",
"(",
"self",
")",
":",
"from",
"spyder",
".",
"widgets",
".",
"helperwidgets",
"import",
"MessageCheckBox",
"# feedback` = False is used on startup, so only positive feedback is\r",
"# given. `feedback` = True is used when after startup (when using the\r",
"# menu action, and gives feeback if updates are, or are not found.\r",
"feedback",
"=",
"self",
".",
"give_updates_feedback",
"# Get results from worker\r",
"update_available",
"=",
"self",
".",
"worker_updates",
".",
"update_available",
"latest_release",
"=",
"self",
".",
"worker_updates",
".",
"latest_release",
"error_msg",
"=",
"self",
".",
"worker_updates",
".",
"error",
"url_r",
"=",
"__project_url__",
"+",
"'/releases'",
"url_i",
"=",
"'https://docs.spyder-ide.org/installation.html'",
"# Define the custom QMessageBox\r",
"box",
"=",
"MessageCheckBox",
"(",
"icon",
"=",
"QMessageBox",
".",
"Information",
",",
"parent",
"=",
"self",
")",
"box",
".",
"setWindowTitle",
"(",
"_",
"(",
"\"Spyder updates\"",
")",
")",
"box",
".",
"set_checkbox_text",
"(",
"_",
"(",
"\"Check for updates on startup\"",
")",
")",
"box",
".",
"setStandardButtons",
"(",
"QMessageBox",
".",
"Ok",
")",
"box",
".",
"setDefaultButton",
"(",
"QMessageBox",
".",
"Ok",
")",
"# Adjust the checkbox depending on the stored configuration\r",
"section",
",",
"option",
"=",
"'main'",
",",
"'check_updates_on_startup'",
"check_updates",
"=",
"CONF",
".",
"get",
"(",
"section",
",",
"option",
")",
"box",
".",
"set_checked",
"(",
"check_updates",
")",
"if",
"error_msg",
"is",
"not",
"None",
":",
"msg",
"=",
"error_msg",
"box",
".",
"setText",
"(",
"msg",
")",
"box",
".",
"set_check_visible",
"(",
"False",
")",
"box",
".",
"exec_",
"(",
")",
"check_updates",
"=",
"box",
".",
"is_checked",
"(",
")",
"else",
":",
"if",
"update_available",
":",
"anaconda_msg",
"=",
"''",
"if",
"'Anaconda'",
"in",
"sys",
".",
"version",
"or",
"'conda-forge'",
"in",
"sys",
".",
"version",
":",
"anaconda_msg",
"=",
"_",
"(",
"\"<hr><b>IMPORTANT NOTE:</b> It seems \"",
"\"that you are using Spyder with \"",
"\"<b>Anaconda/Miniconda</b>. Please \"",
"\"<b>don't</b> use <code>pip</code> to \"",
"\"update it as that will probably break \"",
"\"your installation.<br><br>\"",
"\"Instead, please wait until new conda \"",
"\"packages are available and use \"",
"\"<code>conda</code> to perform the \"",
"\"update.<hr>\"",
")",
"msg",
"=",
"_",
"(",
"\"<b>Spyder %s is available!</b> <br><br>Please use \"",
"\"your package manager to update Spyder or go to our \"",
"\"<a href=\\\"%s\\\">Releases</a> page to download this \"",
"\"new version. <br><br>If you are not sure how to \"",
"\"proceed to update Spyder please refer to our \"",
"\" <a href=\\\"%s\\\">Installation</a> instructions.\"",
"\"\"",
")",
"%",
"(",
"latest_release",
",",
"url_r",
",",
"url_i",
")",
"msg",
"+=",
"'<br>'",
"+",
"anaconda_msg",
"box",
".",
"setText",
"(",
"msg",
")",
"box",
".",
"set_check_visible",
"(",
"True",
")",
"box",
".",
"exec_",
"(",
")",
"check_updates",
"=",
"box",
".",
"is_checked",
"(",
")",
"elif",
"feedback",
":",
"msg",
"=",
"_",
"(",
"\"Spyder is up to date.\"",
")",
"box",
".",
"setText",
"(",
"msg",
")",
"box",
".",
"set_check_visible",
"(",
"False",
")",
"box",
".",
"exec_",
"(",
")",
"check_updates",
"=",
"box",
".",
"is_checked",
"(",
")",
"# Update checkbox based on user interaction\r",
"CONF",
".",
"set",
"(",
"section",
",",
"option",
",",
"check_updates",
")",
"# Enable check_updates_action after the thread has finished\r",
"self",
".",
"check_updates_action",
".",
"setDisabled",
"(",
"False",
")",
"# Provide feeback when clicking menu if check on startup is on\r",
"self",
".",
"give_updates_feedback",
"=",
"True"
] | Called by WorkerUpdates when ready | [
"Called",
"by",
"WorkerUpdates",
"when",
"ready"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L3097-L3173 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | MainWindow.check_updates | def check_updates(self, startup=False):
"""
Check for spyder updates on github releases using a QThread.
"""
from spyder.workers.updates import WorkerUpdates
# Disable check_updates_action while the thread is working
self.check_updates_action.setDisabled(True)
if self.thread_updates is not None:
self.thread_updates.terminate()
self.thread_updates = QThread(self)
self.worker_updates = WorkerUpdates(self, startup=startup)
self.worker_updates.sig_ready.connect(self._check_updates_ready)
self.worker_updates.sig_ready.connect(self.thread_updates.quit)
self.worker_updates.moveToThread(self.thread_updates)
self.thread_updates.started.connect(self.worker_updates.start)
self.thread_updates.start() | python | def check_updates(self, startup=False):
"""
Check for spyder updates on github releases using a QThread.
"""
from spyder.workers.updates import WorkerUpdates
# Disable check_updates_action while the thread is working
self.check_updates_action.setDisabled(True)
if self.thread_updates is not None:
self.thread_updates.terminate()
self.thread_updates = QThread(self)
self.worker_updates = WorkerUpdates(self, startup=startup)
self.worker_updates.sig_ready.connect(self._check_updates_ready)
self.worker_updates.sig_ready.connect(self.thread_updates.quit)
self.worker_updates.moveToThread(self.thread_updates)
self.thread_updates.started.connect(self.worker_updates.start)
self.thread_updates.start() | [
"def",
"check_updates",
"(",
"self",
",",
"startup",
"=",
"False",
")",
":",
"from",
"spyder",
".",
"workers",
".",
"updates",
"import",
"WorkerUpdates",
"# Disable check_updates_action while the thread is working\r",
"self",
".",
"check_updates_action",
".",
"setDisabled",
"(",
"True",
")",
"if",
"self",
".",
"thread_updates",
"is",
"not",
"None",
":",
"self",
".",
"thread_updates",
".",
"terminate",
"(",
")",
"self",
".",
"thread_updates",
"=",
"QThread",
"(",
"self",
")",
"self",
".",
"worker_updates",
"=",
"WorkerUpdates",
"(",
"self",
",",
"startup",
"=",
"startup",
")",
"self",
".",
"worker_updates",
".",
"sig_ready",
".",
"connect",
"(",
"self",
".",
"_check_updates_ready",
")",
"self",
".",
"worker_updates",
".",
"sig_ready",
".",
"connect",
"(",
"self",
".",
"thread_updates",
".",
"quit",
")",
"self",
".",
"worker_updates",
".",
"moveToThread",
"(",
"self",
".",
"thread_updates",
")",
"self",
".",
"thread_updates",
".",
"started",
".",
"connect",
"(",
"self",
".",
"worker_updates",
".",
"start",
")",
"self",
".",
"thread_updates",
".",
"start",
"(",
")"
] | Check for spyder updates on github releases using a QThread. | [
"Check",
"for",
"spyder",
"updates",
"on",
"github",
"releases",
"using",
"a",
"QThread",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L3176-L3194 | train |
spyder-ide/spyder | spyder/config/user.py | DefaultsConfig._set | def _set(self, section, option, value, verbose):
"""
Private set method
"""
if not self.has_section(section):
self.add_section( section )
if not is_text_string(value):
value = repr( value )
if verbose:
print('%s[ %s ] = %s' % (section, option, value)) # spyder: test-skip
cp.ConfigParser.set(self, section, option, value) | python | def _set(self, section, option, value, verbose):
"""
Private set method
"""
if not self.has_section(section):
self.add_section( section )
if not is_text_string(value):
value = repr( value )
if verbose:
print('%s[ %s ] = %s' % (section, option, value)) # spyder: test-skip
cp.ConfigParser.set(self, section, option, value) | [
"def",
"_set",
"(",
"self",
",",
"section",
",",
"option",
",",
"value",
",",
"verbose",
")",
":",
"if",
"not",
"self",
".",
"has_section",
"(",
"section",
")",
":",
"self",
".",
"add_section",
"(",
"section",
")",
"if",
"not",
"is_text_string",
"(",
"value",
")",
":",
"value",
"=",
"repr",
"(",
"value",
")",
"if",
"verbose",
":",
"print",
"(",
"'%s[ %s ] = %s'",
"%",
"(",
"section",
",",
"option",
",",
"value",
")",
")",
"# spyder: test-skip\r",
"cp",
".",
"ConfigParser",
".",
"set",
"(",
"self",
",",
"section",
",",
"option",
",",
"value",
")"
] | Private set method | [
"Private",
"set",
"method"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/user.py#L79-L89 | train |
spyder-ide/spyder | spyder/config/user.py | DefaultsConfig._save | def _save(self):
"""
Save config into the associated .ini file
"""
# See Issue 1086 and 1242 for background on why this
# method contains all the exception handling.
fname = self.filename()
def _write_file(fname):
if PY2:
# Python 2
with codecs.open(fname, 'w', encoding='utf-8') as configfile:
self._write(configfile)
else:
# Python 3
with open(fname, 'w', encoding='utf-8') as configfile:
self.write(configfile)
try: # the "easy" way
_write_file(fname)
except EnvironmentError:
try: # the "delete and sleep" way
if osp.isfile(fname):
os.remove(fname)
time.sleep(0.05)
_write_file(fname)
except Exception as e:
print("Failed to write user configuration file to disk, with "
"the exception shown below") # spyder: test-skip
print(e) | python | def _save(self):
"""
Save config into the associated .ini file
"""
# See Issue 1086 and 1242 for background on why this
# method contains all the exception handling.
fname = self.filename()
def _write_file(fname):
if PY2:
# Python 2
with codecs.open(fname, 'w', encoding='utf-8') as configfile:
self._write(configfile)
else:
# Python 3
with open(fname, 'w', encoding='utf-8') as configfile:
self.write(configfile)
try: # the "easy" way
_write_file(fname)
except EnvironmentError:
try: # the "delete and sleep" way
if osp.isfile(fname):
os.remove(fname)
time.sleep(0.05)
_write_file(fname)
except Exception as e:
print("Failed to write user configuration file to disk, with "
"the exception shown below") # spyder: test-skip
print(e) | [
"def",
"_save",
"(",
"self",
")",
":",
"# See Issue 1086 and 1242 for background on why this\r",
"# method contains all the exception handling.\r",
"fname",
"=",
"self",
".",
"filename",
"(",
")",
"def",
"_write_file",
"(",
"fname",
")",
":",
"if",
"PY2",
":",
"# Python 2\r",
"with",
"codecs",
".",
"open",
"(",
"fname",
",",
"'w'",
",",
"encoding",
"=",
"'utf-8'",
")",
"as",
"configfile",
":",
"self",
".",
"_write",
"(",
"configfile",
")",
"else",
":",
"# Python 3\r",
"with",
"open",
"(",
"fname",
",",
"'w'",
",",
"encoding",
"=",
"'utf-8'",
")",
"as",
"configfile",
":",
"self",
".",
"write",
"(",
"configfile",
")",
"try",
":",
"# the \"easy\" way\r",
"_write_file",
"(",
"fname",
")",
"except",
"EnvironmentError",
":",
"try",
":",
"# the \"delete and sleep\" way\r",
"if",
"osp",
".",
"isfile",
"(",
"fname",
")",
":",
"os",
".",
"remove",
"(",
"fname",
")",
"time",
".",
"sleep",
"(",
"0.05",
")",
"_write_file",
"(",
"fname",
")",
"except",
"Exception",
"as",
"e",
":",
"print",
"(",
"\"Failed to write user configuration file to disk, with \"",
"\"the exception shown below\"",
")",
"# spyder: test-skip\r",
"print",
"(",
"e",
")"
] | Save config into the associated .ini file | [
"Save",
"config",
"into",
"the",
"associated",
".",
"ini",
"file"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/user.py#L91-L120 | train |
spyder-ide/spyder | spyder/config/user.py | DefaultsConfig.filename | def filename(self):
"""Defines the name of the configuration file to use."""
# Needs to be done this way to be used by the project config.
# To fix on a later PR
self._filename = getattr(self, '_filename', None)
self._root_path = getattr(self, '_root_path', None)
if self._filename is None and self._root_path is None:
return self._filename_global()
else:
return self._filename_projects() | python | def filename(self):
"""Defines the name of the configuration file to use."""
# Needs to be done this way to be used by the project config.
# To fix on a later PR
self._filename = getattr(self, '_filename', None)
self._root_path = getattr(self, '_root_path', None)
if self._filename is None and self._root_path is None:
return self._filename_global()
else:
return self._filename_projects() | [
"def",
"filename",
"(",
"self",
")",
":",
"# Needs to be done this way to be used by the project config.\r",
"# To fix on a later PR\r",
"self",
".",
"_filename",
"=",
"getattr",
"(",
"self",
",",
"'_filename'",
",",
"None",
")",
"self",
".",
"_root_path",
"=",
"getattr",
"(",
"self",
",",
"'_root_path'",
",",
"None",
")",
"if",
"self",
".",
"_filename",
"is",
"None",
"and",
"self",
".",
"_root_path",
"is",
"None",
":",
"return",
"self",
".",
"_filename_global",
"(",
")",
"else",
":",
"return",
"self",
".",
"_filename_projects",
"(",
")"
] | Defines the name of the configuration file to use. | [
"Defines",
"the",
"name",
"of",
"the",
"configuration",
"file",
"to",
"use",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/user.py#L122-L132 | train |
spyder-ide/spyder | spyder/config/user.py | DefaultsConfig._filename_global | def _filename_global(self):
"""Create a .ini filename located in user home directory.
This .ini files stores the global spyder preferences.
"""
if self.subfolder is None:
config_file = osp.join(get_home_dir(), '.%s.ini' % self.name)
return config_file
else:
folder = get_conf_path()
# Save defaults in a "defaults" dir of .spyder2 to not pollute it
if 'defaults' in self.name:
folder = osp.join(folder, 'defaults')
if not osp.isdir(folder):
os.mkdir(folder)
config_file = osp.join(folder, '%s.ini' % self.name)
return config_file | python | def _filename_global(self):
"""Create a .ini filename located in user home directory.
This .ini files stores the global spyder preferences.
"""
if self.subfolder is None:
config_file = osp.join(get_home_dir(), '.%s.ini' % self.name)
return config_file
else:
folder = get_conf_path()
# Save defaults in a "defaults" dir of .spyder2 to not pollute it
if 'defaults' in self.name:
folder = osp.join(folder, 'defaults')
if not osp.isdir(folder):
os.mkdir(folder)
config_file = osp.join(folder, '%s.ini' % self.name)
return config_file | [
"def",
"_filename_global",
"(",
"self",
")",
":",
"if",
"self",
".",
"subfolder",
"is",
"None",
":",
"config_file",
"=",
"osp",
".",
"join",
"(",
"get_home_dir",
"(",
")",
",",
"'.%s.ini'",
"%",
"self",
".",
"name",
")",
"return",
"config_file",
"else",
":",
"folder",
"=",
"get_conf_path",
"(",
")",
"# Save defaults in a \"defaults\" dir of .spyder2 to not pollute it\r",
"if",
"'defaults'",
"in",
"self",
".",
"name",
":",
"folder",
"=",
"osp",
".",
"join",
"(",
"folder",
",",
"'defaults'",
")",
"if",
"not",
"osp",
".",
"isdir",
"(",
"folder",
")",
":",
"os",
".",
"mkdir",
"(",
"folder",
")",
"config_file",
"=",
"osp",
".",
"join",
"(",
"folder",
",",
"'%s.ini'",
"%",
"self",
".",
"name",
")",
"return",
"config_file"
] | Create a .ini filename located in user home directory.
This .ini files stores the global spyder preferences. | [
"Create",
"a",
".",
"ini",
"filename",
"located",
"in",
"user",
"home",
"directory",
".",
"This",
".",
"ini",
"files",
"stores",
"the",
"global",
"spyder",
"preferences",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/user.py#L141-L156 | train |
spyder-ide/spyder | spyder/config/user.py | UserConfig.set_version | def set_version(self, version='0.0.0', save=True):
"""Set configuration (not application!) version"""
self.set(self.DEFAULT_SECTION_NAME, 'version', version, save=save) | python | def set_version(self, version='0.0.0', save=True):
"""Set configuration (not application!) version"""
self.set(self.DEFAULT_SECTION_NAME, 'version', version, save=save) | [
"def",
"set_version",
"(",
"self",
",",
"version",
"=",
"'0.0.0'",
",",
"save",
"=",
"True",
")",
":",
"self",
".",
"set",
"(",
"self",
".",
"DEFAULT_SECTION_NAME",
",",
"'version'",
",",
"version",
",",
"save",
"=",
"save",
")"
] | Set configuration (not application!) version | [
"Set",
"configuration",
"(",
"not",
"application!",
")",
"version"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/user.py#L239-L241 | train |
spyder-ide/spyder | spyder/config/user.py | UserConfig.load_from_ini | def load_from_ini(self):
"""
Load config from the associated .ini file
"""
try:
if PY2:
# Python 2
fname = self.filename()
if osp.isfile(fname):
try:
with codecs.open(fname, encoding='utf-8') as configfile:
self.readfp(configfile)
except IOError:
print("Failed reading file", fname) # spyder: test-skip
else:
# Python 3
self.read(self.filename(), encoding='utf-8')
except cp.MissingSectionHeaderError:
print("Warning: File contains no section headers.") | python | def load_from_ini(self):
"""
Load config from the associated .ini file
"""
try:
if PY2:
# Python 2
fname = self.filename()
if osp.isfile(fname):
try:
with codecs.open(fname, encoding='utf-8') as configfile:
self.readfp(configfile)
except IOError:
print("Failed reading file", fname) # spyder: test-skip
else:
# Python 3
self.read(self.filename(), encoding='utf-8')
except cp.MissingSectionHeaderError:
print("Warning: File contains no section headers.") | [
"def",
"load_from_ini",
"(",
"self",
")",
":",
"try",
":",
"if",
"PY2",
":",
"# Python 2\r",
"fname",
"=",
"self",
".",
"filename",
"(",
")",
"if",
"osp",
".",
"isfile",
"(",
"fname",
")",
":",
"try",
":",
"with",
"codecs",
".",
"open",
"(",
"fname",
",",
"encoding",
"=",
"'utf-8'",
")",
"as",
"configfile",
":",
"self",
".",
"readfp",
"(",
"configfile",
")",
"except",
"IOError",
":",
"print",
"(",
"\"Failed reading file\"",
",",
"fname",
")",
"# spyder: test-skip\r",
"else",
":",
"# Python 3\r",
"self",
".",
"read",
"(",
"self",
".",
"filename",
"(",
")",
",",
"encoding",
"=",
"'utf-8'",
")",
"except",
"cp",
".",
"MissingSectionHeaderError",
":",
"print",
"(",
"\"Warning: File contains no section headers.\"",
")"
] | Load config from the associated .ini file | [
"Load",
"config",
"from",
"the",
"associated",
".",
"ini",
"file"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/user.py#L243-L261 | train |
spyder-ide/spyder | spyder/config/user.py | UserConfig._load_old_defaults | def _load_old_defaults(self, old_version):
"""Read old defaults"""
old_defaults = cp.ConfigParser()
if check_version(old_version, '3.0.0', '<='):
path = get_module_source_path('spyder')
else:
path = osp.dirname(self.filename())
path = osp.join(path, 'defaults')
old_defaults.read(osp.join(path, 'defaults-'+old_version+'.ini'))
return old_defaults | python | def _load_old_defaults(self, old_version):
"""Read old defaults"""
old_defaults = cp.ConfigParser()
if check_version(old_version, '3.0.0', '<='):
path = get_module_source_path('spyder')
else:
path = osp.dirname(self.filename())
path = osp.join(path, 'defaults')
old_defaults.read(osp.join(path, 'defaults-'+old_version+'.ini'))
return old_defaults | [
"def",
"_load_old_defaults",
"(",
"self",
",",
"old_version",
")",
":",
"old_defaults",
"=",
"cp",
".",
"ConfigParser",
"(",
")",
"if",
"check_version",
"(",
"old_version",
",",
"'3.0.0'",
",",
"'<='",
")",
":",
"path",
"=",
"get_module_source_path",
"(",
"'spyder'",
")",
"else",
":",
"path",
"=",
"osp",
".",
"dirname",
"(",
"self",
".",
"filename",
"(",
")",
")",
"path",
"=",
"osp",
".",
"join",
"(",
"path",
",",
"'defaults'",
")",
"old_defaults",
".",
"read",
"(",
"osp",
".",
"join",
"(",
"path",
",",
"'defaults-'",
"+",
"old_version",
"+",
"'.ini'",
")",
")",
"return",
"old_defaults"
] | Read old defaults | [
"Read",
"old",
"defaults"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/user.py#L263-L272 | train |
spyder-ide/spyder | spyder/config/user.py | UserConfig._save_new_defaults | def _save_new_defaults(self, defaults, new_version, subfolder):
"""Save new defaults"""
new_defaults = DefaultsConfig(name='defaults-'+new_version,
subfolder=subfolder)
if not osp.isfile(new_defaults.filename()):
new_defaults.set_defaults(defaults)
new_defaults._save() | python | def _save_new_defaults(self, defaults, new_version, subfolder):
"""Save new defaults"""
new_defaults = DefaultsConfig(name='defaults-'+new_version,
subfolder=subfolder)
if not osp.isfile(new_defaults.filename()):
new_defaults.set_defaults(defaults)
new_defaults._save() | [
"def",
"_save_new_defaults",
"(",
"self",
",",
"defaults",
",",
"new_version",
",",
"subfolder",
")",
":",
"new_defaults",
"=",
"DefaultsConfig",
"(",
"name",
"=",
"'defaults-'",
"+",
"new_version",
",",
"subfolder",
"=",
"subfolder",
")",
"if",
"not",
"osp",
".",
"isfile",
"(",
"new_defaults",
".",
"filename",
"(",
")",
")",
":",
"new_defaults",
".",
"set_defaults",
"(",
"defaults",
")",
"new_defaults",
".",
"_save",
"(",
")"
] | Save new defaults | [
"Save",
"new",
"defaults"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/user.py#L274-L280 | train |
spyder-ide/spyder | spyder/config/user.py | UserConfig._update_defaults | def _update_defaults(self, defaults, old_version, verbose=False):
"""Update defaults after a change in version"""
old_defaults = self._load_old_defaults(old_version)
for section, options in defaults:
for option in options:
new_value = options[ option ]
try:
old_value = old_defaults.get(section, option)
except (cp.NoSectionError, cp.NoOptionError):
old_value = None
if old_value is None or \
to_text_string(new_value) != old_value:
self._set(section, option, new_value, verbose) | python | def _update_defaults(self, defaults, old_version, verbose=False):
"""Update defaults after a change in version"""
old_defaults = self._load_old_defaults(old_version)
for section, options in defaults:
for option in options:
new_value = options[ option ]
try:
old_value = old_defaults.get(section, option)
except (cp.NoSectionError, cp.NoOptionError):
old_value = None
if old_value is None or \
to_text_string(new_value) != old_value:
self._set(section, option, new_value, verbose) | [
"def",
"_update_defaults",
"(",
"self",
",",
"defaults",
",",
"old_version",
",",
"verbose",
"=",
"False",
")",
":",
"old_defaults",
"=",
"self",
".",
"_load_old_defaults",
"(",
"old_version",
")",
"for",
"section",
",",
"options",
"in",
"defaults",
":",
"for",
"option",
"in",
"options",
":",
"new_value",
"=",
"options",
"[",
"option",
"]",
"try",
":",
"old_value",
"=",
"old_defaults",
".",
"get",
"(",
"section",
",",
"option",
")",
"except",
"(",
"cp",
".",
"NoSectionError",
",",
"cp",
".",
"NoOptionError",
")",
":",
"old_value",
"=",
"None",
"if",
"old_value",
"is",
"None",
"or",
"to_text_string",
"(",
"new_value",
")",
"!=",
"old_value",
":",
"self",
".",
"_set",
"(",
"section",
",",
"option",
",",
"new_value",
",",
"verbose",
")"
] | Update defaults after a change in version | [
"Update",
"defaults",
"after",
"a",
"change",
"in",
"version"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/user.py#L282-L294 | train |
spyder-ide/spyder | spyder/config/user.py | UserConfig._remove_deprecated_options | def _remove_deprecated_options(self, old_version):
"""
Remove options which are present in the .ini file but not in defaults
"""
old_defaults = self._load_old_defaults(old_version)
for section in old_defaults.sections():
for option, _ in old_defaults.items(section, raw=self.raw):
if self.get_default(section, option) is NoDefault:
try:
self.remove_option(section, option)
if len(self.items(section, raw=self.raw)) == 0:
self.remove_section(section)
except cp.NoSectionError:
self.remove_section(section) | python | def _remove_deprecated_options(self, old_version):
"""
Remove options which are present in the .ini file but not in defaults
"""
old_defaults = self._load_old_defaults(old_version)
for section in old_defaults.sections():
for option, _ in old_defaults.items(section, raw=self.raw):
if self.get_default(section, option) is NoDefault:
try:
self.remove_option(section, option)
if len(self.items(section, raw=self.raw)) == 0:
self.remove_section(section)
except cp.NoSectionError:
self.remove_section(section) | [
"def",
"_remove_deprecated_options",
"(",
"self",
",",
"old_version",
")",
":",
"old_defaults",
"=",
"self",
".",
"_load_old_defaults",
"(",
"old_version",
")",
"for",
"section",
"in",
"old_defaults",
".",
"sections",
"(",
")",
":",
"for",
"option",
",",
"_",
"in",
"old_defaults",
".",
"items",
"(",
"section",
",",
"raw",
"=",
"self",
".",
"raw",
")",
":",
"if",
"self",
".",
"get_default",
"(",
"section",
",",
"option",
")",
"is",
"NoDefault",
":",
"try",
":",
"self",
".",
"remove_option",
"(",
"section",
",",
"option",
")",
"if",
"len",
"(",
"self",
".",
"items",
"(",
"section",
",",
"raw",
"=",
"self",
".",
"raw",
")",
")",
"==",
"0",
":",
"self",
".",
"remove_section",
"(",
"section",
")",
"except",
"cp",
".",
"NoSectionError",
":",
"self",
".",
"remove_section",
"(",
"section",
")"
] | Remove options which are present in the .ini file but not in defaults | [
"Remove",
"options",
"which",
"are",
"present",
"in",
"the",
".",
"ini",
"file",
"but",
"not",
"in",
"defaults"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/user.py#L296-L309 | train |
spyder-ide/spyder | spyder/config/user.py | UserConfig.set_as_defaults | def set_as_defaults(self):
"""
Set defaults from the current config
"""
self.defaults = []
for section in self.sections():
secdict = {}
for option, value in self.items(section, raw=self.raw):
secdict[option] = value
self.defaults.append( (section, secdict) ) | python | def set_as_defaults(self):
"""
Set defaults from the current config
"""
self.defaults = []
for section in self.sections():
secdict = {}
for option, value in self.items(section, raw=self.raw):
secdict[option] = value
self.defaults.append( (section, secdict) ) | [
"def",
"set_as_defaults",
"(",
"self",
")",
":",
"self",
".",
"defaults",
"=",
"[",
"]",
"for",
"section",
"in",
"self",
".",
"sections",
"(",
")",
":",
"secdict",
"=",
"{",
"}",
"for",
"option",
",",
"value",
"in",
"self",
".",
"items",
"(",
"section",
",",
"raw",
"=",
"self",
".",
"raw",
")",
":",
"secdict",
"[",
"option",
"]",
"=",
"value",
"self",
".",
"defaults",
".",
"append",
"(",
"(",
"section",
",",
"secdict",
")",
")"
] | Set defaults from the current config | [
"Set",
"defaults",
"from",
"the",
"current",
"config"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/user.py#L317-L326 | train |
spyder-ide/spyder | spyder/config/user.py | UserConfig.reset_to_defaults | def reset_to_defaults(self, save=True, verbose=False, section=None):
"""
Reset config to Default values
"""
for sec, options in self.defaults:
if section == None or section == sec:
for option in options:
value = options[ option ]
self._set(sec, option, value, verbose)
if save:
self._save() | python | def reset_to_defaults(self, save=True, verbose=False, section=None):
"""
Reset config to Default values
"""
for sec, options in self.defaults:
if section == None or section == sec:
for option in options:
value = options[ option ]
self._set(sec, option, value, verbose)
if save:
self._save() | [
"def",
"reset_to_defaults",
"(",
"self",
",",
"save",
"=",
"True",
",",
"verbose",
"=",
"False",
",",
"section",
"=",
"None",
")",
":",
"for",
"sec",
",",
"options",
"in",
"self",
".",
"defaults",
":",
"if",
"section",
"==",
"None",
"or",
"section",
"==",
"sec",
":",
"for",
"option",
"in",
"options",
":",
"value",
"=",
"options",
"[",
"option",
"]",
"self",
".",
"_set",
"(",
"sec",
",",
"option",
",",
"value",
",",
"verbose",
")",
"if",
"save",
":",
"self",
".",
"_save",
"(",
")"
] | Reset config to Default values | [
"Reset",
"config",
"to",
"Default",
"values"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/user.py#L328-L338 | train |
spyder-ide/spyder | spyder/config/user.py | UserConfig._check_section_option | def _check_section_option(self, section, option):
"""
Private method to check section and option types
"""
if section is None:
section = self.DEFAULT_SECTION_NAME
elif not is_text_string(section):
raise RuntimeError("Argument 'section' must be a string")
if not is_text_string(option):
raise RuntimeError("Argument 'option' must be a string")
return section | python | def _check_section_option(self, section, option):
"""
Private method to check section and option types
"""
if section is None:
section = self.DEFAULT_SECTION_NAME
elif not is_text_string(section):
raise RuntimeError("Argument 'section' must be a string")
if not is_text_string(option):
raise RuntimeError("Argument 'option' must be a string")
return section | [
"def",
"_check_section_option",
"(",
"self",
",",
"section",
",",
"option",
")",
":",
"if",
"section",
"is",
"None",
":",
"section",
"=",
"self",
".",
"DEFAULT_SECTION_NAME",
"elif",
"not",
"is_text_string",
"(",
"section",
")",
":",
"raise",
"RuntimeError",
"(",
"\"Argument 'section' must be a string\"",
")",
"if",
"not",
"is_text_string",
"(",
"option",
")",
":",
"raise",
"RuntimeError",
"(",
"\"Argument 'option' must be a string\"",
")",
"return",
"section"
] | Private method to check section and option types | [
"Private",
"method",
"to",
"check",
"section",
"and",
"option",
"types"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/user.py#L340-L350 | train |
spyder-ide/spyder | spyder/config/user.py | UserConfig.get_default | def get_default(self, section, option):
"""
Get Default value for a given (section, option)
-> useful for type checking in 'get' method
"""
section = self._check_section_option(section, option)
for sec, options in self.defaults:
if sec == section:
if option in options:
return options[ option ]
else:
return NoDefault | python | def get_default(self, section, option):
"""
Get Default value for a given (section, option)
-> useful for type checking in 'get' method
"""
section = self._check_section_option(section, option)
for sec, options in self.defaults:
if sec == section:
if option in options:
return options[ option ]
else:
return NoDefault | [
"def",
"get_default",
"(",
"self",
",",
"section",
",",
"option",
")",
":",
"section",
"=",
"self",
".",
"_check_section_option",
"(",
"section",
",",
"option",
")",
"for",
"sec",
",",
"options",
"in",
"self",
".",
"defaults",
":",
"if",
"sec",
"==",
"section",
":",
"if",
"option",
"in",
"options",
":",
"return",
"options",
"[",
"option",
"]",
"else",
":",
"return",
"NoDefault"
] | Get Default value for a given (section, option)
-> useful for type checking in 'get' method | [
"Get",
"Default",
"value",
"for",
"a",
"given",
"(",
"section",
"option",
")",
"-",
">",
"useful",
"for",
"type",
"checking",
"in",
"get",
"method"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/user.py#L352-L363 | train |
spyder-ide/spyder | spyder/config/user.py | UserConfig.get | def get(self, section, option, default=NoDefault):
"""
Get an option
section=None: attribute a default section name
default: default value (if not specified, an exception
will be raised if option doesn't exist)
"""
section = self._check_section_option(section, option)
if not self.has_section(section):
if default is NoDefault:
raise cp.NoSectionError(section)
else:
self.add_section(section)
if not self.has_option(section, option):
if default is NoDefault:
raise cp.NoOptionError(option, section)
else:
self.set(section, option, default)
return default
value = cp.ConfigParser.get(self, section, option, raw=self.raw)
# Use type of default_value to parse value correctly
default_value = self.get_default(section, option)
if isinstance(default_value, bool):
value = ast.literal_eval(value)
elif isinstance(default_value, float):
value = float(value)
elif isinstance(default_value, int):
value = int(value)
elif is_text_string(default_value):
if PY2:
try:
value = value.decode('utf-8')
try:
# Some str config values expect to be eval after decoding
new_value = ast.literal_eval(value)
if is_text_string(new_value):
value = new_value
except (SyntaxError, ValueError):
pass
except (UnicodeEncodeError, UnicodeDecodeError):
pass
else:
try:
# lists, tuples, ...
value = ast.literal_eval(value)
except (SyntaxError, ValueError):
pass
return value | python | def get(self, section, option, default=NoDefault):
"""
Get an option
section=None: attribute a default section name
default: default value (if not specified, an exception
will be raised if option doesn't exist)
"""
section = self._check_section_option(section, option)
if not self.has_section(section):
if default is NoDefault:
raise cp.NoSectionError(section)
else:
self.add_section(section)
if not self.has_option(section, option):
if default is NoDefault:
raise cp.NoOptionError(option, section)
else:
self.set(section, option, default)
return default
value = cp.ConfigParser.get(self, section, option, raw=self.raw)
# Use type of default_value to parse value correctly
default_value = self.get_default(section, option)
if isinstance(default_value, bool):
value = ast.literal_eval(value)
elif isinstance(default_value, float):
value = float(value)
elif isinstance(default_value, int):
value = int(value)
elif is_text_string(default_value):
if PY2:
try:
value = value.decode('utf-8')
try:
# Some str config values expect to be eval after decoding
new_value = ast.literal_eval(value)
if is_text_string(new_value):
value = new_value
except (SyntaxError, ValueError):
pass
except (UnicodeEncodeError, UnicodeDecodeError):
pass
else:
try:
# lists, tuples, ...
value = ast.literal_eval(value)
except (SyntaxError, ValueError):
pass
return value | [
"def",
"get",
"(",
"self",
",",
"section",
",",
"option",
",",
"default",
"=",
"NoDefault",
")",
":",
"section",
"=",
"self",
".",
"_check_section_option",
"(",
"section",
",",
"option",
")",
"if",
"not",
"self",
".",
"has_section",
"(",
"section",
")",
":",
"if",
"default",
"is",
"NoDefault",
":",
"raise",
"cp",
".",
"NoSectionError",
"(",
"section",
")",
"else",
":",
"self",
".",
"add_section",
"(",
"section",
")",
"if",
"not",
"self",
".",
"has_option",
"(",
"section",
",",
"option",
")",
":",
"if",
"default",
"is",
"NoDefault",
":",
"raise",
"cp",
".",
"NoOptionError",
"(",
"option",
",",
"section",
")",
"else",
":",
"self",
".",
"set",
"(",
"section",
",",
"option",
",",
"default",
")",
"return",
"default",
"value",
"=",
"cp",
".",
"ConfigParser",
".",
"get",
"(",
"self",
",",
"section",
",",
"option",
",",
"raw",
"=",
"self",
".",
"raw",
")",
"# Use type of default_value to parse value correctly\r",
"default_value",
"=",
"self",
".",
"get_default",
"(",
"section",
",",
"option",
")",
"if",
"isinstance",
"(",
"default_value",
",",
"bool",
")",
":",
"value",
"=",
"ast",
".",
"literal_eval",
"(",
"value",
")",
"elif",
"isinstance",
"(",
"default_value",
",",
"float",
")",
":",
"value",
"=",
"float",
"(",
"value",
")",
"elif",
"isinstance",
"(",
"default_value",
",",
"int",
")",
":",
"value",
"=",
"int",
"(",
"value",
")",
"elif",
"is_text_string",
"(",
"default_value",
")",
":",
"if",
"PY2",
":",
"try",
":",
"value",
"=",
"value",
".",
"decode",
"(",
"'utf-8'",
")",
"try",
":",
"# Some str config values expect to be eval after decoding\r",
"new_value",
"=",
"ast",
".",
"literal_eval",
"(",
"value",
")",
"if",
"is_text_string",
"(",
"new_value",
")",
":",
"value",
"=",
"new_value",
"except",
"(",
"SyntaxError",
",",
"ValueError",
")",
":",
"pass",
"except",
"(",
"UnicodeEncodeError",
",",
"UnicodeDecodeError",
")",
":",
"pass",
"else",
":",
"try",
":",
"# lists, tuples, ...\r",
"value",
"=",
"ast",
".",
"literal_eval",
"(",
"value",
")",
"except",
"(",
"SyntaxError",
",",
"ValueError",
")",
":",
"pass",
"return",
"value"
] | Get an option
section=None: attribute a default section name
default: default value (if not specified, an exception
will be raised if option doesn't exist) | [
"Get",
"an",
"option",
"section",
"=",
"None",
":",
"attribute",
"a",
"default",
"section",
"name",
"default",
":",
"default",
"value",
"(",
"if",
"not",
"specified",
"an",
"exception",
"will",
"be",
"raised",
"if",
"option",
"doesn",
"t",
"exist",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/user.py#L365-L415 | train |
spyder-ide/spyder | spyder/config/user.py | UserConfig.set_default | def set_default(self, section, option, default_value):
"""
Set Default value for a given (section, option)
-> called when a new (section, option) is set and no default exists
"""
section = self._check_section_option(section, option)
for sec, options in self.defaults:
if sec == section:
options[ option ] = default_value | python | def set_default(self, section, option, default_value):
"""
Set Default value for a given (section, option)
-> called when a new (section, option) is set and no default exists
"""
section = self._check_section_option(section, option)
for sec, options in self.defaults:
if sec == section:
options[ option ] = default_value | [
"def",
"set_default",
"(",
"self",
",",
"section",
",",
"option",
",",
"default_value",
")",
":",
"section",
"=",
"self",
".",
"_check_section_option",
"(",
"section",
",",
"option",
")",
"for",
"sec",
",",
"options",
"in",
"self",
".",
"defaults",
":",
"if",
"sec",
"==",
"section",
":",
"options",
"[",
"option",
"]",
"=",
"default_value"
] | Set Default value for a given (section, option)
-> called when a new (section, option) is set and no default exists | [
"Set",
"Default",
"value",
"for",
"a",
"given",
"(",
"section",
"option",
")",
"-",
">",
"called",
"when",
"a",
"new",
"(",
"section",
"option",
")",
"is",
"set",
"and",
"no",
"default",
"exists"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/user.py#L417-L425 | train |
spyder-ide/spyder | spyder/config/user.py | UserConfig.set | def set(self, section, option, value, verbose=False, save=True):
"""
Set an option
section=None: attribute a default section name
"""
section = self._check_section_option(section, option)
default_value = self.get_default(section, option)
if default_value is NoDefault:
# This let us save correctly string value options with
# no config default that contain non-ascii chars in
# Python 2
if PY2 and is_text_string(value):
value = repr(value)
default_value = value
self.set_default(section, option, default_value)
if isinstance(default_value, bool):
value = bool(value)
elif isinstance(default_value, float):
value = float(value)
elif isinstance(default_value, int):
value = int(value)
elif not is_text_string(default_value):
value = repr(value)
self._set(section, option, value, verbose)
if save:
self._save() | python | def set(self, section, option, value, verbose=False, save=True):
"""
Set an option
section=None: attribute a default section name
"""
section = self._check_section_option(section, option)
default_value = self.get_default(section, option)
if default_value is NoDefault:
# This let us save correctly string value options with
# no config default that contain non-ascii chars in
# Python 2
if PY2 and is_text_string(value):
value = repr(value)
default_value = value
self.set_default(section, option, default_value)
if isinstance(default_value, bool):
value = bool(value)
elif isinstance(default_value, float):
value = float(value)
elif isinstance(default_value, int):
value = int(value)
elif not is_text_string(default_value):
value = repr(value)
self._set(section, option, value, verbose)
if save:
self._save() | [
"def",
"set",
"(",
"self",
",",
"section",
",",
"option",
",",
"value",
",",
"verbose",
"=",
"False",
",",
"save",
"=",
"True",
")",
":",
"section",
"=",
"self",
".",
"_check_section_option",
"(",
"section",
",",
"option",
")",
"default_value",
"=",
"self",
".",
"get_default",
"(",
"section",
",",
"option",
")",
"if",
"default_value",
"is",
"NoDefault",
":",
"# This let us save correctly string value options with\r",
"# no config default that contain non-ascii chars in\r",
"# Python 2\r",
"if",
"PY2",
"and",
"is_text_string",
"(",
"value",
")",
":",
"value",
"=",
"repr",
"(",
"value",
")",
"default_value",
"=",
"value",
"self",
".",
"set_default",
"(",
"section",
",",
"option",
",",
"default_value",
")",
"if",
"isinstance",
"(",
"default_value",
",",
"bool",
")",
":",
"value",
"=",
"bool",
"(",
"value",
")",
"elif",
"isinstance",
"(",
"default_value",
",",
"float",
")",
":",
"value",
"=",
"float",
"(",
"value",
")",
"elif",
"isinstance",
"(",
"default_value",
",",
"int",
")",
":",
"value",
"=",
"int",
"(",
"value",
")",
"elif",
"not",
"is_text_string",
"(",
"default_value",
")",
":",
"value",
"=",
"repr",
"(",
"value",
")",
"self",
".",
"_set",
"(",
"section",
",",
"option",
",",
"value",
",",
"verbose",
")",
"if",
"save",
":",
"self",
".",
"_save",
"(",
")"
] | Set an option
section=None: attribute a default section name | [
"Set",
"an",
"option",
"section",
"=",
"None",
":",
"attribute",
"a",
"default",
"section",
"name"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/user.py#L427-L452 | train |
spyder-ide/spyder | spyder/utils/programs.py | get_temp_dir | def get_temp_dir(suffix=None):
"""
Return temporary Spyder directory, checking previously that it exists.
"""
to_join = [tempfile.gettempdir()]
if os.name == 'nt':
to_join.append('spyder')
else:
username = encoding.to_unicode_from_fs(getuser())
to_join.append('spyder-' + username)
if suffix is not None:
to_join.append(suffix)
tempdir = osp.join(*to_join)
if not osp.isdir(tempdir):
os.mkdir(tempdir)
return tempdir | python | def get_temp_dir(suffix=None):
"""
Return temporary Spyder directory, checking previously that it exists.
"""
to_join = [tempfile.gettempdir()]
if os.name == 'nt':
to_join.append('spyder')
else:
username = encoding.to_unicode_from_fs(getuser())
to_join.append('spyder-' + username)
if suffix is not None:
to_join.append(suffix)
tempdir = osp.join(*to_join)
if not osp.isdir(tempdir):
os.mkdir(tempdir)
return tempdir | [
"def",
"get_temp_dir",
"(",
"suffix",
"=",
"None",
")",
":",
"to_join",
"=",
"[",
"tempfile",
".",
"gettempdir",
"(",
")",
"]",
"if",
"os",
".",
"name",
"==",
"'nt'",
":",
"to_join",
".",
"append",
"(",
"'spyder'",
")",
"else",
":",
"username",
"=",
"encoding",
".",
"to_unicode_from_fs",
"(",
"getuser",
"(",
")",
")",
"to_join",
".",
"append",
"(",
"'spyder-'",
"+",
"username",
")",
"if",
"suffix",
"is",
"not",
"None",
":",
"to_join",
".",
"append",
"(",
"suffix",
")",
"tempdir",
"=",
"osp",
".",
"join",
"(",
"*",
"to_join",
")",
"if",
"not",
"osp",
".",
"isdir",
"(",
"tempdir",
")",
":",
"os",
".",
"mkdir",
"(",
"tempdir",
")",
"return",
"tempdir"
] | Return temporary Spyder directory, checking previously that it exists. | [
"Return",
"temporary",
"Spyder",
"directory",
"checking",
"previously",
"that",
"it",
"exists",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/programs.py#L34-L54 | train |
spyder-ide/spyder | spyder/utils/programs.py | is_program_installed | def is_program_installed(basename):
"""
Return program absolute path if installed in PATH.
Otherwise, return None
"""
for path in os.environ["PATH"].split(os.pathsep):
abspath = osp.join(path, basename)
if osp.isfile(abspath):
return abspath | python | def is_program_installed(basename):
"""
Return program absolute path if installed in PATH.
Otherwise, return None
"""
for path in os.environ["PATH"].split(os.pathsep):
abspath = osp.join(path, basename)
if osp.isfile(abspath):
return abspath | [
"def",
"is_program_installed",
"(",
"basename",
")",
":",
"for",
"path",
"in",
"os",
".",
"environ",
"[",
"\"PATH\"",
"]",
".",
"split",
"(",
"os",
".",
"pathsep",
")",
":",
"abspath",
"=",
"osp",
".",
"join",
"(",
"path",
",",
"basename",
")",
"if",
"osp",
".",
"isfile",
"(",
"abspath",
")",
":",
"return",
"abspath"
] | Return program absolute path if installed in PATH.
Otherwise, return None | [
"Return",
"program",
"absolute",
"path",
"if",
"installed",
"in",
"PATH",
".",
"Otherwise",
"return",
"None"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/programs.py#L57-L66 | train |
spyder-ide/spyder | spyder/utils/programs.py | find_program | def find_program(basename):
"""
Find program in PATH and return absolute path
Try adding .exe or .bat to basename on Windows platforms
(return None if not found)
"""
names = [basename]
if os.name == 'nt':
# Windows platforms
extensions = ('.exe', '.bat', '.cmd')
if not basename.endswith(extensions):
names = [basename+ext for ext in extensions]+[basename]
for name in names:
path = is_program_installed(name)
if path:
return path | python | def find_program(basename):
"""
Find program in PATH and return absolute path
Try adding .exe or .bat to basename on Windows platforms
(return None if not found)
"""
names = [basename]
if os.name == 'nt':
# Windows platforms
extensions = ('.exe', '.bat', '.cmd')
if not basename.endswith(extensions):
names = [basename+ext for ext in extensions]+[basename]
for name in names:
path = is_program_installed(name)
if path:
return path | [
"def",
"find_program",
"(",
"basename",
")",
":",
"names",
"=",
"[",
"basename",
"]",
"if",
"os",
".",
"name",
"==",
"'nt'",
":",
"# Windows platforms\r",
"extensions",
"=",
"(",
"'.exe'",
",",
"'.bat'",
",",
"'.cmd'",
")",
"if",
"not",
"basename",
".",
"endswith",
"(",
"extensions",
")",
":",
"names",
"=",
"[",
"basename",
"+",
"ext",
"for",
"ext",
"in",
"extensions",
"]",
"+",
"[",
"basename",
"]",
"for",
"name",
"in",
"names",
":",
"path",
"=",
"is_program_installed",
"(",
"name",
")",
"if",
"path",
":",
"return",
"path"
] | Find program in PATH and return absolute path
Try adding .exe or .bat to basename on Windows platforms
(return None if not found) | [
"Find",
"program",
"in",
"PATH",
"and",
"return",
"absolute",
"path",
"Try",
"adding",
".",
"exe",
"or",
".",
"bat",
"to",
"basename",
"on",
"Windows",
"platforms",
"(",
"return",
"None",
"if",
"not",
"found",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/programs.py#L69-L85 | train |
spyder-ide/spyder | spyder/utils/programs.py | alter_subprocess_kwargs_by_platform | def alter_subprocess_kwargs_by_platform(**kwargs):
"""
Given a dict, populate kwargs to create a generally
useful default setup for running subprocess processes
on different platforms. For example, `close_fds` is
set on posix and creation of a new console window is
disabled on Windows.
This function will alter the given kwargs and return
the modified dict.
"""
kwargs.setdefault('close_fds', os.name == 'posix')
if os.name == 'nt':
CONSOLE_CREATION_FLAGS = 0 # Default value
# See: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863%28v=vs.85%29.aspx
CREATE_NO_WINDOW = 0x08000000
# We "or" them together
CONSOLE_CREATION_FLAGS |= CREATE_NO_WINDOW
kwargs.setdefault('creationflags', CONSOLE_CREATION_FLAGS)
return kwargs | python | def alter_subprocess_kwargs_by_platform(**kwargs):
"""
Given a dict, populate kwargs to create a generally
useful default setup for running subprocess processes
on different platforms. For example, `close_fds` is
set on posix and creation of a new console window is
disabled on Windows.
This function will alter the given kwargs and return
the modified dict.
"""
kwargs.setdefault('close_fds', os.name == 'posix')
if os.name == 'nt':
CONSOLE_CREATION_FLAGS = 0 # Default value
# See: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863%28v=vs.85%29.aspx
CREATE_NO_WINDOW = 0x08000000
# We "or" them together
CONSOLE_CREATION_FLAGS |= CREATE_NO_WINDOW
kwargs.setdefault('creationflags', CONSOLE_CREATION_FLAGS)
return kwargs | [
"def",
"alter_subprocess_kwargs_by_platform",
"(",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
".",
"setdefault",
"(",
"'close_fds'",
",",
"os",
".",
"name",
"==",
"'posix'",
")",
"if",
"os",
".",
"name",
"==",
"'nt'",
":",
"CONSOLE_CREATION_FLAGS",
"=",
"0",
"# Default value\r",
"# See: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863%28v=vs.85%29.aspx\r",
"CREATE_NO_WINDOW",
"=",
"0x08000000",
"# We \"or\" them together\r",
"CONSOLE_CREATION_FLAGS",
"|=",
"CREATE_NO_WINDOW",
"kwargs",
".",
"setdefault",
"(",
"'creationflags'",
",",
"CONSOLE_CREATION_FLAGS",
")",
"return",
"kwargs"
] | Given a dict, populate kwargs to create a generally
useful default setup for running subprocess processes
on different platforms. For example, `close_fds` is
set on posix and creation of a new console window is
disabled on Windows.
This function will alter the given kwargs and return
the modified dict. | [
"Given",
"a",
"dict",
"populate",
"kwargs",
"to",
"create",
"a",
"generally",
"useful",
"default",
"setup",
"for",
"running",
"subprocess",
"processes",
"on",
"different",
"platforms",
".",
"For",
"example",
"close_fds",
"is",
"set",
"on",
"posix",
"and",
"creation",
"of",
"a",
"new",
"console",
"window",
"is",
"disabled",
"on",
"Windows",
".",
"This",
"function",
"will",
"alter",
"the",
"given",
"kwargs",
"and",
"return",
"the",
"modified",
"dict",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/programs.py#L88-L107 | train |
spyder-ide/spyder | spyder/utils/programs.py | run_shell_command | def run_shell_command(cmdstr, **subprocess_kwargs):
"""
Execute the given shell command.
Note that *args and **kwargs will be passed to the subprocess call.
If 'shell' is given in subprocess_kwargs it must be True,
otherwise ProgramError will be raised.
.
If 'executable' is not given in subprocess_kwargs, it will
be set to the value of the SHELL environment variable.
Note that stdin, stdout and stderr will be set by default
to PIPE unless specified in subprocess_kwargs.
:str cmdstr: The string run as a shell command.
:subprocess_kwargs: These will be passed to subprocess.Popen.
"""
if 'shell' in subprocess_kwargs and not subprocess_kwargs['shell']:
raise ProgramError(
'The "shell" kwarg may be omitted, but if '
'provided it must be True.')
else:
subprocess_kwargs['shell'] = True
if 'executable' not in subprocess_kwargs:
subprocess_kwargs['executable'] = os.getenv('SHELL')
for stream in ['stdin', 'stdout', 'stderr']:
subprocess_kwargs.setdefault(stream, subprocess.PIPE)
subprocess_kwargs = alter_subprocess_kwargs_by_platform(
**subprocess_kwargs)
return subprocess.Popen(cmdstr, **subprocess_kwargs) | python | def run_shell_command(cmdstr, **subprocess_kwargs):
"""
Execute the given shell command.
Note that *args and **kwargs will be passed to the subprocess call.
If 'shell' is given in subprocess_kwargs it must be True,
otherwise ProgramError will be raised.
.
If 'executable' is not given in subprocess_kwargs, it will
be set to the value of the SHELL environment variable.
Note that stdin, stdout and stderr will be set by default
to PIPE unless specified in subprocess_kwargs.
:str cmdstr: The string run as a shell command.
:subprocess_kwargs: These will be passed to subprocess.Popen.
"""
if 'shell' in subprocess_kwargs and not subprocess_kwargs['shell']:
raise ProgramError(
'The "shell" kwarg may be omitted, but if '
'provided it must be True.')
else:
subprocess_kwargs['shell'] = True
if 'executable' not in subprocess_kwargs:
subprocess_kwargs['executable'] = os.getenv('SHELL')
for stream in ['stdin', 'stdout', 'stderr']:
subprocess_kwargs.setdefault(stream, subprocess.PIPE)
subprocess_kwargs = alter_subprocess_kwargs_by_platform(
**subprocess_kwargs)
return subprocess.Popen(cmdstr, **subprocess_kwargs) | [
"def",
"run_shell_command",
"(",
"cmdstr",
",",
"*",
"*",
"subprocess_kwargs",
")",
":",
"if",
"'shell'",
"in",
"subprocess_kwargs",
"and",
"not",
"subprocess_kwargs",
"[",
"'shell'",
"]",
":",
"raise",
"ProgramError",
"(",
"'The \"shell\" kwarg may be omitted, but if '",
"'provided it must be True.'",
")",
"else",
":",
"subprocess_kwargs",
"[",
"'shell'",
"]",
"=",
"True",
"if",
"'executable'",
"not",
"in",
"subprocess_kwargs",
":",
"subprocess_kwargs",
"[",
"'executable'",
"]",
"=",
"os",
".",
"getenv",
"(",
"'SHELL'",
")",
"for",
"stream",
"in",
"[",
"'stdin'",
",",
"'stdout'",
",",
"'stderr'",
"]",
":",
"subprocess_kwargs",
".",
"setdefault",
"(",
"stream",
",",
"subprocess",
".",
"PIPE",
")",
"subprocess_kwargs",
"=",
"alter_subprocess_kwargs_by_platform",
"(",
"*",
"*",
"subprocess_kwargs",
")",
"return",
"subprocess",
".",
"Popen",
"(",
"cmdstr",
",",
"*",
"*",
"subprocess_kwargs",
")"
] | Execute the given shell command.
Note that *args and **kwargs will be passed to the subprocess call.
If 'shell' is given in subprocess_kwargs it must be True,
otherwise ProgramError will be raised.
.
If 'executable' is not given in subprocess_kwargs, it will
be set to the value of the SHELL environment variable.
Note that stdin, stdout and stderr will be set by default
to PIPE unless specified in subprocess_kwargs.
:str cmdstr: The string run as a shell command.
:subprocess_kwargs: These will be passed to subprocess.Popen. | [
"Execute",
"the",
"given",
"shell",
"command",
".",
"Note",
"that",
"*",
"args",
"and",
"**",
"kwargs",
"will",
"be",
"passed",
"to",
"the",
"subprocess",
"call",
".",
"If",
"shell",
"is",
"given",
"in",
"subprocess_kwargs",
"it",
"must",
"be",
"True",
"otherwise",
"ProgramError",
"will",
"be",
"raised",
".",
".",
"If",
"executable",
"is",
"not",
"given",
"in",
"subprocess_kwargs",
"it",
"will",
"be",
"set",
"to",
"the",
"value",
"of",
"the",
"SHELL",
"environment",
"variable",
".",
"Note",
"that",
"stdin",
"stdout",
"and",
"stderr",
"will",
"be",
"set",
"by",
"default",
"to",
"PIPE",
"unless",
"specified",
"in",
"subprocess_kwargs",
".",
":",
"str",
"cmdstr",
":",
"The",
"string",
"run",
"as",
"a",
"shell",
"command",
".",
":",
"subprocess_kwargs",
":",
"These",
"will",
"be",
"passed",
"to",
"subprocess",
".",
"Popen",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/programs.py#L110-L142 | train |
spyder-ide/spyder | spyder/utils/programs.py | run_program | def run_program(program, args=None, **subprocess_kwargs):
"""
Run program in a separate process.
NOTE: returns the process object created by
`subprocess.Popen()`. This can be used with
`proc.communicate()` for example.
If 'shell' appears in the kwargs, it must be False,
otherwise ProgramError will be raised.
If only the program name is given and not the full path,
a lookup will be performed to find the program. If the
lookup fails, ProgramError will be raised.
Note that stdin, stdout and stderr will be set by default
to PIPE unless specified in subprocess_kwargs.
:str program: The name of the program to run.
:list args: The program arguments.
:subprocess_kwargs: These will be passed to subprocess.Popen.
"""
if 'shell' in subprocess_kwargs and subprocess_kwargs['shell']:
raise ProgramError(
"This function is only for non-shell programs, "
"use run_shell_command() instead.")
fullcmd = find_program(program)
if not fullcmd:
raise ProgramError("Program %s was not found" % program)
# As per subprocess, we make a complete list of prog+args
fullcmd = [fullcmd] + (args or [])
for stream in ['stdin', 'stdout', 'stderr']:
subprocess_kwargs.setdefault(stream, subprocess.PIPE)
subprocess_kwargs = alter_subprocess_kwargs_by_platform(
**subprocess_kwargs)
return subprocess.Popen(fullcmd, **subprocess_kwargs) | python | def run_program(program, args=None, **subprocess_kwargs):
"""
Run program in a separate process.
NOTE: returns the process object created by
`subprocess.Popen()`. This can be used with
`proc.communicate()` for example.
If 'shell' appears in the kwargs, it must be False,
otherwise ProgramError will be raised.
If only the program name is given and not the full path,
a lookup will be performed to find the program. If the
lookup fails, ProgramError will be raised.
Note that stdin, stdout and stderr will be set by default
to PIPE unless specified in subprocess_kwargs.
:str program: The name of the program to run.
:list args: The program arguments.
:subprocess_kwargs: These will be passed to subprocess.Popen.
"""
if 'shell' in subprocess_kwargs and subprocess_kwargs['shell']:
raise ProgramError(
"This function is only for non-shell programs, "
"use run_shell_command() instead.")
fullcmd = find_program(program)
if not fullcmd:
raise ProgramError("Program %s was not found" % program)
# As per subprocess, we make a complete list of prog+args
fullcmd = [fullcmd] + (args or [])
for stream in ['stdin', 'stdout', 'stderr']:
subprocess_kwargs.setdefault(stream, subprocess.PIPE)
subprocess_kwargs = alter_subprocess_kwargs_by_platform(
**subprocess_kwargs)
return subprocess.Popen(fullcmd, **subprocess_kwargs) | [
"def",
"run_program",
"(",
"program",
",",
"args",
"=",
"None",
",",
"*",
"*",
"subprocess_kwargs",
")",
":",
"if",
"'shell'",
"in",
"subprocess_kwargs",
"and",
"subprocess_kwargs",
"[",
"'shell'",
"]",
":",
"raise",
"ProgramError",
"(",
"\"This function is only for non-shell programs, \"",
"\"use run_shell_command() instead.\"",
")",
"fullcmd",
"=",
"find_program",
"(",
"program",
")",
"if",
"not",
"fullcmd",
":",
"raise",
"ProgramError",
"(",
"\"Program %s was not found\"",
"%",
"program",
")",
"# As per subprocess, we make a complete list of prog+args\r",
"fullcmd",
"=",
"[",
"fullcmd",
"]",
"+",
"(",
"args",
"or",
"[",
"]",
")",
"for",
"stream",
"in",
"[",
"'stdin'",
",",
"'stdout'",
",",
"'stderr'",
"]",
":",
"subprocess_kwargs",
".",
"setdefault",
"(",
"stream",
",",
"subprocess",
".",
"PIPE",
")",
"subprocess_kwargs",
"=",
"alter_subprocess_kwargs_by_platform",
"(",
"*",
"*",
"subprocess_kwargs",
")",
"return",
"subprocess",
".",
"Popen",
"(",
"fullcmd",
",",
"*",
"*",
"subprocess_kwargs",
")"
] | Run program in a separate process.
NOTE: returns the process object created by
`subprocess.Popen()`. This can be used with
`proc.communicate()` for example.
If 'shell' appears in the kwargs, it must be False,
otherwise ProgramError will be raised.
If only the program name is given and not the full path,
a lookup will be performed to find the program. If the
lookup fails, ProgramError will be raised.
Note that stdin, stdout and stderr will be set by default
to PIPE unless specified in subprocess_kwargs.
:str program: The name of the program to run.
:list args: The program arguments.
:subprocess_kwargs: These will be passed to subprocess.Popen. | [
"Run",
"program",
"in",
"a",
"separate",
"process",
".",
"NOTE",
":",
"returns",
"the",
"process",
"object",
"created",
"by",
"subprocess",
".",
"Popen",
"()",
".",
"This",
"can",
"be",
"used",
"with",
"proc",
".",
"communicate",
"()",
"for",
"example",
".",
"If",
"shell",
"appears",
"in",
"the",
"kwargs",
"it",
"must",
"be",
"False",
"otherwise",
"ProgramError",
"will",
"be",
"raised",
".",
"If",
"only",
"the",
"program",
"name",
"is",
"given",
"and",
"not",
"the",
"full",
"path",
"a",
"lookup",
"will",
"be",
"performed",
"to",
"find",
"the",
"program",
".",
"If",
"the",
"lookup",
"fails",
"ProgramError",
"will",
"be",
"raised",
".",
"Note",
"that",
"stdin",
"stdout",
"and",
"stderr",
"will",
"be",
"set",
"by",
"default",
"to",
"PIPE",
"unless",
"specified",
"in",
"subprocess_kwargs",
".",
":",
"str",
"program",
":",
"The",
"name",
"of",
"the",
"program",
"to",
"run",
".",
":",
"list",
"args",
":",
"The",
"program",
"arguments",
".",
":",
"subprocess_kwargs",
":",
"These",
"will",
"be",
"passed",
"to",
"subprocess",
".",
"Popen",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/programs.py#L145-L180 | train |
spyder-ide/spyder | spyder/utils/programs.py | start_file | def start_file(filename):
"""
Generalized os.startfile for all platforms supported by Qt
This function is simply wrapping QDesktopServices.openUrl
Returns True if successfull, otherwise returns False.
"""
from qtpy.QtCore import QUrl
from qtpy.QtGui import QDesktopServices
# We need to use setUrl instead of setPath because this is the only
# cross-platform way to open external files. setPath fails completely on
# Mac and doesn't open non-ascii files on Linux.
# Fixes Issue 740
url = QUrl()
url.setUrl(filename)
return QDesktopServices.openUrl(url) | python | def start_file(filename):
"""
Generalized os.startfile for all platforms supported by Qt
This function is simply wrapping QDesktopServices.openUrl
Returns True if successfull, otherwise returns False.
"""
from qtpy.QtCore import QUrl
from qtpy.QtGui import QDesktopServices
# We need to use setUrl instead of setPath because this is the only
# cross-platform way to open external files. setPath fails completely on
# Mac and doesn't open non-ascii files on Linux.
# Fixes Issue 740
url = QUrl()
url.setUrl(filename)
return QDesktopServices.openUrl(url) | [
"def",
"start_file",
"(",
"filename",
")",
":",
"from",
"qtpy",
".",
"QtCore",
"import",
"QUrl",
"from",
"qtpy",
".",
"QtGui",
"import",
"QDesktopServices",
"# We need to use setUrl instead of setPath because this is the only\r",
"# cross-platform way to open external files. setPath fails completely on\r",
"# Mac and doesn't open non-ascii files on Linux.\r",
"# Fixes Issue 740\r",
"url",
"=",
"QUrl",
"(",
")",
"url",
".",
"setUrl",
"(",
"filename",
")",
"return",
"QDesktopServices",
".",
"openUrl",
"(",
"url",
")"
] | Generalized os.startfile for all platforms supported by Qt
This function is simply wrapping QDesktopServices.openUrl
Returns True if successfull, otherwise returns False. | [
"Generalized",
"os",
".",
"startfile",
"for",
"all",
"platforms",
"supported",
"by",
"Qt",
"This",
"function",
"is",
"simply",
"wrapping",
"QDesktopServices",
".",
"openUrl",
"Returns",
"True",
"if",
"successfull",
"otherwise",
"returns",
"False",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/programs.py#L183-L200 | train |
spyder-ide/spyder | spyder/utils/programs.py | python_script_exists | def python_script_exists(package=None, module=None):
"""
Return absolute path if Python script exists (otherwise, return None)
package=None -> module is in sys.path (standard library modules)
"""
assert module is not None
try:
if package is None:
path = imp.find_module(module)[1]
else:
path = osp.join(imp.find_module(package)[1], module)+'.py'
except ImportError:
return
if not osp.isfile(path):
path += 'w'
if osp.isfile(path):
return path | python | def python_script_exists(package=None, module=None):
"""
Return absolute path if Python script exists (otherwise, return None)
package=None -> module is in sys.path (standard library modules)
"""
assert module is not None
try:
if package is None:
path = imp.find_module(module)[1]
else:
path = osp.join(imp.find_module(package)[1], module)+'.py'
except ImportError:
return
if not osp.isfile(path):
path += 'w'
if osp.isfile(path):
return path | [
"def",
"python_script_exists",
"(",
"package",
"=",
"None",
",",
"module",
"=",
"None",
")",
":",
"assert",
"module",
"is",
"not",
"None",
"try",
":",
"if",
"package",
"is",
"None",
":",
"path",
"=",
"imp",
".",
"find_module",
"(",
"module",
")",
"[",
"1",
"]",
"else",
":",
"path",
"=",
"osp",
".",
"join",
"(",
"imp",
".",
"find_module",
"(",
"package",
")",
"[",
"1",
"]",
",",
"module",
")",
"+",
"'.py'",
"except",
"ImportError",
":",
"return",
"if",
"not",
"osp",
".",
"isfile",
"(",
"path",
")",
":",
"path",
"+=",
"'w'",
"if",
"osp",
".",
"isfile",
"(",
"path",
")",
":",
"return",
"path"
] | Return absolute path if Python script exists (otherwise, return None)
package=None -> module is in sys.path (standard library modules) | [
"Return",
"absolute",
"path",
"if",
"Python",
"script",
"exists",
"(",
"otherwise",
"return",
"None",
")",
"package",
"=",
"None",
"-",
">",
"module",
"is",
"in",
"sys",
".",
"path",
"(",
"standard",
"library",
"modules",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/programs.py#L203-L219 | train |
spyder-ide/spyder | spyder/utils/programs.py | run_python_script | def run_python_script(package=None, module=None, args=[], p_args=[]):
"""
Run Python script in a separate process
package=None -> module is in sys.path (standard library modules)
"""
assert module is not None
assert isinstance(args, (tuple, list)) and isinstance(p_args, (tuple, list))
path = python_script_exists(package, module)
run_program(sys.executable, p_args + [path] + args) | python | def run_python_script(package=None, module=None, args=[], p_args=[]):
"""
Run Python script in a separate process
package=None -> module is in sys.path (standard library modules)
"""
assert module is not None
assert isinstance(args, (tuple, list)) and isinstance(p_args, (tuple, list))
path = python_script_exists(package, module)
run_program(sys.executable, p_args + [path] + args) | [
"def",
"run_python_script",
"(",
"package",
"=",
"None",
",",
"module",
"=",
"None",
",",
"args",
"=",
"[",
"]",
",",
"p_args",
"=",
"[",
"]",
")",
":",
"assert",
"module",
"is",
"not",
"None",
"assert",
"isinstance",
"(",
"args",
",",
"(",
"tuple",
",",
"list",
")",
")",
"and",
"isinstance",
"(",
"p_args",
",",
"(",
"tuple",
",",
"list",
")",
")",
"path",
"=",
"python_script_exists",
"(",
"package",
",",
"module",
")",
"run_program",
"(",
"sys",
".",
"executable",
",",
"p_args",
"+",
"[",
"path",
"]",
"+",
"args",
")"
] | Run Python script in a separate process
package=None -> module is in sys.path (standard library modules) | [
"Run",
"Python",
"script",
"in",
"a",
"separate",
"process",
"package",
"=",
"None",
"-",
">",
"module",
"is",
"in",
"sys",
".",
"path",
"(",
"standard",
"library",
"modules",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/programs.py#L222-L230 | train |
spyder-ide/spyder | spyder/utils/programs.py | shell_split | def shell_split(text):
"""
Split the string `text` using shell-like syntax
This avoids breaking single/double-quoted strings (e.g. containing
strings with spaces). This function is almost equivalent to the shlex.split
function (see standard library `shlex`) except that it is supporting
unicode strings (shlex does not support unicode until Python 2.7.3).
"""
assert is_text_string(text) # in case a QString is passed...
pattern = r'(\s+|(?<!\\)".*?(?<!\\)"|(?<!\\)\'.*?(?<!\\)\')'
out = []
for token in re.split(pattern, text):
if token.strip():
out.append(token.strip('"').strip("'"))
return out | python | def shell_split(text):
"""
Split the string `text` using shell-like syntax
This avoids breaking single/double-quoted strings (e.g. containing
strings with spaces). This function is almost equivalent to the shlex.split
function (see standard library `shlex`) except that it is supporting
unicode strings (shlex does not support unicode until Python 2.7.3).
"""
assert is_text_string(text) # in case a QString is passed...
pattern = r'(\s+|(?<!\\)".*?(?<!\\)"|(?<!\\)\'.*?(?<!\\)\')'
out = []
for token in re.split(pattern, text):
if token.strip():
out.append(token.strip('"').strip("'"))
return out | [
"def",
"shell_split",
"(",
"text",
")",
":",
"assert",
"is_text_string",
"(",
"text",
")",
"# in case a QString is passed...\r",
"pattern",
"=",
"r'(\\s+|(?<!\\\\)\".*?(?<!\\\\)\"|(?<!\\\\)\\'.*?(?<!\\\\)\\')'",
"out",
"=",
"[",
"]",
"for",
"token",
"in",
"re",
".",
"split",
"(",
"pattern",
",",
"text",
")",
":",
"if",
"token",
".",
"strip",
"(",
")",
":",
"out",
".",
"append",
"(",
"token",
".",
"strip",
"(",
"'\"'",
")",
".",
"strip",
"(",
"\"'\"",
")",
")",
"return",
"out"
] | Split the string `text` using shell-like syntax
This avoids breaking single/double-quoted strings (e.g. containing
strings with spaces). This function is almost equivalent to the shlex.split
function (see standard library `shlex`) except that it is supporting
unicode strings (shlex does not support unicode until Python 2.7.3). | [
"Split",
"the",
"string",
"text",
"using",
"shell",
"-",
"like",
"syntax",
"This",
"avoids",
"breaking",
"single",
"/",
"double",
"-",
"quoted",
"strings",
"(",
"e",
".",
"g",
".",
"containing",
"strings",
"with",
"spaces",
")",
".",
"This",
"function",
"is",
"almost",
"equivalent",
"to",
"the",
"shlex",
".",
"split",
"function",
"(",
"see",
"standard",
"library",
"shlex",
")",
"except",
"that",
"it",
"is",
"supporting",
"unicode",
"strings",
"(",
"shlex",
"does",
"not",
"support",
"unicode",
"until",
"Python",
"2",
".",
"7",
".",
"3",
")",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/programs.py#L233-L248 | train |
spyder-ide/spyder | spyder/utils/programs.py | get_python_args | def get_python_args(fname, python_args, interact, debug, end_args):
"""Construct Python interpreter arguments"""
p_args = []
if python_args is not None:
p_args += python_args.split()
if interact:
p_args.append('-i')
if debug:
p_args.extend(['-m', 'pdb'])
if fname is not None:
if os.name == 'nt' and debug:
# When calling pdb on Windows, one has to replace backslashes by
# slashes to avoid confusion with escape characters (otherwise,
# for example, '\t' will be interpreted as a tabulation):
p_args.append(osp.normpath(fname).replace(os.sep, '/'))
else:
p_args.append(fname)
if end_args:
p_args.extend(shell_split(end_args))
return p_args | python | def get_python_args(fname, python_args, interact, debug, end_args):
"""Construct Python interpreter arguments"""
p_args = []
if python_args is not None:
p_args += python_args.split()
if interact:
p_args.append('-i')
if debug:
p_args.extend(['-m', 'pdb'])
if fname is not None:
if os.name == 'nt' and debug:
# When calling pdb on Windows, one has to replace backslashes by
# slashes to avoid confusion with escape characters (otherwise,
# for example, '\t' will be interpreted as a tabulation):
p_args.append(osp.normpath(fname).replace(os.sep, '/'))
else:
p_args.append(fname)
if end_args:
p_args.extend(shell_split(end_args))
return p_args | [
"def",
"get_python_args",
"(",
"fname",
",",
"python_args",
",",
"interact",
",",
"debug",
",",
"end_args",
")",
":",
"p_args",
"=",
"[",
"]",
"if",
"python_args",
"is",
"not",
"None",
":",
"p_args",
"+=",
"python_args",
".",
"split",
"(",
")",
"if",
"interact",
":",
"p_args",
".",
"append",
"(",
"'-i'",
")",
"if",
"debug",
":",
"p_args",
".",
"extend",
"(",
"[",
"'-m'",
",",
"'pdb'",
"]",
")",
"if",
"fname",
"is",
"not",
"None",
":",
"if",
"os",
".",
"name",
"==",
"'nt'",
"and",
"debug",
":",
"# When calling pdb on Windows, one has to replace backslashes by\r",
"# slashes to avoid confusion with escape characters (otherwise, \r",
"# for example, '\\t' will be interpreted as a tabulation):\r",
"p_args",
".",
"append",
"(",
"osp",
".",
"normpath",
"(",
"fname",
")",
".",
"replace",
"(",
"os",
".",
"sep",
",",
"'/'",
")",
")",
"else",
":",
"p_args",
".",
"append",
"(",
"fname",
")",
"if",
"end_args",
":",
"p_args",
".",
"extend",
"(",
"shell_split",
"(",
"end_args",
")",
")",
"return",
"p_args"
] | Construct Python interpreter arguments | [
"Construct",
"Python",
"interpreter",
"arguments"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/programs.py#L251-L270 | train |
spyder-ide/spyder | spyder/utils/programs.py | run_python_script_in_terminal | def run_python_script_in_terminal(fname, wdir, args, interact,
debug, python_args, executable=None):
"""
Run Python script in an external system terminal.
:str wdir: working directory, may be empty.
"""
if executable is None:
executable = get_python_executable()
# If fname or python_exe contains spaces, it can't be ran on Windows, so we
# have to enclose them in quotes. Also wdir can come with / as os.sep, so
# we need to take care of it.
if os.name == 'nt':
fname = '"' + fname + '"'
wdir = wdir.replace('/', '\\')
executable = '"' + executable + '"'
p_args = [executable]
p_args += get_python_args(fname, python_args, interact, debug, args)
if os.name == 'nt':
cmd = 'start cmd.exe /c "cd %s && ' % wdir + ' '.join(p_args) + '"'
# Command line and cwd have to be converted to the filesystem
# encoding before passing them to subprocess, but only for
# Python 2.
# See https://bugs.python.org/issue1759845#msg74142 and Issue 1856
if PY2:
cmd = encoding.to_fs_from_unicode(cmd)
wdir = encoding.to_fs_from_unicode(wdir)
try:
run_shell_command(cmd, cwd=wdir)
except WindowsError:
from qtpy.QtWidgets import QMessageBox
from spyder.config.base import _
QMessageBox.critical(None, _('Run'),
_("It was not possible to run this file in "
"an external terminal"),
QMessageBox.Ok)
elif os.name == 'posix':
programs = [{'cmd': 'gnome-terminal',
'wdir-option': '--working-directory',
'execute-option': '-x'},
{'cmd': 'konsole',
'wdir-option': '--workdir',
'execute-option': '-e'},
{'cmd': 'xfce4-terminal',
'wdir-option': '--working-directory',
'execute-option': '-x'},
{'cmd': 'xterm',
'wdir-option': None,
'execute-option': '-e'},]
for program in programs:
if is_program_installed(program['cmd']):
arglist = []
if program['wdir-option'] and wdir:
arglist += [program['wdir-option'], wdir]
arglist.append(program['execute-option'])
arglist += p_args
if wdir:
run_program(program['cmd'], arglist, cwd=wdir)
else:
run_program(program['cmd'], arglist)
return
# TODO: Add a fallback to OSX
else:
raise NotImplementedError | python | def run_python_script_in_terminal(fname, wdir, args, interact,
debug, python_args, executable=None):
"""
Run Python script in an external system terminal.
:str wdir: working directory, may be empty.
"""
if executable is None:
executable = get_python_executable()
# If fname or python_exe contains spaces, it can't be ran on Windows, so we
# have to enclose them in quotes. Also wdir can come with / as os.sep, so
# we need to take care of it.
if os.name == 'nt':
fname = '"' + fname + '"'
wdir = wdir.replace('/', '\\')
executable = '"' + executable + '"'
p_args = [executable]
p_args += get_python_args(fname, python_args, interact, debug, args)
if os.name == 'nt':
cmd = 'start cmd.exe /c "cd %s && ' % wdir + ' '.join(p_args) + '"'
# Command line and cwd have to be converted to the filesystem
# encoding before passing them to subprocess, but only for
# Python 2.
# See https://bugs.python.org/issue1759845#msg74142 and Issue 1856
if PY2:
cmd = encoding.to_fs_from_unicode(cmd)
wdir = encoding.to_fs_from_unicode(wdir)
try:
run_shell_command(cmd, cwd=wdir)
except WindowsError:
from qtpy.QtWidgets import QMessageBox
from spyder.config.base import _
QMessageBox.critical(None, _('Run'),
_("It was not possible to run this file in "
"an external terminal"),
QMessageBox.Ok)
elif os.name == 'posix':
programs = [{'cmd': 'gnome-terminal',
'wdir-option': '--working-directory',
'execute-option': '-x'},
{'cmd': 'konsole',
'wdir-option': '--workdir',
'execute-option': '-e'},
{'cmd': 'xfce4-terminal',
'wdir-option': '--working-directory',
'execute-option': '-x'},
{'cmd': 'xterm',
'wdir-option': None,
'execute-option': '-e'},]
for program in programs:
if is_program_installed(program['cmd']):
arglist = []
if program['wdir-option'] and wdir:
arglist += [program['wdir-option'], wdir]
arglist.append(program['execute-option'])
arglist += p_args
if wdir:
run_program(program['cmd'], arglist, cwd=wdir)
else:
run_program(program['cmd'], arglist)
return
# TODO: Add a fallback to OSX
else:
raise NotImplementedError | [
"def",
"run_python_script_in_terminal",
"(",
"fname",
",",
"wdir",
",",
"args",
",",
"interact",
",",
"debug",
",",
"python_args",
",",
"executable",
"=",
"None",
")",
":",
"if",
"executable",
"is",
"None",
":",
"executable",
"=",
"get_python_executable",
"(",
")",
"# If fname or python_exe contains spaces, it can't be ran on Windows, so we\r",
"# have to enclose them in quotes. Also wdir can come with / as os.sep, so\r",
"# we need to take care of it.\r",
"if",
"os",
".",
"name",
"==",
"'nt'",
":",
"fname",
"=",
"'\"'",
"+",
"fname",
"+",
"'\"'",
"wdir",
"=",
"wdir",
".",
"replace",
"(",
"'/'",
",",
"'\\\\'",
")",
"executable",
"=",
"'\"'",
"+",
"executable",
"+",
"'\"'",
"p_args",
"=",
"[",
"executable",
"]",
"p_args",
"+=",
"get_python_args",
"(",
"fname",
",",
"python_args",
",",
"interact",
",",
"debug",
",",
"args",
")",
"if",
"os",
".",
"name",
"==",
"'nt'",
":",
"cmd",
"=",
"'start cmd.exe /c \"cd %s && '",
"%",
"wdir",
"+",
"' '",
".",
"join",
"(",
"p_args",
")",
"+",
"'\"'",
"# Command line and cwd have to be converted to the filesystem\r",
"# encoding before passing them to subprocess, but only for\r",
"# Python 2.\r",
"# See https://bugs.python.org/issue1759845#msg74142 and Issue 1856\r",
"if",
"PY2",
":",
"cmd",
"=",
"encoding",
".",
"to_fs_from_unicode",
"(",
"cmd",
")",
"wdir",
"=",
"encoding",
".",
"to_fs_from_unicode",
"(",
"wdir",
")",
"try",
":",
"run_shell_command",
"(",
"cmd",
",",
"cwd",
"=",
"wdir",
")",
"except",
"WindowsError",
":",
"from",
"qtpy",
".",
"QtWidgets",
"import",
"QMessageBox",
"from",
"spyder",
".",
"config",
".",
"base",
"import",
"_",
"QMessageBox",
".",
"critical",
"(",
"None",
",",
"_",
"(",
"'Run'",
")",
",",
"_",
"(",
"\"It was not possible to run this file in \"",
"\"an external terminal\"",
")",
",",
"QMessageBox",
".",
"Ok",
")",
"elif",
"os",
".",
"name",
"==",
"'posix'",
":",
"programs",
"=",
"[",
"{",
"'cmd'",
":",
"'gnome-terminal'",
",",
"'wdir-option'",
":",
"'--working-directory'",
",",
"'execute-option'",
":",
"'-x'",
"}",
",",
"{",
"'cmd'",
":",
"'konsole'",
",",
"'wdir-option'",
":",
"'--workdir'",
",",
"'execute-option'",
":",
"'-e'",
"}",
",",
"{",
"'cmd'",
":",
"'xfce4-terminal'",
",",
"'wdir-option'",
":",
"'--working-directory'",
",",
"'execute-option'",
":",
"'-x'",
"}",
",",
"{",
"'cmd'",
":",
"'xterm'",
",",
"'wdir-option'",
":",
"None",
",",
"'execute-option'",
":",
"'-e'",
"}",
",",
"]",
"for",
"program",
"in",
"programs",
":",
"if",
"is_program_installed",
"(",
"program",
"[",
"'cmd'",
"]",
")",
":",
"arglist",
"=",
"[",
"]",
"if",
"program",
"[",
"'wdir-option'",
"]",
"and",
"wdir",
":",
"arglist",
"+=",
"[",
"program",
"[",
"'wdir-option'",
"]",
",",
"wdir",
"]",
"arglist",
".",
"append",
"(",
"program",
"[",
"'execute-option'",
"]",
")",
"arglist",
"+=",
"p_args",
"if",
"wdir",
":",
"run_program",
"(",
"program",
"[",
"'cmd'",
"]",
",",
"arglist",
",",
"cwd",
"=",
"wdir",
")",
"else",
":",
"run_program",
"(",
"program",
"[",
"'cmd'",
"]",
",",
"arglist",
")",
"return",
"# TODO: Add a fallback to OSX\r",
"else",
":",
"raise",
"NotImplementedError"
] | Run Python script in an external system terminal.
:str wdir: working directory, may be empty. | [
"Run",
"Python",
"script",
"in",
"an",
"external",
"system",
"terminal",
".",
":",
"str",
"wdir",
":",
"working",
"directory",
"may",
"be",
"empty",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/programs.py#L273-L339 | train |
spyder-ide/spyder | spyder/utils/programs.py | check_version | def check_version(actver, version, cmp_op):
"""
Check version string of an active module against a required version.
If dev/prerelease tags result in TypeError for string-number comparison,
it is assumed that the dependency is satisfied.
Users on dev branches are responsible for keeping their own packages up to
date.
Copyright (C) 2013 The IPython Development Team
Distributed under the terms of the BSD License.
"""
if isinstance(actver, tuple):
actver = '.'.join([str(i) for i in actver])
# Hacks needed so that LooseVersion understands that (for example)
# version = '3.0.0' is in fact bigger than actver = '3.0.0rc1'
if is_stable_version(version) and not is_stable_version(actver) and \
actver.startswith(version) and version != actver:
version = version + 'zz'
elif is_stable_version(actver) and not is_stable_version(version) and \
version.startswith(actver) and version != actver:
actver = actver + 'zz'
try:
if cmp_op == '>':
return LooseVersion(actver) > LooseVersion(version)
elif cmp_op == '>=':
return LooseVersion(actver) >= LooseVersion(version)
elif cmp_op == '=':
return LooseVersion(actver) == LooseVersion(version)
elif cmp_op == '<':
return LooseVersion(actver) < LooseVersion(version)
elif cmp_op == '<=':
return LooseVersion(actver) <= LooseVersion(version)
else:
return False
except TypeError:
return True | python | def check_version(actver, version, cmp_op):
"""
Check version string of an active module against a required version.
If dev/prerelease tags result in TypeError for string-number comparison,
it is assumed that the dependency is satisfied.
Users on dev branches are responsible for keeping their own packages up to
date.
Copyright (C) 2013 The IPython Development Team
Distributed under the terms of the BSD License.
"""
if isinstance(actver, tuple):
actver = '.'.join([str(i) for i in actver])
# Hacks needed so that LooseVersion understands that (for example)
# version = '3.0.0' is in fact bigger than actver = '3.0.0rc1'
if is_stable_version(version) and not is_stable_version(actver) and \
actver.startswith(version) and version != actver:
version = version + 'zz'
elif is_stable_version(actver) and not is_stable_version(version) and \
version.startswith(actver) and version != actver:
actver = actver + 'zz'
try:
if cmp_op == '>':
return LooseVersion(actver) > LooseVersion(version)
elif cmp_op == '>=':
return LooseVersion(actver) >= LooseVersion(version)
elif cmp_op == '=':
return LooseVersion(actver) == LooseVersion(version)
elif cmp_op == '<':
return LooseVersion(actver) < LooseVersion(version)
elif cmp_op == '<=':
return LooseVersion(actver) <= LooseVersion(version)
else:
return False
except TypeError:
return True | [
"def",
"check_version",
"(",
"actver",
",",
"version",
",",
"cmp_op",
")",
":",
"if",
"isinstance",
"(",
"actver",
",",
"tuple",
")",
":",
"actver",
"=",
"'.'",
".",
"join",
"(",
"[",
"str",
"(",
"i",
")",
"for",
"i",
"in",
"actver",
"]",
")",
"# Hacks needed so that LooseVersion understands that (for example)\r",
"# version = '3.0.0' is in fact bigger than actver = '3.0.0rc1'\r",
"if",
"is_stable_version",
"(",
"version",
")",
"and",
"not",
"is_stable_version",
"(",
"actver",
")",
"and",
"actver",
".",
"startswith",
"(",
"version",
")",
"and",
"version",
"!=",
"actver",
":",
"version",
"=",
"version",
"+",
"'zz'",
"elif",
"is_stable_version",
"(",
"actver",
")",
"and",
"not",
"is_stable_version",
"(",
"version",
")",
"and",
"version",
".",
"startswith",
"(",
"actver",
")",
"and",
"version",
"!=",
"actver",
":",
"actver",
"=",
"actver",
"+",
"'zz'",
"try",
":",
"if",
"cmp_op",
"==",
"'>'",
":",
"return",
"LooseVersion",
"(",
"actver",
")",
">",
"LooseVersion",
"(",
"version",
")",
"elif",
"cmp_op",
"==",
"'>='",
":",
"return",
"LooseVersion",
"(",
"actver",
")",
">=",
"LooseVersion",
"(",
"version",
")",
"elif",
"cmp_op",
"==",
"'='",
":",
"return",
"LooseVersion",
"(",
"actver",
")",
"==",
"LooseVersion",
"(",
"version",
")",
"elif",
"cmp_op",
"==",
"'<'",
":",
"return",
"LooseVersion",
"(",
"actver",
")",
"<",
"LooseVersion",
"(",
"version",
")",
"elif",
"cmp_op",
"==",
"'<='",
":",
"return",
"LooseVersion",
"(",
"actver",
")",
"<=",
"LooseVersion",
"(",
"version",
")",
"else",
":",
"return",
"False",
"except",
"TypeError",
":",
"return",
"True"
] | Check version string of an active module against a required version.
If dev/prerelease tags result in TypeError for string-number comparison,
it is assumed that the dependency is satisfied.
Users on dev branches are responsible for keeping their own packages up to
date.
Copyright (C) 2013 The IPython Development Team
Distributed under the terms of the BSD License. | [
"Check",
"version",
"string",
"of",
"an",
"active",
"module",
"against",
"a",
"required",
"version",
".",
"If",
"dev",
"/",
"prerelease",
"tags",
"result",
"in",
"TypeError",
"for",
"string",
"-",
"number",
"comparison",
"it",
"is",
"assumed",
"that",
"the",
"dependency",
"is",
"satisfied",
".",
"Users",
"on",
"dev",
"branches",
"are",
"responsible",
"for",
"keeping",
"their",
"own",
"packages",
"up",
"to",
"date",
".",
"Copyright",
"(",
"C",
")",
"2013",
"The",
"IPython",
"Development",
"Team",
"Distributed",
"under",
"the",
"terms",
"of",
"the",
"BSD",
"License",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/programs.py#L342-L381 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.