repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1 value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.get_dirname | def get_dirname(self, index):
"""Return dirname associated with *index*"""
fname = self.get_filename(index)
if fname:
if osp.isdir(fname):
return fname
else:
return osp.dirname(fname) | python | def get_dirname(self, index):
"""Return dirname associated with *index*"""
fname = self.get_filename(index)
if fname:
if osp.isdir(fname):
return fname
else:
return osp.dirname(fname) | [
"def",
"get_dirname",
"(",
"self",
",",
"index",
")",
":",
"fname",
"=",
"self",
".",
"get_filename",
"(",
"index",
")",
"if",
"fname",
":",
"if",
"osp",
".",
"isdir",
"(",
"fname",
")",
":",
"return",
"fname",
"else",
":",
"return",
"osp",
".",
"dirname",
"(",
"fname",
")"
] | Return dirname associated with *index* | [
"Return",
"dirname",
"associated",
"with",
"*",
"index",
"*"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L228-L235 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.setup | def setup(self, name_filters=['*.py', '*.pyw'], show_all=False,
single_click_to_open=False):
"""Setup tree widget"""
self.setup_view()
self.set_name_filters(name_filters)
self.show_all = show_all
self.single_click_to_open = single_click_to_open
# Setup context menu
self.menu = QMenu(self)
self.common_actions = self.setup_common_actions() | python | def setup(self, name_filters=['*.py', '*.pyw'], show_all=False,
single_click_to_open=False):
"""Setup tree widget"""
self.setup_view()
self.set_name_filters(name_filters)
self.show_all = show_all
self.single_click_to_open = single_click_to_open
# Setup context menu
self.menu = QMenu(self)
self.common_actions = self.setup_common_actions() | [
"def",
"setup",
"(",
"self",
",",
"name_filters",
"=",
"[",
"'*.py'",
",",
"'*.pyw'",
"]",
",",
"show_all",
"=",
"False",
",",
"single_click_to_open",
"=",
"False",
")",
":",
"self",
".",
"setup_view",
"(",
")",
"self",
".",
"set_name_filters",
"(",
"name_filters",
")",
"self",
".",
"show_all",
"=",
"show_all",
"self",
".",
"single_click_to_open",
"=",
"single_click_to_open",
"# Setup context menu\r",
"self",
".",
"menu",
"=",
"QMenu",
"(",
"self",
")",
"self",
".",
"common_actions",
"=",
"self",
".",
"setup_common_actions",
"(",
")"
] | Setup tree widget | [
"Setup",
"tree",
"widget"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L238-L249 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.setup_common_actions | def setup_common_actions(self):
"""Setup context menu common actions"""
# Filters
filters_action = create_action(self, _("Edit filename filters..."),
None, ima.icon('filter'),
triggered=self.edit_filter)
# Show all files
all_action = create_action(self, _("Show all files"),
toggled=self.toggle_all)
all_action.setChecked(self.show_all)
self.toggle_all(self.show_all)
# Show all files
single_click_to_open = create_action(
self,
_("Single click to open"),
toggled=self.set_single_click_to_open,
)
single_click_to_open.setChecked(self.single_click_to_open)
return [filters_action, all_action, single_click_to_open] | python | def setup_common_actions(self):
"""Setup context menu common actions"""
# Filters
filters_action = create_action(self, _("Edit filename filters..."),
None, ima.icon('filter'),
triggered=self.edit_filter)
# Show all files
all_action = create_action(self, _("Show all files"),
toggled=self.toggle_all)
all_action.setChecked(self.show_all)
self.toggle_all(self.show_all)
# Show all files
single_click_to_open = create_action(
self,
_("Single click to open"),
toggled=self.set_single_click_to_open,
)
single_click_to_open.setChecked(self.single_click_to_open)
return [filters_action, all_action, single_click_to_open] | [
"def",
"setup_common_actions",
"(",
"self",
")",
":",
"# Filters\r",
"filters_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Edit filename filters...\"",
")",
",",
"None",
",",
"ima",
".",
"icon",
"(",
"'filter'",
")",
",",
"triggered",
"=",
"self",
".",
"edit_filter",
")",
"# Show all files\r",
"all_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Show all files\"",
")",
",",
"toggled",
"=",
"self",
".",
"toggle_all",
")",
"all_action",
".",
"setChecked",
"(",
"self",
".",
"show_all",
")",
"self",
".",
"toggle_all",
"(",
"self",
".",
"show_all",
")",
"# Show all files\r",
"single_click_to_open",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Single click to open\"",
")",
",",
"toggled",
"=",
"self",
".",
"set_single_click_to_open",
",",
")",
"single_click_to_open",
".",
"setChecked",
"(",
"self",
".",
"single_click_to_open",
")",
"return",
"[",
"filters_action",
",",
"all_action",
",",
"single_click_to_open",
"]"
] | Setup context menu common actions | [
"Setup",
"context",
"menu",
"common",
"actions"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L257-L276 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.edit_filter | def edit_filter(self):
"""Edit name filters"""
filters, valid = QInputDialog.getText(self, _('Edit filename filters'),
_('Name filters:'),
QLineEdit.Normal,
", ".join(self.name_filters))
if valid:
filters = [f.strip() for f in to_text_string(filters).split(',')]
self.parent_widget.sig_option_changed.emit('name_filters', filters)
self.set_name_filters(filters) | python | def edit_filter(self):
"""Edit name filters"""
filters, valid = QInputDialog.getText(self, _('Edit filename filters'),
_('Name filters:'),
QLineEdit.Normal,
", ".join(self.name_filters))
if valid:
filters = [f.strip() for f in to_text_string(filters).split(',')]
self.parent_widget.sig_option_changed.emit('name_filters', filters)
self.set_name_filters(filters) | [
"def",
"edit_filter",
"(",
"self",
")",
":",
"filters",
",",
"valid",
"=",
"QInputDialog",
".",
"getText",
"(",
"self",
",",
"_",
"(",
"'Edit filename filters'",
")",
",",
"_",
"(",
"'Name filters:'",
")",
",",
"QLineEdit",
".",
"Normal",
",",
"\", \"",
".",
"join",
"(",
"self",
".",
"name_filters",
")",
")",
"if",
"valid",
":",
"filters",
"=",
"[",
"f",
".",
"strip",
"(",
")",
"for",
"f",
"in",
"to_text_string",
"(",
"filters",
")",
".",
"split",
"(",
"','",
")",
"]",
"self",
".",
"parent_widget",
".",
"sig_option_changed",
".",
"emit",
"(",
"'name_filters'",
",",
"filters",
")",
"self",
".",
"set_name_filters",
"(",
"filters",
")"
] | Edit name filters | [
"Edit",
"name",
"filters"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L279-L288 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.toggle_all | def toggle_all(self, checked):
"""Toggle all files mode"""
self.parent_widget.sig_option_changed.emit('show_all', checked)
self.show_all = checked
self.set_show_all(checked) | python | def toggle_all(self, checked):
"""Toggle all files mode"""
self.parent_widget.sig_option_changed.emit('show_all', checked)
self.show_all = checked
self.set_show_all(checked) | [
"def",
"toggle_all",
"(",
"self",
",",
"checked",
")",
":",
"self",
".",
"parent_widget",
".",
"sig_option_changed",
".",
"emit",
"(",
"'show_all'",
",",
"checked",
")",
"self",
".",
"show_all",
"=",
"checked",
"self",
".",
"set_show_all",
"(",
"checked",
")"
] | Toggle all files mode | [
"Toggle",
"all",
"files",
"mode"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L291-L295 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.create_file_new_actions | def create_file_new_actions(self, fnames):
"""Return actions for submenu 'New...'"""
if not fnames:
return []
new_file_act = create_action(self, _("File..."),
icon=ima.icon('filenew'),
triggered=lambda:
self.new_file(fnames[-1]))
new_module_act = create_action(self, _("Module..."),
icon=ima.icon('spyder'),
triggered=lambda:
self.new_module(fnames[-1]))
new_folder_act = create_action(self, _("Folder..."),
icon=ima.icon('folder_new'),
triggered=lambda:
self.new_folder(fnames[-1]))
new_package_act = create_action(self, _("Package..."),
icon=ima.icon('package_new'),
triggered=lambda:
self.new_package(fnames[-1]))
return [new_file_act, new_folder_act, None,
new_module_act, new_package_act] | python | def create_file_new_actions(self, fnames):
"""Return actions for submenu 'New...'"""
if not fnames:
return []
new_file_act = create_action(self, _("File..."),
icon=ima.icon('filenew'),
triggered=lambda:
self.new_file(fnames[-1]))
new_module_act = create_action(self, _("Module..."),
icon=ima.icon('spyder'),
triggered=lambda:
self.new_module(fnames[-1]))
new_folder_act = create_action(self, _("Folder..."),
icon=ima.icon('folder_new'),
triggered=lambda:
self.new_folder(fnames[-1]))
new_package_act = create_action(self, _("Package..."),
icon=ima.icon('package_new'),
triggered=lambda:
self.new_package(fnames[-1]))
return [new_file_act, new_folder_act, None,
new_module_act, new_package_act] | [
"def",
"create_file_new_actions",
"(",
"self",
",",
"fnames",
")",
":",
"if",
"not",
"fnames",
":",
"return",
"[",
"]",
"new_file_act",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"File...\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'filenew'",
")",
",",
"triggered",
"=",
"lambda",
":",
"self",
".",
"new_file",
"(",
"fnames",
"[",
"-",
"1",
"]",
")",
")",
"new_module_act",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Module...\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'spyder'",
")",
",",
"triggered",
"=",
"lambda",
":",
"self",
".",
"new_module",
"(",
"fnames",
"[",
"-",
"1",
"]",
")",
")",
"new_folder_act",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Folder...\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'folder_new'",
")",
",",
"triggered",
"=",
"lambda",
":",
"self",
".",
"new_folder",
"(",
"fnames",
"[",
"-",
"1",
"]",
")",
")",
"new_package_act",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Package...\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'package_new'",
")",
",",
"triggered",
"=",
"lambda",
":",
"self",
".",
"new_package",
"(",
"fnames",
"[",
"-",
"1",
"]",
")",
")",
"return",
"[",
"new_file_act",
",",
"new_folder_act",
",",
"None",
",",
"new_module_act",
",",
"new_package_act",
"]"
] | Return actions for submenu 'New... | [
"Return",
"actions",
"for",
"submenu",
"New",
"..."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L297-L318 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.create_file_manage_actions | def create_file_manage_actions(self, fnames):
"""Return file management actions"""
only_files = all([osp.isfile(_fn) for _fn in fnames])
only_modules = all([osp.splitext(_fn)[1] in ('.py', '.pyw', '.ipy')
for _fn in fnames])
only_notebooks = all([osp.splitext(_fn)[1] == '.ipynb'
for _fn in fnames])
only_valid = all([encoding.is_text_file(_fn) for _fn in fnames])
run_action = create_action(self, _("Run"), icon=ima.icon('run'),
triggered=self.run)
edit_action = create_action(self, _("Edit"), icon=ima.icon('edit'),
triggered=self.clicked)
move_action = create_action(self, _("Move..."),
icon="move.png",
triggered=self.move)
delete_action = create_action(self, _("Delete..."),
icon=ima.icon('editdelete'),
triggered=self.delete)
rename_action = create_action(self, _("Rename..."),
icon=ima.icon('rename'),
triggered=self.rename)
open_external_action = create_action(self, _("Open With OS"),
triggered=self.open_external)
ipynb_convert_action = create_action(self, _("Convert to Python script"),
icon=ima.icon('python'),
triggered=self.convert_notebooks)
copy_file_clipboard_action = (
create_action(self, _("Copy"),
QKeySequence(get_shortcut('explorer', 'copy file')),
icon=ima.icon('editcopy'),
triggered=self.copy_file_clipboard))
save_file_clipboard_action = (
create_action(self, _("Paste"),
QKeySequence(get_shortcut('explorer', 'paste file')),
icon=ima.icon('editpaste'),
triggered=self.save_file_clipboard))
copy_absolute_path_action = (
create_action(self, _("Copy Absolute Path"), QKeySequence(
get_shortcut('explorer', 'copy absolute path')),
triggered=self.copy_absolute_path))
copy_relative_path_action = (
create_action(self, _("Copy Relative Path"), QKeySequence(
get_shortcut('explorer', 'copy relative path')),
triggered=self.copy_relative_path))
actions = []
if only_modules:
actions.append(run_action)
if only_valid and only_files:
actions.append(edit_action)
if sys.platform == 'darwin':
text=_("Show in Finder")
else:
text=_("Show in Folder")
external_fileexp_action = create_action(self, text,
triggered=self.show_in_external_file_explorer)
actions += [delete_action, rename_action]
basedir = fixpath(osp.dirname(fnames[0]))
if all([fixpath(osp.dirname(_fn)) == basedir for _fn in fnames]):
actions.append(move_action)
actions += [None]
actions += [copy_file_clipboard_action, save_file_clipboard_action,
copy_absolute_path_action, copy_relative_path_action]
if not QApplication.clipboard().mimeData().hasUrls():
save_file_clipboard_action.setDisabled(True)
actions += [None]
if only_files:
actions.append(open_external_action)
actions.append(external_fileexp_action)
actions.append([None])
if only_notebooks and nbexporter is not None:
actions.append(ipynb_convert_action)
# VCS support is quite limited for now, so we are enabling the VCS
# related actions only when a single file/folder is selected:
dirname = fnames[0] if osp.isdir(fnames[0]) else osp.dirname(fnames[0])
if len(fnames) == 1 and vcs.is_vcs_repository(dirname):
commit_slot = lambda : self.vcs_command([dirname], 'commit')
browse_slot = lambda : self.vcs_command([dirname], 'browse')
vcs_ci = create_action(self, _("Commit"),
icon=ima.icon('vcs_commit'),
triggered=commit_slot)
vcs_log = create_action(self, _("Browse repository"),
icon=ima.icon('vcs_browse'),
triggered=browse_slot)
actions += [None, vcs_ci, vcs_log]
return actions | python | def create_file_manage_actions(self, fnames):
"""Return file management actions"""
only_files = all([osp.isfile(_fn) for _fn in fnames])
only_modules = all([osp.splitext(_fn)[1] in ('.py', '.pyw', '.ipy')
for _fn in fnames])
only_notebooks = all([osp.splitext(_fn)[1] == '.ipynb'
for _fn in fnames])
only_valid = all([encoding.is_text_file(_fn) for _fn in fnames])
run_action = create_action(self, _("Run"), icon=ima.icon('run'),
triggered=self.run)
edit_action = create_action(self, _("Edit"), icon=ima.icon('edit'),
triggered=self.clicked)
move_action = create_action(self, _("Move..."),
icon="move.png",
triggered=self.move)
delete_action = create_action(self, _("Delete..."),
icon=ima.icon('editdelete'),
triggered=self.delete)
rename_action = create_action(self, _("Rename..."),
icon=ima.icon('rename'),
triggered=self.rename)
open_external_action = create_action(self, _("Open With OS"),
triggered=self.open_external)
ipynb_convert_action = create_action(self, _("Convert to Python script"),
icon=ima.icon('python'),
triggered=self.convert_notebooks)
copy_file_clipboard_action = (
create_action(self, _("Copy"),
QKeySequence(get_shortcut('explorer', 'copy file')),
icon=ima.icon('editcopy'),
triggered=self.copy_file_clipboard))
save_file_clipboard_action = (
create_action(self, _("Paste"),
QKeySequence(get_shortcut('explorer', 'paste file')),
icon=ima.icon('editpaste'),
triggered=self.save_file_clipboard))
copy_absolute_path_action = (
create_action(self, _("Copy Absolute Path"), QKeySequence(
get_shortcut('explorer', 'copy absolute path')),
triggered=self.copy_absolute_path))
copy_relative_path_action = (
create_action(self, _("Copy Relative Path"), QKeySequence(
get_shortcut('explorer', 'copy relative path')),
triggered=self.copy_relative_path))
actions = []
if only_modules:
actions.append(run_action)
if only_valid and only_files:
actions.append(edit_action)
if sys.platform == 'darwin':
text=_("Show in Finder")
else:
text=_("Show in Folder")
external_fileexp_action = create_action(self, text,
triggered=self.show_in_external_file_explorer)
actions += [delete_action, rename_action]
basedir = fixpath(osp.dirname(fnames[0]))
if all([fixpath(osp.dirname(_fn)) == basedir for _fn in fnames]):
actions.append(move_action)
actions += [None]
actions += [copy_file_clipboard_action, save_file_clipboard_action,
copy_absolute_path_action, copy_relative_path_action]
if not QApplication.clipboard().mimeData().hasUrls():
save_file_clipboard_action.setDisabled(True)
actions += [None]
if only_files:
actions.append(open_external_action)
actions.append(external_fileexp_action)
actions.append([None])
if only_notebooks and nbexporter is not None:
actions.append(ipynb_convert_action)
# VCS support is quite limited for now, so we are enabling the VCS
# related actions only when a single file/folder is selected:
dirname = fnames[0] if osp.isdir(fnames[0]) else osp.dirname(fnames[0])
if len(fnames) == 1 and vcs.is_vcs_repository(dirname):
commit_slot = lambda : self.vcs_command([dirname], 'commit')
browse_slot = lambda : self.vcs_command([dirname], 'browse')
vcs_ci = create_action(self, _("Commit"),
icon=ima.icon('vcs_commit'),
triggered=commit_slot)
vcs_log = create_action(self, _("Browse repository"),
icon=ima.icon('vcs_browse'),
triggered=browse_slot)
actions += [None, vcs_ci, vcs_log]
return actions | [
"def",
"create_file_manage_actions",
"(",
"self",
",",
"fnames",
")",
":",
"only_files",
"=",
"all",
"(",
"[",
"osp",
".",
"isfile",
"(",
"_fn",
")",
"for",
"_fn",
"in",
"fnames",
"]",
")",
"only_modules",
"=",
"all",
"(",
"[",
"osp",
".",
"splitext",
"(",
"_fn",
")",
"[",
"1",
"]",
"in",
"(",
"'.py'",
",",
"'.pyw'",
",",
"'.ipy'",
")",
"for",
"_fn",
"in",
"fnames",
"]",
")",
"only_notebooks",
"=",
"all",
"(",
"[",
"osp",
".",
"splitext",
"(",
"_fn",
")",
"[",
"1",
"]",
"==",
"'.ipynb'",
"for",
"_fn",
"in",
"fnames",
"]",
")",
"only_valid",
"=",
"all",
"(",
"[",
"encoding",
".",
"is_text_file",
"(",
"_fn",
")",
"for",
"_fn",
"in",
"fnames",
"]",
")",
"run_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Run\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'run'",
")",
",",
"triggered",
"=",
"self",
".",
"run",
")",
"edit_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Edit\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'edit'",
")",
",",
"triggered",
"=",
"self",
".",
"clicked",
")",
"move_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Move...\"",
")",
",",
"icon",
"=",
"\"move.png\"",
",",
"triggered",
"=",
"self",
".",
"move",
")",
"delete_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Delete...\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'editdelete'",
")",
",",
"triggered",
"=",
"self",
".",
"delete",
")",
"rename_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Rename...\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'rename'",
")",
",",
"triggered",
"=",
"self",
".",
"rename",
")",
"open_external_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Open With OS\"",
")",
",",
"triggered",
"=",
"self",
".",
"open_external",
")",
"ipynb_convert_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Convert to Python script\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'python'",
")",
",",
"triggered",
"=",
"self",
".",
"convert_notebooks",
")",
"copy_file_clipboard_action",
"=",
"(",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Copy\"",
")",
",",
"QKeySequence",
"(",
"get_shortcut",
"(",
"'explorer'",
",",
"'copy file'",
")",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'editcopy'",
")",
",",
"triggered",
"=",
"self",
".",
"copy_file_clipboard",
")",
")",
"save_file_clipboard_action",
"=",
"(",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Paste\"",
")",
",",
"QKeySequence",
"(",
"get_shortcut",
"(",
"'explorer'",
",",
"'paste file'",
")",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'editpaste'",
")",
",",
"triggered",
"=",
"self",
".",
"save_file_clipboard",
")",
")",
"copy_absolute_path_action",
"=",
"(",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Copy Absolute Path\"",
")",
",",
"QKeySequence",
"(",
"get_shortcut",
"(",
"'explorer'",
",",
"'copy absolute path'",
")",
")",
",",
"triggered",
"=",
"self",
".",
"copy_absolute_path",
")",
")",
"copy_relative_path_action",
"=",
"(",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Copy Relative Path\"",
")",
",",
"QKeySequence",
"(",
"get_shortcut",
"(",
"'explorer'",
",",
"'copy relative path'",
")",
")",
",",
"triggered",
"=",
"self",
".",
"copy_relative_path",
")",
")",
"actions",
"=",
"[",
"]",
"if",
"only_modules",
":",
"actions",
".",
"append",
"(",
"run_action",
")",
"if",
"only_valid",
"and",
"only_files",
":",
"actions",
".",
"append",
"(",
"edit_action",
")",
"if",
"sys",
".",
"platform",
"==",
"'darwin'",
":",
"text",
"=",
"_",
"(",
"\"Show in Finder\"",
")",
"else",
":",
"text",
"=",
"_",
"(",
"\"Show in Folder\"",
")",
"external_fileexp_action",
"=",
"create_action",
"(",
"self",
",",
"text",
",",
"triggered",
"=",
"self",
".",
"show_in_external_file_explorer",
")",
"actions",
"+=",
"[",
"delete_action",
",",
"rename_action",
"]",
"basedir",
"=",
"fixpath",
"(",
"osp",
".",
"dirname",
"(",
"fnames",
"[",
"0",
"]",
")",
")",
"if",
"all",
"(",
"[",
"fixpath",
"(",
"osp",
".",
"dirname",
"(",
"_fn",
")",
")",
"==",
"basedir",
"for",
"_fn",
"in",
"fnames",
"]",
")",
":",
"actions",
".",
"append",
"(",
"move_action",
")",
"actions",
"+=",
"[",
"None",
"]",
"actions",
"+=",
"[",
"copy_file_clipboard_action",
",",
"save_file_clipboard_action",
",",
"copy_absolute_path_action",
",",
"copy_relative_path_action",
"]",
"if",
"not",
"QApplication",
".",
"clipboard",
"(",
")",
".",
"mimeData",
"(",
")",
".",
"hasUrls",
"(",
")",
":",
"save_file_clipboard_action",
".",
"setDisabled",
"(",
"True",
")",
"actions",
"+=",
"[",
"None",
"]",
"if",
"only_files",
":",
"actions",
".",
"append",
"(",
"open_external_action",
")",
"actions",
".",
"append",
"(",
"external_fileexp_action",
")",
"actions",
".",
"append",
"(",
"[",
"None",
"]",
")",
"if",
"only_notebooks",
"and",
"nbexporter",
"is",
"not",
"None",
":",
"actions",
".",
"append",
"(",
"ipynb_convert_action",
")",
"# VCS support is quite limited for now, so we are enabling the VCS\r",
"# related actions only when a single file/folder is selected:\r",
"dirname",
"=",
"fnames",
"[",
"0",
"]",
"if",
"osp",
".",
"isdir",
"(",
"fnames",
"[",
"0",
"]",
")",
"else",
"osp",
".",
"dirname",
"(",
"fnames",
"[",
"0",
"]",
")",
"if",
"len",
"(",
"fnames",
")",
"==",
"1",
"and",
"vcs",
".",
"is_vcs_repository",
"(",
"dirname",
")",
":",
"commit_slot",
"=",
"lambda",
":",
"self",
".",
"vcs_command",
"(",
"[",
"dirname",
"]",
",",
"'commit'",
")",
"browse_slot",
"=",
"lambda",
":",
"self",
".",
"vcs_command",
"(",
"[",
"dirname",
"]",
",",
"'browse'",
")",
"vcs_ci",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Commit\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'vcs_commit'",
")",
",",
"triggered",
"=",
"commit_slot",
")",
"vcs_log",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Browse repository\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'vcs_browse'",
")",
",",
"triggered",
"=",
"browse_slot",
")",
"actions",
"+=",
"[",
"None",
",",
"vcs_ci",
",",
"vcs_log",
"]",
"return",
"actions"
] | Return file management actions | [
"Return",
"file",
"management",
"actions"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L324-L412 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.create_folder_manage_actions | def create_folder_manage_actions(self, fnames):
"""Return folder management actions"""
actions = []
if os.name == 'nt':
_title = _("Open command prompt here")
else:
_title = _("Open terminal here")
_title = _("Open IPython console here")
action = create_action(self, _title,
triggered=lambda:
self.open_interpreter(fnames))
actions.append(action)
return actions | python | def create_folder_manage_actions(self, fnames):
"""Return folder management actions"""
actions = []
if os.name == 'nt':
_title = _("Open command prompt here")
else:
_title = _("Open terminal here")
_title = _("Open IPython console here")
action = create_action(self, _title,
triggered=lambda:
self.open_interpreter(fnames))
actions.append(action)
return actions | [
"def",
"create_folder_manage_actions",
"(",
"self",
",",
"fnames",
")",
":",
"actions",
"=",
"[",
"]",
"if",
"os",
".",
"name",
"==",
"'nt'",
":",
"_title",
"=",
"_",
"(",
"\"Open command prompt here\"",
")",
"else",
":",
"_title",
"=",
"_",
"(",
"\"Open terminal here\"",
")",
"_title",
"=",
"_",
"(",
"\"Open IPython console here\"",
")",
"action",
"=",
"create_action",
"(",
"self",
",",
"_title",
",",
"triggered",
"=",
"lambda",
":",
"self",
".",
"open_interpreter",
"(",
"fnames",
")",
")",
"actions",
".",
"append",
"(",
"action",
")",
"return",
"actions"
] | Return folder management actions | [
"Return",
"folder",
"management",
"actions"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L414-L426 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.create_context_menu_actions | def create_context_menu_actions(self):
"""Create context menu actions"""
actions = []
fnames = self.get_selected_filenames()
new_actions = self.create_file_new_actions(fnames)
if len(new_actions) > 1:
# Creating a submenu only if there is more than one entry
new_act_menu = QMenu(_('New'), self)
add_actions(new_act_menu, new_actions)
actions.append(new_act_menu)
else:
actions += new_actions
import_actions = self.create_file_import_actions(fnames)
if len(import_actions) > 1:
# Creating a submenu only if there is more than one entry
import_act_menu = QMenu(_('Import'), self)
add_actions(import_act_menu, import_actions)
actions.append(import_act_menu)
else:
actions += import_actions
if actions:
actions.append(None)
if fnames:
actions += self.create_file_manage_actions(fnames)
if actions:
actions.append(None)
if fnames and all([osp.isdir(_fn) for _fn in fnames]):
actions += self.create_folder_manage_actions(fnames)
return actions | python | def create_context_menu_actions(self):
"""Create context menu actions"""
actions = []
fnames = self.get_selected_filenames()
new_actions = self.create_file_new_actions(fnames)
if len(new_actions) > 1:
# Creating a submenu only if there is more than one entry
new_act_menu = QMenu(_('New'), self)
add_actions(new_act_menu, new_actions)
actions.append(new_act_menu)
else:
actions += new_actions
import_actions = self.create_file_import_actions(fnames)
if len(import_actions) > 1:
# Creating a submenu only if there is more than one entry
import_act_menu = QMenu(_('Import'), self)
add_actions(import_act_menu, import_actions)
actions.append(import_act_menu)
else:
actions += import_actions
if actions:
actions.append(None)
if fnames:
actions += self.create_file_manage_actions(fnames)
if actions:
actions.append(None)
if fnames and all([osp.isdir(_fn) for _fn in fnames]):
actions += self.create_folder_manage_actions(fnames)
return actions | [
"def",
"create_context_menu_actions",
"(",
"self",
")",
":",
"actions",
"=",
"[",
"]",
"fnames",
"=",
"self",
".",
"get_selected_filenames",
"(",
")",
"new_actions",
"=",
"self",
".",
"create_file_new_actions",
"(",
"fnames",
")",
"if",
"len",
"(",
"new_actions",
")",
">",
"1",
":",
"# Creating a submenu only if there is more than one entry\r",
"new_act_menu",
"=",
"QMenu",
"(",
"_",
"(",
"'New'",
")",
",",
"self",
")",
"add_actions",
"(",
"new_act_menu",
",",
"new_actions",
")",
"actions",
".",
"append",
"(",
"new_act_menu",
")",
"else",
":",
"actions",
"+=",
"new_actions",
"import_actions",
"=",
"self",
".",
"create_file_import_actions",
"(",
"fnames",
")",
"if",
"len",
"(",
"import_actions",
")",
">",
"1",
":",
"# Creating a submenu only if there is more than one entry\r",
"import_act_menu",
"=",
"QMenu",
"(",
"_",
"(",
"'Import'",
")",
",",
"self",
")",
"add_actions",
"(",
"import_act_menu",
",",
"import_actions",
")",
"actions",
".",
"append",
"(",
"import_act_menu",
")",
"else",
":",
"actions",
"+=",
"import_actions",
"if",
"actions",
":",
"actions",
".",
"append",
"(",
"None",
")",
"if",
"fnames",
":",
"actions",
"+=",
"self",
".",
"create_file_manage_actions",
"(",
"fnames",
")",
"if",
"actions",
":",
"actions",
".",
"append",
"(",
"None",
")",
"if",
"fnames",
"and",
"all",
"(",
"[",
"osp",
".",
"isdir",
"(",
"_fn",
")",
"for",
"_fn",
"in",
"fnames",
"]",
")",
":",
"actions",
"+=",
"self",
".",
"create_folder_manage_actions",
"(",
"fnames",
")",
"return",
"actions"
] | Create context menu actions | [
"Create",
"context",
"menu",
"actions"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L428-L456 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.update_menu | def update_menu(self):
"""Update context menu"""
self.menu.clear()
add_actions(self.menu, self.create_context_menu_actions()) | python | def update_menu(self):
"""Update context menu"""
self.menu.clear()
add_actions(self.menu, self.create_context_menu_actions()) | [
"def",
"update_menu",
"(",
"self",
")",
":",
"self",
".",
"menu",
".",
"clear",
"(",
")",
"add_actions",
"(",
"self",
".",
"menu",
",",
"self",
".",
"create_context_menu_actions",
"(",
")",
")"
] | Update context menu | [
"Update",
"context",
"menu"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L458-L461 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.keyPressEvent | def keyPressEvent(self, event):
"""Reimplement Qt method"""
if event.key() in (Qt.Key_Enter, Qt.Key_Return):
self.clicked()
elif event.key() == Qt.Key_F2:
self.rename()
elif event.key() == Qt.Key_Delete:
self.delete()
elif event.key() == Qt.Key_Backspace:
self.go_to_parent_directory()
else:
QTreeView.keyPressEvent(self, event) | python | def keyPressEvent(self, event):
"""Reimplement Qt method"""
if event.key() in (Qt.Key_Enter, Qt.Key_Return):
self.clicked()
elif event.key() == Qt.Key_F2:
self.rename()
elif event.key() == Qt.Key_Delete:
self.delete()
elif event.key() == Qt.Key_Backspace:
self.go_to_parent_directory()
else:
QTreeView.keyPressEvent(self, event) | [
"def",
"keyPressEvent",
"(",
"self",
",",
"event",
")",
":",
"if",
"event",
".",
"key",
"(",
")",
"in",
"(",
"Qt",
".",
"Key_Enter",
",",
"Qt",
".",
"Key_Return",
")",
":",
"self",
".",
"clicked",
"(",
")",
"elif",
"event",
".",
"key",
"(",
")",
"==",
"Qt",
".",
"Key_F2",
":",
"self",
".",
"rename",
"(",
")",
"elif",
"event",
".",
"key",
"(",
")",
"==",
"Qt",
".",
"Key_Delete",
":",
"self",
".",
"delete",
"(",
")",
"elif",
"event",
".",
"key",
"(",
")",
"==",
"Qt",
".",
"Key_Backspace",
":",
"self",
".",
"go_to_parent_directory",
"(",
")",
"else",
":",
"QTreeView",
".",
"keyPressEvent",
"(",
"self",
",",
"event",
")"
] | Reimplement Qt method | [
"Reimplement",
"Qt",
"method"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L490-L501 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.mouseReleaseEvent | def mouseReleaseEvent(self, event):
"""Reimplement Qt method."""
QTreeView.mouseReleaseEvent(self, event)
if self.single_click_to_open:
self.clicked() | python | def mouseReleaseEvent(self, event):
"""Reimplement Qt method."""
QTreeView.mouseReleaseEvent(self, event)
if self.single_click_to_open:
self.clicked() | [
"def",
"mouseReleaseEvent",
"(",
"self",
",",
"event",
")",
":",
"QTreeView",
".",
"mouseReleaseEvent",
"(",
"self",
",",
"event",
")",
"if",
"self",
".",
"single_click_to_open",
":",
"self",
".",
"clicked",
"(",
")"
] | Reimplement Qt method. | [
"Reimplement",
"Qt",
"method",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L508-L512 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.clicked | def clicked(self):
"""Selected item was double-clicked or enter/return was pressed"""
fnames = self.get_selected_filenames()
for fname in fnames:
if osp.isdir(fname):
self.directory_clicked(fname)
else:
self.open([fname]) | python | def clicked(self):
"""Selected item was double-clicked or enter/return was pressed"""
fnames = self.get_selected_filenames()
for fname in fnames:
if osp.isdir(fname):
self.directory_clicked(fname)
else:
self.open([fname]) | [
"def",
"clicked",
"(",
"self",
")",
":",
"fnames",
"=",
"self",
".",
"get_selected_filenames",
"(",
")",
"for",
"fname",
"in",
"fnames",
":",
"if",
"osp",
".",
"isdir",
"(",
"fname",
")",
":",
"self",
".",
"directory_clicked",
"(",
"fname",
")",
"else",
":",
"self",
".",
"open",
"(",
"[",
"fname",
"]",
")"
] | Selected item was double-clicked or enter/return was pressed | [
"Selected",
"item",
"was",
"double",
"-",
"clicked",
"or",
"enter",
"/",
"return",
"was",
"pressed"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L515-L522 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.dragMoveEvent | def dragMoveEvent(self, event):
"""Drag and Drop - Move event"""
if (event.mimeData().hasFormat("text/plain")):
event.setDropAction(Qt.MoveAction)
event.accept()
else:
event.ignore() | python | def dragMoveEvent(self, event):
"""Drag and Drop - Move event"""
if (event.mimeData().hasFormat("text/plain")):
event.setDropAction(Qt.MoveAction)
event.accept()
else:
event.ignore() | [
"def",
"dragMoveEvent",
"(",
"self",
",",
"event",
")",
":",
"if",
"(",
"event",
".",
"mimeData",
"(",
")",
".",
"hasFormat",
"(",
"\"text/plain\"",
")",
")",
":",
"event",
".",
"setDropAction",
"(",
"Qt",
".",
"MoveAction",
")",
"event",
".",
"accept",
"(",
")",
"else",
":",
"event",
".",
"ignore",
"(",
")"
] | Drag and Drop - Move event | [
"Drag",
"and",
"Drop",
"-",
"Move",
"event"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L533-L539 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.startDrag | def startDrag(self, dropActions):
"""Reimplement Qt Method - handle drag event"""
data = QMimeData()
data.setUrls([QUrl(fname) for fname in self.get_selected_filenames()])
drag = QDrag(self)
drag.setMimeData(data)
drag.exec_() | python | def startDrag(self, dropActions):
"""Reimplement Qt Method - handle drag event"""
data = QMimeData()
data.setUrls([QUrl(fname) for fname in self.get_selected_filenames()])
drag = QDrag(self)
drag.setMimeData(data)
drag.exec_() | [
"def",
"startDrag",
"(",
"self",
",",
"dropActions",
")",
":",
"data",
"=",
"QMimeData",
"(",
")",
"data",
".",
"setUrls",
"(",
"[",
"QUrl",
"(",
"fname",
")",
"for",
"fname",
"in",
"self",
".",
"get_selected_filenames",
"(",
")",
"]",
")",
"drag",
"=",
"QDrag",
"(",
"self",
")",
"drag",
".",
"setMimeData",
"(",
"data",
")",
"drag",
".",
"exec_",
"(",
")"
] | Reimplement Qt Method - handle drag event | [
"Reimplement",
"Qt",
"Method",
"-",
"handle",
"drag",
"event"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L541-L547 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.open | def open(self, fnames=None):
"""Open files with the appropriate application"""
if fnames is None:
fnames = self.get_selected_filenames()
for fname in fnames:
if osp.isfile(fname) and encoding.is_text_file(fname):
self.parent_widget.sig_open_file.emit(fname)
else:
self.open_outside_spyder([fname]) | python | def open(self, fnames=None):
"""Open files with the appropriate application"""
if fnames is None:
fnames = self.get_selected_filenames()
for fname in fnames:
if osp.isfile(fname) and encoding.is_text_file(fname):
self.parent_widget.sig_open_file.emit(fname)
else:
self.open_outside_spyder([fname]) | [
"def",
"open",
"(",
"self",
",",
"fnames",
"=",
"None",
")",
":",
"if",
"fnames",
"is",
"None",
":",
"fnames",
"=",
"self",
".",
"get_selected_filenames",
"(",
")",
"for",
"fname",
"in",
"fnames",
":",
"if",
"osp",
".",
"isfile",
"(",
"fname",
")",
"and",
"encoding",
".",
"is_text_file",
"(",
"fname",
")",
":",
"self",
".",
"parent_widget",
".",
"sig_open_file",
".",
"emit",
"(",
"fname",
")",
"else",
":",
"self",
".",
"open_outside_spyder",
"(",
"[",
"fname",
"]",
")"
] | Open files with the appropriate application | [
"Open",
"files",
"with",
"the",
"appropriate",
"application"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L551-L559 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.open_external | def open_external(self, fnames=None):
"""Open files with default application"""
if fnames is None:
fnames = self.get_selected_filenames()
for fname in fnames:
self.open_outside_spyder([fname]) | python | def open_external(self, fnames=None):
"""Open files with default application"""
if fnames is None:
fnames = self.get_selected_filenames()
for fname in fnames:
self.open_outside_spyder([fname]) | [
"def",
"open_external",
"(",
"self",
",",
"fnames",
"=",
"None",
")",
":",
"if",
"fnames",
"is",
"None",
":",
"fnames",
"=",
"self",
".",
"get_selected_filenames",
"(",
")",
"for",
"fname",
"in",
"fnames",
":",
"self",
".",
"open_outside_spyder",
"(",
"[",
"fname",
"]",
")"
] | Open files with default application | [
"Open",
"files",
"with",
"default",
"application"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L562-L567 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.open_outside_spyder | def open_outside_spyder(self, fnames):
"""Open file outside Spyder with the appropriate application
If this does not work, opening unknown file in Spyder, as text file"""
for path in sorted(fnames):
path = file_uri(path)
ok = programs.start_file(path)
if not ok:
self.sig_edit.emit(path) | python | def open_outside_spyder(self, fnames):
"""Open file outside Spyder with the appropriate application
If this does not work, opening unknown file in Spyder, as text file"""
for path in sorted(fnames):
path = file_uri(path)
ok = programs.start_file(path)
if not ok:
self.sig_edit.emit(path) | [
"def",
"open_outside_spyder",
"(",
"self",
",",
"fnames",
")",
":",
"for",
"path",
"in",
"sorted",
"(",
"fnames",
")",
":",
"path",
"=",
"file_uri",
"(",
"path",
")",
"ok",
"=",
"programs",
".",
"start_file",
"(",
"path",
")",
"if",
"not",
"ok",
":",
"self",
".",
"sig_edit",
".",
"emit",
"(",
"path",
")"
] | Open file outside Spyder with the appropriate application
If this does not work, opening unknown file in Spyder, as text file | [
"Open",
"file",
"outside",
"Spyder",
"with",
"the",
"appropriate",
"application",
"If",
"this",
"does",
"not",
"work",
"opening",
"unknown",
"file",
"in",
"Spyder",
"as",
"text",
"file"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L569-L576 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.open_interpreter | def open_interpreter(self, fnames):
"""Open interpreter"""
for path in sorted(fnames):
self.sig_open_interpreter.emit(path) | python | def open_interpreter(self, fnames):
"""Open interpreter"""
for path in sorted(fnames):
self.sig_open_interpreter.emit(path) | [
"def",
"open_interpreter",
"(",
"self",
",",
"fnames",
")",
":",
"for",
"path",
"in",
"sorted",
"(",
"fnames",
")",
":",
"self",
".",
"sig_open_interpreter",
".",
"emit",
"(",
"path",
")"
] | Open interpreter | [
"Open",
"interpreter"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L578-L581 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.run | def run(self, fnames=None):
"""Run Python scripts"""
if fnames is None:
fnames = self.get_selected_filenames()
for fname in fnames:
self.sig_run.emit(fname) | python | def run(self, fnames=None):
"""Run Python scripts"""
if fnames is None:
fnames = self.get_selected_filenames()
for fname in fnames:
self.sig_run.emit(fname) | [
"def",
"run",
"(",
"self",
",",
"fnames",
"=",
"None",
")",
":",
"if",
"fnames",
"is",
"None",
":",
"fnames",
"=",
"self",
".",
"get_selected_filenames",
"(",
")",
"for",
"fname",
"in",
"fnames",
":",
"self",
".",
"sig_run",
".",
"emit",
"(",
"fname",
")"
] | Run Python scripts | [
"Run",
"Python",
"scripts"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L584-L589 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.remove_tree | def remove_tree(self, dirname):
"""Remove whole directory tree
Reimplemented in project explorer widget"""
while osp.exists(dirname):
try:
shutil.rmtree(dirname, onerror=misc.onerror)
except Exception as e:
# This handles a Windows problem with shutil.rmtree.
# See issue #8567.
if type(e).__name__ == "OSError":
error_path = to_text_string(e.filename)
shutil.rmtree(error_path, ignore_errors=True) | python | def remove_tree(self, dirname):
"""Remove whole directory tree
Reimplemented in project explorer widget"""
while osp.exists(dirname):
try:
shutil.rmtree(dirname, onerror=misc.onerror)
except Exception as e:
# This handles a Windows problem with shutil.rmtree.
# See issue #8567.
if type(e).__name__ == "OSError":
error_path = to_text_string(e.filename)
shutil.rmtree(error_path, ignore_errors=True) | [
"def",
"remove_tree",
"(",
"self",
",",
"dirname",
")",
":",
"while",
"osp",
".",
"exists",
"(",
"dirname",
")",
":",
"try",
":",
"shutil",
".",
"rmtree",
"(",
"dirname",
",",
"onerror",
"=",
"misc",
".",
"onerror",
")",
"except",
"Exception",
"as",
"e",
":",
"# This handles a Windows problem with shutil.rmtree.\r",
"# See issue #8567.\r",
"if",
"type",
"(",
"e",
")",
".",
"__name__",
"==",
"\"OSError\"",
":",
"error_path",
"=",
"to_text_string",
"(",
"e",
".",
"filename",
")",
"shutil",
".",
"rmtree",
"(",
"error_path",
",",
"ignore_errors",
"=",
"True",
")"
] | Remove whole directory tree
Reimplemented in project explorer widget | [
"Remove",
"whole",
"directory",
"tree",
"Reimplemented",
"in",
"project",
"explorer",
"widget"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L591-L602 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.delete_file | def delete_file(self, fname, multiple, yes_to_all):
"""Delete file"""
if multiple:
buttons = QMessageBox.Yes|QMessageBox.YesToAll| \
QMessageBox.No|QMessageBox.Cancel
else:
buttons = QMessageBox.Yes|QMessageBox.No
if yes_to_all is None:
answer = QMessageBox.warning(self, _("Delete"),
_("Do you really want "
"to delete <b>%s</b>?"
) % osp.basename(fname), buttons)
if answer == QMessageBox.No:
return yes_to_all
elif answer == QMessageBox.Cancel:
return False
elif answer == QMessageBox.YesToAll:
yes_to_all = True
try:
if osp.isfile(fname):
misc.remove_file(fname)
self.sig_removed.emit(fname)
else:
self.remove_tree(fname)
self.sig_removed_tree.emit(fname)
return yes_to_all
except EnvironmentError as error:
action_str = _('delete')
QMessageBox.critical(self, _("Project Explorer"),
_("<b>Unable to %s <i>%s</i></b>"
"<br><br>Error message:<br>%s"
) % (action_str, fname, to_text_string(error)))
return False | python | def delete_file(self, fname, multiple, yes_to_all):
"""Delete file"""
if multiple:
buttons = QMessageBox.Yes|QMessageBox.YesToAll| \
QMessageBox.No|QMessageBox.Cancel
else:
buttons = QMessageBox.Yes|QMessageBox.No
if yes_to_all is None:
answer = QMessageBox.warning(self, _("Delete"),
_("Do you really want "
"to delete <b>%s</b>?"
) % osp.basename(fname), buttons)
if answer == QMessageBox.No:
return yes_to_all
elif answer == QMessageBox.Cancel:
return False
elif answer == QMessageBox.YesToAll:
yes_to_all = True
try:
if osp.isfile(fname):
misc.remove_file(fname)
self.sig_removed.emit(fname)
else:
self.remove_tree(fname)
self.sig_removed_tree.emit(fname)
return yes_to_all
except EnvironmentError as error:
action_str = _('delete')
QMessageBox.critical(self, _("Project Explorer"),
_("<b>Unable to %s <i>%s</i></b>"
"<br><br>Error message:<br>%s"
) % (action_str, fname, to_text_string(error)))
return False | [
"def",
"delete_file",
"(",
"self",
",",
"fname",
",",
"multiple",
",",
"yes_to_all",
")",
":",
"if",
"multiple",
":",
"buttons",
"=",
"QMessageBox",
".",
"Yes",
"|",
"QMessageBox",
".",
"YesToAll",
"|",
"QMessageBox",
".",
"No",
"|",
"QMessageBox",
".",
"Cancel",
"else",
":",
"buttons",
"=",
"QMessageBox",
".",
"Yes",
"|",
"QMessageBox",
".",
"No",
"if",
"yes_to_all",
"is",
"None",
":",
"answer",
"=",
"QMessageBox",
".",
"warning",
"(",
"self",
",",
"_",
"(",
"\"Delete\"",
")",
",",
"_",
"(",
"\"Do you really want \"",
"\"to delete <b>%s</b>?\"",
")",
"%",
"osp",
".",
"basename",
"(",
"fname",
")",
",",
"buttons",
")",
"if",
"answer",
"==",
"QMessageBox",
".",
"No",
":",
"return",
"yes_to_all",
"elif",
"answer",
"==",
"QMessageBox",
".",
"Cancel",
":",
"return",
"False",
"elif",
"answer",
"==",
"QMessageBox",
".",
"YesToAll",
":",
"yes_to_all",
"=",
"True",
"try",
":",
"if",
"osp",
".",
"isfile",
"(",
"fname",
")",
":",
"misc",
".",
"remove_file",
"(",
"fname",
")",
"self",
".",
"sig_removed",
".",
"emit",
"(",
"fname",
")",
"else",
":",
"self",
".",
"remove_tree",
"(",
"fname",
")",
"self",
".",
"sig_removed_tree",
".",
"emit",
"(",
"fname",
")",
"return",
"yes_to_all",
"except",
"EnvironmentError",
"as",
"error",
":",
"action_str",
"=",
"_",
"(",
"'delete'",
")",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"\"Project Explorer\"",
")",
",",
"_",
"(",
"\"<b>Unable to %s <i>%s</i></b>\"",
"\"<br><br>Error message:<br>%s\"",
")",
"%",
"(",
"action_str",
",",
"fname",
",",
"to_text_string",
"(",
"error",
")",
")",
")",
"return",
"False"
] | Delete file | [
"Delete",
"file"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L604-L636 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.delete | def delete(self, fnames=None):
"""Delete files"""
if fnames is None:
fnames = self.get_selected_filenames()
multiple = len(fnames) > 1
yes_to_all = None
for fname in fnames:
spyproject_path = osp.join(fname,'.spyproject')
if osp.isdir(fname) and osp.exists(spyproject_path):
QMessageBox.information(self, _('File Explorer'),
_("The current directory contains a "
"project.<br><br>"
"If you want to delete"
" the project, please go to "
"<b>Projects</b> » <b>Delete "
"Project</b>"))
else:
yes_to_all = self.delete_file(fname, multiple, yes_to_all)
if yes_to_all is not None and not yes_to_all:
# Canceled
break | python | def delete(self, fnames=None):
"""Delete files"""
if fnames is None:
fnames = self.get_selected_filenames()
multiple = len(fnames) > 1
yes_to_all = None
for fname in fnames:
spyproject_path = osp.join(fname,'.spyproject')
if osp.isdir(fname) and osp.exists(spyproject_path):
QMessageBox.information(self, _('File Explorer'),
_("The current directory contains a "
"project.<br><br>"
"If you want to delete"
" the project, please go to "
"<b>Projects</b> » <b>Delete "
"Project</b>"))
else:
yes_to_all = self.delete_file(fname, multiple, yes_to_all)
if yes_to_all is not None and not yes_to_all:
# Canceled
break | [
"def",
"delete",
"(",
"self",
",",
"fnames",
"=",
"None",
")",
":",
"if",
"fnames",
"is",
"None",
":",
"fnames",
"=",
"self",
".",
"get_selected_filenames",
"(",
")",
"multiple",
"=",
"len",
"(",
"fnames",
")",
">",
"1",
"yes_to_all",
"=",
"None",
"for",
"fname",
"in",
"fnames",
":",
"spyproject_path",
"=",
"osp",
".",
"join",
"(",
"fname",
",",
"'.spyproject'",
")",
"if",
"osp",
".",
"isdir",
"(",
"fname",
")",
"and",
"osp",
".",
"exists",
"(",
"spyproject_path",
")",
":",
"QMessageBox",
".",
"information",
"(",
"self",
",",
"_",
"(",
"'File Explorer'",
")",
",",
"_",
"(",
"\"The current directory contains a \"",
"\"project.<br><br>\"",
"\"If you want to delete\"",
"\" the project, please go to \"",
"\"<b>Projects</b> » <b>Delete \"",
"\"Project</b>\"",
")",
")",
"else",
":",
"yes_to_all",
"=",
"self",
".",
"delete_file",
"(",
"fname",
",",
"multiple",
",",
"yes_to_all",
")",
"if",
"yes_to_all",
"is",
"not",
"None",
"and",
"not",
"yes_to_all",
":",
"# Canceled\r",
"break"
] | Delete files | [
"Delete",
"files"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L639-L659 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.convert_notebook | def convert_notebook(self, fname):
"""Convert an IPython notebook to a Python script in editor"""
try:
script = nbexporter().from_filename(fname)[0]
except Exception as e:
QMessageBox.critical(self, _('Conversion error'),
_("It was not possible to convert this "
"notebook. The error is:\n\n") + \
to_text_string(e))
return
self.sig_new_file.emit(script) | python | def convert_notebook(self, fname):
"""Convert an IPython notebook to a Python script in editor"""
try:
script = nbexporter().from_filename(fname)[0]
except Exception as e:
QMessageBox.critical(self, _('Conversion error'),
_("It was not possible to convert this "
"notebook. The error is:\n\n") + \
to_text_string(e))
return
self.sig_new_file.emit(script) | [
"def",
"convert_notebook",
"(",
"self",
",",
"fname",
")",
":",
"try",
":",
"script",
"=",
"nbexporter",
"(",
")",
".",
"from_filename",
"(",
"fname",
")",
"[",
"0",
"]",
"except",
"Exception",
"as",
"e",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"'Conversion error'",
")",
",",
"_",
"(",
"\"It was not possible to convert this \"",
"\"notebook. The error is:\\n\\n\"",
")",
"+",
"to_text_string",
"(",
"e",
")",
")",
"return",
"self",
".",
"sig_new_file",
".",
"emit",
"(",
"script",
")"
] | Convert an IPython notebook to a Python script in editor | [
"Convert",
"an",
"IPython",
"notebook",
"to",
"a",
"Python",
"script",
"in",
"editor"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L661-L671 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.convert_notebooks | def convert_notebooks(self):
"""Convert IPython notebooks to Python scripts in editor"""
fnames = self.get_selected_filenames()
if not isinstance(fnames, (tuple, list)):
fnames = [fnames]
for fname in fnames:
self.convert_notebook(fname) | python | def convert_notebooks(self):
"""Convert IPython notebooks to Python scripts in editor"""
fnames = self.get_selected_filenames()
if not isinstance(fnames, (tuple, list)):
fnames = [fnames]
for fname in fnames:
self.convert_notebook(fname) | [
"def",
"convert_notebooks",
"(",
"self",
")",
":",
"fnames",
"=",
"self",
".",
"get_selected_filenames",
"(",
")",
"if",
"not",
"isinstance",
"(",
"fnames",
",",
"(",
"tuple",
",",
"list",
")",
")",
":",
"fnames",
"=",
"[",
"fnames",
"]",
"for",
"fname",
"in",
"fnames",
":",
"self",
".",
"convert_notebook",
"(",
"fname",
")"
] | Convert IPython notebooks to Python scripts in editor | [
"Convert",
"IPython",
"notebooks",
"to",
"Python",
"scripts",
"in",
"editor"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L674-L680 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.rename_file | def rename_file(self, fname):
"""Rename file"""
path, valid = QInputDialog.getText(self, _('Rename'),
_('New name:'), QLineEdit.Normal,
osp.basename(fname))
if valid:
path = osp.join(osp.dirname(fname), to_text_string(path))
if path == fname:
return
if osp.exists(path):
if QMessageBox.warning(self, _("Rename"),
_("Do you really want to rename <b>%s</b> and "
"overwrite the existing file <b>%s</b>?"
) % (osp.basename(fname), osp.basename(path)),
QMessageBox.Yes|QMessageBox.No) == QMessageBox.No:
return
try:
misc.rename_file(fname, path)
if osp.isfile(fname):
self.sig_renamed.emit(fname, path)
else:
self.sig_renamed_tree.emit(fname, path)
return path
except EnvironmentError as error:
QMessageBox.critical(self, _("Rename"),
_("<b>Unable to rename file <i>%s</i></b>"
"<br><br>Error message:<br>%s"
) % (osp.basename(fname), to_text_string(error))) | python | def rename_file(self, fname):
"""Rename file"""
path, valid = QInputDialog.getText(self, _('Rename'),
_('New name:'), QLineEdit.Normal,
osp.basename(fname))
if valid:
path = osp.join(osp.dirname(fname), to_text_string(path))
if path == fname:
return
if osp.exists(path):
if QMessageBox.warning(self, _("Rename"),
_("Do you really want to rename <b>%s</b> and "
"overwrite the existing file <b>%s</b>?"
) % (osp.basename(fname), osp.basename(path)),
QMessageBox.Yes|QMessageBox.No) == QMessageBox.No:
return
try:
misc.rename_file(fname, path)
if osp.isfile(fname):
self.sig_renamed.emit(fname, path)
else:
self.sig_renamed_tree.emit(fname, path)
return path
except EnvironmentError as error:
QMessageBox.critical(self, _("Rename"),
_("<b>Unable to rename file <i>%s</i></b>"
"<br><br>Error message:<br>%s"
) % (osp.basename(fname), to_text_string(error))) | [
"def",
"rename_file",
"(",
"self",
",",
"fname",
")",
":",
"path",
",",
"valid",
"=",
"QInputDialog",
".",
"getText",
"(",
"self",
",",
"_",
"(",
"'Rename'",
")",
",",
"_",
"(",
"'New name:'",
")",
",",
"QLineEdit",
".",
"Normal",
",",
"osp",
".",
"basename",
"(",
"fname",
")",
")",
"if",
"valid",
":",
"path",
"=",
"osp",
".",
"join",
"(",
"osp",
".",
"dirname",
"(",
"fname",
")",
",",
"to_text_string",
"(",
"path",
")",
")",
"if",
"path",
"==",
"fname",
":",
"return",
"if",
"osp",
".",
"exists",
"(",
"path",
")",
":",
"if",
"QMessageBox",
".",
"warning",
"(",
"self",
",",
"_",
"(",
"\"Rename\"",
")",
",",
"_",
"(",
"\"Do you really want to rename <b>%s</b> and \"",
"\"overwrite the existing file <b>%s</b>?\"",
")",
"%",
"(",
"osp",
".",
"basename",
"(",
"fname",
")",
",",
"osp",
".",
"basename",
"(",
"path",
")",
")",
",",
"QMessageBox",
".",
"Yes",
"|",
"QMessageBox",
".",
"No",
")",
"==",
"QMessageBox",
".",
"No",
":",
"return",
"try",
":",
"misc",
".",
"rename_file",
"(",
"fname",
",",
"path",
")",
"if",
"osp",
".",
"isfile",
"(",
"fname",
")",
":",
"self",
".",
"sig_renamed",
".",
"emit",
"(",
"fname",
",",
"path",
")",
"else",
":",
"self",
".",
"sig_renamed_tree",
".",
"emit",
"(",
"fname",
",",
"path",
")",
"return",
"path",
"except",
"EnvironmentError",
"as",
"error",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"\"Rename\"",
")",
",",
"_",
"(",
"\"<b>Unable to rename file <i>%s</i></b>\"",
"\"<br><br>Error message:<br>%s\"",
")",
"%",
"(",
"osp",
".",
"basename",
"(",
"fname",
")",
",",
"to_text_string",
"(",
"error",
")",
")",
")"
] | Rename file | [
"Rename",
"file"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L682-L709 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.rename | def rename(self, fnames=None):
"""Rename files"""
if fnames is None:
fnames = self.get_selected_filenames()
if not isinstance(fnames, (tuple, list)):
fnames = [fnames]
for fname in fnames:
self.rename_file(fname) | python | def rename(self, fnames=None):
"""Rename files"""
if fnames is None:
fnames = self.get_selected_filenames()
if not isinstance(fnames, (tuple, list)):
fnames = [fnames]
for fname in fnames:
self.rename_file(fname) | [
"def",
"rename",
"(",
"self",
",",
"fnames",
"=",
"None",
")",
":",
"if",
"fnames",
"is",
"None",
":",
"fnames",
"=",
"self",
".",
"get_selected_filenames",
"(",
")",
"if",
"not",
"isinstance",
"(",
"fnames",
",",
"(",
"tuple",
",",
"list",
")",
")",
":",
"fnames",
"=",
"[",
"fnames",
"]",
"for",
"fname",
"in",
"fnames",
":",
"self",
".",
"rename_file",
"(",
"fname",
")"
] | Rename files | [
"Rename",
"files"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L719-L726 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.move | def move(self, fnames=None, directory=None):
"""Move files/directories"""
if fnames is None:
fnames = self.get_selected_filenames()
orig = fixpath(osp.dirname(fnames[0]))
while True:
self.redirect_stdio.emit(False)
if directory is None:
folder = getexistingdirectory(self, _("Select directory"),
orig)
else:
folder = directory
self.redirect_stdio.emit(True)
if folder:
folder = fixpath(folder)
if folder != orig:
break
else:
return
for fname in fnames:
basename = osp.basename(fname)
try:
misc.move_file(fname, osp.join(folder, basename))
except EnvironmentError as error:
QMessageBox.critical(self, _("Error"),
_("<b>Unable to move <i>%s</i></b>"
"<br><br>Error message:<br>%s"
) % (basename, to_text_string(error))) | python | def move(self, fnames=None, directory=None):
"""Move files/directories"""
if fnames is None:
fnames = self.get_selected_filenames()
orig = fixpath(osp.dirname(fnames[0]))
while True:
self.redirect_stdio.emit(False)
if directory is None:
folder = getexistingdirectory(self, _("Select directory"),
orig)
else:
folder = directory
self.redirect_stdio.emit(True)
if folder:
folder = fixpath(folder)
if folder != orig:
break
else:
return
for fname in fnames:
basename = osp.basename(fname)
try:
misc.move_file(fname, osp.join(folder, basename))
except EnvironmentError as error:
QMessageBox.critical(self, _("Error"),
_("<b>Unable to move <i>%s</i></b>"
"<br><br>Error message:<br>%s"
) % (basename, to_text_string(error))) | [
"def",
"move",
"(",
"self",
",",
"fnames",
"=",
"None",
",",
"directory",
"=",
"None",
")",
":",
"if",
"fnames",
"is",
"None",
":",
"fnames",
"=",
"self",
".",
"get_selected_filenames",
"(",
")",
"orig",
"=",
"fixpath",
"(",
"osp",
".",
"dirname",
"(",
"fnames",
"[",
"0",
"]",
")",
")",
"while",
"True",
":",
"self",
".",
"redirect_stdio",
".",
"emit",
"(",
"False",
")",
"if",
"directory",
"is",
"None",
":",
"folder",
"=",
"getexistingdirectory",
"(",
"self",
",",
"_",
"(",
"\"Select directory\"",
")",
",",
"orig",
")",
"else",
":",
"folder",
"=",
"directory",
"self",
".",
"redirect_stdio",
".",
"emit",
"(",
"True",
")",
"if",
"folder",
":",
"folder",
"=",
"fixpath",
"(",
"folder",
")",
"if",
"folder",
"!=",
"orig",
":",
"break",
"else",
":",
"return",
"for",
"fname",
"in",
"fnames",
":",
"basename",
"=",
"osp",
".",
"basename",
"(",
"fname",
")",
"try",
":",
"misc",
".",
"move_file",
"(",
"fname",
",",
"osp",
".",
"join",
"(",
"folder",
",",
"basename",
")",
")",
"except",
"EnvironmentError",
"as",
"error",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"\"Error\"",
")",
",",
"_",
"(",
"\"<b>Unable to move <i>%s</i></b>\"",
"\"<br><br>Error message:<br>%s\"",
")",
"%",
"(",
"basename",
",",
"to_text_string",
"(",
"error",
")",
")",
")"
] | Move files/directories | [
"Move",
"files",
"/",
"directories"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L729-L756 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.create_new_folder | def create_new_folder(self, current_path, title, subtitle, is_package):
"""Create new folder"""
if current_path is None:
current_path = ''
if osp.isfile(current_path):
current_path = osp.dirname(current_path)
name, valid = QInputDialog.getText(self, title, subtitle,
QLineEdit.Normal, "")
if valid:
dirname = osp.join(current_path, to_text_string(name))
try:
os.mkdir(dirname)
except EnvironmentError as error:
QMessageBox.critical(self, title,
_("<b>Unable "
"to create folder <i>%s</i></b>"
"<br><br>Error message:<br>%s"
) % (dirname, to_text_string(error)))
finally:
if is_package:
fname = osp.join(dirname, '__init__.py')
try:
with open(fname, 'wb') as f:
f.write(to_binary_string('#'))
return dirname
except EnvironmentError as error:
QMessageBox.critical(self, title,
_("<b>Unable "
"to create file <i>%s</i></b>"
"<br><br>Error message:<br>%s"
) % (fname,
to_text_string(error))) | python | def create_new_folder(self, current_path, title, subtitle, is_package):
"""Create new folder"""
if current_path is None:
current_path = ''
if osp.isfile(current_path):
current_path = osp.dirname(current_path)
name, valid = QInputDialog.getText(self, title, subtitle,
QLineEdit.Normal, "")
if valid:
dirname = osp.join(current_path, to_text_string(name))
try:
os.mkdir(dirname)
except EnvironmentError as error:
QMessageBox.critical(self, title,
_("<b>Unable "
"to create folder <i>%s</i></b>"
"<br><br>Error message:<br>%s"
) % (dirname, to_text_string(error)))
finally:
if is_package:
fname = osp.join(dirname, '__init__.py')
try:
with open(fname, 'wb') as f:
f.write(to_binary_string('#'))
return dirname
except EnvironmentError as error:
QMessageBox.critical(self, title,
_("<b>Unable "
"to create file <i>%s</i></b>"
"<br><br>Error message:<br>%s"
) % (fname,
to_text_string(error))) | [
"def",
"create_new_folder",
"(",
"self",
",",
"current_path",
",",
"title",
",",
"subtitle",
",",
"is_package",
")",
":",
"if",
"current_path",
"is",
"None",
":",
"current_path",
"=",
"''",
"if",
"osp",
".",
"isfile",
"(",
"current_path",
")",
":",
"current_path",
"=",
"osp",
".",
"dirname",
"(",
"current_path",
")",
"name",
",",
"valid",
"=",
"QInputDialog",
".",
"getText",
"(",
"self",
",",
"title",
",",
"subtitle",
",",
"QLineEdit",
".",
"Normal",
",",
"\"\"",
")",
"if",
"valid",
":",
"dirname",
"=",
"osp",
".",
"join",
"(",
"current_path",
",",
"to_text_string",
"(",
"name",
")",
")",
"try",
":",
"os",
".",
"mkdir",
"(",
"dirname",
")",
"except",
"EnvironmentError",
"as",
"error",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"title",
",",
"_",
"(",
"\"<b>Unable \"",
"\"to create folder <i>%s</i></b>\"",
"\"<br><br>Error message:<br>%s\"",
")",
"%",
"(",
"dirname",
",",
"to_text_string",
"(",
"error",
")",
")",
")",
"finally",
":",
"if",
"is_package",
":",
"fname",
"=",
"osp",
".",
"join",
"(",
"dirname",
",",
"'__init__.py'",
")",
"try",
":",
"with",
"open",
"(",
"fname",
",",
"'wb'",
")",
"as",
"f",
":",
"f",
".",
"write",
"(",
"to_binary_string",
"(",
"'#'",
")",
")",
"return",
"dirname",
"except",
"EnvironmentError",
"as",
"error",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"title",
",",
"_",
"(",
"\"<b>Unable \"",
"\"to create file <i>%s</i></b>\"",
"\"<br><br>Error message:<br>%s\"",
")",
"%",
"(",
"fname",
",",
"to_text_string",
"(",
"error",
")",
")",
")"
] | Create new folder | [
"Create",
"new",
"folder"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L758-L789 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.new_folder | def new_folder(self, basedir):
"""New folder"""
title = _('New folder')
subtitle = _('Folder name:')
self.create_new_folder(basedir, title, subtitle, is_package=False) | python | def new_folder(self, basedir):
"""New folder"""
title = _('New folder')
subtitle = _('Folder name:')
self.create_new_folder(basedir, title, subtitle, is_package=False) | [
"def",
"new_folder",
"(",
"self",
",",
"basedir",
")",
":",
"title",
"=",
"_",
"(",
"'New folder'",
")",
"subtitle",
"=",
"_",
"(",
"'Folder name:'",
")",
"self",
".",
"create_new_folder",
"(",
"basedir",
",",
"title",
",",
"subtitle",
",",
"is_package",
"=",
"False",
")"
] | New folder | [
"New",
"folder"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L791-L795 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.new_package | def new_package(self, basedir):
"""New package"""
title = _('New package')
subtitle = _('Package name:')
self.create_new_folder(basedir, title, subtitle, is_package=True) | python | def new_package(self, basedir):
"""New package"""
title = _('New package')
subtitle = _('Package name:')
self.create_new_folder(basedir, title, subtitle, is_package=True) | [
"def",
"new_package",
"(",
"self",
",",
"basedir",
")",
":",
"title",
"=",
"_",
"(",
"'New package'",
")",
"subtitle",
"=",
"_",
"(",
"'Package name:'",
")",
"self",
".",
"create_new_folder",
"(",
"basedir",
",",
"title",
",",
"subtitle",
",",
"is_package",
"=",
"True",
")"
] | New package | [
"New",
"package"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L797-L801 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.create_new_file | def create_new_file(self, current_path, title, filters, create_func):
"""Create new file
Returns True if successful"""
if current_path is None:
current_path = ''
if osp.isfile(current_path):
current_path = osp.dirname(current_path)
self.redirect_stdio.emit(False)
fname, _selfilter = getsavefilename(self, title, current_path, filters)
self.redirect_stdio.emit(True)
if fname:
try:
create_func(fname)
return fname
except EnvironmentError as error:
QMessageBox.critical(self, _("New file"),
_("<b>Unable to create file <i>%s</i>"
"</b><br><br>Error message:<br>%s"
) % (fname, to_text_string(error))) | python | def create_new_file(self, current_path, title, filters, create_func):
"""Create new file
Returns True if successful"""
if current_path is None:
current_path = ''
if osp.isfile(current_path):
current_path = osp.dirname(current_path)
self.redirect_stdio.emit(False)
fname, _selfilter = getsavefilename(self, title, current_path, filters)
self.redirect_stdio.emit(True)
if fname:
try:
create_func(fname)
return fname
except EnvironmentError as error:
QMessageBox.critical(self, _("New file"),
_("<b>Unable to create file <i>%s</i>"
"</b><br><br>Error message:<br>%s"
) % (fname, to_text_string(error))) | [
"def",
"create_new_file",
"(",
"self",
",",
"current_path",
",",
"title",
",",
"filters",
",",
"create_func",
")",
":",
"if",
"current_path",
"is",
"None",
":",
"current_path",
"=",
"''",
"if",
"osp",
".",
"isfile",
"(",
"current_path",
")",
":",
"current_path",
"=",
"osp",
".",
"dirname",
"(",
"current_path",
")",
"self",
".",
"redirect_stdio",
".",
"emit",
"(",
"False",
")",
"fname",
",",
"_selfilter",
"=",
"getsavefilename",
"(",
"self",
",",
"title",
",",
"current_path",
",",
"filters",
")",
"self",
".",
"redirect_stdio",
".",
"emit",
"(",
"True",
")",
"if",
"fname",
":",
"try",
":",
"create_func",
"(",
"fname",
")",
"return",
"fname",
"except",
"EnvironmentError",
"as",
"error",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"\"New file\"",
")",
",",
"_",
"(",
"\"<b>Unable to create file <i>%s</i>\"",
"\"</b><br><br>Error message:<br>%s\"",
")",
"%",
"(",
"fname",
",",
"to_text_string",
"(",
"error",
")",
")",
")"
] | Create new file
Returns True if successful | [
"Create",
"new",
"file",
"Returns",
"True",
"if",
"successful"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L803-L821 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.new_file | def new_file(self, basedir):
"""New file"""
title = _("New file")
filters = _("All files")+" (*)"
def create_func(fname):
"""File creation callback"""
if osp.splitext(fname)[1] in ('.py', '.pyw', '.ipy'):
create_script(fname)
else:
with open(fname, 'wb') as f:
f.write(to_binary_string(''))
fname = self.create_new_file(basedir, title, filters, create_func)
if fname is not None:
self.open([fname]) | python | def new_file(self, basedir):
"""New file"""
title = _("New file")
filters = _("All files")+" (*)"
def create_func(fname):
"""File creation callback"""
if osp.splitext(fname)[1] in ('.py', '.pyw', '.ipy'):
create_script(fname)
else:
with open(fname, 'wb') as f:
f.write(to_binary_string(''))
fname = self.create_new_file(basedir, title, filters, create_func)
if fname is not None:
self.open([fname]) | [
"def",
"new_file",
"(",
"self",
",",
"basedir",
")",
":",
"title",
"=",
"_",
"(",
"\"New file\"",
")",
"filters",
"=",
"_",
"(",
"\"All files\"",
")",
"+",
"\" (*)\"",
"def",
"create_func",
"(",
"fname",
")",
":",
"\"\"\"File creation callback\"\"\"",
"if",
"osp",
".",
"splitext",
"(",
"fname",
")",
"[",
"1",
"]",
"in",
"(",
"'.py'",
",",
"'.pyw'",
",",
"'.ipy'",
")",
":",
"create_script",
"(",
"fname",
")",
"else",
":",
"with",
"open",
"(",
"fname",
",",
"'wb'",
")",
"as",
"f",
":",
"f",
".",
"write",
"(",
"to_binary_string",
"(",
"''",
")",
")",
"fname",
"=",
"self",
".",
"create_new_file",
"(",
"basedir",
",",
"title",
",",
"filters",
",",
"create_func",
")",
"if",
"fname",
"is",
"not",
"None",
":",
"self",
".",
"open",
"(",
"[",
"fname",
"]",
")"
] | New file | [
"New",
"file"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L823-L836 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.new_module | def new_module(self, basedir):
"""New module"""
title = _("New module")
filters = _("Python scripts")+" (*.py *.pyw *.ipy)"
def create_func(fname):
self.sig_create_module.emit(fname)
self.create_new_file(basedir, title, filters, create_func) | python | def new_module(self, basedir):
"""New module"""
title = _("New module")
filters = _("Python scripts")+" (*.py *.pyw *.ipy)"
def create_func(fname):
self.sig_create_module.emit(fname)
self.create_new_file(basedir, title, filters, create_func) | [
"def",
"new_module",
"(",
"self",
",",
"basedir",
")",
":",
"title",
"=",
"_",
"(",
"\"New module\"",
")",
"filters",
"=",
"_",
"(",
"\"Python scripts\"",
")",
"+",
"\" (*.py *.pyw *.ipy)\"",
"def",
"create_func",
"(",
"fname",
")",
":",
"self",
".",
"sig_create_module",
".",
"emit",
"(",
"fname",
")",
"self",
".",
"create_new_file",
"(",
"basedir",
",",
"title",
",",
"filters",
",",
"create_func",
")"
] | New module | [
"New",
"module"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L838-L846 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.copy_path | def copy_path(self, fnames=None, method="absolute"):
"""Copy absolute or relative path to given file(s)/folders(s)."""
cb = QApplication.clipboard()
explorer_dir = self.fsmodel.rootPath()
if fnames is None:
fnames = self.get_selected_filenames()
if not isinstance(fnames, (tuple, list)):
fnames = [fnames]
fnames = [_fn.replace(os.sep, "/") for _fn in fnames]
if len(fnames) > 1:
if method == "absolute":
clipboard_files = ',\n'.join('"' + _fn + '"' for _fn in fnames)
elif method == "relative":
clipboard_files = ',\n'.join('"' +
osp.relpath(_fn, explorer_dir).
replace(os.sep, "/") + '"'
for _fn in fnames)
else:
if method == "absolute":
clipboard_files = fnames[0]
elif method == "relative":
clipboard_files = (osp.relpath(fnames[0], explorer_dir).
replace(os.sep, "/"))
copied_from = self.parent_widget.__class__.__name__
if copied_from == 'ProjectExplorerWidget' and method == 'relative':
clipboard_files = [path.strip(',"') for path in
clipboard_files.splitlines()]
clipboard_files = ['/'.join(path.strip('/').split('/')[1:]) for
path in clipboard_files]
if len(clipboard_files) > 1:
clipboard_files = ',\n'.join('"' + _fn + '"' for _fn in
clipboard_files)
else:
clipboard_files = clipboard_files[0]
cb.setText(clipboard_files, mode=cb.Clipboard) | python | def copy_path(self, fnames=None, method="absolute"):
"""Copy absolute or relative path to given file(s)/folders(s)."""
cb = QApplication.clipboard()
explorer_dir = self.fsmodel.rootPath()
if fnames is None:
fnames = self.get_selected_filenames()
if not isinstance(fnames, (tuple, list)):
fnames = [fnames]
fnames = [_fn.replace(os.sep, "/") for _fn in fnames]
if len(fnames) > 1:
if method == "absolute":
clipboard_files = ',\n'.join('"' + _fn + '"' for _fn in fnames)
elif method == "relative":
clipboard_files = ',\n'.join('"' +
osp.relpath(_fn, explorer_dir).
replace(os.sep, "/") + '"'
for _fn in fnames)
else:
if method == "absolute":
clipboard_files = fnames[0]
elif method == "relative":
clipboard_files = (osp.relpath(fnames[0], explorer_dir).
replace(os.sep, "/"))
copied_from = self.parent_widget.__class__.__name__
if copied_from == 'ProjectExplorerWidget' and method == 'relative':
clipboard_files = [path.strip(',"') for path in
clipboard_files.splitlines()]
clipboard_files = ['/'.join(path.strip('/').split('/')[1:]) for
path in clipboard_files]
if len(clipboard_files) > 1:
clipboard_files = ',\n'.join('"' + _fn + '"' for _fn in
clipboard_files)
else:
clipboard_files = clipboard_files[0]
cb.setText(clipboard_files, mode=cb.Clipboard) | [
"def",
"copy_path",
"(",
"self",
",",
"fnames",
"=",
"None",
",",
"method",
"=",
"\"absolute\"",
")",
":",
"cb",
"=",
"QApplication",
".",
"clipboard",
"(",
")",
"explorer_dir",
"=",
"self",
".",
"fsmodel",
".",
"rootPath",
"(",
")",
"if",
"fnames",
"is",
"None",
":",
"fnames",
"=",
"self",
".",
"get_selected_filenames",
"(",
")",
"if",
"not",
"isinstance",
"(",
"fnames",
",",
"(",
"tuple",
",",
"list",
")",
")",
":",
"fnames",
"=",
"[",
"fnames",
"]",
"fnames",
"=",
"[",
"_fn",
".",
"replace",
"(",
"os",
".",
"sep",
",",
"\"/\"",
")",
"for",
"_fn",
"in",
"fnames",
"]",
"if",
"len",
"(",
"fnames",
")",
">",
"1",
":",
"if",
"method",
"==",
"\"absolute\"",
":",
"clipboard_files",
"=",
"',\\n'",
".",
"join",
"(",
"'\"'",
"+",
"_fn",
"+",
"'\"'",
"for",
"_fn",
"in",
"fnames",
")",
"elif",
"method",
"==",
"\"relative\"",
":",
"clipboard_files",
"=",
"',\\n'",
".",
"join",
"(",
"'\"'",
"+",
"osp",
".",
"relpath",
"(",
"_fn",
",",
"explorer_dir",
")",
".",
"replace",
"(",
"os",
".",
"sep",
",",
"\"/\"",
")",
"+",
"'\"'",
"for",
"_fn",
"in",
"fnames",
")",
"else",
":",
"if",
"method",
"==",
"\"absolute\"",
":",
"clipboard_files",
"=",
"fnames",
"[",
"0",
"]",
"elif",
"method",
"==",
"\"relative\"",
":",
"clipboard_files",
"=",
"(",
"osp",
".",
"relpath",
"(",
"fnames",
"[",
"0",
"]",
",",
"explorer_dir",
")",
".",
"replace",
"(",
"os",
".",
"sep",
",",
"\"/\"",
")",
")",
"copied_from",
"=",
"self",
".",
"parent_widget",
".",
"__class__",
".",
"__name__",
"if",
"copied_from",
"==",
"'ProjectExplorerWidget'",
"and",
"method",
"==",
"'relative'",
":",
"clipboard_files",
"=",
"[",
"path",
".",
"strip",
"(",
"',\"'",
")",
"for",
"path",
"in",
"clipboard_files",
".",
"splitlines",
"(",
")",
"]",
"clipboard_files",
"=",
"[",
"'/'",
".",
"join",
"(",
"path",
".",
"strip",
"(",
"'/'",
")",
".",
"split",
"(",
"'/'",
")",
"[",
"1",
":",
"]",
")",
"for",
"path",
"in",
"clipboard_files",
"]",
"if",
"len",
"(",
"clipboard_files",
")",
">",
"1",
":",
"clipboard_files",
"=",
"',\\n'",
".",
"join",
"(",
"'\"'",
"+",
"_fn",
"+",
"'\"'",
"for",
"_fn",
"in",
"clipboard_files",
")",
"else",
":",
"clipboard_files",
"=",
"clipboard_files",
"[",
"0",
"]",
"cb",
".",
"setText",
"(",
"clipboard_files",
",",
"mode",
"=",
"cb",
".",
"Clipboard",
")"
] | Copy absolute or relative path to given file(s)/folders(s). | [
"Copy",
"absolute",
"or",
"relative",
"path",
"to",
"given",
"file",
"(",
"s",
")",
"/",
"folders",
"(",
"s",
")",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L851-L885 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.copy_file_clipboard | def copy_file_clipboard(self, fnames=None):
"""Copy file(s)/folders(s) to clipboard."""
if fnames is None:
fnames = self.get_selected_filenames()
if not isinstance(fnames, (tuple, list)):
fnames = [fnames]
try:
file_content = QMimeData()
file_content.setUrls([QUrl.fromLocalFile(_fn) for _fn in fnames])
cb = QApplication.clipboard()
cb.setMimeData(file_content, mode=cb.Clipboard)
except Exception as e:
QMessageBox.critical(self,
_('File/Folder copy error'),
_("Cannot copy this type of file(s) or "
"folder(s). The error was:\n\n")
+ to_text_string(e)) | python | def copy_file_clipboard(self, fnames=None):
"""Copy file(s)/folders(s) to clipboard."""
if fnames is None:
fnames = self.get_selected_filenames()
if not isinstance(fnames, (tuple, list)):
fnames = [fnames]
try:
file_content = QMimeData()
file_content.setUrls([QUrl.fromLocalFile(_fn) for _fn in fnames])
cb = QApplication.clipboard()
cb.setMimeData(file_content, mode=cb.Clipboard)
except Exception as e:
QMessageBox.critical(self,
_('File/Folder copy error'),
_("Cannot copy this type of file(s) or "
"folder(s). The error was:\n\n")
+ to_text_string(e)) | [
"def",
"copy_file_clipboard",
"(",
"self",
",",
"fnames",
"=",
"None",
")",
":",
"if",
"fnames",
"is",
"None",
":",
"fnames",
"=",
"self",
".",
"get_selected_filenames",
"(",
")",
"if",
"not",
"isinstance",
"(",
"fnames",
",",
"(",
"tuple",
",",
"list",
")",
")",
":",
"fnames",
"=",
"[",
"fnames",
"]",
"try",
":",
"file_content",
"=",
"QMimeData",
"(",
")",
"file_content",
".",
"setUrls",
"(",
"[",
"QUrl",
".",
"fromLocalFile",
"(",
"_fn",
")",
"for",
"_fn",
"in",
"fnames",
"]",
")",
"cb",
"=",
"QApplication",
".",
"clipboard",
"(",
")",
"cb",
".",
"setMimeData",
"(",
"file_content",
",",
"mode",
"=",
"cb",
".",
"Clipboard",
")",
"except",
"Exception",
"as",
"e",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"'File/Folder copy error'",
")",
",",
"_",
"(",
"\"Cannot copy this type of file(s) or \"",
"\"folder(s). The error was:\\n\\n\"",
")",
"+",
"to_text_string",
"(",
"e",
")",
")"
] | Copy file(s)/folders(s) to clipboard. | [
"Copy",
"file",
"(",
"s",
")",
"/",
"folders",
"(",
"s",
")",
"to",
"clipboard",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L898-L914 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.save_file_clipboard | def save_file_clipboard(self, fnames=None):
"""Paste file from clipboard into file/project explorer directory."""
if fnames is None:
fnames = self.get_selected_filenames()
if not isinstance(fnames, (tuple, list)):
fnames = [fnames]
if len(fnames) >= 1:
try:
selected_item = osp.commonpath(fnames)
except AttributeError:
# py2 does not have commonpath
if len(fnames) > 1:
selected_item = osp.normpath(
osp.dirname(osp.commonprefix(fnames)))
else:
selected_item = fnames[0]
if osp.isfile(selected_item):
parent_path = osp.dirname(selected_item)
else:
parent_path = osp.normpath(selected_item)
cb_data = QApplication.clipboard().mimeData()
if cb_data.hasUrls():
urls = cb_data.urls()
for url in urls:
source_name = url.toLocalFile()
base_name = osp.basename(source_name)
if osp.isfile(source_name):
try:
while base_name in os.listdir(parent_path):
file_no_ext, file_ext = osp.splitext(base_name)
end_number = re.search(r'\d+$', file_no_ext)
if end_number:
new_number = int(end_number.group()) + 1
else:
new_number = 1
left_string = re.sub(r'\d+$', '', file_no_ext)
left_string += str(new_number)
base_name = left_string + file_ext
destination = osp.join(parent_path, base_name)
else:
destination = osp.join(parent_path, base_name)
shutil.copy(source_name, destination)
except Exception as e:
QMessageBox.critical(self, _('Error pasting file'),
_("Unsupported copy operation"
". The error was:\n\n")
+ to_text_string(e))
else:
try:
while base_name in os.listdir(parent_path):
end_number = re.search(r'\d+$', base_name)
if end_number:
new_number = int(end_number.group()) + 1
else:
new_number = 1
left_string = re.sub(r'\d+$', '', base_name)
base_name = left_string + str(new_number)
destination = osp.join(parent_path, base_name)
else:
destination = osp.join(parent_path, base_name)
if osp.realpath(destination).startswith(
osp.realpath(source_name) + os.sep):
QMessageBox.critical(self,
_('Recursive copy'),
_("Source is an ancestor"
" of destination"
" folder."))
continue
shutil.copytree(source_name, destination)
except Exception as e:
QMessageBox.critical(self,
_('Error pasting folder'),
_("Unsupported copy"
" operation. The error was:"
"\n\n") + to_text_string(e))
else:
QMessageBox.critical(self, _("No file in clipboard"),
_("No file in the clipboard. Please copy"
" a file to the clipboard first."))
else:
if QApplication.clipboard().mimeData().hasUrls():
QMessageBox.critical(self, _('Blank area'),
_("Cannot paste in the blank area."))
else:
pass | python | def save_file_clipboard(self, fnames=None):
"""Paste file from clipboard into file/project explorer directory."""
if fnames is None:
fnames = self.get_selected_filenames()
if not isinstance(fnames, (tuple, list)):
fnames = [fnames]
if len(fnames) >= 1:
try:
selected_item = osp.commonpath(fnames)
except AttributeError:
# py2 does not have commonpath
if len(fnames) > 1:
selected_item = osp.normpath(
osp.dirname(osp.commonprefix(fnames)))
else:
selected_item = fnames[0]
if osp.isfile(selected_item):
parent_path = osp.dirname(selected_item)
else:
parent_path = osp.normpath(selected_item)
cb_data = QApplication.clipboard().mimeData()
if cb_data.hasUrls():
urls = cb_data.urls()
for url in urls:
source_name = url.toLocalFile()
base_name = osp.basename(source_name)
if osp.isfile(source_name):
try:
while base_name in os.listdir(parent_path):
file_no_ext, file_ext = osp.splitext(base_name)
end_number = re.search(r'\d+$', file_no_ext)
if end_number:
new_number = int(end_number.group()) + 1
else:
new_number = 1
left_string = re.sub(r'\d+$', '', file_no_ext)
left_string += str(new_number)
base_name = left_string + file_ext
destination = osp.join(parent_path, base_name)
else:
destination = osp.join(parent_path, base_name)
shutil.copy(source_name, destination)
except Exception as e:
QMessageBox.critical(self, _('Error pasting file'),
_("Unsupported copy operation"
". The error was:\n\n")
+ to_text_string(e))
else:
try:
while base_name in os.listdir(parent_path):
end_number = re.search(r'\d+$', base_name)
if end_number:
new_number = int(end_number.group()) + 1
else:
new_number = 1
left_string = re.sub(r'\d+$', '', base_name)
base_name = left_string + str(new_number)
destination = osp.join(parent_path, base_name)
else:
destination = osp.join(parent_path, base_name)
if osp.realpath(destination).startswith(
osp.realpath(source_name) + os.sep):
QMessageBox.critical(self,
_('Recursive copy'),
_("Source is an ancestor"
" of destination"
" folder."))
continue
shutil.copytree(source_name, destination)
except Exception as e:
QMessageBox.critical(self,
_('Error pasting folder'),
_("Unsupported copy"
" operation. The error was:"
"\n\n") + to_text_string(e))
else:
QMessageBox.critical(self, _("No file in clipboard"),
_("No file in the clipboard. Please copy"
" a file to the clipboard first."))
else:
if QApplication.clipboard().mimeData().hasUrls():
QMessageBox.critical(self, _('Blank area'),
_("Cannot paste in the blank area."))
else:
pass | [
"def",
"save_file_clipboard",
"(",
"self",
",",
"fnames",
"=",
"None",
")",
":",
"if",
"fnames",
"is",
"None",
":",
"fnames",
"=",
"self",
".",
"get_selected_filenames",
"(",
")",
"if",
"not",
"isinstance",
"(",
"fnames",
",",
"(",
"tuple",
",",
"list",
")",
")",
":",
"fnames",
"=",
"[",
"fnames",
"]",
"if",
"len",
"(",
"fnames",
")",
">=",
"1",
":",
"try",
":",
"selected_item",
"=",
"osp",
".",
"commonpath",
"(",
"fnames",
")",
"except",
"AttributeError",
":",
"# py2 does not have commonpath\r",
"if",
"len",
"(",
"fnames",
")",
">",
"1",
":",
"selected_item",
"=",
"osp",
".",
"normpath",
"(",
"osp",
".",
"dirname",
"(",
"osp",
".",
"commonprefix",
"(",
"fnames",
")",
")",
")",
"else",
":",
"selected_item",
"=",
"fnames",
"[",
"0",
"]",
"if",
"osp",
".",
"isfile",
"(",
"selected_item",
")",
":",
"parent_path",
"=",
"osp",
".",
"dirname",
"(",
"selected_item",
")",
"else",
":",
"parent_path",
"=",
"osp",
".",
"normpath",
"(",
"selected_item",
")",
"cb_data",
"=",
"QApplication",
".",
"clipboard",
"(",
")",
".",
"mimeData",
"(",
")",
"if",
"cb_data",
".",
"hasUrls",
"(",
")",
":",
"urls",
"=",
"cb_data",
".",
"urls",
"(",
")",
"for",
"url",
"in",
"urls",
":",
"source_name",
"=",
"url",
".",
"toLocalFile",
"(",
")",
"base_name",
"=",
"osp",
".",
"basename",
"(",
"source_name",
")",
"if",
"osp",
".",
"isfile",
"(",
"source_name",
")",
":",
"try",
":",
"while",
"base_name",
"in",
"os",
".",
"listdir",
"(",
"parent_path",
")",
":",
"file_no_ext",
",",
"file_ext",
"=",
"osp",
".",
"splitext",
"(",
"base_name",
")",
"end_number",
"=",
"re",
".",
"search",
"(",
"r'\\d+$'",
",",
"file_no_ext",
")",
"if",
"end_number",
":",
"new_number",
"=",
"int",
"(",
"end_number",
".",
"group",
"(",
")",
")",
"+",
"1",
"else",
":",
"new_number",
"=",
"1",
"left_string",
"=",
"re",
".",
"sub",
"(",
"r'\\d+$'",
",",
"''",
",",
"file_no_ext",
")",
"left_string",
"+=",
"str",
"(",
"new_number",
")",
"base_name",
"=",
"left_string",
"+",
"file_ext",
"destination",
"=",
"osp",
".",
"join",
"(",
"parent_path",
",",
"base_name",
")",
"else",
":",
"destination",
"=",
"osp",
".",
"join",
"(",
"parent_path",
",",
"base_name",
")",
"shutil",
".",
"copy",
"(",
"source_name",
",",
"destination",
")",
"except",
"Exception",
"as",
"e",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"'Error pasting file'",
")",
",",
"_",
"(",
"\"Unsupported copy operation\"",
"\". The error was:\\n\\n\"",
")",
"+",
"to_text_string",
"(",
"e",
")",
")",
"else",
":",
"try",
":",
"while",
"base_name",
"in",
"os",
".",
"listdir",
"(",
"parent_path",
")",
":",
"end_number",
"=",
"re",
".",
"search",
"(",
"r'\\d+$'",
",",
"base_name",
")",
"if",
"end_number",
":",
"new_number",
"=",
"int",
"(",
"end_number",
".",
"group",
"(",
")",
")",
"+",
"1",
"else",
":",
"new_number",
"=",
"1",
"left_string",
"=",
"re",
".",
"sub",
"(",
"r'\\d+$'",
",",
"''",
",",
"base_name",
")",
"base_name",
"=",
"left_string",
"+",
"str",
"(",
"new_number",
")",
"destination",
"=",
"osp",
".",
"join",
"(",
"parent_path",
",",
"base_name",
")",
"else",
":",
"destination",
"=",
"osp",
".",
"join",
"(",
"parent_path",
",",
"base_name",
")",
"if",
"osp",
".",
"realpath",
"(",
"destination",
")",
".",
"startswith",
"(",
"osp",
".",
"realpath",
"(",
"source_name",
")",
"+",
"os",
".",
"sep",
")",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"'Recursive copy'",
")",
",",
"_",
"(",
"\"Source is an ancestor\"",
"\" of destination\"",
"\" folder.\"",
")",
")",
"continue",
"shutil",
".",
"copytree",
"(",
"source_name",
",",
"destination",
")",
"except",
"Exception",
"as",
"e",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"'Error pasting folder'",
")",
",",
"_",
"(",
"\"Unsupported copy\"",
"\" operation. The error was:\"",
"\"\\n\\n\"",
")",
"+",
"to_text_string",
"(",
"e",
")",
")",
"else",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"\"No file in clipboard\"",
")",
",",
"_",
"(",
"\"No file in the clipboard. Please copy\"",
"\" a file to the clipboard first.\"",
")",
")",
"else",
":",
"if",
"QApplication",
".",
"clipboard",
"(",
")",
".",
"mimeData",
"(",
")",
".",
"hasUrls",
"(",
")",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"'Blank area'",
")",
",",
"_",
"(",
"\"Cannot paste in the blank area.\"",
")",
")",
"else",
":",
"pass"
] | Paste file from clipboard into file/project explorer directory. | [
"Paste",
"file",
"from",
"clipboard",
"into",
"file",
"/",
"project",
"explorer",
"directory",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L917-L1001 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.create_shortcuts | def create_shortcuts(self):
"""Create shortcuts for this file explorer."""
# Configurable
copy_clipboard_file = config_shortcut(self.copy_file_clipboard,
context='explorer',
name='copy file', parent=self)
paste_clipboard_file = config_shortcut(self.save_file_clipboard,
context='explorer',
name='paste file', parent=self)
copy_absolute_path = config_shortcut(self.copy_absolute_path,
context='explorer',
name='copy absolute path',
parent=self)
copy_relative_path = config_shortcut(self.copy_relative_path,
context='explorer',
name='copy relative path',
parent=self)
return [copy_clipboard_file, paste_clipboard_file, copy_absolute_path,
copy_relative_path] | python | def create_shortcuts(self):
"""Create shortcuts for this file explorer."""
# Configurable
copy_clipboard_file = config_shortcut(self.copy_file_clipboard,
context='explorer',
name='copy file', parent=self)
paste_clipboard_file = config_shortcut(self.save_file_clipboard,
context='explorer',
name='paste file', parent=self)
copy_absolute_path = config_shortcut(self.copy_absolute_path,
context='explorer',
name='copy absolute path',
parent=self)
copy_relative_path = config_shortcut(self.copy_relative_path,
context='explorer',
name='copy relative path',
parent=self)
return [copy_clipboard_file, paste_clipboard_file, copy_absolute_path,
copy_relative_path] | [
"def",
"create_shortcuts",
"(",
"self",
")",
":",
"# Configurable\r",
"copy_clipboard_file",
"=",
"config_shortcut",
"(",
"self",
".",
"copy_file_clipboard",
",",
"context",
"=",
"'explorer'",
",",
"name",
"=",
"'copy file'",
",",
"parent",
"=",
"self",
")",
"paste_clipboard_file",
"=",
"config_shortcut",
"(",
"self",
".",
"save_file_clipboard",
",",
"context",
"=",
"'explorer'",
",",
"name",
"=",
"'paste file'",
",",
"parent",
"=",
"self",
")",
"copy_absolute_path",
"=",
"config_shortcut",
"(",
"self",
".",
"copy_absolute_path",
",",
"context",
"=",
"'explorer'",
",",
"name",
"=",
"'copy absolute path'",
",",
"parent",
"=",
"self",
")",
"copy_relative_path",
"=",
"config_shortcut",
"(",
"self",
".",
"copy_relative_path",
",",
"context",
"=",
"'explorer'",
",",
"name",
"=",
"'copy relative path'",
",",
"parent",
"=",
"self",
")",
"return",
"[",
"copy_clipboard_file",
",",
"paste_clipboard_file",
",",
"copy_absolute_path",
",",
"copy_relative_path",
"]"
] | Create shortcuts for this file explorer. | [
"Create",
"shortcuts",
"for",
"this",
"file",
"explorer",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1003-L1021 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.vcs_command | def vcs_command(self, fnames, action):
"""VCS action (commit, browse)"""
try:
for path in sorted(fnames):
vcs.run_vcs_tool(path, action)
except vcs.ActionToolNotFound as error:
msg = _("For %s support, please install one of the<br/> "
"following tools:<br/><br/> %s")\
% (error.vcsname, ', '.join(error.tools))
QMessageBox.critical(self, _("Error"),
_("""<b>Unable to find external program.</b><br><br>%s""")
% to_text_string(msg)) | python | def vcs_command(self, fnames, action):
"""VCS action (commit, browse)"""
try:
for path in sorted(fnames):
vcs.run_vcs_tool(path, action)
except vcs.ActionToolNotFound as error:
msg = _("For %s support, please install one of the<br/> "
"following tools:<br/><br/> %s")\
% (error.vcsname, ', '.join(error.tools))
QMessageBox.critical(self, _("Error"),
_("""<b>Unable to find external program.</b><br><br>%s""")
% to_text_string(msg)) | [
"def",
"vcs_command",
"(",
"self",
",",
"fnames",
",",
"action",
")",
":",
"try",
":",
"for",
"path",
"in",
"sorted",
"(",
"fnames",
")",
":",
"vcs",
".",
"run_vcs_tool",
"(",
"path",
",",
"action",
")",
"except",
"vcs",
".",
"ActionToolNotFound",
"as",
"error",
":",
"msg",
"=",
"_",
"(",
"\"For %s support, please install one of the<br/> \"",
"\"following tools:<br/><br/> %s\"",
")",
"%",
"(",
"error",
".",
"vcsname",
",",
"', '",
".",
"join",
"(",
"error",
".",
"tools",
")",
")",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"\"Error\"",
")",
",",
"_",
"(",
"\"\"\"<b>Unable to find external program.</b><br><br>%s\"\"\"",
")",
"%",
"to_text_string",
"(",
"msg",
")",
")"
] | VCS action (commit, browse) | [
"VCS",
"action",
"(",
"commit",
"browse",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1033-L1044 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.set_scrollbar_position | def set_scrollbar_position(self, position):
"""Set scrollbar positions"""
# Scrollbars will be restored after the expanded state
self._scrollbar_positions = position
if self._to_be_loaded is not None and len(self._to_be_loaded) == 0:
self.restore_scrollbar_positions() | python | def set_scrollbar_position(self, position):
"""Set scrollbar positions"""
# Scrollbars will be restored after the expanded state
self._scrollbar_positions = position
if self._to_be_loaded is not None and len(self._to_be_loaded) == 0:
self.restore_scrollbar_positions() | [
"def",
"set_scrollbar_position",
"(",
"self",
",",
"position",
")",
":",
"# Scrollbars will be restored after the expanded state\r",
"self",
".",
"_scrollbar_positions",
"=",
"position",
"if",
"self",
".",
"_to_be_loaded",
"is",
"not",
"None",
"and",
"len",
"(",
"self",
".",
"_to_be_loaded",
")",
"==",
"0",
":",
"self",
".",
"restore_scrollbar_positions",
"(",
")"
] | Set scrollbar positions | [
"Set",
"scrollbar",
"positions"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1052-L1057 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.restore_scrollbar_positions | def restore_scrollbar_positions(self):
"""Restore scrollbar positions once tree is loaded"""
hor, ver = self._scrollbar_positions
self.horizontalScrollBar().setValue(hor)
self.verticalScrollBar().setValue(ver) | python | def restore_scrollbar_positions(self):
"""Restore scrollbar positions once tree is loaded"""
hor, ver = self._scrollbar_positions
self.horizontalScrollBar().setValue(hor)
self.verticalScrollBar().setValue(ver) | [
"def",
"restore_scrollbar_positions",
"(",
"self",
")",
":",
"hor",
",",
"ver",
"=",
"self",
".",
"_scrollbar_positions",
"self",
".",
"horizontalScrollBar",
"(",
")",
".",
"setValue",
"(",
"hor",
")",
"self",
".",
"verticalScrollBar",
"(",
")",
".",
"setValue",
"(",
"ver",
")"
] | Restore scrollbar positions once tree is loaded | [
"Restore",
"scrollbar",
"positions",
"once",
"tree",
"is",
"loaded"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1059-L1063 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.save_expanded_state | def save_expanded_state(self):
"""Save all items expanded state"""
model = self.model()
# If model is not installed, 'model' will be None: this happens when
# using the Project Explorer without having selected a workspace yet
if model is not None:
self.__expanded_state = []
for idx in model.persistentIndexList():
if self.isExpanded(idx):
self.__expanded_state.append(self.get_filename(idx)) | python | def save_expanded_state(self):
"""Save all items expanded state"""
model = self.model()
# If model is not installed, 'model' will be None: this happens when
# using the Project Explorer without having selected a workspace yet
if model is not None:
self.__expanded_state = []
for idx in model.persistentIndexList():
if self.isExpanded(idx):
self.__expanded_state.append(self.get_filename(idx)) | [
"def",
"save_expanded_state",
"(",
"self",
")",
":",
"model",
"=",
"self",
".",
"model",
"(",
")",
"# If model is not installed, 'model' will be None: this happens when\r",
"# using the Project Explorer without having selected a workspace yet\r",
"if",
"model",
"is",
"not",
"None",
":",
"self",
".",
"__expanded_state",
"=",
"[",
"]",
"for",
"idx",
"in",
"model",
".",
"persistentIndexList",
"(",
")",
":",
"if",
"self",
".",
"isExpanded",
"(",
"idx",
")",
":",
"self",
".",
"__expanded_state",
".",
"append",
"(",
"self",
".",
"get_filename",
"(",
"idx",
")",
")"
] | Save all items expanded state | [
"Save",
"all",
"items",
"expanded",
"state"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1075-L1084 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.restore_directory_state | def restore_directory_state(self, fname):
"""Restore directory expanded state"""
root = osp.normpath(to_text_string(fname))
if not osp.exists(root):
# Directory has been (re)moved outside Spyder
return
for basename in os.listdir(root):
path = osp.normpath(osp.join(root, basename))
if osp.isdir(path) and path in self.__expanded_state:
self.__expanded_state.pop(self.__expanded_state.index(path))
if self._to_be_loaded is None:
self._to_be_loaded = []
self._to_be_loaded.append(path)
self.setExpanded(self.get_index(path), True)
if not self.__expanded_state:
self.fsmodel.directoryLoaded.disconnect(self.restore_directory_state) | python | def restore_directory_state(self, fname):
"""Restore directory expanded state"""
root = osp.normpath(to_text_string(fname))
if not osp.exists(root):
# Directory has been (re)moved outside Spyder
return
for basename in os.listdir(root):
path = osp.normpath(osp.join(root, basename))
if osp.isdir(path) and path in self.__expanded_state:
self.__expanded_state.pop(self.__expanded_state.index(path))
if self._to_be_loaded is None:
self._to_be_loaded = []
self._to_be_loaded.append(path)
self.setExpanded(self.get_index(path), True)
if not self.__expanded_state:
self.fsmodel.directoryLoaded.disconnect(self.restore_directory_state) | [
"def",
"restore_directory_state",
"(",
"self",
",",
"fname",
")",
":",
"root",
"=",
"osp",
".",
"normpath",
"(",
"to_text_string",
"(",
"fname",
")",
")",
"if",
"not",
"osp",
".",
"exists",
"(",
"root",
")",
":",
"# Directory has been (re)moved outside Spyder\r",
"return",
"for",
"basename",
"in",
"os",
".",
"listdir",
"(",
"root",
")",
":",
"path",
"=",
"osp",
".",
"normpath",
"(",
"osp",
".",
"join",
"(",
"root",
",",
"basename",
")",
")",
"if",
"osp",
".",
"isdir",
"(",
"path",
")",
"and",
"path",
"in",
"self",
".",
"__expanded_state",
":",
"self",
".",
"__expanded_state",
".",
"pop",
"(",
"self",
".",
"__expanded_state",
".",
"index",
"(",
"path",
")",
")",
"if",
"self",
".",
"_to_be_loaded",
"is",
"None",
":",
"self",
".",
"_to_be_loaded",
"=",
"[",
"]",
"self",
".",
"_to_be_loaded",
".",
"append",
"(",
"path",
")",
"self",
".",
"setExpanded",
"(",
"self",
".",
"get_index",
"(",
"path",
")",
",",
"True",
")",
"if",
"not",
"self",
".",
"__expanded_state",
":",
"self",
".",
"fsmodel",
".",
"directoryLoaded",
".",
"disconnect",
"(",
"self",
".",
"restore_directory_state",
")"
] | Restore directory expanded state | [
"Restore",
"directory",
"expanded",
"state"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1086-L1101 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.follow_directories_loaded | def follow_directories_loaded(self, fname):
"""Follow directories loaded during startup"""
if self._to_be_loaded is None:
return
path = osp.normpath(to_text_string(fname))
if path in self._to_be_loaded:
self._to_be_loaded.remove(path)
if self._to_be_loaded is not None and len(self._to_be_loaded) == 0:
self.fsmodel.directoryLoaded.disconnect(
self.follow_directories_loaded)
if self._scrollbar_positions is not None:
# The tree view need some time to render branches:
QTimer.singleShot(50, self.restore_scrollbar_positions) | python | def follow_directories_loaded(self, fname):
"""Follow directories loaded during startup"""
if self._to_be_loaded is None:
return
path = osp.normpath(to_text_string(fname))
if path in self._to_be_loaded:
self._to_be_loaded.remove(path)
if self._to_be_loaded is not None and len(self._to_be_loaded) == 0:
self.fsmodel.directoryLoaded.disconnect(
self.follow_directories_loaded)
if self._scrollbar_positions is not None:
# The tree view need some time to render branches:
QTimer.singleShot(50, self.restore_scrollbar_positions) | [
"def",
"follow_directories_loaded",
"(",
"self",
",",
"fname",
")",
":",
"if",
"self",
".",
"_to_be_loaded",
"is",
"None",
":",
"return",
"path",
"=",
"osp",
".",
"normpath",
"(",
"to_text_string",
"(",
"fname",
")",
")",
"if",
"path",
"in",
"self",
".",
"_to_be_loaded",
":",
"self",
".",
"_to_be_loaded",
".",
"remove",
"(",
"path",
")",
"if",
"self",
".",
"_to_be_loaded",
"is",
"not",
"None",
"and",
"len",
"(",
"self",
".",
"_to_be_loaded",
")",
"==",
"0",
":",
"self",
".",
"fsmodel",
".",
"directoryLoaded",
".",
"disconnect",
"(",
"self",
".",
"follow_directories_loaded",
")",
"if",
"self",
".",
"_scrollbar_positions",
"is",
"not",
"None",
":",
"# The tree view need some time to render branches:\r",
"QTimer",
".",
"singleShot",
"(",
"50",
",",
"self",
".",
"restore_scrollbar_positions",
")"
] | Follow directories loaded during startup | [
"Follow",
"directories",
"loaded",
"during",
"startup"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1103-L1115 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.restore_expanded_state | def restore_expanded_state(self):
"""Restore all items expanded state"""
if self.__expanded_state is not None:
# In the old project explorer, the expanded state was a dictionnary:
if isinstance(self.__expanded_state, list):
self.fsmodel.directoryLoaded.connect(
self.restore_directory_state)
self.fsmodel.directoryLoaded.connect(
self.follow_directories_loaded) | python | def restore_expanded_state(self):
"""Restore all items expanded state"""
if self.__expanded_state is not None:
# In the old project explorer, the expanded state was a dictionnary:
if isinstance(self.__expanded_state, list):
self.fsmodel.directoryLoaded.connect(
self.restore_directory_state)
self.fsmodel.directoryLoaded.connect(
self.follow_directories_loaded) | [
"def",
"restore_expanded_state",
"(",
"self",
")",
":",
"if",
"self",
".",
"__expanded_state",
"is",
"not",
"None",
":",
"# In the old project explorer, the expanded state was a dictionnary:\r",
"if",
"isinstance",
"(",
"self",
".",
"__expanded_state",
",",
"list",
")",
":",
"self",
".",
"fsmodel",
".",
"directoryLoaded",
".",
"connect",
"(",
"self",
".",
"restore_directory_state",
")",
"self",
".",
"fsmodel",
".",
"directoryLoaded",
".",
"connect",
"(",
"self",
".",
"follow_directories_loaded",
")"
] | Restore all items expanded state | [
"Restore",
"all",
"items",
"expanded",
"state"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1117-L1125 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | DirView.filter_directories | def filter_directories(self):
"""Filter the directories to show"""
index = self.get_index('.spyproject')
if index is not None:
self.setRowHidden(index.row(), index.parent(), True) | python | def filter_directories(self):
"""Filter the directories to show"""
index = self.get_index('.spyproject')
if index is not None:
self.setRowHidden(index.row(), index.parent(), True) | [
"def",
"filter_directories",
"(",
"self",
")",
":",
"index",
"=",
"self",
".",
"get_index",
"(",
"'.spyproject'",
")",
"if",
"index",
"is",
"not",
"None",
":",
"self",
".",
"setRowHidden",
"(",
"index",
".",
"row",
"(",
")",
",",
"index",
".",
"parent",
"(",
")",
",",
"True",
")"
] | Filter the directories to show | [
"Filter",
"the",
"directories",
"to",
"show"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1127-L1131 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | ProxyModel.setup_filter | def setup_filter(self, root_path, path_list):
"""Setup proxy model filter parameters"""
self.root_path = osp.normpath(to_text_string(root_path))
self.path_list = [osp.normpath(to_text_string(p)) for p in path_list]
self.invalidateFilter() | python | def setup_filter(self, root_path, path_list):
"""Setup proxy model filter parameters"""
self.root_path = osp.normpath(to_text_string(root_path))
self.path_list = [osp.normpath(to_text_string(p)) for p in path_list]
self.invalidateFilter() | [
"def",
"setup_filter",
"(",
"self",
",",
"root_path",
",",
"path_list",
")",
":",
"self",
".",
"root_path",
"=",
"osp",
".",
"normpath",
"(",
"to_text_string",
"(",
"root_path",
")",
")",
"self",
".",
"path_list",
"=",
"[",
"osp",
".",
"normpath",
"(",
"to_text_string",
"(",
"p",
")",
")",
"for",
"p",
"in",
"path_list",
"]",
"self",
".",
"invalidateFilter",
"(",
")"
] | Setup proxy model filter parameters | [
"Setup",
"proxy",
"model",
"filter",
"parameters"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1141-L1145 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | ProxyModel.sort | def sort(self, column, order=Qt.AscendingOrder):
"""Reimplement Qt method"""
self.sourceModel().sort(column, order) | python | def sort(self, column, order=Qt.AscendingOrder):
"""Reimplement Qt method"""
self.sourceModel().sort(column, order) | [
"def",
"sort",
"(",
"self",
",",
"column",
",",
"order",
"=",
"Qt",
".",
"AscendingOrder",
")",
":",
"self",
".",
"sourceModel",
"(",
")",
".",
"sort",
"(",
"column",
",",
"order",
")"
] | Reimplement Qt method | [
"Reimplement",
"Qt",
"method"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1147-L1149 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | ProxyModel.filterAcceptsRow | def filterAcceptsRow(self, row, parent_index):
"""Reimplement Qt method"""
if self.root_path is None:
return True
index = self.sourceModel().index(row, 0, parent_index)
path = osp.normcase(osp.normpath(
to_text_string(self.sourceModel().filePath(index))))
if osp.normcase(self.root_path).startswith(path):
# This is necessary because parent folders need to be scanned
return True
else:
for p in [osp.normcase(p) for p in self.path_list]:
if path == p or path.startswith(p+os.sep):
return True
else:
return False | python | def filterAcceptsRow(self, row, parent_index):
"""Reimplement Qt method"""
if self.root_path is None:
return True
index = self.sourceModel().index(row, 0, parent_index)
path = osp.normcase(osp.normpath(
to_text_string(self.sourceModel().filePath(index))))
if osp.normcase(self.root_path).startswith(path):
# This is necessary because parent folders need to be scanned
return True
else:
for p in [osp.normcase(p) for p in self.path_list]:
if path == p or path.startswith(p+os.sep):
return True
else:
return False | [
"def",
"filterAcceptsRow",
"(",
"self",
",",
"row",
",",
"parent_index",
")",
":",
"if",
"self",
".",
"root_path",
"is",
"None",
":",
"return",
"True",
"index",
"=",
"self",
".",
"sourceModel",
"(",
")",
".",
"index",
"(",
"row",
",",
"0",
",",
"parent_index",
")",
"path",
"=",
"osp",
".",
"normcase",
"(",
"osp",
".",
"normpath",
"(",
"to_text_string",
"(",
"self",
".",
"sourceModel",
"(",
")",
".",
"filePath",
"(",
"index",
")",
")",
")",
")",
"if",
"osp",
".",
"normcase",
"(",
"self",
".",
"root_path",
")",
".",
"startswith",
"(",
"path",
")",
":",
"# This is necessary because parent folders need to be scanned\r",
"return",
"True",
"else",
":",
"for",
"p",
"in",
"[",
"osp",
".",
"normcase",
"(",
"p",
")",
"for",
"p",
"in",
"self",
".",
"path_list",
"]",
":",
"if",
"path",
"==",
"p",
"or",
"path",
".",
"startswith",
"(",
"p",
"+",
"os",
".",
"sep",
")",
":",
"return",
"True",
"else",
":",
"return",
"False"
] | Reimplement Qt method | [
"Reimplement",
"Qt",
"method"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1151-L1166 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | ProxyModel.data | def data(self, index, role):
"""Show tooltip with full path only for the root directory"""
if role == Qt.ToolTipRole:
root_dir = self.path_list[0].split(osp.sep)[-1]
if index.data() == root_dir:
return osp.join(self.root_path, root_dir)
return QSortFilterProxyModel.data(self, index, role) | python | def data(self, index, role):
"""Show tooltip with full path only for the root directory"""
if role == Qt.ToolTipRole:
root_dir = self.path_list[0].split(osp.sep)[-1]
if index.data() == root_dir:
return osp.join(self.root_path, root_dir)
return QSortFilterProxyModel.data(self, index, role) | [
"def",
"data",
"(",
"self",
",",
"index",
",",
"role",
")",
":",
"if",
"role",
"==",
"Qt",
".",
"ToolTipRole",
":",
"root_dir",
"=",
"self",
".",
"path_list",
"[",
"0",
"]",
".",
"split",
"(",
"osp",
".",
"sep",
")",
"[",
"-",
"1",
"]",
"if",
"index",
".",
"data",
"(",
")",
"==",
"root_dir",
":",
"return",
"osp",
".",
"join",
"(",
"self",
".",
"root_path",
",",
"root_dir",
")",
"return",
"QSortFilterProxyModel",
".",
"data",
"(",
"self",
",",
"index",
",",
"role",
")"
] | Show tooltip with full path only for the root directory | [
"Show",
"tooltip",
"with",
"full",
"path",
"only",
"for",
"the",
"root",
"directory"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1168-L1174 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | FilteredDirView.setup_proxy_model | def setup_proxy_model(self):
"""Setup proxy model"""
self.proxymodel = ProxyModel(self)
self.proxymodel.setSourceModel(self.fsmodel) | python | def setup_proxy_model(self):
"""Setup proxy model"""
self.proxymodel = ProxyModel(self)
self.proxymodel.setSourceModel(self.fsmodel) | [
"def",
"setup_proxy_model",
"(",
"self",
")",
":",
"self",
".",
"proxymodel",
"=",
"ProxyModel",
"(",
"self",
")",
"self",
".",
"proxymodel",
".",
"setSourceModel",
"(",
"self",
".",
"fsmodel",
")"
] | Setup proxy model | [
"Setup",
"proxy",
"model"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1185-L1188 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | FilteredDirView.set_root_path | def set_root_path(self, root_path):
"""Set root path"""
self.root_path = root_path
self.install_model()
index = self.fsmodel.setRootPath(root_path)
self.proxymodel.setup_filter(self.root_path, [])
self.setRootIndex(self.proxymodel.mapFromSource(index)) | python | def set_root_path(self, root_path):
"""Set root path"""
self.root_path = root_path
self.install_model()
index = self.fsmodel.setRootPath(root_path)
self.proxymodel.setup_filter(self.root_path, [])
self.setRootIndex(self.proxymodel.mapFromSource(index)) | [
"def",
"set_root_path",
"(",
"self",
",",
"root_path",
")",
":",
"self",
".",
"root_path",
"=",
"root_path",
"self",
".",
"install_model",
"(",
")",
"index",
"=",
"self",
".",
"fsmodel",
".",
"setRootPath",
"(",
"root_path",
")",
"self",
".",
"proxymodel",
".",
"setup_filter",
"(",
"self",
".",
"root_path",
",",
"[",
"]",
")",
"self",
".",
"setRootIndex",
"(",
"self",
".",
"proxymodel",
".",
"mapFromSource",
"(",
"index",
")",
")"
] | Set root path | [
"Set",
"root",
"path"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1195-L1201 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | FilteredDirView.get_index | def get_index(self, filename):
"""Return index associated with filename"""
index = self.fsmodel.index(filename)
if index.isValid() and index.model() is self.fsmodel:
return self.proxymodel.mapFromSource(index) | python | def get_index(self, filename):
"""Return index associated with filename"""
index = self.fsmodel.index(filename)
if index.isValid() and index.model() is self.fsmodel:
return self.proxymodel.mapFromSource(index) | [
"def",
"get_index",
"(",
"self",
",",
"filename",
")",
":",
"index",
"=",
"self",
".",
"fsmodel",
".",
"index",
"(",
"filename",
")",
"if",
"index",
".",
"isValid",
"(",
")",
"and",
"index",
".",
"model",
"(",
")",
"is",
"self",
".",
"fsmodel",
":",
"return",
"self",
".",
"proxymodel",
".",
"mapFromSource",
"(",
"index",
")"
] | Return index associated with filename | [
"Return",
"index",
"associated",
"with",
"filename"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1203-L1207 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | FilteredDirView.set_folder_names | def set_folder_names(self, folder_names):
"""Set folder names"""
assert self.root_path is not None
path_list = [osp.join(self.root_path, dirname)
for dirname in folder_names]
self.proxymodel.setup_filter(self.root_path, path_list) | python | def set_folder_names(self, folder_names):
"""Set folder names"""
assert self.root_path is not None
path_list = [osp.join(self.root_path, dirname)
for dirname in folder_names]
self.proxymodel.setup_filter(self.root_path, path_list) | [
"def",
"set_folder_names",
"(",
"self",
",",
"folder_names",
")",
":",
"assert",
"self",
".",
"root_path",
"is",
"not",
"None",
"path_list",
"=",
"[",
"osp",
".",
"join",
"(",
"self",
".",
"root_path",
",",
"dirname",
")",
"for",
"dirname",
"in",
"folder_names",
"]",
"self",
".",
"proxymodel",
".",
"setup_filter",
"(",
"self",
".",
"root_path",
",",
"path_list",
")"
] | Set folder names | [
"Set",
"folder",
"names"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1209-L1214 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | FilteredDirView.get_filename | def get_filename(self, index):
"""Return filename from index"""
if index:
path = self.fsmodel.filePath(self.proxymodel.mapToSource(index))
return osp.normpath(to_text_string(path)) | python | def get_filename(self, index):
"""Return filename from index"""
if index:
path = self.fsmodel.filePath(self.proxymodel.mapToSource(index))
return osp.normpath(to_text_string(path)) | [
"def",
"get_filename",
"(",
"self",
",",
"index",
")",
":",
"if",
"index",
":",
"path",
"=",
"self",
".",
"fsmodel",
".",
"filePath",
"(",
"self",
".",
"proxymodel",
".",
"mapToSource",
"(",
"index",
")",
")",
"return",
"osp",
".",
"normpath",
"(",
"to_text_string",
"(",
"path",
")",
")"
] | Return filename from index | [
"Return",
"filename",
"from",
"index"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1216-L1220 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | FilteredDirView.setup_project_view | def setup_project_view(self):
"""Setup view for projects"""
for i in [1, 2, 3]:
self.hideColumn(i)
self.setHeaderHidden(True)
# Disable the view of .spyproject.
self.filter_directories() | python | def setup_project_view(self):
"""Setup view for projects"""
for i in [1, 2, 3]:
self.hideColumn(i)
self.setHeaderHidden(True)
# Disable the view of .spyproject.
self.filter_directories() | [
"def",
"setup_project_view",
"(",
"self",
")",
":",
"for",
"i",
"in",
"[",
"1",
",",
"2",
",",
"3",
"]",
":",
"self",
".",
"hideColumn",
"(",
"i",
")",
"self",
".",
"setHeaderHidden",
"(",
"True",
")",
"# Disable the view of .spyproject. \r",
"self",
".",
"filter_directories",
"(",
")"
] | Setup view for projects | [
"Setup",
"view",
"for",
"projects"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1222-L1228 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | ExplorerTreeWidget.setup_common_actions | def setup_common_actions(self):
"""Setup context menu common actions"""
actions = super(ExplorerTreeWidget, self).setup_common_actions()
if self.show_cd_only is None:
# Enabling the 'show current directory only' option but do not
# allow the user to disable it
self.show_cd_only = True
else:
# Show current directory only
cd_only_action = create_action(self,
_("Show current directory only"),
toggled=self.toggle_show_cd_only)
cd_only_action.setChecked(self.show_cd_only)
self.toggle_show_cd_only(self.show_cd_only)
actions.append(cd_only_action)
return actions | python | def setup_common_actions(self):
"""Setup context menu common actions"""
actions = super(ExplorerTreeWidget, self).setup_common_actions()
if self.show_cd_only is None:
# Enabling the 'show current directory only' option but do not
# allow the user to disable it
self.show_cd_only = True
else:
# Show current directory only
cd_only_action = create_action(self,
_("Show current directory only"),
toggled=self.toggle_show_cd_only)
cd_only_action.setChecked(self.show_cd_only)
self.toggle_show_cd_only(self.show_cd_only)
actions.append(cd_only_action)
return actions | [
"def",
"setup_common_actions",
"(",
"self",
")",
":",
"actions",
"=",
"super",
"(",
"ExplorerTreeWidget",
",",
"self",
")",
".",
"setup_common_actions",
"(",
")",
"if",
"self",
".",
"show_cd_only",
"is",
"None",
":",
"# Enabling the 'show current directory only' option but do not\r",
"# allow the user to disable it\r",
"self",
".",
"show_cd_only",
"=",
"True",
"else",
":",
"# Show current directory only\r",
"cd_only_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Show current directory only\"",
")",
",",
"toggled",
"=",
"self",
".",
"toggle_show_cd_only",
")",
"cd_only_action",
".",
"setChecked",
"(",
"self",
".",
"show_cd_only",
")",
"self",
".",
"toggle_show_cd_only",
"(",
"self",
".",
"show_cd_only",
")",
"actions",
".",
"append",
"(",
"cd_only_action",
")",
"return",
"actions"
] | Setup context menu common actions | [
"Setup",
"context",
"menu",
"common",
"actions"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1257-L1272 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | ExplorerTreeWidget.toggle_show_cd_only | def toggle_show_cd_only(self, checked):
"""Toggle show current directory only mode"""
self.parent_widget.sig_option_changed.emit('show_cd_only', checked)
self.show_cd_only = checked
if checked:
if self.__last_folder is not None:
self.set_current_folder(self.__last_folder)
elif self.__original_root_index is not None:
self.setRootIndex(self.__original_root_index) | python | def toggle_show_cd_only(self, checked):
"""Toggle show current directory only mode"""
self.parent_widget.sig_option_changed.emit('show_cd_only', checked)
self.show_cd_only = checked
if checked:
if self.__last_folder is not None:
self.set_current_folder(self.__last_folder)
elif self.__original_root_index is not None:
self.setRootIndex(self.__original_root_index) | [
"def",
"toggle_show_cd_only",
"(",
"self",
",",
"checked",
")",
":",
"self",
".",
"parent_widget",
".",
"sig_option_changed",
".",
"emit",
"(",
"'show_cd_only'",
",",
"checked",
")",
"self",
".",
"show_cd_only",
"=",
"checked",
"if",
"checked",
":",
"if",
"self",
".",
"__last_folder",
"is",
"not",
"None",
":",
"self",
".",
"set_current_folder",
"(",
"self",
".",
"__last_folder",
")",
"elif",
"self",
".",
"__original_root_index",
"is",
"not",
"None",
":",
"self",
".",
"setRootIndex",
"(",
"self",
".",
"__original_root_index",
")"
] | Toggle show current directory only mode | [
"Toggle",
"show",
"current",
"directory",
"only",
"mode"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1275-L1283 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | ExplorerTreeWidget.set_current_folder | def set_current_folder(self, folder):
"""Set current folder and return associated model index"""
index = self.fsmodel.setRootPath(folder)
self.__last_folder = folder
if self.show_cd_only:
if self.__original_root_index is None:
self.__original_root_index = self.rootIndex()
self.setRootIndex(index)
return index | python | def set_current_folder(self, folder):
"""Set current folder and return associated model index"""
index = self.fsmodel.setRootPath(folder)
self.__last_folder = folder
if self.show_cd_only:
if self.__original_root_index is None:
self.__original_root_index = self.rootIndex()
self.setRootIndex(index)
return index | [
"def",
"set_current_folder",
"(",
"self",
",",
"folder",
")",
":",
"index",
"=",
"self",
".",
"fsmodel",
".",
"setRootPath",
"(",
"folder",
")",
"self",
".",
"__last_folder",
"=",
"folder",
"if",
"self",
".",
"show_cd_only",
":",
"if",
"self",
".",
"__original_root_index",
"is",
"None",
":",
"self",
".",
"__original_root_index",
"=",
"self",
".",
"rootIndex",
"(",
")",
"self",
".",
"setRootIndex",
"(",
"index",
")",
"return",
"index"
] | Set current folder and return associated model index | [
"Set",
"current",
"folder",
"and",
"return",
"associated",
"model",
"index"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1286-L1294 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | ExplorerTreeWidget.refresh | def refresh(self, new_path=None, force_current=False):
"""Refresh widget
force=False: won't refresh widget if path has not changed"""
if new_path is None:
new_path = getcwd_or_home()
if force_current:
index = self.set_current_folder(new_path)
self.expand(index)
self.setCurrentIndex(index)
self.set_previous_enabled.emit(
self.histindex is not None and self.histindex > 0)
self.set_next_enabled.emit(self.histindex is not None and \
self.histindex < len(self.history)-1)
# Disable the view of .spyproject.
self.filter_directories() | python | def refresh(self, new_path=None, force_current=False):
"""Refresh widget
force=False: won't refresh widget if path has not changed"""
if new_path is None:
new_path = getcwd_or_home()
if force_current:
index = self.set_current_folder(new_path)
self.expand(index)
self.setCurrentIndex(index)
self.set_previous_enabled.emit(
self.histindex is not None and self.histindex > 0)
self.set_next_enabled.emit(self.histindex is not None and \
self.histindex < len(self.history)-1)
# Disable the view of .spyproject.
self.filter_directories() | [
"def",
"refresh",
"(",
"self",
",",
"new_path",
"=",
"None",
",",
"force_current",
"=",
"False",
")",
":",
"if",
"new_path",
"is",
"None",
":",
"new_path",
"=",
"getcwd_or_home",
"(",
")",
"if",
"force_current",
":",
"index",
"=",
"self",
".",
"set_current_folder",
"(",
"new_path",
")",
"self",
".",
"expand",
"(",
"index",
")",
"self",
".",
"setCurrentIndex",
"(",
"index",
")",
"self",
".",
"set_previous_enabled",
".",
"emit",
"(",
"self",
".",
"histindex",
"is",
"not",
"None",
"and",
"self",
".",
"histindex",
">",
"0",
")",
"self",
".",
"set_next_enabled",
".",
"emit",
"(",
"self",
".",
"histindex",
"is",
"not",
"None",
"and",
"self",
".",
"histindex",
"<",
"len",
"(",
"self",
".",
"history",
")",
"-",
"1",
")",
"# Disable the view of .spyproject. \r",
"self",
".",
"filter_directories",
"(",
")"
] | Refresh widget
force=False: won't refresh widget if path has not changed | [
"Refresh",
"widget",
"force",
"=",
"False",
":",
"won",
"t",
"refresh",
"widget",
"if",
"path",
"has",
"not",
"changed"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1299-L1313 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | ExplorerTreeWidget.go_to_parent_directory | def go_to_parent_directory(self):
"""Go to parent directory"""
self.chdir(osp.abspath(osp.join(getcwd_or_home(), os.pardir))) | python | def go_to_parent_directory(self):
"""Go to parent directory"""
self.chdir(osp.abspath(osp.join(getcwd_or_home(), os.pardir))) | [
"def",
"go_to_parent_directory",
"(",
"self",
")",
":",
"self",
".",
"chdir",
"(",
"osp",
".",
"abspath",
"(",
"osp",
".",
"join",
"(",
"getcwd_or_home",
"(",
")",
",",
"os",
".",
"pardir",
")",
")",
")"
] | Go to parent directory | [
"Go",
"to",
"parent",
"directory"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1322-L1324 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | ExplorerTreeWidget.update_history | def update_history(self, directory):
"""Update browse history"""
try:
directory = osp.abspath(to_text_string(directory))
if directory in self.history:
self.histindex = self.history.index(directory)
except Exception:
user_directory = get_home_dir()
self.chdir(directory=user_directory, browsing_history=True) | python | def update_history(self, directory):
"""Update browse history"""
try:
directory = osp.abspath(to_text_string(directory))
if directory in self.history:
self.histindex = self.history.index(directory)
except Exception:
user_directory = get_home_dir()
self.chdir(directory=user_directory, browsing_history=True) | [
"def",
"update_history",
"(",
"self",
",",
"directory",
")",
":",
"try",
":",
"directory",
"=",
"osp",
".",
"abspath",
"(",
"to_text_string",
"(",
"directory",
")",
")",
"if",
"directory",
"in",
"self",
".",
"history",
":",
"self",
".",
"histindex",
"=",
"self",
".",
"history",
".",
"index",
"(",
"directory",
")",
"except",
"Exception",
":",
"user_directory",
"=",
"get_home_dir",
"(",
")",
"self",
".",
"chdir",
"(",
"directory",
"=",
"user_directory",
",",
"browsing_history",
"=",
"True",
")"
] | Update browse history | [
"Update",
"browse",
"history"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1338-L1346 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | ExplorerTreeWidget.chdir | def chdir(self, directory=None, browsing_history=False):
"""Set directory as working directory"""
if directory is not None:
directory = osp.abspath(to_text_string(directory))
if browsing_history:
directory = self.history[self.histindex]
elif directory in self.history:
self.histindex = self.history.index(directory)
else:
if self.histindex is None:
self.history = []
else:
self.history = self.history[:self.histindex+1]
if len(self.history) == 0 or \
(self.history and self.history[-1] != directory):
self.history.append(directory)
self.histindex = len(self.history)-1
directory = to_text_string(directory)
try:
PermissionError
FileNotFoundError
except NameError:
PermissionError = OSError
if os.name == 'nt':
FileNotFoundError = WindowsError
else:
FileNotFoundError = IOError
try:
os.chdir(directory)
self.sig_open_dir.emit(directory)
self.refresh(new_path=directory, force_current=True)
except PermissionError:
QMessageBox.critical(self.parent_widget, "Error",
_("You don't have the right permissions to "
"open this directory"))
except FileNotFoundError:
# Handle renaming directories on the fly. See issue #5183
self.history.pop(self.histindex) | python | def chdir(self, directory=None, browsing_history=False):
"""Set directory as working directory"""
if directory is not None:
directory = osp.abspath(to_text_string(directory))
if browsing_history:
directory = self.history[self.histindex]
elif directory in self.history:
self.histindex = self.history.index(directory)
else:
if self.histindex is None:
self.history = []
else:
self.history = self.history[:self.histindex+1]
if len(self.history) == 0 or \
(self.history and self.history[-1] != directory):
self.history.append(directory)
self.histindex = len(self.history)-1
directory = to_text_string(directory)
try:
PermissionError
FileNotFoundError
except NameError:
PermissionError = OSError
if os.name == 'nt':
FileNotFoundError = WindowsError
else:
FileNotFoundError = IOError
try:
os.chdir(directory)
self.sig_open_dir.emit(directory)
self.refresh(new_path=directory, force_current=True)
except PermissionError:
QMessageBox.critical(self.parent_widget, "Error",
_("You don't have the right permissions to "
"open this directory"))
except FileNotFoundError:
# Handle renaming directories on the fly. See issue #5183
self.history.pop(self.histindex) | [
"def",
"chdir",
"(",
"self",
",",
"directory",
"=",
"None",
",",
"browsing_history",
"=",
"False",
")",
":",
"if",
"directory",
"is",
"not",
"None",
":",
"directory",
"=",
"osp",
".",
"abspath",
"(",
"to_text_string",
"(",
"directory",
")",
")",
"if",
"browsing_history",
":",
"directory",
"=",
"self",
".",
"history",
"[",
"self",
".",
"histindex",
"]",
"elif",
"directory",
"in",
"self",
".",
"history",
":",
"self",
".",
"histindex",
"=",
"self",
".",
"history",
".",
"index",
"(",
"directory",
")",
"else",
":",
"if",
"self",
".",
"histindex",
"is",
"None",
":",
"self",
".",
"history",
"=",
"[",
"]",
"else",
":",
"self",
".",
"history",
"=",
"self",
".",
"history",
"[",
":",
"self",
".",
"histindex",
"+",
"1",
"]",
"if",
"len",
"(",
"self",
".",
"history",
")",
"==",
"0",
"or",
"(",
"self",
".",
"history",
"and",
"self",
".",
"history",
"[",
"-",
"1",
"]",
"!=",
"directory",
")",
":",
"self",
".",
"history",
".",
"append",
"(",
"directory",
")",
"self",
".",
"histindex",
"=",
"len",
"(",
"self",
".",
"history",
")",
"-",
"1",
"directory",
"=",
"to_text_string",
"(",
"directory",
")",
"try",
":",
"PermissionError",
"FileNotFoundError",
"except",
"NameError",
":",
"PermissionError",
"=",
"OSError",
"if",
"os",
".",
"name",
"==",
"'nt'",
":",
"FileNotFoundError",
"=",
"WindowsError",
"else",
":",
"FileNotFoundError",
"=",
"IOError",
"try",
":",
"os",
".",
"chdir",
"(",
"directory",
")",
"self",
".",
"sig_open_dir",
".",
"emit",
"(",
"directory",
")",
"self",
".",
"refresh",
"(",
"new_path",
"=",
"directory",
",",
"force_current",
"=",
"True",
")",
"except",
"PermissionError",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
".",
"parent_widget",
",",
"\"Error\"",
",",
"_",
"(",
"\"You don't have the right permissions to \"",
"\"open this directory\"",
")",
")",
"except",
"FileNotFoundError",
":",
"# Handle renaming directories on the fly. See issue #5183\r",
"self",
".",
"history",
".",
"pop",
"(",
"self",
".",
"histindex",
")"
] | Set directory as working directory | [
"Set",
"directory",
"as",
"working",
"directory"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1348-L1385 | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | ExplorerWidget.toggle_icontext | def toggle_icontext(self, state):
"""Toggle icon text"""
self.sig_option_changed.emit('show_icontext', state)
for widget in self.action_widgets:
if widget is not self.button_menu:
if state:
widget.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
else:
widget.setToolButtonStyle(Qt.ToolButtonIconOnly) | python | def toggle_icontext(self, state):
"""Toggle icon text"""
self.sig_option_changed.emit('show_icontext', state)
for widget in self.action_widgets:
if widget is not self.button_menu:
if state:
widget.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
else:
widget.setToolButtonStyle(Qt.ToolButtonIconOnly) | [
"def",
"toggle_icontext",
"(",
"self",
",",
"state",
")",
":",
"self",
".",
"sig_option_changed",
".",
"emit",
"(",
"'show_icontext'",
",",
"state",
")",
"for",
"widget",
"in",
"self",
".",
"action_widgets",
":",
"if",
"widget",
"is",
"not",
"self",
".",
"button_menu",
":",
"if",
"state",
":",
"widget",
".",
"setToolButtonStyle",
"(",
"Qt",
".",
"ToolButtonTextBesideIcon",
")",
"else",
":",
"widget",
".",
"setToolButtonStyle",
"(",
"Qt",
".",
"ToolButtonIconOnly",
")"
] | Toggle icon text | [
"Toggle",
"icon",
"text"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L1463-L1471 | train |
spyder-ide/spyder | spyder/plugins/breakpoints/widgets/breakpointsgui.py | BreakpointTableModel.set_data | def set_data(self, data):
"""Set model data"""
self._data = data
keys = list(data.keys())
self.breakpoints = []
for key in keys:
bp_list = data[key]
if bp_list:
for item in data[key]:
self.breakpoints.append((key, item[0], item[1], ""))
self.reset() | python | def set_data(self, data):
"""Set model data"""
self._data = data
keys = list(data.keys())
self.breakpoints = []
for key in keys:
bp_list = data[key]
if bp_list:
for item in data[key]:
self.breakpoints.append((key, item[0], item[1], ""))
self.reset() | [
"def",
"set_data",
"(",
"self",
",",
"data",
")",
":",
"self",
".",
"_data",
"=",
"data",
"keys",
"=",
"list",
"(",
"data",
".",
"keys",
"(",
")",
")",
"self",
".",
"breakpoints",
"=",
"[",
"]",
"for",
"key",
"in",
"keys",
":",
"bp_list",
"=",
"data",
"[",
"key",
"]",
"if",
"bp_list",
":",
"for",
"item",
"in",
"data",
"[",
"key",
"]",
":",
"self",
".",
"breakpoints",
".",
"append",
"(",
"(",
"key",
",",
"item",
"[",
"0",
"]",
",",
"item",
"[",
"1",
"]",
",",
"\"\"",
")",
")",
"self",
".",
"reset",
"(",
")"
] | Set model data | [
"Set",
"model",
"data"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/breakpoints/widgets/breakpointsgui.py#L57-L67 | train |
spyder-ide/spyder | spyder/plugins/breakpoints/widgets/breakpointsgui.py | BreakpointTableModel.sort | def sort(self, column, order=Qt.DescendingOrder):
"""Overriding sort method"""
if column == 0:
self.breakpoints.sort(
key=lambda breakpoint: breakpoint[1])
self.breakpoints.sort(
key=lambda breakpoint: osp.basename(breakpoint[0]))
elif column == 1:
pass
elif column == 2:
pass
elif column == 3:
pass
self.reset() | python | def sort(self, column, order=Qt.DescendingOrder):
"""Overriding sort method"""
if column == 0:
self.breakpoints.sort(
key=lambda breakpoint: breakpoint[1])
self.breakpoints.sort(
key=lambda breakpoint: osp.basename(breakpoint[0]))
elif column == 1:
pass
elif column == 2:
pass
elif column == 3:
pass
self.reset() | [
"def",
"sort",
"(",
"self",
",",
"column",
",",
"order",
"=",
"Qt",
".",
"DescendingOrder",
")",
":",
"if",
"column",
"==",
"0",
":",
"self",
".",
"breakpoints",
".",
"sort",
"(",
"key",
"=",
"lambda",
"breakpoint",
":",
"breakpoint",
"[",
"1",
"]",
")",
"self",
".",
"breakpoints",
".",
"sort",
"(",
"key",
"=",
"lambda",
"breakpoint",
":",
"osp",
".",
"basename",
"(",
"breakpoint",
"[",
"0",
"]",
")",
")",
"elif",
"column",
"==",
"1",
":",
"pass",
"elif",
"column",
"==",
"2",
":",
"pass",
"elif",
"column",
"==",
"3",
":",
"pass",
"self",
".",
"reset",
"(",
")"
] | Overriding sort method | [
"Overriding",
"sort",
"method"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/breakpoints/widgets/breakpointsgui.py#L77-L90 | train |
spyder-ide/spyder | spyder/plugins/breakpoints/widgets/breakpointsgui.py | BreakpointTableModel.data | def data(self, index, role=Qt.DisplayRole):
"""Return data at table index"""
if not index.isValid():
return to_qvariant()
if role == Qt.DisplayRole:
if index.column() == 0:
value = osp.basename(self.get_value(index))
return to_qvariant(value)
else:
value = self.get_value(index)
return to_qvariant(value)
elif role == Qt.TextAlignmentRole:
return to_qvariant(int(Qt.AlignLeft|Qt.AlignVCenter))
elif role == Qt.ToolTipRole:
if index.column() == 0:
value = self.get_value(index)
return to_qvariant(value)
else:
return to_qvariant() | python | def data(self, index, role=Qt.DisplayRole):
"""Return data at table index"""
if not index.isValid():
return to_qvariant()
if role == Qt.DisplayRole:
if index.column() == 0:
value = osp.basename(self.get_value(index))
return to_qvariant(value)
else:
value = self.get_value(index)
return to_qvariant(value)
elif role == Qt.TextAlignmentRole:
return to_qvariant(int(Qt.AlignLeft|Qt.AlignVCenter))
elif role == Qt.ToolTipRole:
if index.column() == 0:
value = self.get_value(index)
return to_qvariant(value)
else:
return to_qvariant() | [
"def",
"data",
"(",
"self",
",",
"index",
",",
"role",
"=",
"Qt",
".",
"DisplayRole",
")",
":",
"if",
"not",
"index",
".",
"isValid",
"(",
")",
":",
"return",
"to_qvariant",
"(",
")",
"if",
"role",
"==",
"Qt",
".",
"DisplayRole",
":",
"if",
"index",
".",
"column",
"(",
")",
"==",
"0",
":",
"value",
"=",
"osp",
".",
"basename",
"(",
"self",
".",
"get_value",
"(",
"index",
")",
")",
"return",
"to_qvariant",
"(",
"value",
")",
"else",
":",
"value",
"=",
"self",
".",
"get_value",
"(",
"index",
")",
"return",
"to_qvariant",
"(",
"value",
")",
"elif",
"role",
"==",
"Qt",
".",
"TextAlignmentRole",
":",
"return",
"to_qvariant",
"(",
"int",
"(",
"Qt",
".",
"AlignLeft",
"|",
"Qt",
".",
"AlignVCenter",
")",
")",
"elif",
"role",
"==",
"Qt",
".",
"ToolTipRole",
":",
"if",
"index",
".",
"column",
"(",
")",
"==",
"0",
":",
"value",
"=",
"self",
".",
"get_value",
"(",
"index",
")",
"return",
"to_qvariant",
"(",
"value",
")",
"else",
":",
"return",
"to_qvariant",
"(",
")"
] | Return data at table index | [
"Return",
"data",
"at",
"table",
"index"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/breakpoints/widgets/breakpointsgui.py#L107-L125 | train |
spyder-ide/spyder | spyder/plugins/breakpoints/widgets/breakpointsgui.py | BreakpointTableView.setup_table | def setup_table(self):
"""Setup table"""
self.horizontalHeader().setStretchLastSection(True)
self.adjust_columns()
self.columnAt(0)
# Sorting columns
self.setSortingEnabled(False)
self.sortByColumn(0, Qt.DescendingOrder) | python | def setup_table(self):
"""Setup table"""
self.horizontalHeader().setStretchLastSection(True)
self.adjust_columns()
self.columnAt(0)
# Sorting columns
self.setSortingEnabled(False)
self.sortByColumn(0, Qt.DescendingOrder) | [
"def",
"setup_table",
"(",
"self",
")",
":",
"self",
".",
"horizontalHeader",
"(",
")",
".",
"setStretchLastSection",
"(",
"True",
")",
"self",
".",
"adjust_columns",
"(",
")",
"self",
".",
"columnAt",
"(",
"0",
")",
"# Sorting columns\r",
"self",
".",
"setSortingEnabled",
"(",
"False",
")",
"self",
".",
"sortByColumn",
"(",
"0",
",",
"Qt",
".",
"DescendingOrder",
")"
] | Setup table | [
"Setup",
"table"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/breakpoints/widgets/breakpointsgui.py#L152-L159 | train |
spyder-ide/spyder | spyder/plugins/breakpoints/widgets/breakpointsgui.py | BreakpointTableView.mouseDoubleClickEvent | def mouseDoubleClickEvent(self, event):
"""Reimplement Qt method"""
index_clicked = self.indexAt(event.pos())
if self.model.breakpoints:
filename = self.model.breakpoints[index_clicked.row()][0]
line_number_str = self.model.breakpoints[index_clicked.row()][1]
self.edit_goto.emit(filename, int(line_number_str), '')
if index_clicked.column()==2:
self.set_or_edit_conditional_breakpoint.emit() | python | def mouseDoubleClickEvent(self, event):
"""Reimplement Qt method"""
index_clicked = self.indexAt(event.pos())
if self.model.breakpoints:
filename = self.model.breakpoints[index_clicked.row()][0]
line_number_str = self.model.breakpoints[index_clicked.row()][1]
self.edit_goto.emit(filename, int(line_number_str), '')
if index_clicked.column()==2:
self.set_or_edit_conditional_breakpoint.emit() | [
"def",
"mouseDoubleClickEvent",
"(",
"self",
",",
"event",
")",
":",
"index_clicked",
"=",
"self",
".",
"indexAt",
"(",
"event",
".",
"pos",
"(",
")",
")",
"if",
"self",
".",
"model",
".",
"breakpoints",
":",
"filename",
"=",
"self",
".",
"model",
".",
"breakpoints",
"[",
"index_clicked",
".",
"row",
"(",
")",
"]",
"[",
"0",
"]",
"line_number_str",
"=",
"self",
".",
"model",
".",
"breakpoints",
"[",
"index_clicked",
".",
"row",
"(",
")",
"]",
"[",
"1",
"]",
"self",
".",
"edit_goto",
".",
"emit",
"(",
"filename",
",",
"int",
"(",
"line_number_str",
")",
",",
"''",
")",
"if",
"index_clicked",
".",
"column",
"(",
")",
"==",
"2",
":",
"self",
".",
"set_or_edit_conditional_breakpoint",
".",
"emit",
"(",
")"
] | Reimplement Qt method | [
"Reimplement",
"Qt",
"method"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/breakpoints/widgets/breakpointsgui.py#L166-L174 | train |
spyder-ide/spyder | spyder/plugins/editor/lsp/manager.py | LSPManager.get_languages | def get_languages(self):
"""
Get the list of languages we need to start servers and create
clients for.
"""
languages = ['python']
all_options = CONF.options(self.CONF_SECTION)
for option in all_options:
if option in [l.lower() for l in LSP_LANGUAGES]:
languages.append(option)
return languages | python | def get_languages(self):
"""
Get the list of languages we need to start servers and create
clients for.
"""
languages = ['python']
all_options = CONF.options(self.CONF_SECTION)
for option in all_options:
if option in [l.lower() for l in LSP_LANGUAGES]:
languages.append(option)
return languages | [
"def",
"get_languages",
"(",
"self",
")",
":",
"languages",
"=",
"[",
"'python'",
"]",
"all_options",
"=",
"CONF",
".",
"options",
"(",
"self",
".",
"CONF_SECTION",
")",
"for",
"option",
"in",
"all_options",
":",
"if",
"option",
"in",
"[",
"l",
".",
"lower",
"(",
")",
"for",
"l",
"in",
"LSP_LANGUAGES",
"]",
":",
"languages",
".",
"append",
"(",
"option",
")",
"return",
"languages"
] | Get the list of languages we need to start servers and create
clients for. | [
"Get",
"the",
"list",
"of",
"languages",
"we",
"need",
"to",
"start",
"servers",
"and",
"create",
"clients",
"for",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/lsp/manager.py#L68-L78 | train |
spyder-ide/spyder | spyder/plugins/editor/lsp/manager.py | LSPManager.get_root_path | def get_root_path(self, language):
"""
Get root path to pass to the LSP servers.
This can be the current project path or the output of
getcwd_or_home (except for Python, see below).
"""
path = None
# Get path of the current project
if self.main and self.main.projects:
path = self.main.projects.get_active_project_path()
# If there's no project, use the output of getcwd_or_home.
if not path:
# We can't use getcwd_or_home for Python because if it
# returns home and you have a lot of Python files on it
# then computing Rope completions takes a long time
# and blocks the PyLS server.
# Instead we use an empty directory inside our config one,
# just like we did for Rope in Spyder 3.
if language == 'python':
path = get_conf_path('lsp_root_path')
if not osp.exists(path):
os.mkdir(path)
else:
path = getcwd_or_home()
return path | python | def get_root_path(self, language):
"""
Get root path to pass to the LSP servers.
This can be the current project path or the output of
getcwd_or_home (except for Python, see below).
"""
path = None
# Get path of the current project
if self.main and self.main.projects:
path = self.main.projects.get_active_project_path()
# If there's no project, use the output of getcwd_or_home.
if not path:
# We can't use getcwd_or_home for Python because if it
# returns home and you have a lot of Python files on it
# then computing Rope completions takes a long time
# and blocks the PyLS server.
# Instead we use an empty directory inside our config one,
# just like we did for Rope in Spyder 3.
if language == 'python':
path = get_conf_path('lsp_root_path')
if not osp.exists(path):
os.mkdir(path)
else:
path = getcwd_or_home()
return path | [
"def",
"get_root_path",
"(",
"self",
",",
"language",
")",
":",
"path",
"=",
"None",
"# Get path of the current project",
"if",
"self",
".",
"main",
"and",
"self",
".",
"main",
".",
"projects",
":",
"path",
"=",
"self",
".",
"main",
".",
"projects",
".",
"get_active_project_path",
"(",
")",
"# If there's no project, use the output of getcwd_or_home.",
"if",
"not",
"path",
":",
"# We can't use getcwd_or_home for Python because if it",
"# returns home and you have a lot of Python files on it",
"# then computing Rope completions takes a long time",
"# and blocks the PyLS server.",
"# Instead we use an empty directory inside our config one,",
"# just like we did for Rope in Spyder 3.",
"if",
"language",
"==",
"'python'",
":",
"path",
"=",
"get_conf_path",
"(",
"'lsp_root_path'",
")",
"if",
"not",
"osp",
".",
"exists",
"(",
"path",
")",
":",
"os",
".",
"mkdir",
"(",
"path",
")",
"else",
":",
"path",
"=",
"getcwd_or_home",
"(",
")",
"return",
"path"
] | Get root path to pass to the LSP servers.
This can be the current project path or the output of
getcwd_or_home (except for Python, see below). | [
"Get",
"root",
"path",
"to",
"pass",
"to",
"the",
"LSP",
"servers",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/lsp/manager.py#L87-L115 | train |
spyder-ide/spyder | spyder/plugins/editor/lsp/manager.py | LSPManager.reinitialize_all_clients | def reinitialize_all_clients(self):
"""
Send a new initialize message to each LSP server when the project
path has changed so they can update the respective server root paths.
"""
for language in self.clients:
language_client = self.clients[language]
if language_client['status'] == self.RUNNING:
folder = self.get_root_path(language)
instance = language_client['instance']
instance.folder = folder
instance.initialize() | python | def reinitialize_all_clients(self):
"""
Send a new initialize message to each LSP server when the project
path has changed so they can update the respective server root paths.
"""
for language in self.clients:
language_client = self.clients[language]
if language_client['status'] == self.RUNNING:
folder = self.get_root_path(language)
instance = language_client['instance']
instance.folder = folder
instance.initialize() | [
"def",
"reinitialize_all_clients",
"(",
"self",
")",
":",
"for",
"language",
"in",
"self",
".",
"clients",
":",
"language_client",
"=",
"self",
".",
"clients",
"[",
"language",
"]",
"if",
"language_client",
"[",
"'status'",
"]",
"==",
"self",
".",
"RUNNING",
":",
"folder",
"=",
"self",
".",
"get_root_path",
"(",
"language",
")",
"instance",
"=",
"language_client",
"[",
"'instance'",
"]",
"instance",
".",
"folder",
"=",
"folder",
"instance",
".",
"initialize",
"(",
")"
] | Send a new initialize message to each LSP server when the project
path has changed so they can update the respective server root paths. | [
"Send",
"a",
"new",
"initialize",
"message",
"to",
"each",
"LSP",
"server",
"when",
"the",
"project",
"path",
"has",
"changed",
"so",
"they",
"can",
"update",
"the",
"respective",
"server",
"root",
"paths",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/lsp/manager.py#L118-L129 | train |
spyder-ide/spyder | spyder/plugins/editor/lsp/manager.py | LSPManager.start_client | def start_client(self, language):
"""Start an LSP client for a given language."""
started = False
if language in self.clients:
language_client = self.clients[language]
queue = self.register_queue[language]
# Don't start LSP services when testing unless we demand
# them.
if running_under_pytest():
if not os.environ.get('SPY_TEST_USE_INTROSPECTION'):
return started
# Start client
started = language_client['status'] == self.RUNNING
if language_client['status'] == self.STOPPED:
config = language_client['config']
if not config['external']:
port = select_port(default_port=config['port'])
config['port'] = port
language_client['instance'] = LSPClient(
parent=self,
server_settings=config,
folder=self.get_root_path(language),
language=language
)
# Connect signals emitted by the client to the methods that
# can handle them
if self.main and self.main.editor:
language_client['instance'].sig_initialize.connect(
self.main.editor.register_lsp_server_settings)
logger.info("Starting LSP client for {}...".format(language))
language_client['instance'].start()
language_client['status'] = self.RUNNING
for entry in queue:
language_client.register_file(*entry)
self.register_queue[language] = []
return started | python | def start_client(self, language):
"""Start an LSP client for a given language."""
started = False
if language in self.clients:
language_client = self.clients[language]
queue = self.register_queue[language]
# Don't start LSP services when testing unless we demand
# them.
if running_under_pytest():
if not os.environ.get('SPY_TEST_USE_INTROSPECTION'):
return started
# Start client
started = language_client['status'] == self.RUNNING
if language_client['status'] == self.STOPPED:
config = language_client['config']
if not config['external']:
port = select_port(default_port=config['port'])
config['port'] = port
language_client['instance'] = LSPClient(
parent=self,
server_settings=config,
folder=self.get_root_path(language),
language=language
)
# Connect signals emitted by the client to the methods that
# can handle them
if self.main and self.main.editor:
language_client['instance'].sig_initialize.connect(
self.main.editor.register_lsp_server_settings)
logger.info("Starting LSP client for {}...".format(language))
language_client['instance'].start()
language_client['status'] = self.RUNNING
for entry in queue:
language_client.register_file(*entry)
self.register_queue[language] = []
return started | [
"def",
"start_client",
"(",
"self",
",",
"language",
")",
":",
"started",
"=",
"False",
"if",
"language",
"in",
"self",
".",
"clients",
":",
"language_client",
"=",
"self",
".",
"clients",
"[",
"language",
"]",
"queue",
"=",
"self",
".",
"register_queue",
"[",
"language",
"]",
"# Don't start LSP services when testing unless we demand",
"# them.",
"if",
"running_under_pytest",
"(",
")",
":",
"if",
"not",
"os",
".",
"environ",
".",
"get",
"(",
"'SPY_TEST_USE_INTROSPECTION'",
")",
":",
"return",
"started",
"# Start client",
"started",
"=",
"language_client",
"[",
"'status'",
"]",
"==",
"self",
".",
"RUNNING",
"if",
"language_client",
"[",
"'status'",
"]",
"==",
"self",
".",
"STOPPED",
":",
"config",
"=",
"language_client",
"[",
"'config'",
"]",
"if",
"not",
"config",
"[",
"'external'",
"]",
":",
"port",
"=",
"select_port",
"(",
"default_port",
"=",
"config",
"[",
"'port'",
"]",
")",
"config",
"[",
"'port'",
"]",
"=",
"port",
"language_client",
"[",
"'instance'",
"]",
"=",
"LSPClient",
"(",
"parent",
"=",
"self",
",",
"server_settings",
"=",
"config",
",",
"folder",
"=",
"self",
".",
"get_root_path",
"(",
"language",
")",
",",
"language",
"=",
"language",
")",
"# Connect signals emitted by the client to the methods that",
"# can handle them",
"if",
"self",
".",
"main",
"and",
"self",
".",
"main",
".",
"editor",
":",
"language_client",
"[",
"'instance'",
"]",
".",
"sig_initialize",
".",
"connect",
"(",
"self",
".",
"main",
".",
"editor",
".",
"register_lsp_server_settings",
")",
"logger",
".",
"info",
"(",
"\"Starting LSP client for {}...\"",
".",
"format",
"(",
"language",
")",
")",
"language_client",
"[",
"'instance'",
"]",
".",
"start",
"(",
")",
"language_client",
"[",
"'status'",
"]",
"=",
"self",
".",
"RUNNING",
"for",
"entry",
"in",
"queue",
":",
"language_client",
".",
"register_file",
"(",
"*",
"entry",
")",
"self",
".",
"register_queue",
"[",
"language",
"]",
"=",
"[",
"]",
"return",
"started"
] | Start an LSP client for a given language. | [
"Start",
"an",
"LSP",
"client",
"for",
"a",
"given",
"language",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/lsp/manager.py#L131-L172 | train |
spyder-ide/spyder | spyder/plugins/editor/lsp/manager.py | LSPManager.generate_python_config | def generate_python_config(self):
"""
Update Python server configuration with the options saved in our
config system.
"""
python_config = PYTHON_CONFIG.copy()
# Server options
cmd = self.get_option('advanced/command_launch')
host = self.get_option('advanced/host')
port = self.get_option('advanced/port')
# Pycodestyle
cs_exclude = self.get_option('pycodestyle/exclude').split(',')
cs_filename = self.get_option('pycodestyle/filename').split(',')
cs_select = self.get_option('pycodestyle/select').split(',')
cs_ignore = self.get_option('pycodestyle/ignore').split(',')
cs_max_line_length = self.get_option('pycodestyle/max_line_length')
pycodestyle = {
'enabled': self.get_option('pycodestyle'),
'exclude': [exclude.strip() for exclude in cs_exclude],
'filename': [filename.strip() for filename in cs_filename],
'select': [select.strip() for select in cs_select],
'ignore': [ignore.strip() for ignore in cs_ignore],
'hangClosing': False,
'maxLineLength': cs_max_line_length
}
# Linting - Pyflakes
pyflakes = {
'enabled': self.get_option('pyflakes')
}
# Pydocstyle
convention = self.get_option('pydocstyle/convention')
if convention == 'Custom':
ds_ignore = self.get_option('pydocstyle/ignore').split(',')
ds_select = self.get_option('pydocstyle/select').split(',')
ds_add_ignore = []
ds_add_select = []
else:
ds_ignore = []
ds_select = []
ds_add_ignore = self.get_option('pydocstyle/ignore').split(',')
ds_add_select = self.get_option('pydocstyle/select').split(',')
pydocstyle = {
'enabled': self.get_option('pydocstyle'),
'convention': convention,
'addIgnore': [ignore.strip() for ignore in ds_add_ignore],
'addSelect': [select.strip() for select in ds_add_select],
'ignore': [ignore.strip() for ignore in ds_ignore],
'select': [select.strip() for select in ds_select],
'match': self.get_option('pydocstyle/match'),
'matchDir': self.get_option('pydocstyle/match_dir')
}
# Code completion
jedi_completion = {
'enabled': self.get_option('code_completion'),
'include_params': False
}
jedi_signature_help = {
'enabled': self.get_option('jedi_signature_help')
}
jedi_definition = {
'enabled': self.get_option('jedi_definition'),
'follow_imports': self.get_option('jedi_definition/follow_imports')
}
# Advanced
external_server = self.get_option('advanced/external')
# Setup options in json
python_config['cmd'] = cmd
if host in self.LOCALHOST:
python_config['args'] = '--host {host} --port {port} --tcp'
else:
python_config['args'] = ''
python_config['external'] = external_server
python_config['host'] = host
python_config['port'] = port
plugins = python_config['configurations']['pyls']['plugins']
plugins['pycodestyle'] = pycodestyle
plugins['pyflakes'] = pyflakes
plugins['pydocstyle'] = pydocstyle
plugins['jedi_completion'] = jedi_completion
plugins['jedi_signature_help'] = jedi_signature_help
plugins['preload']['modules'] = self.get_option('preload_modules')
plugins['jedi_definition'] = jedi_definition
return python_config | python | def generate_python_config(self):
"""
Update Python server configuration with the options saved in our
config system.
"""
python_config = PYTHON_CONFIG.copy()
# Server options
cmd = self.get_option('advanced/command_launch')
host = self.get_option('advanced/host')
port = self.get_option('advanced/port')
# Pycodestyle
cs_exclude = self.get_option('pycodestyle/exclude').split(',')
cs_filename = self.get_option('pycodestyle/filename').split(',')
cs_select = self.get_option('pycodestyle/select').split(',')
cs_ignore = self.get_option('pycodestyle/ignore').split(',')
cs_max_line_length = self.get_option('pycodestyle/max_line_length')
pycodestyle = {
'enabled': self.get_option('pycodestyle'),
'exclude': [exclude.strip() for exclude in cs_exclude],
'filename': [filename.strip() for filename in cs_filename],
'select': [select.strip() for select in cs_select],
'ignore': [ignore.strip() for ignore in cs_ignore],
'hangClosing': False,
'maxLineLength': cs_max_line_length
}
# Linting - Pyflakes
pyflakes = {
'enabled': self.get_option('pyflakes')
}
# Pydocstyle
convention = self.get_option('pydocstyle/convention')
if convention == 'Custom':
ds_ignore = self.get_option('pydocstyle/ignore').split(',')
ds_select = self.get_option('pydocstyle/select').split(',')
ds_add_ignore = []
ds_add_select = []
else:
ds_ignore = []
ds_select = []
ds_add_ignore = self.get_option('pydocstyle/ignore').split(',')
ds_add_select = self.get_option('pydocstyle/select').split(',')
pydocstyle = {
'enabled': self.get_option('pydocstyle'),
'convention': convention,
'addIgnore': [ignore.strip() for ignore in ds_add_ignore],
'addSelect': [select.strip() for select in ds_add_select],
'ignore': [ignore.strip() for ignore in ds_ignore],
'select': [select.strip() for select in ds_select],
'match': self.get_option('pydocstyle/match'),
'matchDir': self.get_option('pydocstyle/match_dir')
}
# Code completion
jedi_completion = {
'enabled': self.get_option('code_completion'),
'include_params': False
}
jedi_signature_help = {
'enabled': self.get_option('jedi_signature_help')
}
jedi_definition = {
'enabled': self.get_option('jedi_definition'),
'follow_imports': self.get_option('jedi_definition/follow_imports')
}
# Advanced
external_server = self.get_option('advanced/external')
# Setup options in json
python_config['cmd'] = cmd
if host in self.LOCALHOST:
python_config['args'] = '--host {host} --port {port} --tcp'
else:
python_config['args'] = ''
python_config['external'] = external_server
python_config['host'] = host
python_config['port'] = port
plugins = python_config['configurations']['pyls']['plugins']
plugins['pycodestyle'] = pycodestyle
plugins['pyflakes'] = pyflakes
plugins['pydocstyle'] = pydocstyle
plugins['jedi_completion'] = jedi_completion
plugins['jedi_signature_help'] = jedi_signature_help
plugins['preload']['modules'] = self.get_option('preload_modules')
plugins['jedi_definition'] = jedi_definition
return python_config | [
"def",
"generate_python_config",
"(",
"self",
")",
":",
"python_config",
"=",
"PYTHON_CONFIG",
".",
"copy",
"(",
")",
"# Server options",
"cmd",
"=",
"self",
".",
"get_option",
"(",
"'advanced/command_launch'",
")",
"host",
"=",
"self",
".",
"get_option",
"(",
"'advanced/host'",
")",
"port",
"=",
"self",
".",
"get_option",
"(",
"'advanced/port'",
")",
"# Pycodestyle",
"cs_exclude",
"=",
"self",
".",
"get_option",
"(",
"'pycodestyle/exclude'",
")",
".",
"split",
"(",
"','",
")",
"cs_filename",
"=",
"self",
".",
"get_option",
"(",
"'pycodestyle/filename'",
")",
".",
"split",
"(",
"','",
")",
"cs_select",
"=",
"self",
".",
"get_option",
"(",
"'pycodestyle/select'",
")",
".",
"split",
"(",
"','",
")",
"cs_ignore",
"=",
"self",
".",
"get_option",
"(",
"'pycodestyle/ignore'",
")",
".",
"split",
"(",
"','",
")",
"cs_max_line_length",
"=",
"self",
".",
"get_option",
"(",
"'pycodestyle/max_line_length'",
")",
"pycodestyle",
"=",
"{",
"'enabled'",
":",
"self",
".",
"get_option",
"(",
"'pycodestyle'",
")",
",",
"'exclude'",
":",
"[",
"exclude",
".",
"strip",
"(",
")",
"for",
"exclude",
"in",
"cs_exclude",
"]",
",",
"'filename'",
":",
"[",
"filename",
".",
"strip",
"(",
")",
"for",
"filename",
"in",
"cs_filename",
"]",
",",
"'select'",
":",
"[",
"select",
".",
"strip",
"(",
")",
"for",
"select",
"in",
"cs_select",
"]",
",",
"'ignore'",
":",
"[",
"ignore",
".",
"strip",
"(",
")",
"for",
"ignore",
"in",
"cs_ignore",
"]",
",",
"'hangClosing'",
":",
"False",
",",
"'maxLineLength'",
":",
"cs_max_line_length",
"}",
"# Linting - Pyflakes",
"pyflakes",
"=",
"{",
"'enabled'",
":",
"self",
".",
"get_option",
"(",
"'pyflakes'",
")",
"}",
"# Pydocstyle",
"convention",
"=",
"self",
".",
"get_option",
"(",
"'pydocstyle/convention'",
")",
"if",
"convention",
"==",
"'Custom'",
":",
"ds_ignore",
"=",
"self",
".",
"get_option",
"(",
"'pydocstyle/ignore'",
")",
".",
"split",
"(",
"','",
")",
"ds_select",
"=",
"self",
".",
"get_option",
"(",
"'pydocstyle/select'",
")",
".",
"split",
"(",
"','",
")",
"ds_add_ignore",
"=",
"[",
"]",
"ds_add_select",
"=",
"[",
"]",
"else",
":",
"ds_ignore",
"=",
"[",
"]",
"ds_select",
"=",
"[",
"]",
"ds_add_ignore",
"=",
"self",
".",
"get_option",
"(",
"'pydocstyle/ignore'",
")",
".",
"split",
"(",
"','",
")",
"ds_add_select",
"=",
"self",
".",
"get_option",
"(",
"'pydocstyle/select'",
")",
".",
"split",
"(",
"','",
")",
"pydocstyle",
"=",
"{",
"'enabled'",
":",
"self",
".",
"get_option",
"(",
"'pydocstyle'",
")",
",",
"'convention'",
":",
"convention",
",",
"'addIgnore'",
":",
"[",
"ignore",
".",
"strip",
"(",
")",
"for",
"ignore",
"in",
"ds_add_ignore",
"]",
",",
"'addSelect'",
":",
"[",
"select",
".",
"strip",
"(",
")",
"for",
"select",
"in",
"ds_add_select",
"]",
",",
"'ignore'",
":",
"[",
"ignore",
".",
"strip",
"(",
")",
"for",
"ignore",
"in",
"ds_ignore",
"]",
",",
"'select'",
":",
"[",
"select",
".",
"strip",
"(",
")",
"for",
"select",
"in",
"ds_select",
"]",
",",
"'match'",
":",
"self",
".",
"get_option",
"(",
"'pydocstyle/match'",
")",
",",
"'matchDir'",
":",
"self",
".",
"get_option",
"(",
"'pydocstyle/match_dir'",
")",
"}",
"# Code completion",
"jedi_completion",
"=",
"{",
"'enabled'",
":",
"self",
".",
"get_option",
"(",
"'code_completion'",
")",
",",
"'include_params'",
":",
"False",
"}",
"jedi_signature_help",
"=",
"{",
"'enabled'",
":",
"self",
".",
"get_option",
"(",
"'jedi_signature_help'",
")",
"}",
"jedi_definition",
"=",
"{",
"'enabled'",
":",
"self",
".",
"get_option",
"(",
"'jedi_definition'",
")",
",",
"'follow_imports'",
":",
"self",
".",
"get_option",
"(",
"'jedi_definition/follow_imports'",
")",
"}",
"# Advanced",
"external_server",
"=",
"self",
".",
"get_option",
"(",
"'advanced/external'",
")",
"# Setup options in json",
"python_config",
"[",
"'cmd'",
"]",
"=",
"cmd",
"if",
"host",
"in",
"self",
".",
"LOCALHOST",
":",
"python_config",
"[",
"'args'",
"]",
"=",
"'--host {host} --port {port} --tcp'",
"else",
":",
"python_config",
"[",
"'args'",
"]",
"=",
"''",
"python_config",
"[",
"'external'",
"]",
"=",
"external_server",
"python_config",
"[",
"'host'",
"]",
"=",
"host",
"python_config",
"[",
"'port'",
"]",
"=",
"port",
"plugins",
"=",
"python_config",
"[",
"'configurations'",
"]",
"[",
"'pyls'",
"]",
"[",
"'plugins'",
"]",
"plugins",
"[",
"'pycodestyle'",
"]",
"=",
"pycodestyle",
"plugins",
"[",
"'pyflakes'",
"]",
"=",
"pyflakes",
"plugins",
"[",
"'pydocstyle'",
"]",
"=",
"pydocstyle",
"plugins",
"[",
"'jedi_completion'",
"]",
"=",
"jedi_completion",
"plugins",
"[",
"'jedi_signature_help'",
"]",
"=",
"jedi_signature_help",
"plugins",
"[",
"'preload'",
"]",
"[",
"'modules'",
"]",
"=",
"self",
".",
"get_option",
"(",
"'preload_modules'",
")",
"plugins",
"[",
"'jedi_definition'",
"]",
"=",
"jedi_definition",
"return",
"python_config"
] | Update Python server configuration with the options saved in our
config system. | [
"Update",
"Python",
"server",
"configuration",
"with",
"the",
"options",
"saved",
"in",
"our",
"config",
"system",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/lsp/manager.py#L230-L326 | train |
spyder-ide/spyder | spyder/plugins/history/confpage.py | HistoryConfigPage.setup_page | def setup_page(self):
"""Setup config page widgets and options."""
settings_group = QGroupBox(_("Settings"))
hist_spin = self.create_spinbox(
_("History depth: "), _(" entries"),
'max_entries', min_=10, max_=10000, step=10,
tip=_("Set maximum line count"))
sourcecode_group = QGroupBox(_("Source code"))
wrap_mode_box = self.create_checkbox(_("Wrap lines"), 'wrap')
linenumbers_mode_box = self.create_checkbox(_("Show line numbers"),
'line_numbers')
go_to_eof_box = self.create_checkbox(
_("Scroll automatically to last entry"), 'go_to_eof')
settings_layout = QVBoxLayout()
settings_layout.addWidget(hist_spin)
settings_group.setLayout(settings_layout)
sourcecode_layout = QVBoxLayout()
sourcecode_layout.addWidget(wrap_mode_box)
sourcecode_layout.addWidget(linenumbers_mode_box)
sourcecode_layout.addWidget(go_to_eof_box)
sourcecode_group.setLayout(sourcecode_layout)
vlayout = QVBoxLayout()
vlayout.addWidget(settings_group)
vlayout.addWidget(sourcecode_group)
vlayout.addStretch(1)
self.setLayout(vlayout) | python | def setup_page(self):
"""Setup config page widgets and options."""
settings_group = QGroupBox(_("Settings"))
hist_spin = self.create_spinbox(
_("History depth: "), _(" entries"),
'max_entries', min_=10, max_=10000, step=10,
tip=_("Set maximum line count"))
sourcecode_group = QGroupBox(_("Source code"))
wrap_mode_box = self.create_checkbox(_("Wrap lines"), 'wrap')
linenumbers_mode_box = self.create_checkbox(_("Show line numbers"),
'line_numbers')
go_to_eof_box = self.create_checkbox(
_("Scroll automatically to last entry"), 'go_to_eof')
settings_layout = QVBoxLayout()
settings_layout.addWidget(hist_spin)
settings_group.setLayout(settings_layout)
sourcecode_layout = QVBoxLayout()
sourcecode_layout.addWidget(wrap_mode_box)
sourcecode_layout.addWidget(linenumbers_mode_box)
sourcecode_layout.addWidget(go_to_eof_box)
sourcecode_group.setLayout(sourcecode_layout)
vlayout = QVBoxLayout()
vlayout.addWidget(settings_group)
vlayout.addWidget(sourcecode_group)
vlayout.addStretch(1)
self.setLayout(vlayout) | [
"def",
"setup_page",
"(",
"self",
")",
":",
"settings_group",
"=",
"QGroupBox",
"(",
"_",
"(",
"\"Settings\"",
")",
")",
"hist_spin",
"=",
"self",
".",
"create_spinbox",
"(",
"_",
"(",
"\"History depth: \"",
")",
",",
"_",
"(",
"\" entries\"",
")",
",",
"'max_entries'",
",",
"min_",
"=",
"10",
",",
"max_",
"=",
"10000",
",",
"step",
"=",
"10",
",",
"tip",
"=",
"_",
"(",
"\"Set maximum line count\"",
")",
")",
"sourcecode_group",
"=",
"QGroupBox",
"(",
"_",
"(",
"\"Source code\"",
")",
")",
"wrap_mode_box",
"=",
"self",
".",
"create_checkbox",
"(",
"_",
"(",
"\"Wrap lines\"",
")",
",",
"'wrap'",
")",
"linenumbers_mode_box",
"=",
"self",
".",
"create_checkbox",
"(",
"_",
"(",
"\"Show line numbers\"",
")",
",",
"'line_numbers'",
")",
"go_to_eof_box",
"=",
"self",
".",
"create_checkbox",
"(",
"_",
"(",
"\"Scroll automatically to last entry\"",
")",
",",
"'go_to_eof'",
")",
"settings_layout",
"=",
"QVBoxLayout",
"(",
")",
"settings_layout",
".",
"addWidget",
"(",
"hist_spin",
")",
"settings_group",
".",
"setLayout",
"(",
"settings_layout",
")",
"sourcecode_layout",
"=",
"QVBoxLayout",
"(",
")",
"sourcecode_layout",
".",
"addWidget",
"(",
"wrap_mode_box",
")",
"sourcecode_layout",
".",
"addWidget",
"(",
"linenumbers_mode_box",
")",
"sourcecode_layout",
".",
"addWidget",
"(",
"go_to_eof_box",
")",
"sourcecode_group",
".",
"setLayout",
"(",
"sourcecode_layout",
")",
"vlayout",
"=",
"QVBoxLayout",
"(",
")",
"vlayout",
".",
"addWidget",
"(",
"settings_group",
")",
"vlayout",
".",
"addWidget",
"(",
"sourcecode_group",
")",
"vlayout",
".",
"addStretch",
"(",
"1",
")",
"self",
".",
"setLayout",
"(",
"vlayout",
")"
] | Setup config page widgets and options. | [
"Setup",
"config",
"page",
"widgets",
"and",
"options",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/history/confpage.py#L25-L54 | train |
spyder-ide/spyder | spyder/utils/encoding.py | transcode | def transcode(text, input=PREFERRED_ENCODING, output=PREFERRED_ENCODING):
"""Transcode a text string"""
try:
return text.decode("cp437").encode("cp1252")
except UnicodeError:
try:
return text.decode("cp437").encode(output)
except UnicodeError:
return text | python | def transcode(text, input=PREFERRED_ENCODING, output=PREFERRED_ENCODING):
"""Transcode a text string"""
try:
return text.decode("cp437").encode("cp1252")
except UnicodeError:
try:
return text.decode("cp437").encode(output)
except UnicodeError:
return text | [
"def",
"transcode",
"(",
"text",
",",
"input",
"=",
"PREFERRED_ENCODING",
",",
"output",
"=",
"PREFERRED_ENCODING",
")",
":",
"try",
":",
"return",
"text",
".",
"decode",
"(",
"\"cp437\"",
")",
".",
"encode",
"(",
"\"cp1252\"",
")",
"except",
"UnicodeError",
":",
"try",
":",
"return",
"text",
".",
"decode",
"(",
"\"cp437\"",
")",
".",
"encode",
"(",
"output",
")",
"except",
"UnicodeError",
":",
"return",
"text"
] | Transcode a text string | [
"Transcode",
"a",
"text",
"string"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/encoding.py#L33-L41 | train |
spyder-ide/spyder | spyder/utils/encoding.py | to_unicode_from_fs | def to_unicode_from_fs(string):
"""
Return a unicode version of string decoded using the file system encoding.
"""
if not is_string(string): # string is a QString
string = to_text_string(string.toUtf8(), 'utf-8')
else:
if is_binary_string(string):
try:
unic = string.decode(FS_ENCODING)
except (UnicodeError, TypeError):
pass
else:
return unic
return string | python | def to_unicode_from_fs(string):
"""
Return a unicode version of string decoded using the file system encoding.
"""
if not is_string(string): # string is a QString
string = to_text_string(string.toUtf8(), 'utf-8')
else:
if is_binary_string(string):
try:
unic = string.decode(FS_ENCODING)
except (UnicodeError, TypeError):
pass
else:
return unic
return string | [
"def",
"to_unicode_from_fs",
"(",
"string",
")",
":",
"if",
"not",
"is_string",
"(",
"string",
")",
":",
"# string is a QString\r",
"string",
"=",
"to_text_string",
"(",
"string",
".",
"toUtf8",
"(",
")",
",",
"'utf-8'",
")",
"else",
":",
"if",
"is_binary_string",
"(",
"string",
")",
":",
"try",
":",
"unic",
"=",
"string",
".",
"decode",
"(",
"FS_ENCODING",
")",
"except",
"(",
"UnicodeError",
",",
"TypeError",
")",
":",
"pass",
"else",
":",
"return",
"unic",
"return",
"string"
] | Return a unicode version of string decoded using the file system encoding. | [
"Return",
"a",
"unicode",
"version",
"of",
"string",
"decoded",
"using",
"the",
"file",
"system",
"encoding",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/encoding.py#L63-L77 | train |
spyder-ide/spyder | spyder/utils/encoding.py | to_fs_from_unicode | def to_fs_from_unicode(unic):
"""
Return a byte string version of unic encoded using the file
system encoding.
"""
if is_unicode(unic):
try:
string = unic.encode(FS_ENCODING)
except (UnicodeError, TypeError):
pass
else:
return string
return unic | python | def to_fs_from_unicode(unic):
"""
Return a byte string version of unic encoded using the file
system encoding.
"""
if is_unicode(unic):
try:
string = unic.encode(FS_ENCODING)
except (UnicodeError, TypeError):
pass
else:
return string
return unic | [
"def",
"to_fs_from_unicode",
"(",
"unic",
")",
":",
"if",
"is_unicode",
"(",
"unic",
")",
":",
"try",
":",
"string",
"=",
"unic",
".",
"encode",
"(",
"FS_ENCODING",
")",
"except",
"(",
"UnicodeError",
",",
"TypeError",
")",
":",
"pass",
"else",
":",
"return",
"string",
"return",
"unic"
] | Return a byte string version of unic encoded using the file
system encoding. | [
"Return",
"a",
"byte",
"string",
"version",
"of",
"unic",
"encoded",
"using",
"the",
"file",
"system",
"encoding",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/encoding.py#L79-L91 | train |
spyder-ide/spyder | spyder/utils/encoding.py | get_coding | def get_coding(text, force_chardet=False):
"""
Function to get the coding of a text.
@param text text to inspect (string)
@return coding string
"""
if not force_chardet:
for line in text.splitlines()[:2]:
try:
result = CODING_RE.search(to_text_string(line))
except UnicodeDecodeError:
# This could fail because to_text_string assume the text
# is utf8-like and we don't know the encoding to give
# it to to_text_string
pass
else:
if result:
codec = result.group(1)
# sometimes we find a false encoding that can
# result in errors
if codec in CODECS:
return codec
# Fallback using chardet
if is_binary_string(text):
detector = UniversalDetector()
for line in text.splitlines()[:2]:
detector.feed(line)
if detector.done: break
detector.close()
return detector.result['encoding']
return None | python | def get_coding(text, force_chardet=False):
"""
Function to get the coding of a text.
@param text text to inspect (string)
@return coding string
"""
if not force_chardet:
for line in text.splitlines()[:2]:
try:
result = CODING_RE.search(to_text_string(line))
except UnicodeDecodeError:
# This could fail because to_text_string assume the text
# is utf8-like and we don't know the encoding to give
# it to to_text_string
pass
else:
if result:
codec = result.group(1)
# sometimes we find a false encoding that can
# result in errors
if codec in CODECS:
return codec
# Fallback using chardet
if is_binary_string(text):
detector = UniversalDetector()
for line in text.splitlines()[:2]:
detector.feed(line)
if detector.done: break
detector.close()
return detector.result['encoding']
return None | [
"def",
"get_coding",
"(",
"text",
",",
"force_chardet",
"=",
"False",
")",
":",
"if",
"not",
"force_chardet",
":",
"for",
"line",
"in",
"text",
".",
"splitlines",
"(",
")",
"[",
":",
"2",
"]",
":",
"try",
":",
"result",
"=",
"CODING_RE",
".",
"search",
"(",
"to_text_string",
"(",
"line",
")",
")",
"except",
"UnicodeDecodeError",
":",
"# This could fail because to_text_string assume the text\r",
"# is utf8-like and we don't know the encoding to give\r",
"# it to to_text_string\r",
"pass",
"else",
":",
"if",
"result",
":",
"codec",
"=",
"result",
".",
"group",
"(",
"1",
")",
"# sometimes we find a false encoding that can\r",
"# result in errors\r",
"if",
"codec",
"in",
"CODECS",
":",
"return",
"codec",
"# Fallback using chardet\r",
"if",
"is_binary_string",
"(",
"text",
")",
":",
"detector",
"=",
"UniversalDetector",
"(",
")",
"for",
"line",
"in",
"text",
".",
"splitlines",
"(",
")",
"[",
":",
"2",
"]",
":",
"detector",
".",
"feed",
"(",
"line",
")",
"if",
"detector",
".",
"done",
":",
"break",
"detector",
".",
"close",
"(",
")",
"return",
"detector",
".",
"result",
"[",
"'encoding'",
"]",
"return",
"None"
] | Function to get the coding of a text.
@param text text to inspect (string)
@return coding string | [
"Function",
"to",
"get",
"the",
"coding",
"of",
"a",
"text",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/encoding.py#L107-L140 | train |
spyder-ide/spyder | spyder/utils/encoding.py | decode | def decode(text):
"""
Function to decode a text.
@param text text to decode (string)
@return decoded text and encoding
"""
try:
if text.startswith(BOM_UTF8):
# UTF-8 with BOM
return to_text_string(text[len(BOM_UTF8):], 'utf-8'), 'utf-8-bom'
elif text.startswith(BOM_UTF16):
# UTF-16 with BOM
return to_text_string(text[len(BOM_UTF16):], 'utf-16'), 'utf-16'
elif text.startswith(BOM_UTF32):
# UTF-32 with BOM
return to_text_string(text[len(BOM_UTF32):], 'utf-32'), 'utf-32'
coding = get_coding(text)
if coding:
return to_text_string(text, coding), coding
except (UnicodeError, LookupError):
pass
# Assume UTF-8
try:
return to_text_string(text, 'utf-8'), 'utf-8-guessed'
except (UnicodeError, LookupError):
pass
# Assume Latin-1 (behaviour before 3.7.1)
return to_text_string(text, "latin-1"), 'latin-1-guessed' | python | def decode(text):
"""
Function to decode a text.
@param text text to decode (string)
@return decoded text and encoding
"""
try:
if text.startswith(BOM_UTF8):
# UTF-8 with BOM
return to_text_string(text[len(BOM_UTF8):], 'utf-8'), 'utf-8-bom'
elif text.startswith(BOM_UTF16):
# UTF-16 with BOM
return to_text_string(text[len(BOM_UTF16):], 'utf-16'), 'utf-16'
elif text.startswith(BOM_UTF32):
# UTF-32 with BOM
return to_text_string(text[len(BOM_UTF32):], 'utf-32'), 'utf-32'
coding = get_coding(text)
if coding:
return to_text_string(text, coding), coding
except (UnicodeError, LookupError):
pass
# Assume UTF-8
try:
return to_text_string(text, 'utf-8'), 'utf-8-guessed'
except (UnicodeError, LookupError):
pass
# Assume Latin-1 (behaviour before 3.7.1)
return to_text_string(text, "latin-1"), 'latin-1-guessed' | [
"def",
"decode",
"(",
"text",
")",
":",
"try",
":",
"if",
"text",
".",
"startswith",
"(",
"BOM_UTF8",
")",
":",
"# UTF-8 with BOM\r",
"return",
"to_text_string",
"(",
"text",
"[",
"len",
"(",
"BOM_UTF8",
")",
":",
"]",
",",
"'utf-8'",
")",
",",
"'utf-8-bom'",
"elif",
"text",
".",
"startswith",
"(",
"BOM_UTF16",
")",
":",
"# UTF-16 with BOM\r",
"return",
"to_text_string",
"(",
"text",
"[",
"len",
"(",
"BOM_UTF16",
")",
":",
"]",
",",
"'utf-16'",
")",
",",
"'utf-16'",
"elif",
"text",
".",
"startswith",
"(",
"BOM_UTF32",
")",
":",
"# UTF-32 with BOM\r",
"return",
"to_text_string",
"(",
"text",
"[",
"len",
"(",
"BOM_UTF32",
")",
":",
"]",
",",
"'utf-32'",
")",
",",
"'utf-32'",
"coding",
"=",
"get_coding",
"(",
"text",
")",
"if",
"coding",
":",
"return",
"to_text_string",
"(",
"text",
",",
"coding",
")",
",",
"coding",
"except",
"(",
"UnicodeError",
",",
"LookupError",
")",
":",
"pass",
"# Assume UTF-8\r",
"try",
":",
"return",
"to_text_string",
"(",
"text",
",",
"'utf-8'",
")",
",",
"'utf-8-guessed'",
"except",
"(",
"UnicodeError",
",",
"LookupError",
")",
":",
"pass",
"# Assume Latin-1 (behaviour before 3.7.1)\r",
"return",
"to_text_string",
"(",
"text",
",",
"\"latin-1\"",
")",
",",
"'latin-1-guessed'"
] | Function to decode a text.
@param text text to decode (string)
@return decoded text and encoding | [
"Function",
"to",
"decode",
"a",
"text",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/encoding.py#L142-L169 | train |
spyder-ide/spyder | spyder/utils/encoding.py | to_unicode | def to_unicode(string):
"""Convert a string to unicode"""
if not is_unicode(string):
for codec in CODECS:
try:
unic = to_text_string(string, codec)
except UnicodeError:
pass
except TypeError:
break
else:
return unic
return string | python | def to_unicode(string):
"""Convert a string to unicode"""
if not is_unicode(string):
for codec in CODECS:
try:
unic = to_text_string(string, codec)
except UnicodeError:
pass
except TypeError:
break
else:
return unic
return string | [
"def",
"to_unicode",
"(",
"string",
")",
":",
"if",
"not",
"is_unicode",
"(",
"string",
")",
":",
"for",
"codec",
"in",
"CODECS",
":",
"try",
":",
"unic",
"=",
"to_text_string",
"(",
"string",
",",
"codec",
")",
"except",
"UnicodeError",
":",
"pass",
"except",
"TypeError",
":",
"break",
"else",
":",
"return",
"unic",
"return",
"string"
] | Convert a string to unicode | [
"Convert",
"a",
"string",
"to",
"unicode"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/encoding.py#L213-L225 | train |
spyder-ide/spyder | spyder/utils/encoding.py | write | def write(text, filename, encoding='utf-8', mode='wb'):
"""
Write 'text' to file ('filename') assuming 'encoding' in an atomic way
Return (eventually new) encoding
"""
text, encoding = encode(text, encoding)
if 'a' in mode:
with open(filename, mode) as textfile:
textfile.write(text)
else:
with atomic_write(filename,
overwrite=True,
mode=mode) as textfile:
textfile.write(text)
return encoding | python | def write(text, filename, encoding='utf-8', mode='wb'):
"""
Write 'text' to file ('filename') assuming 'encoding' in an atomic way
Return (eventually new) encoding
"""
text, encoding = encode(text, encoding)
if 'a' in mode:
with open(filename, mode) as textfile:
textfile.write(text)
else:
with atomic_write(filename,
overwrite=True,
mode=mode) as textfile:
textfile.write(text)
return encoding | [
"def",
"write",
"(",
"text",
",",
"filename",
",",
"encoding",
"=",
"'utf-8'",
",",
"mode",
"=",
"'wb'",
")",
":",
"text",
",",
"encoding",
"=",
"encode",
"(",
"text",
",",
"encoding",
")",
"if",
"'a'",
"in",
"mode",
":",
"with",
"open",
"(",
"filename",
",",
"mode",
")",
"as",
"textfile",
":",
"textfile",
".",
"write",
"(",
"text",
")",
"else",
":",
"with",
"atomic_write",
"(",
"filename",
",",
"overwrite",
"=",
"True",
",",
"mode",
"=",
"mode",
")",
"as",
"textfile",
":",
"textfile",
".",
"write",
"(",
"text",
")",
"return",
"encoding"
] | Write 'text' to file ('filename') assuming 'encoding' in an atomic way
Return (eventually new) encoding | [
"Write",
"text",
"to",
"file",
"(",
"filename",
")",
"assuming",
"encoding",
"in",
"an",
"atomic",
"way",
"Return",
"(",
"eventually",
"new",
")",
"encoding"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/encoding.py#L228-L242 | train |
spyder-ide/spyder | spyder/utils/encoding.py | writelines | def writelines(lines, filename, encoding='utf-8', mode='wb'):
"""
Write 'lines' to file ('filename') assuming 'encoding'
Return (eventually new) encoding
"""
return write(os.linesep.join(lines), filename, encoding, mode) | python | def writelines(lines, filename, encoding='utf-8', mode='wb'):
"""
Write 'lines' to file ('filename') assuming 'encoding'
Return (eventually new) encoding
"""
return write(os.linesep.join(lines), filename, encoding, mode) | [
"def",
"writelines",
"(",
"lines",
",",
"filename",
",",
"encoding",
"=",
"'utf-8'",
",",
"mode",
"=",
"'wb'",
")",
":",
"return",
"write",
"(",
"os",
".",
"linesep",
".",
"join",
"(",
"lines",
")",
",",
"filename",
",",
"encoding",
",",
"mode",
")"
] | Write 'lines' to file ('filename') assuming 'encoding'
Return (eventually new) encoding | [
"Write",
"lines",
"to",
"file",
"(",
"filename",
")",
"assuming",
"encoding",
"Return",
"(",
"eventually",
"new",
")",
"encoding"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/encoding.py#L245-L250 | train |
spyder-ide/spyder | spyder/utils/encoding.py | read | def read(filename, encoding='utf-8'):
"""
Read text from file ('filename')
Return text and encoding
"""
text, encoding = decode( open(filename, 'rb').read() )
return text, encoding | python | def read(filename, encoding='utf-8'):
"""
Read text from file ('filename')
Return text and encoding
"""
text, encoding = decode( open(filename, 'rb').read() )
return text, encoding | [
"def",
"read",
"(",
"filename",
",",
"encoding",
"=",
"'utf-8'",
")",
":",
"text",
",",
"encoding",
"=",
"decode",
"(",
"open",
"(",
"filename",
",",
"'rb'",
")",
".",
"read",
"(",
")",
")",
"return",
"text",
",",
"encoding"
] | Read text from file ('filename')
Return text and encoding | [
"Read",
"text",
"from",
"file",
"(",
"filename",
")",
"Return",
"text",
"and",
"encoding"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/encoding.py#L252-L258 | train |
spyder-ide/spyder | spyder/utils/encoding.py | readlines | def readlines(filename, encoding='utf-8'):
"""
Read lines from file ('filename')
Return lines and encoding
"""
text, encoding = read(filename, encoding)
return text.split(os.linesep), encoding | python | def readlines(filename, encoding='utf-8'):
"""
Read lines from file ('filename')
Return lines and encoding
"""
text, encoding = read(filename, encoding)
return text.split(os.linesep), encoding | [
"def",
"readlines",
"(",
"filename",
",",
"encoding",
"=",
"'utf-8'",
")",
":",
"text",
",",
"encoding",
"=",
"read",
"(",
"filename",
",",
"encoding",
")",
"return",
"text",
".",
"split",
"(",
"os",
".",
"linesep",
")",
",",
"encoding"
] | Read lines from file ('filename')
Return lines and encoding | [
"Read",
"lines",
"from",
"file",
"(",
"filename",
")",
"Return",
"lines",
"and",
"encoding"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/encoding.py#L260-L266 | train |
spyder-ide/spyder | spyder/config/utils.py | _get_pygments_extensions | def _get_pygments_extensions():
"""Return all file type extensions supported by Pygments"""
# NOTE: Leave this import here to keep startup process fast!
import pygments.lexers as lexers
extensions = []
for lx in lexers.get_all_lexers():
lexer_exts = lx[2]
if lexer_exts:
# Reference: This line was included for leaving untrimmed the
# extensions not starting with `*`
other_exts = [le for le in lexer_exts if not le.startswith('*')]
# Reference: This commented line was replaced by the following one
# to trim only extensions that start with '*'
# lexer_exts = [le[1:] for le in lexer_exts]
lexer_exts = [le[1:] for le in lexer_exts if le.startswith('*')]
lexer_exts = [le for le in lexer_exts if not le.endswith('_*')]
extensions = extensions + list(lexer_exts) + list(other_exts)
return sorted(list(set(extensions))) | python | def _get_pygments_extensions():
"""Return all file type extensions supported by Pygments"""
# NOTE: Leave this import here to keep startup process fast!
import pygments.lexers as lexers
extensions = []
for lx in lexers.get_all_lexers():
lexer_exts = lx[2]
if lexer_exts:
# Reference: This line was included for leaving untrimmed the
# extensions not starting with `*`
other_exts = [le for le in lexer_exts if not le.startswith('*')]
# Reference: This commented line was replaced by the following one
# to trim only extensions that start with '*'
# lexer_exts = [le[1:] for le in lexer_exts]
lexer_exts = [le[1:] for le in lexer_exts if le.startswith('*')]
lexer_exts = [le for le in lexer_exts if not le.endswith('_*')]
extensions = extensions + list(lexer_exts) + list(other_exts)
return sorted(list(set(extensions))) | [
"def",
"_get_pygments_extensions",
"(",
")",
":",
"# NOTE: Leave this import here to keep startup process fast!",
"import",
"pygments",
".",
"lexers",
"as",
"lexers",
"extensions",
"=",
"[",
"]",
"for",
"lx",
"in",
"lexers",
".",
"get_all_lexers",
"(",
")",
":",
"lexer_exts",
"=",
"lx",
"[",
"2",
"]",
"if",
"lexer_exts",
":",
"# Reference: This line was included for leaving untrimmed the",
"# extensions not starting with `*`",
"other_exts",
"=",
"[",
"le",
"for",
"le",
"in",
"lexer_exts",
"if",
"not",
"le",
".",
"startswith",
"(",
"'*'",
")",
"]",
"# Reference: This commented line was replaced by the following one",
"# to trim only extensions that start with '*'",
"# lexer_exts = [le[1:] for le in lexer_exts]",
"lexer_exts",
"=",
"[",
"le",
"[",
"1",
":",
"]",
"for",
"le",
"in",
"lexer_exts",
"if",
"le",
".",
"startswith",
"(",
"'*'",
")",
"]",
"lexer_exts",
"=",
"[",
"le",
"for",
"le",
"in",
"lexer_exts",
"if",
"not",
"le",
".",
"endswith",
"(",
"'_*'",
")",
"]",
"extensions",
"=",
"extensions",
"+",
"list",
"(",
"lexer_exts",
")",
"+",
"list",
"(",
"other_exts",
")",
"return",
"sorted",
"(",
"list",
"(",
"set",
"(",
"extensions",
")",
")",
")"
] | Return all file type extensions supported by Pygments | [
"Return",
"all",
"file",
"type",
"extensions",
"supported",
"by",
"Pygments"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/utils.py#L82-L102 | train |
spyder-ide/spyder | spyder/config/utils.py | get_filter | def get_filter(filetypes, ext):
"""Return filter associated to file extension"""
if not ext:
return ALL_FILTER
for title, ftypes in filetypes:
if ext in ftypes:
return _create_filter(title, ftypes)
else:
return '' | python | def get_filter(filetypes, ext):
"""Return filter associated to file extension"""
if not ext:
return ALL_FILTER
for title, ftypes in filetypes:
if ext in ftypes:
return _create_filter(title, ftypes)
else:
return '' | [
"def",
"get_filter",
"(",
"filetypes",
",",
"ext",
")",
":",
"if",
"not",
"ext",
":",
"return",
"ALL_FILTER",
"for",
"title",
",",
"ftypes",
"in",
"filetypes",
":",
"if",
"ext",
"in",
"ftypes",
":",
"return",
"_create_filter",
"(",
"title",
",",
"ftypes",
")",
"else",
":",
"return",
"''"
] | Return filter associated to file extension | [
"Return",
"filter",
"associated",
"to",
"file",
"extension"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/utils.py#L108-L116 | train |
spyder-ide/spyder | spyder/config/utils.py | get_edit_filetypes | def get_edit_filetypes():
"""Get all file types supported by the Editor"""
# The filter details are not hidden on Windows, so we can't use
# all Pygments extensions on that platform
if os.name == 'nt':
supported_exts = []
else:
try:
supported_exts = _get_pygments_extensions()
except Exception:
supported_exts = []
# NOTE: Try to not add too much extensions to this list to not
# make the filter look too big on Windows
favorite_exts = ['.py', '.R', '.jl', '.ipynb', '.md', '.pyw', '.pyx',
'.c', '.cpp', '.json', '.dat', '.csv', '.tsv', '.txt',
'.ini', '.html', '.js', '.h', '.bat']
other_exts = [ext for ext in supported_exts if ext not in favorite_exts]
all_exts = tuple(favorite_exts + other_exts)
text_filetypes = (_("Supported text files"), all_exts)
return [text_filetypes] + EDIT_FILETYPES | python | def get_edit_filetypes():
"""Get all file types supported by the Editor"""
# The filter details are not hidden on Windows, so we can't use
# all Pygments extensions on that platform
if os.name == 'nt':
supported_exts = []
else:
try:
supported_exts = _get_pygments_extensions()
except Exception:
supported_exts = []
# NOTE: Try to not add too much extensions to this list to not
# make the filter look too big on Windows
favorite_exts = ['.py', '.R', '.jl', '.ipynb', '.md', '.pyw', '.pyx',
'.c', '.cpp', '.json', '.dat', '.csv', '.tsv', '.txt',
'.ini', '.html', '.js', '.h', '.bat']
other_exts = [ext for ext in supported_exts if ext not in favorite_exts]
all_exts = tuple(favorite_exts + other_exts)
text_filetypes = (_("Supported text files"), all_exts)
return [text_filetypes] + EDIT_FILETYPES | [
"def",
"get_edit_filetypes",
"(",
")",
":",
"# The filter details are not hidden on Windows, so we can't use",
"# all Pygments extensions on that platform",
"if",
"os",
".",
"name",
"==",
"'nt'",
":",
"supported_exts",
"=",
"[",
"]",
"else",
":",
"try",
":",
"supported_exts",
"=",
"_get_pygments_extensions",
"(",
")",
"except",
"Exception",
":",
"supported_exts",
"=",
"[",
"]",
"# NOTE: Try to not add too much extensions to this list to not",
"# make the filter look too big on Windows",
"favorite_exts",
"=",
"[",
"'.py'",
",",
"'.R'",
",",
"'.jl'",
",",
"'.ipynb'",
",",
"'.md'",
",",
"'.pyw'",
",",
"'.pyx'",
",",
"'.c'",
",",
"'.cpp'",
",",
"'.json'",
",",
"'.dat'",
",",
"'.csv'",
",",
"'.tsv'",
",",
"'.txt'",
",",
"'.ini'",
",",
"'.html'",
",",
"'.js'",
",",
"'.h'",
",",
"'.bat'",
"]",
"other_exts",
"=",
"[",
"ext",
"for",
"ext",
"in",
"supported_exts",
"if",
"ext",
"not",
"in",
"favorite_exts",
"]",
"all_exts",
"=",
"tuple",
"(",
"favorite_exts",
"+",
"other_exts",
")",
"text_filetypes",
"=",
"(",
"_",
"(",
"\"Supported text files\"",
")",
",",
"all_exts",
")",
"return",
"[",
"text_filetypes",
"]",
"+",
"EDIT_FILETYPES"
] | Get all file types supported by the Editor | [
"Get",
"all",
"file",
"types",
"supported",
"by",
"the",
"Editor"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/utils.py#L119-L140 | train |
spyder-ide/spyder | spyder/config/utils.py | is_ubuntu | def is_ubuntu():
"""Detect if we are running in an Ubuntu-based distribution"""
if sys.platform.startswith('linux') and osp.isfile('/etc/lsb-release'):
release_info = open('/etc/lsb-release').read()
if 'Ubuntu' in release_info:
return True
else:
return False
else:
return False | python | def is_ubuntu():
"""Detect if we are running in an Ubuntu-based distribution"""
if sys.platform.startswith('linux') and osp.isfile('/etc/lsb-release'):
release_info = open('/etc/lsb-release').read()
if 'Ubuntu' in release_info:
return True
else:
return False
else:
return False | [
"def",
"is_ubuntu",
"(",
")",
":",
"if",
"sys",
".",
"platform",
".",
"startswith",
"(",
"'linux'",
")",
"and",
"osp",
".",
"isfile",
"(",
"'/etc/lsb-release'",
")",
":",
"release_info",
"=",
"open",
"(",
"'/etc/lsb-release'",
")",
".",
"read",
"(",
")",
"if",
"'Ubuntu'",
"in",
"release_info",
":",
"return",
"True",
"else",
":",
"return",
"False",
"else",
":",
"return",
"False"
] | Detect if we are running in an Ubuntu-based distribution | [
"Detect",
"if",
"we",
"are",
"running",
"in",
"an",
"Ubuntu",
"-",
"based",
"distribution"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/utils.py#L164-L173 | train |
spyder-ide/spyder | spyder/config/utils.py | is_gtk_desktop | def is_gtk_desktop():
"""Detect if we are running in a Gtk-based desktop"""
if sys.platform.startswith('linux'):
xdg_desktop = os.environ.get('XDG_CURRENT_DESKTOP', '')
if xdg_desktop:
gtk_desktops = ['Unity', 'GNOME', 'XFCE']
if any([xdg_desktop.startswith(d) for d in gtk_desktops]):
return True
else:
return False
else:
return False
else:
return False | python | def is_gtk_desktop():
"""Detect if we are running in a Gtk-based desktop"""
if sys.platform.startswith('linux'):
xdg_desktop = os.environ.get('XDG_CURRENT_DESKTOP', '')
if xdg_desktop:
gtk_desktops = ['Unity', 'GNOME', 'XFCE']
if any([xdg_desktop.startswith(d) for d in gtk_desktops]):
return True
else:
return False
else:
return False
else:
return False | [
"def",
"is_gtk_desktop",
"(",
")",
":",
"if",
"sys",
".",
"platform",
".",
"startswith",
"(",
"'linux'",
")",
":",
"xdg_desktop",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'XDG_CURRENT_DESKTOP'",
",",
"''",
")",
"if",
"xdg_desktop",
":",
"gtk_desktops",
"=",
"[",
"'Unity'",
",",
"'GNOME'",
",",
"'XFCE'",
"]",
"if",
"any",
"(",
"[",
"xdg_desktop",
".",
"startswith",
"(",
"d",
")",
"for",
"d",
"in",
"gtk_desktops",
"]",
")",
":",
"return",
"True",
"else",
":",
"return",
"False",
"else",
":",
"return",
"False",
"else",
":",
"return",
"False"
] | Detect if we are running in a Gtk-based desktop | [
"Detect",
"if",
"we",
"are",
"running",
"in",
"a",
"Gtk",
"-",
"based",
"desktop"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/utils.py#L176-L189 | train |
spyder-ide/spyder | spyder/config/utils.py | is_kde_desktop | def is_kde_desktop():
"""Detect if we are running in a KDE desktop"""
if sys.platform.startswith('linux'):
xdg_desktop = os.environ.get('XDG_CURRENT_DESKTOP', '')
if xdg_desktop:
if 'KDE' in xdg_desktop:
return True
else:
return False
else:
return False
else:
return False | python | def is_kde_desktop():
"""Detect if we are running in a KDE desktop"""
if sys.platform.startswith('linux'):
xdg_desktop = os.environ.get('XDG_CURRENT_DESKTOP', '')
if xdg_desktop:
if 'KDE' in xdg_desktop:
return True
else:
return False
else:
return False
else:
return False | [
"def",
"is_kde_desktop",
"(",
")",
":",
"if",
"sys",
".",
"platform",
".",
"startswith",
"(",
"'linux'",
")",
":",
"xdg_desktop",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'XDG_CURRENT_DESKTOP'",
",",
"''",
")",
"if",
"xdg_desktop",
":",
"if",
"'KDE'",
"in",
"xdg_desktop",
":",
"return",
"True",
"else",
":",
"return",
"False",
"else",
":",
"return",
"False",
"else",
":",
"return",
"False"
] | Detect if we are running in a KDE desktop | [
"Detect",
"if",
"we",
"are",
"running",
"in",
"a",
"KDE",
"desktop"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/utils.py#L192-L204 | train |
spyder-ide/spyder | spyder/plugins/projects/projecttypes/python.py | PythonProject._get_relative_pythonpath | def _get_relative_pythonpath(self):
"""Return PYTHONPATH list as relative paths"""
# Workaround to replace os.path.relpath (new in Python v2.6):
offset = len(self.root_path)+len(os.pathsep)
return [path[offset:] for path in self.pythonpath] | python | def _get_relative_pythonpath(self):
"""Return PYTHONPATH list as relative paths"""
# Workaround to replace os.path.relpath (new in Python v2.6):
offset = len(self.root_path)+len(os.pathsep)
return [path[offset:] for path in self.pythonpath] | [
"def",
"_get_relative_pythonpath",
"(",
"self",
")",
":",
"# Workaround to replace os.path.relpath (new in Python v2.6):\r",
"offset",
"=",
"len",
"(",
"self",
".",
"root_path",
")",
"+",
"len",
"(",
"os",
".",
"pathsep",
")",
"return",
"[",
"path",
"[",
"offset",
":",
"]",
"for",
"path",
"in",
"self",
".",
"pythonpath",
"]"
] | Return PYTHONPATH list as relative paths | [
"Return",
"PYTHONPATH",
"list",
"as",
"relative",
"paths"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/projecttypes/python.py#L23-L27 | train |
spyder-ide/spyder | spyder/plugins/projects/projecttypes/python.py | PythonProject._set_relative_pythonpath | def _set_relative_pythonpath(self, value):
"""Set PYTHONPATH list relative paths"""
self.pythonpath = [osp.abspath(osp.join(self.root_path, path))
for path in value] | python | def _set_relative_pythonpath(self, value):
"""Set PYTHONPATH list relative paths"""
self.pythonpath = [osp.abspath(osp.join(self.root_path, path))
for path in value] | [
"def",
"_set_relative_pythonpath",
"(",
"self",
",",
"value",
")",
":",
"self",
".",
"pythonpath",
"=",
"[",
"osp",
".",
"abspath",
"(",
"osp",
".",
"join",
"(",
"self",
".",
"root_path",
",",
"path",
")",
")",
"for",
"path",
"in",
"value",
"]"
] | Set PYTHONPATH list relative paths | [
"Set",
"PYTHONPATH",
"list",
"relative",
"paths"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/projecttypes/python.py#L29-L32 | train |
spyder-ide/spyder | spyder/plugins/projects/projecttypes/python.py | PythonProject.is_in_pythonpath | def is_in_pythonpath(self, dirname):
"""Return True if dirname is in project's PYTHONPATH"""
return fixpath(dirname) in [fixpath(_p) for _p in self.pythonpath] | python | def is_in_pythonpath(self, dirname):
"""Return True if dirname is in project's PYTHONPATH"""
return fixpath(dirname) in [fixpath(_p) for _p in self.pythonpath] | [
"def",
"is_in_pythonpath",
"(",
"self",
",",
"dirname",
")",
":",
"return",
"fixpath",
"(",
"dirname",
")",
"in",
"[",
"fixpath",
"(",
"_p",
")",
"for",
"_p",
"in",
"self",
".",
"pythonpath",
"]"
] | Return True if dirname is in project's PYTHONPATH | [
"Return",
"True",
"if",
"dirname",
"is",
"in",
"project",
"s",
"PYTHONPATH"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/projecttypes/python.py#L38-L40 | train |
spyder-ide/spyder | spyder/plugins/projects/projecttypes/python.py | PythonProject.remove_from_pythonpath | def remove_from_pythonpath(self, path):
"""Remove path from project's PYTHONPATH
Return True if path was removed, False if it was not found"""
pathlist = self.get_pythonpath()
if path in pathlist:
pathlist.pop(pathlist.index(path))
self.set_pythonpath(pathlist)
return True
else:
return False | python | def remove_from_pythonpath(self, path):
"""Remove path from project's PYTHONPATH
Return True if path was removed, False if it was not found"""
pathlist = self.get_pythonpath()
if path in pathlist:
pathlist.pop(pathlist.index(path))
self.set_pythonpath(pathlist)
return True
else:
return False | [
"def",
"remove_from_pythonpath",
"(",
"self",
",",
"path",
")",
":",
"pathlist",
"=",
"self",
".",
"get_pythonpath",
"(",
")",
"if",
"path",
"in",
"pathlist",
":",
"pathlist",
".",
"pop",
"(",
"pathlist",
".",
"index",
"(",
"path",
")",
")",
"self",
".",
"set_pythonpath",
"(",
"pathlist",
")",
"return",
"True",
"else",
":",
"return",
"False"
] | Remove path from project's PYTHONPATH
Return True if path was removed, False if it was not found | [
"Remove",
"path",
"from",
"project",
"s",
"PYTHONPATH",
"Return",
"True",
"if",
"path",
"was",
"removed",
"False",
"if",
"it",
"was",
"not",
"found"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/projecttypes/python.py#L51-L60 | train |
spyder-ide/spyder | spyder/plugins/projects/projecttypes/python.py | PythonProject.add_to_pythonpath | def add_to_pythonpath(self, path):
"""Add path to project's PYTHONPATH
Return True if path was added, False if it was already there"""
pathlist = self.get_pythonpath()
if path in pathlist:
return False
else:
pathlist.insert(0, path)
self.set_pythonpath(pathlist)
return True | python | def add_to_pythonpath(self, path):
"""Add path to project's PYTHONPATH
Return True if path was added, False if it was already there"""
pathlist = self.get_pythonpath()
if path in pathlist:
return False
else:
pathlist.insert(0, path)
self.set_pythonpath(pathlist)
return True | [
"def",
"add_to_pythonpath",
"(",
"self",
",",
"path",
")",
":",
"pathlist",
"=",
"self",
".",
"get_pythonpath",
"(",
")",
"if",
"path",
"in",
"pathlist",
":",
"return",
"False",
"else",
":",
"pathlist",
".",
"insert",
"(",
"0",
",",
"path",
")",
"self",
".",
"set_pythonpath",
"(",
"pathlist",
")",
"return",
"True"
] | Add path to project's PYTHONPATH
Return True if path was added, False if it was already there | [
"Add",
"path",
"to",
"project",
"s",
"PYTHONPATH",
"Return",
"True",
"if",
"path",
"was",
"added",
"False",
"if",
"it",
"was",
"already",
"there"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/projecttypes/python.py#L62-L71 | train |
spyder-ide/spyder | setup.py | get_package_data | def get_package_data(name, extlist):
"""Return data files for package *name* with extensions in *extlist*"""
flist = []
# Workaround to replace os.path.relpath (not available until Python 2.6):
offset = len(name)+len(os.pathsep)
for dirpath, _dirnames, filenames in os.walk(name):
for fname in filenames:
if not fname.startswith('.') and osp.splitext(fname)[1] in extlist:
flist.append(osp.join(dirpath, fname)[offset:])
return flist | python | def get_package_data(name, extlist):
"""Return data files for package *name* with extensions in *extlist*"""
flist = []
# Workaround to replace os.path.relpath (not available until Python 2.6):
offset = len(name)+len(os.pathsep)
for dirpath, _dirnames, filenames in os.walk(name):
for fname in filenames:
if not fname.startswith('.') and osp.splitext(fname)[1] in extlist:
flist.append(osp.join(dirpath, fname)[offset:])
return flist | [
"def",
"get_package_data",
"(",
"name",
",",
"extlist",
")",
":",
"flist",
"=",
"[",
"]",
"# Workaround to replace os.path.relpath (not available until Python 2.6):",
"offset",
"=",
"len",
"(",
"name",
")",
"+",
"len",
"(",
"os",
".",
"pathsep",
")",
"for",
"dirpath",
",",
"_dirnames",
",",
"filenames",
"in",
"os",
".",
"walk",
"(",
"name",
")",
":",
"for",
"fname",
"in",
"filenames",
":",
"if",
"not",
"fname",
".",
"startswith",
"(",
"'.'",
")",
"and",
"osp",
".",
"splitext",
"(",
"fname",
")",
"[",
"1",
"]",
"in",
"extlist",
":",
"flist",
".",
"append",
"(",
"osp",
".",
"join",
"(",
"dirpath",
",",
"fname",
")",
"[",
"offset",
":",
"]",
")",
"return",
"flist"
] | Return data files for package *name* with extensions in *extlist* | [
"Return",
"data",
"files",
"for",
"package",
"*",
"name",
"*",
"with",
"extensions",
"in",
"*",
"extlist",
"*"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/setup.py#L63-L72 | train |
spyder-ide/spyder | setup.py | get_subpackages | def get_subpackages(name):
"""Return subpackages of package *name*"""
splist = []
for dirpath, _dirnames, _filenames in os.walk(name):
if osp.isfile(osp.join(dirpath, '__init__.py')):
splist.append(".".join(dirpath.split(os.sep)))
return splist | python | def get_subpackages(name):
"""Return subpackages of package *name*"""
splist = []
for dirpath, _dirnames, _filenames in os.walk(name):
if osp.isfile(osp.join(dirpath, '__init__.py')):
splist.append(".".join(dirpath.split(os.sep)))
return splist | [
"def",
"get_subpackages",
"(",
"name",
")",
":",
"splist",
"=",
"[",
"]",
"for",
"dirpath",
",",
"_dirnames",
",",
"_filenames",
"in",
"os",
".",
"walk",
"(",
"name",
")",
":",
"if",
"osp",
".",
"isfile",
"(",
"osp",
".",
"join",
"(",
"dirpath",
",",
"'__init__.py'",
")",
")",
":",
"splist",
".",
"append",
"(",
"\".\"",
".",
"join",
"(",
"dirpath",
".",
"split",
"(",
"os",
".",
"sep",
")",
")",
")",
"return",
"splist"
] | Return subpackages of package *name* | [
"Return",
"subpackages",
"of",
"package",
"*",
"name",
"*"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/setup.py#L75-L81 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | get_python_doc_path | def get_python_doc_path():
"""
Return Python documentation path
(Windows: return the PythonXX.chm path if available)
"""
if os.name == 'nt':
doc_path = osp.join(sys.prefix, "Doc")
if not osp.isdir(doc_path):
return
python_chm = [path for path in os.listdir(doc_path)
if re.match(r"(?i)Python[0-9]{3,6}.chm", path)]
if python_chm:
return file_uri(osp.join(doc_path, python_chm[0]))
else:
vinf = sys.version_info
doc_path = '/usr/share/doc/python%d.%d/html' % (vinf[0], vinf[1])
python_doc = osp.join(doc_path, "index.html")
if osp.isfile(python_doc):
return file_uri(python_doc) | python | def get_python_doc_path():
"""
Return Python documentation path
(Windows: return the PythonXX.chm path if available)
"""
if os.name == 'nt':
doc_path = osp.join(sys.prefix, "Doc")
if not osp.isdir(doc_path):
return
python_chm = [path for path in os.listdir(doc_path)
if re.match(r"(?i)Python[0-9]{3,6}.chm", path)]
if python_chm:
return file_uri(osp.join(doc_path, python_chm[0]))
else:
vinf = sys.version_info
doc_path = '/usr/share/doc/python%d.%d/html' % (vinf[0], vinf[1])
python_doc = osp.join(doc_path, "index.html")
if osp.isfile(python_doc):
return file_uri(python_doc) | [
"def",
"get_python_doc_path",
"(",
")",
":",
"if",
"os",
".",
"name",
"==",
"'nt'",
":",
"doc_path",
"=",
"osp",
".",
"join",
"(",
"sys",
".",
"prefix",
",",
"\"Doc\"",
")",
"if",
"not",
"osp",
".",
"isdir",
"(",
"doc_path",
")",
":",
"return",
"python_chm",
"=",
"[",
"path",
"for",
"path",
"in",
"os",
".",
"listdir",
"(",
"doc_path",
")",
"if",
"re",
".",
"match",
"(",
"r\"(?i)Python[0-9]{3,6}.chm\"",
",",
"path",
")",
"]",
"if",
"python_chm",
":",
"return",
"file_uri",
"(",
"osp",
".",
"join",
"(",
"doc_path",
",",
"python_chm",
"[",
"0",
"]",
")",
")",
"else",
":",
"vinf",
"=",
"sys",
".",
"version_info",
"doc_path",
"=",
"'/usr/share/doc/python%d.%d/html'",
"%",
"(",
"vinf",
"[",
"0",
"]",
",",
"vinf",
"[",
"1",
"]",
")",
"python_doc",
"=",
"osp",
".",
"join",
"(",
"doc_path",
",",
"\"index.html\"",
")",
"if",
"osp",
".",
"isfile",
"(",
"python_doc",
")",
":",
"return",
"file_uri",
"(",
"python_doc",
")"
] | Return Python documentation path
(Windows: return the PythonXX.chm path if available) | [
"Return",
"Python",
"documentation",
"path",
"(",
"Windows",
":",
"return",
"the",
"PythonXX",
".",
"chm",
"path",
"if",
"available",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L192-L210 | train |
spyder-ide/spyder | spyder/app/mainwindow.py | set_opengl_implementation | def set_opengl_implementation(option):
"""
Set the OpenGL implementation used by Spyder.
See issue 7447 for the details.
"""
if option == 'software':
QCoreApplication.setAttribute(Qt.AA_UseSoftwareOpenGL)
if QQuickWindow is not None:
QQuickWindow.setSceneGraphBackend(QSGRendererInterface.Software)
elif option == 'desktop':
QCoreApplication.setAttribute(Qt.AA_UseDesktopOpenGL)
if QQuickWindow is not None:
QQuickWindow.setSceneGraphBackend(QSGRendererInterface.OpenGL)
elif option == 'gles':
QCoreApplication.setAttribute(Qt.AA_UseOpenGLES)
if QQuickWindow is not None:
QQuickWindow.setSceneGraphBackend(QSGRendererInterface.OpenGL) | python | def set_opengl_implementation(option):
"""
Set the OpenGL implementation used by Spyder.
See issue 7447 for the details.
"""
if option == 'software':
QCoreApplication.setAttribute(Qt.AA_UseSoftwareOpenGL)
if QQuickWindow is not None:
QQuickWindow.setSceneGraphBackend(QSGRendererInterface.Software)
elif option == 'desktop':
QCoreApplication.setAttribute(Qt.AA_UseDesktopOpenGL)
if QQuickWindow is not None:
QQuickWindow.setSceneGraphBackend(QSGRendererInterface.OpenGL)
elif option == 'gles':
QCoreApplication.setAttribute(Qt.AA_UseOpenGLES)
if QQuickWindow is not None:
QQuickWindow.setSceneGraphBackend(QSGRendererInterface.OpenGL) | [
"def",
"set_opengl_implementation",
"(",
"option",
")",
":",
"if",
"option",
"==",
"'software'",
":",
"QCoreApplication",
".",
"setAttribute",
"(",
"Qt",
".",
"AA_UseSoftwareOpenGL",
")",
"if",
"QQuickWindow",
"is",
"not",
"None",
":",
"QQuickWindow",
".",
"setSceneGraphBackend",
"(",
"QSGRendererInterface",
".",
"Software",
")",
"elif",
"option",
"==",
"'desktop'",
":",
"QCoreApplication",
".",
"setAttribute",
"(",
"Qt",
".",
"AA_UseDesktopOpenGL",
")",
"if",
"QQuickWindow",
"is",
"not",
"None",
":",
"QQuickWindow",
".",
"setSceneGraphBackend",
"(",
"QSGRendererInterface",
".",
"OpenGL",
")",
"elif",
"option",
"==",
"'gles'",
":",
"QCoreApplication",
".",
"setAttribute",
"(",
"Qt",
".",
"AA_UseOpenGLES",
")",
"if",
"QQuickWindow",
"is",
"not",
"None",
":",
"QQuickWindow",
".",
"setSceneGraphBackend",
"(",
"QSGRendererInterface",
".",
"OpenGL",
")"
] | Set the OpenGL implementation used by Spyder.
See issue 7447 for the details. | [
"Set",
"the",
"OpenGL",
"implementation",
"used",
"by",
"Spyder",
".",
"See",
"issue",
"7447",
"for",
"the",
"details",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L213-L230 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.