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/utils/qthelpers.py
create_bookmark_action
def create_bookmark_action(parent, url, title, icon=None, shortcut=None): """Create bookmark action""" @Slot() def open_url(): return programs.start_file(url) return create_action( parent, title, shortcut=shortcut, icon=icon, triggered=open_url)
python
def create_bookmark_action(parent, url, title, icon=None, shortcut=None): """Create bookmark action""" @Slot() def open_url(): return programs.start_file(url) return create_action( parent, title, shortcut=shortcut, icon=icon, triggered=open_url)
[ "def", "create_bookmark_action", "(", "parent", ",", "url", ",", "title", ",", "icon", "=", "None", ",", "shortcut", "=", "None", ")", ":", "@", "Slot", "(", ")", "def", "open_url", "(", ")", ":", "return", "programs", ".", "start_file", "(", "url", ")", "return", "create_action", "(", "parent", ",", "title", ",", "shortcut", "=", "shortcut", ",", "icon", "=", "icon", ",", "triggered", "=", "open_url", ")" ]
Create bookmark action
[ "Create", "bookmark", "action" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/qthelpers.py#L335-L343
train
spyder-ide/spyder
spyder/utils/qthelpers.py
create_module_bookmark_actions
def create_module_bookmark_actions(parent, bookmarks): """ Create bookmark actions depending on module installation: bookmarks = ((module_name, url, title), ...) """ actions = [] for key, url, title in bookmarks: # Create actions for scientific distros only if Spyder is installed # under them create_act = True if key == 'winpython': if not programs.is_module_installed(key): create_act = False if create_act: act = create_bookmark_action(parent, url, title) actions.append(act) return actions
python
def create_module_bookmark_actions(parent, bookmarks): """ Create bookmark actions depending on module installation: bookmarks = ((module_name, url, title), ...) """ actions = [] for key, url, title in bookmarks: # Create actions for scientific distros only if Spyder is installed # under them create_act = True if key == 'winpython': if not programs.is_module_installed(key): create_act = False if create_act: act = create_bookmark_action(parent, url, title) actions.append(act) return actions
[ "def", "create_module_bookmark_actions", "(", "parent", ",", "bookmarks", ")", ":", "actions", "=", "[", "]", "for", "key", ",", "url", ",", "title", "in", "bookmarks", ":", "# Create actions for scientific distros only if Spyder is installed\r", "# under them\r", "create_act", "=", "True", "if", "key", "==", "'winpython'", ":", "if", "not", "programs", ".", "is_module_installed", "(", "key", ")", ":", "create_act", "=", "False", "if", "create_act", ":", "act", "=", "create_bookmark_action", "(", "parent", ",", "url", ",", "title", ")", "actions", ".", "append", "(", "act", ")", "return", "actions" ]
Create bookmark actions depending on module installation: bookmarks = ((module_name, url, title), ...)
[ "Create", "bookmark", "actions", "depending", "on", "module", "installation", ":", "bookmarks", "=", "((", "module_name", "url", "title", ")", "...", ")" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/qthelpers.py#L346-L362
train
spyder-ide/spyder
spyder/utils/qthelpers.py
create_program_action
def create_program_action(parent, text, name, icon=None, nt_name=None): """Create action to run a program""" if is_text_string(icon): icon = get_icon(icon) if os.name == 'nt' and nt_name is not None: name = nt_name path = programs.find_program(name) if path is not None: return create_action(parent, text, icon=icon, triggered=lambda: programs.run_program(name))
python
def create_program_action(parent, text, name, icon=None, nt_name=None): """Create action to run a program""" if is_text_string(icon): icon = get_icon(icon) if os.name == 'nt' and nt_name is not None: name = nt_name path = programs.find_program(name) if path is not None: return create_action(parent, text, icon=icon, triggered=lambda: programs.run_program(name))
[ "def", "create_program_action", "(", "parent", ",", "text", ",", "name", ",", "icon", "=", "None", ",", "nt_name", "=", "None", ")", ":", "if", "is_text_string", "(", "icon", ")", ":", "icon", "=", "get_icon", "(", "icon", ")", "if", "os", ".", "name", "==", "'nt'", "and", "nt_name", "is", "not", "None", ":", "name", "=", "nt_name", "path", "=", "programs", ".", "find_program", "(", "name", ")", "if", "path", "is", "not", "None", ":", "return", "create_action", "(", "parent", ",", "text", ",", "icon", "=", "icon", ",", "triggered", "=", "lambda", ":", "programs", ".", "run_program", "(", "name", ")", ")" ]
Create action to run a program
[ "Create", "action", "to", "run", "a", "program" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/qthelpers.py#L365-L374
train
spyder-ide/spyder
spyder/utils/qthelpers.py
create_python_script_action
def create_python_script_action(parent, text, icon, package, module, args=[]): """Create action to run a GUI based Python script""" if is_text_string(icon): icon = get_icon(icon) if programs.python_script_exists(package, module): return create_action(parent, text, icon=icon, triggered=lambda: programs.run_python_script(package, module, args))
python
def create_python_script_action(parent, text, icon, package, module, args=[]): """Create action to run a GUI based Python script""" if is_text_string(icon): icon = get_icon(icon) if programs.python_script_exists(package, module): return create_action(parent, text, icon=icon, triggered=lambda: programs.run_python_script(package, module, args))
[ "def", "create_python_script_action", "(", "parent", ",", "text", ",", "icon", ",", "package", ",", "module", ",", "args", "=", "[", "]", ")", ":", "if", "is_text_string", "(", "icon", ")", ":", "icon", "=", "get_icon", "(", "icon", ")", "if", "programs", ".", "python_script_exists", "(", "package", ",", "module", ")", ":", "return", "create_action", "(", "parent", ",", "text", ",", "icon", "=", "icon", ",", "triggered", "=", "lambda", ":", "programs", ".", "run_python_script", "(", "package", ",", "module", ",", "args", ")", ")" ]
Create action to run a GUI based Python script
[ "Create", "action", "to", "run", "a", "GUI", "based", "Python", "script" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/qthelpers.py#L377-L384
train
spyder-ide/spyder
spyder/utils/qthelpers.py
get_filetype_icon
def get_filetype_icon(fname): """Return file type icon""" ext = osp.splitext(fname)[1] if ext.startswith('.'): ext = ext[1:] return get_icon( "%s.png" % ext, ima.icon('FileIcon') )
python
def get_filetype_icon(fname): """Return file type icon""" ext = osp.splitext(fname)[1] if ext.startswith('.'): ext = ext[1:] return get_icon( "%s.png" % ext, ima.icon('FileIcon') )
[ "def", "get_filetype_icon", "(", "fname", ")", ":", "ext", "=", "osp", ".", "splitext", "(", "fname", ")", "[", "1", "]", "if", "ext", ".", "startswith", "(", "'.'", ")", ":", "ext", "=", "ext", "[", "1", ":", "]", "return", "get_icon", "(", "\"%s.png\"", "%", "ext", ",", "ima", ".", "icon", "(", "'FileIcon'", ")", ")" ]
Return file type icon
[ "Return", "file", "type", "icon" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/qthelpers.py#L423-L428
train
spyder-ide/spyder
spyder/utils/qthelpers.py
show_std_icons
def show_std_icons(): """ Show all standard Icons """ app = qapplication() dialog = ShowStdIcons(None) dialog.show() sys.exit(app.exec_())
python
def show_std_icons(): """ Show all standard Icons """ app = qapplication() dialog = ShowStdIcons(None) dialog.show() sys.exit(app.exec_())
[ "def", "show_std_icons", "(", ")", ":", "app", "=", "qapplication", "(", ")", "dialog", "=", "ShowStdIcons", "(", "None", ")", "dialog", ".", "show", "(", ")", "sys", ".", "exit", "(", "app", ".", "exec_", "(", ")", ")" ]
Show all standard Icons
[ "Show", "all", "standard", "Icons" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/qthelpers.py#L501-L508
train
spyder-ide/spyder
spyder/utils/qthelpers.py
calc_tools_spacing
def calc_tools_spacing(tools_layout): """ Return a spacing (int) or None if we don't have the appropriate metrics to calculate the spacing. We're trying to adapt the spacing below the tools_layout spacing so that the main_widget has the same vertical position as the editor widgets (which have tabs above). The required spacing is spacing = tabbar_height - tools_height + offset where the tabbar_heights were empirically determined for a combination of operating systems and styles. Offsets were manually adjusted, so that the heights of main_widgets and editor widgets match. This is probably caused by a still not understood element of the layout and style metrics. """ metrics = { # (tabbar_height, offset) 'nt.fusion': (32, 0), 'nt.windowsvista': (21, 3), 'nt.windowsxp': (24, 0), 'nt.windows': (21, 3), 'posix.breeze': (28, -1), 'posix.oxygen': (38, -2), 'posix.qtcurve': (27, 0), 'posix.windows': (26, 0), 'posix.fusion': (32, 0), } style_name = qapplication().style().property('name') key = '%s.%s' % (os.name, style_name) if key in metrics: tabbar_height, offset = metrics[key] tools_height = tools_layout.sizeHint().height() spacing = tabbar_height - tools_height + offset return max(spacing, 0)
python
def calc_tools_spacing(tools_layout): """ Return a spacing (int) or None if we don't have the appropriate metrics to calculate the spacing. We're trying to adapt the spacing below the tools_layout spacing so that the main_widget has the same vertical position as the editor widgets (which have tabs above). The required spacing is spacing = tabbar_height - tools_height + offset where the tabbar_heights were empirically determined for a combination of operating systems and styles. Offsets were manually adjusted, so that the heights of main_widgets and editor widgets match. This is probably caused by a still not understood element of the layout and style metrics. """ metrics = { # (tabbar_height, offset) 'nt.fusion': (32, 0), 'nt.windowsvista': (21, 3), 'nt.windowsxp': (24, 0), 'nt.windows': (21, 3), 'posix.breeze': (28, -1), 'posix.oxygen': (38, -2), 'posix.qtcurve': (27, 0), 'posix.windows': (26, 0), 'posix.fusion': (32, 0), } style_name = qapplication().style().property('name') key = '%s.%s' % (os.name, style_name) if key in metrics: tabbar_height, offset = metrics[key] tools_height = tools_layout.sizeHint().height() spacing = tabbar_height - tools_height + offset return max(spacing, 0)
[ "def", "calc_tools_spacing", "(", "tools_layout", ")", ":", "metrics", "=", "{", "# (tabbar_height, offset)\r", "'nt.fusion'", ":", "(", "32", ",", "0", ")", ",", "'nt.windowsvista'", ":", "(", "21", ",", "3", ")", ",", "'nt.windowsxp'", ":", "(", "24", ",", "0", ")", ",", "'nt.windows'", ":", "(", "21", ",", "3", ")", ",", "'posix.breeze'", ":", "(", "28", ",", "-", "1", ")", ",", "'posix.oxygen'", ":", "(", "38", ",", "-", "2", ")", ",", "'posix.qtcurve'", ":", "(", "27", ",", "0", ")", ",", "'posix.windows'", ":", "(", "26", ",", "0", ")", ",", "'posix.fusion'", ":", "(", "32", ",", "0", ")", ",", "}", "style_name", "=", "qapplication", "(", ")", ".", "style", "(", ")", ".", "property", "(", "'name'", ")", "key", "=", "'%s.%s'", "%", "(", "os", ".", "name", ",", "style_name", ")", "if", "key", "in", "metrics", ":", "tabbar_height", ",", "offset", "=", "metrics", "[", "key", "]", "tools_height", "=", "tools_layout", ".", "sizeHint", "(", ")", ".", "height", "(", ")", "spacing", "=", "tabbar_height", "-", "tools_height", "+", "offset", "return", "max", "(", "spacing", ",", "0", ")" ]
Return a spacing (int) or None if we don't have the appropriate metrics to calculate the spacing. We're trying to adapt the spacing below the tools_layout spacing so that the main_widget has the same vertical position as the editor widgets (which have tabs above). The required spacing is spacing = tabbar_height - tools_height + offset where the tabbar_heights were empirically determined for a combination of operating systems and styles. Offsets were manually adjusted, so that the heights of main_widgets and editor widgets match. This is probably caused by a still not understood element of the layout and style metrics.
[ "Return", "a", "spacing", "(", "int", ")", "or", "None", "if", "we", "don", "t", "have", "the", "appropriate", "metrics", "to", "calculate", "the", "spacing", ".", "We", "re", "trying", "to", "adapt", "the", "spacing", "below", "the", "tools_layout", "spacing", "so", "that", "the", "main_widget", "has", "the", "same", "vertical", "position", "as", "the", "editor", "widgets", "(", "which", "have", "tabs", "above", ")", ".", "The", "required", "spacing", "is", "spacing", "=", "tabbar_height", "-", "tools_height", "+", "offset", "where", "the", "tabbar_heights", "were", "empirically", "determined", "for", "a", "combination", "of", "operating", "systems", "and", "styles", ".", "Offsets", "were", "manually", "adjusted", "so", "that", "the", "heights", "of", "main_widgets", "and", "editor", "widgets", "match", ".", "This", "is", "probably", "caused", "by", "a", "still", "not", "understood", "element", "of", "the", "layout", "and", "style", "metrics", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/qthelpers.py#L511-L548
train
spyder-ide/spyder
spyder/utils/qthelpers.py
create_plugin_layout
def create_plugin_layout(tools_layout, main_widget=None): """ Returns a layout for a set of controls above a main widget. This is a standard layout for many plugin panes (even though, it's currently more often applied not to the pane itself but with in the one widget contained in the pane. tools_layout: a layout containing the top toolbar main_widget: the main widget. Can be None, if you want to add this manually later on. """ layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) spacing = calc_tools_spacing(tools_layout) if spacing is not None: layout.setSpacing(spacing) layout.addLayout(tools_layout) if main_widget is not None: layout.addWidget(main_widget) return layout
python
def create_plugin_layout(tools_layout, main_widget=None): """ Returns a layout for a set of controls above a main widget. This is a standard layout for many plugin panes (even though, it's currently more often applied not to the pane itself but with in the one widget contained in the pane. tools_layout: a layout containing the top toolbar main_widget: the main widget. Can be None, if you want to add this manually later on. """ layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) spacing = calc_tools_spacing(tools_layout) if spacing is not None: layout.setSpacing(spacing) layout.addLayout(tools_layout) if main_widget is not None: layout.addWidget(main_widget) return layout
[ "def", "create_plugin_layout", "(", "tools_layout", ",", "main_widget", "=", "None", ")", ":", "layout", "=", "QVBoxLayout", "(", ")", "layout", ".", "setContentsMargins", "(", "0", ",", "0", ",", "0", ",", "0", ")", "spacing", "=", "calc_tools_spacing", "(", "tools_layout", ")", "if", "spacing", "is", "not", "None", ":", "layout", ".", "setSpacing", "(", "spacing", ")", "layout", ".", "addLayout", "(", "tools_layout", ")", "if", "main_widget", "is", "not", "None", ":", "layout", ".", "addWidget", "(", "main_widget", ")", "return", "layout" ]
Returns a layout for a set of controls above a main widget. This is a standard layout for many plugin panes (even though, it's currently more often applied not to the pane itself but with in the one widget contained in the pane. tools_layout: a layout containing the top toolbar main_widget: the main widget. Can be None, if you want to add this manually later on.
[ "Returns", "a", "layout", "for", "a", "set", "of", "controls", "above", "a", "main", "widget", ".", "This", "is", "a", "standard", "layout", "for", "many", "plugin", "panes", "(", "even", "though", "it", "s", "currently", "more", "often", "applied", "not", "to", "the", "pane", "itself", "but", "with", "in", "the", "one", "widget", "contained", "in", "the", "pane", ".", "tools_layout", ":", "a", "layout", "containing", "the", "top", "toolbar", "main_widget", ":", "the", "main", "widget", ".", "Can", "be", "None", "if", "you", "want", "to", "add", "this", "manually", "later", "on", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/qthelpers.py#L551-L571
train
spyder-ide/spyder
spyder/utils/qthelpers.py
DialogManager.show
def show(self, dialog): """Generic method to show a non-modal dialog and keep reference to the Qt C++ object""" for dlg in list(self.dialogs.values()): if to_text_string(dlg.windowTitle()) \ == to_text_string(dialog.windowTitle()): dlg.show() dlg.raise_() break else: dialog.show() self.dialogs[id(dialog)] = dialog dialog.accepted.connect( lambda eid=id(dialog): self.dialog_finished(eid)) dialog.rejected.connect( lambda eid=id(dialog): self.dialog_finished(eid))
python
def show(self, dialog): """Generic method to show a non-modal dialog and keep reference to the Qt C++ object""" for dlg in list(self.dialogs.values()): if to_text_string(dlg.windowTitle()) \ == to_text_string(dialog.windowTitle()): dlg.show() dlg.raise_() break else: dialog.show() self.dialogs[id(dialog)] = dialog dialog.accepted.connect( lambda eid=id(dialog): self.dialog_finished(eid)) dialog.rejected.connect( lambda eid=id(dialog): self.dialog_finished(eid))
[ "def", "show", "(", "self", ",", "dialog", ")", ":", "for", "dlg", "in", "list", "(", "self", ".", "dialogs", ".", "values", "(", ")", ")", ":", "if", "to_text_string", "(", "dlg", ".", "windowTitle", "(", ")", ")", "==", "to_text_string", "(", "dialog", ".", "windowTitle", "(", ")", ")", ":", "dlg", ".", "show", "(", ")", "dlg", ".", "raise_", "(", ")", "break", "else", ":", "dialog", ".", "show", "(", ")", "self", ".", "dialogs", "[", "id", "(", "dialog", ")", "]", "=", "dialog", "dialog", ".", "accepted", ".", "connect", "(", "lambda", "eid", "=", "id", "(", "dialog", ")", ":", "self", ".", "dialog_finished", "(", "eid", ")", ")", "dialog", ".", "rejected", ".", "connect", "(", "lambda", "eid", "=", "id", "(", "dialog", ")", ":", "self", ".", "dialog_finished", "(", "eid", ")", ")" ]
Generic method to show a non-modal dialog and keep reference to the Qt C++ object
[ "Generic", "method", "to", "show", "a", "non", "-", "modal", "dialog", "and", "keep", "reference", "to", "the", "Qt", "C", "++", "object" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/qthelpers.py#L396-L411
train
spyder-ide/spyder
spyder/dependencies.py
add
def add(modname, features, required_version, installed_version=None, optional=False): """Add Spyder dependency""" global DEPENDENCIES for dependency in DEPENDENCIES: if dependency.modname == modname: raise ValueError("Dependency has already been registered: %s"\ % modname) DEPENDENCIES += [Dependency(modname, features, required_version, installed_version, optional)]
python
def add(modname, features, required_version, installed_version=None, optional=False): """Add Spyder dependency""" global DEPENDENCIES for dependency in DEPENDENCIES: if dependency.modname == modname: raise ValueError("Dependency has already been registered: %s"\ % modname) DEPENDENCIES += [Dependency(modname, features, required_version, installed_version, optional)]
[ "def", "add", "(", "modname", ",", "features", ",", "required_version", ",", "installed_version", "=", "None", ",", "optional", "=", "False", ")", ":", "global", "DEPENDENCIES", "for", "dependency", "in", "DEPENDENCIES", ":", "if", "dependency", ".", "modname", "==", "modname", ":", "raise", "ValueError", "(", "\"Dependency has already been registered: %s\"", "%", "modname", ")", "DEPENDENCIES", "+=", "[", "Dependency", "(", "modname", ",", "features", ",", "required_version", ",", "installed_version", ",", "optional", ")", "]" ]
Add Spyder dependency
[ "Add", "Spyder", "dependency" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/dependencies.py#L66-L75
train
spyder-ide/spyder
spyder/dependencies.py
check
def check(modname): """Check if required dependency is installed""" for dependency in DEPENDENCIES: if dependency.modname == modname: return dependency.check() else: raise RuntimeError("Unkwown dependency %s" % modname)
python
def check(modname): """Check if required dependency is installed""" for dependency in DEPENDENCIES: if dependency.modname == modname: return dependency.check() else: raise RuntimeError("Unkwown dependency %s" % modname)
[ "def", "check", "(", "modname", ")", ":", "for", "dependency", "in", "DEPENDENCIES", ":", "if", "dependency", ".", "modname", "==", "modname", ":", "return", "dependency", ".", "check", "(", ")", "else", ":", "raise", "RuntimeError", "(", "\"Unkwown dependency %s\"", "%", "modname", ")" ]
Check if required dependency is installed
[ "Check", "if", "required", "dependency", "is", "installed" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/dependencies.py#L78-L84
train
spyder-ide/spyder
spyder/dependencies.py
status
def status(deps=DEPENDENCIES, linesep=os.linesep): """Return a status of dependencies""" maxwidth = 0 col1 = [] col2 = [] for dependency in deps: title1 = dependency.modname title1 += ' ' + dependency.required_version col1.append(title1) maxwidth = max([maxwidth, len(title1)]) col2.append(dependency.get_installed_version()) text = "" for index in range(len(deps)): text += col1[index].ljust(maxwidth) + ': ' + col2[index] + linesep return text[:-1]
python
def status(deps=DEPENDENCIES, linesep=os.linesep): """Return a status of dependencies""" maxwidth = 0 col1 = [] col2 = [] for dependency in deps: title1 = dependency.modname title1 += ' ' + dependency.required_version col1.append(title1) maxwidth = max([maxwidth, len(title1)]) col2.append(dependency.get_installed_version()) text = "" for index in range(len(deps)): text += col1[index].ljust(maxwidth) + ': ' + col2[index] + linesep return text[:-1]
[ "def", "status", "(", "deps", "=", "DEPENDENCIES", ",", "linesep", "=", "os", ".", "linesep", ")", ":", "maxwidth", "=", "0", "col1", "=", "[", "]", "col2", "=", "[", "]", "for", "dependency", "in", "deps", ":", "title1", "=", "dependency", ".", "modname", "title1", "+=", "' '", "+", "dependency", ".", "required_version", "col1", ".", "append", "(", "title1", ")", "maxwidth", "=", "max", "(", "[", "maxwidth", ",", "len", "(", "title1", ")", "]", ")", "col2", ".", "append", "(", "dependency", ".", "get_installed_version", "(", ")", ")", "text", "=", "\"\"", "for", "index", "in", "range", "(", "len", "(", "deps", ")", ")", ":", "text", "+=", "col1", "[", "index", "]", ".", "ljust", "(", "maxwidth", ")", "+", "': '", "+", "col2", "[", "index", "]", "+", "linesep", "return", "text", "[", ":", "-", "1", "]" ]
Return a status of dependencies
[ "Return", "a", "status", "of", "dependencies" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/dependencies.py#L87-L101
train
spyder-ide/spyder
spyder/dependencies.py
missing_dependencies
def missing_dependencies(): """Return the status of missing dependencies (if any)""" missing_deps = [] for dependency in DEPENDENCIES: if not dependency.check() and not dependency.optional: missing_deps.append(dependency) if missing_deps: return status(deps=missing_deps, linesep='<br>') else: return ""
python
def missing_dependencies(): """Return the status of missing dependencies (if any)""" missing_deps = [] for dependency in DEPENDENCIES: if not dependency.check() and not dependency.optional: missing_deps.append(dependency) if missing_deps: return status(deps=missing_deps, linesep='<br>') else: return ""
[ "def", "missing_dependencies", "(", ")", ":", "missing_deps", "=", "[", "]", "for", "dependency", "in", "DEPENDENCIES", ":", "if", "not", "dependency", ".", "check", "(", ")", "and", "not", "dependency", ".", "optional", ":", "missing_deps", ".", "append", "(", "dependency", ")", "if", "missing_deps", ":", "return", "status", "(", "deps", "=", "missing_deps", ",", "linesep", "=", "'<br>'", ")", "else", ":", "return", "\"\"" ]
Return the status of missing dependencies (if any)
[ "Return", "the", "status", "of", "missing", "dependencies", "(", "if", "any", ")" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/dependencies.py#L104-L113
train
spyder-ide/spyder
spyder/dependencies.py
Dependency.check
def check(self): """Check if dependency is installed""" return programs.is_module_installed(self.modname, self.required_version, self.installed_version)
python
def check(self): """Check if dependency is installed""" return programs.is_module_installed(self.modname, self.required_version, self.installed_version)
[ "def", "check", "(", "self", ")", ":", "return", "programs", ".", "is_module_installed", "(", "self", ".", "modname", ",", "self", ".", "required_version", ",", "self", ".", "installed_version", ")" ]
Check if dependency is installed
[ "Check", "if", "dependency", "is", "installed" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/dependencies.py#L42-L46
train
spyder-ide/spyder
spyder/dependencies.py
Dependency.get_installed_version
def get_installed_version(self): """Return dependency status (string)""" if self.check(): return '%s (%s)' % (self.installed_version, self.OK) else: return '%s (%s)' % (self.installed_version, self.NOK)
python
def get_installed_version(self): """Return dependency status (string)""" if self.check(): return '%s (%s)' % (self.installed_version, self.OK) else: return '%s (%s)' % (self.installed_version, self.NOK)
[ "def", "get_installed_version", "(", "self", ")", ":", "if", "self", ".", "check", "(", ")", ":", "return", "'%s (%s)'", "%", "(", "self", ".", "installed_version", ",", "self", ".", "OK", ")", "else", ":", "return", "'%s (%s)'", "%", "(", "self", ".", "installed_version", ",", "self", ".", "NOK", ")" ]
Return dependency status (string)
[ "Return", "dependency", "status", "(", "string", ")" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/dependencies.py#L48-L53
train
spyder-ide/spyder
spyder/otherplugins.py
get_spyderplugins_mods
def get_spyderplugins_mods(io=False): """Import modules from plugins package and return the list""" # Create user directory user_plugin_path = osp.join(get_conf_path(), USER_PLUGIN_DIR) if not osp.isdir(user_plugin_path): os.makedirs(user_plugin_path) modlist, modnames = [], [] # The user plugins directory is given the priority when looking for modules for plugin_path in [user_plugin_path] + sys.path: _get_spyderplugins(plugin_path, io, modnames, modlist) return modlist
python
def get_spyderplugins_mods(io=False): """Import modules from plugins package and return the list""" # Create user directory user_plugin_path = osp.join(get_conf_path(), USER_PLUGIN_DIR) if not osp.isdir(user_plugin_path): os.makedirs(user_plugin_path) modlist, modnames = [], [] # The user plugins directory is given the priority when looking for modules for plugin_path in [user_plugin_path] + sys.path: _get_spyderplugins(plugin_path, io, modnames, modlist) return modlist
[ "def", "get_spyderplugins_mods", "(", "io", "=", "False", ")", ":", "# Create user directory\r", "user_plugin_path", "=", "osp", ".", "join", "(", "get_conf_path", "(", ")", ",", "USER_PLUGIN_DIR", ")", "if", "not", "osp", ".", "isdir", "(", "user_plugin_path", ")", ":", "os", ".", "makedirs", "(", "user_plugin_path", ")", "modlist", ",", "modnames", "=", "[", "]", ",", "[", "]", "# The user plugins directory is given the priority when looking for modules\r", "for", "plugin_path", "in", "[", "user_plugin_path", "]", "+", "sys", ".", "path", ":", "_get_spyderplugins", "(", "plugin_path", ",", "io", ",", "modnames", ",", "modlist", ")", "return", "modlist" ]
Import modules from plugins package and return the list
[ "Import", "modules", "from", "plugins", "package", "and", "return", "the", "list" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/otherplugins.py#L31-L43
train
spyder-ide/spyder
spyder/otherplugins.py
_get_spyderplugins
def _get_spyderplugins(plugin_path, is_io, modnames, modlist): """Scan the directory `plugin_path` for plugin packages and loads them.""" if not osp.isdir(plugin_path): return for name in os.listdir(plugin_path): # This is needed in order to register the spyder_io_hdf5 plugin. # See issue 4487 # Is this a Spyder plugin? if not name.startswith(PLUGIN_PREFIX): continue # Ensure right type of plugin if is_io != name.startswith(IO_PREFIX): continue # Skip names that end in certain suffixes forbidden_suffixes = ['dist-info', 'egg.info', 'egg-info', 'egg-link', 'kernels'] if any([name.endswith(s) for s in forbidden_suffixes]): continue # Import the plugin _import_plugin(name, plugin_path, modnames, modlist)
python
def _get_spyderplugins(plugin_path, is_io, modnames, modlist): """Scan the directory `plugin_path` for plugin packages and loads them.""" if not osp.isdir(plugin_path): return for name in os.listdir(plugin_path): # This is needed in order to register the spyder_io_hdf5 plugin. # See issue 4487 # Is this a Spyder plugin? if not name.startswith(PLUGIN_PREFIX): continue # Ensure right type of plugin if is_io != name.startswith(IO_PREFIX): continue # Skip names that end in certain suffixes forbidden_suffixes = ['dist-info', 'egg.info', 'egg-info', 'egg-link', 'kernels'] if any([name.endswith(s) for s in forbidden_suffixes]): continue # Import the plugin _import_plugin(name, plugin_path, modnames, modlist)
[ "def", "_get_spyderplugins", "(", "plugin_path", ",", "is_io", ",", "modnames", ",", "modlist", ")", ":", "if", "not", "osp", ".", "isdir", "(", "plugin_path", ")", ":", "return", "for", "name", "in", "os", ".", "listdir", "(", "plugin_path", ")", ":", "# This is needed in order to register the spyder_io_hdf5 plugin.\r", "# See issue 4487\r", "# Is this a Spyder plugin?\r", "if", "not", "name", ".", "startswith", "(", "PLUGIN_PREFIX", ")", ":", "continue", "# Ensure right type of plugin\r", "if", "is_io", "!=", "name", ".", "startswith", "(", "IO_PREFIX", ")", ":", "continue", "# Skip names that end in certain suffixes\r", "forbidden_suffixes", "=", "[", "'dist-info'", ",", "'egg.info'", ",", "'egg-info'", ",", "'egg-link'", ",", "'kernels'", "]", "if", "any", "(", "[", "name", ".", "endswith", "(", "s", ")", "for", "s", "in", "forbidden_suffixes", "]", ")", ":", "continue", "# Import the plugin\r", "_import_plugin", "(", "name", ",", "plugin_path", ",", "modnames", ",", "modlist", ")" ]
Scan the directory `plugin_path` for plugin packages and loads them.
[ "Scan", "the", "directory", "plugin_path", "for", "plugin", "packages", "and", "loads", "them", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/otherplugins.py#L46-L69
train
spyder-ide/spyder
spyder/otherplugins.py
_import_plugin
def _import_plugin(module_name, plugin_path, modnames, modlist): """Import the plugin `module_name` from `plugin_path`, add it to `modlist` and adds its name to `modnames`. """ if module_name in modnames: return try: # First add a mock module with the LOCALEPATH attribute so that the # helper method can find the locale on import mock = _ModuleMock() mock.LOCALEPATH = osp.join(plugin_path, module_name, 'locale') sys.modules[module_name] = mock if osp.isdir(osp.join(plugin_path, module_name)): module = _import_module_from_path(module_name, plugin_path) else: module = None # Then restore the actual loaded module instead of the mock if module and getattr(module, 'PLUGIN_CLASS', False): sys.modules[module_name] = module modlist.append(module) modnames.append(module_name) except Exception: sys.stderr.write("ERROR: 3rd party plugin import failed for " "`{0}`\n".format(module_name)) traceback.print_exc(file=sys.stderr)
python
def _import_plugin(module_name, plugin_path, modnames, modlist): """Import the plugin `module_name` from `plugin_path`, add it to `modlist` and adds its name to `modnames`. """ if module_name in modnames: return try: # First add a mock module with the LOCALEPATH attribute so that the # helper method can find the locale on import mock = _ModuleMock() mock.LOCALEPATH = osp.join(plugin_path, module_name, 'locale') sys.modules[module_name] = mock if osp.isdir(osp.join(plugin_path, module_name)): module = _import_module_from_path(module_name, plugin_path) else: module = None # Then restore the actual loaded module instead of the mock if module and getattr(module, 'PLUGIN_CLASS', False): sys.modules[module_name] = module modlist.append(module) modnames.append(module_name) except Exception: sys.stderr.write("ERROR: 3rd party plugin import failed for " "`{0}`\n".format(module_name)) traceback.print_exc(file=sys.stderr)
[ "def", "_import_plugin", "(", "module_name", ",", "plugin_path", ",", "modnames", ",", "modlist", ")", ":", "if", "module_name", "in", "modnames", ":", "return", "try", ":", "# First add a mock module with the LOCALEPATH attribute so that the\r", "# helper method can find the locale on import\r", "mock", "=", "_ModuleMock", "(", ")", "mock", ".", "LOCALEPATH", "=", "osp", ".", "join", "(", "plugin_path", ",", "module_name", ",", "'locale'", ")", "sys", ".", "modules", "[", "module_name", "]", "=", "mock", "if", "osp", ".", "isdir", "(", "osp", ".", "join", "(", "plugin_path", ",", "module_name", ")", ")", ":", "module", "=", "_import_module_from_path", "(", "module_name", ",", "plugin_path", ")", "else", ":", "module", "=", "None", "# Then restore the actual loaded module instead of the mock\r", "if", "module", "and", "getattr", "(", "module", ",", "'PLUGIN_CLASS'", ",", "False", ")", ":", "sys", ".", "modules", "[", "module_name", "]", "=", "module", "modlist", ".", "append", "(", "module", ")", "modnames", ".", "append", "(", "module_name", ")", "except", "Exception", ":", "sys", ".", "stderr", ".", "write", "(", "\"ERROR: 3rd party plugin import failed for \"", "\"`{0}`\\n\"", ".", "format", "(", "module_name", ")", ")", "traceback", ".", "print_exc", "(", "file", "=", "sys", ".", "stderr", ")" ]
Import the plugin `module_name` from `plugin_path`, add it to `modlist` and adds its name to `modnames`.
[ "Import", "the", "plugin", "module_name", "from", "plugin_path", "add", "it", "to", "modlist", "and", "adds", "its", "name", "to", "modnames", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/otherplugins.py#L72-L98
train
spyder-ide/spyder
spyder/otherplugins.py
_import_module_from_path
def _import_module_from_path(module_name, plugin_path): """Imports `module_name` from `plugin_path`. Return None if no module is found. """ module = None try: if PY2: info = imp.find_module(module_name, [plugin_path]) if info: module = imp.load_module(module_name, *info) else: # Python 3.4+ spec = importlib.machinery.PathFinder.find_spec( module_name, [plugin_path]) if spec: module = spec.loader.load_module(module_name) except Exception: pass return module
python
def _import_module_from_path(module_name, plugin_path): """Imports `module_name` from `plugin_path`. Return None if no module is found. """ module = None try: if PY2: info = imp.find_module(module_name, [plugin_path]) if info: module = imp.load_module(module_name, *info) else: # Python 3.4+ spec = importlib.machinery.PathFinder.find_spec( module_name, [plugin_path]) if spec: module = spec.loader.load_module(module_name) except Exception: pass return module
[ "def", "_import_module_from_path", "(", "module_name", ",", "plugin_path", ")", ":", "module", "=", "None", "try", ":", "if", "PY2", ":", "info", "=", "imp", ".", "find_module", "(", "module_name", ",", "[", "plugin_path", "]", ")", "if", "info", ":", "module", "=", "imp", ".", "load_module", "(", "module_name", ",", "*", "info", ")", "else", ":", "# Python 3.4+\r", "spec", "=", "importlib", ".", "machinery", ".", "PathFinder", ".", "find_spec", "(", "module_name", ",", "[", "plugin_path", "]", ")", "if", "spec", ":", "module", "=", "spec", ".", "loader", ".", "load_module", "(", "module_name", ")", "except", "Exception", ":", "pass", "return", "module" ]
Imports `module_name` from `plugin_path`. Return None if no module is found.
[ "Imports", "module_name", "from", "plugin_path", ".", "Return", "None", "if", "no", "module", "is", "found", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/otherplugins.py#L101-L121
train
spyder-ide/spyder
spyder/utils/icon_manager.py
get_std_icon
def get_std_icon(name, size=None): """Get standard platform icon Call 'show_std_icons()' for details""" if not name.startswith('SP_'): name = 'SP_' + name icon = QWidget().style().standardIcon(getattr(QStyle, name)) if size is None: return icon else: return QIcon(icon.pixmap(size, size))
python
def get_std_icon(name, size=None): """Get standard platform icon Call 'show_std_icons()' for details""" if not name.startswith('SP_'): name = 'SP_' + name icon = QWidget().style().standardIcon(getattr(QStyle, name)) if size is None: return icon else: return QIcon(icon.pixmap(size, size))
[ "def", "get_std_icon", "(", "name", ",", "size", "=", "None", ")", ":", "if", "not", "name", ".", "startswith", "(", "'SP_'", ")", ":", "name", "=", "'SP_'", "+", "name", "icon", "=", "QWidget", "(", ")", ".", "style", "(", ")", ".", "standardIcon", "(", "getattr", "(", "QStyle", ",", "name", ")", ")", "if", "size", "is", "None", ":", "return", "icon", "else", ":", "return", "QIcon", "(", "icon", ".", "pixmap", "(", "size", ",", "size", ")", ")" ]
Get standard platform icon Call 'show_std_icons()' for details
[ "Get", "standard", "platform", "icon", "Call", "show_std_icons", "()", "for", "details" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/icon_manager.py#L346-L355
train
spyder-ide/spyder
spyder/utils/icon_manager.py
get_icon
def get_icon(name, default=None, resample=False): """Return image inside a QIcon object. default: default image name or icon resample: if True, manually resample icon pixmaps for usual sizes (16, 24, 32, 48, 96, 128, 256). This is recommended for QMainWindow icons created from SVG images on non-Windows platforms due to a Qt bug (see Issue 1314). """ icon_path = get_image_path(name, default=None) if icon_path is not None: icon = QIcon(icon_path) elif isinstance(default, QIcon): icon = default elif default is None: try: icon = get_std_icon(name[:-4]) except AttributeError: icon = QIcon(get_image_path(name, default)) else: icon = QIcon(get_image_path(name, default)) if resample: icon0 = QIcon() for size in (16, 24, 32, 48, 96, 128, 256, 512): icon0.addPixmap(icon.pixmap(size, size)) return icon0 else: return icon
python
def get_icon(name, default=None, resample=False): """Return image inside a QIcon object. default: default image name or icon resample: if True, manually resample icon pixmaps for usual sizes (16, 24, 32, 48, 96, 128, 256). This is recommended for QMainWindow icons created from SVG images on non-Windows platforms due to a Qt bug (see Issue 1314). """ icon_path = get_image_path(name, default=None) if icon_path is not None: icon = QIcon(icon_path) elif isinstance(default, QIcon): icon = default elif default is None: try: icon = get_std_icon(name[:-4]) except AttributeError: icon = QIcon(get_image_path(name, default)) else: icon = QIcon(get_image_path(name, default)) if resample: icon0 = QIcon() for size in (16, 24, 32, 48, 96, 128, 256, 512): icon0.addPixmap(icon.pixmap(size, size)) return icon0 else: return icon
[ "def", "get_icon", "(", "name", ",", "default", "=", "None", ",", "resample", "=", "False", ")", ":", "icon_path", "=", "get_image_path", "(", "name", ",", "default", "=", "None", ")", "if", "icon_path", "is", "not", "None", ":", "icon", "=", "QIcon", "(", "icon_path", ")", "elif", "isinstance", "(", "default", ",", "QIcon", ")", ":", "icon", "=", "default", "elif", "default", "is", "None", ":", "try", ":", "icon", "=", "get_std_icon", "(", "name", "[", ":", "-", "4", "]", ")", "except", "AttributeError", ":", "icon", "=", "QIcon", "(", "get_image_path", "(", "name", ",", "default", ")", ")", "else", ":", "icon", "=", "QIcon", "(", "get_image_path", "(", "name", ",", "default", ")", ")", "if", "resample", ":", "icon0", "=", "QIcon", "(", ")", "for", "size", "in", "(", "16", ",", "24", ",", "32", ",", "48", ",", "96", ",", "128", ",", "256", ",", "512", ")", ":", "icon0", ".", "addPixmap", "(", "icon", ".", "pixmap", "(", "size", ",", "size", ")", ")", "return", "icon0", "else", ":", "return", "icon" ]
Return image inside a QIcon object. default: default image name or icon resample: if True, manually resample icon pixmaps for usual sizes (16, 24, 32, 48, 96, 128, 256). This is recommended for QMainWindow icons created from SVG images on non-Windows platforms due to a Qt bug (see Issue 1314).
[ "Return", "image", "inside", "a", "QIcon", "object", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/icon_manager.py#L358-L386
train
spyder-ide/spyder
spyder/utils/icon_manager.py
get_icon_by_extension
def get_icon_by_extension(fname, scale_factor): """Return the icon depending on the file extension""" application_icons = {} application_icons.update(BIN_FILES) application_icons.update(DOCUMENT_FILES) if osp.isdir(fname): return icon('DirOpenIcon', scale_factor) else: basename = osp.basename(fname) __, extension = osp.splitext(basename.lower()) mime_type, __ = mime.guess_type(basename) icon_by_extension = icon('FileIcon', scale_factor) if extension in OFFICE_FILES: icon_by_extension = icon(OFFICE_FILES[extension], scale_factor) if extension in LANGUAGE_ICONS: icon_by_extension = icon(LANGUAGE_ICONS[extension], scale_factor) else: if extension == '.ipynb': if is_dark_interface(): icon_by_extension = QIcon( get_image_path('notebook_dark.svg')) else: icon_by_extension = QIcon( get_image_path('notebook_light.svg')) elif mime_type is not None: try: # Fix for issue 5080. Even though # mimetypes.guess_type documentation states that # the return value will be None or a tuple of # the form type/subtype, in the Windows registry, # .sql has a mimetype of text\plain # instead of text/plain therefore mimetypes is # returning it incorrectly. file_type, bin_name = mime_type.split('/') except ValueError: file_type = 'text' if file_type == 'text': icon_by_extension = icon('TextFileIcon', scale_factor) elif file_type == 'audio': icon_by_extension = icon('AudioFileIcon', scale_factor) elif file_type == 'video': icon_by_extension = icon('VideoFileIcon', scale_factor) elif file_type == 'image': icon_by_extension = icon('ImageFileIcon', scale_factor) elif file_type == 'application': if bin_name in application_icons: icon_by_extension = icon( application_icons[bin_name], scale_factor) return icon_by_extension
python
def get_icon_by_extension(fname, scale_factor): """Return the icon depending on the file extension""" application_icons = {} application_icons.update(BIN_FILES) application_icons.update(DOCUMENT_FILES) if osp.isdir(fname): return icon('DirOpenIcon', scale_factor) else: basename = osp.basename(fname) __, extension = osp.splitext(basename.lower()) mime_type, __ = mime.guess_type(basename) icon_by_extension = icon('FileIcon', scale_factor) if extension in OFFICE_FILES: icon_by_extension = icon(OFFICE_FILES[extension], scale_factor) if extension in LANGUAGE_ICONS: icon_by_extension = icon(LANGUAGE_ICONS[extension], scale_factor) else: if extension == '.ipynb': if is_dark_interface(): icon_by_extension = QIcon( get_image_path('notebook_dark.svg')) else: icon_by_extension = QIcon( get_image_path('notebook_light.svg')) elif mime_type is not None: try: # Fix for issue 5080. Even though # mimetypes.guess_type documentation states that # the return value will be None or a tuple of # the form type/subtype, in the Windows registry, # .sql has a mimetype of text\plain # instead of text/plain therefore mimetypes is # returning it incorrectly. file_type, bin_name = mime_type.split('/') except ValueError: file_type = 'text' if file_type == 'text': icon_by_extension = icon('TextFileIcon', scale_factor) elif file_type == 'audio': icon_by_extension = icon('AudioFileIcon', scale_factor) elif file_type == 'video': icon_by_extension = icon('VideoFileIcon', scale_factor) elif file_type == 'image': icon_by_extension = icon('ImageFileIcon', scale_factor) elif file_type == 'application': if bin_name in application_icons: icon_by_extension = icon( application_icons[bin_name], scale_factor) return icon_by_extension
[ "def", "get_icon_by_extension", "(", "fname", ",", "scale_factor", ")", ":", "application_icons", "=", "{", "}", "application_icons", ".", "update", "(", "BIN_FILES", ")", "application_icons", ".", "update", "(", "DOCUMENT_FILES", ")", "if", "osp", ".", "isdir", "(", "fname", ")", ":", "return", "icon", "(", "'DirOpenIcon'", ",", "scale_factor", ")", "else", ":", "basename", "=", "osp", ".", "basename", "(", "fname", ")", "__", ",", "extension", "=", "osp", ".", "splitext", "(", "basename", ".", "lower", "(", ")", ")", "mime_type", ",", "__", "=", "mime", ".", "guess_type", "(", "basename", ")", "icon_by_extension", "=", "icon", "(", "'FileIcon'", ",", "scale_factor", ")", "if", "extension", "in", "OFFICE_FILES", ":", "icon_by_extension", "=", "icon", "(", "OFFICE_FILES", "[", "extension", "]", ",", "scale_factor", ")", "if", "extension", "in", "LANGUAGE_ICONS", ":", "icon_by_extension", "=", "icon", "(", "LANGUAGE_ICONS", "[", "extension", "]", ",", "scale_factor", ")", "else", ":", "if", "extension", "==", "'.ipynb'", ":", "if", "is_dark_interface", "(", ")", ":", "icon_by_extension", "=", "QIcon", "(", "get_image_path", "(", "'notebook_dark.svg'", ")", ")", "else", ":", "icon_by_extension", "=", "QIcon", "(", "get_image_path", "(", "'notebook_light.svg'", ")", ")", "elif", "mime_type", "is", "not", "None", ":", "try", ":", "# Fix for issue 5080. Even though", "# mimetypes.guess_type documentation states that", "# the return value will be None or a tuple of", "# the form type/subtype, in the Windows registry,", "# .sql has a mimetype of text\\plain", "# instead of text/plain therefore mimetypes is", "# returning it incorrectly.", "file_type", ",", "bin_name", "=", "mime_type", ".", "split", "(", "'/'", ")", "except", "ValueError", ":", "file_type", "=", "'text'", "if", "file_type", "==", "'text'", ":", "icon_by_extension", "=", "icon", "(", "'TextFileIcon'", ",", "scale_factor", ")", "elif", "file_type", "==", "'audio'", ":", "icon_by_extension", "=", "icon", "(", "'AudioFileIcon'", ",", "scale_factor", ")", "elif", "file_type", "==", "'video'", ":", "icon_by_extension", "=", "icon", "(", "'VideoFileIcon'", ",", "scale_factor", ")", "elif", "file_type", "==", "'image'", ":", "icon_by_extension", "=", "icon", "(", "'ImageFileIcon'", ",", "scale_factor", ")", "elif", "file_type", "==", "'application'", ":", "if", "bin_name", "in", "application_icons", ":", "icon_by_extension", "=", "icon", "(", "application_icons", "[", "bin_name", "]", ",", "scale_factor", ")", "return", "icon_by_extension" ]
Return the icon depending on the file extension
[ "Return", "the", "icon", "depending", "on", "the", "file", "extension" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/icon_manager.py#L409-L459
train
spyder-ide/spyder
spyder/plugins/editor/widgets/autosaveerror.py
AutosaveErrorDialog.accept
def accept(self): """ Update `show_errors` and hide dialog box. Overrides method of `QDialogBox`. """ AutosaveErrorDialog.show_errors = not self.dismiss_box.isChecked() return QDialog.accept(self)
python
def accept(self): """ Update `show_errors` and hide dialog box. Overrides method of `QDialogBox`. """ AutosaveErrorDialog.show_errors = not self.dismiss_box.isChecked() return QDialog.accept(self)
[ "def", "accept", "(", "self", ")", ":", "AutosaveErrorDialog", ".", "show_errors", "=", "not", "self", ".", "dismiss_box", ".", "isChecked", "(", ")", "return", "QDialog", ".", "accept", "(", "self", ")" ]
Update `show_errors` and hide dialog box. Overrides method of `QDialogBox`.
[ "Update", "show_errors", "and", "hide", "dialog", "box", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/widgets/autosaveerror.py#L78-L85
train
spyder-ide/spyder
spyder/widgets/onecolumntree.py
OneColumnTree.setup_common_actions
def setup_common_actions(self): """Setup context menu common actions""" self.collapse_all_action = create_action(self, text=_('Collapse all'), icon=ima.icon('collapse'), triggered=self.collapseAll) self.expand_all_action = create_action(self, text=_('Expand all'), icon=ima.icon('expand'), triggered=self.expandAll) self.restore_action = create_action(self, text=_('Restore'), tip=_('Restore original tree layout'), icon=ima.icon('restore'), triggered=self.restore) self.collapse_selection_action = create_action(self, text=_('Collapse selection'), icon=ima.icon('collapse_selection'), triggered=self.collapse_selection) self.expand_selection_action = create_action(self, text=_('Expand selection'), icon=ima.icon('expand_selection'), triggered=self.expand_selection) return [self.collapse_all_action, self.expand_all_action, self.restore_action, None, self.collapse_selection_action, self.expand_selection_action]
python
def setup_common_actions(self): """Setup context menu common actions""" self.collapse_all_action = create_action(self, text=_('Collapse all'), icon=ima.icon('collapse'), triggered=self.collapseAll) self.expand_all_action = create_action(self, text=_('Expand all'), icon=ima.icon('expand'), triggered=self.expandAll) self.restore_action = create_action(self, text=_('Restore'), tip=_('Restore original tree layout'), icon=ima.icon('restore'), triggered=self.restore) self.collapse_selection_action = create_action(self, text=_('Collapse selection'), icon=ima.icon('collapse_selection'), triggered=self.collapse_selection) self.expand_selection_action = create_action(self, text=_('Expand selection'), icon=ima.icon('expand_selection'), triggered=self.expand_selection) return [self.collapse_all_action, self.expand_all_action, self.restore_action, None, self.collapse_selection_action, self.expand_selection_action]
[ "def", "setup_common_actions", "(", "self", ")", ":", "self", ".", "collapse_all_action", "=", "create_action", "(", "self", ",", "text", "=", "_", "(", "'Collapse all'", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'collapse'", ")", ",", "triggered", "=", "self", ".", "collapseAll", ")", "self", ".", "expand_all_action", "=", "create_action", "(", "self", ",", "text", "=", "_", "(", "'Expand all'", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'expand'", ")", ",", "triggered", "=", "self", ".", "expandAll", ")", "self", ".", "restore_action", "=", "create_action", "(", "self", ",", "text", "=", "_", "(", "'Restore'", ")", ",", "tip", "=", "_", "(", "'Restore original tree layout'", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'restore'", ")", ",", "triggered", "=", "self", ".", "restore", ")", "self", ".", "collapse_selection_action", "=", "create_action", "(", "self", ",", "text", "=", "_", "(", "'Collapse selection'", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'collapse_selection'", ")", ",", "triggered", "=", "self", ".", "collapse_selection", ")", "self", ".", "expand_selection_action", "=", "create_action", "(", "self", ",", "text", "=", "_", "(", "'Expand selection'", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'expand_selection'", ")", ",", "triggered", "=", "self", ".", "expand_selection", ")", "return", "[", "self", ".", "collapse_all_action", ",", "self", ".", "expand_all_action", ",", "self", ".", "restore_action", ",", "None", ",", "self", ".", "collapse_selection_action", ",", "self", ".", "expand_selection_action", "]" ]
Setup context menu common actions
[ "Setup", "context", "menu", "common", "actions" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/onecolumntree.py#L49-L74
train
spyder-ide/spyder
spyder/widgets/onecolumntree.py
OneColumnTree.get_menu_actions
def get_menu_actions(self): """Returns a list of menu actions""" items = self.selectedItems() actions = self.get_actions_from_items(items) if actions: actions.append(None) actions += self.common_actions return actions
python
def get_menu_actions(self): """Returns a list of menu actions""" items = self.selectedItems() actions = self.get_actions_from_items(items) if actions: actions.append(None) actions += self.common_actions return actions
[ "def", "get_menu_actions", "(", "self", ")", ":", "items", "=", "self", ".", "selectedItems", "(", ")", "actions", "=", "self", ".", "get_actions_from_items", "(", "items", ")", "if", "actions", ":", "actions", ".", "append", "(", "None", ")", "actions", "+=", "self", ".", "common_actions", "return", "actions" ]
Returns a list of menu actions
[ "Returns", "a", "list", "of", "menu", "actions" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/onecolumntree.py#L76-L83
train
spyder-ide/spyder
spyder/widgets/onecolumntree.py
OneColumnTree.item_selection_changed
def item_selection_changed(self): """Item selection has changed""" is_selection = len(self.selectedItems()) > 0 self.expand_selection_action.setEnabled(is_selection) self.collapse_selection_action.setEnabled(is_selection)
python
def item_selection_changed(self): """Item selection has changed""" is_selection = len(self.selectedItems()) > 0 self.expand_selection_action.setEnabled(is_selection) self.collapse_selection_action.setEnabled(is_selection)
[ "def", "item_selection_changed", "(", "self", ")", ":", "is_selection", "=", "len", "(", "self", ".", "selectedItems", "(", ")", ")", ">", "0", "self", ".", "expand_selection_action", ".", "setEnabled", "(", "is_selection", ")", "self", ".", "collapse_selection_action", ".", "setEnabled", "(", "is_selection", ")" ]
Item selection has changed
[ "Item", "selection", "has", "changed" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/onecolumntree.py#L139-L143
train
spyder-ide/spyder
spyder/widgets/onecolumntree.py
OneColumnTree.get_items
def get_items(self): """Return items (excluding top level items)""" itemlist = [] def add_to_itemlist(item): for index in range(item.childCount()): citem = item.child(index) itemlist.append(citem) add_to_itemlist(citem) for tlitem in self.get_top_level_items(): add_to_itemlist(tlitem) return itemlist
python
def get_items(self): """Return items (excluding top level items)""" itemlist = [] def add_to_itemlist(item): for index in range(item.childCount()): citem = item.child(index) itemlist.append(citem) add_to_itemlist(citem) for tlitem in self.get_top_level_items(): add_to_itemlist(tlitem) return itemlist
[ "def", "get_items", "(", "self", ")", ":", "itemlist", "=", "[", "]", "def", "add_to_itemlist", "(", "item", ")", ":", "for", "index", "in", "range", "(", "item", ".", "childCount", "(", ")", ")", ":", "citem", "=", "item", ".", "child", "(", "index", ")", "itemlist", ".", "append", "(", "citem", ")", "add_to_itemlist", "(", "citem", ")", "for", "tlitem", "in", "self", ".", "get_top_level_items", "(", ")", ":", "add_to_itemlist", "(", "tlitem", ")", "return", "itemlist" ]
Return items (excluding top level items)
[ "Return", "items", "(", "excluding", "top", "level", "items", ")" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/onecolumntree.py#L149-L159
train
spyder-ide/spyder
spyder/widgets/onecolumntree.py
OneColumnTree.save_expanded_state
def save_expanded_state(self): """Save all items expanded state""" self.__expanded_state = {} def add_to_state(item): user_text = get_item_user_text(item) self.__expanded_state[hash(user_text)] = item.isExpanded() def browse_children(item): add_to_state(item) for index in range(item.childCount()): citem = item.child(index) user_text = get_item_user_text(citem) self.__expanded_state[hash(user_text)] = citem.isExpanded() browse_children(citem) for tlitem in self.get_top_level_items(): browse_children(tlitem)
python
def save_expanded_state(self): """Save all items expanded state""" self.__expanded_state = {} def add_to_state(item): user_text = get_item_user_text(item) self.__expanded_state[hash(user_text)] = item.isExpanded() def browse_children(item): add_to_state(item) for index in range(item.childCount()): citem = item.child(index) user_text = get_item_user_text(citem) self.__expanded_state[hash(user_text)] = citem.isExpanded() browse_children(citem) for tlitem in self.get_top_level_items(): browse_children(tlitem)
[ "def", "save_expanded_state", "(", "self", ")", ":", "self", ".", "__expanded_state", "=", "{", "}", "def", "add_to_state", "(", "item", ")", ":", "user_text", "=", "get_item_user_text", "(", "item", ")", "self", ".", "__expanded_state", "[", "hash", "(", "user_text", ")", "]", "=", "item", ".", "isExpanded", "(", ")", "def", "browse_children", "(", "item", ")", ":", "add_to_state", "(", "item", ")", "for", "index", "in", "range", "(", "item", ".", "childCount", "(", ")", ")", ":", "citem", "=", "item", ".", "child", "(", "index", ")", "user_text", "=", "get_item_user_text", "(", "citem", ")", "self", ".", "__expanded_state", "[", "hash", "(", "user_text", ")", "]", "=", "citem", ".", "isExpanded", "(", ")", "browse_children", "(", "citem", ")", "for", "tlitem", "in", "self", ".", "get_top_level_items", "(", ")", ":", "browse_children", "(", "tlitem", ")" ]
Save all items expanded state
[ "Save", "all", "items", "expanded", "state" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/onecolumntree.py#L178-L192
train
spyder-ide/spyder
spyder/widgets/onecolumntree.py
OneColumnTree.restore_expanded_state
def restore_expanded_state(self): """Restore all items expanded state""" if self.__expanded_state is None: return for item in self.get_items()+self.get_top_level_items(): user_text = get_item_user_text(item) is_expanded = self.__expanded_state.get(hash(user_text)) if is_expanded is not None: item.setExpanded(is_expanded)
python
def restore_expanded_state(self): """Restore all items expanded state""" if self.__expanded_state is None: return for item in self.get_items()+self.get_top_level_items(): user_text = get_item_user_text(item) is_expanded = self.__expanded_state.get(hash(user_text)) if is_expanded is not None: item.setExpanded(is_expanded)
[ "def", "restore_expanded_state", "(", "self", ")", ":", "if", "self", ".", "__expanded_state", "is", "None", ":", "return", "for", "item", "in", "self", ".", "get_items", "(", ")", "+", "self", ".", "get_top_level_items", "(", ")", ":", "user_text", "=", "get_item_user_text", "(", "item", ")", "is_expanded", "=", "self", ".", "__expanded_state", ".", "get", "(", "hash", "(", "user_text", ")", ")", "if", "is_expanded", "is", "not", "None", ":", "item", ".", "setExpanded", "(", "is_expanded", ")" ]
Restore all items expanded state
[ "Restore", "all", "items", "expanded", "state" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/onecolumntree.py#L194-L202
train
spyder-ide/spyder
spyder/widgets/onecolumntree.py
OneColumnTree.sort_top_level_items
def sort_top_level_items(self, key): """Sorting tree wrt top level items""" self.save_expanded_state() items = sorted([self.takeTopLevelItem(0) for index in range(self.topLevelItemCount())], key=key) for index, item in enumerate(items): self.insertTopLevelItem(index, item) self.restore_expanded_state()
python
def sort_top_level_items(self, key): """Sorting tree wrt top level items""" self.save_expanded_state() items = sorted([self.takeTopLevelItem(0) for index in range(self.topLevelItemCount())], key=key) for index, item in enumerate(items): self.insertTopLevelItem(index, item) self.restore_expanded_state()
[ "def", "sort_top_level_items", "(", "self", ",", "key", ")", ":", "self", ".", "save_expanded_state", "(", ")", "items", "=", "sorted", "(", "[", "self", ".", "takeTopLevelItem", "(", "0", ")", "for", "index", "in", "range", "(", "self", ".", "topLevelItemCount", "(", ")", ")", "]", ",", "key", "=", "key", ")", "for", "index", ",", "item", "in", "enumerate", "(", "items", ")", ":", "self", ".", "insertTopLevelItem", "(", "index", ",", "item", ")", "self", ".", "restore_expanded_state", "(", ")" ]
Sorting tree wrt top level items
[ "Sorting", "tree", "wrt", "top", "level", "items" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/onecolumntree.py#L204-L211
train
spyder-ide/spyder
spyder/widgets/onecolumntree.py
OneColumnTree.contextMenuEvent
def contextMenuEvent(self, event): """Override Qt method""" self.update_menu() self.menu.popup(event.globalPos())
python
def contextMenuEvent(self, event): """Override Qt method""" self.update_menu() self.menu.popup(event.globalPos())
[ "def", "contextMenuEvent", "(", "self", ",", "event", ")", ":", "self", ".", "update_menu", "(", ")", "self", ".", "menu", ".", "popup", "(", "event", ".", "globalPos", "(", ")", ")" ]
Override Qt method
[ "Override", "Qt", "method" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/onecolumntree.py#L213-L216
train
spyder-ide/spyder
create_app.py
get_stdlib_modules
def get_stdlib_modules(): """ Returns a list containing the names of all the modules available in the standard library. Based on the function get_root_modules from the IPython project. Present in IPython.core.completerlib in v0.13.1 Copyright (C) 2010-2011 The IPython Development Team. Distributed under the terms of the BSD License. """ modules = list(sys.builtin_module_names) for path in sys.path[1:]: if 'site-packages' not in path: modules += module_list(path) modules = set(modules) if '__init__' in modules: modules.remove('__init__') modules = list(modules) return modules
python
def get_stdlib_modules(): """ Returns a list containing the names of all the modules available in the standard library. Based on the function get_root_modules from the IPython project. Present in IPython.core.completerlib in v0.13.1 Copyright (C) 2010-2011 The IPython Development Team. Distributed under the terms of the BSD License. """ modules = list(sys.builtin_module_names) for path in sys.path[1:]: if 'site-packages' not in path: modules += module_list(path) modules = set(modules) if '__init__' in modules: modules.remove('__init__') modules = list(modules) return modules
[ "def", "get_stdlib_modules", "(", ")", ":", "modules", "=", "list", "(", "sys", ".", "builtin_module_names", ")", "for", "path", "in", "sys", ".", "path", "[", "1", ":", "]", ":", "if", "'site-packages'", "not", "in", "path", ":", "modules", "+=", "module_list", "(", "path", ")", "modules", "=", "set", "(", "modules", ")", "if", "'__init__'", "in", "modules", ":", "modules", ".", "remove", "(", "'__init__'", ")", "modules", "=", "list", "(", "modules", ")", "return", "modules" ]
Returns a list containing the names of all the modules available in the standard library. Based on the function get_root_modules from the IPython project. Present in IPython.core.completerlib in v0.13.1 Copyright (C) 2010-2011 The IPython Development Team. Distributed under the terms of the BSD License.
[ "Returns", "a", "list", "containing", "the", "names", "of", "all", "the", "modules", "available", "in", "the", "standard", "library", ".", "Based", "on", "the", "function", "get_root_modules", "from", "the", "IPython", "project", ".", "Present", "in", "IPython", ".", "core", ".", "completerlib", "in", "v0", ".", "13", ".", "1", "Copyright", "(", "C", ")", "2010", "-", "2011", "The", "IPython", "Development", "Team", ".", "Distributed", "under", "the", "terms", "of", "the", "BSD", "License", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/create_app.py#L44-L64
train
spyder-ide/spyder
spyder/plugins/editor/api/folding.py
print_tree
def print_tree(editor, file=sys.stdout, print_blocks=False, return_list=False): """ Prints the editor fold tree to stdout, for debugging purpose. :param editor: CodeEditor instance. :param file: file handle where the tree will be printed. Default is stdout. :param print_blocks: True to print all blocks, False to only print blocks that are fold triggers """ output_list = [] block = editor.document().firstBlock() while block.isValid(): trigger = TextBlockHelper().is_fold_trigger(block) trigger_state = TextBlockHelper().is_collapsed(block) lvl = TextBlockHelper().get_fold_lvl(block) visible = 'V' if block.isVisible() else 'I' if trigger: trigger = '+' if trigger_state else '-' if return_list: output_list.append([block.blockNumber() + 1, lvl, visible]) else: print('l%d:%s%s%s' % (block.blockNumber() + 1, lvl, trigger, visible), file=file) elif print_blocks: if return_list: output_list.append([block.blockNumber() + 1, lvl, visible]) else: print('l%d:%s%s' % (block.blockNumber() + 1, lvl, visible), file=file) block = block.next() if return_list: return output_list
python
def print_tree(editor, file=sys.stdout, print_blocks=False, return_list=False): """ Prints the editor fold tree to stdout, for debugging purpose. :param editor: CodeEditor instance. :param file: file handle where the tree will be printed. Default is stdout. :param print_blocks: True to print all blocks, False to only print blocks that are fold triggers """ output_list = [] block = editor.document().firstBlock() while block.isValid(): trigger = TextBlockHelper().is_fold_trigger(block) trigger_state = TextBlockHelper().is_collapsed(block) lvl = TextBlockHelper().get_fold_lvl(block) visible = 'V' if block.isVisible() else 'I' if trigger: trigger = '+' if trigger_state else '-' if return_list: output_list.append([block.blockNumber() + 1, lvl, visible]) else: print('l%d:%s%s%s' % (block.blockNumber() + 1, lvl, trigger, visible), file=file) elif print_blocks: if return_list: output_list.append([block.blockNumber() + 1, lvl, visible]) else: print('l%d:%s%s' % (block.blockNumber() + 1, lvl, visible), file=file) block = block.next() if return_list: return output_list
[ "def", "print_tree", "(", "editor", ",", "file", "=", "sys", ".", "stdout", ",", "print_blocks", "=", "False", ",", "return_list", "=", "False", ")", ":", "output_list", "=", "[", "]", "block", "=", "editor", ".", "document", "(", ")", ".", "firstBlock", "(", ")", "while", "block", ".", "isValid", "(", ")", ":", "trigger", "=", "TextBlockHelper", "(", ")", ".", "is_fold_trigger", "(", "block", ")", "trigger_state", "=", "TextBlockHelper", "(", ")", ".", "is_collapsed", "(", "block", ")", "lvl", "=", "TextBlockHelper", "(", ")", ".", "get_fold_lvl", "(", "block", ")", "visible", "=", "'V'", "if", "block", ".", "isVisible", "(", ")", "else", "'I'", "if", "trigger", ":", "trigger", "=", "'+'", "if", "trigger_state", "else", "'-'", "if", "return_list", ":", "output_list", ".", "append", "(", "[", "block", ".", "blockNumber", "(", ")", "+", "1", ",", "lvl", ",", "visible", "]", ")", "else", ":", "print", "(", "'l%d:%s%s%s'", "%", "(", "block", ".", "blockNumber", "(", ")", "+", "1", ",", "lvl", ",", "trigger", ",", "visible", ")", ",", "file", "=", "file", ")", "elif", "print_blocks", ":", "if", "return_list", ":", "output_list", ".", "append", "(", "[", "block", ".", "blockNumber", "(", ")", "+", "1", ",", "lvl", ",", "visible", "]", ")", "else", ":", "print", "(", "'l%d:%s%s'", "%", "(", "block", ".", "blockNumber", "(", ")", "+", "1", ",", "lvl", ",", "visible", ")", ",", "file", "=", "file", ")", "block", "=", "block", ".", "next", "(", ")", "if", "return_list", ":", "return", "output_list" ]
Prints the editor fold tree to stdout, for debugging purpose. :param editor: CodeEditor instance. :param file: file handle where the tree will be printed. Default is stdout. :param print_blocks: True to print all blocks, False to only print blocks that are fold triggers
[ "Prints", "the", "editor", "fold", "tree", "to", "stdout", "for", "debugging", "purpose", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/api/folding.py#L29-L63
train
spyder-ide/spyder
spyder/utils/environ.py
envdict2listdict
def envdict2listdict(envdict): """Dict --> Dict of lists""" sep = os.path.pathsep for key in envdict: if sep in envdict[key]: envdict[key] = [path.strip() for path in envdict[key].split(sep)] return envdict
python
def envdict2listdict(envdict): """Dict --> Dict of lists""" sep = os.path.pathsep for key in envdict: if sep in envdict[key]: envdict[key] = [path.strip() for path in envdict[key].split(sep)] return envdict
[ "def", "envdict2listdict", "(", "envdict", ")", ":", "sep", "=", "os", ".", "path", ".", "pathsep", "for", "key", "in", "envdict", ":", "if", "sep", "in", "envdict", "[", "key", "]", ":", "envdict", "[", "key", "]", "=", "[", "path", ".", "strip", "(", ")", "for", "path", "in", "envdict", "[", "key", "]", ".", "split", "(", "sep", ")", "]", "return", "envdict" ]
Dict --> Dict of lists
[ "Dict", "--", ">", "Dict", "of", "lists" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/environ.py#L24-L30
train
spyder-ide/spyder
spyder/utils/environ.py
listdict2envdict
def listdict2envdict(listdict): """Dict of lists --> Dict""" for key in listdict: if isinstance(listdict[key], list): listdict[key] = os.path.pathsep.join(listdict[key]) return listdict
python
def listdict2envdict(listdict): """Dict of lists --> Dict""" for key in listdict: if isinstance(listdict[key], list): listdict[key] = os.path.pathsep.join(listdict[key]) return listdict
[ "def", "listdict2envdict", "(", "listdict", ")", ":", "for", "key", "in", "listdict", ":", "if", "isinstance", "(", "listdict", "[", "key", "]", ",", "list", ")", ":", "listdict", "[", "key", "]", "=", "os", ".", "path", ".", "pathsep", ".", "join", "(", "listdict", "[", "key", "]", ")", "return", "listdict" ]
Dict of lists --> Dict
[ "Dict", "of", "lists", "--", ">", "Dict" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/environ.py#L33-L38
train
spyder-ide/spyder
spyder/utils/environ.py
main
def main(): """Run Windows environment variable editor""" from spyder.utils.qthelpers import qapplication app = qapplication() if os.name == 'nt': dialog = WinUserEnvDialog() else: dialog = EnvDialog() dialog.show() app.exec_()
python
def main(): """Run Windows environment variable editor""" from spyder.utils.qthelpers import qapplication app = qapplication() if os.name == 'nt': dialog = WinUserEnvDialog() else: dialog = EnvDialog() dialog.show() app.exec_()
[ "def", "main", "(", ")", ":", "from", "spyder", ".", "utils", ".", "qthelpers", "import", "qapplication", "app", "=", "qapplication", "(", ")", "if", "os", ".", "name", "==", "'nt'", ":", "dialog", "=", "WinUserEnvDialog", "(", ")", "else", ":", "dialog", "=", "EnvDialog", "(", ")", "dialog", ".", "show", "(", ")", "app", ".", "exec_", "(", ")" ]
Run Windows environment variable editor
[ "Run", "Windows", "environment", "variable", "editor" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/environ.py#L141-L150
train
spyder-ide/spyder
spyder/widgets/arraybuilder.py
NumpyArrayInline.keyPressEvent
def keyPressEvent(self, event): """ Qt override. """ if event.key() in [Qt.Key_Enter, Qt.Key_Return]: self._parent.process_text() if self._parent.is_valid(): self._parent.keyPressEvent(event) else: QLineEdit.keyPressEvent(self, event)
python
def keyPressEvent(self, event): """ Qt override. """ if event.key() in [Qt.Key_Enter, Qt.Key_Return]: self._parent.process_text() if self._parent.is_valid(): self._parent.keyPressEvent(event) else: QLineEdit.keyPressEvent(self, event)
[ "def", "keyPressEvent", "(", "self", ",", "event", ")", ":", "if", "event", ".", "key", "(", ")", "in", "[", "Qt", ".", "Key_Enter", ",", "Qt", ".", "Key_Return", "]", ":", "self", ".", "_parent", ".", "process_text", "(", ")", "if", "self", ".", "_parent", ".", "is_valid", "(", ")", ":", "self", ".", "_parent", ".", "keyPressEvent", "(", "event", ")", "else", ":", "QLineEdit", ".", "keyPressEvent", "(", "self", ",", "event", ")" ]
Qt override.
[ "Qt", "override", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/arraybuilder.py#L47-L56
train
spyder-ide/spyder
spyder/widgets/arraybuilder.py
NumpyArrayInline.event
def event(self, event): """ Qt override. This is needed to be able to intercept the Tab key press event. """ if event.type() == QEvent.KeyPress: if (event.key() == Qt.Key_Tab or event.key() == Qt.Key_Space): text = self.text() cursor = self.cursorPosition() # fix to include in "undo/redo" history if cursor != 0 and text[cursor-1] == ' ': text = text[:cursor-1] + ROW_SEPARATOR + ' ' +\ text[cursor:] else: text = text[:cursor] + ' ' + text[cursor:] self.setCursorPosition(cursor) self.setText(text) self.setCursorPosition(cursor + 1) return False return QWidget.event(self, event)
python
def event(self, event): """ Qt override. This is needed to be able to intercept the Tab key press event. """ if event.type() == QEvent.KeyPress: if (event.key() == Qt.Key_Tab or event.key() == Qt.Key_Space): text = self.text() cursor = self.cursorPosition() # fix to include in "undo/redo" history if cursor != 0 and text[cursor-1] == ' ': text = text[:cursor-1] + ROW_SEPARATOR + ' ' +\ text[cursor:] else: text = text[:cursor] + ' ' + text[cursor:] self.setCursorPosition(cursor) self.setText(text) self.setCursorPosition(cursor + 1) return False return QWidget.event(self, event)
[ "def", "event", "(", "self", ",", "event", ")", ":", "if", "event", ".", "type", "(", ")", "==", "QEvent", ".", "KeyPress", ":", "if", "(", "event", ".", "key", "(", ")", "==", "Qt", ".", "Key_Tab", "or", "event", ".", "key", "(", ")", "==", "Qt", ".", "Key_Space", ")", ":", "text", "=", "self", ".", "text", "(", ")", "cursor", "=", "self", ".", "cursorPosition", "(", ")", "# fix to include in \"undo/redo\" history\r", "if", "cursor", "!=", "0", "and", "text", "[", "cursor", "-", "1", "]", "==", "' '", ":", "text", "=", "text", "[", ":", "cursor", "-", "1", "]", "+", "ROW_SEPARATOR", "+", "' '", "+", "text", "[", "cursor", ":", "]", "else", ":", "text", "=", "text", "[", ":", "cursor", "]", "+", "' '", "+", "text", "[", "cursor", ":", "]", "self", ".", "setCursorPosition", "(", "cursor", ")", "self", ".", "setText", "(", "text", ")", "self", ".", "setCursorPosition", "(", "cursor", "+", "1", ")", "return", "False", "return", "QWidget", ".", "event", "(", "self", ",", "event", ")" ]
Qt override. This is needed to be able to intercept the Tab key press event.
[ "Qt", "override", ".", "This", "is", "needed", "to", "be", "able", "to", "intercept", "the", "Tab", "key", "press", "event", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/arraybuilder.py#L59-L79
train
spyder-ide/spyder
spyder/widgets/arraybuilder.py
NumpyArrayTable.keyPressEvent
def keyPressEvent(self, event): """ Qt override. """ if event.key() in [Qt.Key_Enter, Qt.Key_Return]: QTableWidget.keyPressEvent(self, event) # To avoid having to enter one final tab self.setDisabled(True) self.setDisabled(False) self._parent.keyPressEvent(event) else: QTableWidget.keyPressEvent(self, event)
python
def keyPressEvent(self, event): """ Qt override. """ if event.key() in [Qt.Key_Enter, Qt.Key_Return]: QTableWidget.keyPressEvent(self, event) # To avoid having to enter one final tab self.setDisabled(True) self.setDisabled(False) self._parent.keyPressEvent(event) else: QTableWidget.keyPressEvent(self, event)
[ "def", "keyPressEvent", "(", "self", ",", "event", ")", ":", "if", "event", ".", "key", "(", ")", "in", "[", "Qt", ".", "Key_Enter", ",", "Qt", ".", "Key_Return", "]", ":", "QTableWidget", ".", "keyPressEvent", "(", "self", ",", "event", ")", "# To avoid having to enter one final tab\r", "self", ".", "setDisabled", "(", "True", ")", "self", ".", "setDisabled", "(", "False", ")", "self", ".", "_parent", ".", "keyPressEvent", "(", "event", ")", "else", ":", "QTableWidget", ".", "keyPressEvent", "(", "self", ",", "event", ")" ]
Qt override.
[ "Qt", "override", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/arraybuilder.py#L93-L104
train
spyder-ide/spyder
spyder/widgets/arraybuilder.py
NumpyArrayTable.reset_headers
def reset_headers(self): """ Update the column and row numbering in the headers. """ rows = self.rowCount() cols = self.columnCount() for r in range(rows): self.setVerticalHeaderItem(r, QTableWidgetItem(str(r))) for c in range(cols): self.setHorizontalHeaderItem(c, QTableWidgetItem(str(c))) self.setColumnWidth(c, 40)
python
def reset_headers(self): """ Update the column and row numbering in the headers. """ rows = self.rowCount() cols = self.columnCount() for r in range(rows): self.setVerticalHeaderItem(r, QTableWidgetItem(str(r))) for c in range(cols): self.setHorizontalHeaderItem(c, QTableWidgetItem(str(c))) self.setColumnWidth(c, 40)
[ "def", "reset_headers", "(", "self", ")", ":", "rows", "=", "self", ".", "rowCount", "(", ")", "cols", "=", "self", ".", "columnCount", "(", ")", "for", "r", "in", "range", "(", "rows", ")", ":", "self", ".", "setVerticalHeaderItem", "(", "r", ",", "QTableWidgetItem", "(", "str", "(", "r", ")", ")", ")", "for", "c", "in", "range", "(", "cols", ")", ":", "self", ".", "setHorizontalHeaderItem", "(", "c", ",", "QTableWidgetItem", "(", "str", "(", "c", ")", ")", ")", "self", ".", "setColumnWidth", "(", "c", ",", "40", ")" ]
Update the column and row numbering in the headers.
[ "Update", "the", "column", "and", "row", "numbering", "in", "the", "headers", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/arraybuilder.py#L124-L135
train
spyder-ide/spyder
spyder/widgets/arraybuilder.py
NumpyArrayTable.text
def text(self): """ Return the entered array in a parseable form. """ text = [] rows = self.rowCount() cols = self.columnCount() # handle empty table case if rows == 2 and cols == 2: item = self.item(0, 0) if item is None: return '' for r in range(rows - 1): for c in range(cols - 1): item = self.item(r, c) if item is not None: value = item.text() else: value = '0' if not value.strip(): value = '0' text.append(' ') text.append(value) text.append(ROW_SEPARATOR) return ''.join(text[:-1])
python
def text(self): """ Return the entered array in a parseable form. """ text = [] rows = self.rowCount() cols = self.columnCount() # handle empty table case if rows == 2 and cols == 2: item = self.item(0, 0) if item is None: return '' for r in range(rows - 1): for c in range(cols - 1): item = self.item(r, c) if item is not None: value = item.text() else: value = '0' if not value.strip(): value = '0' text.append(' ') text.append(value) text.append(ROW_SEPARATOR) return ''.join(text[:-1])
[ "def", "text", "(", "self", ")", ":", "text", "=", "[", "]", "rows", "=", "self", ".", "rowCount", "(", ")", "cols", "=", "self", ".", "columnCount", "(", ")", "# handle empty table case\r", "if", "rows", "==", "2", "and", "cols", "==", "2", ":", "item", "=", "self", ".", "item", "(", "0", ",", "0", ")", "if", "item", "is", "None", ":", "return", "''", "for", "r", "in", "range", "(", "rows", "-", "1", ")", ":", "for", "c", "in", "range", "(", "cols", "-", "1", ")", ":", "item", "=", "self", ".", "item", "(", "r", ",", "c", ")", "if", "item", "is", "not", "None", ":", "value", "=", "item", ".", "text", "(", ")", "else", ":", "value", "=", "'0'", "if", "not", "value", ".", "strip", "(", ")", ":", "value", "=", "'0'", "text", ".", "append", "(", "' '", ")", "text", ".", "append", "(", "value", ")", "text", ".", "append", "(", "ROW_SEPARATOR", ")", "return", "''", ".", "join", "(", "text", "[", ":", "-", "1", "]", ")" ]
Return the entered array in a parseable form.
[ "Return", "the", "entered", "array", "in", "a", "parseable", "form", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/arraybuilder.py#L137-L166
train
spyder-ide/spyder
spyder/widgets/arraybuilder.py
NumpyArrayDialog.keyPressEvent
def keyPressEvent(self, event): """ Qt override. """ QToolTip.hideText() ctrl = event.modifiers() & Qt.ControlModifier if event.key() in [Qt.Key_Enter, Qt.Key_Return]: if ctrl: self.process_text(array=False) else: self.process_text(array=True) self.accept() else: QDialog.keyPressEvent(self, event)
python
def keyPressEvent(self, event): """ Qt override. """ QToolTip.hideText() ctrl = event.modifiers() & Qt.ControlModifier if event.key() in [Qt.Key_Enter, Qt.Key_Return]: if ctrl: self.process_text(array=False) else: self.process_text(array=True) self.accept() else: QDialog.keyPressEvent(self, event)
[ "def", "keyPressEvent", "(", "self", ",", "event", ")", ":", "QToolTip", ".", "hideText", "(", ")", "ctrl", "=", "event", ".", "modifiers", "(", ")", "&", "Qt", ".", "ControlModifier", "if", "event", ".", "key", "(", ")", "in", "[", "Qt", ".", "Key_Enter", ",", "Qt", ".", "Key_Return", "]", ":", "if", "ctrl", ":", "self", ".", "process_text", "(", "array", "=", "False", ")", "else", ":", "self", ".", "process_text", "(", "array", "=", "True", ")", "self", ".", "accept", "(", ")", "else", ":", "QDialog", ".", "keyPressEvent", "(", "self", ",", "event", ")" ]
Qt override.
[ "Qt", "override", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/arraybuilder.py#L271-L285
train
spyder-ide/spyder
spyder/widgets/arraybuilder.py
NumpyArrayDialog.event
def event(self, event): """ Qt Override. Usefull when in line edit mode. """ if event.type() == QEvent.KeyPress and event.key() == Qt.Key_Tab: return False return QWidget.event(self, event)
python
def event(self, event): """ Qt Override. Usefull when in line edit mode. """ if event.type() == QEvent.KeyPress and event.key() == Qt.Key_Tab: return False return QWidget.event(self, event)
[ "def", "event", "(", "self", ",", "event", ")", ":", "if", "event", ".", "type", "(", ")", "==", "QEvent", ".", "KeyPress", "and", "event", ".", "key", "(", ")", "==", "Qt", ".", "Key_Tab", ":", "return", "False", "return", "QWidget", ".", "event", "(", "self", ",", "event", ")" ]
Qt Override. Usefull when in line edit mode.
[ "Qt", "Override", ".", "Usefull", "when", "in", "line", "edit", "mode", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/arraybuilder.py#L287-L295
train
spyder-ide/spyder
spyder/widgets/arraybuilder.py
NumpyArrayDialog.process_text
def process_text(self, array=True): """ Construct the text based on the entered content in the widget. """ if array: prefix = 'np.array([[' else: prefix = 'np.matrix([[' suffix = ']])' values = self._widget.text().strip() if values != '': # cleans repeated spaces exp = r'(\s*)' + ROW_SEPARATOR + r'(\s*)' values = re.sub(exp, ROW_SEPARATOR, values) values = re.sub(r"\s+", " ", values) values = re.sub(r"]$", "", values) values = re.sub(r"^\[", "", values) values = re.sub(ROW_SEPARATOR + r'*$', '', values) # replaces spaces by commas values = values.replace(' ', ELEMENT_SEPARATOR) # iterate to find number of rows and columns new_values = [] rows = values.split(ROW_SEPARATOR) nrows = len(rows) ncols = [] for row in rows: new_row = [] elements = row.split(ELEMENT_SEPARATOR) ncols.append(len(elements)) for e in elements: num = e # replaces not defined values if num in NAN_VALUES: num = 'np.nan' # Convert numbers to floating point if self._force_float: try: num = str(float(e)) except: pass new_row.append(num) new_values.append(ELEMENT_SEPARATOR.join(new_row)) new_values = ROW_SEPARATOR.join(new_values) values = new_values # Check validity if len(set(ncols)) == 1: self._valid = True else: self._valid = False # Single rows are parsed as 1D arrays/matrices if nrows == 1: prefix = prefix[:-1] suffix = suffix.replace("]])", "])") # Fix offset offset = self._offset braces = BRACES.replace(' ', '\n' + ' '*(offset + len(prefix) - 1)) values = values.replace(ROW_SEPARATOR, braces) text = "{0}{1}{2}".format(prefix, values, suffix) self._text = text else: self._text = '' self.update_warning()
python
def process_text(self, array=True): """ Construct the text based on the entered content in the widget. """ if array: prefix = 'np.array([[' else: prefix = 'np.matrix([[' suffix = ']])' values = self._widget.text().strip() if values != '': # cleans repeated spaces exp = r'(\s*)' + ROW_SEPARATOR + r'(\s*)' values = re.sub(exp, ROW_SEPARATOR, values) values = re.sub(r"\s+", " ", values) values = re.sub(r"]$", "", values) values = re.sub(r"^\[", "", values) values = re.sub(ROW_SEPARATOR + r'*$', '', values) # replaces spaces by commas values = values.replace(' ', ELEMENT_SEPARATOR) # iterate to find number of rows and columns new_values = [] rows = values.split(ROW_SEPARATOR) nrows = len(rows) ncols = [] for row in rows: new_row = [] elements = row.split(ELEMENT_SEPARATOR) ncols.append(len(elements)) for e in elements: num = e # replaces not defined values if num in NAN_VALUES: num = 'np.nan' # Convert numbers to floating point if self._force_float: try: num = str(float(e)) except: pass new_row.append(num) new_values.append(ELEMENT_SEPARATOR.join(new_row)) new_values = ROW_SEPARATOR.join(new_values) values = new_values # Check validity if len(set(ncols)) == 1: self._valid = True else: self._valid = False # Single rows are parsed as 1D arrays/matrices if nrows == 1: prefix = prefix[:-1] suffix = suffix.replace("]])", "])") # Fix offset offset = self._offset braces = BRACES.replace(' ', '\n' + ' '*(offset + len(prefix) - 1)) values = values.replace(ROW_SEPARATOR, braces) text = "{0}{1}{2}".format(prefix, values, suffix) self._text = text else: self._text = '' self.update_warning()
[ "def", "process_text", "(", "self", ",", "array", "=", "True", ")", ":", "if", "array", ":", "prefix", "=", "'np.array([['", "else", ":", "prefix", "=", "'np.matrix([['", "suffix", "=", "']])'", "values", "=", "self", ".", "_widget", ".", "text", "(", ")", ".", "strip", "(", ")", "if", "values", "!=", "''", ":", "# cleans repeated spaces\r", "exp", "=", "r'(\\s*)'", "+", "ROW_SEPARATOR", "+", "r'(\\s*)'", "values", "=", "re", ".", "sub", "(", "exp", ",", "ROW_SEPARATOR", ",", "values", ")", "values", "=", "re", ".", "sub", "(", "r\"\\s+\"", ",", "\" \"", ",", "values", ")", "values", "=", "re", ".", "sub", "(", "r\"]$\"", ",", "\"\"", ",", "values", ")", "values", "=", "re", ".", "sub", "(", "r\"^\\[\"", ",", "\"\"", ",", "values", ")", "values", "=", "re", ".", "sub", "(", "ROW_SEPARATOR", "+", "r'*$'", ",", "''", ",", "values", ")", "# replaces spaces by commas\r", "values", "=", "values", ".", "replace", "(", "' '", ",", "ELEMENT_SEPARATOR", ")", "# iterate to find number of rows and columns\r", "new_values", "=", "[", "]", "rows", "=", "values", ".", "split", "(", "ROW_SEPARATOR", ")", "nrows", "=", "len", "(", "rows", ")", "ncols", "=", "[", "]", "for", "row", "in", "rows", ":", "new_row", "=", "[", "]", "elements", "=", "row", ".", "split", "(", "ELEMENT_SEPARATOR", ")", "ncols", ".", "append", "(", "len", "(", "elements", ")", ")", "for", "e", "in", "elements", ":", "num", "=", "e", "# replaces not defined values\r", "if", "num", "in", "NAN_VALUES", ":", "num", "=", "'np.nan'", "# Convert numbers to floating point\r", "if", "self", ".", "_force_float", ":", "try", ":", "num", "=", "str", "(", "float", "(", "e", ")", ")", "except", ":", "pass", "new_row", ".", "append", "(", "num", ")", "new_values", ".", "append", "(", "ELEMENT_SEPARATOR", ".", "join", "(", "new_row", ")", ")", "new_values", "=", "ROW_SEPARATOR", ".", "join", "(", "new_values", ")", "values", "=", "new_values", "# Check validity\r", "if", "len", "(", "set", "(", "ncols", ")", ")", "==", "1", ":", "self", ".", "_valid", "=", "True", "else", ":", "self", ".", "_valid", "=", "False", "# Single rows are parsed as 1D arrays/matrices\r", "if", "nrows", "==", "1", ":", "prefix", "=", "prefix", "[", ":", "-", "1", "]", "suffix", "=", "suffix", ".", "replace", "(", "\"]])\"", ",", "\"])\"", ")", "# Fix offset\r", "offset", "=", "self", ".", "_offset", "braces", "=", "BRACES", ".", "replace", "(", "' '", ",", "'\\n'", "+", "' '", "*", "(", "offset", "+", "len", "(", "prefix", ")", "-", "1", ")", ")", "values", "=", "values", ".", "replace", "(", "ROW_SEPARATOR", ",", "braces", ")", "text", "=", "\"{0}{1}{2}\"", ".", "format", "(", "prefix", ",", "values", ",", "suffix", ")", "self", ".", "_text", "=", "text", "else", ":", "self", ".", "_text", "=", "''", "self", ".", "update_warning", "(", ")" ]
Construct the text based on the entered content in the widget.
[ "Construct", "the", "text", "based", "on", "the", "entered", "content", "in", "the", "widget", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/arraybuilder.py#L297-L369
train
spyder-ide/spyder
spyder/widgets/arraybuilder.py
NumpyArrayDialog.update_warning
def update_warning(self): """ Updates the icon and tip based on the validity of the array content. """ widget = self._button_warning if not self.is_valid(): tip = _('Array dimensions not valid') widget.setIcon(ima.icon('MessageBoxWarning')) widget.setToolTip(tip) QToolTip.showText(self._widget.mapToGlobal(QPoint(0, 5)), tip) else: self._button_warning.setToolTip('')
python
def update_warning(self): """ Updates the icon and tip based on the validity of the array content. """ widget = self._button_warning if not self.is_valid(): tip = _('Array dimensions not valid') widget.setIcon(ima.icon('MessageBoxWarning')) widget.setToolTip(tip) QToolTip.showText(self._widget.mapToGlobal(QPoint(0, 5)), tip) else: self._button_warning.setToolTip('')
[ "def", "update_warning", "(", "self", ")", ":", "widget", "=", "self", ".", "_button_warning", "if", "not", "self", ".", "is_valid", "(", ")", ":", "tip", "=", "_", "(", "'Array dimensions not valid'", ")", "widget", ".", "setIcon", "(", "ima", ".", "icon", "(", "'MessageBoxWarning'", ")", ")", "widget", ".", "setToolTip", "(", "tip", ")", "QToolTip", ".", "showText", "(", "self", ".", "_widget", ".", "mapToGlobal", "(", "QPoint", "(", "0", ",", "5", ")", ")", ",", "tip", ")", "else", ":", "self", ".", "_button_warning", ".", "setToolTip", "(", "''", ")" ]
Updates the icon and tip based on the validity of the array content.
[ "Updates", "the", "icon", "and", "tip", "based", "on", "the", "validity", "of", "the", "array", "content", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/arraybuilder.py#L371-L382
train
spyder-ide/spyder
spyder/preferences/general.py
MainConfigPage._save_lang
def _save_lang(self): """ Get selected language setting and save to language configuration file. """ for combobox, (option, _default) in list(self.comboboxes.items()): if option == 'interface_language': data = combobox.itemData(combobox.currentIndex()) value = from_qvariant(data, to_text_string) break try: save_lang_conf(value) self.set_option('interface_language', value) except Exception: QMessageBox.critical( self, _("Error"), _("We're sorry but the following error occurred while trying " "to set your selected language:<br><br>" "<tt>{}</tt>").format(traceback.format_exc()), QMessageBox.Ok) return
python
def _save_lang(self): """ Get selected language setting and save to language configuration file. """ for combobox, (option, _default) in list(self.comboboxes.items()): if option == 'interface_language': data = combobox.itemData(combobox.currentIndex()) value = from_qvariant(data, to_text_string) break try: save_lang_conf(value) self.set_option('interface_language', value) except Exception: QMessageBox.critical( self, _("Error"), _("We're sorry but the following error occurred while trying " "to set your selected language:<br><br>" "<tt>{}</tt>").format(traceback.format_exc()), QMessageBox.Ok) return
[ "def", "_save_lang", "(", "self", ")", ":", "for", "combobox", ",", "(", "option", ",", "_default", ")", "in", "list", "(", "self", ".", "comboboxes", ".", "items", "(", ")", ")", ":", "if", "option", "==", "'interface_language'", ":", "data", "=", "combobox", ".", "itemData", "(", "combobox", ".", "currentIndex", "(", ")", ")", "value", "=", "from_qvariant", "(", "data", ",", "to_text_string", ")", "break", "try", ":", "save_lang_conf", "(", "value", ")", "self", ".", "set_option", "(", "'interface_language'", ",", "value", ")", "except", "Exception", ":", "QMessageBox", ".", "critical", "(", "self", ",", "_", "(", "\"Error\"", ")", ",", "_", "(", "\"We're sorry but the following error occurred while trying \"", "\"to set your selected language:<br><br>\"", "\"<tt>{}</tt>\"", ")", ".", "format", "(", "traceback", ".", "format_exc", "(", ")", ")", ",", "QMessageBox", ".", "Ok", ")", "return" ]
Get selected language setting and save to language configuration file.
[ "Get", "selected", "language", "setting", "and", "save", "to", "language", "configuration", "file", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/general.py#L262-L281
train
spyder-ide/spyder
spyder/plugins/projects/widgets/projectdialog.py
is_writable
def is_writable(path): """Check if path has write access""" try: testfile = tempfile.TemporaryFile(dir=path) testfile.close() except OSError as e: if e.errno == errno.EACCES: # 13 return False return True
python
def is_writable(path): """Check if path has write access""" try: testfile = tempfile.TemporaryFile(dir=path) testfile.close() except OSError as e: if e.errno == errno.EACCES: # 13 return False return True
[ "def", "is_writable", "(", "path", ")", ":", "try", ":", "testfile", "=", "tempfile", ".", "TemporaryFile", "(", "dir", "=", "path", ")", "testfile", ".", "close", "(", ")", "except", "OSError", "as", "e", ":", "if", "e", ".", "errno", "==", "errno", ".", "EACCES", ":", "# 13\r", "return", "False", "return", "True" ]
Check if path has write access
[ "Check", "if", "path", "has", "write", "access" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/widgets/projectdialog.py#L35-L43
train
spyder-ide/spyder
spyder/plugins/projects/widgets/projectdialog.py
ProjectDialog._get_project_types
def _get_project_types(self): """Get all available project types.""" project_types = get_available_project_types() projects = [] for project in project_types: projects.append(project.PROJECT_TYPE_NAME) return projects
python
def _get_project_types(self): """Get all available project types.""" project_types = get_available_project_types() projects = [] for project in project_types: projects.append(project.PROJECT_TYPE_NAME) return projects
[ "def", "_get_project_types", "(", "self", ")", ":", "project_types", "=", "get_available_project_types", "(", ")", "projects", "=", "[", "]", "for", "project", "in", "project_types", ":", "projects", ".", "append", "(", "project", ".", "PROJECT_TYPE_NAME", ")", "return", "projects" ]
Get all available project types.
[ "Get", "all", "available", "project", "types", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/widgets/projectdialog.py#L143-L151
train
spyder-ide/spyder
spyder/plugins/projects/widgets/projectdialog.py
ProjectDialog.select_location
def select_location(self): """Select directory.""" location = osp.normpath(getexistingdirectory(self, _("Select directory"), self.location)) if location: if is_writable(location): self.location = location self.update_location()
python
def select_location(self): """Select directory.""" location = osp.normpath(getexistingdirectory(self, _("Select directory"), self.location)) if location: if is_writable(location): self.location = location self.update_location()
[ "def", "select_location", "(", "self", ")", ":", "location", "=", "osp", ".", "normpath", "(", "getexistingdirectory", "(", "self", ",", "_", "(", "\"Select directory\"", ")", ",", "self", ".", "location", ")", ")", "if", "location", ":", "if", "is_writable", "(", "location", ")", ":", "self", ".", "location", "=", "location", "self", ".", "update_location", "(", ")" ]
Select directory.
[ "Select", "directory", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/widgets/projectdialog.py#L153-L162
train
spyder-ide/spyder
spyder/plugins/projects/widgets/projectdialog.py
ProjectDialog.update_location
def update_location(self, text=''): """Update text of location.""" self.text_project_name.setEnabled(self.radio_new_dir.isChecked()) name = self.text_project_name.text().strip() if name and self.radio_new_dir.isChecked(): path = osp.join(self.location, name) self.button_create.setDisabled(os.path.isdir(path)) elif self.radio_from_dir.isChecked(): self.button_create.setEnabled(True) path = self.location else: self.button_create.setEnabled(False) path = self.location self.text_location.setText(path)
python
def update_location(self, text=''): """Update text of location.""" self.text_project_name.setEnabled(self.radio_new_dir.isChecked()) name = self.text_project_name.text().strip() if name and self.radio_new_dir.isChecked(): path = osp.join(self.location, name) self.button_create.setDisabled(os.path.isdir(path)) elif self.radio_from_dir.isChecked(): self.button_create.setEnabled(True) path = self.location else: self.button_create.setEnabled(False) path = self.location self.text_location.setText(path)
[ "def", "update_location", "(", "self", ",", "text", "=", "''", ")", ":", "self", ".", "text_project_name", ".", "setEnabled", "(", "self", ".", "radio_new_dir", ".", "isChecked", "(", ")", ")", "name", "=", "self", ".", "text_project_name", ".", "text", "(", ")", ".", "strip", "(", ")", "if", "name", "and", "self", ".", "radio_new_dir", ".", "isChecked", "(", ")", ":", "path", "=", "osp", ".", "join", "(", "self", ".", "location", ",", "name", ")", "self", ".", "button_create", ".", "setDisabled", "(", "os", ".", "path", ".", "isdir", "(", "path", ")", ")", "elif", "self", ".", "radio_from_dir", ".", "isChecked", "(", ")", ":", "self", ".", "button_create", ".", "setEnabled", "(", "True", ")", "path", "=", "self", ".", "location", "else", ":", "self", ".", "button_create", ".", "setEnabled", "(", "False", ")", "path", "=", "self", ".", "location", "self", ".", "text_location", ".", "setText", "(", "path", ")" ]
Update text of location.
[ "Update", "text", "of", "location", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/widgets/projectdialog.py#L164-L179
train
spyder-ide/spyder
spyder/plugins/projects/widgets/projectdialog.py
ProjectDialog.create_project
def create_project(self): """Create project.""" packages = ['python={0}'.format(self.combo_python_version.currentText())] self.sig_project_creation_requested.emit( self.text_location.text(), self.combo_project_type.currentText(), packages) self.accept()
python
def create_project(self): """Create project.""" packages = ['python={0}'.format(self.combo_python_version.currentText())] self.sig_project_creation_requested.emit( self.text_location.text(), self.combo_project_type.currentText(), packages) self.accept()
[ "def", "create_project", "(", "self", ")", ":", "packages", "=", "[", "'python={0}'", ".", "format", "(", "self", ".", "combo_python_version", ".", "currentText", "(", ")", ")", "]", "self", ".", "sig_project_creation_requested", ".", "emit", "(", "self", ".", "text_location", ".", "text", "(", ")", ",", "self", ".", "combo_project_type", ".", "currentText", "(", ")", ",", "packages", ")", "self", ".", "accept", "(", ")" ]
Create project.
[ "Create", "project", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/widgets/projectdialog.py#L181-L188
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget.set_font
def set_font(self, font): """Set shell styles font""" self.setFont(font) self.set_pythonshell_font(font) cursor = self.textCursor() cursor.select(QTextCursor.Document) charformat = QTextCharFormat() charformat.setFontFamily(font.family()) charformat.setFontPointSize(font.pointSize()) cursor.mergeCharFormat(charformat)
python
def set_font(self, font): """Set shell styles font""" self.setFont(font) self.set_pythonshell_font(font) cursor = self.textCursor() cursor.select(QTextCursor.Document) charformat = QTextCharFormat() charformat.setFontFamily(font.family()) charformat.setFontPointSize(font.pointSize()) cursor.mergeCharFormat(charformat)
[ "def", "set_font", "(", "self", ",", "font", ")", ":", "self", ".", "setFont", "(", "font", ")", "self", ".", "set_pythonshell_font", "(", "font", ")", "cursor", "=", "self", ".", "textCursor", "(", ")", "cursor", ".", "select", "(", "QTextCursor", ".", "Document", ")", "charformat", "=", "QTextCharFormat", "(", ")", "charformat", ".", "setFontFamily", "(", "font", ".", "family", "(", ")", ")", "charformat", ".", "setFontPointSize", "(", "font", ".", "pointSize", "(", ")", ")", "cursor", ".", "mergeCharFormat", "(", "charformat", ")" ]
Set shell styles font
[ "Set", "shell", "styles", "font" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L108-L117
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget.setup_context_menu
def setup_context_menu(self): """Setup shell context menu""" self.menu = QMenu(self) self.cut_action = create_action(self, _("Cut"), shortcut=keybinding('Cut'), icon=ima.icon('editcut'), triggered=self.cut) self.copy_action = create_action(self, _("Copy"), shortcut=keybinding('Copy'), icon=ima.icon('editcopy'), triggered=self.copy) paste_action = create_action(self, _("Paste"), shortcut=keybinding('Paste'), icon=ima.icon('editpaste'), triggered=self.paste) save_action = create_action(self, _("Save history log..."), icon=ima.icon('filesave'), tip=_("Save current history log (i.e. all " "inputs and outputs) in a text file"), triggered=self.save_historylog) self.delete_action = create_action(self, _("Delete"), shortcut=keybinding('Delete'), icon=ima.icon('editdelete'), triggered=self.delete) selectall_action = create_action(self, _("Select All"), shortcut=keybinding('SelectAll'), icon=ima.icon('selectall'), triggered=self.selectAll) add_actions(self.menu, (self.cut_action, self.copy_action, paste_action, self.delete_action, None, selectall_action, None, save_action) )
python
def setup_context_menu(self): """Setup shell context menu""" self.menu = QMenu(self) self.cut_action = create_action(self, _("Cut"), shortcut=keybinding('Cut'), icon=ima.icon('editcut'), triggered=self.cut) self.copy_action = create_action(self, _("Copy"), shortcut=keybinding('Copy'), icon=ima.icon('editcopy'), triggered=self.copy) paste_action = create_action(self, _("Paste"), shortcut=keybinding('Paste'), icon=ima.icon('editpaste'), triggered=self.paste) save_action = create_action(self, _("Save history log..."), icon=ima.icon('filesave'), tip=_("Save current history log (i.e. all " "inputs and outputs) in a text file"), triggered=self.save_historylog) self.delete_action = create_action(self, _("Delete"), shortcut=keybinding('Delete'), icon=ima.icon('editdelete'), triggered=self.delete) selectall_action = create_action(self, _("Select All"), shortcut=keybinding('SelectAll'), icon=ima.icon('selectall'), triggered=self.selectAll) add_actions(self.menu, (self.cut_action, self.copy_action, paste_action, self.delete_action, None, selectall_action, None, save_action) )
[ "def", "setup_context_menu", "(", "self", ")", ":", "self", ".", "menu", "=", "QMenu", "(", "self", ")", "self", ".", "cut_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Cut\"", ")", ",", "shortcut", "=", "keybinding", "(", "'Cut'", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'editcut'", ")", ",", "triggered", "=", "self", ".", "cut", ")", "self", ".", "copy_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Copy\"", ")", ",", "shortcut", "=", "keybinding", "(", "'Copy'", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'editcopy'", ")", ",", "triggered", "=", "self", ".", "copy", ")", "paste_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Paste\"", ")", ",", "shortcut", "=", "keybinding", "(", "'Paste'", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'editpaste'", ")", ",", "triggered", "=", "self", ".", "paste", ")", "save_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Save history log...\"", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'filesave'", ")", ",", "tip", "=", "_", "(", "\"Save current history log (i.e. all \"", "\"inputs and outputs) in a text file\"", ")", ",", "triggered", "=", "self", ".", "save_historylog", ")", "self", ".", "delete_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Delete\"", ")", ",", "shortcut", "=", "keybinding", "(", "'Delete'", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'editdelete'", ")", ",", "triggered", "=", "self", ".", "delete", ")", "selectall_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Select All\"", ")", ",", "shortcut", "=", "keybinding", "(", "'SelectAll'", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'selectall'", ")", ",", "triggered", "=", "self", ".", "selectAll", ")", "add_actions", "(", "self", ".", "menu", ",", "(", "self", ".", "cut_action", ",", "self", ".", "copy_action", ",", "paste_action", ",", "self", ".", "delete_action", ",", "None", ",", "selectall_action", ",", "None", ",", "save_action", ")", ")" ]
Setup shell context menu
[ "Setup", "shell", "context", "menu" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L121-L151
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget.contextMenuEvent
def contextMenuEvent(self, event): """Reimplement Qt method""" state = self.has_selected_text() self.copy_action.setEnabled(state) self.cut_action.setEnabled(state) self.delete_action.setEnabled(state) self.menu.popup(event.globalPos()) event.accept()
python
def contextMenuEvent(self, event): """Reimplement Qt method""" state = self.has_selected_text() self.copy_action.setEnabled(state) self.cut_action.setEnabled(state) self.delete_action.setEnabled(state) self.menu.popup(event.globalPos()) event.accept()
[ "def", "contextMenuEvent", "(", "self", ",", "event", ")", ":", "state", "=", "self", ".", "has_selected_text", "(", ")", "self", ".", "copy_action", ".", "setEnabled", "(", "state", ")", "self", ".", "cut_action", ".", "setEnabled", "(", "state", ")", "self", ".", "delete_action", ".", "setEnabled", "(", "state", ")", "self", ".", "menu", ".", "popup", "(", "event", ".", "globalPos", "(", ")", ")", "event", ".", "accept", "(", ")" ]
Reimplement Qt method
[ "Reimplement", "Qt", "method" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L153-L160
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget._select_input
def _select_input(self): """Select current line (without selecting console prompt)""" line, index = self.get_position('eof') if self.current_prompt_pos is None: pline, pindex = line, index else: pline, pindex = self.current_prompt_pos self.setSelection(pline, pindex, line, index)
python
def _select_input(self): """Select current line (without selecting console prompt)""" line, index = self.get_position('eof') if self.current_prompt_pos is None: pline, pindex = line, index else: pline, pindex = self.current_prompt_pos self.setSelection(pline, pindex, line, index)
[ "def", "_select_input", "(", "self", ")", ":", "line", ",", "index", "=", "self", ".", "get_position", "(", "'eof'", ")", "if", "self", ".", "current_prompt_pos", "is", "None", ":", "pline", ",", "pindex", "=", "line", ",", "index", "else", ":", "pline", ",", "pindex", "=", "self", ".", "current_prompt_pos", "self", ".", "setSelection", "(", "pline", ",", "pindex", ",", "line", ",", "index", ")" ]
Select current line (without selecting console prompt)
[ "Select", "current", "line", "(", "without", "selecting", "console", "prompt", ")" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L167-L174
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget._set_input_buffer
def _set_input_buffer(self, text): """Set input buffer""" if self.current_prompt_pos is not None: self.replace_text(self.current_prompt_pos, 'eol', text) else: self.insert(text) self.set_cursor_position('eof')
python
def _set_input_buffer(self, text): """Set input buffer""" if self.current_prompt_pos is not None: self.replace_text(self.current_prompt_pos, 'eol', text) else: self.insert(text) self.set_cursor_position('eof')
[ "def", "_set_input_buffer", "(", "self", ",", "text", ")", ":", "if", "self", ".", "current_prompt_pos", "is", "not", "None", ":", "self", ".", "replace_text", "(", "self", ".", "current_prompt_pos", ",", "'eol'", ",", "text", ")", "else", ":", "self", ".", "insert", "(", "text", ")", "self", ".", "set_cursor_position", "(", "'eof'", ")" ]
Set input buffer
[ "Set", "input", "buffer" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L185-L191
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget._get_input_buffer
def _get_input_buffer(self): """Return input buffer""" input_buffer = '' if self.current_prompt_pos is not None: input_buffer = self.get_text(self.current_prompt_pos, 'eol') input_buffer = input_buffer.replace(os.linesep, '\n') return input_buffer
python
def _get_input_buffer(self): """Return input buffer""" input_buffer = '' if self.current_prompt_pos is not None: input_buffer = self.get_text(self.current_prompt_pos, 'eol') input_buffer = input_buffer.replace(os.linesep, '\n') return input_buffer
[ "def", "_get_input_buffer", "(", "self", ")", ":", "input_buffer", "=", "''", "if", "self", ".", "current_prompt_pos", "is", "not", "None", ":", "input_buffer", "=", "self", ".", "get_text", "(", "self", ".", "current_prompt_pos", ",", "'eol'", ")", "input_buffer", "=", "input_buffer", ".", "replace", "(", "os", ".", "linesep", ",", "'\\n'", ")", "return", "input_buffer" ]
Return input buffer
[ "Return", "input", "buffer" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L193-L199
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget.new_prompt
def new_prompt(self, prompt): """ Print a new prompt and save its (line, index) position """ if self.get_cursor_line_column()[1] != 0: self.write('\n') self.write(prompt, prompt=True) # now we update our cursor giving end of prompt self.current_prompt_pos = self.get_position('cursor') self.ensureCursorVisible() self.new_input_line = False
python
def new_prompt(self, prompt): """ Print a new prompt and save its (line, index) position """ if self.get_cursor_line_column()[1] != 0: self.write('\n') self.write(prompt, prompt=True) # now we update our cursor giving end of prompt self.current_prompt_pos = self.get_position('cursor') self.ensureCursorVisible() self.new_input_line = False
[ "def", "new_prompt", "(", "self", ",", "prompt", ")", ":", "if", "self", ".", "get_cursor_line_column", "(", ")", "[", "1", "]", "!=", "0", ":", "self", ".", "write", "(", "'\\n'", ")", "self", ".", "write", "(", "prompt", ",", "prompt", "=", "True", ")", "# now we update our cursor giving end of prompt\r", "self", ".", "current_prompt_pos", "=", "self", ".", "get_position", "(", "'cursor'", ")", "self", ".", "ensureCursorVisible", "(", ")", "self", ".", "new_input_line", "=", "False" ]
Print a new prompt and save its (line, index) position
[ "Print", "a", "new", "prompt", "and", "save", "its", "(", "line", "index", ")", "position" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L205-L215
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget.check_selection
def check_selection(self): """ Check if selected text is r/w, otherwise remove read-only parts of selection """ if self.current_prompt_pos is None: self.set_cursor_position('eof') else: self.truncate_selection(self.current_prompt_pos)
python
def check_selection(self): """ Check if selected text is r/w, otherwise remove read-only parts of selection """ if self.current_prompt_pos is None: self.set_cursor_position('eof') else: self.truncate_selection(self.current_prompt_pos)
[ "def", "check_selection", "(", "self", ")", ":", "if", "self", ".", "current_prompt_pos", "is", "None", ":", "self", ".", "set_cursor_position", "(", "'eof'", ")", "else", ":", "self", ".", "truncate_selection", "(", "self", ".", "current_prompt_pos", ")" ]
Check if selected text is r/w, otherwise remove read-only parts of selection
[ "Check", "if", "selected", "text", "is", "r", "/", "w", "otherwise", "remove", "read", "-", "only", "parts", "of", "selection" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L217-L225
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget.copy
def copy(self): """Copy text to clipboard... or keyboard interrupt""" if self.has_selected_text(): ConsoleBaseWidget.copy(self) elif not sys.platform == 'darwin': self.interrupt()
python
def copy(self): """Copy text to clipboard... or keyboard interrupt""" if self.has_selected_text(): ConsoleBaseWidget.copy(self) elif not sys.platform == 'darwin': self.interrupt()
[ "def", "copy", "(", "self", ")", ":", "if", "self", ".", "has_selected_text", "(", ")", ":", "ConsoleBaseWidget", ".", "copy", "(", "self", ")", "elif", "not", "sys", ".", "platform", "==", "'darwin'", ":", "self", ".", "interrupt", "(", ")" ]
Copy text to clipboard... or keyboard interrupt
[ "Copy", "text", "to", "clipboard", "...", "or", "keyboard", "interrupt" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L230-L235
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget.save_historylog
def save_historylog(self): """Save current history log (all text in console)""" title = _("Save history log") self.redirect_stdio.emit(False) filename, _selfilter = getsavefilename(self, title, self.historylog_filename, "%s (*.log)" % _("History logs")) self.redirect_stdio.emit(True) if filename: filename = osp.normpath(filename) try: encoding.write(to_text_string(self.get_text_with_eol()), filename) self.historylog_filename = filename CONF.set('main', 'historylog_filename', filename) except EnvironmentError: pass
python
def save_historylog(self): """Save current history log (all text in console)""" title = _("Save history log") self.redirect_stdio.emit(False) filename, _selfilter = getsavefilename(self, title, self.historylog_filename, "%s (*.log)" % _("History logs")) self.redirect_stdio.emit(True) if filename: filename = osp.normpath(filename) try: encoding.write(to_text_string(self.get_text_with_eol()), filename) self.historylog_filename = filename CONF.set('main', 'historylog_filename', filename) except EnvironmentError: pass
[ "def", "save_historylog", "(", "self", ")", ":", "title", "=", "_", "(", "\"Save history log\"", ")", "self", ".", "redirect_stdio", ".", "emit", "(", "False", ")", "filename", ",", "_selfilter", "=", "getsavefilename", "(", "self", ",", "title", ",", "self", ".", "historylog_filename", ",", "\"%s (*.log)\"", "%", "_", "(", "\"History logs\"", ")", ")", "self", ".", "redirect_stdio", ".", "emit", "(", "True", ")", "if", "filename", ":", "filename", "=", "osp", ".", "normpath", "(", "filename", ")", "try", ":", "encoding", ".", "write", "(", "to_text_string", "(", "self", ".", "get_text_with_eol", "(", ")", ")", ",", "filename", ")", "self", ".", "historylog_filename", "=", "filename", "CONF", ".", "set", "(", "'main'", ",", "'historylog_filename'", ",", "filename", ")", "except", "EnvironmentError", ":", "pass" ]
Save current history log (all text in console)
[ "Save", "current", "history", "log", "(", "all", "text", "in", "console", ")" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L256-L271
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget.on_new_line
def on_new_line(self): """On new input line""" self.set_cursor_position('eof') self.current_prompt_pos = self.get_position('cursor') self.new_input_line = False
python
def on_new_line(self): """On new input line""" self.set_cursor_position('eof') self.current_prompt_pos = self.get_position('cursor') self.new_input_line = False
[ "def", "on_new_line", "(", "self", ")", ":", "self", ".", "set_cursor_position", "(", "'eof'", ")", "self", ".", "current_prompt_pos", "=", "self", ".", "get_position", "(", "'cursor'", ")", "self", ".", "new_input_line", "=", "False" ]
On new input line
[ "On", "new", "input", "line" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L283-L287
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget.preprocess_keyevent
def preprocess_keyevent(self, event): """Pre-process keypress event: return True if event is accepted, false otherwise""" # Copy must be done first to be able to copy read-only text parts # (otherwise, right below, we would remove selection # if not on current line) ctrl = event.modifiers() & Qt.ControlModifier meta = event.modifiers() & Qt.MetaModifier # meta=ctrl in OSX if event.key() == Qt.Key_C and \ ((Qt.MetaModifier | Qt.ControlModifier) & event.modifiers()): if meta and sys.platform == 'darwin': self.interrupt() elif ctrl: self.copy() event.accept() return True if self.new_input_line and ( len(event.text()) or event.key() in \ (Qt.Key_Up, Qt.Key_Down, Qt.Key_Left, Qt.Key_Right) ): self.on_new_line() return False
python
def preprocess_keyevent(self, event): """Pre-process keypress event: return True if event is accepted, false otherwise""" # Copy must be done first to be able to copy read-only text parts # (otherwise, right below, we would remove selection # if not on current line) ctrl = event.modifiers() & Qt.ControlModifier meta = event.modifiers() & Qt.MetaModifier # meta=ctrl in OSX if event.key() == Qt.Key_C and \ ((Qt.MetaModifier | Qt.ControlModifier) & event.modifiers()): if meta and sys.platform == 'darwin': self.interrupt() elif ctrl: self.copy() event.accept() return True if self.new_input_line and ( len(event.text()) or event.key() in \ (Qt.Key_Up, Qt.Key_Down, Qt.Key_Left, Qt.Key_Right) ): self.on_new_line() return False
[ "def", "preprocess_keyevent", "(", "self", ",", "event", ")", ":", "# Copy must be done first to be able to copy read-only text parts\r", "# (otherwise, right below, we would remove selection\r", "# if not on current line)\r", "ctrl", "=", "event", ".", "modifiers", "(", ")", "&", "Qt", ".", "ControlModifier", "meta", "=", "event", ".", "modifiers", "(", ")", "&", "Qt", ".", "MetaModifier", "# meta=ctrl in OSX\r", "if", "event", ".", "key", "(", ")", "==", "Qt", ".", "Key_C", "and", "(", "(", "Qt", ".", "MetaModifier", "|", "Qt", ".", "ControlModifier", ")", "&", "event", ".", "modifiers", "(", ")", ")", ":", "if", "meta", "and", "sys", ".", "platform", "==", "'darwin'", ":", "self", ".", "interrupt", "(", ")", "elif", "ctrl", ":", "self", ".", "copy", "(", ")", "event", ".", "accept", "(", ")", "return", "True", "if", "self", ".", "new_input_line", "and", "(", "len", "(", "event", ".", "text", "(", ")", ")", "or", "event", ".", "key", "(", ")", "in", "(", "Qt", ".", "Key_Up", ",", "Qt", ".", "Key_Down", ",", "Qt", ".", "Key_Left", ",", "Qt", ".", "Key_Right", ")", ")", ":", "self", ".", "on_new_line", "(", ")", "return", "False" ]
Pre-process keypress event: return True if event is accepted, false otherwise
[ "Pre", "-", "process", "keypress", "event", ":", "return", "True", "if", "event", "is", "accepted", "false", "otherwise" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L307-L328
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget.postprocess_keyevent
def postprocess_keyevent(self, event): """Post-process keypress event: in InternalShell, this is method is called when shell is ready""" event, text, key, ctrl, shift = restore_keyevent(event) # Is cursor on the last line? and after prompt? if len(text): #XXX: Shouldn't it be: `if len(unicode(text).strip(os.linesep))` ? if self.has_selected_text(): self.check_selection() self.restrict_cursor_position(self.current_prompt_pos, 'eof') cursor_position = self.get_position('cursor') if key in (Qt.Key_Return, Qt.Key_Enter): if self.is_cursor_on_last_line(): self._key_enter() # add and run selection else: self.insert_text(self.get_selected_text(), at_end=True) elif key == Qt.Key_Insert and not shift and not ctrl: self.setOverwriteMode(not self.overwriteMode()) elif key == Qt.Key_Delete: if self.has_selected_text(): self.check_selection() self.remove_selected_text() elif self.is_cursor_on_last_line(): self.stdkey_clear() elif key == Qt.Key_Backspace: self._key_backspace(cursor_position) elif key == Qt.Key_Tab: self._key_tab() elif key == Qt.Key_Space and ctrl: self._key_ctrl_space() elif key == Qt.Key_Left: if self.current_prompt_pos == cursor_position: # Avoid moving cursor on prompt return method = self.extend_selection_to_next if shift \ else self.move_cursor_to_next method('word' if ctrl else 'character', direction='left') elif key == Qt.Key_Right: if self.is_cursor_at_end(): return method = self.extend_selection_to_next if shift \ else self.move_cursor_to_next method('word' if ctrl else 'character', direction='right') elif (key == Qt.Key_Home) or ((key == Qt.Key_Up) and ctrl): self._key_home(shift, ctrl) elif (key == Qt.Key_End) or ((key == Qt.Key_Down) and ctrl): self._key_end(shift, ctrl) elif key == Qt.Key_Up: if not self.is_cursor_on_last_line(): self.set_cursor_position('eof') y_cursor = self.get_coordinates(cursor_position)[1] y_prompt = self.get_coordinates(self.current_prompt_pos)[1] if y_cursor > y_prompt: self.stdkey_up(shift) else: self.browse_history(backward=True) elif key == Qt.Key_Down: if not self.is_cursor_on_last_line(): self.set_cursor_position('eof') y_cursor = self.get_coordinates(cursor_position)[1] y_end = self.get_coordinates('eol')[1] if y_cursor < y_end: self.stdkey_down(shift) else: self.browse_history(backward=False) elif key in (Qt.Key_PageUp, Qt.Key_PageDown): #XXX: Find a way to do this programmatically instead of calling # widget keyhandler (this won't work if the *event* is coming from # the event queue - i.e. if the busy buffer is ever implemented) ConsoleBaseWidget.keyPressEvent(self, event) elif key == Qt.Key_Escape and shift: self.clear_line() elif key == Qt.Key_Escape: self._key_escape() elif key == Qt.Key_L and ctrl: self.clear_terminal() elif key == Qt.Key_V and ctrl: self.paste() elif key == Qt.Key_X and ctrl: self.cut() elif key == Qt.Key_Z and ctrl: self.undo() elif key == Qt.Key_Y and ctrl: self.redo() elif key == Qt.Key_A and ctrl: self.selectAll() elif key == Qt.Key_Question and not self.has_selected_text(): self._key_question(text) elif key == Qt.Key_ParenLeft and not self.has_selected_text(): self._key_parenleft(text) elif key == Qt.Key_Period and not self.has_selected_text(): self._key_period(text) elif len(text) and not self.isReadOnly(): self.hist_wholeline = False self.insert_text(text) self._key_other(text) else: # Let the parent widget handle the key press event ConsoleBaseWidget.keyPressEvent(self, event)
python
def postprocess_keyevent(self, event): """Post-process keypress event: in InternalShell, this is method is called when shell is ready""" event, text, key, ctrl, shift = restore_keyevent(event) # Is cursor on the last line? and after prompt? if len(text): #XXX: Shouldn't it be: `if len(unicode(text).strip(os.linesep))` ? if self.has_selected_text(): self.check_selection() self.restrict_cursor_position(self.current_prompt_pos, 'eof') cursor_position = self.get_position('cursor') if key in (Qt.Key_Return, Qt.Key_Enter): if self.is_cursor_on_last_line(): self._key_enter() # add and run selection else: self.insert_text(self.get_selected_text(), at_end=True) elif key == Qt.Key_Insert and not shift and not ctrl: self.setOverwriteMode(not self.overwriteMode()) elif key == Qt.Key_Delete: if self.has_selected_text(): self.check_selection() self.remove_selected_text() elif self.is_cursor_on_last_line(): self.stdkey_clear() elif key == Qt.Key_Backspace: self._key_backspace(cursor_position) elif key == Qt.Key_Tab: self._key_tab() elif key == Qt.Key_Space and ctrl: self._key_ctrl_space() elif key == Qt.Key_Left: if self.current_prompt_pos == cursor_position: # Avoid moving cursor on prompt return method = self.extend_selection_to_next if shift \ else self.move_cursor_to_next method('word' if ctrl else 'character', direction='left') elif key == Qt.Key_Right: if self.is_cursor_at_end(): return method = self.extend_selection_to_next if shift \ else self.move_cursor_to_next method('word' if ctrl else 'character', direction='right') elif (key == Qt.Key_Home) or ((key == Qt.Key_Up) and ctrl): self._key_home(shift, ctrl) elif (key == Qt.Key_End) or ((key == Qt.Key_Down) and ctrl): self._key_end(shift, ctrl) elif key == Qt.Key_Up: if not self.is_cursor_on_last_line(): self.set_cursor_position('eof') y_cursor = self.get_coordinates(cursor_position)[1] y_prompt = self.get_coordinates(self.current_prompt_pos)[1] if y_cursor > y_prompt: self.stdkey_up(shift) else: self.browse_history(backward=True) elif key == Qt.Key_Down: if not self.is_cursor_on_last_line(): self.set_cursor_position('eof') y_cursor = self.get_coordinates(cursor_position)[1] y_end = self.get_coordinates('eol')[1] if y_cursor < y_end: self.stdkey_down(shift) else: self.browse_history(backward=False) elif key in (Qt.Key_PageUp, Qt.Key_PageDown): #XXX: Find a way to do this programmatically instead of calling # widget keyhandler (this won't work if the *event* is coming from # the event queue - i.e. if the busy buffer is ever implemented) ConsoleBaseWidget.keyPressEvent(self, event) elif key == Qt.Key_Escape and shift: self.clear_line() elif key == Qt.Key_Escape: self._key_escape() elif key == Qt.Key_L and ctrl: self.clear_terminal() elif key == Qt.Key_V and ctrl: self.paste() elif key == Qt.Key_X and ctrl: self.cut() elif key == Qt.Key_Z and ctrl: self.undo() elif key == Qt.Key_Y and ctrl: self.redo() elif key == Qt.Key_A and ctrl: self.selectAll() elif key == Qt.Key_Question and not self.has_selected_text(): self._key_question(text) elif key == Qt.Key_ParenLeft and not self.has_selected_text(): self._key_parenleft(text) elif key == Qt.Key_Period and not self.has_selected_text(): self._key_period(text) elif len(text) and not self.isReadOnly(): self.hist_wholeline = False self.insert_text(text) self._key_other(text) else: # Let the parent widget handle the key press event ConsoleBaseWidget.keyPressEvent(self, event)
[ "def", "postprocess_keyevent", "(", "self", ",", "event", ")", ":", "event", ",", "text", ",", "key", ",", "ctrl", ",", "shift", "=", "restore_keyevent", "(", "event", ")", "# Is cursor on the last line? and after prompt?\r", "if", "len", "(", "text", ")", ":", "#XXX: Shouldn't it be: `if len(unicode(text).strip(os.linesep))` ?\r", "if", "self", ".", "has_selected_text", "(", ")", ":", "self", ".", "check_selection", "(", ")", "self", ".", "restrict_cursor_position", "(", "self", ".", "current_prompt_pos", ",", "'eof'", ")", "cursor_position", "=", "self", ".", "get_position", "(", "'cursor'", ")", "if", "key", "in", "(", "Qt", ".", "Key_Return", ",", "Qt", ".", "Key_Enter", ")", ":", "if", "self", ".", "is_cursor_on_last_line", "(", ")", ":", "self", ".", "_key_enter", "(", ")", "# add and run selection\r", "else", ":", "self", ".", "insert_text", "(", "self", ".", "get_selected_text", "(", ")", ",", "at_end", "=", "True", ")", "elif", "key", "==", "Qt", ".", "Key_Insert", "and", "not", "shift", "and", "not", "ctrl", ":", "self", ".", "setOverwriteMode", "(", "not", "self", ".", "overwriteMode", "(", ")", ")", "elif", "key", "==", "Qt", ".", "Key_Delete", ":", "if", "self", ".", "has_selected_text", "(", ")", ":", "self", ".", "check_selection", "(", ")", "self", ".", "remove_selected_text", "(", ")", "elif", "self", ".", "is_cursor_on_last_line", "(", ")", ":", "self", ".", "stdkey_clear", "(", ")", "elif", "key", "==", "Qt", ".", "Key_Backspace", ":", "self", ".", "_key_backspace", "(", "cursor_position", ")", "elif", "key", "==", "Qt", ".", "Key_Tab", ":", "self", ".", "_key_tab", "(", ")", "elif", "key", "==", "Qt", ".", "Key_Space", "and", "ctrl", ":", "self", ".", "_key_ctrl_space", "(", ")", "elif", "key", "==", "Qt", ".", "Key_Left", ":", "if", "self", ".", "current_prompt_pos", "==", "cursor_position", ":", "# Avoid moving cursor on prompt\r", "return", "method", "=", "self", ".", "extend_selection_to_next", "if", "shift", "else", "self", ".", "move_cursor_to_next", "method", "(", "'word'", "if", "ctrl", "else", "'character'", ",", "direction", "=", "'left'", ")", "elif", "key", "==", "Qt", ".", "Key_Right", ":", "if", "self", ".", "is_cursor_at_end", "(", ")", ":", "return", "method", "=", "self", ".", "extend_selection_to_next", "if", "shift", "else", "self", ".", "move_cursor_to_next", "method", "(", "'word'", "if", "ctrl", "else", "'character'", ",", "direction", "=", "'right'", ")", "elif", "(", "key", "==", "Qt", ".", "Key_Home", ")", "or", "(", "(", "key", "==", "Qt", ".", "Key_Up", ")", "and", "ctrl", ")", ":", "self", ".", "_key_home", "(", "shift", ",", "ctrl", ")", "elif", "(", "key", "==", "Qt", ".", "Key_End", ")", "or", "(", "(", "key", "==", "Qt", ".", "Key_Down", ")", "and", "ctrl", ")", ":", "self", ".", "_key_end", "(", "shift", ",", "ctrl", ")", "elif", "key", "==", "Qt", ".", "Key_Up", ":", "if", "not", "self", ".", "is_cursor_on_last_line", "(", ")", ":", "self", ".", "set_cursor_position", "(", "'eof'", ")", "y_cursor", "=", "self", ".", "get_coordinates", "(", "cursor_position", ")", "[", "1", "]", "y_prompt", "=", "self", ".", "get_coordinates", "(", "self", ".", "current_prompt_pos", ")", "[", "1", "]", "if", "y_cursor", ">", "y_prompt", ":", "self", ".", "stdkey_up", "(", "shift", ")", "else", ":", "self", ".", "browse_history", "(", "backward", "=", "True", ")", "elif", "key", "==", "Qt", ".", "Key_Down", ":", "if", "not", "self", ".", "is_cursor_on_last_line", "(", ")", ":", "self", ".", "set_cursor_position", "(", "'eof'", ")", "y_cursor", "=", "self", ".", "get_coordinates", "(", "cursor_position", ")", "[", "1", "]", "y_end", "=", "self", ".", "get_coordinates", "(", "'eol'", ")", "[", "1", "]", "if", "y_cursor", "<", "y_end", ":", "self", ".", "stdkey_down", "(", "shift", ")", "else", ":", "self", ".", "browse_history", "(", "backward", "=", "False", ")", "elif", "key", "in", "(", "Qt", ".", "Key_PageUp", ",", "Qt", ".", "Key_PageDown", ")", ":", "#XXX: Find a way to do this programmatically instead of calling\r", "# widget keyhandler (this won't work if the *event* is coming from\r", "# the event queue - i.e. if the busy buffer is ever implemented)\r", "ConsoleBaseWidget", ".", "keyPressEvent", "(", "self", ",", "event", ")", "elif", "key", "==", "Qt", ".", "Key_Escape", "and", "shift", ":", "self", ".", "clear_line", "(", ")", "elif", "key", "==", "Qt", ".", "Key_Escape", ":", "self", ".", "_key_escape", "(", ")", "elif", "key", "==", "Qt", ".", "Key_L", "and", "ctrl", ":", "self", ".", "clear_terminal", "(", ")", "elif", "key", "==", "Qt", ".", "Key_V", "and", "ctrl", ":", "self", ".", "paste", "(", ")", "elif", "key", "==", "Qt", ".", "Key_X", "and", "ctrl", ":", "self", ".", "cut", "(", ")", "elif", "key", "==", "Qt", ".", "Key_Z", "and", "ctrl", ":", "self", ".", "undo", "(", ")", "elif", "key", "==", "Qt", ".", "Key_Y", "and", "ctrl", ":", "self", ".", "redo", "(", ")", "elif", "key", "==", "Qt", ".", "Key_A", "and", "ctrl", ":", "self", ".", "selectAll", "(", ")", "elif", "key", "==", "Qt", ".", "Key_Question", "and", "not", "self", ".", "has_selected_text", "(", ")", ":", "self", ".", "_key_question", "(", "text", ")", "elif", "key", "==", "Qt", ".", "Key_ParenLeft", "and", "not", "self", ".", "has_selected_text", "(", ")", ":", "self", ".", "_key_parenleft", "(", "text", ")", "elif", "key", "==", "Qt", ".", "Key_Period", "and", "not", "self", ".", "has_selected_text", "(", ")", ":", "self", ".", "_key_period", "(", "text", ")", "elif", "len", "(", "text", ")", "and", "not", "self", ".", "isReadOnly", "(", ")", ":", "self", ".", "hist_wholeline", "=", "False", "self", ".", "insert_text", "(", "text", ")", "self", ".", "_key_other", "(", "text", ")", "else", ":", "# Let the parent widget handle the key press event\r", "ConsoleBaseWidget", ".", "keyPressEvent", "(", "self", ",", "event", ")" ]
Post-process keypress event: in InternalShell, this is method is called when shell is ready
[ "Post", "-", "process", "keypress", "event", ":", "in", "InternalShell", "this", "is", "method", "is", "called", "when", "shell", "is", "ready" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L330-L457
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget.load_history
def load_history(self): """Load history from a .py file in user home directory""" if osp.isfile(self.history_filename): rawhistory, _ = encoding.readlines(self.history_filename) rawhistory = [line.replace('\n', '') for line in rawhistory] if rawhistory[1] != self.INITHISTORY[1]: rawhistory[1] = self.INITHISTORY[1] else: rawhistory = self.INITHISTORY history = [line for line in rawhistory \ if line and not line.startswith('#')] # Truncating history to X entries: while len(history) >= CONF.get('historylog', 'max_entries'): del history[0] while rawhistory[0].startswith('#'): del rawhistory[0] del rawhistory[0] # Saving truncated history: try: encoding.writelines(rawhistory, self.history_filename) except EnvironmentError: pass return history
python
def load_history(self): """Load history from a .py file in user home directory""" if osp.isfile(self.history_filename): rawhistory, _ = encoding.readlines(self.history_filename) rawhistory = [line.replace('\n', '') for line in rawhistory] if rawhistory[1] != self.INITHISTORY[1]: rawhistory[1] = self.INITHISTORY[1] else: rawhistory = self.INITHISTORY history = [line for line in rawhistory \ if line and not line.startswith('#')] # Truncating history to X entries: while len(history) >= CONF.get('historylog', 'max_entries'): del history[0] while rawhistory[0].startswith('#'): del rawhistory[0] del rawhistory[0] # Saving truncated history: try: encoding.writelines(rawhistory, self.history_filename) except EnvironmentError: pass return history
[ "def", "load_history", "(", "self", ")", ":", "if", "osp", ".", "isfile", "(", "self", ".", "history_filename", ")", ":", "rawhistory", ",", "_", "=", "encoding", ".", "readlines", "(", "self", ".", "history_filename", ")", "rawhistory", "=", "[", "line", ".", "replace", "(", "'\\n'", ",", "''", ")", "for", "line", "in", "rawhistory", "]", "if", "rawhistory", "[", "1", "]", "!=", "self", ".", "INITHISTORY", "[", "1", "]", ":", "rawhistory", "[", "1", "]", "=", "self", ".", "INITHISTORY", "[", "1", "]", "else", ":", "rawhistory", "=", "self", ".", "INITHISTORY", "history", "=", "[", "line", "for", "line", "in", "rawhistory", "if", "line", "and", "not", "line", ".", "startswith", "(", "'#'", ")", "]", "# Truncating history to X entries:\r", "while", "len", "(", "history", ")", ">=", "CONF", ".", "get", "(", "'historylog'", ",", "'max_entries'", ")", ":", "del", "history", "[", "0", "]", "while", "rawhistory", "[", "0", "]", ".", "startswith", "(", "'#'", ")", ":", "del", "rawhistory", "[", "0", "]", "del", "rawhistory", "[", "0", "]", "# Saving truncated history:\r", "try", ":", "encoding", ".", "writelines", "(", "rawhistory", ",", "self", ".", "history_filename", ")", "except", "EnvironmentError", ":", "pass", "return", "history" ]
Load history from a .py file in user home directory
[ "Load", "history", "from", "a", ".", "py", "file", "in", "user", "home", "directory" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L495-L520
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget.write_error
def write_error(self, text): """Simulate stderr""" self.flush() self.write(text, flush=True, error=True) if get_debug_level(): STDERR.write(text)
python
def write_error(self, text): """Simulate stderr""" self.flush() self.write(text, flush=True, error=True) if get_debug_level(): STDERR.write(text)
[ "def", "write_error", "(", "self", ",", "text", ")", ":", "self", ".", "flush", "(", ")", "self", ".", "write", "(", "text", ",", "flush", "=", "True", ",", "error", "=", "True", ")", "if", "get_debug_level", "(", ")", ":", "STDERR", ".", "write", "(", "text", ")" ]
Simulate stderr
[ "Simulate", "stderr" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L523-L528
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget.write
def write(self, text, flush=False, error=False, prompt=False): """Simulate stdout and stderr""" if prompt: self.flush() if not is_string(text): # This test is useful to discriminate QStrings from decoded str text = to_text_string(text) self.__buffer.append(text) ts = time.time() if flush or prompt: self.flush(error=error, prompt=prompt) elif ts - self.__timestamp > 0.05: self.flush(error=error) self.__timestamp = ts # Timer to flush strings cached by last write() operation in series self.__flushtimer.start(50)
python
def write(self, text, flush=False, error=False, prompt=False): """Simulate stdout and stderr""" if prompt: self.flush() if not is_string(text): # This test is useful to discriminate QStrings from decoded str text = to_text_string(text) self.__buffer.append(text) ts = time.time() if flush or prompt: self.flush(error=error, prompt=prompt) elif ts - self.__timestamp > 0.05: self.flush(error=error) self.__timestamp = ts # Timer to flush strings cached by last write() operation in series self.__flushtimer.start(50)
[ "def", "write", "(", "self", ",", "text", ",", "flush", "=", "False", ",", "error", "=", "False", ",", "prompt", "=", "False", ")", ":", "if", "prompt", ":", "self", ".", "flush", "(", ")", "if", "not", "is_string", "(", "text", ")", ":", "# This test is useful to discriminate QStrings from decoded str\r", "text", "=", "to_text_string", "(", "text", ")", "self", ".", "__buffer", ".", "append", "(", "text", ")", "ts", "=", "time", ".", "time", "(", ")", "if", "flush", "or", "prompt", ":", "self", ".", "flush", "(", "error", "=", "error", ",", "prompt", "=", "prompt", ")", "elif", "ts", "-", "self", ".", "__timestamp", ">", "0.05", ":", "self", ".", "flush", "(", "error", "=", "error", ")", "self", ".", "__timestamp", "=", "ts", "# Timer to flush strings cached by last write() operation in series\r", "self", ".", "__flushtimer", ".", "start", "(", "50", ")" ]
Simulate stdout and stderr
[ "Simulate", "stdout", "and", "stderr" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L530-L545
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget.flush
def flush(self, error=False, prompt=False): """Flush buffer, write text to console""" # Fix for Issue 2452 if PY3: try: text = "".join(self.__buffer) except TypeError: text = b"".join(self.__buffer) try: text = text.decode( locale.getdefaultlocale()[1] ) except: pass else: text = "".join(self.__buffer) self.__buffer = [] self.insert_text(text, at_end=True, error=error, prompt=prompt) QCoreApplication.processEvents() self.repaint() # Clear input buffer: self.new_input_line = True
python
def flush(self, error=False, prompt=False): """Flush buffer, write text to console""" # Fix for Issue 2452 if PY3: try: text = "".join(self.__buffer) except TypeError: text = b"".join(self.__buffer) try: text = text.decode( locale.getdefaultlocale()[1] ) except: pass else: text = "".join(self.__buffer) self.__buffer = [] self.insert_text(text, at_end=True, error=error, prompt=prompt) QCoreApplication.processEvents() self.repaint() # Clear input buffer: self.new_input_line = True
[ "def", "flush", "(", "self", ",", "error", "=", "False", ",", "prompt", "=", "False", ")", ":", "# Fix for Issue 2452 \r", "if", "PY3", ":", "try", ":", "text", "=", "\"\"", ".", "join", "(", "self", ".", "__buffer", ")", "except", "TypeError", ":", "text", "=", "b\"\"", ".", "join", "(", "self", ".", "__buffer", ")", "try", ":", "text", "=", "text", ".", "decode", "(", "locale", ".", "getdefaultlocale", "(", ")", "[", "1", "]", ")", "except", ":", "pass", "else", ":", "text", "=", "\"\"", ".", "join", "(", "self", ".", "__buffer", ")", "self", ".", "__buffer", "=", "[", "]", "self", ".", "insert_text", "(", "text", ",", "at_end", "=", "True", ",", "error", "=", "error", ",", "prompt", "=", "prompt", ")", "QCoreApplication", ".", "processEvents", "(", ")", "self", ".", "repaint", "(", ")", "# Clear input buffer:\r", "self", ".", "new_input_line", "=", "True" ]
Flush buffer, write text to console
[ "Flush", "buffer", "write", "text", "to", "console" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L547-L567
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget.insert_text
def insert_text(self, text, at_end=False, error=False, prompt=False): """ Insert text at the current cursor position or at the end of the command line """ if at_end: # Insert text at the end of the command line self.append_text_to_shell(text, error, prompt) else: # Insert text at current cursor position ConsoleBaseWidget.insert_text(self, text)
python
def insert_text(self, text, at_end=False, error=False, prompt=False): """ Insert text at the current cursor position or at the end of the command line """ if at_end: # Insert text at the end of the command line self.append_text_to_shell(text, error, prompt) else: # Insert text at current cursor position ConsoleBaseWidget.insert_text(self, text)
[ "def", "insert_text", "(", "self", ",", "text", ",", "at_end", "=", "False", ",", "error", "=", "False", ",", "prompt", "=", "False", ")", ":", "if", "at_end", ":", "# Insert text at the end of the command line\r", "self", ".", "append_text_to_shell", "(", "text", ",", "error", ",", "prompt", ")", "else", ":", "# Insert text at current cursor position\r", "ConsoleBaseWidget", ".", "insert_text", "(", "self", ",", "text", ")" ]
Insert text at the current cursor position or at the end of the command line
[ "Insert", "text", "at", "the", "current", "cursor", "position", "or", "at", "the", "end", "of", "the", "command", "line" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L571-L581
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
ShellBaseWidget.dropEvent
def dropEvent(self, event): """Drag and Drop - Drop event""" if (event.mimeData().hasFormat("text/plain")): text = to_text_string(event.mimeData().text()) if self.new_input_line: self.on_new_line() self.insert_text(text, at_end=True) self.setFocus() event.setDropAction(Qt.MoveAction) event.accept() else: event.ignore()
python
def dropEvent(self, event): """Drag and Drop - Drop event""" if (event.mimeData().hasFormat("text/plain")): text = to_text_string(event.mimeData().text()) if self.new_input_line: self.on_new_line() self.insert_text(text, at_end=True) self.setFocus() event.setDropAction(Qt.MoveAction) event.accept() else: event.ignore()
[ "def", "dropEvent", "(", "self", ",", "event", ")", ":", "if", "(", "event", ".", "mimeData", "(", ")", ".", "hasFormat", "(", "\"text/plain\"", ")", ")", ":", "text", "=", "to_text_string", "(", "event", ".", "mimeData", "(", ")", ".", "text", "(", ")", ")", "if", "self", ".", "new_input_line", ":", "self", ".", "on_new_line", "(", ")", "self", ".", "insert_text", "(", "text", ",", "at_end", "=", "True", ")", "self", ".", "setFocus", "(", ")", "event", ".", "setDropAction", "(", "Qt", ".", "MoveAction", ")", "event", ".", "accept", "(", ")", "else", ":", "event", ".", "ignore", "(", ")" ]
Drag and Drop - Drop event
[ "Drag", "and", "Drop", "-", "Drop", "event" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L607-L618
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
PythonShellWidget.setup_context_menu
def setup_context_menu(self): """Reimplements ShellBaseWidget method""" ShellBaseWidget.setup_context_menu(self) self.copy_without_prompts_action = create_action(self, _("Copy without prompts"), icon=ima.icon('copywop'), triggered=self.copy_without_prompts) clear_line_action = create_action(self, _("Clear line"), QKeySequence(get_shortcut('console', 'Clear line')), icon=ima.icon('editdelete'), tip=_("Clear line"), triggered=self.clear_line) clear_action = create_action(self, _("Clear shell"), QKeySequence(get_shortcut('console', 'Clear shell')), icon=ima.icon('editclear'), tip=_("Clear shell contents " "('cls' command)"), triggered=self.clear_terminal) add_actions(self.menu, (self.copy_without_prompts_action, clear_line_action, clear_action))
python
def setup_context_menu(self): """Reimplements ShellBaseWidget method""" ShellBaseWidget.setup_context_menu(self) self.copy_without_prompts_action = create_action(self, _("Copy without prompts"), icon=ima.icon('copywop'), triggered=self.copy_without_prompts) clear_line_action = create_action(self, _("Clear line"), QKeySequence(get_shortcut('console', 'Clear line')), icon=ima.icon('editdelete'), tip=_("Clear line"), triggered=self.clear_line) clear_action = create_action(self, _("Clear shell"), QKeySequence(get_shortcut('console', 'Clear shell')), icon=ima.icon('editclear'), tip=_("Clear shell contents " "('cls' command)"), triggered=self.clear_terminal) add_actions(self.menu, (self.copy_without_prompts_action, clear_line_action, clear_action))
[ "def", "setup_context_menu", "(", "self", ")", ":", "ShellBaseWidget", ".", "setup_context_menu", "(", "self", ")", "self", ".", "copy_without_prompts_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Copy without prompts\"", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'copywop'", ")", ",", "triggered", "=", "self", ".", "copy_without_prompts", ")", "clear_line_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Clear line\"", ")", ",", "QKeySequence", "(", "get_shortcut", "(", "'console'", ",", "'Clear line'", ")", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'editdelete'", ")", ",", "tip", "=", "_", "(", "\"Clear line\"", ")", ",", "triggered", "=", "self", ".", "clear_line", ")", "clear_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Clear shell\"", ")", ",", "QKeySequence", "(", "get_shortcut", "(", "'console'", ",", "'Clear shell'", ")", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'editclear'", ")", ",", "tip", "=", "_", "(", "\"Clear shell contents \"", "\"('cls' command)\"", ")", ",", "triggered", "=", "self", ".", "clear_terminal", ")", "add_actions", "(", "self", ".", "menu", ",", "(", "self", ".", "copy_without_prompts_action", ",", "clear_line_action", ",", "clear_action", ")", ")" ]
Reimplements ShellBaseWidget method
[ "Reimplements", "ShellBaseWidget", "method" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L672-L693
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
PythonShellWidget.contextMenuEvent
def contextMenuEvent(self, event): """Reimplements ShellBaseWidget method""" state = self.has_selected_text() self.copy_without_prompts_action.setEnabled(state) ShellBaseWidget.contextMenuEvent(self, event)
python
def contextMenuEvent(self, event): """Reimplements ShellBaseWidget method""" state = self.has_selected_text() self.copy_without_prompts_action.setEnabled(state) ShellBaseWidget.contextMenuEvent(self, event)
[ "def", "contextMenuEvent", "(", "self", ",", "event", ")", ":", "state", "=", "self", ".", "has_selected_text", "(", ")", "self", ".", "copy_without_prompts_action", ".", "setEnabled", "(", "state", ")", "ShellBaseWidget", ".", "contextMenuEvent", "(", "self", ",", "event", ")" ]
Reimplements ShellBaseWidget method
[ "Reimplements", "ShellBaseWidget", "method" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L695-L699
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
PythonShellWidget.copy_without_prompts
def copy_without_prompts(self): """Copy text to clipboard without prompts""" text = self.get_selected_text() lines = text.split(os.linesep) for index, line in enumerate(lines): if line.startswith('>>> ') or line.startswith('... '): lines[index] = line[4:] text = os.linesep.join(lines) QApplication.clipboard().setText(text)
python
def copy_without_prompts(self): """Copy text to clipboard without prompts""" text = self.get_selected_text() lines = text.split(os.linesep) for index, line in enumerate(lines): if line.startswith('>>> ') or line.startswith('... '): lines[index] = line[4:] text = os.linesep.join(lines) QApplication.clipboard().setText(text)
[ "def", "copy_without_prompts", "(", "self", ")", ":", "text", "=", "self", ".", "get_selected_text", "(", ")", "lines", "=", "text", ".", "split", "(", "os", ".", "linesep", ")", "for", "index", ",", "line", "in", "enumerate", "(", "lines", ")", ":", "if", "line", ".", "startswith", "(", "'>>> '", ")", "or", "line", ".", "startswith", "(", "'... '", ")", ":", "lines", "[", "index", "]", "=", "line", "[", "4", ":", "]", "text", "=", "os", ".", "linesep", ".", "join", "(", "lines", ")", "QApplication", ".", "clipboard", "(", ")", ".", "setText", "(", "text", ")" ]
Copy text to clipboard without prompts
[ "Copy", "text", "to", "clipboard", "without", "prompts" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L702-L710
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
PythonShellWidget.postprocess_keyevent
def postprocess_keyevent(self, event): """Process keypress event""" ShellBaseWidget.postprocess_keyevent(self, event) if QToolTip.isVisible(): _event, _text, key, _ctrl, _shift = restore_keyevent(event) self.hide_tooltip_if_necessary(key)
python
def postprocess_keyevent(self, event): """Process keypress event""" ShellBaseWidget.postprocess_keyevent(self, event) if QToolTip.isVisible(): _event, _text, key, _ctrl, _shift = restore_keyevent(event) self.hide_tooltip_if_necessary(key)
[ "def", "postprocess_keyevent", "(", "self", ",", "event", ")", ":", "ShellBaseWidget", ".", "postprocess_keyevent", "(", "self", ",", "event", ")", "if", "QToolTip", ".", "isVisible", "(", ")", ":", "_event", ",", "_text", ",", "key", ",", "_ctrl", ",", "_shift", "=", "restore_keyevent", "(", "event", ")", "self", ".", "hide_tooltip_if_necessary", "(", "key", ")" ]
Process keypress event
[ "Process", "keypress", "event" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L714-L719
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
PythonShellWidget._key_backspace
def _key_backspace(self, cursor_position): """Action for Backspace key""" if self.has_selected_text(): self.check_selection() self.remove_selected_text() elif self.current_prompt_pos == cursor_position: # Avoid deleting prompt return elif self.is_cursor_on_last_line(): self.stdkey_backspace() if self.is_completion_widget_visible(): # Removing only last character because if there was a selection # the completion widget would have been canceled self.completion_text = self.completion_text[:-1]
python
def _key_backspace(self, cursor_position): """Action for Backspace key""" if self.has_selected_text(): self.check_selection() self.remove_selected_text() elif self.current_prompt_pos == cursor_position: # Avoid deleting prompt return elif self.is_cursor_on_last_line(): self.stdkey_backspace() if self.is_completion_widget_visible(): # Removing only last character because if there was a selection # the completion widget would have been canceled self.completion_text = self.completion_text[:-1]
[ "def", "_key_backspace", "(", "self", ",", "cursor_position", ")", ":", "if", "self", ".", "has_selected_text", "(", ")", ":", "self", ".", "check_selection", "(", ")", "self", ".", "remove_selected_text", "(", ")", "elif", "self", ".", "current_prompt_pos", "==", "cursor_position", ":", "# Avoid deleting prompt\r", "return", "elif", "self", ".", "is_cursor_on_last_line", "(", ")", ":", "self", ".", "stdkey_backspace", "(", ")", "if", "self", ".", "is_completion_widget_visible", "(", ")", ":", "# Removing only last character because if there was a selection\r", "# the completion widget would have been canceled\r", "self", ".", "completion_text", "=", "self", ".", "completion_text", "[", ":", "-", "1", "]" ]
Action for Backspace key
[ "Action", "for", "Backspace", "key" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L726-L739
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
PythonShellWidget._key_tab
def _key_tab(self): """Action for TAB key""" if self.is_cursor_on_last_line(): empty_line = not self.get_current_line_to_cursor().strip() if empty_line: self.stdkey_tab() else: self.show_code_completion()
python
def _key_tab(self): """Action for TAB key""" if self.is_cursor_on_last_line(): empty_line = not self.get_current_line_to_cursor().strip() if empty_line: self.stdkey_tab() else: self.show_code_completion()
[ "def", "_key_tab", "(", "self", ")", ":", "if", "self", ".", "is_cursor_on_last_line", "(", ")", ":", "empty_line", "=", "not", "self", ".", "get_current_line_to_cursor", "(", ")", ".", "strip", "(", ")", "if", "empty_line", ":", "self", ".", "stdkey_tab", "(", ")", "else", ":", "self", ".", "show_code_completion", "(", ")" ]
Action for TAB key
[ "Action", "for", "TAB", "key" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L741-L748
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
PythonShellWidget._key_question
def _key_question(self, text): """Action for '?'""" if self.get_current_line_to_cursor(): last_obj = self.get_last_obj() if last_obj and not last_obj.isdigit(): self.show_object_info(last_obj) self.insert_text(text) # In case calltip and completion are shown at the same time: if self.is_completion_widget_visible(): self.completion_text += '?'
python
def _key_question(self, text): """Action for '?'""" if self.get_current_line_to_cursor(): last_obj = self.get_last_obj() if last_obj and not last_obj.isdigit(): self.show_object_info(last_obj) self.insert_text(text) # In case calltip and completion are shown at the same time: if self.is_completion_widget_visible(): self.completion_text += '?'
[ "def", "_key_question", "(", "self", ",", "text", ")", ":", "if", "self", ".", "get_current_line_to_cursor", "(", ")", ":", "last_obj", "=", "self", ".", "get_last_obj", "(", ")", "if", "last_obj", "and", "not", "last_obj", ".", "isdigit", "(", ")", ":", "self", ".", "show_object_info", "(", "last_obj", ")", "self", ".", "insert_text", "(", "text", ")", "# In case calltip and completion are shown at the same time:\r", "if", "self", ".", "is_completion_widget_visible", "(", ")", ":", "self", ".", "completion_text", "+=", "'?'" ]
Action for '?
[ "Action", "for", "?" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L768-L777
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
PythonShellWidget._key_parenleft
def _key_parenleft(self, text): """Action for '('""" self.hide_completion_widget() if self.get_current_line_to_cursor(): last_obj = self.get_last_obj() if last_obj and not last_obj.isdigit(): self.insert_text(text) self.show_object_info(last_obj, call=True) return self.insert_text(text)
python
def _key_parenleft(self, text): """Action for '('""" self.hide_completion_widget() if self.get_current_line_to_cursor(): last_obj = self.get_last_obj() if last_obj and not last_obj.isdigit(): self.insert_text(text) self.show_object_info(last_obj, call=True) return self.insert_text(text)
[ "def", "_key_parenleft", "(", "self", ",", "text", ")", ":", "self", ".", "hide_completion_widget", "(", ")", "if", "self", ".", "get_current_line_to_cursor", "(", ")", ":", "last_obj", "=", "self", ".", "get_last_obj", "(", ")", "if", "last_obj", "and", "not", "last_obj", ".", "isdigit", "(", ")", ":", "self", ".", "insert_text", "(", "text", ")", "self", ".", "show_object_info", "(", "last_obj", ",", "call", "=", "True", ")", "return", "self", ".", "insert_text", "(", "text", ")" ]
Action for '(
[ "Action", "for", "(" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L779-L788
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
PythonShellWidget._key_period
def _key_period(self, text): """Action for '.'""" self.insert_text(text) if self.codecompletion_auto: # Enable auto-completion only if last token isn't a float last_obj = self.get_last_obj() if last_obj and not last_obj.isdigit(): self.show_code_completion()
python
def _key_period(self, text): """Action for '.'""" self.insert_text(text) if self.codecompletion_auto: # Enable auto-completion only if last token isn't a float last_obj = self.get_last_obj() if last_obj and not last_obj.isdigit(): self.show_code_completion()
[ "def", "_key_period", "(", "self", ",", "text", ")", ":", "self", ".", "insert_text", "(", "text", ")", "if", "self", ".", "codecompletion_auto", ":", "# Enable auto-completion only if last token isn't a float\r", "last_obj", "=", "self", ".", "get_last_obj", "(", ")", "if", "last_obj", "and", "not", "last_obj", ".", "isdigit", "(", ")", ":", "self", ".", "show_code_completion", "(", ")" ]
Action for '.
[ "Action", "for", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L790-L797
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
PythonShellWidget.paste
def paste(self): """Reimplemented slot to handle multiline paste action""" text = to_text_string(QApplication.clipboard().text()) if len(text.splitlines()) > 1: # Multiline paste if self.new_input_line: self.on_new_line() self.remove_selected_text() # Remove selection, eventually end = self.get_current_line_from_cursor() lines = self.get_current_line_to_cursor() + text + end self.clear_line() self.execute_lines(lines) self.move_cursor(-len(end)) else: # Standard paste ShellBaseWidget.paste(self)
python
def paste(self): """Reimplemented slot to handle multiline paste action""" text = to_text_string(QApplication.clipboard().text()) if len(text.splitlines()) > 1: # Multiline paste if self.new_input_line: self.on_new_line() self.remove_selected_text() # Remove selection, eventually end = self.get_current_line_from_cursor() lines = self.get_current_line_to_cursor() + text + end self.clear_line() self.execute_lines(lines) self.move_cursor(-len(end)) else: # Standard paste ShellBaseWidget.paste(self)
[ "def", "paste", "(", "self", ")", ":", "text", "=", "to_text_string", "(", "QApplication", ".", "clipboard", "(", ")", ".", "text", "(", ")", ")", "if", "len", "(", "text", ".", "splitlines", "(", ")", ")", ">", "1", ":", "# Multiline paste\r", "if", "self", ".", "new_input_line", ":", "self", ".", "on_new_line", "(", ")", "self", ".", "remove_selected_text", "(", ")", "# Remove selection, eventually\r", "end", "=", "self", ".", "get_current_line_from_cursor", "(", ")", "lines", "=", "self", ".", "get_current_line_to_cursor", "(", ")", "+", "text", "+", "end", "self", ".", "clear_line", "(", ")", "self", ".", "execute_lines", "(", "lines", ")", "self", ".", "move_cursor", "(", "-", "len", "(", "end", ")", ")", "else", ":", "# Standard paste\r", "ShellBaseWidget", ".", "paste", "(", "self", ")" ]
Reimplemented slot to handle multiline paste action
[ "Reimplemented", "slot", "to", "handle", "multiline", "paste", "action" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L801-L816
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
PythonShellWidget.show_completion_list
def show_completion_list(self, completions, completion_text=""): """Display the possible completions""" if not completions: return if not isinstance(completions[0], tuple): completions = [(c, '') for c in completions] if len(completions) == 1 and completions[0][0] == completion_text: return self.completion_text = completion_text # Sorting completion list (entries starting with underscore are # put at the end of the list): underscore = set([(comp, t) for (comp, t) in completions if comp.startswith('_')]) completions = sorted(set(completions) - underscore, key=lambda x: str_lower(x[0])) completions += sorted(underscore, key=lambda x: str_lower(x[0])) self.show_completion_widget(completions)
python
def show_completion_list(self, completions, completion_text=""): """Display the possible completions""" if not completions: return if not isinstance(completions[0], tuple): completions = [(c, '') for c in completions] if len(completions) == 1 and completions[0][0] == completion_text: return self.completion_text = completion_text # Sorting completion list (entries starting with underscore are # put at the end of the list): underscore = set([(comp, t) for (comp, t) in completions if comp.startswith('_')]) completions = sorted(set(completions) - underscore, key=lambda x: str_lower(x[0])) completions += sorted(underscore, key=lambda x: str_lower(x[0])) self.show_completion_widget(completions)
[ "def", "show_completion_list", "(", "self", ",", "completions", ",", "completion_text", "=", "\"\"", ")", ":", "if", "not", "completions", ":", "return", "if", "not", "isinstance", "(", "completions", "[", "0", "]", ",", "tuple", ")", ":", "completions", "=", "[", "(", "c", ",", "''", ")", "for", "c", "in", "completions", "]", "if", "len", "(", "completions", ")", "==", "1", "and", "completions", "[", "0", "]", "[", "0", "]", "==", "completion_text", ":", "return", "self", ".", "completion_text", "=", "completion_text", "# Sorting completion list (entries starting with underscore are\r", "# put at the end of the list):\r", "underscore", "=", "set", "(", "[", "(", "comp", ",", "t", ")", "for", "(", "comp", ",", "t", ")", "in", "completions", "if", "comp", ".", "startswith", "(", "'_'", ")", "]", ")", "completions", "=", "sorted", "(", "set", "(", "completions", ")", "-", "underscore", ",", "key", "=", "lambda", "x", ":", "str_lower", "(", "x", "[", "0", "]", ")", ")", "completions", "+=", "sorted", "(", "underscore", ",", "key", "=", "lambda", "x", ":", "str_lower", "(", "x", "[", "0", "]", ")", ")", "self", ".", "show_completion_widget", "(", "completions", ")" ]
Display the possible completions
[ "Display", "the", "possible", "completions" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L858-L875
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
PythonShellWidget.show_code_completion
def show_code_completion(self): """Display a completion list based on the current line""" # Note: unicode conversion is needed only for ExternalShellBase text = to_text_string(self.get_current_line_to_cursor()) last_obj = self.get_last_obj() if not text: return obj_dir = self.get_dir(last_obj) if last_obj and obj_dir and text.endswith('.'): self.show_completion_list(obj_dir) return # Builtins and globals if not text.endswith('.') and last_obj \ and re.match(r'[a-zA-Z_0-9]*$', last_obj): b_k_g = dir(builtins)+self.get_globals_keys()+keyword.kwlist for objname in b_k_g: if objname.startswith(last_obj) and objname != last_obj: self.show_completion_list(b_k_g, completion_text=last_obj) return else: return # Looking for an incomplete completion if last_obj is None: last_obj = text dot_pos = last_obj.rfind('.') if dot_pos != -1: if dot_pos == len(last_obj)-1: completion_text = "" else: completion_text = last_obj[dot_pos+1:] last_obj = last_obj[:dot_pos] completions = self.get_dir(last_obj) if completions is not None: self.show_completion_list(completions, completion_text=completion_text) return # Looking for ' or ": filename completion q_pos = max([text.rfind("'"), text.rfind('"')]) if q_pos != -1: completions = self.get_cdlistdir() if completions: self.show_completion_list(completions, completion_text=text[q_pos+1:]) return
python
def show_code_completion(self): """Display a completion list based on the current line""" # Note: unicode conversion is needed only for ExternalShellBase text = to_text_string(self.get_current_line_to_cursor()) last_obj = self.get_last_obj() if not text: return obj_dir = self.get_dir(last_obj) if last_obj and obj_dir and text.endswith('.'): self.show_completion_list(obj_dir) return # Builtins and globals if not text.endswith('.') and last_obj \ and re.match(r'[a-zA-Z_0-9]*$', last_obj): b_k_g = dir(builtins)+self.get_globals_keys()+keyword.kwlist for objname in b_k_g: if objname.startswith(last_obj) and objname != last_obj: self.show_completion_list(b_k_g, completion_text=last_obj) return else: return # Looking for an incomplete completion if last_obj is None: last_obj = text dot_pos = last_obj.rfind('.') if dot_pos != -1: if dot_pos == len(last_obj)-1: completion_text = "" else: completion_text = last_obj[dot_pos+1:] last_obj = last_obj[:dot_pos] completions = self.get_dir(last_obj) if completions is not None: self.show_completion_list(completions, completion_text=completion_text) return # Looking for ' or ": filename completion q_pos = max([text.rfind("'"), text.rfind('"')]) if q_pos != -1: completions = self.get_cdlistdir() if completions: self.show_completion_list(completions, completion_text=text[q_pos+1:]) return
[ "def", "show_code_completion", "(", "self", ")", ":", "# Note: unicode conversion is needed only for ExternalShellBase\r", "text", "=", "to_text_string", "(", "self", ".", "get_current_line_to_cursor", "(", ")", ")", "last_obj", "=", "self", ".", "get_last_obj", "(", ")", "if", "not", "text", ":", "return", "obj_dir", "=", "self", ".", "get_dir", "(", "last_obj", ")", "if", "last_obj", "and", "obj_dir", "and", "text", ".", "endswith", "(", "'.'", ")", ":", "self", ".", "show_completion_list", "(", "obj_dir", ")", "return", "# Builtins and globals\r", "if", "not", "text", ".", "endswith", "(", "'.'", ")", "and", "last_obj", "and", "re", ".", "match", "(", "r'[a-zA-Z_0-9]*$'", ",", "last_obj", ")", ":", "b_k_g", "=", "dir", "(", "builtins", ")", "+", "self", ".", "get_globals_keys", "(", ")", "+", "keyword", ".", "kwlist", "for", "objname", "in", "b_k_g", ":", "if", "objname", ".", "startswith", "(", "last_obj", ")", "and", "objname", "!=", "last_obj", ":", "self", ".", "show_completion_list", "(", "b_k_g", ",", "completion_text", "=", "last_obj", ")", "return", "else", ":", "return", "# Looking for an incomplete completion\r", "if", "last_obj", "is", "None", ":", "last_obj", "=", "text", "dot_pos", "=", "last_obj", ".", "rfind", "(", "'.'", ")", "if", "dot_pos", "!=", "-", "1", ":", "if", "dot_pos", "==", "len", "(", "last_obj", ")", "-", "1", ":", "completion_text", "=", "\"\"", "else", ":", "completion_text", "=", "last_obj", "[", "dot_pos", "+", "1", ":", "]", "last_obj", "=", "last_obj", "[", ":", "dot_pos", "]", "completions", "=", "self", ".", "get_dir", "(", "last_obj", ")", "if", "completions", "is", "not", "None", ":", "self", ".", "show_completion_list", "(", "completions", ",", "completion_text", "=", "completion_text", ")", "return", "# Looking for ' or \": filename completion\r", "q_pos", "=", "max", "(", "[", "text", ".", "rfind", "(", "\"'\"", ")", ",", "text", ".", "rfind", "(", "'\"'", ")", "]", ")", "if", "q_pos", "!=", "-", "1", ":", "completions", "=", "self", ".", "get_cdlistdir", "(", ")", "if", "completions", ":", "self", ".", "show_completion_list", "(", "completions", ",", "completion_text", "=", "text", "[", "q_pos", "+", "1", ":", "]", ")", "return" ]
Display a completion list based on the current line
[ "Display", "a", "completion", "list", "based", "on", "the", "current", "line" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L877-L924
train
spyder-ide/spyder
spyder/plugins/console/widgets/shell.py
PythonShellWidget.drop_pathlist
def drop_pathlist(self, pathlist): """Drop path list""" if pathlist: files = ["r'%s'" % path for path in pathlist] if len(files) == 1: text = files[0] else: text = "[" + ", ".join(files) + "]" if self.new_input_line: self.on_new_line() self.insert_text(text) self.setFocus()
python
def drop_pathlist(self, pathlist): """Drop path list""" if pathlist: files = ["r'%s'" % path for path in pathlist] if len(files) == 1: text = files[0] else: text = "[" + ", ".join(files) + "]" if self.new_input_line: self.on_new_line() self.insert_text(text) self.setFocus()
[ "def", "drop_pathlist", "(", "self", ",", "pathlist", ")", ":", "if", "pathlist", ":", "files", "=", "[", "\"r'%s'\"", "%", "path", "for", "path", "in", "pathlist", "]", "if", "len", "(", "files", ")", "==", "1", ":", "text", "=", "files", "[", "0", "]", "else", ":", "text", "=", "\"[\"", "+", "\", \"", ".", "join", "(", "files", ")", "+", "\"]\"", "if", "self", ".", "new_input_line", ":", "self", ".", "on_new_line", "(", ")", "self", ".", "insert_text", "(", "text", ")", "self", ".", "setFocus", "(", ")" ]
Drop path list
[ "Drop", "path", "list" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/shell.py#L934-L945
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/utils/kernelspec.py
SpyderKernelSpec.argv
def argv(self): """Command to start kernels""" # Python interpreter used to start kernels if CONF.get('main_interpreter', 'default'): pyexec = get_python_executable() else: # Avoid IPython adding the virtualenv on which Spyder is running # to the kernel sys.path os.environ.pop('VIRTUAL_ENV', None) pyexec = CONF.get('main_interpreter', 'executable') if not is_python_interpreter(pyexec): pyexec = get_python_executable() CONF.set('main_interpreter', 'executable', '') CONF.set('main_interpreter', 'default', True) CONF.set('main_interpreter', 'custom', False) # Fixes Issue #3427 if os.name == 'nt': dir_pyexec = osp.dirname(pyexec) pyexec_w = osp.join(dir_pyexec, 'pythonw.exe') if osp.isfile(pyexec_w): pyexec = pyexec_w # Command used to start kernels kernel_cmd = [ pyexec, '-m', 'spyder_kernels.console', '-f', '{connection_file}' ] return kernel_cmd
python
def argv(self): """Command to start kernels""" # Python interpreter used to start kernels if CONF.get('main_interpreter', 'default'): pyexec = get_python_executable() else: # Avoid IPython adding the virtualenv on which Spyder is running # to the kernel sys.path os.environ.pop('VIRTUAL_ENV', None) pyexec = CONF.get('main_interpreter', 'executable') if not is_python_interpreter(pyexec): pyexec = get_python_executable() CONF.set('main_interpreter', 'executable', '') CONF.set('main_interpreter', 'default', True) CONF.set('main_interpreter', 'custom', False) # Fixes Issue #3427 if os.name == 'nt': dir_pyexec = osp.dirname(pyexec) pyexec_w = osp.join(dir_pyexec, 'pythonw.exe') if osp.isfile(pyexec_w): pyexec = pyexec_w # Command used to start kernels kernel_cmd = [ pyexec, '-m', 'spyder_kernels.console', '-f', '{connection_file}' ] return kernel_cmd
[ "def", "argv", "(", "self", ")", ":", "# Python interpreter used to start kernels", "if", "CONF", ".", "get", "(", "'main_interpreter'", ",", "'default'", ")", ":", "pyexec", "=", "get_python_executable", "(", ")", "else", ":", "# Avoid IPython adding the virtualenv on which Spyder is running", "# to the kernel sys.path", "os", ".", "environ", ".", "pop", "(", "'VIRTUAL_ENV'", ",", "None", ")", "pyexec", "=", "CONF", ".", "get", "(", "'main_interpreter'", ",", "'executable'", ")", "if", "not", "is_python_interpreter", "(", "pyexec", ")", ":", "pyexec", "=", "get_python_executable", "(", ")", "CONF", ".", "set", "(", "'main_interpreter'", ",", "'executable'", ",", "''", ")", "CONF", ".", "set", "(", "'main_interpreter'", ",", "'default'", ",", "True", ")", "CONF", ".", "set", "(", "'main_interpreter'", ",", "'custom'", ",", "False", ")", "# Fixes Issue #3427", "if", "os", ".", "name", "==", "'nt'", ":", "dir_pyexec", "=", "osp", ".", "dirname", "(", "pyexec", ")", "pyexec_w", "=", "osp", ".", "join", "(", "dir_pyexec", ",", "'pythonw.exe'", ")", "if", "osp", ".", "isfile", "(", "pyexec_w", ")", ":", "pyexec", "=", "pyexec_w", "# Command used to start kernels", "kernel_cmd", "=", "[", "pyexec", ",", "'-m'", ",", "'spyder_kernels.console'", ",", "'-f'", ",", "'{connection_file}'", "]", "return", "kernel_cmd" ]
Command to start kernels
[ "Command", "to", "start", "kernels" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/utils/kernelspec.py#L41-L73
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/utils/kernelspec.py
SpyderKernelSpec.env
def env(self): """Env vars for kernels""" # Add our PYTHONPATH to the kernel pathlist = CONF.get('main', 'spyder_pythonpath', default=[]) default_interpreter = CONF.get('main_interpreter', 'default') pypath = add_pathlist_to_PYTHONPATH([], pathlist, ipyconsole=True, drop_env=False) # Environment variables that we need to pass to our sitecustomize umr_namelist = CONF.get('main_interpreter', 'umr/namelist') if PY2: original_list = umr_namelist[:] for umr_n in umr_namelist: try: umr_n.encode('utf-8') except UnicodeDecodeError: umr_namelist.remove(umr_n) if original_list != umr_namelist: CONF.set('main_interpreter', 'umr/namelist', umr_namelist) env_vars = { 'SPY_EXTERNAL_INTERPRETER': not default_interpreter, 'SPY_UMR_ENABLED': CONF.get('main_interpreter', 'umr/enabled'), 'SPY_UMR_VERBOSE': CONF.get('main_interpreter', 'umr/verbose'), 'SPY_UMR_NAMELIST': ','.join(umr_namelist), 'SPY_RUN_LINES_O': CONF.get('ipython_console', 'startup/run_lines'), 'SPY_PYLAB_O': CONF.get('ipython_console', 'pylab'), 'SPY_BACKEND_O': CONF.get('ipython_console', 'pylab/backend'), 'SPY_AUTOLOAD_PYLAB_O': CONF.get('ipython_console', 'pylab/autoload'), 'SPY_FORMAT_O': CONF.get('ipython_console', 'pylab/inline/figure_format'), 'SPY_BBOX_INCHES_O': CONF.get('ipython_console', 'pylab/inline/bbox_inches'), 'SPY_RESOLUTION_O': CONF.get('ipython_console', 'pylab/inline/resolution'), 'SPY_WIDTH_O': CONF.get('ipython_console', 'pylab/inline/width'), 'SPY_HEIGHT_O': CONF.get('ipython_console', 'pylab/inline/height'), 'SPY_USE_FILE_O': CONF.get('ipython_console', 'startup/use_run_file'), 'SPY_RUN_FILE_O': CONF.get('ipython_console', 'startup/run_file'), 'SPY_AUTOCALL_O': CONF.get('ipython_console', 'autocall'), 'SPY_GREEDY_O': CONF.get('ipython_console', 'greedy_completer'), 'SPY_JEDI_O': CONF.get('ipython_console', 'jedi_completer'), 'SPY_SYMPY_O': CONF.get('ipython_console', 'symbolic_math'), 'SPY_TESTING': running_under_pytest() or SAFE_MODE, 'SPY_HIDE_CMD': CONF.get('ipython_console', 'hide_cmd_windows') } if self.is_pylab is True: env_vars['SPY_AUTOLOAD_PYLAB_O'] = True env_vars['SPY_SYMPY_O'] = False env_vars['SPY_RUN_CYTHON'] = False if self.is_sympy is True: env_vars['SPY_AUTOLOAD_PYLAB_O'] = False env_vars['SPY_SYMPY_O'] = True env_vars['SPY_RUN_CYTHON'] = False if self.is_cython is True: env_vars['SPY_AUTOLOAD_PYLAB_O'] = False env_vars['SPY_SYMPY_O'] = False env_vars['SPY_RUN_CYTHON'] = True # Add our PYTHONPATH to env_vars env_vars.update(pypath) # Making all env_vars strings for key,var in iteritems(env_vars): if PY2: # Try to convert vars first to utf-8. try: unicode_var = to_text_string(var) except UnicodeDecodeError: # If that fails, try to use the file system # encoding because one of our vars is our # PYTHONPATH, and that contains file system # directories try: unicode_var = to_unicode_from_fs(var) except: # If that also fails, make the var empty # to be able to start Spyder. # See https://stackoverflow.com/q/44506900/438386 # for details. unicode_var = '' env_vars[key] = to_binary_string(unicode_var, encoding='utf-8') else: env_vars[key] = to_text_string(var) return env_vars
python
def env(self): """Env vars for kernels""" # Add our PYTHONPATH to the kernel pathlist = CONF.get('main', 'spyder_pythonpath', default=[]) default_interpreter = CONF.get('main_interpreter', 'default') pypath = add_pathlist_to_PYTHONPATH([], pathlist, ipyconsole=True, drop_env=False) # Environment variables that we need to pass to our sitecustomize umr_namelist = CONF.get('main_interpreter', 'umr/namelist') if PY2: original_list = umr_namelist[:] for umr_n in umr_namelist: try: umr_n.encode('utf-8') except UnicodeDecodeError: umr_namelist.remove(umr_n) if original_list != umr_namelist: CONF.set('main_interpreter', 'umr/namelist', umr_namelist) env_vars = { 'SPY_EXTERNAL_INTERPRETER': not default_interpreter, 'SPY_UMR_ENABLED': CONF.get('main_interpreter', 'umr/enabled'), 'SPY_UMR_VERBOSE': CONF.get('main_interpreter', 'umr/verbose'), 'SPY_UMR_NAMELIST': ','.join(umr_namelist), 'SPY_RUN_LINES_O': CONF.get('ipython_console', 'startup/run_lines'), 'SPY_PYLAB_O': CONF.get('ipython_console', 'pylab'), 'SPY_BACKEND_O': CONF.get('ipython_console', 'pylab/backend'), 'SPY_AUTOLOAD_PYLAB_O': CONF.get('ipython_console', 'pylab/autoload'), 'SPY_FORMAT_O': CONF.get('ipython_console', 'pylab/inline/figure_format'), 'SPY_BBOX_INCHES_O': CONF.get('ipython_console', 'pylab/inline/bbox_inches'), 'SPY_RESOLUTION_O': CONF.get('ipython_console', 'pylab/inline/resolution'), 'SPY_WIDTH_O': CONF.get('ipython_console', 'pylab/inline/width'), 'SPY_HEIGHT_O': CONF.get('ipython_console', 'pylab/inline/height'), 'SPY_USE_FILE_O': CONF.get('ipython_console', 'startup/use_run_file'), 'SPY_RUN_FILE_O': CONF.get('ipython_console', 'startup/run_file'), 'SPY_AUTOCALL_O': CONF.get('ipython_console', 'autocall'), 'SPY_GREEDY_O': CONF.get('ipython_console', 'greedy_completer'), 'SPY_JEDI_O': CONF.get('ipython_console', 'jedi_completer'), 'SPY_SYMPY_O': CONF.get('ipython_console', 'symbolic_math'), 'SPY_TESTING': running_under_pytest() or SAFE_MODE, 'SPY_HIDE_CMD': CONF.get('ipython_console', 'hide_cmd_windows') } if self.is_pylab is True: env_vars['SPY_AUTOLOAD_PYLAB_O'] = True env_vars['SPY_SYMPY_O'] = False env_vars['SPY_RUN_CYTHON'] = False if self.is_sympy is True: env_vars['SPY_AUTOLOAD_PYLAB_O'] = False env_vars['SPY_SYMPY_O'] = True env_vars['SPY_RUN_CYTHON'] = False if self.is_cython is True: env_vars['SPY_AUTOLOAD_PYLAB_O'] = False env_vars['SPY_SYMPY_O'] = False env_vars['SPY_RUN_CYTHON'] = True # Add our PYTHONPATH to env_vars env_vars.update(pypath) # Making all env_vars strings for key,var in iteritems(env_vars): if PY2: # Try to convert vars first to utf-8. try: unicode_var = to_text_string(var) except UnicodeDecodeError: # If that fails, try to use the file system # encoding because one of our vars is our # PYTHONPATH, and that contains file system # directories try: unicode_var = to_unicode_from_fs(var) except: # If that also fails, make the var empty # to be able to start Spyder. # See https://stackoverflow.com/q/44506900/438386 # for details. unicode_var = '' env_vars[key] = to_binary_string(unicode_var, encoding='utf-8') else: env_vars[key] = to_text_string(var) return env_vars
[ "def", "env", "(", "self", ")", ":", "# Add our PYTHONPATH to the kernel", "pathlist", "=", "CONF", ".", "get", "(", "'main'", ",", "'spyder_pythonpath'", ",", "default", "=", "[", "]", ")", "default_interpreter", "=", "CONF", ".", "get", "(", "'main_interpreter'", ",", "'default'", ")", "pypath", "=", "add_pathlist_to_PYTHONPATH", "(", "[", "]", ",", "pathlist", ",", "ipyconsole", "=", "True", ",", "drop_env", "=", "False", ")", "# Environment variables that we need to pass to our sitecustomize", "umr_namelist", "=", "CONF", ".", "get", "(", "'main_interpreter'", ",", "'umr/namelist'", ")", "if", "PY2", ":", "original_list", "=", "umr_namelist", "[", ":", "]", "for", "umr_n", "in", "umr_namelist", ":", "try", ":", "umr_n", ".", "encode", "(", "'utf-8'", ")", "except", "UnicodeDecodeError", ":", "umr_namelist", ".", "remove", "(", "umr_n", ")", "if", "original_list", "!=", "umr_namelist", ":", "CONF", ".", "set", "(", "'main_interpreter'", ",", "'umr/namelist'", ",", "umr_namelist", ")", "env_vars", "=", "{", "'SPY_EXTERNAL_INTERPRETER'", ":", "not", "default_interpreter", ",", "'SPY_UMR_ENABLED'", ":", "CONF", ".", "get", "(", "'main_interpreter'", ",", "'umr/enabled'", ")", ",", "'SPY_UMR_VERBOSE'", ":", "CONF", ".", "get", "(", "'main_interpreter'", ",", "'umr/verbose'", ")", ",", "'SPY_UMR_NAMELIST'", ":", "','", ".", "join", "(", "umr_namelist", ")", ",", "'SPY_RUN_LINES_O'", ":", "CONF", ".", "get", "(", "'ipython_console'", ",", "'startup/run_lines'", ")", ",", "'SPY_PYLAB_O'", ":", "CONF", ".", "get", "(", "'ipython_console'", ",", "'pylab'", ")", ",", "'SPY_BACKEND_O'", ":", "CONF", ".", "get", "(", "'ipython_console'", ",", "'pylab/backend'", ")", ",", "'SPY_AUTOLOAD_PYLAB_O'", ":", "CONF", ".", "get", "(", "'ipython_console'", ",", "'pylab/autoload'", ")", ",", "'SPY_FORMAT_O'", ":", "CONF", ".", "get", "(", "'ipython_console'", ",", "'pylab/inline/figure_format'", ")", ",", "'SPY_BBOX_INCHES_O'", ":", "CONF", ".", "get", "(", "'ipython_console'", ",", "'pylab/inline/bbox_inches'", ")", ",", "'SPY_RESOLUTION_O'", ":", "CONF", ".", "get", "(", "'ipython_console'", ",", "'pylab/inline/resolution'", ")", ",", "'SPY_WIDTH_O'", ":", "CONF", ".", "get", "(", "'ipython_console'", ",", "'pylab/inline/width'", ")", ",", "'SPY_HEIGHT_O'", ":", "CONF", ".", "get", "(", "'ipython_console'", ",", "'pylab/inline/height'", ")", ",", "'SPY_USE_FILE_O'", ":", "CONF", ".", "get", "(", "'ipython_console'", ",", "'startup/use_run_file'", ")", ",", "'SPY_RUN_FILE_O'", ":", "CONF", ".", "get", "(", "'ipython_console'", ",", "'startup/run_file'", ")", ",", "'SPY_AUTOCALL_O'", ":", "CONF", ".", "get", "(", "'ipython_console'", ",", "'autocall'", ")", ",", "'SPY_GREEDY_O'", ":", "CONF", ".", "get", "(", "'ipython_console'", ",", "'greedy_completer'", ")", ",", "'SPY_JEDI_O'", ":", "CONF", ".", "get", "(", "'ipython_console'", ",", "'jedi_completer'", ")", ",", "'SPY_SYMPY_O'", ":", "CONF", ".", "get", "(", "'ipython_console'", ",", "'symbolic_math'", ")", ",", "'SPY_TESTING'", ":", "running_under_pytest", "(", ")", "or", "SAFE_MODE", ",", "'SPY_HIDE_CMD'", ":", "CONF", ".", "get", "(", "'ipython_console'", ",", "'hide_cmd_windows'", ")", "}", "if", "self", ".", "is_pylab", "is", "True", ":", "env_vars", "[", "'SPY_AUTOLOAD_PYLAB_O'", "]", "=", "True", "env_vars", "[", "'SPY_SYMPY_O'", "]", "=", "False", "env_vars", "[", "'SPY_RUN_CYTHON'", "]", "=", "False", "if", "self", ".", "is_sympy", "is", "True", ":", "env_vars", "[", "'SPY_AUTOLOAD_PYLAB_O'", "]", "=", "False", "env_vars", "[", "'SPY_SYMPY_O'", "]", "=", "True", "env_vars", "[", "'SPY_RUN_CYTHON'", "]", "=", "False", "if", "self", ".", "is_cython", "is", "True", ":", "env_vars", "[", "'SPY_AUTOLOAD_PYLAB_O'", "]", "=", "False", "env_vars", "[", "'SPY_SYMPY_O'", "]", "=", "False", "env_vars", "[", "'SPY_RUN_CYTHON'", "]", "=", "True", "# Add our PYTHONPATH to env_vars", "env_vars", ".", "update", "(", "pypath", ")", "# Making all env_vars strings", "for", "key", ",", "var", "in", "iteritems", "(", "env_vars", ")", ":", "if", "PY2", ":", "# Try to convert vars first to utf-8.", "try", ":", "unicode_var", "=", "to_text_string", "(", "var", ")", "except", "UnicodeDecodeError", ":", "# If that fails, try to use the file system", "# encoding because one of our vars is our", "# PYTHONPATH, and that contains file system", "# directories", "try", ":", "unicode_var", "=", "to_unicode_from_fs", "(", "var", ")", "except", ":", "# If that also fails, make the var empty", "# to be able to start Spyder.", "# See https://stackoverflow.com/q/44506900/438386", "# for details.", "unicode_var", "=", "''", "env_vars", "[", "key", "]", "=", "to_binary_string", "(", "unicode_var", ",", "encoding", "=", "'utf-8'", ")", "else", ":", "env_vars", "[", "key", "]", "=", "to_text_string", "(", "var", ")", "return", "env_vars" ]
Env vars for kernels
[ "Env", "vars", "for", "kernels" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/utils/kernelspec.py#L76-L166
train
spyder-ide/spyder
spyder/plugins/projects/widgets/explorer.py
ExplorerTreeWidget.setup_common_actions
def setup_common_actions(self): """Setup context menu common actions""" actions = FilteredDirView.setup_common_actions(self) # Toggle horizontal scrollbar hscrollbar_action = create_action(self, _("Show horizontal scrollbar"), toggled=self.toggle_hscrollbar) hscrollbar_action.setChecked(self.show_hscrollbar) self.toggle_hscrollbar(self.show_hscrollbar) return actions + [hscrollbar_action]
python
def setup_common_actions(self): """Setup context menu common actions""" actions = FilteredDirView.setup_common_actions(self) # Toggle horizontal scrollbar hscrollbar_action = create_action(self, _("Show horizontal scrollbar"), toggled=self.toggle_hscrollbar) hscrollbar_action.setChecked(self.show_hscrollbar) self.toggle_hscrollbar(self.show_hscrollbar) return actions + [hscrollbar_action]
[ "def", "setup_common_actions", "(", "self", ")", ":", "actions", "=", "FilteredDirView", ".", "setup_common_actions", "(", "self", ")", "# Toggle horizontal scrollbar\r", "hscrollbar_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Show horizontal scrollbar\"", ")", ",", "toggled", "=", "self", ".", "toggle_hscrollbar", ")", "hscrollbar_action", ".", "setChecked", "(", "self", ".", "show_hscrollbar", ")", "self", ".", "toggle_hscrollbar", "(", "self", ".", "show_hscrollbar", ")", "return", "actions", "+", "[", "hscrollbar_action", "]" ]
Setup context menu common actions
[ "Setup", "context", "menu", "common", "actions" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/widgets/explorer.py#L46-L56
train
spyder-ide/spyder
spyder/plugins/projects/widgets/explorer.py
ExplorerTreeWidget.toggle_hscrollbar
def toggle_hscrollbar(self, checked): """Toggle horizontal scrollbar""" self.parent_widget.sig_option_changed.emit('show_hscrollbar', checked) self.show_hscrollbar = checked self.header().setStretchLastSection(not checked) self.header().setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel) try: self.header().setSectionResizeMode(QHeaderView.ResizeToContents) except: # support for qtpy<1.2.0 self.header().setResizeMode(QHeaderView.ResizeToContents)
python
def toggle_hscrollbar(self, checked): """Toggle horizontal scrollbar""" self.parent_widget.sig_option_changed.emit('show_hscrollbar', checked) self.show_hscrollbar = checked self.header().setStretchLastSection(not checked) self.header().setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel) try: self.header().setSectionResizeMode(QHeaderView.ResizeToContents) except: # support for qtpy<1.2.0 self.header().setResizeMode(QHeaderView.ResizeToContents)
[ "def", "toggle_hscrollbar", "(", "self", ",", "checked", ")", ":", "self", ".", "parent_widget", ".", "sig_option_changed", ".", "emit", "(", "'show_hscrollbar'", ",", "checked", ")", "self", ".", "show_hscrollbar", "=", "checked", "self", ".", "header", "(", ")", ".", "setStretchLastSection", "(", "not", "checked", ")", "self", ".", "header", "(", ")", ".", "setHorizontalScrollMode", "(", "QAbstractItemView", ".", "ScrollPerPixel", ")", "try", ":", "self", ".", "header", "(", ")", ".", "setSectionResizeMode", "(", "QHeaderView", ".", "ResizeToContents", ")", "except", ":", "# support for qtpy<1.2.0\r", "self", ".", "header", "(", ")", ".", "setResizeMode", "(", "QHeaderView", ".", "ResizeToContents", ")" ]
Toggle horizontal scrollbar
[ "Toggle", "horizontal", "scrollbar" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/widgets/explorer.py#L60-L69
train
spyder-ide/spyder
spyder/plugins/projects/widgets/explorer.py
ExplorerTreeWidget.dragMoveEvent
def dragMoveEvent(self, event): """Reimplement Qt method""" index = self.indexAt(event.pos()) if index: dst = self.get_filename(index) if osp.isdir(dst): event.acceptProposedAction() else: event.ignore() else: event.ignore()
python
def dragMoveEvent(self, event): """Reimplement Qt method""" index = self.indexAt(event.pos()) if index: dst = self.get_filename(index) if osp.isdir(dst): event.acceptProposedAction() else: event.ignore() else: event.ignore()
[ "def", "dragMoveEvent", "(", "self", ",", "event", ")", ":", "index", "=", "self", ".", "indexAt", "(", "event", ".", "pos", "(", ")", ")", "if", "index", ":", "dst", "=", "self", ".", "get_filename", "(", "index", ")", "if", "osp", ".", "isdir", "(", "dst", ")", ":", "event", ".", "acceptProposedAction", "(", ")", "else", ":", "event", ".", "ignore", "(", ")", "else", ":", "event", ".", "ignore", "(", ")" ]
Reimplement Qt method
[ "Reimplement", "Qt", "method" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/widgets/explorer.py#L72-L82
train
spyder-ide/spyder
spyder/plugins/projects/widgets/explorer.py
ExplorerTreeWidget.dropEvent
def dropEvent(self, event): """Reimplement Qt method""" event.ignore() action = event.dropAction() if action not in (Qt.MoveAction, Qt.CopyAction): return # QTreeView must not remove the source items even in MoveAction mode: # event.setDropAction(Qt.CopyAction) dst = self.get_filename(self.indexAt(event.pos())) yes_to_all, no_to_all = None, None src_list = [to_text_string(url.toString()) for url in event.mimeData().urls()] if len(src_list) > 1: buttons = QMessageBox.Yes|QMessageBox.YesToAll| \ QMessageBox.No|QMessageBox.NoToAll|QMessageBox.Cancel else: buttons = QMessageBox.Yes|QMessageBox.No for src in src_list: if src == dst: continue dst_fname = osp.join(dst, osp.basename(src)) if osp.exists(dst_fname): if yes_to_all is not None or no_to_all is not None: if no_to_all: continue elif osp.isfile(dst_fname): answer = QMessageBox.warning(self, _('Project explorer'), _('File <b>%s</b> already exists.<br>' 'Do you want to overwrite it?') % dst_fname, buttons) if answer == QMessageBox.No: continue elif answer == QMessageBox.Cancel: break elif answer == QMessageBox.YesToAll: yes_to_all = True elif answer == QMessageBox.NoToAll: no_to_all = True continue else: QMessageBox.critical(self, _('Project explorer'), _('Folder <b>%s</b> already exists.' ) % dst_fname, QMessageBox.Ok) event.setDropAction(Qt.CopyAction) return try: if action == Qt.CopyAction: if osp.isfile(src): shutil.copy(src, dst) else: shutil.copytree(src, dst) else: if osp.isfile(src): misc.move_file(src, dst) else: shutil.move(src, dst) self.parent_widget.removed.emit(src) except EnvironmentError as error: if action == Qt.CopyAction: action_str = _('copy') else: action_str = _('move') QMessageBox.critical(self, _("Project Explorer"), _("<b>Unable to %s <i>%s</i></b>" "<br><br>Error message:<br>%s" ) % (action_str, src, to_text_string(error)))
python
def dropEvent(self, event): """Reimplement Qt method""" event.ignore() action = event.dropAction() if action not in (Qt.MoveAction, Qt.CopyAction): return # QTreeView must not remove the source items even in MoveAction mode: # event.setDropAction(Qt.CopyAction) dst = self.get_filename(self.indexAt(event.pos())) yes_to_all, no_to_all = None, None src_list = [to_text_string(url.toString()) for url in event.mimeData().urls()] if len(src_list) > 1: buttons = QMessageBox.Yes|QMessageBox.YesToAll| \ QMessageBox.No|QMessageBox.NoToAll|QMessageBox.Cancel else: buttons = QMessageBox.Yes|QMessageBox.No for src in src_list: if src == dst: continue dst_fname = osp.join(dst, osp.basename(src)) if osp.exists(dst_fname): if yes_to_all is not None or no_to_all is not None: if no_to_all: continue elif osp.isfile(dst_fname): answer = QMessageBox.warning(self, _('Project explorer'), _('File <b>%s</b> already exists.<br>' 'Do you want to overwrite it?') % dst_fname, buttons) if answer == QMessageBox.No: continue elif answer == QMessageBox.Cancel: break elif answer == QMessageBox.YesToAll: yes_to_all = True elif answer == QMessageBox.NoToAll: no_to_all = True continue else: QMessageBox.critical(self, _('Project explorer'), _('Folder <b>%s</b> already exists.' ) % dst_fname, QMessageBox.Ok) event.setDropAction(Qt.CopyAction) return try: if action == Qt.CopyAction: if osp.isfile(src): shutil.copy(src, dst) else: shutil.copytree(src, dst) else: if osp.isfile(src): misc.move_file(src, dst) else: shutil.move(src, dst) self.parent_widget.removed.emit(src) except EnvironmentError as error: if action == Qt.CopyAction: action_str = _('copy') else: action_str = _('move') QMessageBox.critical(self, _("Project Explorer"), _("<b>Unable to %s <i>%s</i></b>" "<br><br>Error message:<br>%s" ) % (action_str, src, to_text_string(error)))
[ "def", "dropEvent", "(", "self", ",", "event", ")", ":", "event", ".", "ignore", "(", ")", "action", "=", "event", ".", "dropAction", "(", ")", "if", "action", "not", "in", "(", "Qt", ".", "MoveAction", ",", "Qt", ".", "CopyAction", ")", ":", "return", "# QTreeView must not remove the source items even in MoveAction mode:\r", "# event.setDropAction(Qt.CopyAction)\r", "dst", "=", "self", ".", "get_filename", "(", "self", ".", "indexAt", "(", "event", ".", "pos", "(", ")", ")", ")", "yes_to_all", ",", "no_to_all", "=", "None", ",", "None", "src_list", "=", "[", "to_text_string", "(", "url", ".", "toString", "(", ")", ")", "for", "url", "in", "event", ".", "mimeData", "(", ")", ".", "urls", "(", ")", "]", "if", "len", "(", "src_list", ")", ">", "1", ":", "buttons", "=", "QMessageBox", ".", "Yes", "|", "QMessageBox", ".", "YesToAll", "|", "QMessageBox", ".", "No", "|", "QMessageBox", ".", "NoToAll", "|", "QMessageBox", ".", "Cancel", "else", ":", "buttons", "=", "QMessageBox", ".", "Yes", "|", "QMessageBox", ".", "No", "for", "src", "in", "src_list", ":", "if", "src", "==", "dst", ":", "continue", "dst_fname", "=", "osp", ".", "join", "(", "dst", ",", "osp", ".", "basename", "(", "src", ")", ")", "if", "osp", ".", "exists", "(", "dst_fname", ")", ":", "if", "yes_to_all", "is", "not", "None", "or", "no_to_all", "is", "not", "None", ":", "if", "no_to_all", ":", "continue", "elif", "osp", ".", "isfile", "(", "dst_fname", ")", ":", "answer", "=", "QMessageBox", ".", "warning", "(", "self", ",", "_", "(", "'Project explorer'", ")", ",", "_", "(", "'File <b>%s</b> already exists.<br>'", "'Do you want to overwrite it?'", ")", "%", "dst_fname", ",", "buttons", ")", "if", "answer", "==", "QMessageBox", ".", "No", ":", "continue", "elif", "answer", "==", "QMessageBox", ".", "Cancel", ":", "break", "elif", "answer", "==", "QMessageBox", ".", "YesToAll", ":", "yes_to_all", "=", "True", "elif", "answer", "==", "QMessageBox", ".", "NoToAll", ":", "no_to_all", "=", "True", "continue", "else", ":", "QMessageBox", ".", "critical", "(", "self", ",", "_", "(", "'Project explorer'", ")", ",", "_", "(", "'Folder <b>%s</b> already exists.'", ")", "%", "dst_fname", ",", "QMessageBox", ".", "Ok", ")", "event", ".", "setDropAction", "(", "Qt", ".", "CopyAction", ")", "return", "try", ":", "if", "action", "==", "Qt", ".", "CopyAction", ":", "if", "osp", ".", "isfile", "(", "src", ")", ":", "shutil", ".", "copy", "(", "src", ",", "dst", ")", "else", ":", "shutil", ".", "copytree", "(", "src", ",", "dst", ")", "else", ":", "if", "osp", ".", "isfile", "(", "src", ")", ":", "misc", ".", "move_file", "(", "src", ",", "dst", ")", "else", ":", "shutil", ".", "move", "(", "src", ",", "dst", ")", "self", ".", "parent_widget", ".", "removed", ".", "emit", "(", "src", ")", "except", "EnvironmentError", "as", "error", ":", "if", "action", "==", "Qt", ".", "CopyAction", ":", "action_str", "=", "_", "(", "'copy'", ")", "else", ":", "action_str", "=", "_", "(", "'move'", ")", "QMessageBox", ".", "critical", "(", "self", ",", "_", "(", "\"Project Explorer\"", ")", ",", "_", "(", "\"<b>Unable to %s <i>%s</i></b>\"", "\"<br><br>Error message:<br>%s\"", ")", "%", "(", "action_str", ",", "src", ",", "to_text_string", "(", "error", ")", ")", ")" ]
Reimplement Qt method
[ "Reimplement", "Qt", "method" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/widgets/explorer.py#L84-L152
train
spyder-ide/spyder
spyder/plugins/projects/widgets/explorer.py
ExplorerTreeWidget.delete
def delete(self, fnames=None): """Delete files""" if fnames is None: fnames = self.get_selected_filenames() multiple = len(fnames) > 1 yes_to_all = None for fname in fnames: if fname == self.proxymodel.path_list[0]: self.sig_delete_project.emit() else: yes_to_all = self.delete_file(fname, multiple, yes_to_all) if yes_to_all is not None and not yes_to_all: # Canceled break
python
def delete(self, fnames=None): """Delete files""" if fnames is None: fnames = self.get_selected_filenames() multiple = len(fnames) > 1 yes_to_all = None for fname in fnames: if fname == self.proxymodel.path_list[0]: self.sig_delete_project.emit() else: yes_to_all = self.delete_file(fname, multiple, yes_to_all) if yes_to_all is not None and not yes_to_all: # Canceled break
[ "def", "delete", "(", "self", ",", "fnames", "=", "None", ")", ":", "if", "fnames", "is", "None", ":", "fnames", "=", "self", ".", "get_selected_filenames", "(", ")", "multiple", "=", "len", "(", "fnames", ")", ">", "1", "yes_to_all", "=", "None", "for", "fname", "in", "fnames", ":", "if", "fname", "==", "self", ".", "proxymodel", ".", "path_list", "[", "0", "]", ":", "self", ".", "sig_delete_project", ".", "emit", "(", ")", "else", ":", "yes_to_all", "=", "self", ".", "delete_file", "(", "fname", ",", "multiple", ",", "yes_to_all", ")", "if", "yes_to_all", "is", "not", "None", "and", "not", "yes_to_all", ":", "# Canceled\r", "break" ]
Delete files
[ "Delete", "files" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/widgets/explorer.py#L154-L167
train
spyder-ide/spyder
spyder/plugins/projects/widgets/explorer.py
ProjectExplorerWidget.set_project_dir
def set_project_dir(self, directory): """Set the project directory""" if directory is not None: self.treewidget.set_root_path(osp.dirname(directory)) self.treewidget.set_folder_names([osp.basename(directory)]) self.treewidget.setup_project_view() try: self.treewidget.setExpanded(self.treewidget.get_index(directory), True) except TypeError: pass
python
def set_project_dir(self, directory): """Set the project directory""" if directory is not None: self.treewidget.set_root_path(osp.dirname(directory)) self.treewidget.set_folder_names([osp.basename(directory)]) self.treewidget.setup_project_view() try: self.treewidget.setExpanded(self.treewidget.get_index(directory), True) except TypeError: pass
[ "def", "set_project_dir", "(", "self", ",", "directory", ")", ":", "if", "directory", "is", "not", "None", ":", "self", ".", "treewidget", ".", "set_root_path", "(", "osp", ".", "dirname", "(", "directory", ")", ")", "self", ".", "treewidget", ".", "set_folder_names", "(", "[", "osp", ".", "basename", "(", "directory", ")", "]", ")", "self", ".", "treewidget", ".", "setup_project_view", "(", ")", "try", ":", "self", ".", "treewidget", ".", "setExpanded", "(", "self", ".", "treewidget", ".", "get_index", "(", "directory", ")", ",", "True", ")", "except", "TypeError", ":", "pass" ]
Set the project directory
[ "Set", "the", "project", "directory" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/widgets/explorer.py#L208-L218
train
spyder-ide/spyder
spyder/plugins/projects/widgets/explorer.py
ProjectExplorerWidget.setup_project
def setup_project(self, directory): """Setup project""" self.emptywidget.hide() self.treewidget.show() # Setup the directory shown by the tree self.set_project_dir(directory)
python
def setup_project(self, directory): """Setup project""" self.emptywidget.hide() self.treewidget.show() # Setup the directory shown by the tree self.set_project_dir(directory)
[ "def", "setup_project", "(", "self", ",", "directory", ")", ":", "self", ".", "emptywidget", ".", "hide", "(", ")", "self", ".", "treewidget", ".", "show", "(", ")", "# Setup the directory shown by the tree\r", "self", ".", "set_project_dir", "(", "directory", ")" ]
Setup project
[ "Setup", "project" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/widgets/explorer.py#L225-L231
train
spyder-ide/spyder
spyder/plugins/console/widgets/internalshell.py
InternalShell.start_interpreter
def start_interpreter(self, namespace): """Start Python interpreter""" self.clear() if self.interpreter is not None: self.interpreter.closing() self.interpreter = Interpreter(namespace, self.exitfunc, SysOutput, WidgetProxy, get_debug_level()) self.interpreter.stdout_write.data_avail.connect(self.stdout_avail) self.interpreter.stderr_write.data_avail.connect(self.stderr_avail) self.interpreter.widget_proxy.sig_set_readonly.connect(self.setReadOnly) self.interpreter.widget_proxy.sig_new_prompt.connect(self.new_prompt) self.interpreter.widget_proxy.sig_edit.connect(self.edit_script) self.interpreter.widget_proxy.sig_wait_input.connect(self.wait_input) if self.multithreaded: self.interpreter.start() # Interpreter banner banner = create_banner(self.message) self.write(banner, prompt=True) # Initial commands for cmd in self.commands: self.run_command(cmd, history=False, new_prompt=False) # First prompt self.new_prompt(self.interpreter.p1) self.refresh.emit() return self.interpreter
python
def start_interpreter(self, namespace): """Start Python interpreter""" self.clear() if self.interpreter is not None: self.interpreter.closing() self.interpreter = Interpreter(namespace, self.exitfunc, SysOutput, WidgetProxy, get_debug_level()) self.interpreter.stdout_write.data_avail.connect(self.stdout_avail) self.interpreter.stderr_write.data_avail.connect(self.stderr_avail) self.interpreter.widget_proxy.sig_set_readonly.connect(self.setReadOnly) self.interpreter.widget_proxy.sig_new_prompt.connect(self.new_prompt) self.interpreter.widget_proxy.sig_edit.connect(self.edit_script) self.interpreter.widget_proxy.sig_wait_input.connect(self.wait_input) if self.multithreaded: self.interpreter.start() # Interpreter banner banner = create_banner(self.message) self.write(banner, prompt=True) # Initial commands for cmd in self.commands: self.run_command(cmd, history=False, new_prompt=False) # First prompt self.new_prompt(self.interpreter.p1) self.refresh.emit() return self.interpreter
[ "def", "start_interpreter", "(", "self", ",", "namespace", ")", ":", "self", ".", "clear", "(", ")", "if", "self", ".", "interpreter", "is", "not", "None", ":", "self", ".", "interpreter", ".", "closing", "(", ")", "self", ".", "interpreter", "=", "Interpreter", "(", "namespace", ",", "self", ".", "exitfunc", ",", "SysOutput", ",", "WidgetProxy", ",", "get_debug_level", "(", ")", ")", "self", ".", "interpreter", ".", "stdout_write", ".", "data_avail", ".", "connect", "(", "self", ".", "stdout_avail", ")", "self", ".", "interpreter", ".", "stderr_write", ".", "data_avail", ".", "connect", "(", "self", ".", "stderr_avail", ")", "self", ".", "interpreter", ".", "widget_proxy", ".", "sig_set_readonly", ".", "connect", "(", "self", ".", "setReadOnly", ")", "self", ".", "interpreter", ".", "widget_proxy", ".", "sig_new_prompt", ".", "connect", "(", "self", ".", "new_prompt", ")", "self", ".", "interpreter", ".", "widget_proxy", ".", "sig_edit", ".", "connect", "(", "self", ".", "edit_script", ")", "self", ".", "interpreter", ".", "widget_proxy", ".", "sig_wait_input", ".", "connect", "(", "self", ".", "wait_input", ")", "if", "self", ".", "multithreaded", ":", "self", ".", "interpreter", ".", "start", "(", ")", "# Interpreter banner\r", "banner", "=", "create_banner", "(", "self", ".", "message", ")", "self", ".", "write", "(", "banner", ",", "prompt", "=", "True", ")", "# Initial commands\r", "for", "cmd", "in", "self", ".", "commands", ":", "self", ".", "run_command", "(", "cmd", ",", "history", "=", "False", ",", "new_prompt", "=", "False", ")", "# First prompt\r", "self", ".", "new_prompt", "(", "self", ".", "interpreter", ".", "p1", ")", "self", ".", "refresh", ".", "emit", "(", ")", "return", "self", ".", "interpreter" ]
Start Python interpreter
[ "Start", "Python", "interpreter" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/internalshell.py#L180-L210
train
spyder-ide/spyder
spyder/plugins/console/widgets/internalshell.py
InternalShell.exit_interpreter
def exit_interpreter(self): """Exit interpreter""" self.interpreter.exit_flag = True if self.multithreaded: self.interpreter.stdin_write.write(to_binary_string('\n')) self.interpreter.restore_stds()
python
def exit_interpreter(self): """Exit interpreter""" self.interpreter.exit_flag = True if self.multithreaded: self.interpreter.stdin_write.write(to_binary_string('\n')) self.interpreter.restore_stds()
[ "def", "exit_interpreter", "(", "self", ")", ":", "self", ".", "interpreter", ".", "exit_flag", "=", "True", "if", "self", ".", "multithreaded", ":", "self", ".", "interpreter", ".", "stdin_write", ".", "write", "(", "to_binary_string", "(", "'\\n'", ")", ")", "self", ".", "interpreter", ".", "restore_stds", "(", ")" ]
Exit interpreter
[ "Exit", "interpreter" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/internalshell.py#L212-L217
train
spyder-ide/spyder
spyder/plugins/console/widgets/internalshell.py
InternalShell.stdout_avail
def stdout_avail(self): """Data is available in stdout, let's empty the queue and write it!""" data = self.interpreter.stdout_write.empty_queue() if data: self.write(data)
python
def stdout_avail(self): """Data is available in stdout, let's empty the queue and write it!""" data = self.interpreter.stdout_write.empty_queue() if data: self.write(data)
[ "def", "stdout_avail", "(", "self", ")", ":", "data", "=", "self", ".", "interpreter", ".", "stdout_write", ".", "empty_queue", "(", ")", "if", "data", ":", "self", ".", "write", "(", "data", ")" ]
Data is available in stdout, let's empty the queue and write it!
[ "Data", "is", "available", "in", "stdout", "let", "s", "empty", "the", "queue", "and", "write", "it!" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/internalshell.py#L226-L230
train
spyder-ide/spyder
spyder/plugins/console/widgets/internalshell.py
InternalShell.stderr_avail
def stderr_avail(self): """Data is available in stderr, let's empty the queue and write it!""" data = self.interpreter.stderr_write.empty_queue() if data: self.write(data, error=True) self.flush(error=True)
python
def stderr_avail(self): """Data is available in stderr, let's empty the queue and write it!""" data = self.interpreter.stderr_write.empty_queue() if data: self.write(data, error=True) self.flush(error=True)
[ "def", "stderr_avail", "(", "self", ")", ":", "data", "=", "self", ".", "interpreter", ".", "stderr_write", ".", "empty_queue", "(", ")", "if", "data", ":", "self", ".", "write", "(", "data", ",", "error", "=", "True", ")", "self", ".", "flush", "(", "error", "=", "True", ")" ]
Data is available in stderr, let's empty the queue and write it!
[ "Data", "is", "available", "in", "stderr", "let", "s", "empty", "the", "queue", "and", "write", "it!" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/internalshell.py#L232-L237
train
spyder-ide/spyder
spyder/plugins/console/widgets/internalshell.py
InternalShell.wait_input
def wait_input(self, prompt=''): """Wait for input (raw_input support)""" self.new_prompt(prompt) self.setFocus() self.input_mode = True self.input_loop = QEventLoop() self.input_loop.exec_() self.input_loop = None
python
def wait_input(self, prompt=''): """Wait for input (raw_input support)""" self.new_prompt(prompt) self.setFocus() self.input_mode = True self.input_loop = QEventLoop() self.input_loop.exec_() self.input_loop = None
[ "def", "wait_input", "(", "self", ",", "prompt", "=", "''", ")", ":", "self", ".", "new_prompt", "(", "prompt", ")", "self", ".", "setFocus", "(", ")", "self", ".", "input_mode", "=", "True", "self", ".", "input_loop", "=", "QEventLoop", "(", ")", "self", ".", "input_loop", ".", "exec_", "(", ")", "self", ".", "input_loop", "=", "None" ]
Wait for input (raw_input support)
[ "Wait", "for", "input", "(", "raw_input", "support", ")" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/internalshell.py#L241-L248
train
spyder-ide/spyder
spyder/plugins/console/widgets/internalshell.py
InternalShell.end_input
def end_input(self, cmd): """End of wait_input mode""" self.input_mode = False self.input_loop.exit() self.interpreter.widget_proxy.end_input(cmd)
python
def end_input(self, cmd): """End of wait_input mode""" self.input_mode = False self.input_loop.exit() self.interpreter.widget_proxy.end_input(cmd)
[ "def", "end_input", "(", "self", ",", "cmd", ")", ":", "self", ".", "input_mode", "=", "False", "self", ".", "input_loop", ".", "exit", "(", ")", "self", ".", "interpreter", ".", "widget_proxy", ".", "end_input", "(", "cmd", ")" ]
End of wait_input mode
[ "End", "of", "wait_input", "mode" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/internalshell.py#L250-L254
train
spyder-ide/spyder
spyder/plugins/console/widgets/internalshell.py
InternalShell.setup_context_menu
def setup_context_menu(self): """Reimplement PythonShellWidget method""" PythonShellWidget.setup_context_menu(self) self.help_action = create_action(self, _("Help..."), icon=ima.icon('DialogHelpButton'), triggered=self.help) self.menu.addAction(self.help_action)
python
def setup_context_menu(self): """Reimplement PythonShellWidget method""" PythonShellWidget.setup_context_menu(self) self.help_action = create_action(self, _("Help..."), icon=ima.icon('DialogHelpButton'), triggered=self.help) self.menu.addAction(self.help_action)
[ "def", "setup_context_menu", "(", "self", ")", ":", "PythonShellWidget", ".", "setup_context_menu", "(", "self", ")", "self", ".", "help_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Help...\"", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'DialogHelpButton'", ")", ",", "triggered", "=", "self", ".", "help", ")", "self", ".", "menu", ".", "addAction", "(", "self", ".", "help_action", ")" ]
Reimplement PythonShellWidget method
[ "Reimplement", "PythonShellWidget", "method" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/internalshell.py#L258-L264
train
spyder-ide/spyder
spyder/plugins/console/widgets/internalshell.py
InternalShell.help
def help(self): """Help on Spyder console""" QMessageBox.about(self, _("Help"), """<b>%s</b> <p><i>%s</i><br> edit foobar.py <p><i>%s</i><br> xedit foobar.py <p><i>%s</i><br> run foobar.py <p><i>%s</i><br> clear x, y <p><i>%s</i><br> !ls <p><i>%s</i><br> object? <p><i>%s</i><br> result = oedit(object) """ % (_('Shell special commands:'), _('Internal editor:'), _('External editor:'), _('Run script:'), _('Remove references:'), _('System commands:'), _('Python help:'), _('GUI-based editor:')))
python
def help(self): """Help on Spyder console""" QMessageBox.about(self, _("Help"), """<b>%s</b> <p><i>%s</i><br> edit foobar.py <p><i>%s</i><br> xedit foobar.py <p><i>%s</i><br> run foobar.py <p><i>%s</i><br> clear x, y <p><i>%s</i><br> !ls <p><i>%s</i><br> object? <p><i>%s</i><br> result = oedit(object) """ % (_('Shell special commands:'), _('Internal editor:'), _('External editor:'), _('Run script:'), _('Remove references:'), _('System commands:'), _('Python help:'), _('GUI-based editor:')))
[ "def", "help", "(", "self", ")", ":", "QMessageBox", ".", "about", "(", "self", ",", "_", "(", "\"Help\"", ")", ",", "\"\"\"<b>%s</b>\r\n <p><i>%s</i><br> edit foobar.py\r\n <p><i>%s</i><br> xedit foobar.py\r\n <p><i>%s</i><br> run foobar.py\r\n <p><i>%s</i><br> clear x, y\r\n <p><i>%s</i><br> !ls\r\n <p><i>%s</i><br> object?\r\n <p><i>%s</i><br> result = oedit(object)\r\n \"\"\"", "%", "(", "_", "(", "'Shell special commands:'", ")", ",", "_", "(", "'Internal editor:'", ")", ",", "_", "(", "'External editor:'", ")", ",", "_", "(", "'Run script:'", ")", ",", "_", "(", "'Remove references:'", ")", ",", "_", "(", "'System commands:'", ")", ",", "_", "(", "'Python help:'", ")", ",", "_", "(", "'GUI-based editor:'", ")", ")", ")" ]
Help on Spyder console
[ "Help", "on", "Spyder", "console" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/internalshell.py#L267-L285
train