id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1 value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
31,400 | spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutFinder.set_text | def set_text(self, text):
"""Set the filter text."""
text = text.strip()
new_text = self.text() + text
self.setText(new_text) | python | def set_text(self, text):
"""Set the filter text."""
text = text.strip()
new_text = self.text() + text
self.setText(new_text) | [
"def",
"set_text",
"(",
"self",
",",
"text",
")",
":",
"text",
"=",
"text",
".",
"strip",
"(",
")",
"new_text",
"=",
"self",
".",
"text",
"(",
")",
"+",
"text",
"self",
".",
"setText",
"(",
"new_text",
")"
] | Set the filter text. | [
"Set",
"the",
"filter",
"text",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L136-L140 |
31,401 | spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutEditor.check_singlekey | def check_singlekey(self):
"""Check if the first sub-sequence of the new key sequence is valid."""
if len(self._qsequences) == 0:
return True
else:
keystr = self._qsequences[0]
valid_single_keys = (EDITOR_SINGLE_KEYS if
self.context == 'editor' else SINGLE_KEYS)
if any((m in keystr for m in ('Ctrl', 'Alt', 'Shift', 'Meta'))):
return True
else:
# This means that the the first subsequence is composed of
# a single key with no modifier.
valid_single_keys = (EDITOR_SINGLE_KEYS if
self.context == 'editor' else SINGLE_KEYS)
if any((k == keystr for k in valid_single_keys)):
return True
else:
return False | python | def check_singlekey(self):
"""Check if the first sub-sequence of the new key sequence is valid."""
if len(self._qsequences) == 0:
return True
else:
keystr = self._qsequences[0]
valid_single_keys = (EDITOR_SINGLE_KEYS if
self.context == 'editor' else SINGLE_KEYS)
if any((m in keystr for m in ('Ctrl', 'Alt', 'Shift', 'Meta'))):
return True
else:
# This means that the the first subsequence is composed of
# a single key with no modifier.
valid_single_keys = (EDITOR_SINGLE_KEYS if
self.context == 'editor' else SINGLE_KEYS)
if any((k == keystr for k in valid_single_keys)):
return True
else:
return False | [
"def",
"check_singlekey",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"_qsequences",
")",
"==",
"0",
":",
"return",
"True",
"else",
":",
"keystr",
"=",
"self",
".",
"_qsequences",
"[",
"0",
"]",
"valid_single_keys",
"=",
"(",
"EDITOR_SINGLE_KEY... | Check if the first sub-sequence of the new key sequence is valid. | [
"Check",
"if",
"the",
"first",
"sub",
"-",
"sequence",
"of",
"the",
"new",
"key",
"sequence",
"is",
"valid",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L372-L390 |
31,402 | spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutEditor.update_warning | def update_warning(self):
"""Update the warning label, buttons state and sequence text."""
new_qsequence = self.new_qsequence
new_sequence = self.new_sequence
self.text_new_sequence.setText(
new_qsequence.toString(QKeySequence.NativeText))
conflicts = self.check_conflicts()
if len(self._qsequences) == 0:
warning = SEQUENCE_EMPTY
tip = ''
icon = QIcon()
elif conflicts:
warning = SEQUENCE_CONFLICT
template = '<i>{0}<b>{1}</b>{2}</i>'
tip_title = _('The new shortcut conflicts with:') + '<br>'
tip_body = ''
for s in conflicts:
tip_body += ' - {0}: {1}<br>'.format(s.context, s.name)
tip_body = tip_body[:-4] # Removing last <br>
tip_override = '<br>Press <b>OK</b> to unbind '
tip_override += 'it' if len(conflicts) == 1 else 'them'
tip_override += ' and assign it to <b>{}</b>'.format(self.name)
tip = template.format(tip_title, tip_body, tip_override)
icon = get_std_icon('MessageBoxWarning')
elif new_sequence in BLACKLIST:
warning = IN_BLACKLIST
template = '<i>{0}<b>{1}</b></i>'
tip_title = _('Forbidden key sequence!') + '<br>'
tip_body = ''
use = BLACKLIST[new_sequence]
if use is not None:
tip_body = use
tip = template.format(tip_title, tip_body)
icon = get_std_icon('MessageBoxWarning')
elif self.check_singlekey() is False or self.check_ascii() is False:
warning = INVALID_KEY
template = '<i>{0}</i>'
tip = _('Invalid key sequence entered') + '<br>'
icon = get_std_icon('MessageBoxWarning')
else:
warning = NO_WARNING
tip = 'This shortcut is valid.'
icon = get_std_icon('DialogApplyButton')
self.warning = warning
self.conflicts = conflicts
self.helper_button.setIcon(icon)
self.button_ok.setEnabled(
self.warning in [NO_WARNING, SEQUENCE_CONFLICT])
self.label_warning.setText(tip)
# Everytime after update warning message, update the label height
new_height = self.label_warning.sizeHint().height()
self.label_warning.setMaximumHeight(new_height) | python | def update_warning(self):
"""Update the warning label, buttons state and sequence text."""
new_qsequence = self.new_qsequence
new_sequence = self.new_sequence
self.text_new_sequence.setText(
new_qsequence.toString(QKeySequence.NativeText))
conflicts = self.check_conflicts()
if len(self._qsequences) == 0:
warning = SEQUENCE_EMPTY
tip = ''
icon = QIcon()
elif conflicts:
warning = SEQUENCE_CONFLICT
template = '<i>{0}<b>{1}</b>{2}</i>'
tip_title = _('The new shortcut conflicts with:') + '<br>'
tip_body = ''
for s in conflicts:
tip_body += ' - {0}: {1}<br>'.format(s.context, s.name)
tip_body = tip_body[:-4] # Removing last <br>
tip_override = '<br>Press <b>OK</b> to unbind '
tip_override += 'it' if len(conflicts) == 1 else 'them'
tip_override += ' and assign it to <b>{}</b>'.format(self.name)
tip = template.format(tip_title, tip_body, tip_override)
icon = get_std_icon('MessageBoxWarning')
elif new_sequence in BLACKLIST:
warning = IN_BLACKLIST
template = '<i>{0}<b>{1}</b></i>'
tip_title = _('Forbidden key sequence!') + '<br>'
tip_body = ''
use = BLACKLIST[new_sequence]
if use is not None:
tip_body = use
tip = template.format(tip_title, tip_body)
icon = get_std_icon('MessageBoxWarning')
elif self.check_singlekey() is False or self.check_ascii() is False:
warning = INVALID_KEY
template = '<i>{0}</i>'
tip = _('Invalid key sequence entered') + '<br>'
icon = get_std_icon('MessageBoxWarning')
else:
warning = NO_WARNING
tip = 'This shortcut is valid.'
icon = get_std_icon('DialogApplyButton')
self.warning = warning
self.conflicts = conflicts
self.helper_button.setIcon(icon)
self.button_ok.setEnabled(
self.warning in [NO_WARNING, SEQUENCE_CONFLICT])
self.label_warning.setText(tip)
# Everytime after update warning message, update the label height
new_height = self.label_warning.sizeHint().height()
self.label_warning.setMaximumHeight(new_height) | [
"def",
"update_warning",
"(",
"self",
")",
":",
"new_qsequence",
"=",
"self",
".",
"new_qsequence",
"new_sequence",
"=",
"self",
".",
"new_sequence",
"self",
".",
"text_new_sequence",
".",
"setText",
"(",
"new_qsequence",
".",
"toString",
"(",
"QKeySequence",
".... | Update the warning label, buttons state and sequence text. | [
"Update",
"the",
"warning",
"label",
"buttons",
"state",
"and",
"sequence",
"text",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L392-L446 |
31,403 | spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutEditor.set_sequence_from_str | def set_sequence_from_str(self, sequence):
"""
This is a convenience method to set the new QKeySequence of the
shortcut editor from a string.
"""
self._qsequences = [QKeySequence(s) for s in sequence.split(', ')]
self.update_warning() | python | def set_sequence_from_str(self, sequence):
"""
This is a convenience method to set the new QKeySequence of the
shortcut editor from a string.
"""
self._qsequences = [QKeySequence(s) for s in sequence.split(', ')]
self.update_warning() | [
"def",
"set_sequence_from_str",
"(",
"self",
",",
"sequence",
")",
":",
"self",
".",
"_qsequences",
"=",
"[",
"QKeySequence",
"(",
"s",
")",
"for",
"s",
"in",
"sequence",
".",
"split",
"(",
"', '",
")",
"]",
"self",
".",
"update_warning",
"(",
")"
] | This is a convenience method to set the new QKeySequence of the
shortcut editor from a string. | [
"This",
"is",
"a",
"convenience",
"method",
"to",
"set",
"the",
"new",
"QKeySequence",
"of",
"the",
"shortcut",
"editor",
"from",
"a",
"string",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L448-L454 |
31,404 | spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutEditor.set_sequence_to_default | def set_sequence_to_default(self):
"""Set the new sequence to the default value defined in the config."""
sequence = CONF.get_default(
'shortcuts', "{}/{}".format(self.context, self.name))
self._qsequences = sequence.split(', ')
self.update_warning() | python | def set_sequence_to_default(self):
"""Set the new sequence to the default value defined in the config."""
sequence = CONF.get_default(
'shortcuts', "{}/{}".format(self.context, self.name))
self._qsequences = sequence.split(', ')
self.update_warning() | [
"def",
"set_sequence_to_default",
"(",
"self",
")",
":",
"sequence",
"=",
"CONF",
".",
"get_default",
"(",
"'shortcuts'",
",",
"\"{}/{}\"",
".",
"format",
"(",
"self",
".",
"context",
",",
"self",
".",
"name",
")",
")",
"self",
".",
"_qsequences",
"=",
"... | Set the new sequence to the default value defined in the config. | [
"Set",
"the",
"new",
"sequence",
"to",
"the",
"default",
"value",
"defined",
"in",
"the",
"config",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L456-L461 |
31,405 | spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutEditor.accept_override | def accept_override(self):
"""Unbind all conflicted shortcuts, and accept the new one"""
conflicts = self.check_conflicts()
if conflicts:
for shortcut in conflicts:
shortcut.key = ''
self.accept() | python | def accept_override(self):
"""Unbind all conflicted shortcuts, and accept the new one"""
conflicts = self.check_conflicts()
if conflicts:
for shortcut in conflicts:
shortcut.key = ''
self.accept() | [
"def",
"accept_override",
"(",
"self",
")",
":",
"conflicts",
"=",
"self",
".",
"check_conflicts",
"(",
")",
"if",
"conflicts",
":",
"for",
"shortcut",
"in",
"conflicts",
":",
"shortcut",
".",
"key",
"=",
"''",
"self",
".",
"accept",
"(",
")"
] | Unbind all conflicted shortcuts, and accept the new one | [
"Unbind",
"all",
"conflicted",
"shortcuts",
"and",
"accept",
"the",
"new",
"one"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L478-L484 |
31,406 | spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutsModel.current_index | def current_index(self):
"""Get the currently selected index in the parent table view."""
i = self._parent.proxy_model.mapToSource(self._parent.currentIndex())
return i | python | def current_index(self):
"""Get the currently selected index in the parent table view."""
i = self._parent.proxy_model.mapToSource(self._parent.currentIndex())
return i | [
"def",
"current_index",
"(",
"self",
")",
":",
"i",
"=",
"self",
".",
"_parent",
".",
"proxy_model",
".",
"mapToSource",
"(",
"self",
".",
"_parent",
".",
"currentIndex",
"(",
")",
")",
"return",
"i"
] | Get the currently selected index in the parent table view. | [
"Get",
"the",
"currently",
"selected",
"index",
"in",
"the",
"parent",
"table",
"view",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L537-L540 |
31,407 | spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutsModel.update_search_letters | def update_search_letters(self, text):
"""Update search letters with text input in search box."""
self.letters = text
names = [shortcut.name for shortcut in self.shortcuts]
results = get_search_scores(text, names, template='<b>{0}</b>')
self.normal_text, self.rich_text, self.scores = zip(*results)
self.reset() | python | def update_search_letters(self, text):
"""Update search letters with text input in search box."""
self.letters = text
names = [shortcut.name for shortcut in self.shortcuts]
results = get_search_scores(text, names, template='<b>{0}</b>')
self.normal_text, self.rich_text, self.scores = zip(*results)
self.reset() | [
"def",
"update_search_letters",
"(",
"self",
",",
"text",
")",
":",
"self",
".",
"letters",
"=",
"text",
"names",
"=",
"[",
"shortcut",
".",
"name",
"for",
"shortcut",
"in",
"self",
".",
"shortcuts",
"]",
"results",
"=",
"get_search_scores",
"(",
"text",
... | Update search letters with text input in search box. | [
"Update",
"search",
"letters",
"with",
"text",
"input",
"in",
"search",
"box",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L629-L635 |
31,408 | spyder-ide/spyder | spyder/preferences/shortcuts.py | CustomSortFilterProxy.set_filter | def set_filter(self, text):
"""Set regular expression for filter."""
self.pattern = get_search_regex(text)
if self.pattern:
self._parent.setSortingEnabled(False)
else:
self._parent.setSortingEnabled(True)
self.invalidateFilter() | python | def set_filter(self, text):
"""Set regular expression for filter."""
self.pattern = get_search_regex(text)
if self.pattern:
self._parent.setSortingEnabled(False)
else:
self._parent.setSortingEnabled(True)
self.invalidateFilter() | [
"def",
"set_filter",
"(",
"self",
",",
"text",
")",
":",
"self",
".",
"pattern",
"=",
"get_search_regex",
"(",
"text",
")",
"if",
"self",
".",
"pattern",
":",
"self",
".",
"_parent",
".",
"setSortingEnabled",
"(",
"False",
")",
"else",
":",
"self",
"."... | Set regular expression for filter. | [
"Set",
"regular",
"expression",
"for",
"filter",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L659-L666 |
31,409 | spyder-ide/spyder | spyder/preferences/shortcuts.py | CustomSortFilterProxy.filterAcceptsRow | def filterAcceptsRow(self, row_num, parent):
"""Qt override.
Reimplemented from base class to allow the use of custom filtering.
"""
model = self.sourceModel()
name = model.row(row_num).name
r = re.search(self.pattern, name)
if r is None:
return False
else:
return True | python | def filterAcceptsRow(self, row_num, parent):
"""Qt override.
Reimplemented from base class to allow the use of custom filtering.
"""
model = self.sourceModel()
name = model.row(row_num).name
r = re.search(self.pattern, name)
if r is None:
return False
else:
return True | [
"def",
"filterAcceptsRow",
"(",
"self",
",",
"row_num",
",",
"parent",
")",
":",
"model",
"=",
"self",
".",
"sourceModel",
"(",
")",
"name",
"=",
"model",
".",
"row",
"(",
"row_num",
")",
".",
"name",
"r",
"=",
"re",
".",
"search",
"(",
"self",
"."... | Qt override.
Reimplemented from base class to allow the use of custom filtering. | [
"Qt",
"override",
".",
"Reimplemented",
"from",
"base",
"class",
"to",
"allow",
"the",
"use",
"of",
"custom",
"filtering",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L668-L680 |
31,410 | spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutsTable.load_shortcuts | def load_shortcuts(self):
"""Load shortcuts and assign to table model."""
shortcuts = []
for context, name, keystr in iter_shortcuts():
shortcut = Shortcut(context, name, keystr)
shortcuts.append(shortcut)
shortcuts = sorted(shortcuts, key=lambda x: x.context+x.name)
# Store the original order of shortcuts
for i, shortcut in enumerate(shortcuts):
shortcut.index = i
self.source_model.shortcuts = shortcuts
self.source_model.scores = [0]*len(shortcuts)
self.source_model.rich_text = [s.name for s in shortcuts]
self.source_model.reset()
self.adjust_cells()
self.sortByColumn(CONTEXT, Qt.AscendingOrder) | python | def load_shortcuts(self):
"""Load shortcuts and assign to table model."""
shortcuts = []
for context, name, keystr in iter_shortcuts():
shortcut = Shortcut(context, name, keystr)
shortcuts.append(shortcut)
shortcuts = sorted(shortcuts, key=lambda x: x.context+x.name)
# Store the original order of shortcuts
for i, shortcut in enumerate(shortcuts):
shortcut.index = i
self.source_model.shortcuts = shortcuts
self.source_model.scores = [0]*len(shortcuts)
self.source_model.rich_text = [s.name for s in shortcuts]
self.source_model.reset()
self.adjust_cells()
self.sortByColumn(CONTEXT, Qt.AscendingOrder) | [
"def",
"load_shortcuts",
"(",
"self",
")",
":",
"shortcuts",
"=",
"[",
"]",
"for",
"context",
",",
"name",
",",
"keystr",
"in",
"iter_shortcuts",
"(",
")",
":",
"shortcut",
"=",
"Shortcut",
"(",
"context",
",",
"name",
",",
"keystr",
")",
"shortcuts",
... | Load shortcuts and assign to table model. | [
"Load",
"shortcuts",
"and",
"assign",
"to",
"table",
"model",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L737-L752 |
31,411 | spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutsTable.save_shortcuts | def save_shortcuts(self):
"""Save shortcuts from table model."""
self.check_shortcuts()
for shortcut in self.source_model.shortcuts:
shortcut.save() | python | def save_shortcuts(self):
"""Save shortcuts from table model."""
self.check_shortcuts()
for shortcut in self.source_model.shortcuts:
shortcut.save() | [
"def",
"save_shortcuts",
"(",
"self",
")",
":",
"self",
".",
"check_shortcuts",
"(",
")",
"for",
"shortcut",
"in",
"self",
".",
"source_model",
".",
"shortcuts",
":",
"shortcut",
".",
"save",
"(",
")"
] | Save shortcuts from table model. | [
"Save",
"shortcuts",
"from",
"table",
"model",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L777-L781 |
31,412 | spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutsTable.show_editor | def show_editor(self):
"""Create, setup and display the shortcut editor dialog."""
index = self.proxy_model.mapToSource(self.currentIndex())
row, column = index.row(), index.column()
shortcuts = self.source_model.shortcuts
context = shortcuts[row].context
name = shortcuts[row].name
sequence_index = self.source_model.index(row, SEQUENCE)
sequence = sequence_index.data()
dialog = ShortcutEditor(self, context, name, sequence, shortcuts)
if dialog.exec_():
new_sequence = dialog.new_sequence
self.source_model.setData(sequence_index, new_sequence) | python | def show_editor(self):
"""Create, setup and display the shortcut editor dialog."""
index = self.proxy_model.mapToSource(self.currentIndex())
row, column = index.row(), index.column()
shortcuts = self.source_model.shortcuts
context = shortcuts[row].context
name = shortcuts[row].name
sequence_index = self.source_model.index(row, SEQUENCE)
sequence = sequence_index.data()
dialog = ShortcutEditor(self, context, name, sequence, shortcuts)
if dialog.exec_():
new_sequence = dialog.new_sequence
self.source_model.setData(sequence_index, new_sequence) | [
"def",
"show_editor",
"(",
"self",
")",
":",
"index",
"=",
"self",
".",
"proxy_model",
".",
"mapToSource",
"(",
"self",
".",
"currentIndex",
"(",
")",
")",
"row",
",",
"column",
"=",
"index",
".",
"row",
"(",
")",
",",
"index",
".",
"column",
"(",
... | Create, setup and display the shortcut editor dialog. | [
"Create",
"setup",
"and",
"display",
"the",
"shortcut",
"editor",
"dialog",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L783-L798 |
31,413 | spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutsTable.set_regex | def set_regex(self, regex=None, reset=False):
"""Update the regex text for the shortcut finder."""
if reset:
text = ''
else:
text = self.finder.text().replace(' ', '').lower()
self.proxy_model.set_filter(text)
self.source_model.update_search_letters(text)
self.sortByColumn(SEARCH_SCORE, Qt.AscendingOrder)
if self.last_regex != regex:
self.selectRow(0)
self.last_regex = regex | python | def set_regex(self, regex=None, reset=False):
"""Update the regex text for the shortcut finder."""
if reset:
text = ''
else:
text = self.finder.text().replace(' ', '').lower()
self.proxy_model.set_filter(text)
self.source_model.update_search_letters(text)
self.sortByColumn(SEARCH_SCORE, Qt.AscendingOrder)
if self.last_regex != regex:
self.selectRow(0)
self.last_regex = regex | [
"def",
"set_regex",
"(",
"self",
",",
"regex",
"=",
"None",
",",
"reset",
"=",
"False",
")",
":",
"if",
"reset",
":",
"text",
"=",
"''",
"else",
":",
"text",
"=",
"self",
".",
"finder",
".",
"text",
"(",
")",
".",
"replace",
"(",
"' '",
",",
"'... | Update the regex text for the shortcut finder. | [
"Update",
"the",
"regex",
"text",
"for",
"the",
"shortcut",
"finder",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L800-L813 |
31,414 | spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutsConfigPage.reset_to_default | def reset_to_default(self):
"""Reset to default values of the shortcuts making a confirmation."""
reset = QMessageBox.warning(self, _("Shortcuts reset"),
_("Do you want to reset "
"to default values?"),
QMessageBox.Yes | QMessageBox.No)
if reset == QMessageBox.No:
return
reset_shortcuts()
self.main.apply_shortcuts()
self.table.load_shortcuts()
self.load_from_conf()
self.set_modified(False) | python | def reset_to_default(self):
"""Reset to default values of the shortcuts making a confirmation."""
reset = QMessageBox.warning(self, _("Shortcuts reset"),
_("Do you want to reset "
"to default values?"),
QMessageBox.Yes | QMessageBox.No)
if reset == QMessageBox.No:
return
reset_shortcuts()
self.main.apply_shortcuts()
self.table.load_shortcuts()
self.load_from_conf()
self.set_modified(False) | [
"def",
"reset_to_default",
"(",
"self",
")",
":",
"reset",
"=",
"QMessageBox",
".",
"warning",
"(",
"self",
",",
"_",
"(",
"\"Shortcuts reset\"",
")",
",",
"_",
"(",
"\"Do you want to reset \"",
"\"to default values?\"",
")",
",",
"QMessageBox",
".",
"Yes",
"|... | Reset to default values of the shortcuts making a confirmation. | [
"Reset",
"to",
"default",
"values",
"of",
"the",
"shortcuts",
"making",
"a",
"confirmation",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L895-L907 |
31,415 | spyder-ide/spyder | spyder/utils/syntaxhighlighters.py | get_color_scheme | def get_color_scheme(name):
"""Get a color scheme from config using its name"""
name = name.lower()
scheme = {}
for key in COLOR_SCHEME_KEYS:
try:
scheme[key] = CONF.get('appearance', name+'/'+key)
except:
scheme[key] = CONF.get('appearance', 'spyder/'+key)
return scheme | python | def get_color_scheme(name):
"""Get a color scheme from config using its name"""
name = name.lower()
scheme = {}
for key in COLOR_SCHEME_KEYS:
try:
scheme[key] = CONF.get('appearance', name+'/'+key)
except:
scheme[key] = CONF.get('appearance', 'spyder/'+key)
return scheme | [
"def",
"get_color_scheme",
"(",
"name",
")",
":",
"name",
"=",
"name",
".",
"lower",
"(",
")",
"scheme",
"=",
"{",
"}",
"for",
"key",
"in",
"COLOR_SCHEME_KEYS",
":",
"try",
":",
"scheme",
"[",
"key",
"]",
"=",
"CONF",
".",
"get",
"(",
"'appearance'",... | Get a color scheme from config using its name | [
"Get",
"a",
"color",
"scheme",
"from",
"config",
"using",
"its",
"name"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/syntaxhighlighters.py#L88-L97 |
31,416 | spyder-ide/spyder | spyder/utils/syntaxhighlighters.py | get_code_cell_name | def get_code_cell_name(text):
"""Returns a code cell name from a code cell comment."""
name = text.strip().lstrip("#% ")
if name.startswith("<codecell>"):
name = name[10:].lstrip()
elif name.startswith("In["):
name = name[2:]
if name.endswith("]:"):
name = name[:-1]
name = name.strip()
return name | python | def get_code_cell_name(text):
"""Returns a code cell name from a code cell comment."""
name = text.strip().lstrip("#% ")
if name.startswith("<codecell>"):
name = name[10:].lstrip()
elif name.startswith("In["):
name = name[2:]
if name.endswith("]:"):
name = name[:-1]
name = name.strip()
return name | [
"def",
"get_code_cell_name",
"(",
"text",
")",
":",
"name",
"=",
"text",
".",
"strip",
"(",
")",
".",
"lstrip",
"(",
"\"#% \"",
")",
"if",
"name",
".",
"startswith",
"(",
"\"<codecell>\"",
")",
":",
"name",
"=",
"name",
"[",
"10",
":",
"]",
".",
"l... | Returns a code cell name from a code cell comment. | [
"Returns",
"a",
"code",
"cell",
"name",
"from",
"a",
"code",
"cell",
"comment",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/syntaxhighlighters.py#L392-L402 |
31,417 | spyder-ide/spyder | spyder/utils/syntaxhighlighters.py | make_yaml_patterns | def make_yaml_patterns():
"Strongly inspired from sublime highlighter "
kw = any("keyword", [r":|>|-|\||\[|\]|[A-Za-z][\w\s\-\_ ]+(?=:)"])
links = any("normal", [r"#:[^\n]*"])
comment = any("comment", [r"#[^\n]*"])
number = any("number",
[r"\b[+-]?[0-9]+[lL]?\b",
r"\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b",
r"\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b"])
sqstring = r"(\b[rRuU])?'[^'\\\n]*(\\.[^'\\\n]*)*'?"
dqstring = r'(\b[rRuU])?"[^"\\\n]*(\\.[^"\\\n]*)*"?'
string = any("string", [sqstring, dqstring])
return "|".join([kw, string, number, links, comment,
any("SYNC", [r"\n"])]) | python | def make_yaml_patterns():
"Strongly inspired from sublime highlighter "
kw = any("keyword", [r":|>|-|\||\[|\]|[A-Za-z][\w\s\-\_ ]+(?=:)"])
links = any("normal", [r"#:[^\n]*"])
comment = any("comment", [r"#[^\n]*"])
number = any("number",
[r"\b[+-]?[0-9]+[lL]?\b",
r"\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b",
r"\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b"])
sqstring = r"(\b[rRuU])?'[^'\\\n]*(\\.[^'\\\n]*)*'?"
dqstring = r'(\b[rRuU])?"[^"\\\n]*(\\.[^"\\\n]*)*"?'
string = any("string", [sqstring, dqstring])
return "|".join([kw, string, number, links, comment,
any("SYNC", [r"\n"])]) | [
"def",
"make_yaml_patterns",
"(",
")",
":",
"kw",
"=",
"any",
"(",
"\"keyword\"",
",",
"[",
"r\":|>|-|\\||\\[|\\]|[A-Za-z][\\w\\s\\-\\_ ]+(?=:)\"",
"]",
")",
"links",
"=",
"any",
"(",
"\"normal\"",
",",
"[",
"r\"#:[^\\n]*\"",
"]",
")",
"comment",
"=",
"any",
"... | Strongly inspired from sublime highlighter | [
"Strongly",
"inspired",
"from",
"sublime",
"highlighter"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/syntaxhighlighters.py#L878-L891 |
31,418 | spyder-ide/spyder | spyder/utils/syntaxhighlighters.py | guess_pygments_highlighter | def guess_pygments_highlighter(filename):
"""Factory to generate syntax highlighter for the given filename.
If a syntax highlighter is not available for a particular file, this
function will attempt to generate one based on the lexers in Pygments. If
Pygments is not available or does not have an appropriate lexer, TextSH
will be returned instead.
"""
try:
from pygments.lexers import get_lexer_for_filename, get_lexer_by_name
except Exception:
return TextSH
root, ext = os.path.splitext(filename)
if ext in custom_extension_lexer_mapping:
try:
lexer = get_lexer_by_name(custom_extension_lexer_mapping[ext])
except Exception:
return TextSH
else:
try:
lexer = get_lexer_for_filename(filename)
except Exception:
return TextSH
class GuessedPygmentsSH(PygmentsSH):
_lexer = lexer
return GuessedPygmentsSH | python | def guess_pygments_highlighter(filename):
"""Factory to generate syntax highlighter for the given filename.
If a syntax highlighter is not available for a particular file, this
function will attempt to generate one based on the lexers in Pygments. If
Pygments is not available or does not have an appropriate lexer, TextSH
will be returned instead.
"""
try:
from pygments.lexers import get_lexer_for_filename, get_lexer_by_name
except Exception:
return TextSH
root, ext = os.path.splitext(filename)
if ext in custom_extension_lexer_mapping:
try:
lexer = get_lexer_by_name(custom_extension_lexer_mapping[ext])
except Exception:
return TextSH
else:
try:
lexer = get_lexer_for_filename(filename)
except Exception:
return TextSH
class GuessedPygmentsSH(PygmentsSH):
_lexer = lexer
return GuessedPygmentsSH | [
"def",
"guess_pygments_highlighter",
"(",
"filename",
")",
":",
"try",
":",
"from",
"pygments",
".",
"lexers",
"import",
"get_lexer_for_filename",
",",
"get_lexer_by_name",
"except",
"Exception",
":",
"return",
"TextSH",
"root",
",",
"ext",
"=",
"os",
".",
"path... | Factory to generate syntax highlighter for the given filename.
If a syntax highlighter is not available for a particular file, this
function will attempt to generate one based on the lexers in Pygments. If
Pygments is not available or does not have an appropriate lexer, TextSH
will be returned instead. | [
"Factory",
"to",
"generate",
"syntax",
"highlighter",
"for",
"the",
"given",
"filename",
".",
"If",
"a",
"syntax",
"highlighter",
"is",
"not",
"available",
"for",
"a",
"particular",
"file",
"this",
"function",
"will",
"attempt",
"to",
"generate",
"one",
"based... | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/syntaxhighlighters.py#L1233-L1259 |
31,419 | spyder-ide/spyder | spyder/utils/syntaxhighlighters.py | FortranSH.highlight_block | def highlight_block(self, text):
"""Implement highlight specific for Fortran."""
text = to_text_string(text)
self.setFormat(0, len(text), self.formats["normal"])
match = self.PROG.search(text)
index = 0
while match:
for key, value in list(match.groupdict().items()):
if value:
start, end = match.span(key)
index += end-start
self.setFormat(start, end-start, self.formats[key])
if value.lower() in ("subroutine", "module", "function"):
match1 = self.IDPROG.match(text, end)
if match1:
start1, end1 = match1.span(1)
self.setFormat(start1, end1-start1,
self.formats["definition"])
match = self.PROG.search(text, match.end())
self.highlight_spaces(text) | python | def highlight_block(self, text):
"""Implement highlight specific for Fortran."""
text = to_text_string(text)
self.setFormat(0, len(text), self.formats["normal"])
match = self.PROG.search(text)
index = 0
while match:
for key, value in list(match.groupdict().items()):
if value:
start, end = match.span(key)
index += end-start
self.setFormat(start, end-start, self.formats[key])
if value.lower() in ("subroutine", "module", "function"):
match1 = self.IDPROG.match(text, end)
if match1:
start1, end1 = match1.span(1)
self.setFormat(start1, end1-start1,
self.formats["definition"])
match = self.PROG.search(text, match.end())
self.highlight_spaces(text) | [
"def",
"highlight_block",
"(",
"self",
",",
"text",
")",
":",
"text",
"=",
"to_text_string",
"(",
"text",
")",
"self",
".",
"setFormat",
"(",
"0",
",",
"len",
"(",
"text",
")",
",",
"self",
".",
"formats",
"[",
"\"normal\"",
"]",
")",
"match",
"=",
... | Implement highlight specific for Fortran. | [
"Implement",
"highlight",
"specific",
"for",
"Fortran",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/syntaxhighlighters.py#L733-L755 |
31,420 | spyder-ide/spyder | spyder/utils/syntaxhighlighters.py | Fortran77SH.highlight_block | def highlight_block(self, text):
"""Implement highlight specific for Fortran77."""
text = to_text_string(text)
if text.startswith(("c", "C")):
self.setFormat(0, len(text), self.formats["comment"])
self.highlight_spaces(text)
else:
FortranSH.highlight_block(self, text)
self.setFormat(0, 5, self.formats["comment"])
self.setFormat(73, max([73, len(text)]),
self.formats["comment"]) | python | def highlight_block(self, text):
"""Implement highlight specific for Fortran77."""
text = to_text_string(text)
if text.startswith(("c", "C")):
self.setFormat(0, len(text), self.formats["comment"])
self.highlight_spaces(text)
else:
FortranSH.highlight_block(self, text)
self.setFormat(0, 5, self.formats["comment"])
self.setFormat(73, max([73, len(text)]),
self.formats["comment"]) | [
"def",
"highlight_block",
"(",
"self",
",",
"text",
")",
":",
"text",
"=",
"to_text_string",
"(",
"text",
")",
"if",
"text",
".",
"startswith",
"(",
"(",
"\"c\"",
",",
"\"C\"",
")",
")",
":",
"self",
".",
"setFormat",
"(",
"0",
",",
"len",
"(",
"te... | Implement highlight specific for Fortran77. | [
"Implement",
"highlight",
"specific",
"for",
"Fortran77",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/syntaxhighlighters.py#L759-L769 |
31,421 | spyder-ide/spyder | spyder/utils/syntaxhighlighters.py | BaseWebSH.highlight_block | def highlight_block(self, text):
"""Implement highlight specific for CSS and HTML."""
text = to_text_string(text)
previous_state = tbh.get_state(self.currentBlock().previous())
if previous_state == self.COMMENT:
self.setFormat(0, len(text), self.formats["comment"])
else:
previous_state = self.NORMAL
self.setFormat(0, len(text), self.formats["normal"])
tbh.set_state(self.currentBlock(), previous_state)
match = self.PROG.search(text)
match_count = 0
n_characters = len(text)
# There should never be more matches than characters in the text.
while match and match_count < n_characters:
match_dict = match.groupdict()
for key, value in list(match_dict.items()):
if value:
start, end = match.span(key)
if previous_state == self.COMMENT:
if key == "multiline_comment_end":
tbh.set_state(self.currentBlock(), self.NORMAL)
self.setFormat(end, len(text),
self.formats["normal"])
else:
tbh.set_state(self.currentBlock(), self.COMMENT)
self.setFormat(0, len(text),
self.formats["comment"])
else:
if key == "multiline_comment_start":
tbh.set_state(self.currentBlock(), self.COMMENT)
self.setFormat(start, len(text),
self.formats["comment"])
else:
tbh.set_state(self.currentBlock(), self.NORMAL)
try:
self.setFormat(start, end-start,
self.formats[key])
except KeyError:
# happens with unmatched end-of-comment;
# see issue 1462
pass
match = self.PROG.search(text, match.end())
match_count += 1
self.highlight_spaces(text) | python | def highlight_block(self, text):
"""Implement highlight specific for CSS and HTML."""
text = to_text_string(text)
previous_state = tbh.get_state(self.currentBlock().previous())
if previous_state == self.COMMENT:
self.setFormat(0, len(text), self.formats["comment"])
else:
previous_state = self.NORMAL
self.setFormat(0, len(text), self.formats["normal"])
tbh.set_state(self.currentBlock(), previous_state)
match = self.PROG.search(text)
match_count = 0
n_characters = len(text)
# There should never be more matches than characters in the text.
while match and match_count < n_characters:
match_dict = match.groupdict()
for key, value in list(match_dict.items()):
if value:
start, end = match.span(key)
if previous_state == self.COMMENT:
if key == "multiline_comment_end":
tbh.set_state(self.currentBlock(), self.NORMAL)
self.setFormat(end, len(text),
self.formats["normal"])
else:
tbh.set_state(self.currentBlock(), self.COMMENT)
self.setFormat(0, len(text),
self.formats["comment"])
else:
if key == "multiline_comment_start":
tbh.set_state(self.currentBlock(), self.COMMENT)
self.setFormat(start, len(text),
self.formats["comment"])
else:
tbh.set_state(self.currentBlock(), self.NORMAL)
try:
self.setFormat(start, end-start,
self.formats[key])
except KeyError:
# happens with unmatched end-of-comment;
# see issue 1462
pass
match = self.PROG.search(text, match.end())
match_count += 1
self.highlight_spaces(text) | [
"def",
"highlight_block",
"(",
"self",
",",
"text",
")",
":",
"text",
"=",
"to_text_string",
"(",
"text",
")",
"previous_state",
"=",
"tbh",
".",
"get_state",
"(",
"self",
".",
"currentBlock",
"(",
")",
".",
"previous",
"(",
")",
")",
"if",
"previous_sta... | Implement highlight specific for CSS and HTML. | [
"Implement",
"highlight",
"specific",
"for",
"CSS",
"and",
"HTML",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/syntaxhighlighters.py#L911-L960 |
31,422 | spyder-ide/spyder | spyder/utils/syntaxhighlighters.py | PygmentsSH.make_charlist | def make_charlist(self):
"""Parses the complete text and stores format for each character."""
def worker_output(worker, output, error):
"""Worker finished callback."""
self._charlist = output
if error is None and output:
self._allow_highlight = True
self.rehighlight()
self._allow_highlight = False
text = to_text_string(self.document().toPlainText())
tokens = self._lexer.get_tokens(text)
# Before starting a new worker process make sure to end previous
# incarnations
self._worker_manager.terminate_all()
worker = self._worker_manager.create_python_worker(
self._make_charlist,
tokens,
self._tokmap,
self.formats,
)
worker.sig_finished.connect(worker_output)
worker.start() | python | def make_charlist(self):
"""Parses the complete text and stores format for each character."""
def worker_output(worker, output, error):
"""Worker finished callback."""
self._charlist = output
if error is None and output:
self._allow_highlight = True
self.rehighlight()
self._allow_highlight = False
text = to_text_string(self.document().toPlainText())
tokens = self._lexer.get_tokens(text)
# Before starting a new worker process make sure to end previous
# incarnations
self._worker_manager.terminate_all()
worker = self._worker_manager.create_python_worker(
self._make_charlist,
tokens,
self._tokmap,
self.formats,
)
worker.sig_finished.connect(worker_output)
worker.start() | [
"def",
"make_charlist",
"(",
"self",
")",
":",
"def",
"worker_output",
"(",
"worker",
",",
"output",
",",
"error",
")",
":",
"\"\"\"Worker finished callback.\"\"\"",
"self",
".",
"_charlist",
"=",
"output",
"if",
"error",
"is",
"None",
"and",
"output",
":",
... | Parses the complete text and stores format for each character. | [
"Parses",
"the",
"complete",
"text",
"and",
"stores",
"format",
"for",
"each",
"character",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/syntaxhighlighters.py#L1161-L1186 |
31,423 | spyder-ide/spyder | spyder/utils/syntaxhighlighters.py | PygmentsSH._make_charlist | def _make_charlist(self, tokens, tokmap, formats):
"""
Parses the complete text and stores format for each character.
Uses the attached lexer to parse into a list of tokens and Pygments
token types. Then breaks tokens into individual letters, each with a
Spyder token type attached. Stores this list as self._charlist.
It's attached to the contentsChange signal of the parent QTextDocument
so that the charlist is updated whenever the document changes.
"""
def _get_fmt(typ):
"""Get the Spyder format code for the given Pygments token type."""
# Exact matches first
if typ in tokmap:
return tokmap[typ]
# Partial (parent-> child) matches
for key, val in tokmap.items():
if typ in key: # Checks if typ is a subtype of key.
return val
return 'normal'
charlist = []
for typ, token in tokens:
fmt = formats[_get_fmt(typ)]
for letter in token:
charlist.append((fmt, letter))
return charlist | python | def _make_charlist(self, tokens, tokmap, formats):
"""
Parses the complete text and stores format for each character.
Uses the attached lexer to parse into a list of tokens and Pygments
token types. Then breaks tokens into individual letters, each with a
Spyder token type attached. Stores this list as self._charlist.
It's attached to the contentsChange signal of the parent QTextDocument
so that the charlist is updated whenever the document changes.
"""
def _get_fmt(typ):
"""Get the Spyder format code for the given Pygments token type."""
# Exact matches first
if typ in tokmap:
return tokmap[typ]
# Partial (parent-> child) matches
for key, val in tokmap.items():
if typ in key: # Checks if typ is a subtype of key.
return val
return 'normal'
charlist = []
for typ, token in tokens:
fmt = formats[_get_fmt(typ)]
for letter in token:
charlist.append((fmt, letter))
return charlist | [
"def",
"_make_charlist",
"(",
"self",
",",
"tokens",
",",
"tokmap",
",",
"formats",
")",
":",
"def",
"_get_fmt",
"(",
"typ",
")",
":",
"\"\"\"Get the Spyder format code for the given Pygments token type.\"\"\"",
"# Exact matches first\r",
"if",
"typ",
"in",
"tokmap",
... | Parses the complete text and stores format for each character.
Uses the attached lexer to parse into a list of tokens and Pygments
token types. Then breaks tokens into individual letters, each with a
Spyder token type attached. Stores this list as self._charlist.
It's attached to the contentsChange signal of the parent QTextDocument
so that the charlist is updated whenever the document changes. | [
"Parses",
"the",
"complete",
"text",
"and",
"stores",
"format",
"for",
"each",
"character",
".",
"Uses",
"the",
"attached",
"lexer",
"to",
"parse",
"into",
"a",
"list",
"of",
"tokens",
"and",
"Pygments",
"token",
"types",
".",
"Then",
"breaks",
"tokens",
"... | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/syntaxhighlighters.py#L1188-L1218 |
31,424 | spyder-ide/spyder | spyder/utils/syntaxhighlighters.py | PygmentsSH.highlightBlock | def highlightBlock(self, text):
""" Actually highlight the block"""
# Note that an undefined blockstate is equal to -1, so the first block
# will have the correct behaviour of starting at 0.
if self._allow_highlight:
start = self.previousBlockState() + 1
end = start + len(text)
for i, (fmt, letter) in enumerate(self._charlist[start:end]):
self.setFormat(i, 1, fmt)
self.setCurrentBlockState(end)
self.highlight_spaces(text) | python | def highlightBlock(self, text):
""" Actually highlight the block"""
# Note that an undefined blockstate is equal to -1, so the first block
# will have the correct behaviour of starting at 0.
if self._allow_highlight:
start = self.previousBlockState() + 1
end = start + len(text)
for i, (fmt, letter) in enumerate(self._charlist[start:end]):
self.setFormat(i, 1, fmt)
self.setCurrentBlockState(end)
self.highlight_spaces(text) | [
"def",
"highlightBlock",
"(",
"self",
",",
"text",
")",
":",
"# Note that an undefined blockstate is equal to -1, so the first block\r",
"# will have the correct behaviour of starting at 0.\r",
"if",
"self",
".",
"_allow_highlight",
":",
"start",
"=",
"self",
".",
"previousBloc... | Actually highlight the block | [
"Actually",
"highlight",
"the",
"block"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/syntaxhighlighters.py#L1220-L1230 |
31,425 | spyder-ide/spyder | spyder/utils/introspection/module_completion.py | get_submodules | def get_submodules(mod):
"""Get all submodules of a given module"""
def catch_exceptions(module):
pass
try:
m = __import__(mod)
submodules = [mod]
submods = pkgutil.walk_packages(m.__path__, m.__name__ + '.',
catch_exceptions)
for sm in submods:
sm_name = sm[1]
submodules.append(sm_name)
except ImportError:
return []
except:
return [mod]
return submodules | python | def get_submodules(mod):
"""Get all submodules of a given module"""
def catch_exceptions(module):
pass
try:
m = __import__(mod)
submodules = [mod]
submods = pkgutil.walk_packages(m.__path__, m.__name__ + '.',
catch_exceptions)
for sm in submods:
sm_name = sm[1]
submodules.append(sm_name)
except ImportError:
return []
except:
return [mod]
return submodules | [
"def",
"get_submodules",
"(",
"mod",
")",
":",
"def",
"catch_exceptions",
"(",
"module",
")",
":",
"pass",
"try",
":",
"m",
"=",
"__import__",
"(",
"mod",
")",
"submodules",
"=",
"[",
"mod",
"]",
"submods",
"=",
"pkgutil",
".",
"walk_packages",
"(",
"m... | Get all submodules of a given module | [
"Get",
"all",
"submodules",
"of",
"a",
"given",
"module"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/introspection/module_completion.py#L34-L51 |
31,426 | spyder-ide/spyder | spyder/utils/introspection/module_completion.py | get_preferred_submodules | def get_preferred_submodules():
"""
Get all submodules of the main scientific modules and others of our
interest
"""
# Path to the modules database
modules_path = get_conf_path('db')
# Modules database
modules_db = PickleShareDB(modules_path)
if 'submodules' in modules_db:
return modules_db['submodules']
submodules = []
for m in PREFERRED_MODULES:
submods = get_submodules(m)
submodules += submods
modules_db['submodules'] = submodules
return submodules | python | def get_preferred_submodules():
"""
Get all submodules of the main scientific modules and others of our
interest
"""
# Path to the modules database
modules_path = get_conf_path('db')
# Modules database
modules_db = PickleShareDB(modules_path)
if 'submodules' in modules_db:
return modules_db['submodules']
submodules = []
for m in PREFERRED_MODULES:
submods = get_submodules(m)
submodules += submods
modules_db['submodules'] = submodules
return submodules | [
"def",
"get_preferred_submodules",
"(",
")",
":",
"# Path to the modules database\r",
"modules_path",
"=",
"get_conf_path",
"(",
"'db'",
")",
"# Modules database\r",
"modules_db",
"=",
"PickleShareDB",
"(",
"modules_path",
")",
"if",
"'submodules'",
"in",
"modules_db",
... | Get all submodules of the main scientific modules and others of our
interest | [
"Get",
"all",
"submodules",
"of",
"the",
"main",
"scientific",
"modules",
"and",
"others",
"of",
"our",
"interest"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/introspection/module_completion.py#L54-L75 |
31,427 | spyder-ide/spyder | spyder/config/base.py | use_dev_config_dir | def use_dev_config_dir(use_dev_config_dir=USE_DEV_CONFIG_DIR):
"""Return whether the dev configuration directory should used."""
if use_dev_config_dir is not None:
if use_dev_config_dir.lower() in {'false', '0'}:
use_dev_config_dir = False
else:
use_dev_config_dir = DEV or not is_stable_version(__version__)
return use_dev_config_dir | python | def use_dev_config_dir(use_dev_config_dir=USE_DEV_CONFIG_DIR):
"""Return whether the dev configuration directory should used."""
if use_dev_config_dir is not None:
if use_dev_config_dir.lower() in {'false', '0'}:
use_dev_config_dir = False
else:
use_dev_config_dir = DEV or not is_stable_version(__version__)
return use_dev_config_dir | [
"def",
"use_dev_config_dir",
"(",
"use_dev_config_dir",
"=",
"USE_DEV_CONFIG_DIR",
")",
":",
"if",
"use_dev_config_dir",
"is",
"not",
"None",
":",
"if",
"use_dev_config_dir",
".",
"lower",
"(",
")",
"in",
"{",
"'false'",
",",
"'0'",
"}",
":",
"use_dev_config_dir... | Return whether the dev configuration directory should used. | [
"Return",
"whether",
"the",
"dev",
"configuration",
"directory",
"should",
"used",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/base.py#L77-L84 |
31,428 | spyder-ide/spyder | spyder/config/base.py | debug_print | def debug_print(*message):
"""Output debug messages to stdout"""
warnings.warn("debug_print is deprecated; use the logging module instead.")
if get_debug_level():
ss = STDOUT
if PY3:
# This is needed after restarting and using debug_print
for m in message:
ss.buffer.write(str(m).encode('utf-8'))
print('', file=ss)
else:
print(*message, file=ss) | python | def debug_print(*message):
"""Output debug messages to stdout"""
warnings.warn("debug_print is deprecated; use the logging module instead.")
if get_debug_level():
ss = STDOUT
if PY3:
# This is needed after restarting and using debug_print
for m in message:
ss.buffer.write(str(m).encode('utf-8'))
print('', file=ss)
else:
print(*message, file=ss) | [
"def",
"debug_print",
"(",
"*",
"message",
")",
":",
"warnings",
".",
"warn",
"(",
"\"debug_print is deprecated; use the logging module instead.\"",
")",
"if",
"get_debug_level",
"(",
")",
":",
"ss",
"=",
"STDOUT",
"if",
"PY3",
":",
"# This is needed after restarting ... | Output debug messages to stdout | [
"Output",
"debug",
"messages",
"to",
"stdout"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/base.py#L102-L113 |
31,429 | spyder-ide/spyder | spyder/config/base.py | get_home_dir | def get_home_dir():
"""
Return user home directory
"""
try:
# expanduser() returns a raw byte string which needs to be
# decoded with the codec that the OS is using to represent
# file paths.
path = encoding.to_unicode_from_fs(osp.expanduser('~'))
except Exception:
path = ''
if osp.isdir(path):
return path
else:
# Get home from alternative locations
for env_var in ('HOME', 'USERPROFILE', 'TMP'):
# os.environ.get() returns a raw byte string which needs to be
# decoded with the codec that the OS is using to represent
# environment variables.
path = encoding.to_unicode_from_fs(os.environ.get(env_var, ''))
if osp.isdir(path):
return path
else:
path = ''
if not path:
raise RuntimeError('Please set the environment variable HOME to '
'your user/home directory path so Spyder can '
'start properly.') | python | def get_home_dir():
"""
Return user home directory
"""
try:
# expanduser() returns a raw byte string which needs to be
# decoded with the codec that the OS is using to represent
# file paths.
path = encoding.to_unicode_from_fs(osp.expanduser('~'))
except Exception:
path = ''
if osp.isdir(path):
return path
else:
# Get home from alternative locations
for env_var in ('HOME', 'USERPROFILE', 'TMP'):
# os.environ.get() returns a raw byte string which needs to be
# decoded with the codec that the OS is using to represent
# environment variables.
path = encoding.to_unicode_from_fs(os.environ.get(env_var, ''))
if osp.isdir(path):
return path
else:
path = ''
if not path:
raise RuntimeError('Please set the environment variable HOME to '
'your user/home directory path so Spyder can '
'start properly.') | [
"def",
"get_home_dir",
"(",
")",
":",
"try",
":",
"# expanduser() returns a raw byte string which needs to be\r",
"# decoded with the codec that the OS is using to represent\r",
"# file paths.\r",
"path",
"=",
"encoding",
".",
"to_unicode_from_fs",
"(",
"osp",
".",
"expanduser",
... | Return user home directory | [
"Return",
"user",
"home",
"directory"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/base.py#L145-L174 |
31,430 | spyder-ide/spyder | spyder/config/base.py | get_clean_conf_dir | def get_clean_conf_dir():
"""
Return the path to a temp clean configuration dir, for tests and safe mode.
"""
if sys.platform.startswith("win"):
current_user = ''
else:
current_user = '-' + str(getpass.getuser())
conf_dir = osp.join(str(tempfile.gettempdir()),
'pytest-spyder{0!s}'.format(current_user),
SUBFOLDER)
return conf_dir | python | def get_clean_conf_dir():
"""
Return the path to a temp clean configuration dir, for tests and safe mode.
"""
if sys.platform.startswith("win"):
current_user = ''
else:
current_user = '-' + str(getpass.getuser())
conf_dir = osp.join(str(tempfile.gettempdir()),
'pytest-spyder{0!s}'.format(current_user),
SUBFOLDER)
return conf_dir | [
"def",
"get_clean_conf_dir",
"(",
")",
":",
"if",
"sys",
".",
"platform",
".",
"startswith",
"(",
"\"win\"",
")",
":",
"current_user",
"=",
"''",
"else",
":",
"current_user",
"=",
"'-'",
"+",
"str",
"(",
"getpass",
".",
"getuser",
"(",
")",
")",
"conf_... | Return the path to a temp clean configuration dir, for tests and safe mode. | [
"Return",
"the",
"path",
"to",
"a",
"temp",
"clean",
"configuration",
"dir",
"for",
"tests",
"and",
"safe",
"mode",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/base.py#L177-L189 |
31,431 | spyder-ide/spyder | spyder/config/base.py | get_conf_path | def get_conf_path(filename=None):
"""Return absolute path to the config file with the specified filename."""
# Define conf_dir
if running_under_pytest() or SAFE_MODE:
# Use clean config dir if running tests or the user requests it.
conf_dir = get_clean_conf_dir()
elif sys.platform.startswith('linux'):
# This makes us follow the XDG standard to save our settings
# on Linux, as it was requested on Issue 2629
xdg_config_home = os.environ.get('XDG_CONFIG_HOME', '')
if not xdg_config_home:
xdg_config_home = osp.join(get_home_dir(), '.config')
if not osp.isdir(xdg_config_home):
os.makedirs(xdg_config_home)
conf_dir = osp.join(xdg_config_home, SUBFOLDER)
else:
conf_dir = osp.join(get_home_dir(), SUBFOLDER)
# Create conf_dir
if not osp.isdir(conf_dir):
if running_under_pytest() or SAFE_MODE:
os.makedirs(conf_dir)
else:
os.mkdir(conf_dir)
if filename is None:
return conf_dir
else:
return osp.join(conf_dir, filename) | python | def get_conf_path(filename=None):
"""Return absolute path to the config file with the specified filename."""
# Define conf_dir
if running_under_pytest() or SAFE_MODE:
# Use clean config dir if running tests or the user requests it.
conf_dir = get_clean_conf_dir()
elif sys.platform.startswith('linux'):
# This makes us follow the XDG standard to save our settings
# on Linux, as it was requested on Issue 2629
xdg_config_home = os.environ.get('XDG_CONFIG_HOME', '')
if not xdg_config_home:
xdg_config_home = osp.join(get_home_dir(), '.config')
if not osp.isdir(xdg_config_home):
os.makedirs(xdg_config_home)
conf_dir = osp.join(xdg_config_home, SUBFOLDER)
else:
conf_dir = osp.join(get_home_dir(), SUBFOLDER)
# Create conf_dir
if not osp.isdir(conf_dir):
if running_under_pytest() or SAFE_MODE:
os.makedirs(conf_dir)
else:
os.mkdir(conf_dir)
if filename is None:
return conf_dir
else:
return osp.join(conf_dir, filename) | [
"def",
"get_conf_path",
"(",
"filename",
"=",
"None",
")",
":",
"# Define conf_dir\r",
"if",
"running_under_pytest",
"(",
")",
"or",
"SAFE_MODE",
":",
"# Use clean config dir if running tests or the user requests it.\r",
"conf_dir",
"=",
"get_clean_conf_dir",
"(",
")",
"e... | Return absolute path to the config file with the specified filename. | [
"Return",
"absolute",
"path",
"to",
"the",
"config",
"file",
"with",
"the",
"specified",
"filename",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/base.py#L192-L219 |
31,432 | spyder-ide/spyder | spyder/config/base.py | get_image_path | def get_image_path(name, default="not_found.png"):
"""Return image absolute path"""
for img_path in IMG_PATH:
full_path = osp.join(img_path, name)
if osp.isfile(full_path):
return osp.abspath(full_path)
if default is not None:
img_path = osp.join(get_module_path('spyder'), 'images')
return osp.abspath(osp.join(img_path, default)) | python | def get_image_path(name, default="not_found.png"):
"""Return image absolute path"""
for img_path in IMG_PATH:
full_path = osp.join(img_path, name)
if osp.isfile(full_path):
return osp.abspath(full_path)
if default is not None:
img_path = osp.join(get_module_path('spyder'), 'images')
return osp.abspath(osp.join(img_path, default)) | [
"def",
"get_image_path",
"(",
"name",
",",
"default",
"=",
"\"not_found.png\"",
")",
":",
"for",
"img_path",
"in",
"IMG_PATH",
":",
"full_path",
"=",
"osp",
".",
"join",
"(",
"img_path",
",",
"name",
")",
"if",
"osp",
".",
"isfile",
"(",
"full_path",
")"... | Return image absolute path | [
"Return",
"image",
"absolute",
"path"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/base.py#L289-L297 |
31,433 | spyder-ide/spyder | spyder/config/base.py | get_available_translations | def get_available_translations():
"""
List available translations for spyder based on the folders found in the
locale folder. This function checks if LANGUAGE_CODES contain the same
information that is found in the 'locale' folder to ensure that when a new
language is added, LANGUAGE_CODES is updated.
"""
locale_path = get_module_data_path("spyder", relpath="locale",
attr_name='LOCALEPATH')
listdir = os.listdir(locale_path)
langs = [d for d in listdir if osp.isdir(osp.join(locale_path, d))]
langs = [DEFAULT_LANGUAGE] + langs
# Remove disabled languages
langs = list( set(langs) - set(DISABLED_LANGUAGES) )
# Check that there is a language code available in case a new translation
# is added, to ensure LANGUAGE_CODES is updated.
for lang in langs:
if lang not in LANGUAGE_CODES:
error = ('Update LANGUAGE_CODES (inside config/base.py) if a new '
'translation has been added to Spyder')
print(error) # spyder: test-skip
return ['en']
return langs | python | def get_available_translations():
"""
List available translations for spyder based on the folders found in the
locale folder. This function checks if LANGUAGE_CODES contain the same
information that is found in the 'locale' folder to ensure that when a new
language is added, LANGUAGE_CODES is updated.
"""
locale_path = get_module_data_path("spyder", relpath="locale",
attr_name='LOCALEPATH')
listdir = os.listdir(locale_path)
langs = [d for d in listdir if osp.isdir(osp.join(locale_path, d))]
langs = [DEFAULT_LANGUAGE] + langs
# Remove disabled languages
langs = list( set(langs) - set(DISABLED_LANGUAGES) )
# Check that there is a language code available in case a new translation
# is added, to ensure LANGUAGE_CODES is updated.
for lang in langs:
if lang not in LANGUAGE_CODES:
error = ('Update LANGUAGE_CODES (inside config/base.py) if a new '
'translation has been added to Spyder')
print(error) # spyder: test-skip
return ['en']
return langs | [
"def",
"get_available_translations",
"(",
")",
":",
"locale_path",
"=",
"get_module_data_path",
"(",
"\"spyder\"",
",",
"relpath",
"=",
"\"locale\"",
",",
"attr_name",
"=",
"'LOCALEPATH'",
")",
"listdir",
"=",
"os",
".",
"listdir",
"(",
"locale_path",
")",
"lang... | List available translations for spyder based on the folders found in the
locale folder. This function checks if LANGUAGE_CODES contain the same
information that is found in the 'locale' folder to ensure that when a new
language is added, LANGUAGE_CODES is updated. | [
"List",
"available",
"translations",
"for",
"spyder",
"based",
"on",
"the",
"folders",
"found",
"in",
"the",
"locale",
"folder",
".",
"This",
"function",
"checks",
"if",
"LANGUAGE_CODES",
"contain",
"the",
"same",
"information",
"that",
"is",
"found",
"in",
"t... | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/base.py#L322-L346 |
31,434 | spyder-ide/spyder | spyder/config/base.py | load_lang_conf | def load_lang_conf():
"""
Load language setting from language config file if it exists, otherwise
try to use the local settings if Spyder provides a translation, or
return the default if no translation provided.
"""
if osp.isfile(LANG_FILE):
with open(LANG_FILE, 'r') as f:
lang = f.read()
else:
lang = get_interface_language()
save_lang_conf(lang)
# Save language again if it's been disabled
if lang.strip('\n') in DISABLED_LANGUAGES:
lang = DEFAULT_LANGUAGE
save_lang_conf(lang)
return lang | python | def load_lang_conf():
"""
Load language setting from language config file if it exists, otherwise
try to use the local settings if Spyder provides a translation, or
return the default if no translation provided.
"""
if osp.isfile(LANG_FILE):
with open(LANG_FILE, 'r') as f:
lang = f.read()
else:
lang = get_interface_language()
save_lang_conf(lang)
# Save language again if it's been disabled
if lang.strip('\n') in DISABLED_LANGUAGES:
lang = DEFAULT_LANGUAGE
save_lang_conf(lang)
return lang | [
"def",
"load_lang_conf",
"(",
")",
":",
"if",
"osp",
".",
"isfile",
"(",
"LANG_FILE",
")",
":",
"with",
"open",
"(",
"LANG_FILE",
",",
"'r'",
")",
"as",
"f",
":",
"lang",
"=",
"f",
".",
"read",
"(",
")",
"else",
":",
"lang",
"=",
"get_interface_lan... | Load language setting from language config file if it exists, otherwise
try to use the local settings if Spyder provides a translation, or
return the default if no translation provided. | [
"Load",
"language",
"setting",
"from",
"language",
"config",
"file",
"if",
"it",
"exists",
"otherwise",
"try",
"to",
"use",
"the",
"local",
"settings",
"if",
"Spyder",
"provides",
"a",
"translation",
"or",
"return",
"the",
"default",
"if",
"no",
"translation",... | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/base.py#L401-L419 |
31,435 | spyder-ide/spyder | spyder/config/base.py | reset_config_files | def reset_config_files():
"""Remove all config files"""
print("*** Reset Spyder settings to defaults ***", file=STDERR)
for fname in SAVED_CONFIG_FILES:
cfg_fname = get_conf_path(fname)
if osp.isfile(cfg_fname) or osp.islink(cfg_fname):
os.remove(cfg_fname)
elif osp.isdir(cfg_fname):
shutil.rmtree(cfg_fname)
else:
continue
print("removing:", cfg_fname, file=STDERR) | python | def reset_config_files():
"""Remove all config files"""
print("*** Reset Spyder settings to defaults ***", file=STDERR)
for fname in SAVED_CONFIG_FILES:
cfg_fname = get_conf_path(fname)
if osp.isfile(cfg_fname) or osp.islink(cfg_fname):
os.remove(cfg_fname)
elif osp.isdir(cfg_fname):
shutil.rmtree(cfg_fname)
else:
continue
print("removing:", cfg_fname, file=STDERR) | [
"def",
"reset_config_files",
"(",
")",
":",
"print",
"(",
"\"*** Reset Spyder settings to defaults ***\"",
",",
"file",
"=",
"STDERR",
")",
"for",
"fname",
"in",
"SAVED_CONFIG_FILES",
":",
"cfg_fname",
"=",
"get_conf_path",
"(",
"fname",
")",
"if",
"osp",
".",
"... | Remove all config files | [
"Remove",
"all",
"config",
"files"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/base.py#L512-L523 |
31,436 | spyder-ide/spyder | spyder/plugins/explorer/plugin.py | Explorer.refresh_plugin | def refresh_plugin(self, new_path=None, force_current=True):
"""Refresh explorer widget"""
self.fileexplorer.treewidget.update_history(new_path)
self.fileexplorer.treewidget.refresh(new_path,
force_current=force_current) | python | def refresh_plugin(self, new_path=None, force_current=True):
"""Refresh explorer widget"""
self.fileexplorer.treewidget.update_history(new_path)
self.fileexplorer.treewidget.refresh(new_path,
force_current=force_current) | [
"def",
"refresh_plugin",
"(",
"self",
",",
"new_path",
"=",
"None",
",",
"force_current",
"=",
"True",
")",
":",
"self",
".",
"fileexplorer",
".",
"treewidget",
".",
"update_history",
"(",
"new_path",
")",
"self",
".",
"fileexplorer",
".",
"treewidget",
".",... | Refresh explorer widget | [
"Refresh",
"explorer",
"widget"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/plugin.py#L108-L112 |
31,437 | spyder-ide/spyder | spyder/py3compat.py | is_type_text_string | def is_type_text_string(obj):
"""Return True if `obj` is type text string, False if it is anything else,
like an instance of a class that extends the basestring class."""
if PY2:
# Python 2
return type(obj) in [str, unicode]
else:
# Python 3
return type(obj) in [str, bytes] | python | def is_type_text_string(obj):
"""Return True if `obj` is type text string, False if it is anything else,
like an instance of a class that extends the basestring class."""
if PY2:
# Python 2
return type(obj) in [str, unicode]
else:
# Python 3
return type(obj) in [str, bytes] | [
"def",
"is_type_text_string",
"(",
"obj",
")",
":",
"if",
"PY2",
":",
"# Python 2\r",
"return",
"type",
"(",
"obj",
")",
"in",
"[",
"str",
",",
"unicode",
"]",
"else",
":",
"# Python 3\r",
"return",
"type",
"(",
"obj",
")",
"in",
"[",
"str",
",",
"by... | Return True if `obj` is type text string, False if it is anything else,
like an instance of a class that extends the basestring class. | [
"Return",
"True",
"if",
"obj",
"is",
"type",
"text",
"string",
"False",
"if",
"it",
"is",
"anything",
"else",
"like",
"an",
"instance",
"of",
"a",
"class",
"that",
"extends",
"the",
"basestring",
"class",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/py3compat.py#L87-L95 |
31,438 | spyder-ide/spyder | spyder/plugins/onlinehelp/onlinehelp.py | OnlineHelp.get_focus_widget | def get_focus_widget(self):
"""
Return the widget to give focus to when
this plugin's dockwidget is raised on top-level
"""
self.pydocbrowser.url_combo.lineEdit().selectAll()
return self.pydocbrowser.url_combo | python | def get_focus_widget(self):
"""
Return the widget to give focus to when
this plugin's dockwidget is raised on top-level
"""
self.pydocbrowser.url_combo.lineEdit().selectAll()
return self.pydocbrowser.url_combo | [
"def",
"get_focus_widget",
"(",
"self",
")",
":",
"self",
".",
"pydocbrowser",
".",
"url_combo",
".",
"lineEdit",
"(",
")",
".",
"selectAll",
"(",
")",
"return",
"self",
".",
"pydocbrowser",
".",
"url_combo"
] | Return the widget to give focus to when
this plugin's dockwidget is raised on top-level | [
"Return",
"the",
"widget",
"to",
"give",
"focus",
"to",
"when",
"this",
"plugin",
"s",
"dockwidget",
"is",
"raised",
"on",
"top",
"-",
"level"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/onlinehelp/onlinehelp.py#L75-L81 |
31,439 | spyder-ide/spyder | spyder/widgets/pathmanager.py | PathManager.update_list | def update_list(self):
"""Update path list"""
self.listwidget.clear()
for name in self.pathlist+self.ro_pathlist:
item = QListWidgetItem(name)
item.setIcon(ima.icon('DirClosedIcon'))
if name in self.ro_pathlist:
item.setFlags(Qt.NoItemFlags | Qt.ItemIsUserCheckable)
item.setCheckState(Qt.Checked)
elif name in self.not_active_pathlist:
item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
item.setCheckState(Qt.Unchecked)
else:
item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
item.setCheckState(Qt.Checked)
self.listwidget.addItem(item)
self.refresh() | python | def update_list(self):
"""Update path list"""
self.listwidget.clear()
for name in self.pathlist+self.ro_pathlist:
item = QListWidgetItem(name)
item.setIcon(ima.icon('DirClosedIcon'))
if name in self.ro_pathlist:
item.setFlags(Qt.NoItemFlags | Qt.ItemIsUserCheckable)
item.setCheckState(Qt.Checked)
elif name in self.not_active_pathlist:
item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
item.setCheckState(Qt.Unchecked)
else:
item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
item.setCheckState(Qt.Checked)
self.listwidget.addItem(item)
self.refresh() | [
"def",
"update_list",
"(",
"self",
")",
":",
"self",
".",
"listwidget",
".",
"clear",
"(",
")",
"for",
"name",
"in",
"self",
".",
"pathlist",
"+",
"self",
".",
"ro_pathlist",
":",
"item",
"=",
"QListWidgetItem",
"(",
"name",
")",
"item",
".",
"setIcon"... | Update path list | [
"Update",
"path",
"list"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/pathmanager.py#L204-L220 |
31,440 | spyder-ide/spyder | spyder/widgets/tabs.py | EditTabNamePopup.eventFilter | def eventFilter(self, widget, event):
"""Catch clicks outside the object and ESC key press."""
if ((event.type() == QEvent.MouseButtonPress and
not self.geometry().contains(event.globalPos())) or
(event.type() == QEvent.KeyPress and
event.key() == Qt.Key_Escape)):
# Exits editing
self.hide()
self.setFocus(False)
return True
# Event is not interessant, raise to parent
return QLineEdit.eventFilter(self, widget, event) | python | def eventFilter(self, widget, event):
"""Catch clicks outside the object and ESC key press."""
if ((event.type() == QEvent.MouseButtonPress and
not self.geometry().contains(event.globalPos())) or
(event.type() == QEvent.KeyPress and
event.key() == Qt.Key_Escape)):
# Exits editing
self.hide()
self.setFocus(False)
return True
# Event is not interessant, raise to parent
return QLineEdit.eventFilter(self, widget, event) | [
"def",
"eventFilter",
"(",
"self",
",",
"widget",
",",
"event",
")",
":",
"if",
"(",
"(",
"event",
".",
"type",
"(",
")",
"==",
"QEvent",
".",
"MouseButtonPress",
"and",
"not",
"self",
".",
"geometry",
"(",
")",
".",
"contains",
"(",
"event",
".",
... | Catch clicks outside the object and ESC key press. | [
"Catch",
"clicks",
"outside",
"the",
"object",
"and",
"ESC",
"key",
"press",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/tabs.py#L77-L89 |
31,441 | spyder-ide/spyder | spyder/widgets/tabs.py | EditTabNamePopup.edit_tab | def edit_tab(self, index):
"""Activate the edit tab."""
# Sets focus, shows cursor
self.setFocus(True)
# Updates tab index
self.tab_index = index
# Gets tab size and shrinks to avoid overlapping tab borders
rect = self.main.tabRect(index)
rect.adjust(1, 1, -2, -1)
# Sets size
self.setFixedSize(rect.size())
# Places on top of the tab
self.move(self.main.mapToGlobal(rect.topLeft()))
# Copies tab name and selects all
text = self.main.tabText(index)
text = text.replace(u'&', u'')
if self.split_char:
text = text.split(self.split_char)[self.split_index]
self.setText(text)
self.selectAll()
if not self.isVisible():
# Makes editor visible
self.show() | python | def edit_tab(self, index):
"""Activate the edit tab."""
# Sets focus, shows cursor
self.setFocus(True)
# Updates tab index
self.tab_index = index
# Gets tab size and shrinks to avoid overlapping tab borders
rect = self.main.tabRect(index)
rect.adjust(1, 1, -2, -1)
# Sets size
self.setFixedSize(rect.size())
# Places on top of the tab
self.move(self.main.mapToGlobal(rect.topLeft()))
# Copies tab name and selects all
text = self.main.tabText(index)
text = text.replace(u'&', u'')
if self.split_char:
text = text.split(self.split_char)[self.split_index]
self.setText(text)
self.selectAll()
if not self.isVisible():
# Makes editor visible
self.show() | [
"def",
"edit_tab",
"(",
"self",
",",
"index",
")",
":",
"# Sets focus, shows cursor\r",
"self",
".",
"setFocus",
"(",
"True",
")",
"# Updates tab index\r",
"self",
".",
"tab_index",
"=",
"index",
"# Gets tab size and shrinks to avoid overlapping tab borders\r",
"rect",
... | Activate the edit tab. | [
"Activate",
"the",
"edit",
"tab",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/tabs.py#L91-L121 |
31,442 | spyder-ide/spyder | spyder/widgets/tabs.py | EditTabNamePopup.edit_finished | def edit_finished(self):
"""On clean exit, update tab name."""
# Hides editor
self.hide()
if isinstance(self.tab_index, int) and self.tab_index >= 0:
# We are editing a valid tab, update name
tab_text = to_text_string(self.text())
self.main.setTabText(self.tab_index, tab_text)
self.main.sig_change_name.emit(tab_text) | python | def edit_finished(self):
"""On clean exit, update tab name."""
# Hides editor
self.hide()
if isinstance(self.tab_index, int) and self.tab_index >= 0:
# We are editing a valid tab, update name
tab_text = to_text_string(self.text())
self.main.setTabText(self.tab_index, tab_text)
self.main.sig_change_name.emit(tab_text) | [
"def",
"edit_finished",
"(",
"self",
")",
":",
"# Hides editor\r",
"self",
".",
"hide",
"(",
")",
"if",
"isinstance",
"(",
"self",
".",
"tab_index",
",",
"int",
")",
"and",
"self",
".",
"tab_index",
">=",
"0",
":",
"# We are editing a valid tab, update name\r"... | On clean exit, update tab name. | [
"On",
"clean",
"exit",
"update",
"tab",
"name",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/tabs.py#L123-L132 |
31,443 | spyder-ide/spyder | spyder/widgets/tabs.py | TabBar.mouseDoubleClickEvent | def mouseDoubleClickEvent(self, event):
"""Override Qt method to trigger the tab name editor."""
if self.rename_tabs is True and \
event.buttons() == Qt.MouseButtons(Qt.LeftButton):
# Tab index
index = self.tabAt(event.pos())
if index >= 0:
# Tab is valid, call tab name editor
self.tab_name_editor.edit_tab(index)
else:
# Event is not interesting, raise to parent
QTabBar.mouseDoubleClickEvent(self, event) | python | def mouseDoubleClickEvent(self, event):
"""Override Qt method to trigger the tab name editor."""
if self.rename_tabs is True and \
event.buttons() == Qt.MouseButtons(Qt.LeftButton):
# Tab index
index = self.tabAt(event.pos())
if index >= 0:
# Tab is valid, call tab name editor
self.tab_name_editor.edit_tab(index)
else:
# Event is not interesting, raise to parent
QTabBar.mouseDoubleClickEvent(self, event) | [
"def",
"mouseDoubleClickEvent",
"(",
"self",
",",
"event",
")",
":",
"if",
"self",
".",
"rename_tabs",
"is",
"True",
"and",
"event",
".",
"buttons",
"(",
")",
"==",
"Qt",
".",
"MouseButtons",
"(",
"Qt",
".",
"LeftButton",
")",
":",
"# Tab index\r",
"inde... | Override Qt method to trigger the tab name editor. | [
"Override",
"Qt",
"method",
"to",
"trigger",
"the",
"tab",
"name",
"editor",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/tabs.py#L230-L241 |
31,444 | spyder-ide/spyder | spyder/widgets/tabs.py | BaseTabs.update_browse_tabs_menu | def update_browse_tabs_menu(self):
"""Update browse tabs menu"""
self.browse_tabs_menu.clear()
names = []
dirnames = []
for index in range(self.count()):
if self.menu_use_tooltips:
text = to_text_string(self.tabToolTip(index))
else:
text = to_text_string(self.tabText(index))
names.append(text)
if osp.isfile(text):
# Testing if tab names are filenames
dirnames.append(osp.dirname(text))
offset = None
# If tab names are all filenames, removing common path:
if len(names) == len(dirnames):
common = get_common_path(dirnames)
if common is None:
offset = None
else:
offset = len(common)+1
if offset <= 3:
# Common path is not a path but a drive letter...
offset = None
for index, text in enumerate(names):
tab_action = create_action(self, text[offset:],
icon=self.tabIcon(index),
toggled=lambda state, index=index:
self.setCurrentIndex(index),
tip=self.tabToolTip(index))
tab_action.setChecked(index == self.currentIndex())
self.browse_tabs_menu.addAction(tab_action) | python | def update_browse_tabs_menu(self):
"""Update browse tabs menu"""
self.browse_tabs_menu.clear()
names = []
dirnames = []
for index in range(self.count()):
if self.menu_use_tooltips:
text = to_text_string(self.tabToolTip(index))
else:
text = to_text_string(self.tabText(index))
names.append(text)
if osp.isfile(text):
# Testing if tab names are filenames
dirnames.append(osp.dirname(text))
offset = None
# If tab names are all filenames, removing common path:
if len(names) == len(dirnames):
common = get_common_path(dirnames)
if common is None:
offset = None
else:
offset = len(common)+1
if offset <= 3:
# Common path is not a path but a drive letter...
offset = None
for index, text in enumerate(names):
tab_action = create_action(self, text[offset:],
icon=self.tabIcon(index),
toggled=lambda state, index=index:
self.setCurrentIndex(index),
tip=self.tabToolTip(index))
tab_action.setChecked(index == self.currentIndex())
self.browse_tabs_menu.addAction(tab_action) | [
"def",
"update_browse_tabs_menu",
"(",
"self",
")",
":",
"self",
".",
"browse_tabs_menu",
".",
"clear",
"(",
")",
"names",
"=",
"[",
"]",
"dirnames",
"=",
"[",
"]",
"for",
"index",
"in",
"range",
"(",
"self",
".",
"count",
"(",
")",
")",
":",
"if",
... | Update browse tabs menu | [
"Update",
"browse",
"tabs",
"menu"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/tabs.py#L288-L322 |
31,445 | spyder-ide/spyder | spyder/widgets/tabs.py | BaseTabs.tab_navigate | def tab_navigate(self, delta=1):
"""Ctrl+Tab"""
if delta > 0 and self.currentIndex() == self.count()-1:
index = delta-1
elif delta < 0 and self.currentIndex() == 0:
index = self.count()+delta
else:
index = self.currentIndex()+delta
self.setCurrentIndex(index) | python | def tab_navigate(self, delta=1):
"""Ctrl+Tab"""
if delta > 0 and self.currentIndex() == self.count()-1:
index = delta-1
elif delta < 0 and self.currentIndex() == 0:
index = self.count()+delta
else:
index = self.currentIndex()+delta
self.setCurrentIndex(index) | [
"def",
"tab_navigate",
"(",
"self",
",",
"delta",
"=",
"1",
")",
":",
"if",
"delta",
">",
"0",
"and",
"self",
".",
"currentIndex",
"(",
")",
"==",
"self",
".",
"count",
"(",
")",
"-",
"1",
":",
"index",
"=",
"delta",
"-",
"1",
"elif",
"delta",
... | Ctrl+Tab | [
"Ctrl",
"+",
"Tab"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/tabs.py#L394-L402 |
31,446 | spyder-ide/spyder | spyder/widgets/tabs.py | BaseTabs.set_close_function | def set_close_function(self, func):
"""Setting Tabs close function
None -> tabs are not closable"""
state = func is not None
if state:
self.sig_close_tab.connect(func)
try:
# Assuming Qt >= 4.5
QTabWidget.setTabsClosable(self, state)
self.tabCloseRequested.connect(func)
except AttributeError:
# Workaround for Qt < 4.5
close_button = create_toolbutton(self, triggered=func,
icon=ima.icon('fileclose'),
tip=_("Close current tab"))
self.setCornerWidget(close_button if state else None) | python | def set_close_function(self, func):
"""Setting Tabs close function
None -> tabs are not closable"""
state = func is not None
if state:
self.sig_close_tab.connect(func)
try:
# Assuming Qt >= 4.5
QTabWidget.setTabsClosable(self, state)
self.tabCloseRequested.connect(func)
except AttributeError:
# Workaround for Qt < 4.5
close_button = create_toolbutton(self, triggered=func,
icon=ima.icon('fileclose'),
tip=_("Close current tab"))
self.setCornerWidget(close_button if state else None) | [
"def",
"set_close_function",
"(",
"self",
",",
"func",
")",
":",
"state",
"=",
"func",
"is",
"not",
"None",
"if",
"state",
":",
"self",
".",
"sig_close_tab",
".",
"connect",
"(",
"func",
")",
"try",
":",
"# Assuming Qt >= 4.5\r",
"QTabWidget",
".",
"setTab... | Setting Tabs close function
None -> tabs are not closable | [
"Setting",
"Tabs",
"close",
"function",
"None",
"-",
">",
"tabs",
"are",
"not",
"closable"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/tabs.py#L404-L419 |
31,447 | spyder-ide/spyder | spyder/widgets/tabs.py | Tabs.move_tab | def move_tab(self, index_from, index_to):
"""Move tab inside a tabwidget"""
self.move_data.emit(index_from, index_to)
tip, text = self.tabToolTip(index_from), self.tabText(index_from)
icon, widget = self.tabIcon(index_from), self.widget(index_from)
current_widget = self.currentWidget()
self.removeTab(index_from)
self.insertTab(index_to, widget, icon, text)
self.setTabToolTip(index_to, tip)
self.setCurrentWidget(current_widget)
self.move_tab_finished.emit() | python | def move_tab(self, index_from, index_to):
"""Move tab inside a tabwidget"""
self.move_data.emit(index_from, index_to)
tip, text = self.tabToolTip(index_from), self.tabText(index_from)
icon, widget = self.tabIcon(index_from), self.widget(index_from)
current_widget = self.currentWidget()
self.removeTab(index_from)
self.insertTab(index_to, widget, icon, text)
self.setTabToolTip(index_to, tip)
self.setCurrentWidget(current_widget)
self.move_tab_finished.emit() | [
"def",
"move_tab",
"(",
"self",
",",
"index_from",
",",
"index_to",
")",
":",
"self",
".",
"move_data",
".",
"emit",
"(",
"index_from",
",",
"index_to",
")",
"tip",
",",
"text",
"=",
"self",
".",
"tabToolTip",
"(",
"index_from",
")",
",",
"self",
".",
... | Move tab inside a tabwidget | [
"Move",
"tab",
"inside",
"a",
"tabwidget"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/tabs.py#L454-L467 |
31,448 | spyder-ide/spyder | spyder/widgets/tabs.py | Tabs.move_tab_from_another_tabwidget | def move_tab_from_another_tabwidget(self, tabwidget_from,
index_from, index_to):
"""Move tab from a tabwidget to another"""
# We pass self object IDs as QString objs, because otherwise it would
# depend on the platform: long for 64bit, int for 32bit. Replacing
# by long all the time is not working on some 32bit platforms
# (see Issue 1094, Issue 1098)
self.sig_move_tab.emit(tabwidget_from, to_text_string(id(self)),
index_from, index_to) | python | def move_tab_from_another_tabwidget(self, tabwidget_from,
index_from, index_to):
"""Move tab from a tabwidget to another"""
# We pass self object IDs as QString objs, because otherwise it would
# depend on the platform: long for 64bit, int for 32bit. Replacing
# by long all the time is not working on some 32bit platforms
# (see Issue 1094, Issue 1098)
self.sig_move_tab.emit(tabwidget_from, to_text_string(id(self)),
index_from, index_to) | [
"def",
"move_tab_from_another_tabwidget",
"(",
"self",
",",
"tabwidget_from",
",",
"index_from",
",",
"index_to",
")",
":",
"# We pass self object IDs as QString objs, because otherwise it would \r",
"# depend on the platform: long for 64bit, int for 32bit. Replacing \r",
"# by long all ... | Move tab from a tabwidget to another | [
"Move",
"tab",
"from",
"a",
"tabwidget",
"to",
"another"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/tabs.py#L470-L479 |
31,449 | spyder-ide/spyder | spyder/preferences/runconfig.py | BaseRunConfigDialog.add_button_box | def add_button_box(self, stdbtns):
"""Create dialog button box and add it to the dialog layout"""
bbox = QDialogButtonBox(stdbtns)
run_btn = bbox.addButton(_("Run"), QDialogButtonBox.AcceptRole)
run_btn.clicked.connect(self.run_btn_clicked)
bbox.accepted.connect(self.accept)
bbox.rejected.connect(self.reject)
btnlayout = QHBoxLayout()
btnlayout.addStretch(1)
btnlayout.addWidget(bbox)
self.layout().addLayout(btnlayout) | python | def add_button_box(self, stdbtns):
"""Create dialog button box and add it to the dialog layout"""
bbox = QDialogButtonBox(stdbtns)
run_btn = bbox.addButton(_("Run"), QDialogButtonBox.AcceptRole)
run_btn.clicked.connect(self.run_btn_clicked)
bbox.accepted.connect(self.accept)
bbox.rejected.connect(self.reject)
btnlayout = QHBoxLayout()
btnlayout.addStretch(1)
btnlayout.addWidget(bbox)
self.layout().addLayout(btnlayout) | [
"def",
"add_button_box",
"(",
"self",
",",
"stdbtns",
")",
":",
"bbox",
"=",
"QDialogButtonBox",
"(",
"stdbtns",
")",
"run_btn",
"=",
"bbox",
".",
"addButton",
"(",
"_",
"(",
"\"Run\"",
")",
",",
"QDialogButtonBox",
".",
"AcceptRole",
")",
"run_btn",
".",
... | Create dialog button box and add it to the dialog layout | [
"Create",
"dialog",
"button",
"box",
"and",
"add",
"it",
"to",
"the",
"dialog",
"layout"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/runconfig.py#L351-L361 |
31,450 | spyder-ide/spyder | spyder/plugins/editor/panels/linenumber.py | LineNumberArea.compute_width | def compute_width(self):
"""Compute and return line number area width"""
if not self._enabled:
return 0
digits = 1
maxb = max(1, self.editor.blockCount())
while maxb >= 10:
maxb /= 10
digits += 1
if self._margin:
margin = 3+self.editor.fontMetrics().width('9'*digits)
else:
margin = 0
return margin+self.get_markers_margin() | python | def compute_width(self):
"""Compute and return line number area width"""
if not self._enabled:
return 0
digits = 1
maxb = max(1, self.editor.blockCount())
while maxb >= 10:
maxb /= 10
digits += 1
if self._margin:
margin = 3+self.editor.fontMetrics().width('9'*digits)
else:
margin = 0
return margin+self.get_markers_margin() | [
"def",
"compute_width",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_enabled",
":",
"return",
"0",
"digits",
"=",
"1",
"maxb",
"=",
"max",
"(",
"1",
",",
"self",
".",
"editor",
".",
"blockCount",
"(",
")",
")",
"while",
"maxb",
">=",
"10",
... | Compute and return line number area width | [
"Compute",
"and",
"return",
"line",
"number",
"area",
"width"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/linenumber.py#L159-L172 |
31,451 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | process_python_symbol_data | def process_python_symbol_data(oedata):
"""Returns a list with line number, definition name, fold and token."""
symbol_list = []
for key in oedata:
val = oedata[key]
if val and key != 'found_cell_separators':
if val.is_class_or_function():
symbol_list.append((key, val.def_name, val.fold_level,
val.get_token()))
return sorted(symbol_list) | python | def process_python_symbol_data(oedata):
"""Returns a list with line number, definition name, fold and token."""
symbol_list = []
for key in oedata:
val = oedata[key]
if val and key != 'found_cell_separators':
if val.is_class_or_function():
symbol_list.append((key, val.def_name, val.fold_level,
val.get_token()))
return sorted(symbol_list) | [
"def",
"process_python_symbol_data",
"(",
"oedata",
")",
":",
"symbol_list",
"=",
"[",
"]",
"for",
"key",
"in",
"oedata",
":",
"val",
"=",
"oedata",
"[",
"key",
"]",
"if",
"val",
"and",
"key",
"!=",
"'found_cell_separators'",
":",
"if",
"val",
".",
"is_c... | Returns a list with line number, definition name, fold and token. | [
"Returns",
"a",
"list",
"with",
"line",
"number",
"definition",
"name",
"fold",
"and",
"token",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L32-L41 |
31,452 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | get_python_symbol_icons | def get_python_symbol_icons(oedata):
"""Return a list of icons for oedata of a python file."""
class_icon = ima.icon('class')
method_icon = ima.icon('method')
function_icon = ima.icon('function')
private_icon = ima.icon('private1')
super_private_icon = ima.icon('private2')
symbols = process_python_symbol_data(oedata)
# line - 1, name, fold level
fold_levels = sorted(list(set([s[2] for s in symbols])))
parents = [None]*len(symbols)
icons = [None]*len(symbols)
indexes = []
parent = None
for level in fold_levels:
for index, item in enumerate(symbols):
line, name, fold_level, token = item
if index in indexes:
continue
if fold_level == level:
indexes.append(index)
parent = item
else:
parents[index] = parent
for index, item in enumerate(symbols):
parent = parents[index]
if item[-1] == 'def':
icons[index] = function_icon
elif item[-1] == 'class':
icons[index] = class_icon
else:
icons[index] = QIcon()
if parent is not None:
if parent[-1] == 'class':
if item[-1] == 'def' and item[1].startswith('__'):
icons[index] = super_private_icon
elif item[-1] == 'def' and item[1].startswith('_'):
icons[index] = private_icon
else:
icons[index] = method_icon
return icons | python | def get_python_symbol_icons(oedata):
"""Return a list of icons for oedata of a python file."""
class_icon = ima.icon('class')
method_icon = ima.icon('method')
function_icon = ima.icon('function')
private_icon = ima.icon('private1')
super_private_icon = ima.icon('private2')
symbols = process_python_symbol_data(oedata)
# line - 1, name, fold level
fold_levels = sorted(list(set([s[2] for s in symbols])))
parents = [None]*len(symbols)
icons = [None]*len(symbols)
indexes = []
parent = None
for level in fold_levels:
for index, item in enumerate(symbols):
line, name, fold_level, token = item
if index in indexes:
continue
if fold_level == level:
indexes.append(index)
parent = item
else:
parents[index] = parent
for index, item in enumerate(symbols):
parent = parents[index]
if item[-1] == 'def':
icons[index] = function_icon
elif item[-1] == 'class':
icons[index] = class_icon
else:
icons[index] = QIcon()
if parent is not None:
if parent[-1] == 'class':
if item[-1] == 'def' and item[1].startswith('__'):
icons[index] = super_private_icon
elif item[-1] == 'def' and item[1].startswith('_'):
icons[index] = private_icon
else:
icons[index] = method_icon
return icons | [
"def",
"get_python_symbol_icons",
"(",
"oedata",
")",
":",
"class_icon",
"=",
"ima",
".",
"icon",
"(",
"'class'",
")",
"method_icon",
"=",
"ima",
".",
"icon",
"(",
"'method'",
")",
"function_icon",
"=",
"ima",
".",
"icon",
"(",
"'function'",
")",
"private_... | Return a list of icons for oedata of a python file. | [
"Return",
"a",
"list",
"of",
"icons",
"for",
"oedata",
"of",
"a",
"python",
"file",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L44-L92 |
31,453 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | FilesFilterLine.focusOutEvent | def focusOutEvent(self, event):
"""
Detect when the focus goes out of this widget.
This is used to make the file switcher leave focus on the
last selected file by the user.
"""
self.clicked_outside = True
return super(QLineEdit, self).focusOutEvent(event) | python | def focusOutEvent(self, event):
"""
Detect when the focus goes out of this widget.
This is used to make the file switcher leave focus on the
last selected file by the user.
"""
self.clicked_outside = True
return super(QLineEdit, self).focusOutEvent(event) | [
"def",
"focusOutEvent",
"(",
"self",
",",
"event",
")",
":",
"self",
".",
"clicked_outside",
"=",
"True",
"return",
"super",
"(",
"QLineEdit",
",",
"self",
")",
".",
"focusOutEvent",
"(",
"event",
")"
] | Detect when the focus goes out of this widget.
This is used to make the file switcher leave focus on the
last selected file by the user. | [
"Detect",
"when",
"the",
"focus",
"goes",
"out",
"of",
"this",
"widget",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L218-L226 |
31,454 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | FileSwitcher.save_initial_state | def save_initial_state(self):
"""Save initial cursors and initial active widget."""
paths = self.paths
self.initial_widget = self.get_widget()
self.initial_cursors = {}
for i, editor in enumerate(self.widgets):
if editor is self.initial_widget:
self.initial_path = paths[i]
# This try is needed to make the fileswitcher work with
# plugins that does not have a textCursor.
try:
self.initial_cursors[paths[i]] = editor.textCursor()
except AttributeError:
pass | python | def save_initial_state(self):
"""Save initial cursors and initial active widget."""
paths = self.paths
self.initial_widget = self.get_widget()
self.initial_cursors = {}
for i, editor in enumerate(self.widgets):
if editor is self.initial_widget:
self.initial_path = paths[i]
# This try is needed to make the fileswitcher work with
# plugins that does not have a textCursor.
try:
self.initial_cursors[paths[i]] = editor.textCursor()
except AttributeError:
pass | [
"def",
"save_initial_state",
"(",
"self",
")",
":",
"paths",
"=",
"self",
".",
"paths",
"self",
".",
"initial_widget",
"=",
"self",
".",
"get_widget",
"(",
")",
"self",
".",
"initial_cursors",
"=",
"{",
"}",
"for",
"i",
",",
"editor",
"in",
"enumerate",
... | Save initial cursors and initial active widget. | [
"Save",
"initial",
"cursors",
"and",
"initial",
"active",
"widget",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L380-L394 |
31,455 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | FileSwitcher.restore_initial_state | def restore_initial_state(self):
"""Restores initial cursors and initial active editor."""
self.list.clear()
self.is_visible = False
widgets = self.widgets_by_path
if not self.edit.clicked_outside:
for path in self.initial_cursors:
cursor = self.initial_cursors[path]
if path in widgets:
self.set_editor_cursor(widgets[path], cursor)
if self.initial_widget in self.paths_by_widget:
index = self.paths.index(self.initial_path)
self.sig_goto_file.emit(index) | python | def restore_initial_state(self):
"""Restores initial cursors and initial active editor."""
self.list.clear()
self.is_visible = False
widgets = self.widgets_by_path
if not self.edit.clicked_outside:
for path in self.initial_cursors:
cursor = self.initial_cursors[path]
if path in widgets:
self.set_editor_cursor(widgets[path], cursor)
if self.initial_widget in self.paths_by_widget:
index = self.paths.index(self.initial_path)
self.sig_goto_file.emit(index) | [
"def",
"restore_initial_state",
"(",
"self",
")",
":",
"self",
".",
"list",
".",
"clear",
"(",
")",
"self",
".",
"is_visible",
"=",
"False",
"widgets",
"=",
"self",
".",
"widgets_by_path",
"if",
"not",
"self",
".",
"edit",
".",
"clicked_outside",
":",
"f... | Restores initial cursors and initial active editor. | [
"Restores",
"initial",
"cursors",
"and",
"initial",
"active",
"editor",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L401-L415 |
31,456 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | FileSwitcher.set_dialog_position | def set_dialog_position(self):
"""Positions the file switcher dialog."""
parent = self.parent()
geo = parent.geometry()
width = self.list.width() # This has been set in setup
left = parent.geometry().width()/2 - width/2
# Note: the +1 pixel on the top makes it look better
if isinstance(parent, QMainWindow):
top = (parent.toolbars_menu.geometry().height() +
parent.menuBar().geometry().height() + 1)
else:
top = self.plugins_tabs[0][0].tabBar().geometry().height() + 1
while parent:
geo = parent.geometry()
top += geo.top()
left += geo.left()
parent = parent.parent()
self.move(left, top) | python | def set_dialog_position(self):
"""Positions the file switcher dialog."""
parent = self.parent()
geo = parent.geometry()
width = self.list.width() # This has been set in setup
left = parent.geometry().width()/2 - width/2
# Note: the +1 pixel on the top makes it look better
if isinstance(parent, QMainWindow):
top = (parent.toolbars_menu.geometry().height() +
parent.menuBar().geometry().height() + 1)
else:
top = self.plugins_tabs[0][0].tabBar().geometry().height() + 1
while parent:
geo = parent.geometry()
top += geo.top()
left += geo.left()
parent = parent.parent()
self.move(left, top) | [
"def",
"set_dialog_position",
"(",
"self",
")",
":",
"parent",
"=",
"self",
".",
"parent",
"(",
")",
"geo",
"=",
"parent",
".",
"geometry",
"(",
")",
"width",
"=",
"self",
".",
"list",
".",
"width",
"(",
")",
"# This has been set in setup",
"left",
"=",
... | Positions the file switcher dialog. | [
"Positions",
"the",
"file",
"switcher",
"dialog",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L417-L436 |
31,457 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | FileSwitcher.fix_size | def fix_size(self, content):
"""
Adjusts the width and height of the file switcher
based on the relative size of the parent and content.
"""
# Update size of dialog based on relative size of the parent
if content:
width, height = self.get_item_size(content)
# Width
parent = self.parent()
relative_width = parent.geometry().width() * 0.65
if relative_width > self.MAX_WIDTH:
relative_width = self.MAX_WIDTH
self.list.setMinimumWidth(relative_width)
# Height
if len(content) < 15:
max_entries = len(content)
else:
max_entries = 15
max_height = height * max_entries * 1.7
self.list.setMinimumHeight(max_height)
# Resize
self.list.resize(relative_width, self.list.height()) | python | def fix_size(self, content):
"""
Adjusts the width and height of the file switcher
based on the relative size of the parent and content.
"""
# Update size of dialog based on relative size of the parent
if content:
width, height = self.get_item_size(content)
# Width
parent = self.parent()
relative_width = parent.geometry().width() * 0.65
if relative_width > self.MAX_WIDTH:
relative_width = self.MAX_WIDTH
self.list.setMinimumWidth(relative_width)
# Height
if len(content) < 15:
max_entries = len(content)
else:
max_entries = 15
max_height = height * max_entries * 1.7
self.list.setMinimumHeight(max_height)
# Resize
self.list.resize(relative_width, self.list.height()) | [
"def",
"fix_size",
"(",
"self",
",",
"content",
")",
":",
"# Update size of dialog based on relative size of the parent",
"if",
"content",
":",
"width",
",",
"height",
"=",
"self",
".",
"get_item_size",
"(",
"content",
")",
"# Width",
"parent",
"=",
"self",
".",
... | Adjusts the width and height of the file switcher
based on the relative size of the parent and content. | [
"Adjusts",
"the",
"width",
"and",
"height",
"of",
"the",
"file",
"switcher",
"based",
"on",
"the",
"relative",
"size",
"of",
"the",
"parent",
"and",
"content",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L453-L478 |
31,458 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | FileSwitcher.select_row | def select_row(self, steps):
"""Select row in list widget based on a number of steps with direction.
Steps can be positive (next rows) or negative (previous rows).
"""
row = self.current_row() + steps
if 0 <= row < self.count():
self.set_current_row(row) | python | def select_row(self, steps):
"""Select row in list widget based on a number of steps with direction.
Steps can be positive (next rows) or negative (previous rows).
"""
row = self.current_row() + steps
if 0 <= row < self.count():
self.set_current_row(row) | [
"def",
"select_row",
"(",
"self",
",",
"steps",
")",
":",
"row",
"=",
"self",
".",
"current_row",
"(",
")",
"+",
"steps",
"if",
"0",
"<=",
"row",
"<",
"self",
".",
"count",
"(",
")",
":",
"self",
".",
"set_current_row",
"(",
"row",
")"
] | Select row in list widget based on a number of steps with direction.
Steps can be positive (next rows) or negative (previous rows). | [
"Select",
"row",
"in",
"list",
"widget",
"based",
"on",
"a",
"number",
"of",
"steps",
"with",
"direction",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L493-L500 |
31,459 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | FileSwitcher.previous_row | def previous_row(self):
"""Select previous row in list widget."""
if self.mode == self.SYMBOL_MODE:
self.select_row(-1)
return
prev_row = self.current_row() - 1
if prev_row >= 0:
title = self.list.item(prev_row).text()
else:
title = ''
if prev_row == 0 and '</b></big><br>' in title:
self.list.scrollToTop()
elif '</b></big><br>' in title:
# Select the next previous row, the one following is a title
self.select_row(-2)
else:
self.select_row(-1) | python | def previous_row(self):
"""Select previous row in list widget."""
if self.mode == self.SYMBOL_MODE:
self.select_row(-1)
return
prev_row = self.current_row() - 1
if prev_row >= 0:
title = self.list.item(prev_row).text()
else:
title = ''
if prev_row == 0 and '</b></big><br>' in title:
self.list.scrollToTop()
elif '</b></big><br>' in title:
# Select the next previous row, the one following is a title
self.select_row(-2)
else:
self.select_row(-1) | [
"def",
"previous_row",
"(",
"self",
")",
":",
"if",
"self",
".",
"mode",
"==",
"self",
".",
"SYMBOL_MODE",
":",
"self",
".",
"select_row",
"(",
"-",
"1",
")",
"return",
"prev_row",
"=",
"self",
".",
"current_row",
"(",
")",
"-",
"1",
"if",
"prev_row"... | Select previous row in list widget. | [
"Select",
"previous",
"row",
"in",
"list",
"widget",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L502-L518 |
31,460 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | FileSwitcher.next_row | def next_row(self):
"""Select next row in list widget."""
if self.mode == self.SYMBOL_MODE:
self.select_row(+1)
return
next_row = self.current_row() + 1
if next_row < self.count():
if '</b></big><br>' in self.list.item(next_row).text():
# Select the next next row, the one following is a title
self.select_row(+2)
else:
self.select_row(+1) | python | def next_row(self):
"""Select next row in list widget."""
if self.mode == self.SYMBOL_MODE:
self.select_row(+1)
return
next_row = self.current_row() + 1
if next_row < self.count():
if '</b></big><br>' in self.list.item(next_row).text():
# Select the next next row, the one following is a title
self.select_row(+2)
else:
self.select_row(+1) | [
"def",
"next_row",
"(",
"self",
")",
":",
"if",
"self",
".",
"mode",
"==",
"self",
".",
"SYMBOL_MODE",
":",
"self",
".",
"select_row",
"(",
"+",
"1",
")",
"return",
"next_row",
"=",
"self",
".",
"current_row",
"(",
")",
"+",
"1",
"if",
"next_row",
... | Select next row in list widget. | [
"Select",
"next",
"row",
"in",
"list",
"widget",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L520-L531 |
31,461 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | FileSwitcher.get_stack_index | def get_stack_index(self, stack_index, plugin_index):
"""Get the real index of the selected item."""
other_plugins_count = sum([other_tabs[0].count() \
for other_tabs in \
self.plugins_tabs[:plugin_index]])
real_index = stack_index - other_plugins_count
return real_index | python | def get_stack_index(self, stack_index, plugin_index):
"""Get the real index of the selected item."""
other_plugins_count = sum([other_tabs[0].count() \
for other_tabs in \
self.plugins_tabs[:plugin_index]])
real_index = stack_index - other_plugins_count
return real_index | [
"def",
"get_stack_index",
"(",
"self",
",",
"stack_index",
",",
"plugin_index",
")",
":",
"other_plugins_count",
"=",
"sum",
"(",
"[",
"other_tabs",
"[",
"0",
"]",
".",
"count",
"(",
")",
"for",
"other_tabs",
"in",
"self",
".",
"plugins_tabs",
"[",
":",
... | Get the real index of the selected item. | [
"Get",
"the",
"real",
"index",
"of",
"the",
"selected",
"item",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L533-L540 |
31,462 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | FileSwitcher.get_plugin_data | def get_plugin_data(self, plugin):
"""Get the data object of the plugin's current tab manager."""
# The data object is named "data" in the editor plugin while it is
# named "clients" in the notebook plugin.
try:
data = plugin.get_current_tab_manager().data
except AttributeError:
data = plugin.get_current_tab_manager().clients
return data | python | def get_plugin_data(self, plugin):
"""Get the data object of the plugin's current tab manager."""
# The data object is named "data" in the editor plugin while it is
# named "clients" in the notebook plugin.
try:
data = plugin.get_current_tab_manager().data
except AttributeError:
data = plugin.get_current_tab_manager().clients
return data | [
"def",
"get_plugin_data",
"(",
"self",
",",
"plugin",
")",
":",
"# The data object is named \"data\" in the editor plugin while it is",
"# named \"clients\" in the notebook plugin.",
"try",
":",
"data",
"=",
"plugin",
".",
"get_current_tab_manager",
"(",
")",
".",
"data",
"... | Get the data object of the plugin's current tab manager. | [
"Get",
"the",
"data",
"object",
"of",
"the",
"plugin",
"s",
"current",
"tab",
"manager",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L543-L552 |
31,463 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | FileSwitcher.get_plugin_tabwidget | def get_plugin_tabwidget(self, plugin):
"""Get the tabwidget of the plugin's current tab manager."""
# The tab widget is named "tabs" in the editor plugin while it is
# named "tabwidget" in the notebook plugin.
try:
tabwidget = plugin.get_current_tab_manager().tabs
except AttributeError:
tabwidget = plugin.get_current_tab_manager().tabwidget
return tabwidget | python | def get_plugin_tabwidget(self, plugin):
"""Get the tabwidget of the plugin's current tab manager."""
# The tab widget is named "tabs" in the editor plugin while it is
# named "tabwidget" in the notebook plugin.
try:
tabwidget = plugin.get_current_tab_manager().tabs
except AttributeError:
tabwidget = plugin.get_current_tab_manager().tabwidget
return tabwidget | [
"def",
"get_plugin_tabwidget",
"(",
"self",
",",
"plugin",
")",
":",
"# The tab widget is named \"tabs\" in the editor plugin while it is",
"# named \"tabwidget\" in the notebook plugin.",
"try",
":",
"tabwidget",
"=",
"plugin",
".",
"get_current_tab_manager",
"(",
")",
".",
... | Get the tabwidget of the plugin's current tab manager. | [
"Get",
"the",
"tabwidget",
"of",
"the",
"plugin",
"s",
"current",
"tab",
"manager",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L554-L563 |
31,464 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | FileSwitcher.get_widget | def get_widget(self, index=None, path=None, tabs=None):
"""Get widget by index.
If no tabs and index specified the current active widget is returned.
"""
if (index and tabs) or (path and tabs):
return tabs.widget(index)
elif self.plugin:
return self.get_plugin_tabwidget(self.plugin).currentWidget()
else:
return self.plugins_tabs[0][0].currentWidget() | python | def get_widget(self, index=None, path=None, tabs=None):
"""Get widget by index.
If no tabs and index specified the current active widget is returned.
"""
if (index and tabs) or (path and tabs):
return tabs.widget(index)
elif self.plugin:
return self.get_plugin_tabwidget(self.plugin).currentWidget()
else:
return self.plugins_tabs[0][0].currentWidget() | [
"def",
"get_widget",
"(",
"self",
",",
"index",
"=",
"None",
",",
"path",
"=",
"None",
",",
"tabs",
"=",
"None",
")",
":",
"if",
"(",
"index",
"and",
"tabs",
")",
"or",
"(",
"path",
"and",
"tabs",
")",
":",
"return",
"tabs",
".",
"widget",
"(",
... | Get widget by index.
If no tabs and index specified the current active widget is returned. | [
"Get",
"widget",
"by",
"index",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L565-L575 |
31,465 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | FileSwitcher.set_editor_cursor | def set_editor_cursor(self, editor, cursor):
"""Set the cursor of an editor."""
pos = cursor.position()
anchor = cursor.anchor()
new_cursor = QTextCursor()
if pos == anchor:
new_cursor.movePosition(pos)
else:
new_cursor.movePosition(anchor)
new_cursor.movePosition(pos, QTextCursor.KeepAnchor)
editor.setTextCursor(cursor) | python | def set_editor_cursor(self, editor, cursor):
"""Set the cursor of an editor."""
pos = cursor.position()
anchor = cursor.anchor()
new_cursor = QTextCursor()
if pos == anchor:
new_cursor.movePosition(pos)
else:
new_cursor.movePosition(anchor)
new_cursor.movePosition(pos, QTextCursor.KeepAnchor)
editor.setTextCursor(cursor) | [
"def",
"set_editor_cursor",
"(",
"self",
",",
"editor",
",",
"cursor",
")",
":",
"pos",
"=",
"cursor",
".",
"position",
"(",
")",
"anchor",
"=",
"cursor",
".",
"anchor",
"(",
")",
"new_cursor",
"=",
"QTextCursor",
"(",
")",
"if",
"pos",
"==",
"anchor",... | Set the cursor of an editor. | [
"Set",
"the",
"cursor",
"of",
"an",
"editor",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L577-L588 |
31,466 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | FileSwitcher.goto_line | def goto_line(self, line_number):
"""Go to specified line number in current active editor."""
if line_number:
line_number = int(line_number)
try:
self.plugin.go_to_line(line_number)
except AttributeError:
pass | python | def goto_line(self, line_number):
"""Go to specified line number in current active editor."""
if line_number:
line_number = int(line_number)
try:
self.plugin.go_to_line(line_number)
except AttributeError:
pass | [
"def",
"goto_line",
"(",
"self",
",",
"line_number",
")",
":",
"if",
"line_number",
":",
"line_number",
"=",
"int",
"(",
"line_number",
")",
"try",
":",
"self",
".",
"plugin",
".",
"go_to_line",
"(",
"line_number",
")",
"except",
"AttributeError",
":",
"pa... | Go to specified line number in current active editor. | [
"Go",
"to",
"specified",
"line",
"number",
"in",
"current",
"active",
"editor",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L590-L597 |
31,467 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | FileSwitcher.item_selection_changed | def item_selection_changed(self):
"""List widget item selection change handler."""
row = self.current_row()
if self.count() and row >= 0:
if '</b></big><br>' in self.list.currentItem().text() and row == 0:
self.next_row()
if self.mode == self.FILE_MODE:
try:
stack_index = self.paths.index(self.filtered_path[row])
self.plugin = self.widgets[stack_index][1]
self.goto_line(self.line_number)
try:
self.plugin.switch_to_plugin()
self.raise_()
except AttributeError:
# The widget using the fileswitcher is not a plugin
pass
self.edit.setFocus()
except ValueError:
pass
else:
line_number = self.filtered_symbol_lines[row]
self.goto_line(line_number) | python | def item_selection_changed(self):
"""List widget item selection change handler."""
row = self.current_row()
if self.count() and row >= 0:
if '</b></big><br>' in self.list.currentItem().text() and row == 0:
self.next_row()
if self.mode == self.FILE_MODE:
try:
stack_index = self.paths.index(self.filtered_path[row])
self.plugin = self.widgets[stack_index][1]
self.goto_line(self.line_number)
try:
self.plugin.switch_to_plugin()
self.raise_()
except AttributeError:
# The widget using the fileswitcher is not a plugin
pass
self.edit.setFocus()
except ValueError:
pass
else:
line_number = self.filtered_symbol_lines[row]
self.goto_line(line_number) | [
"def",
"item_selection_changed",
"(",
"self",
")",
":",
"row",
"=",
"self",
".",
"current_row",
"(",
")",
"if",
"self",
".",
"count",
"(",
")",
"and",
"row",
">=",
"0",
":",
"if",
"'</b></big><br>'",
"in",
"self",
".",
"list",
".",
"currentItem",
"(",
... | List widget item selection change handler. | [
"List",
"widget",
"item",
"selection",
"change",
"handler",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L609-L631 |
31,468 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | FileSwitcher.setup_symbol_list | def setup_symbol_list(self, filter_text, current_path):
"""Setup list widget content for symbol list display."""
# Get optional symbol name
filter_text, symbol_text = filter_text.split('@')
# Fetch the Outline explorer data, get the icons and values
oedata = self.get_symbol_list()
icons = get_python_symbol_icons(oedata)
# The list of paths here is needed in order to have the same
# point of measurement for the list widget size as in the file list
# See issue 4648
paths = self.paths
# Update list size
self.fix_size(paths)
symbol_list = process_python_symbol_data(oedata)
line_fold_token = [(item[0], item[2], item[3]) for item in symbol_list]
choices = [item[1] for item in symbol_list]
scores = get_search_scores(symbol_text, choices, template="<b>{0}</b>")
# Build the text that will appear on the list widget
results = []
lines = []
self.filtered_symbol_lines = []
for index, score in enumerate(scores):
text, rich_text, score_value = score
line, fold_level, token = line_fold_token[index]
lines.append(text)
if score_value != -1:
results.append((score_value, line, text, rich_text,
fold_level, icons[index], token))
template = '{{0}}<span style="color:{0}">{{1}}</span>'.format(
ima.MAIN_FG_COLOR)
for (score, line, text, rich_text, fold_level, icon,
token) in sorted(results):
fold_space = ' '*(fold_level)
line_number = line + 1
self.filtered_symbol_lines.append(line_number)
textline = template.format(fold_space, rich_text)
item = QListWidgetItem(icon, textline)
item.setSizeHint(QSize(0, 16))
self.list.addItem(item)
# To adjust the delegate layout for KDE themes
self.list.files_list = False
# Select edit line when using symbol search initially.
# See issue 5661
self.edit.setFocus() | python | def setup_symbol_list(self, filter_text, current_path):
"""Setup list widget content for symbol list display."""
# Get optional symbol name
filter_text, symbol_text = filter_text.split('@')
# Fetch the Outline explorer data, get the icons and values
oedata = self.get_symbol_list()
icons = get_python_symbol_icons(oedata)
# The list of paths here is needed in order to have the same
# point of measurement for the list widget size as in the file list
# See issue 4648
paths = self.paths
# Update list size
self.fix_size(paths)
symbol_list = process_python_symbol_data(oedata)
line_fold_token = [(item[0], item[2], item[3]) for item in symbol_list]
choices = [item[1] for item in symbol_list]
scores = get_search_scores(symbol_text, choices, template="<b>{0}</b>")
# Build the text that will appear on the list widget
results = []
lines = []
self.filtered_symbol_lines = []
for index, score in enumerate(scores):
text, rich_text, score_value = score
line, fold_level, token = line_fold_token[index]
lines.append(text)
if score_value != -1:
results.append((score_value, line, text, rich_text,
fold_level, icons[index], token))
template = '{{0}}<span style="color:{0}">{{1}}</span>'.format(
ima.MAIN_FG_COLOR)
for (score, line, text, rich_text, fold_level, icon,
token) in sorted(results):
fold_space = ' '*(fold_level)
line_number = line + 1
self.filtered_symbol_lines.append(line_number)
textline = template.format(fold_space, rich_text)
item = QListWidgetItem(icon, textline)
item.setSizeHint(QSize(0, 16))
self.list.addItem(item)
# To adjust the delegate layout for KDE themes
self.list.files_list = False
# Select edit line when using symbol search initially.
# See issue 5661
self.edit.setFocus() | [
"def",
"setup_symbol_list",
"(",
"self",
",",
"filter_text",
",",
"current_path",
")",
":",
"# Get optional symbol name",
"filter_text",
",",
"symbol_text",
"=",
"filter_text",
".",
"split",
"(",
"'@'",
")",
"# Fetch the Outline explorer data, get the icons and values",
"... | Setup list widget content for symbol list display. | [
"Setup",
"list",
"widget",
"content",
"for",
"symbol",
"list",
"display",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L769-L820 |
31,469 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | FileSwitcher.setup | def setup(self):
"""Setup list widget content."""
if len(self.plugins_tabs) == 0:
self.close()
return
self.list.clear()
current_path = self.current_path
filter_text = self.filter_text
# Get optional line or symbol to define mode and method handler
trying_for_symbol = ('@' in self.filter_text)
if trying_for_symbol:
self.mode = self.SYMBOL_MODE
self.setup_symbol_list(filter_text, current_path)
else:
self.mode = self.FILE_MODE
self.setup_file_list(filter_text, current_path)
# Set position according to size
self.set_dialog_position() | python | def setup(self):
"""Setup list widget content."""
if len(self.plugins_tabs) == 0:
self.close()
return
self.list.clear()
current_path = self.current_path
filter_text = self.filter_text
# Get optional line or symbol to define mode and method handler
trying_for_symbol = ('@' in self.filter_text)
if trying_for_symbol:
self.mode = self.SYMBOL_MODE
self.setup_symbol_list(filter_text, current_path)
else:
self.mode = self.FILE_MODE
self.setup_file_list(filter_text, current_path)
# Set position according to size
self.set_dialog_position() | [
"def",
"setup",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"plugins_tabs",
")",
"==",
"0",
":",
"self",
".",
"close",
"(",
")",
"return",
"self",
".",
"list",
".",
"clear",
"(",
")",
"current_path",
"=",
"self",
".",
"current_path",
"fil... | Setup list widget content. | [
"Setup",
"list",
"widget",
"content",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L831-L852 |
31,470 | spyder-ide/spyder | spyder/widgets/fileswitcher.py | FileSwitcher.add_plugin | def add_plugin(self, plugin, tabs, data, icon):
"""Add a plugin to display its files."""
self.plugins_tabs.append((tabs, plugin))
self.plugins_data.append((data, icon))
self.plugins_instances.append(plugin) | python | def add_plugin(self, plugin, tabs, data, icon):
"""Add a plugin to display its files."""
self.plugins_tabs.append((tabs, plugin))
self.plugins_data.append((data, icon))
self.plugins_instances.append(plugin) | [
"def",
"add_plugin",
"(",
"self",
",",
"plugin",
",",
"tabs",
",",
"data",
",",
"icon",
")",
":",
"self",
".",
"plugins_tabs",
".",
"append",
"(",
"(",
"tabs",
",",
"plugin",
")",
")",
"self",
".",
"plugins_data",
".",
"append",
"(",
"(",
"data",
"... | Add a plugin to display its files. | [
"Add",
"a",
"plugin",
"to",
"display",
"its",
"files",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L862-L866 |
31,471 | spyder-ide/spyder | spyder/utils/vcs.py | get_vcs_info | def get_vcs_info(path):
"""Return support status dict if path is under VCS root"""
for info in SUPPORTED:
vcs_path = osp.join(path, info['rootdir'])
if osp.isdir(vcs_path):
return info | python | def get_vcs_info(path):
"""Return support status dict if path is under VCS root"""
for info in SUPPORTED:
vcs_path = osp.join(path, info['rootdir'])
if osp.isdir(vcs_path):
return info | [
"def",
"get_vcs_info",
"(",
"path",
")",
":",
"for",
"info",
"in",
"SUPPORTED",
":",
"vcs_path",
"=",
"osp",
".",
"join",
"(",
"path",
",",
"info",
"[",
"'rootdir'",
"]",
")",
"if",
"osp",
".",
"isdir",
"(",
"vcs_path",
")",
":",
"return",
"info"
] | Return support status dict if path is under VCS root | [
"Return",
"support",
"status",
"dict",
"if",
"path",
"is",
"under",
"VCS",
"root"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/vcs.py#L52-L57 |
31,472 | spyder-ide/spyder | spyder/utils/vcs.py | get_vcs_root | def get_vcs_root(path):
"""Return VCS root directory path
Return None if path is not within a supported VCS repository"""
previous_path = path
while get_vcs_info(path) is None:
path = abspardir(path)
if path == previous_path:
return
else:
previous_path = path
return osp.abspath(path) | python | def get_vcs_root(path):
"""Return VCS root directory path
Return None if path is not within a supported VCS repository"""
previous_path = path
while get_vcs_info(path) is None:
path = abspardir(path)
if path == previous_path:
return
else:
previous_path = path
return osp.abspath(path) | [
"def",
"get_vcs_root",
"(",
"path",
")",
":",
"previous_path",
"=",
"path",
"while",
"get_vcs_info",
"(",
"path",
")",
"is",
"None",
":",
"path",
"=",
"abspardir",
"(",
"path",
")",
"if",
"path",
"==",
"previous_path",
":",
"return",
"else",
":",
"previo... | Return VCS root directory path
Return None if path is not within a supported VCS repository | [
"Return",
"VCS",
"root",
"directory",
"path",
"Return",
"None",
"if",
"path",
"is",
"not",
"within",
"a",
"supported",
"VCS",
"repository"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/vcs.py#L60-L70 |
31,473 | spyder-ide/spyder | spyder/widgets/comboboxes.py | BaseComboBox.event | def event(self, event):
"""Qt Override.
Filter tab keys and process double tab keys.
"""
if (event.type() == QEvent.KeyPress) and (event.key() == Qt.Key_Tab):
self.sig_tab_pressed.emit(True)
self.numpress += 1
if self.numpress == 1:
self.presstimer = QTimer.singleShot(400, self.handle_keypress)
return True
return QComboBox.event(self, event) | python | def event(self, event):
"""Qt Override.
Filter tab keys and process double tab keys.
"""
if (event.type() == QEvent.KeyPress) and (event.key() == Qt.Key_Tab):
self.sig_tab_pressed.emit(True)
self.numpress += 1
if self.numpress == 1:
self.presstimer = QTimer.singleShot(400, self.handle_keypress)
return True
return QComboBox.event(self, event) | [
"def",
"event",
"(",
"self",
",",
"event",
")",
":",
"if",
"(",
"event",
".",
"type",
"(",
")",
"==",
"QEvent",
".",
"KeyPress",
")",
"and",
"(",
"event",
".",
"key",
"(",
")",
"==",
"Qt",
".",
"Key_Tab",
")",
":",
"self",
".",
"sig_tab_pressed",... | Qt Override.
Filter tab keys and process double tab keys. | [
"Qt",
"Override",
".",
"Filter",
"tab",
"keys",
"and",
"process",
"double",
"tab",
"keys",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L46-L57 |
31,474 | spyder-ide/spyder | spyder/widgets/comboboxes.py | BaseComboBox.keyPressEvent | def keyPressEvent(self, event):
"""Qt Override.
Handle key press events.
"""
if event.key() == Qt.Key_Return or event.key() == Qt.Key_Enter:
if self.add_current_text_if_valid():
self.selected()
self.hide_completer()
elif event.key() == Qt.Key_Escape:
self.set_current_text(self.selected_text)
self.hide_completer()
else:
QComboBox.keyPressEvent(self, event) | python | def keyPressEvent(self, event):
"""Qt Override.
Handle key press events.
"""
if event.key() == Qt.Key_Return or event.key() == Qt.Key_Enter:
if self.add_current_text_if_valid():
self.selected()
self.hide_completer()
elif event.key() == Qt.Key_Escape:
self.set_current_text(self.selected_text)
self.hide_completer()
else:
QComboBox.keyPressEvent(self, event) | [
"def",
"keyPressEvent",
"(",
"self",
",",
"event",
")",
":",
"if",
"event",
".",
"key",
"(",
")",
"==",
"Qt",
".",
"Key_Return",
"or",
"event",
".",
"key",
"(",
")",
"==",
"Qt",
".",
"Key_Enter",
":",
"if",
"self",
".",
"add_current_text_if_valid",
"... | Qt Override.
Handle key press events. | [
"Qt",
"Override",
".",
"Handle",
"key",
"press",
"events",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L59-L72 |
31,475 | spyder-ide/spyder | spyder/widgets/comboboxes.py | BaseComboBox.handle_keypress | def handle_keypress(self):
"""When hitting tab, it handles if single or double tab"""
if self.numpress == 2:
self.sig_double_tab_pressed.emit(True)
self.numpress = 0 | python | def handle_keypress(self):
"""When hitting tab, it handles if single or double tab"""
if self.numpress == 2:
self.sig_double_tab_pressed.emit(True)
self.numpress = 0 | [
"def",
"handle_keypress",
"(",
"self",
")",
":",
"if",
"self",
".",
"numpress",
"==",
"2",
":",
"self",
".",
"sig_double_tab_pressed",
".",
"emit",
"(",
"True",
")",
"self",
".",
"numpress",
"=",
"0"
] | When hitting tab, it handles if single or double tab | [
"When",
"hitting",
"tab",
"it",
"handles",
"if",
"single",
"or",
"double",
"tab"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L75-L79 |
31,476 | spyder-ide/spyder | spyder/widgets/comboboxes.py | BaseComboBox.add_current_text_if_valid | def add_current_text_if_valid(self):
"""Add current text to combo box history if valid"""
valid = self.is_valid(self.currentText())
if valid or valid is None:
self.add_current_text()
return True
else:
self.set_current_text(self.selected_text) | python | def add_current_text_if_valid(self):
"""Add current text to combo box history if valid"""
valid = self.is_valid(self.currentText())
if valid or valid is None:
self.add_current_text()
return True
else:
self.set_current_text(self.selected_text) | [
"def",
"add_current_text_if_valid",
"(",
"self",
")",
":",
"valid",
"=",
"self",
".",
"is_valid",
"(",
"self",
".",
"currentText",
"(",
")",
")",
"if",
"valid",
"or",
"valid",
"is",
"None",
":",
"self",
".",
"add_current_text",
"(",
")",
"return",
"True"... | Add current text to combo box history if valid | [
"Add",
"current",
"text",
"to",
"combo",
"box",
"history",
"if",
"valid"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L120-L127 |
31,477 | spyder-ide/spyder | spyder/widgets/comboboxes.py | EditableComboBox.validate | def validate(self, qstr, editing=True):
"""Validate entered path"""
if self.selected_text == qstr and qstr != '':
self.valid.emit(True, True)
return
valid = self.is_valid(qstr)
if editing:
if valid:
self.valid.emit(True, False)
else:
self.valid.emit(False, False) | python | def validate(self, qstr, editing=True):
"""Validate entered path"""
if self.selected_text == qstr and qstr != '':
self.valid.emit(True, True)
return
valid = self.is_valid(qstr)
if editing:
if valid:
self.valid.emit(True, False)
else:
self.valid.emit(False, False) | [
"def",
"validate",
"(",
"self",
",",
"qstr",
",",
"editing",
"=",
"True",
")",
":",
"if",
"self",
".",
"selected_text",
"==",
"qstr",
"and",
"qstr",
"!=",
"''",
":",
"self",
".",
"valid",
".",
"emit",
"(",
"True",
",",
"True",
")",
"return",
"valid... | Validate entered path | [
"Validate",
"entered",
"path"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L177-L188 |
31,478 | spyder-ide/spyder | spyder/widgets/comboboxes.py | PathComboBox.focusInEvent | def focusInEvent(self, event):
"""Handle focus in event restoring to display the status icon."""
show_status = getattr(self.lineEdit(), 'show_status_icon', None)
if show_status:
show_status()
QComboBox.focusInEvent(self, event) | python | def focusInEvent(self, event):
"""Handle focus in event restoring to display the status icon."""
show_status = getattr(self.lineEdit(), 'show_status_icon', None)
if show_status:
show_status()
QComboBox.focusInEvent(self, event) | [
"def",
"focusInEvent",
"(",
"self",
",",
"event",
")",
":",
"show_status",
"=",
"getattr",
"(",
"self",
".",
"lineEdit",
"(",
")",
",",
"'show_status_icon'",
",",
"None",
")",
"if",
"show_status",
":",
"show_status",
"(",
")",
"QComboBox",
".",
"focusInEve... | Handle focus in event restoring to display the status icon. | [
"Handle",
"focus",
"in",
"event",
"restoring",
"to",
"display",
"the",
"status",
"icon",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L220-L225 |
31,479 | spyder-ide/spyder | spyder/widgets/comboboxes.py | PathComboBox.focusOutEvent | def focusOutEvent(self, event):
"""Handle focus out event restoring the last valid selected path."""
# Calling asynchronously the 'add_current_text' to avoid crash
# https://groups.google.com/group/spyderlib/browse_thread/thread/2257abf530e210bd
if not self.is_valid():
lineedit = self.lineEdit()
QTimer.singleShot(50, lambda: lineedit.setText(self.selected_text))
hide_status = getattr(self.lineEdit(), 'hide_status_icon', None)
if hide_status:
hide_status()
QComboBox.focusOutEvent(self, event) | python | def focusOutEvent(self, event):
"""Handle focus out event restoring the last valid selected path."""
# Calling asynchronously the 'add_current_text' to avoid crash
# https://groups.google.com/group/spyderlib/browse_thread/thread/2257abf530e210bd
if not self.is_valid():
lineedit = self.lineEdit()
QTimer.singleShot(50, lambda: lineedit.setText(self.selected_text))
hide_status = getattr(self.lineEdit(), 'hide_status_icon', None)
if hide_status:
hide_status()
QComboBox.focusOutEvent(self, event) | [
"def",
"focusOutEvent",
"(",
"self",
",",
"event",
")",
":",
"# Calling asynchronously the 'add_current_text' to avoid crash\r",
"# https://groups.google.com/group/spyderlib/browse_thread/thread/2257abf530e210bd\r",
"if",
"not",
"self",
".",
"is_valid",
"(",
")",
":",
"lineedit",... | Handle focus out event restoring the last valid selected path. | [
"Handle",
"focus",
"out",
"event",
"restoring",
"the",
"last",
"valid",
"selected",
"path",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L227-L238 |
31,480 | spyder-ide/spyder | spyder/widgets/comboboxes.py | PathComboBox._complete_options | def _complete_options(self):
"""Find available completion options."""
text = to_text_string(self.currentText())
opts = glob.glob(text + "*")
opts = sorted([opt for opt in opts if osp.isdir(opt)])
self.setCompleter(QCompleter(opts, self))
return opts | python | def _complete_options(self):
"""Find available completion options."""
text = to_text_string(self.currentText())
opts = glob.glob(text + "*")
opts = sorted([opt for opt in opts if osp.isdir(opt)])
self.setCompleter(QCompleter(opts, self))
return opts | [
"def",
"_complete_options",
"(",
"self",
")",
":",
"text",
"=",
"to_text_string",
"(",
"self",
".",
"currentText",
"(",
")",
")",
"opts",
"=",
"glob",
".",
"glob",
"(",
"text",
"+",
"\"*\"",
")",
"opts",
"=",
"sorted",
"(",
"[",
"opt",
"for",
"opt",
... | Find available completion options. | [
"Find",
"available",
"completion",
"options",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L241-L247 |
31,481 | spyder-ide/spyder | spyder/widgets/comboboxes.py | PathComboBox.double_tab_complete | def double_tab_complete(self):
"""If several options available a double tab displays options."""
opts = self._complete_options()
if len(opts) > 1:
self.completer().complete() | python | def double_tab_complete(self):
"""If several options available a double tab displays options."""
opts = self._complete_options()
if len(opts) > 1:
self.completer().complete() | [
"def",
"double_tab_complete",
"(",
"self",
")",
":",
"opts",
"=",
"self",
".",
"_complete_options",
"(",
")",
"if",
"len",
"(",
"opts",
")",
">",
"1",
":",
"self",
".",
"completer",
"(",
")",
".",
"complete",
"(",
")"
] | If several options available a double tab displays options. | [
"If",
"several",
"options",
"available",
"a",
"double",
"tab",
"displays",
"options",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L249-L253 |
31,482 | spyder-ide/spyder | spyder/widgets/comboboxes.py | PathComboBox.tab_complete | def tab_complete(self):
"""
If there is a single option available one tab completes the option.
"""
opts = self._complete_options()
if len(opts) == 1:
self.set_current_text(opts[0] + os.sep)
self.hide_completer() | python | def tab_complete(self):
"""
If there is a single option available one tab completes the option.
"""
opts = self._complete_options()
if len(opts) == 1:
self.set_current_text(opts[0] + os.sep)
self.hide_completer() | [
"def",
"tab_complete",
"(",
"self",
")",
":",
"opts",
"=",
"self",
".",
"_complete_options",
"(",
")",
"if",
"len",
"(",
"opts",
")",
"==",
"1",
":",
"self",
".",
"set_current_text",
"(",
"opts",
"[",
"0",
"]",
"+",
"os",
".",
"sep",
")",
"self",
... | If there is a single option available one tab completes the option. | [
"If",
"there",
"is",
"a",
"single",
"option",
"available",
"one",
"tab",
"completes",
"the",
"option",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L255-L262 |
31,483 | spyder-ide/spyder | spyder/widgets/comboboxes.py | PathComboBox.add_tooltip_to_highlighted_item | def add_tooltip_to_highlighted_item(self, index):
"""
Add a tooltip showing the full path of the currently highlighted item
of the PathComboBox.
"""
self.setItemData(index, self.itemText(index), Qt.ToolTipRole) | python | def add_tooltip_to_highlighted_item(self, index):
"""
Add a tooltip showing the full path of the currently highlighted item
of the PathComboBox.
"""
self.setItemData(index, self.itemText(index), Qt.ToolTipRole) | [
"def",
"add_tooltip_to_highlighted_item",
"(",
"self",
",",
"index",
")",
":",
"self",
".",
"setItemData",
"(",
"index",
",",
"self",
".",
"itemText",
"(",
"index",
")",
",",
"Qt",
".",
"ToolTipRole",
")"
] | Add a tooltip showing the full path of the currently highlighted item
of the PathComboBox. | [
"Add",
"a",
"tooltip",
"showing",
"the",
"full",
"path",
"of",
"the",
"currently",
"highlighted",
"item",
"of",
"the",
"PathComboBox",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L287-L292 |
31,484 | spyder-ide/spyder | spyder/plugins/console/plugin.py | Console.set_historylog | def set_historylog(self, historylog):
"""Bind historylog instance to this console
Not used anymore since v2.0"""
historylog.add_history(self.shell.history_filename)
self.shell.append_to_history.connect(historylog.append_to_history) | python | def set_historylog(self, historylog):
"""Bind historylog instance to this console
Not used anymore since v2.0"""
historylog.add_history(self.shell.history_filename)
self.shell.append_to_history.connect(historylog.append_to_history) | [
"def",
"set_historylog",
"(",
"self",
",",
"historylog",
")",
":",
"historylog",
".",
"add_history",
"(",
"self",
".",
"shell",
".",
"history_filename",
")",
"self",
".",
"shell",
".",
"append_to_history",
".",
"connect",
"(",
"historylog",
".",
"append_to_his... | Bind historylog instance to this console
Not used anymore since v2.0 | [
"Bind",
"historylog",
"instance",
"to",
"this",
"console",
"Not",
"used",
"anymore",
"since",
"v2",
".",
"0"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L106-L110 |
31,485 | spyder-ide/spyder | spyder/plugins/console/plugin.py | Console.exception_occurred | def exception_occurred(self, text, is_traceback):
"""
Exception ocurred in the internal console.
Show a QDialog or the internal console to warn the user.
"""
# Skip errors without traceback or dismiss
if (not is_traceback and self.error_dlg is None) or self.dismiss_error:
return
if CONF.get('main', 'show_internal_errors'):
if self.error_dlg is None:
self.error_dlg = SpyderErrorDialog(self)
self.error_dlg.close_btn.clicked.connect(self.close_error_dlg)
self.error_dlg.rejected.connect(self.remove_error_dlg)
self.error_dlg.details.go_to_error.connect(self.go_to_error)
self.error_dlg.show()
self.error_dlg.append_traceback(text)
elif DEV or get_debug_level():
self.dockwidget.show()
self.dockwidget.raise_() | python | def exception_occurred(self, text, is_traceback):
"""
Exception ocurred in the internal console.
Show a QDialog or the internal console to warn the user.
"""
# Skip errors without traceback or dismiss
if (not is_traceback and self.error_dlg is None) or self.dismiss_error:
return
if CONF.get('main', 'show_internal_errors'):
if self.error_dlg is None:
self.error_dlg = SpyderErrorDialog(self)
self.error_dlg.close_btn.clicked.connect(self.close_error_dlg)
self.error_dlg.rejected.connect(self.remove_error_dlg)
self.error_dlg.details.go_to_error.connect(self.go_to_error)
self.error_dlg.show()
self.error_dlg.append_traceback(text)
elif DEV or get_debug_level():
self.dockwidget.show()
self.dockwidget.raise_() | [
"def",
"exception_occurred",
"(",
"self",
",",
"text",
",",
"is_traceback",
")",
":",
"# Skip errors without traceback or dismiss\r",
"if",
"(",
"not",
"is_traceback",
"and",
"self",
".",
"error_dlg",
"is",
"None",
")",
"or",
"self",
".",
"dismiss_error",
":",
"... | Exception ocurred in the internal console.
Show a QDialog or the internal console to warn the user. | [
"Exception",
"ocurred",
"in",
"the",
"internal",
"console",
".",
"Show",
"a",
"QDialog",
"or",
"the",
"internal",
"console",
"to",
"warn",
"the",
"user",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L200-L220 |
31,486 | spyder-ide/spyder | spyder/plugins/console/plugin.py | Console.close_error_dlg | def close_error_dlg(self):
"""Close error dialog."""
if self.error_dlg.dismiss_box.isChecked():
self.dismiss_error = True
self.error_dlg.reject() | python | def close_error_dlg(self):
"""Close error dialog."""
if self.error_dlg.dismiss_box.isChecked():
self.dismiss_error = True
self.error_dlg.reject() | [
"def",
"close_error_dlg",
"(",
"self",
")",
":",
"if",
"self",
".",
"error_dlg",
".",
"dismiss_box",
".",
"isChecked",
"(",
")",
":",
"self",
".",
"dismiss_error",
"=",
"True",
"self",
".",
"error_dlg",
".",
"reject",
"(",
")"
] | Close error dialog. | [
"Close",
"error",
"dialog",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L222-L226 |
31,487 | spyder-ide/spyder | spyder/plugins/console/plugin.py | Console.show_syspath | def show_syspath(self):
"""Show sys.path"""
editor = CollectionsEditor(parent=self)
editor.setup(sys.path, title="sys.path", readonly=True,
width=600, icon=ima.icon('syspath'))
self.dialog_manager.show(editor) | python | def show_syspath(self):
"""Show sys.path"""
editor = CollectionsEditor(parent=self)
editor.setup(sys.path, title="sys.path", readonly=True,
width=600, icon=ima.icon('syspath'))
self.dialog_manager.show(editor) | [
"def",
"show_syspath",
"(",
"self",
")",
":",
"editor",
"=",
"CollectionsEditor",
"(",
"parent",
"=",
"self",
")",
"editor",
".",
"setup",
"(",
"sys",
".",
"path",
",",
"title",
"=",
"\"sys.path\"",
",",
"readonly",
"=",
"True",
",",
"width",
"=",
"600... | Show sys.path | [
"Show",
"sys",
".",
"path"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L244-L249 |
31,488 | spyder-ide/spyder | spyder/plugins/console/plugin.py | Console.run_script | def run_script(self, filename=None, silent=False, set_focus=False,
args=None):
"""Run a Python script"""
if filename is None:
self.shell.interpreter.restore_stds()
filename, _selfilter = getopenfilename(
self, _("Run Python script"), getcwd_or_home(),
_("Python scripts")+" (*.py ; *.pyw ; *.ipy)")
self.shell.interpreter.redirect_stds()
if filename:
os.chdir( osp.dirname(filename) )
filename = osp.basename(filename)
else:
return
logger.debug("Running script with %s", args)
filename = osp.abspath(filename)
rbs = remove_backslashes
command = "runfile('%s', args='%s')" % (rbs(filename), rbs(args))
if set_focus:
self.shell.setFocus()
if self.dockwidget and not self.ismaximized:
self.dockwidget.setVisible(True)
self.dockwidget.raise_()
self.shell.write(command+'\n')
self.shell.run_command(command) | python | def run_script(self, filename=None, silent=False, set_focus=False,
args=None):
"""Run a Python script"""
if filename is None:
self.shell.interpreter.restore_stds()
filename, _selfilter = getopenfilename(
self, _("Run Python script"), getcwd_or_home(),
_("Python scripts")+" (*.py ; *.pyw ; *.ipy)")
self.shell.interpreter.redirect_stds()
if filename:
os.chdir( osp.dirname(filename) )
filename = osp.basename(filename)
else:
return
logger.debug("Running script with %s", args)
filename = osp.abspath(filename)
rbs = remove_backslashes
command = "runfile('%s', args='%s')" % (rbs(filename), rbs(args))
if set_focus:
self.shell.setFocus()
if self.dockwidget and not self.ismaximized:
self.dockwidget.setVisible(True)
self.dockwidget.raise_()
self.shell.write(command+'\n')
self.shell.run_command(command) | [
"def",
"run_script",
"(",
"self",
",",
"filename",
"=",
"None",
",",
"silent",
"=",
"False",
",",
"set_focus",
"=",
"False",
",",
"args",
"=",
"None",
")",
":",
"if",
"filename",
"is",
"None",
":",
"self",
".",
"shell",
".",
"interpreter",
".",
"rest... | Run a Python script | [
"Run",
"a",
"Python",
"script"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L252-L276 |
31,489 | spyder-ide/spyder | spyder/plugins/console/plugin.py | Console.execute_lines | def execute_lines(self, lines):
"""Execute lines and give focus to shell"""
self.shell.execute_lines(to_text_string(lines))
self.shell.setFocus() | python | def execute_lines(self, lines):
"""Execute lines and give focus to shell"""
self.shell.execute_lines(to_text_string(lines))
self.shell.setFocus() | [
"def",
"execute_lines",
"(",
"self",
",",
"lines",
")",
":",
"self",
".",
"shell",
".",
"execute_lines",
"(",
"to_text_string",
"(",
"lines",
")",
")",
"self",
".",
"shell",
".",
"setFocus",
"(",
")"
] | Execute lines and give focus to shell | [
"Execute",
"lines",
"and",
"give",
"focus",
"to",
"shell"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L296-L299 |
31,490 | spyder-ide/spyder | spyder/plugins/console/plugin.py | Console.change_exteditor | def change_exteditor(self):
"""Change external editor path"""
path, valid = QInputDialog.getText(self, _('External editor'),
_('External editor executable path:'),
QLineEdit.Normal,
self.get_option('external_editor/path'))
if valid:
self.set_option('external_editor/path', to_text_string(path)) | python | def change_exteditor(self):
"""Change external editor path"""
path, valid = QInputDialog.getText(self, _('External editor'),
_('External editor executable path:'),
QLineEdit.Normal,
self.get_option('external_editor/path'))
if valid:
self.set_option('external_editor/path', to_text_string(path)) | [
"def",
"change_exteditor",
"(",
"self",
")",
":",
"path",
",",
"valid",
"=",
"QInputDialog",
".",
"getText",
"(",
"self",
",",
"_",
"(",
"'External editor'",
")",
",",
"_",
"(",
"'External editor executable path:'",
")",
",",
"QLineEdit",
".",
"Normal",
",",... | Change external editor path | [
"Change",
"external",
"editor",
"path"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L313-L320 |
31,491 | spyder-ide/spyder | spyder/plugins/console/plugin.py | Console.toggle_codecompletion | def toggle_codecompletion(self, checked):
"""Toggle automatic code completion"""
self.shell.set_codecompletion_auto(checked)
self.set_option('codecompletion/auto', checked) | python | def toggle_codecompletion(self, checked):
"""Toggle automatic code completion"""
self.shell.set_codecompletion_auto(checked)
self.set_option('codecompletion/auto', checked) | [
"def",
"toggle_codecompletion",
"(",
"self",
",",
"checked",
")",
":",
"self",
".",
"shell",
".",
"set_codecompletion_auto",
"(",
"checked",
")",
"self",
".",
"set_option",
"(",
"'codecompletion/auto'",
",",
"checked",
")"
] | Toggle automatic code completion | [
"Toggle",
"automatic",
"code",
"completion"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L329-L332 |
31,492 | spyder-ide/spyder | scripts/spyder_win_post_install.py | install | def install():
"""Function executed when running the script with the -install switch"""
# Create Spyder start menu folder
# Don't use CSIDL_COMMON_PROGRAMS because it requres admin rights
# This is consistent with use of CSIDL_DESKTOPDIRECTORY below
# CSIDL_COMMON_PROGRAMS =
# C:\ProgramData\Microsoft\Windows\Start Menu\Programs
# CSIDL_PROGRAMS =
# C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
start_menu = osp.join(get_special_folder_path('CSIDL_PROGRAMS'),
'Spyder (Py%i.%i %i bit)' % (sys.version_info[0],
sys.version_info[1],
struct.calcsize('P')*8))
if not osp.isdir(start_menu):
os.mkdir(start_menu)
directory_created(start_menu)
# Create Spyder start menu entries
python = osp.abspath(osp.join(sys.prefix, 'python.exe'))
pythonw = osp.abspath(osp.join(sys.prefix, 'pythonw.exe'))
script = osp.abspath(osp.join(sys.prefix, 'scripts', 'spyder'))
if not osp.exists(script): # if not installed to the site scripts dir
script = osp.abspath(osp.join(osp.dirname(osp.abspath(__file__)), 'spyder'))
workdir = "%HOMEDRIVE%%HOMEPATH%"
import distutils.sysconfig
lib_dir = distutils.sysconfig.get_python_lib(plat_specific=1)
ico_dir = osp.join(lib_dir, 'spyder', 'windows')
# if user is running -install manually then icons are in Scripts/
if not osp.isdir(ico_dir):
ico_dir = osp.dirname(osp.abspath(__file__))
desc = 'The Scientific Python Development Environment'
fname = osp.join(start_menu, 'Spyder (full).lnk')
create_shortcut(python, desc, fname, '"%s"' % script, workdir,
osp.join(ico_dir, 'spyder.ico'))
file_created(fname)
fname = osp.join(start_menu, 'Spyder-Reset all settings.lnk')
create_shortcut(python, 'Reset Spyder settings to defaults',
fname, '"%s" --reset' % script, workdir)
file_created(fname)
current = True # only affects current user
root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE
winreg.SetValueEx(winreg.CreateKey(root, KEY_C1 % ("", EWS)),
"", 0, winreg.REG_SZ,
'"%s" "%s\Scripts\spyder" "%%1"' % (pythonw, sys.prefix))
winreg.SetValueEx(winreg.CreateKey(root, KEY_C1 % ("NoCon", EWS)),
"", 0, winreg.REG_SZ,
'"%s" "%s\Scripts\spyder" "%%1"' % (pythonw, sys.prefix))
# Create desktop shortcut file
desktop_folder = get_special_folder_path("CSIDL_DESKTOPDIRECTORY")
fname = osp.join(desktop_folder, 'Spyder.lnk')
desc = 'The Scientific Python Development Environment'
create_shortcut(pythonw, desc, fname, '"%s"' % script, workdir,
osp.join(ico_dir, 'spyder.ico'))
file_created(fname) | python | def install():
"""Function executed when running the script with the -install switch"""
# Create Spyder start menu folder
# Don't use CSIDL_COMMON_PROGRAMS because it requres admin rights
# This is consistent with use of CSIDL_DESKTOPDIRECTORY below
# CSIDL_COMMON_PROGRAMS =
# C:\ProgramData\Microsoft\Windows\Start Menu\Programs
# CSIDL_PROGRAMS =
# C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
start_menu = osp.join(get_special_folder_path('CSIDL_PROGRAMS'),
'Spyder (Py%i.%i %i bit)' % (sys.version_info[0],
sys.version_info[1],
struct.calcsize('P')*8))
if not osp.isdir(start_menu):
os.mkdir(start_menu)
directory_created(start_menu)
# Create Spyder start menu entries
python = osp.abspath(osp.join(sys.prefix, 'python.exe'))
pythonw = osp.abspath(osp.join(sys.prefix, 'pythonw.exe'))
script = osp.abspath(osp.join(sys.prefix, 'scripts', 'spyder'))
if not osp.exists(script): # if not installed to the site scripts dir
script = osp.abspath(osp.join(osp.dirname(osp.abspath(__file__)), 'spyder'))
workdir = "%HOMEDRIVE%%HOMEPATH%"
import distutils.sysconfig
lib_dir = distutils.sysconfig.get_python_lib(plat_specific=1)
ico_dir = osp.join(lib_dir, 'spyder', 'windows')
# if user is running -install manually then icons are in Scripts/
if not osp.isdir(ico_dir):
ico_dir = osp.dirname(osp.abspath(__file__))
desc = 'The Scientific Python Development Environment'
fname = osp.join(start_menu, 'Spyder (full).lnk')
create_shortcut(python, desc, fname, '"%s"' % script, workdir,
osp.join(ico_dir, 'spyder.ico'))
file_created(fname)
fname = osp.join(start_menu, 'Spyder-Reset all settings.lnk')
create_shortcut(python, 'Reset Spyder settings to defaults',
fname, '"%s" --reset' % script, workdir)
file_created(fname)
current = True # only affects current user
root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE
winreg.SetValueEx(winreg.CreateKey(root, KEY_C1 % ("", EWS)),
"", 0, winreg.REG_SZ,
'"%s" "%s\Scripts\spyder" "%%1"' % (pythonw, sys.prefix))
winreg.SetValueEx(winreg.CreateKey(root, KEY_C1 % ("NoCon", EWS)),
"", 0, winreg.REG_SZ,
'"%s" "%s\Scripts\spyder" "%%1"' % (pythonw, sys.prefix))
# Create desktop shortcut file
desktop_folder = get_special_folder_path("CSIDL_DESKTOPDIRECTORY")
fname = osp.join(desktop_folder, 'Spyder.lnk')
desc = 'The Scientific Python Development Environment'
create_shortcut(pythonw, desc, fname, '"%s"' % script, workdir,
osp.join(ico_dir, 'spyder.ico'))
file_created(fname) | [
"def",
"install",
"(",
")",
":",
"# Create Spyder start menu folder\r",
"# Don't use CSIDL_COMMON_PROGRAMS because it requres admin rights\r",
"# This is consistent with use of CSIDL_DESKTOPDIRECTORY below\r",
"# CSIDL_COMMON_PROGRAMS =\r",
"# C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Progr... | Function executed when running the script with the -install switch | [
"Function",
"executed",
"when",
"running",
"the",
"script",
"with",
"the",
"-",
"install",
"switch"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/scripts/spyder_win_post_install.py#L113-L170 |
31,493 | spyder-ide/spyder | scripts/spyder_win_post_install.py | remove | def remove():
"""Function executed when running the script with the -remove switch"""
current = True # only affects current user
root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE
for key in (KEY_C1 % ("", EWS), KEY_C1 % ("NoCon", EWS),
KEY_C0 % ("", EWS), KEY_C0 % ("NoCon", EWS)):
try:
winreg.DeleteKey(root, key)
except WindowsError:
pass
else:
if not is_bdist_wininst:
print("Successfully removed Spyder shortcuts from Windows "\
"Explorer context menu.", file=sys.stdout)
if not is_bdist_wininst:
# clean up desktop
desktop_folder = get_special_folder_path("CSIDL_DESKTOPDIRECTORY")
fname = osp.join(desktop_folder, 'Spyder.lnk')
if osp.isfile(fname):
try:
os.remove(fname)
except OSError:
print("Failed to remove %s; you may be able to remove it "\
"manually." % fname, file=sys.stderr)
else:
print("Successfully removed Spyder shortcuts from your desktop.",
file=sys.stdout)
# clean up startmenu
start_menu = osp.join(get_special_folder_path('CSIDL_PROGRAMS'),
'Spyder (Py%i.%i %i bit)' % (sys.version_info[0],
sys.version_info[1],
struct.calcsize('P')*8))
if osp.isdir(start_menu):
for fname in os.listdir(start_menu):
try:
os.remove(osp.join(start_menu,fname))
except OSError:
print("Failed to remove %s; you may be able to remove it "\
"manually." % fname, file=sys.stderr)
else:
print("Successfully removed Spyder shortcuts from your "\
" start menu.", file=sys.stdout)
try:
os.rmdir(start_menu)
except OSError:
print("Failed to remove %s; you may be able to remove it "\
"manually." % fname, file=sys.stderr)
else:
print("Successfully removed Spyder shortcut folder from your "\
" start menu.", file=sys.stdout) | python | def remove():
"""Function executed when running the script with the -remove switch"""
current = True # only affects current user
root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE
for key in (KEY_C1 % ("", EWS), KEY_C1 % ("NoCon", EWS),
KEY_C0 % ("", EWS), KEY_C0 % ("NoCon", EWS)):
try:
winreg.DeleteKey(root, key)
except WindowsError:
pass
else:
if not is_bdist_wininst:
print("Successfully removed Spyder shortcuts from Windows "\
"Explorer context menu.", file=sys.stdout)
if not is_bdist_wininst:
# clean up desktop
desktop_folder = get_special_folder_path("CSIDL_DESKTOPDIRECTORY")
fname = osp.join(desktop_folder, 'Spyder.lnk')
if osp.isfile(fname):
try:
os.remove(fname)
except OSError:
print("Failed to remove %s; you may be able to remove it "\
"manually." % fname, file=sys.stderr)
else:
print("Successfully removed Spyder shortcuts from your desktop.",
file=sys.stdout)
# clean up startmenu
start_menu = osp.join(get_special_folder_path('CSIDL_PROGRAMS'),
'Spyder (Py%i.%i %i bit)' % (sys.version_info[0],
sys.version_info[1],
struct.calcsize('P')*8))
if osp.isdir(start_menu):
for fname in os.listdir(start_menu):
try:
os.remove(osp.join(start_menu,fname))
except OSError:
print("Failed to remove %s; you may be able to remove it "\
"manually." % fname, file=sys.stderr)
else:
print("Successfully removed Spyder shortcuts from your "\
" start menu.", file=sys.stdout)
try:
os.rmdir(start_menu)
except OSError:
print("Failed to remove %s; you may be able to remove it "\
"manually." % fname, file=sys.stderr)
else:
print("Successfully removed Spyder shortcut folder from your "\
" start menu.", file=sys.stdout) | [
"def",
"remove",
"(",
")",
":",
"current",
"=",
"True",
"# only affects current user\r",
"root",
"=",
"winreg",
".",
"HKEY_CURRENT_USER",
"if",
"current",
"else",
"winreg",
".",
"HKEY_LOCAL_MACHINE",
"for",
"key",
"in",
"(",
"KEY_C1",
"%",
"(",
"\"\"",
",",
... | Function executed when running the script with the -remove switch | [
"Function",
"executed",
"when",
"running",
"the",
"script",
"with",
"the",
"-",
"remove",
"switch"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/scripts/spyder_win_post_install.py#L173-L222 |
31,494 | spyder-ide/spyder | spyder/app/tour.py | FadingTipBox.mousePressEvent | def mousePressEvent(self, event):
"""override Qt method"""
# Raise the main application window on click
self.parent.raise_()
self.raise_()
if event.button() == Qt.RightButton:
pass | python | def mousePressEvent(self, event):
"""override Qt method"""
# Raise the main application window on click
self.parent.raise_()
self.raise_()
if event.button() == Qt.RightButton:
pass | [
"def",
"mousePressEvent",
"(",
"self",
",",
"event",
")",
":",
"# Raise the main application window on click\r",
"self",
".",
"parent",
".",
"raise_",
"(",
")",
"self",
".",
"raise_",
"(",
")",
"if",
"event",
".",
"button",
"(",
")",
"==",
"Qt",
".",
"Righ... | override Qt method | [
"override",
"Qt",
"method"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/tour.py#L804-L811 |
31,495 | spyder-ide/spyder | spyder/app/tour.py | AnimatedTour._set_data | def _set_data(self):
"""Set data that is displayed in each step of the tour."""
self.setting_data = True
step, steps, frames = self.step_current, self.steps, self.frames
current = '{0}/{1}'.format(step + 1, steps)
frame = frames[step]
combobox_frames = [u"{0}. {1}".format(i+1, f['title'])
for i, f in enumerate(frames)]
title, content, image = '', '', None
widgets, dockwidgets, decoration = None, None, None
run = None
# Check if entry exists in dic and act accordingly
if 'title' in frame:
title = frame['title']
if 'content' in frame:
content = frame['content']
if 'widgets' in frame:
widget_names = frames[step]['widgets']
# Get the widgets based on their name
widgets, dockwidgets = self._process_widgets(widget_names,
self.spy_window)
self.widgets = widgets
self.dockwidgets = dockwidgets
if 'decoration' in frame:
widget_names = frames[step]['decoration']
deco, decoration = self._process_widgets(widget_names,
self.spy_window)
self.decoration = decoration
if 'image' in frame:
image = frames[step]['image']
if 'interact' in frame:
self.canvas.set_interaction(frame['interact'])
if frame['interact']:
self._set_modal(False, [self.tips])
else:
self._set_modal(True, [self.tips])
else:
self.canvas.set_interaction(False)
self._set_modal(True, [self.tips])
if 'run' in frame:
# Asume that the frist widget is the console
run = frame['run']
self.run = run
self.tips.set_data(title, content, current, image, run,
frames=combobox_frames, step=step)
self._check_buttons()
# Make canvas black when starting a new place of decoration
self.canvas.update_widgets(dockwidgets)
self.canvas.update_decoration(decoration)
self.setting_data = False | python | def _set_data(self):
"""Set data that is displayed in each step of the tour."""
self.setting_data = True
step, steps, frames = self.step_current, self.steps, self.frames
current = '{0}/{1}'.format(step + 1, steps)
frame = frames[step]
combobox_frames = [u"{0}. {1}".format(i+1, f['title'])
for i, f in enumerate(frames)]
title, content, image = '', '', None
widgets, dockwidgets, decoration = None, None, None
run = None
# Check if entry exists in dic and act accordingly
if 'title' in frame:
title = frame['title']
if 'content' in frame:
content = frame['content']
if 'widgets' in frame:
widget_names = frames[step]['widgets']
# Get the widgets based on their name
widgets, dockwidgets = self._process_widgets(widget_names,
self.spy_window)
self.widgets = widgets
self.dockwidgets = dockwidgets
if 'decoration' in frame:
widget_names = frames[step]['decoration']
deco, decoration = self._process_widgets(widget_names,
self.spy_window)
self.decoration = decoration
if 'image' in frame:
image = frames[step]['image']
if 'interact' in frame:
self.canvas.set_interaction(frame['interact'])
if frame['interact']:
self._set_modal(False, [self.tips])
else:
self._set_modal(True, [self.tips])
else:
self.canvas.set_interaction(False)
self._set_modal(True, [self.tips])
if 'run' in frame:
# Asume that the frist widget is the console
run = frame['run']
self.run = run
self.tips.set_data(title, content, current, image, run,
frames=combobox_frames, step=step)
self._check_buttons()
# Make canvas black when starting a new place of decoration
self.canvas.update_widgets(dockwidgets)
self.canvas.update_decoration(decoration)
self.setting_data = False | [
"def",
"_set_data",
"(",
"self",
")",
":",
"self",
".",
"setting_data",
"=",
"True",
"step",
",",
"steps",
",",
"frames",
"=",
"self",
".",
"step_current",
",",
"self",
".",
"steps",
",",
"self",
".",
"frames",
"current",
"=",
"'{0}/{1}'",
".",
"format... | Set data that is displayed in each step of the tour. | [
"Set",
"data",
"that",
"is",
"displayed",
"in",
"each",
"step",
"of",
"the",
"tour",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/tour.py#L1001-L1061 |
31,496 | spyder-ide/spyder | spyder/app/tour.py | AnimatedTour.lost_focus | def lost_focus(self):
"""Confirm if the tour loses focus and hides the tips."""
if (self.is_running and not self.any_has_focus() and
not self.setting_data and not self.hidden):
self.hide_tips() | python | def lost_focus(self):
"""Confirm if the tour loses focus and hides the tips."""
if (self.is_running and not self.any_has_focus() and
not self.setting_data and not self.hidden):
self.hide_tips() | [
"def",
"lost_focus",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"is_running",
"and",
"not",
"self",
".",
"any_has_focus",
"(",
")",
"and",
"not",
"self",
".",
"setting_data",
"and",
"not",
"self",
".",
"hidden",
")",
":",
"self",
".",
"hide_tips",
... | Confirm if the tour loses focus and hides the tips. | [
"Confirm",
"if",
"the",
"tour",
"loses",
"focus",
"and",
"hides",
"the",
"tips",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/tour.py#L1239-L1243 |
31,497 | spyder-ide/spyder | spyder/app/tour.py | AnimatedTour.gain_focus | def gain_focus(self):
"""Confirm if the tour regains focus and unhides the tips."""
if (self.is_running and self.any_has_focus() and
not self.setting_data and self.hidden):
self.unhide_tips() | python | def gain_focus(self):
"""Confirm if the tour regains focus and unhides the tips."""
if (self.is_running and self.any_has_focus() and
not self.setting_data and self.hidden):
self.unhide_tips() | [
"def",
"gain_focus",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"is_running",
"and",
"self",
".",
"any_has_focus",
"(",
")",
"and",
"not",
"self",
".",
"setting_data",
"and",
"self",
".",
"hidden",
")",
":",
"self",
".",
"unhide_tips",
"(",
")"
] | Confirm if the tour regains focus and unhides the tips. | [
"Confirm",
"if",
"the",
"tour",
"regains",
"focus",
"and",
"unhides",
"the",
"tips",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/tour.py#L1245-L1249 |
31,498 | spyder-ide/spyder | spyder/app/tour.py | AnimatedTour.any_has_focus | def any_has_focus(self):
"""Returns if tour or any of its components has focus."""
f = (self.hasFocus() or self.parent.hasFocus() or
self.tips.hasFocus() or self.canvas.hasFocus())
return f | python | def any_has_focus(self):
"""Returns if tour or any of its components has focus."""
f = (self.hasFocus() or self.parent.hasFocus() or
self.tips.hasFocus() or self.canvas.hasFocus())
return f | [
"def",
"any_has_focus",
"(",
"self",
")",
":",
"f",
"=",
"(",
"self",
".",
"hasFocus",
"(",
")",
"or",
"self",
".",
"parent",
".",
"hasFocus",
"(",
")",
"or",
"self",
".",
"tips",
".",
"hasFocus",
"(",
")",
"or",
"self",
".",
"canvas",
".",
"hasF... | Returns if tour or any of its components has focus. | [
"Returns",
"if",
"tour",
"or",
"any",
"of",
"its",
"components",
"has",
"focus",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/tour.py#L1251-L1255 |
31,499 | spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/figurebrowser.py | FigureBrowserWidget._handle_display_data | def _handle_display_data(self, msg):
"""
Reimplemented to handle communications between the figure explorer
and the kernel.
"""
img = None
data = msg['content']['data']
if 'image/svg+xml' in data:
fmt = 'image/svg+xml'
img = data['image/svg+xml']
elif 'image/png' in data:
# PNG data is base64 encoded as it passes over the network
# in a JSON structure so we decode it.
fmt = 'image/png'
img = decodestring(data['image/png'].encode('ascii'))
elif 'image/jpeg' in data and self._jpg_supported:
fmt = 'image/jpeg'
img = decodestring(data['image/jpeg'].encode('ascii'))
if img is not None:
self.sig_new_inline_figure.emit(img, fmt)
if (self.figurebrowser is not None and
self.figurebrowser.mute_inline_plotting):
if not self.sended_render_message:
msg['content']['data']['text/plain'] = ''
self._append_html(
_('<br><hr>'
'\nFigures now render in the Plots pane by default. '
'To make them also appear inline in the Console, '
'uncheck "Mute Inline Plotting" under the Plots '
'pane options menu. \n'
'<hr><br>'), before_prompt=True)
self.sended_render_message = True
else:
msg['content']['data']['text/plain'] = ''
del msg['content']['data'][fmt]
return super(FigureBrowserWidget, self)._handle_display_data(msg) | python | def _handle_display_data(self, msg):
"""
Reimplemented to handle communications between the figure explorer
and the kernel.
"""
img = None
data = msg['content']['data']
if 'image/svg+xml' in data:
fmt = 'image/svg+xml'
img = data['image/svg+xml']
elif 'image/png' in data:
# PNG data is base64 encoded as it passes over the network
# in a JSON structure so we decode it.
fmt = 'image/png'
img = decodestring(data['image/png'].encode('ascii'))
elif 'image/jpeg' in data and self._jpg_supported:
fmt = 'image/jpeg'
img = decodestring(data['image/jpeg'].encode('ascii'))
if img is not None:
self.sig_new_inline_figure.emit(img, fmt)
if (self.figurebrowser is not None and
self.figurebrowser.mute_inline_plotting):
if not self.sended_render_message:
msg['content']['data']['text/plain'] = ''
self._append_html(
_('<br><hr>'
'\nFigures now render in the Plots pane by default. '
'To make them also appear inline in the Console, '
'uncheck "Mute Inline Plotting" under the Plots '
'pane options menu. \n'
'<hr><br>'), before_prompt=True)
self.sended_render_message = True
else:
msg['content']['data']['text/plain'] = ''
del msg['content']['data'][fmt]
return super(FigureBrowserWidget, self)._handle_display_data(msg) | [
"def",
"_handle_display_data",
"(",
"self",
",",
"msg",
")",
":",
"img",
"=",
"None",
"data",
"=",
"msg",
"[",
"'content'",
"]",
"[",
"'data'",
"]",
"if",
"'image/svg+xml'",
"in",
"data",
":",
"fmt",
"=",
"'image/svg+xml'",
"img",
"=",
"data",
"[",
"'i... | Reimplemented to handle communications between the figure explorer
and the kernel. | [
"Reimplemented",
"to",
"handle",
"communications",
"between",
"the",
"figure",
"explorer",
"and",
"the",
"kernel",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/figurebrowser.py#L40-L76 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.