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/profiler/widgets/profilergui.py | ProfilerDataTree.show_tree | def show_tree(self):
"""Populate the tree with profiler data and display it."""
self.initialize_view() # Clear before re-populating
self.setItemsExpandable(True)
self.setSortingEnabled(False)
rootkey = self.find_root() # This root contains profiler overhead
if rootkey:
self.populate_tree(self, self.find_callees(rootkey))
self.resizeColumnToContents(0)
self.setSortingEnabled(True)
self.sortItems(1, Qt.AscendingOrder) # FIXME: hardcoded index
self.change_view(1) | python | def show_tree(self):
"""Populate the tree with profiler data and display it."""
self.initialize_view() # Clear before re-populating
self.setItemsExpandable(True)
self.setSortingEnabled(False)
rootkey = self.find_root() # This root contains profiler overhead
if rootkey:
self.populate_tree(self, self.find_callees(rootkey))
self.resizeColumnToContents(0)
self.setSortingEnabled(True)
self.sortItems(1, Qt.AscendingOrder) # FIXME: hardcoded index
self.change_view(1) | [
"def",
"show_tree",
"(",
"self",
")",
":",
"self",
".",
"initialize_view",
"(",
")",
"# Clear before re-populating\r",
"self",
".",
"setItemsExpandable",
"(",
"True",
")",
"self",
".",
"setSortingEnabled",
"(",
"False",
")",
"rootkey",
"=",
"self",
".",
"find_root",
"(",
")",
"# This root contains profiler overhead\r",
"if",
"rootkey",
":",
"self",
".",
"populate_tree",
"(",
"self",
",",
"self",
".",
"find_callees",
"(",
"rootkey",
")",
")",
"self",
".",
"resizeColumnToContents",
"(",
"0",
")",
"self",
".",
"setSortingEnabled",
"(",
"True",
")",
"self",
".",
"sortItems",
"(",
"1",
",",
"Qt",
".",
"AscendingOrder",
")",
"# FIXME: hardcoded index\r",
"self",
".",
"change_view",
"(",
"1",
")"
] | Populate the tree with profiler data and display it. | [
"Populate",
"the",
"tree",
"with",
"profiler",
"data",
"and",
"display",
"it",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/profiler/widgets/profilergui.py#L536-L547 | train |
spyder-ide/spyder | spyder/plugins/profiler/widgets/profilergui.py | ProfilerDataTree.function_info | def function_info(self, functionKey):
"""Returns processed information about the function's name and file."""
node_type = 'function'
filename, line_number, function_name = functionKey
if function_name == '<module>':
modulePath, moduleName = osp.split(filename)
node_type = 'module'
if moduleName == '__init__.py':
modulePath, moduleName = osp.split(modulePath)
function_name = '<' + moduleName + '>'
if not filename or filename == '~':
file_and_line = '(built-in)'
node_type = 'builtin'
else:
if function_name == '__init__':
node_type = 'constructor'
file_and_line = '%s : %d' % (filename, line_number)
return filename, line_number, function_name, file_and_line, node_type | python | def function_info(self, functionKey):
"""Returns processed information about the function's name and file."""
node_type = 'function'
filename, line_number, function_name = functionKey
if function_name == '<module>':
modulePath, moduleName = osp.split(filename)
node_type = 'module'
if moduleName == '__init__.py':
modulePath, moduleName = osp.split(modulePath)
function_name = '<' + moduleName + '>'
if not filename or filename == '~':
file_and_line = '(built-in)'
node_type = 'builtin'
else:
if function_name == '__init__':
node_type = 'constructor'
file_and_line = '%s : %d' % (filename, line_number)
return filename, line_number, function_name, file_and_line, node_type | [
"def",
"function_info",
"(",
"self",
",",
"functionKey",
")",
":",
"node_type",
"=",
"'function'",
"filename",
",",
"line_number",
",",
"function_name",
"=",
"functionKey",
"if",
"function_name",
"==",
"'<module>'",
":",
"modulePath",
",",
"moduleName",
"=",
"osp",
".",
"split",
"(",
"filename",
")",
"node_type",
"=",
"'module'",
"if",
"moduleName",
"==",
"'__init__.py'",
":",
"modulePath",
",",
"moduleName",
"=",
"osp",
".",
"split",
"(",
"modulePath",
")",
"function_name",
"=",
"'<'",
"+",
"moduleName",
"+",
"'>'",
"if",
"not",
"filename",
"or",
"filename",
"==",
"'~'",
":",
"file_and_line",
"=",
"'(built-in)'",
"node_type",
"=",
"'builtin'",
"else",
":",
"if",
"function_name",
"==",
"'__init__'",
":",
"node_type",
"=",
"'constructor'",
"file_and_line",
"=",
"'%s : %d'",
"%",
"(",
"filename",
",",
"line_number",
")",
"return",
"filename",
",",
"line_number",
",",
"function_name",
",",
"file_and_line",
",",
"node_type"
] | Returns processed information about the function's name and file. | [
"Returns",
"processed",
"information",
"about",
"the",
"function",
"s",
"name",
"and",
"file",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/profiler/widgets/profilergui.py#L549-L566 | train |
spyder-ide/spyder | spyder/plugins/profiler/widgets/profilergui.py | ProfilerDataTree.format_measure | def format_measure(measure):
"""Get format and units for data coming from profiler task."""
# Convert to a positive value.
measure = abs(measure)
# For number of calls
if isinstance(measure, int):
return to_text_string(measure)
# For time measurements
if 1.e-9 < measure <= 1.e-6:
measure = u"{0:.2f} ns".format(measure / 1.e-9)
elif 1.e-6 < measure <= 1.e-3:
measure = u"{0:.2f} us".format(measure / 1.e-6)
elif 1.e-3 < measure <= 1:
measure = u"{0:.2f} ms".format(measure / 1.e-3)
elif 1 < measure <= 60:
measure = u"{0:.2f} sec".format(measure)
elif 60 < measure <= 3600:
m, s = divmod(measure, 3600)
if s > 60:
m, s = divmod(measure, 60)
s = to_text_string(s).split(".")[-1]
measure = u"{0:.0f}.{1:.2s} min".format(m, s)
else:
h, m = divmod(measure, 3600)
if m > 60:
m /= 60
measure = u"{0:.0f}h:{1:.0f}min".format(h, m)
return measure | python | def format_measure(measure):
"""Get format and units for data coming from profiler task."""
# Convert to a positive value.
measure = abs(measure)
# For number of calls
if isinstance(measure, int):
return to_text_string(measure)
# For time measurements
if 1.e-9 < measure <= 1.e-6:
measure = u"{0:.2f} ns".format(measure / 1.e-9)
elif 1.e-6 < measure <= 1.e-3:
measure = u"{0:.2f} us".format(measure / 1.e-6)
elif 1.e-3 < measure <= 1:
measure = u"{0:.2f} ms".format(measure / 1.e-3)
elif 1 < measure <= 60:
measure = u"{0:.2f} sec".format(measure)
elif 60 < measure <= 3600:
m, s = divmod(measure, 3600)
if s > 60:
m, s = divmod(measure, 60)
s = to_text_string(s).split(".")[-1]
measure = u"{0:.0f}.{1:.2s} min".format(m, s)
else:
h, m = divmod(measure, 3600)
if m > 60:
m /= 60
measure = u"{0:.0f}h:{1:.0f}min".format(h, m)
return measure | [
"def",
"format_measure",
"(",
"measure",
")",
":",
"# Convert to a positive value.\r",
"measure",
"=",
"abs",
"(",
"measure",
")",
"# For number of calls\r",
"if",
"isinstance",
"(",
"measure",
",",
"int",
")",
":",
"return",
"to_text_string",
"(",
"measure",
")",
"# For time measurements\r",
"if",
"1.e-9",
"<",
"measure",
"<=",
"1.e-6",
":",
"measure",
"=",
"u\"{0:.2f} ns\"",
".",
"format",
"(",
"measure",
"/",
"1.e-9",
")",
"elif",
"1.e-6",
"<",
"measure",
"<=",
"1.e-3",
":",
"measure",
"=",
"u\"{0:.2f} us\"",
".",
"format",
"(",
"measure",
"/",
"1.e-6",
")",
"elif",
"1.e-3",
"<",
"measure",
"<=",
"1",
":",
"measure",
"=",
"u\"{0:.2f} ms\"",
".",
"format",
"(",
"measure",
"/",
"1.e-3",
")",
"elif",
"1",
"<",
"measure",
"<=",
"60",
":",
"measure",
"=",
"u\"{0:.2f} sec\"",
".",
"format",
"(",
"measure",
")",
"elif",
"60",
"<",
"measure",
"<=",
"3600",
":",
"m",
",",
"s",
"=",
"divmod",
"(",
"measure",
",",
"3600",
")",
"if",
"s",
">",
"60",
":",
"m",
",",
"s",
"=",
"divmod",
"(",
"measure",
",",
"60",
")",
"s",
"=",
"to_text_string",
"(",
"s",
")",
".",
"split",
"(",
"\".\"",
")",
"[",
"-",
"1",
"]",
"measure",
"=",
"u\"{0:.0f}.{1:.2s} min\"",
".",
"format",
"(",
"m",
",",
"s",
")",
"else",
":",
"h",
",",
"m",
"=",
"divmod",
"(",
"measure",
",",
"3600",
")",
"if",
"m",
">",
"60",
":",
"m",
"/=",
"60",
"measure",
"=",
"u\"{0:.0f}h:{1:.0f}min\"",
".",
"format",
"(",
"h",
",",
"m",
")",
"return",
"measure"
] | Get format and units for data coming from profiler task. | [
"Get",
"format",
"and",
"units",
"for",
"data",
"coming",
"from",
"profiler",
"task",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/profiler/widgets/profilergui.py#L569-L598 | train |
spyder-ide/spyder | spyder/plugins/profiler/widgets/profilergui.py | ProfilerDataTree.color_string | def color_string(self, x):
"""Return a string formatted delta for the values in x.
Args:
x: 2-item list of integers (representing number of calls) or
2-item list of floats (representing seconds of runtime).
Returns:
A list with [formatted x[0], [color, formatted delta]], where
color reflects whether x[1] is lower, greater, or the same as
x[0].
"""
diff_str = ""
color = "black"
if len(x) == 2 and self.compare_file is not None:
difference = x[0] - x[1]
if difference:
color, sign = ('green', '-') if difference < 0 else ('red', '+')
diff_str = '{}{}'.format(sign, self.format_measure(difference))
return [self.format_measure(x[0]), [diff_str, color]] | python | def color_string(self, x):
"""Return a string formatted delta for the values in x.
Args:
x: 2-item list of integers (representing number of calls) or
2-item list of floats (representing seconds of runtime).
Returns:
A list with [formatted x[0], [color, formatted delta]], where
color reflects whether x[1] is lower, greater, or the same as
x[0].
"""
diff_str = ""
color = "black"
if len(x) == 2 and self.compare_file is not None:
difference = x[0] - x[1]
if difference:
color, sign = ('green', '-') if difference < 0 else ('red', '+')
diff_str = '{}{}'.format(sign, self.format_measure(difference))
return [self.format_measure(x[0]), [diff_str, color]] | [
"def",
"color_string",
"(",
"self",
",",
"x",
")",
":",
"diff_str",
"=",
"\"\"",
"color",
"=",
"\"black\"",
"if",
"len",
"(",
"x",
")",
"==",
"2",
"and",
"self",
".",
"compare_file",
"is",
"not",
"None",
":",
"difference",
"=",
"x",
"[",
"0",
"]",
"-",
"x",
"[",
"1",
"]",
"if",
"difference",
":",
"color",
",",
"sign",
"=",
"(",
"'green'",
",",
"'-'",
")",
"if",
"difference",
"<",
"0",
"else",
"(",
"'red'",
",",
"'+'",
")",
"diff_str",
"=",
"'{}{}'",
".",
"format",
"(",
"sign",
",",
"self",
".",
"format_measure",
"(",
"difference",
")",
")",
"return",
"[",
"self",
".",
"format_measure",
"(",
"x",
"[",
"0",
"]",
")",
",",
"[",
"diff_str",
",",
"color",
"]",
"]"
] | Return a string formatted delta for the values in x.
Args:
x: 2-item list of integers (representing number of calls) or
2-item list of floats (representing seconds of runtime).
Returns:
A list with [formatted x[0], [color, formatted delta]], where
color reflects whether x[1] is lower, greater, or the same as
x[0]. | [
"Return",
"a",
"string",
"formatted",
"delta",
"for",
"the",
"values",
"in",
"x",
".",
"Args",
":",
"x",
":",
"2",
"-",
"item",
"list",
"of",
"integers",
"(",
"representing",
"number",
"of",
"calls",
")",
"or",
"2",
"-",
"item",
"list",
"of",
"floats",
"(",
"representing",
"seconds",
"of",
"runtime",
")",
".",
"Returns",
":",
"A",
"list",
"with",
"[",
"formatted",
"x",
"[",
"0",
"]",
"[",
"color",
"formatted",
"delta",
"]]",
"where",
"color",
"reflects",
"whether",
"x",
"[",
"1",
"]",
"is",
"lower",
"greater",
"or",
"the",
"same",
"as",
"x",
"[",
"0",
"]",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/profiler/widgets/profilergui.py#L600-L620 | train |
spyder-ide/spyder | spyder/plugins/profiler/widgets/profilergui.py | ProfilerDataTree.format_output | def format_output(self, child_key):
""" Formats the data.
self.stats1 contains a list of one or two pstat.Stats() instances, with
the first being the current run and the second, the saved run, if it
exists. Each Stats instance is a dictionary mapping a function to
5 data points - cumulative calls, number of calls, total time,
cumulative time, and callers.
format_output() converts the number of calls, total time, and
cumulative time to a string format for the child_key parameter.
"""
data = [x.stats.get(child_key, [0, 0, 0, 0, {}]) for x in self.stats1]
return (map(self.color_string, islice(zip(*data), 1, 4))) | python | def format_output(self, child_key):
""" Formats the data.
self.stats1 contains a list of one or two pstat.Stats() instances, with
the first being the current run and the second, the saved run, if it
exists. Each Stats instance is a dictionary mapping a function to
5 data points - cumulative calls, number of calls, total time,
cumulative time, and callers.
format_output() converts the number of calls, total time, and
cumulative time to a string format for the child_key parameter.
"""
data = [x.stats.get(child_key, [0, 0, 0, 0, {}]) for x in self.stats1]
return (map(self.color_string, islice(zip(*data), 1, 4))) | [
"def",
"format_output",
"(",
"self",
",",
"child_key",
")",
":",
"data",
"=",
"[",
"x",
".",
"stats",
".",
"get",
"(",
"child_key",
",",
"[",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"{",
"}",
"]",
")",
"for",
"x",
"in",
"self",
".",
"stats1",
"]",
"return",
"(",
"map",
"(",
"self",
".",
"color_string",
",",
"islice",
"(",
"zip",
"(",
"*",
"data",
")",
",",
"1",
",",
"4",
")",
")",
")"
] | Formats the data.
self.stats1 contains a list of one or two pstat.Stats() instances, with
the first being the current run and the second, the saved run, if it
exists. Each Stats instance is a dictionary mapping a function to
5 data points - cumulative calls, number of calls, total time,
cumulative time, and callers.
format_output() converts the number of calls, total time, and
cumulative time to a string format for the child_key parameter. | [
"Formats",
"the",
"data",
".",
"self",
".",
"stats1",
"contains",
"a",
"list",
"of",
"one",
"or",
"two",
"pstat",
".",
"Stats",
"()",
"instances",
"with",
"the",
"first",
"being",
"the",
"current",
"run",
"and",
"the",
"second",
"the",
"saved",
"run",
"if",
"it",
"exists",
".",
"Each",
"Stats",
"instance",
"is",
"a",
"dictionary",
"mapping",
"a",
"function",
"to",
"5",
"data",
"points",
"-",
"cumulative",
"calls",
"number",
"of",
"calls",
"total",
"time",
"cumulative",
"time",
"and",
"callers",
".",
"format_output",
"()",
"converts",
"the",
"number",
"of",
"calls",
"total",
"time",
"and",
"cumulative",
"time",
"to",
"a",
"string",
"format",
"for",
"the",
"child_key",
"parameter",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/profiler/widgets/profilergui.py#L622-L635 | train |
spyder-ide/spyder | spyder/plugins/profiler/widgets/profilergui.py | ProfilerDataTree.populate_tree | def populate_tree(self, parentItem, children_list):
"""Recursive method to create each item (and associated data) in the tree."""
for child_key in children_list:
self.item_depth += 1
(filename, line_number, function_name, file_and_line, node_type
) = self.function_info(child_key)
((total_calls, total_calls_dif), (loc_time, loc_time_dif), (cum_time,
cum_time_dif)) = self.format_output(child_key)
child_item = TreeWidgetItem(parentItem)
self.item_list.append(child_item)
self.set_item_data(child_item, filename, line_number)
# FIXME: indexes to data should be defined by a dictionary on init
child_item.setToolTip(0, _('Function or module name'))
child_item.setData(0, Qt.DisplayRole, function_name)
child_item.setIcon(0, self.icon_list[node_type])
child_item.setToolTip(1, _('Time in function '\
'(including sub-functions)'))
child_item.setData(1, Qt.DisplayRole, cum_time)
child_item.setTextAlignment(1, Qt.AlignRight)
child_item.setData(2, Qt.DisplayRole, cum_time_dif[0])
child_item.setForeground(2, QColor(cum_time_dif[1]))
child_item.setTextAlignment(2, Qt.AlignLeft)
child_item.setToolTip(3, _('Local time in function '\
'(not in sub-functions)'))
child_item.setData(3, Qt.DisplayRole, loc_time)
child_item.setTextAlignment(3, Qt.AlignRight)
child_item.setData(4, Qt.DisplayRole, loc_time_dif[0])
child_item.setForeground(4, QColor(loc_time_dif[1]))
child_item.setTextAlignment(4, Qt.AlignLeft)
child_item.setToolTip(5, _('Total number of calls '\
'(including recursion)'))
child_item.setData(5, Qt.DisplayRole, total_calls)
child_item.setTextAlignment(5, Qt.AlignRight)
child_item.setData(6, Qt.DisplayRole, total_calls_dif[0])
child_item.setForeground(6, QColor(total_calls_dif[1]))
child_item.setTextAlignment(6, Qt.AlignLeft)
child_item.setToolTip(7, _('File:line '\
'where function is defined'))
child_item.setData(7, Qt.DisplayRole, file_and_line)
#child_item.setExpanded(True)
if self.is_recursive(child_item):
child_item.setData(7, Qt.DisplayRole, '(%s)' % _('recursion'))
child_item.setDisabled(True)
else:
callees = self.find_callees(child_key)
if self.item_depth < 3:
self.populate_tree(child_item, callees)
elif callees:
child_item.setChildIndicatorPolicy(child_item.ShowIndicator)
self.items_to_be_shown[id(child_item)] = callees
self.item_depth -= 1 | python | def populate_tree(self, parentItem, children_list):
"""Recursive method to create each item (and associated data) in the tree."""
for child_key in children_list:
self.item_depth += 1
(filename, line_number, function_name, file_and_line, node_type
) = self.function_info(child_key)
((total_calls, total_calls_dif), (loc_time, loc_time_dif), (cum_time,
cum_time_dif)) = self.format_output(child_key)
child_item = TreeWidgetItem(parentItem)
self.item_list.append(child_item)
self.set_item_data(child_item, filename, line_number)
# FIXME: indexes to data should be defined by a dictionary on init
child_item.setToolTip(0, _('Function or module name'))
child_item.setData(0, Qt.DisplayRole, function_name)
child_item.setIcon(0, self.icon_list[node_type])
child_item.setToolTip(1, _('Time in function '\
'(including sub-functions)'))
child_item.setData(1, Qt.DisplayRole, cum_time)
child_item.setTextAlignment(1, Qt.AlignRight)
child_item.setData(2, Qt.DisplayRole, cum_time_dif[0])
child_item.setForeground(2, QColor(cum_time_dif[1]))
child_item.setTextAlignment(2, Qt.AlignLeft)
child_item.setToolTip(3, _('Local time in function '\
'(not in sub-functions)'))
child_item.setData(3, Qt.DisplayRole, loc_time)
child_item.setTextAlignment(3, Qt.AlignRight)
child_item.setData(4, Qt.DisplayRole, loc_time_dif[0])
child_item.setForeground(4, QColor(loc_time_dif[1]))
child_item.setTextAlignment(4, Qt.AlignLeft)
child_item.setToolTip(5, _('Total number of calls '\
'(including recursion)'))
child_item.setData(5, Qt.DisplayRole, total_calls)
child_item.setTextAlignment(5, Qt.AlignRight)
child_item.setData(6, Qt.DisplayRole, total_calls_dif[0])
child_item.setForeground(6, QColor(total_calls_dif[1]))
child_item.setTextAlignment(6, Qt.AlignLeft)
child_item.setToolTip(7, _('File:line '\
'where function is defined'))
child_item.setData(7, Qt.DisplayRole, file_and_line)
#child_item.setExpanded(True)
if self.is_recursive(child_item):
child_item.setData(7, Qt.DisplayRole, '(%s)' % _('recursion'))
child_item.setDisabled(True)
else:
callees = self.find_callees(child_key)
if self.item_depth < 3:
self.populate_tree(child_item, callees)
elif callees:
child_item.setChildIndicatorPolicy(child_item.ShowIndicator)
self.items_to_be_shown[id(child_item)] = callees
self.item_depth -= 1 | [
"def",
"populate_tree",
"(",
"self",
",",
"parentItem",
",",
"children_list",
")",
":",
"for",
"child_key",
"in",
"children_list",
":",
"self",
".",
"item_depth",
"+=",
"1",
"(",
"filename",
",",
"line_number",
",",
"function_name",
",",
"file_and_line",
",",
"node_type",
")",
"=",
"self",
".",
"function_info",
"(",
"child_key",
")",
"(",
"(",
"total_calls",
",",
"total_calls_dif",
")",
",",
"(",
"loc_time",
",",
"loc_time_dif",
")",
",",
"(",
"cum_time",
",",
"cum_time_dif",
")",
")",
"=",
"self",
".",
"format_output",
"(",
"child_key",
")",
"child_item",
"=",
"TreeWidgetItem",
"(",
"parentItem",
")",
"self",
".",
"item_list",
".",
"append",
"(",
"child_item",
")",
"self",
".",
"set_item_data",
"(",
"child_item",
",",
"filename",
",",
"line_number",
")",
"# FIXME: indexes to data should be defined by a dictionary on init\r",
"child_item",
".",
"setToolTip",
"(",
"0",
",",
"_",
"(",
"'Function or module name'",
")",
")",
"child_item",
".",
"setData",
"(",
"0",
",",
"Qt",
".",
"DisplayRole",
",",
"function_name",
")",
"child_item",
".",
"setIcon",
"(",
"0",
",",
"self",
".",
"icon_list",
"[",
"node_type",
"]",
")",
"child_item",
".",
"setToolTip",
"(",
"1",
",",
"_",
"(",
"'Time in function '",
"'(including sub-functions)'",
")",
")",
"child_item",
".",
"setData",
"(",
"1",
",",
"Qt",
".",
"DisplayRole",
",",
"cum_time",
")",
"child_item",
".",
"setTextAlignment",
"(",
"1",
",",
"Qt",
".",
"AlignRight",
")",
"child_item",
".",
"setData",
"(",
"2",
",",
"Qt",
".",
"DisplayRole",
",",
"cum_time_dif",
"[",
"0",
"]",
")",
"child_item",
".",
"setForeground",
"(",
"2",
",",
"QColor",
"(",
"cum_time_dif",
"[",
"1",
"]",
")",
")",
"child_item",
".",
"setTextAlignment",
"(",
"2",
",",
"Qt",
".",
"AlignLeft",
")",
"child_item",
".",
"setToolTip",
"(",
"3",
",",
"_",
"(",
"'Local time in function '",
"'(not in sub-functions)'",
")",
")",
"child_item",
".",
"setData",
"(",
"3",
",",
"Qt",
".",
"DisplayRole",
",",
"loc_time",
")",
"child_item",
".",
"setTextAlignment",
"(",
"3",
",",
"Qt",
".",
"AlignRight",
")",
"child_item",
".",
"setData",
"(",
"4",
",",
"Qt",
".",
"DisplayRole",
",",
"loc_time_dif",
"[",
"0",
"]",
")",
"child_item",
".",
"setForeground",
"(",
"4",
",",
"QColor",
"(",
"loc_time_dif",
"[",
"1",
"]",
")",
")",
"child_item",
".",
"setTextAlignment",
"(",
"4",
",",
"Qt",
".",
"AlignLeft",
")",
"child_item",
".",
"setToolTip",
"(",
"5",
",",
"_",
"(",
"'Total number of calls '",
"'(including recursion)'",
")",
")",
"child_item",
".",
"setData",
"(",
"5",
",",
"Qt",
".",
"DisplayRole",
",",
"total_calls",
")",
"child_item",
".",
"setTextAlignment",
"(",
"5",
",",
"Qt",
".",
"AlignRight",
")",
"child_item",
".",
"setData",
"(",
"6",
",",
"Qt",
".",
"DisplayRole",
",",
"total_calls_dif",
"[",
"0",
"]",
")",
"child_item",
".",
"setForeground",
"(",
"6",
",",
"QColor",
"(",
"total_calls_dif",
"[",
"1",
"]",
")",
")",
"child_item",
".",
"setTextAlignment",
"(",
"6",
",",
"Qt",
".",
"AlignLeft",
")",
"child_item",
".",
"setToolTip",
"(",
"7",
",",
"_",
"(",
"'File:line '",
"'where function is defined'",
")",
")",
"child_item",
".",
"setData",
"(",
"7",
",",
"Qt",
".",
"DisplayRole",
",",
"file_and_line",
")",
"#child_item.setExpanded(True)\r",
"if",
"self",
".",
"is_recursive",
"(",
"child_item",
")",
":",
"child_item",
".",
"setData",
"(",
"7",
",",
"Qt",
".",
"DisplayRole",
",",
"'(%s)'",
"%",
"_",
"(",
"'recursion'",
")",
")",
"child_item",
".",
"setDisabled",
"(",
"True",
")",
"else",
":",
"callees",
"=",
"self",
".",
"find_callees",
"(",
"child_key",
")",
"if",
"self",
".",
"item_depth",
"<",
"3",
":",
"self",
".",
"populate_tree",
"(",
"child_item",
",",
"callees",
")",
"elif",
"callees",
":",
"child_item",
".",
"setChildIndicatorPolicy",
"(",
"child_item",
".",
"ShowIndicator",
")",
"self",
".",
"items_to_be_shown",
"[",
"id",
"(",
"child_item",
")",
"]",
"=",
"callees",
"self",
".",
"item_depth",
"-=",
"1"
] | Recursive method to create each item (and associated data) in the tree. | [
"Recursive",
"method",
"to",
"create",
"each",
"item",
"(",
"and",
"associated",
"data",
")",
"in",
"the",
"tree",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/profiler/widgets/profilergui.py#L637-L699 | train |
spyder-ide/spyder | spyder/plugins/profiler/widgets/profilergui.py | ProfilerDataTree.is_recursive | def is_recursive(self, child_item):
"""Returns True is a function is a descendant of itself."""
ancestor = child_item.parent()
# FIXME: indexes to data should be defined by a dictionary on init
while ancestor:
if (child_item.data(0, Qt.DisplayRole
) == ancestor.data(0, Qt.DisplayRole) and
child_item.data(7, Qt.DisplayRole
) == ancestor.data(7, Qt.DisplayRole)):
return True
else:
ancestor = ancestor.parent()
return False | python | def is_recursive(self, child_item):
"""Returns True is a function is a descendant of itself."""
ancestor = child_item.parent()
# FIXME: indexes to data should be defined by a dictionary on init
while ancestor:
if (child_item.data(0, Qt.DisplayRole
) == ancestor.data(0, Qt.DisplayRole) and
child_item.data(7, Qt.DisplayRole
) == ancestor.data(7, Qt.DisplayRole)):
return True
else:
ancestor = ancestor.parent()
return False | [
"def",
"is_recursive",
"(",
"self",
",",
"child_item",
")",
":",
"ancestor",
"=",
"child_item",
".",
"parent",
"(",
")",
"# FIXME: indexes to data should be defined by a dictionary on init\r",
"while",
"ancestor",
":",
"if",
"(",
"child_item",
".",
"data",
"(",
"0",
",",
"Qt",
".",
"DisplayRole",
")",
"==",
"ancestor",
".",
"data",
"(",
"0",
",",
"Qt",
".",
"DisplayRole",
")",
"and",
"child_item",
".",
"data",
"(",
"7",
",",
"Qt",
".",
"DisplayRole",
")",
"==",
"ancestor",
".",
"data",
"(",
"7",
",",
"Qt",
".",
"DisplayRole",
")",
")",
":",
"return",
"True",
"else",
":",
"ancestor",
"=",
"ancestor",
".",
"parent",
"(",
")",
"return",
"False"
] | Returns True is a function is a descendant of itself. | [
"Returns",
"True",
"is",
"a",
"function",
"is",
"a",
"descendant",
"of",
"itself",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/profiler/widgets/profilergui.py#L710-L722 | train |
spyder-ide/spyder | spyder/plugins/profiler/widgets/profilergui.py | ProfilerDataTree.get_items | def get_items(self, maxlevel):
"""Return all items with a level <= `maxlevel`"""
itemlist = []
def add_to_itemlist(item, maxlevel, level=1):
level += 1
for index in range(item.childCount()):
citem = item.child(index)
itemlist.append(citem)
if level <= maxlevel:
add_to_itemlist(citem, maxlevel, level)
for tlitem in self.get_top_level_items():
itemlist.append(tlitem)
if maxlevel > 0:
add_to_itemlist(tlitem, maxlevel=maxlevel)
return itemlist | python | def get_items(self, maxlevel):
"""Return all items with a level <= `maxlevel`"""
itemlist = []
def add_to_itemlist(item, maxlevel, level=1):
level += 1
for index in range(item.childCount()):
citem = item.child(index)
itemlist.append(citem)
if level <= maxlevel:
add_to_itemlist(citem, maxlevel, level)
for tlitem in self.get_top_level_items():
itemlist.append(tlitem)
if maxlevel > 0:
add_to_itemlist(tlitem, maxlevel=maxlevel)
return itemlist | [
"def",
"get_items",
"(",
"self",
",",
"maxlevel",
")",
":",
"itemlist",
"=",
"[",
"]",
"def",
"add_to_itemlist",
"(",
"item",
",",
"maxlevel",
",",
"level",
"=",
"1",
")",
":",
"level",
"+=",
"1",
"for",
"index",
"in",
"range",
"(",
"item",
".",
"childCount",
"(",
")",
")",
":",
"citem",
"=",
"item",
".",
"child",
"(",
"index",
")",
"itemlist",
".",
"append",
"(",
"citem",
")",
"if",
"level",
"<=",
"maxlevel",
":",
"add_to_itemlist",
"(",
"citem",
",",
"maxlevel",
",",
"level",
")",
"for",
"tlitem",
"in",
"self",
".",
"get_top_level_items",
"(",
")",
":",
"itemlist",
".",
"append",
"(",
"tlitem",
")",
"if",
"maxlevel",
">",
"0",
":",
"add_to_itemlist",
"(",
"tlitem",
",",
"maxlevel",
"=",
"maxlevel",
")",
"return",
"itemlist"
] | Return all items with a level <= `maxlevel` | [
"Return",
"all",
"items",
"with",
"a",
"level",
"<",
"=",
"maxlevel"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/profiler/widgets/profilergui.py#L728-L742 | train |
spyder-ide/spyder | spyder/plugins/profiler/widgets/profilergui.py | ProfilerDataTree.change_view | def change_view(self, change_in_depth):
"""Change the view depth by expand or collapsing all same-level nodes"""
self.current_view_depth += change_in_depth
if self.current_view_depth < 0:
self.current_view_depth = 0
self.collapseAll()
if self.current_view_depth > 0:
for item in self.get_items(maxlevel=self.current_view_depth-1):
item.setExpanded(True) | python | def change_view(self, change_in_depth):
"""Change the view depth by expand or collapsing all same-level nodes"""
self.current_view_depth += change_in_depth
if self.current_view_depth < 0:
self.current_view_depth = 0
self.collapseAll()
if self.current_view_depth > 0:
for item in self.get_items(maxlevel=self.current_view_depth-1):
item.setExpanded(True) | [
"def",
"change_view",
"(",
"self",
",",
"change_in_depth",
")",
":",
"self",
".",
"current_view_depth",
"+=",
"change_in_depth",
"if",
"self",
".",
"current_view_depth",
"<",
"0",
":",
"self",
".",
"current_view_depth",
"=",
"0",
"self",
".",
"collapseAll",
"(",
")",
"if",
"self",
".",
"current_view_depth",
">",
"0",
":",
"for",
"item",
"in",
"self",
".",
"get_items",
"(",
"maxlevel",
"=",
"self",
".",
"current_view_depth",
"-",
"1",
")",
":",
"item",
".",
"setExpanded",
"(",
"True",
")"
] | Change the view depth by expand or collapsing all same-level nodes | [
"Change",
"the",
"view",
"depth",
"by",
"expand",
"or",
"collapsing",
"all",
"same",
"-",
"level",
"nodes"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/profiler/widgets/profilergui.py#L744-L752 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/utils/style.py | create_qss_style | def create_qss_style(color_scheme):
"""Returns a QSS stylesheet with Spyder color scheme settings.
The stylesheet can contain classes for:
Qt: QPlainTextEdit, QFrame, QWidget, etc
Pygments: .c, .k, .o, etc. (see PygmentsHighlighter)
IPython: .error, .in-prompt, .out-prompt, etc
"""
def give_font_weight(is_bold):
if is_bold:
return 'bold'
else:
return 'normal'
def give_font_style(is_italic):
if is_italic:
return 'italic'
else:
return 'normal'
color_scheme = get_color_scheme(color_scheme)
fon_c, fon_fw, fon_fs = color_scheme['normal']
font_color = fon_c
if dark_color(font_color):
in_prompt_color = 'navy'
out_prompt_color = 'darkred'
else:
in_prompt_color = 'lime'
out_prompt_color = 'red'
background_color = color_scheme['background']
error_color = 'red'
in_prompt_number_font_weight = 'bold'
out_prompt_number_font_weight = 'bold'
inverted_background_color = font_color
inverted_font_color = background_color
sheet = """QPlainTextEdit, QTextEdit, ControlWidget {{
color: {} ;
background-color: {};
}}
.error {{ color: {}; }}
.in-prompt {{ color: {}; }}
.in-prompt-number {{ color: {}; font-weight: {}; }}
.out-prompt {{ color: {}; }}
.out-prompt-number {{ color: {}; font-weight: {}; }}
.inverted {{ color: {}; background-color: {}; }}
"""
sheet_formatted = sheet.format(font_color, background_color,
error_color,
in_prompt_color, in_prompt_color,
in_prompt_number_font_weight,
out_prompt_color, out_prompt_color,
out_prompt_number_font_weight,
inverted_background_color,
inverted_font_color)
return (sheet_formatted, dark_color(font_color)) | python | def create_qss_style(color_scheme):
"""Returns a QSS stylesheet with Spyder color scheme settings.
The stylesheet can contain classes for:
Qt: QPlainTextEdit, QFrame, QWidget, etc
Pygments: .c, .k, .o, etc. (see PygmentsHighlighter)
IPython: .error, .in-prompt, .out-prompt, etc
"""
def give_font_weight(is_bold):
if is_bold:
return 'bold'
else:
return 'normal'
def give_font_style(is_italic):
if is_italic:
return 'italic'
else:
return 'normal'
color_scheme = get_color_scheme(color_scheme)
fon_c, fon_fw, fon_fs = color_scheme['normal']
font_color = fon_c
if dark_color(font_color):
in_prompt_color = 'navy'
out_prompt_color = 'darkred'
else:
in_prompt_color = 'lime'
out_prompt_color = 'red'
background_color = color_scheme['background']
error_color = 'red'
in_prompt_number_font_weight = 'bold'
out_prompt_number_font_weight = 'bold'
inverted_background_color = font_color
inverted_font_color = background_color
sheet = """QPlainTextEdit, QTextEdit, ControlWidget {{
color: {} ;
background-color: {};
}}
.error {{ color: {}; }}
.in-prompt {{ color: {}; }}
.in-prompt-number {{ color: {}; font-weight: {}; }}
.out-prompt {{ color: {}; }}
.out-prompt-number {{ color: {}; font-weight: {}; }}
.inverted {{ color: {}; background-color: {}; }}
"""
sheet_formatted = sheet.format(font_color, background_color,
error_color,
in_prompt_color, in_prompt_color,
in_prompt_number_font_weight,
out_prompt_color, out_prompt_color,
out_prompt_number_font_weight,
inverted_background_color,
inverted_font_color)
return (sheet_formatted, dark_color(font_color)) | [
"def",
"create_qss_style",
"(",
"color_scheme",
")",
":",
"def",
"give_font_weight",
"(",
"is_bold",
")",
":",
"if",
"is_bold",
":",
"return",
"'bold'",
"else",
":",
"return",
"'normal'",
"def",
"give_font_style",
"(",
"is_italic",
")",
":",
"if",
"is_italic",
":",
"return",
"'italic'",
"else",
":",
"return",
"'normal'",
"color_scheme",
"=",
"get_color_scheme",
"(",
"color_scheme",
")",
"fon_c",
",",
"fon_fw",
",",
"fon_fs",
"=",
"color_scheme",
"[",
"'normal'",
"]",
"font_color",
"=",
"fon_c",
"if",
"dark_color",
"(",
"font_color",
")",
":",
"in_prompt_color",
"=",
"'navy'",
"out_prompt_color",
"=",
"'darkred'",
"else",
":",
"in_prompt_color",
"=",
"'lime'",
"out_prompt_color",
"=",
"'red'",
"background_color",
"=",
"color_scheme",
"[",
"'background'",
"]",
"error_color",
"=",
"'red'",
"in_prompt_number_font_weight",
"=",
"'bold'",
"out_prompt_number_font_weight",
"=",
"'bold'",
"inverted_background_color",
"=",
"font_color",
"inverted_font_color",
"=",
"background_color",
"sheet",
"=",
"\"\"\"QPlainTextEdit, QTextEdit, ControlWidget {{\n color: {} ;\n background-color: {};\n }}\n .error {{ color: {}; }}\n .in-prompt {{ color: {}; }}\n .in-prompt-number {{ color: {}; font-weight: {}; }}\n .out-prompt {{ color: {}; }}\n .out-prompt-number {{ color: {}; font-weight: {}; }}\n .inverted {{ color: {}; background-color: {}; }}\n \"\"\"",
"sheet_formatted",
"=",
"sheet",
".",
"format",
"(",
"font_color",
",",
"background_color",
",",
"error_color",
",",
"in_prompt_color",
",",
"in_prompt_color",
",",
"in_prompt_number_font_weight",
",",
"out_prompt_color",
",",
"out_prompt_color",
",",
"out_prompt_number_font_weight",
",",
"inverted_background_color",
",",
"inverted_font_color",
")",
"return",
"(",
"sheet_formatted",
",",
"dark_color",
"(",
"font_color",
")",
")"
] | Returns a QSS stylesheet with Spyder color scheme settings.
The stylesheet can contain classes for:
Qt: QPlainTextEdit, QFrame, QWidget, etc
Pygments: .c, .k, .o, etc. (see PygmentsHighlighter)
IPython: .error, .in-prompt, .out-prompt, etc | [
"Returns",
"a",
"QSS",
"stylesheet",
"with",
"Spyder",
"color",
"scheme",
"settings",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/utils/style.py#L22-L80 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/utils/style.py | create_pygments_dict | def create_pygments_dict(color_scheme_name):
"""
Create a dictionary that saves the given color scheme as a
Pygments style.
"""
def give_font_weight(is_bold):
if is_bold:
return 'bold'
else:
return ''
def give_font_style(is_italic):
if is_italic:
return 'italic'
else:
return ''
color_scheme = get_color_scheme(color_scheme_name)
fon_c, fon_fw, fon_fs = color_scheme['normal']
font_color = fon_c
font_font_weight = give_font_weight(fon_fw)
font_font_style = give_font_style(fon_fs)
key_c, key_fw, key_fs = color_scheme['keyword']
keyword_color = key_c
keyword_font_weight = give_font_weight(key_fw)
keyword_font_style = give_font_style(key_fs)
bui_c, bui_fw, bui_fs = color_scheme['builtin']
builtin_color = bui_c
builtin_font_weight = give_font_weight(bui_fw)
builtin_font_style = give_font_style(bui_fs)
str_c, str_fw, str_fs = color_scheme['string']
string_color = str_c
string_font_weight = give_font_weight(str_fw)
string_font_style = give_font_style(str_fs)
num_c, num_fw, num_fs = color_scheme['number']
number_color = num_c
number_font_weight = give_font_weight(num_fw)
number_font_style = give_font_style(num_fs)
com_c, com_fw, com_fs = color_scheme['comment']
comment_color = com_c
comment_font_weight = give_font_weight(com_fw)
comment_font_style = give_font_style(com_fs)
def_c, def_fw, def_fs = color_scheme['definition']
definition_color = def_c
definition_font_weight = give_font_weight(def_fw)
definition_font_style = give_font_style(def_fs)
ins_c, ins_fw, ins_fs = color_scheme['instance']
instance_color = ins_c
instance_font_weight = give_font_weight(ins_fw)
instance_font_style = give_font_style(ins_fs)
font_token = font_font_style + ' ' + font_font_weight + ' ' + font_color
definition_token = (definition_font_style + ' ' + definition_font_weight +
' ' + definition_color)
builtin_token = (builtin_font_style + ' ' + builtin_font_weight + ' ' +
builtin_color)
instance_token = (instance_font_style + ' ' + instance_font_weight + ' ' +
instance_color)
keyword_token = (keyword_font_style + ' ' + keyword_font_weight + ' ' +
keyword_color)
comment_token = (comment_font_style + ' ' + comment_font_weight + ' ' +
comment_color)
string_token = (string_font_style + ' ' + string_font_weight + ' ' +
string_color)
number_token = (number_font_style + ' ' + number_font_weight + ' ' +
number_color)
syntax_style_dic = {Name: font_token.strip(),
Name.Class: definition_token.strip(),
Name.Function: definition_token.strip(),
Name.Builtin: builtin_token.strip(),
Name.Builtin.Pseudo: instance_token.strip(),
Keyword: keyword_token.strip(),
Keyword.Type: builtin_token.strip(),
Comment: comment_token.strip(),
String: string_token.strip(),
Number: number_token.strip(),
Punctuation: font_token.strip(),
Operator.Word: keyword_token.strip()}
return syntax_style_dic | python | def create_pygments_dict(color_scheme_name):
"""
Create a dictionary that saves the given color scheme as a
Pygments style.
"""
def give_font_weight(is_bold):
if is_bold:
return 'bold'
else:
return ''
def give_font_style(is_italic):
if is_italic:
return 'italic'
else:
return ''
color_scheme = get_color_scheme(color_scheme_name)
fon_c, fon_fw, fon_fs = color_scheme['normal']
font_color = fon_c
font_font_weight = give_font_weight(fon_fw)
font_font_style = give_font_style(fon_fs)
key_c, key_fw, key_fs = color_scheme['keyword']
keyword_color = key_c
keyword_font_weight = give_font_weight(key_fw)
keyword_font_style = give_font_style(key_fs)
bui_c, bui_fw, bui_fs = color_scheme['builtin']
builtin_color = bui_c
builtin_font_weight = give_font_weight(bui_fw)
builtin_font_style = give_font_style(bui_fs)
str_c, str_fw, str_fs = color_scheme['string']
string_color = str_c
string_font_weight = give_font_weight(str_fw)
string_font_style = give_font_style(str_fs)
num_c, num_fw, num_fs = color_scheme['number']
number_color = num_c
number_font_weight = give_font_weight(num_fw)
number_font_style = give_font_style(num_fs)
com_c, com_fw, com_fs = color_scheme['comment']
comment_color = com_c
comment_font_weight = give_font_weight(com_fw)
comment_font_style = give_font_style(com_fs)
def_c, def_fw, def_fs = color_scheme['definition']
definition_color = def_c
definition_font_weight = give_font_weight(def_fw)
definition_font_style = give_font_style(def_fs)
ins_c, ins_fw, ins_fs = color_scheme['instance']
instance_color = ins_c
instance_font_weight = give_font_weight(ins_fw)
instance_font_style = give_font_style(ins_fs)
font_token = font_font_style + ' ' + font_font_weight + ' ' + font_color
definition_token = (definition_font_style + ' ' + definition_font_weight +
' ' + definition_color)
builtin_token = (builtin_font_style + ' ' + builtin_font_weight + ' ' +
builtin_color)
instance_token = (instance_font_style + ' ' + instance_font_weight + ' ' +
instance_color)
keyword_token = (keyword_font_style + ' ' + keyword_font_weight + ' ' +
keyword_color)
comment_token = (comment_font_style + ' ' + comment_font_weight + ' ' +
comment_color)
string_token = (string_font_style + ' ' + string_font_weight + ' ' +
string_color)
number_token = (number_font_style + ' ' + number_font_weight + ' ' +
number_color)
syntax_style_dic = {Name: font_token.strip(),
Name.Class: definition_token.strip(),
Name.Function: definition_token.strip(),
Name.Builtin: builtin_token.strip(),
Name.Builtin.Pseudo: instance_token.strip(),
Keyword: keyword_token.strip(),
Keyword.Type: builtin_token.strip(),
Comment: comment_token.strip(),
String: string_token.strip(),
Number: number_token.strip(),
Punctuation: font_token.strip(),
Operator.Word: keyword_token.strip()}
return syntax_style_dic | [
"def",
"create_pygments_dict",
"(",
"color_scheme_name",
")",
":",
"def",
"give_font_weight",
"(",
"is_bold",
")",
":",
"if",
"is_bold",
":",
"return",
"'bold'",
"else",
":",
"return",
"''",
"def",
"give_font_style",
"(",
"is_italic",
")",
":",
"if",
"is_italic",
":",
"return",
"'italic'",
"else",
":",
"return",
"''",
"color_scheme",
"=",
"get_color_scheme",
"(",
"color_scheme_name",
")",
"fon_c",
",",
"fon_fw",
",",
"fon_fs",
"=",
"color_scheme",
"[",
"'normal'",
"]",
"font_color",
"=",
"fon_c",
"font_font_weight",
"=",
"give_font_weight",
"(",
"fon_fw",
")",
"font_font_style",
"=",
"give_font_style",
"(",
"fon_fs",
")",
"key_c",
",",
"key_fw",
",",
"key_fs",
"=",
"color_scheme",
"[",
"'keyword'",
"]",
"keyword_color",
"=",
"key_c",
"keyword_font_weight",
"=",
"give_font_weight",
"(",
"key_fw",
")",
"keyword_font_style",
"=",
"give_font_style",
"(",
"key_fs",
")",
"bui_c",
",",
"bui_fw",
",",
"bui_fs",
"=",
"color_scheme",
"[",
"'builtin'",
"]",
"builtin_color",
"=",
"bui_c",
"builtin_font_weight",
"=",
"give_font_weight",
"(",
"bui_fw",
")",
"builtin_font_style",
"=",
"give_font_style",
"(",
"bui_fs",
")",
"str_c",
",",
"str_fw",
",",
"str_fs",
"=",
"color_scheme",
"[",
"'string'",
"]",
"string_color",
"=",
"str_c",
"string_font_weight",
"=",
"give_font_weight",
"(",
"str_fw",
")",
"string_font_style",
"=",
"give_font_style",
"(",
"str_fs",
")",
"num_c",
",",
"num_fw",
",",
"num_fs",
"=",
"color_scheme",
"[",
"'number'",
"]",
"number_color",
"=",
"num_c",
"number_font_weight",
"=",
"give_font_weight",
"(",
"num_fw",
")",
"number_font_style",
"=",
"give_font_style",
"(",
"num_fs",
")",
"com_c",
",",
"com_fw",
",",
"com_fs",
"=",
"color_scheme",
"[",
"'comment'",
"]",
"comment_color",
"=",
"com_c",
"comment_font_weight",
"=",
"give_font_weight",
"(",
"com_fw",
")",
"comment_font_style",
"=",
"give_font_style",
"(",
"com_fs",
")",
"def_c",
",",
"def_fw",
",",
"def_fs",
"=",
"color_scheme",
"[",
"'definition'",
"]",
"definition_color",
"=",
"def_c",
"definition_font_weight",
"=",
"give_font_weight",
"(",
"def_fw",
")",
"definition_font_style",
"=",
"give_font_style",
"(",
"def_fs",
")",
"ins_c",
",",
"ins_fw",
",",
"ins_fs",
"=",
"color_scheme",
"[",
"'instance'",
"]",
"instance_color",
"=",
"ins_c",
"instance_font_weight",
"=",
"give_font_weight",
"(",
"ins_fw",
")",
"instance_font_style",
"=",
"give_font_style",
"(",
"ins_fs",
")",
"font_token",
"=",
"font_font_style",
"+",
"' '",
"+",
"font_font_weight",
"+",
"' '",
"+",
"font_color",
"definition_token",
"=",
"(",
"definition_font_style",
"+",
"' '",
"+",
"definition_font_weight",
"+",
"' '",
"+",
"definition_color",
")",
"builtin_token",
"=",
"(",
"builtin_font_style",
"+",
"' '",
"+",
"builtin_font_weight",
"+",
"' '",
"+",
"builtin_color",
")",
"instance_token",
"=",
"(",
"instance_font_style",
"+",
"' '",
"+",
"instance_font_weight",
"+",
"' '",
"+",
"instance_color",
")",
"keyword_token",
"=",
"(",
"keyword_font_style",
"+",
"' '",
"+",
"keyword_font_weight",
"+",
"' '",
"+",
"keyword_color",
")",
"comment_token",
"=",
"(",
"comment_font_style",
"+",
"' '",
"+",
"comment_font_weight",
"+",
"' '",
"+",
"comment_color",
")",
"string_token",
"=",
"(",
"string_font_style",
"+",
"' '",
"+",
"string_font_weight",
"+",
"' '",
"+",
"string_color",
")",
"number_token",
"=",
"(",
"number_font_style",
"+",
"' '",
"+",
"number_font_weight",
"+",
"' '",
"+",
"number_color",
")",
"syntax_style_dic",
"=",
"{",
"Name",
":",
"font_token",
".",
"strip",
"(",
")",
",",
"Name",
".",
"Class",
":",
"definition_token",
".",
"strip",
"(",
")",
",",
"Name",
".",
"Function",
":",
"definition_token",
".",
"strip",
"(",
")",
",",
"Name",
".",
"Builtin",
":",
"builtin_token",
".",
"strip",
"(",
")",
",",
"Name",
".",
"Builtin",
".",
"Pseudo",
":",
"instance_token",
".",
"strip",
"(",
")",
",",
"Keyword",
":",
"keyword_token",
".",
"strip",
"(",
")",
",",
"Keyword",
".",
"Type",
":",
"builtin_token",
".",
"strip",
"(",
")",
",",
"Comment",
":",
"comment_token",
".",
"strip",
"(",
")",
",",
"String",
":",
"string_token",
".",
"strip",
"(",
")",
",",
"Number",
":",
"number_token",
".",
"strip",
"(",
")",
",",
"Punctuation",
":",
"font_token",
".",
"strip",
"(",
")",
",",
"Operator",
".",
"Word",
":",
"keyword_token",
".",
"strip",
"(",
")",
"}",
"return",
"syntax_style_dic"
] | Create a dictionary that saves the given color scheme as a
Pygments style. | [
"Create",
"a",
"dictionary",
"that",
"saves",
"the",
"given",
"color",
"scheme",
"as",
"a",
"Pygments",
"style",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/utils/style.py#L83-L165 | train |
spyder-ide/spyder | spyder/utils/misc.py | __remove_pyc_pyo | def __remove_pyc_pyo(fname):
"""Eventually remove .pyc and .pyo files associated to a Python script"""
if osp.splitext(fname)[1] == '.py':
for ending in ('c', 'o'):
if osp.exists(fname+ending):
os.remove(fname+ending) | python | def __remove_pyc_pyo(fname):
"""Eventually remove .pyc and .pyo files associated to a Python script"""
if osp.splitext(fname)[1] == '.py':
for ending in ('c', 'o'):
if osp.exists(fname+ending):
os.remove(fname+ending) | [
"def",
"__remove_pyc_pyo",
"(",
"fname",
")",
":",
"if",
"osp",
".",
"splitext",
"(",
"fname",
")",
"[",
"1",
"]",
"==",
"'.py'",
":",
"for",
"ending",
"in",
"(",
"'c'",
",",
"'o'",
")",
":",
"if",
"osp",
".",
"exists",
"(",
"fname",
"+",
"ending",
")",
":",
"os",
".",
"remove",
"(",
"fname",
"+",
"ending",
")"
] | Eventually remove .pyc and .pyo files associated to a Python script | [
"Eventually",
"remove",
".",
"pyc",
"and",
".",
"pyo",
"files",
"associated",
"to",
"a",
"Python",
"script"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/misc.py#L24-L29 | train |
spyder-ide/spyder | spyder/utils/misc.py | move_file | def move_file(source, dest):
"""
Move file from *source* to *dest*
If file is a Python script, also rename .pyc and .pyo files if any
"""
import shutil
shutil.copy(source, dest)
remove_file(source) | python | def move_file(source, dest):
"""
Move file from *source* to *dest*
If file is a Python script, also rename .pyc and .pyo files if any
"""
import shutil
shutil.copy(source, dest)
remove_file(source) | [
"def",
"move_file",
"(",
"source",
",",
"dest",
")",
":",
"import",
"shutil",
"shutil",
".",
"copy",
"(",
"source",
",",
"dest",
")",
"remove_file",
"(",
"source",
")"
] | Move file from *source* to *dest*
If file is a Python script, also rename .pyc and .pyo files if any | [
"Move",
"file",
"from",
"*",
"source",
"*",
"to",
"*",
"dest",
"*",
"If",
"file",
"is",
"a",
"Python",
"script",
"also",
"rename",
".",
"pyc",
"and",
".",
"pyo",
"files",
"if",
"any"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/misc.py#L50-L57 | train |
spyder-ide/spyder | spyder/utils/misc.py | onerror | def onerror(function, path, excinfo):
"""Error handler for `shutil.rmtree`.
If the error is due to an access error (read-only file), it
attempts to add write permission and then retries.
If the error is for another reason, it re-raises the error.
Usage: `shutil.rmtree(path, onerror=onerror)"""
if not os.access(path, os.W_OK):
# Is the error an access error?
os.chmod(path, stat.S_IWUSR)
function(path)
else:
raise | python | def onerror(function, path, excinfo):
"""Error handler for `shutil.rmtree`.
If the error is due to an access error (read-only file), it
attempts to add write permission and then retries.
If the error is for another reason, it re-raises the error.
Usage: `shutil.rmtree(path, onerror=onerror)"""
if not os.access(path, os.W_OK):
# Is the error an access error?
os.chmod(path, stat.S_IWUSR)
function(path)
else:
raise | [
"def",
"onerror",
"(",
"function",
",",
"path",
",",
"excinfo",
")",
":",
"if",
"not",
"os",
".",
"access",
"(",
"path",
",",
"os",
".",
"W_OK",
")",
":",
"# Is the error an access error?\r",
"os",
".",
"chmod",
"(",
"path",
",",
"stat",
".",
"S_IWUSR",
")",
"function",
"(",
"path",
")",
"else",
":",
"raise"
] | Error handler for `shutil.rmtree`.
If the error is due to an access error (read-only file), it
attempts to add write permission and then retries.
If the error is for another reason, it re-raises the error.
Usage: `shutil.rmtree(path, onerror=onerror) | [
"Error",
"handler",
"for",
"shutil",
".",
"rmtree",
".",
"If",
"the",
"error",
"is",
"due",
"to",
"an",
"access",
"error",
"(",
"read",
"-",
"only",
"file",
")",
"it",
"attempts",
"to",
"add",
"write",
"permission",
"and",
"then",
"retries",
".",
"If",
"the",
"error",
"is",
"for",
"another",
"reason",
"it",
"re",
"-",
"raises",
"the",
"error",
".",
"Usage",
":",
"shutil",
".",
"rmtree",
"(",
"path",
"onerror",
"=",
"onerror",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/misc.py#L60-L73 | train |
spyder-ide/spyder | spyder/utils/misc.py | select_port | def select_port(default_port=20128):
"""Find and return a non used port"""
import socket
while True:
try:
sock = socket.socket(socket.AF_INET,
socket.SOCK_STREAM,
socket.IPPROTO_TCP)
# sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind( ("127.0.0.1", default_port) )
except socket.error as _msg: # analysis:ignore
default_port += 1
else:
break
finally:
sock.close()
sock = None
return default_port | python | def select_port(default_port=20128):
"""Find and return a non used port"""
import socket
while True:
try:
sock = socket.socket(socket.AF_INET,
socket.SOCK_STREAM,
socket.IPPROTO_TCP)
# sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind( ("127.0.0.1", default_port) )
except socket.error as _msg: # analysis:ignore
default_port += 1
else:
break
finally:
sock.close()
sock = None
return default_port | [
"def",
"select_port",
"(",
"default_port",
"=",
"20128",
")",
":",
"import",
"socket",
"while",
"True",
":",
"try",
":",
"sock",
"=",
"socket",
".",
"socket",
"(",
"socket",
".",
"AF_INET",
",",
"socket",
".",
"SOCK_STREAM",
",",
"socket",
".",
"IPPROTO_TCP",
")",
"# sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)\r",
"sock",
".",
"bind",
"(",
"(",
"\"127.0.0.1\"",
",",
"default_port",
")",
")",
"except",
"socket",
".",
"error",
"as",
"_msg",
":",
"# analysis:ignore\r",
"default_port",
"+=",
"1",
"else",
":",
"break",
"finally",
":",
"sock",
".",
"close",
"(",
")",
"sock",
"=",
"None",
"return",
"default_port"
] | Find and return a non used port | [
"Find",
"and",
"return",
"a",
"non",
"used",
"port"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/misc.py#L76-L93 | train |
spyder-ide/spyder | spyder/utils/misc.py | count_lines | def count_lines(path, extensions=None, excluded_dirnames=None):
"""Return number of source code lines for all filenames in subdirectories
of *path* with names ending with *extensions*
Directory names *excluded_dirnames* will be ignored"""
if extensions is None:
extensions = ['.py', '.pyw', '.ipy', '.enaml', '.c', '.h', '.cpp',
'.hpp', '.inc', '.', '.hh', '.hxx', '.cc', '.cxx',
'.cl', '.f', '.for', '.f77', '.f90', '.f95', '.f2k',
'.f03', '.f08']
if excluded_dirnames is None:
excluded_dirnames = ['build', 'dist', '.hg', '.svn']
def get_filelines(path):
dfiles, dlines = 0, 0
if osp.splitext(path)[1] in extensions:
dfiles = 1
with open(path, 'rb') as textfile:
dlines = len(textfile.read().strip().splitlines())
return dfiles, dlines
lines = 0
files = 0
if osp.isdir(path):
for dirpath, dirnames, filenames in os.walk(path):
for d in dirnames[:]:
if d in excluded_dirnames:
dirnames.remove(d)
if excluded_dirnames is None or \
osp.dirname(dirpath) not in excluded_dirnames:
for fname in filenames:
dfiles, dlines = get_filelines(osp.join(dirpath, fname))
files += dfiles
lines += dlines
else:
dfiles, dlines = get_filelines(path)
files += dfiles
lines += dlines
return files, lines | python | def count_lines(path, extensions=None, excluded_dirnames=None):
"""Return number of source code lines for all filenames in subdirectories
of *path* with names ending with *extensions*
Directory names *excluded_dirnames* will be ignored"""
if extensions is None:
extensions = ['.py', '.pyw', '.ipy', '.enaml', '.c', '.h', '.cpp',
'.hpp', '.inc', '.', '.hh', '.hxx', '.cc', '.cxx',
'.cl', '.f', '.for', '.f77', '.f90', '.f95', '.f2k',
'.f03', '.f08']
if excluded_dirnames is None:
excluded_dirnames = ['build', 'dist', '.hg', '.svn']
def get_filelines(path):
dfiles, dlines = 0, 0
if osp.splitext(path)[1] in extensions:
dfiles = 1
with open(path, 'rb') as textfile:
dlines = len(textfile.read().strip().splitlines())
return dfiles, dlines
lines = 0
files = 0
if osp.isdir(path):
for dirpath, dirnames, filenames in os.walk(path):
for d in dirnames[:]:
if d in excluded_dirnames:
dirnames.remove(d)
if excluded_dirnames is None or \
osp.dirname(dirpath) not in excluded_dirnames:
for fname in filenames:
dfiles, dlines = get_filelines(osp.join(dirpath, fname))
files += dfiles
lines += dlines
else:
dfiles, dlines = get_filelines(path)
files += dfiles
lines += dlines
return files, lines | [
"def",
"count_lines",
"(",
"path",
",",
"extensions",
"=",
"None",
",",
"excluded_dirnames",
"=",
"None",
")",
":",
"if",
"extensions",
"is",
"None",
":",
"extensions",
"=",
"[",
"'.py'",
",",
"'.pyw'",
",",
"'.ipy'",
",",
"'.enaml'",
",",
"'.c'",
",",
"'.h'",
",",
"'.cpp'",
",",
"'.hpp'",
",",
"'.inc'",
",",
"'.'",
",",
"'.hh'",
",",
"'.hxx'",
",",
"'.cc'",
",",
"'.cxx'",
",",
"'.cl'",
",",
"'.f'",
",",
"'.for'",
",",
"'.f77'",
",",
"'.f90'",
",",
"'.f95'",
",",
"'.f2k'",
",",
"'.f03'",
",",
"'.f08'",
"]",
"if",
"excluded_dirnames",
"is",
"None",
":",
"excluded_dirnames",
"=",
"[",
"'build'",
",",
"'dist'",
",",
"'.hg'",
",",
"'.svn'",
"]",
"def",
"get_filelines",
"(",
"path",
")",
":",
"dfiles",
",",
"dlines",
"=",
"0",
",",
"0",
"if",
"osp",
".",
"splitext",
"(",
"path",
")",
"[",
"1",
"]",
"in",
"extensions",
":",
"dfiles",
"=",
"1",
"with",
"open",
"(",
"path",
",",
"'rb'",
")",
"as",
"textfile",
":",
"dlines",
"=",
"len",
"(",
"textfile",
".",
"read",
"(",
")",
".",
"strip",
"(",
")",
".",
"splitlines",
"(",
")",
")",
"return",
"dfiles",
",",
"dlines",
"lines",
"=",
"0",
"files",
"=",
"0",
"if",
"osp",
".",
"isdir",
"(",
"path",
")",
":",
"for",
"dirpath",
",",
"dirnames",
",",
"filenames",
"in",
"os",
".",
"walk",
"(",
"path",
")",
":",
"for",
"d",
"in",
"dirnames",
"[",
":",
"]",
":",
"if",
"d",
"in",
"excluded_dirnames",
":",
"dirnames",
".",
"remove",
"(",
"d",
")",
"if",
"excluded_dirnames",
"is",
"None",
"or",
"osp",
".",
"dirname",
"(",
"dirpath",
")",
"not",
"in",
"excluded_dirnames",
":",
"for",
"fname",
"in",
"filenames",
":",
"dfiles",
",",
"dlines",
"=",
"get_filelines",
"(",
"osp",
".",
"join",
"(",
"dirpath",
",",
"fname",
")",
")",
"files",
"+=",
"dfiles",
"lines",
"+=",
"dlines",
"else",
":",
"dfiles",
",",
"dlines",
"=",
"get_filelines",
"(",
"path",
")",
"files",
"+=",
"dfiles",
"lines",
"+=",
"dlines",
"return",
"files",
",",
"lines"
] | Return number of source code lines for all filenames in subdirectories
of *path* with names ending with *extensions*
Directory names *excluded_dirnames* will be ignored | [
"Return",
"number",
"of",
"source",
"code",
"lines",
"for",
"all",
"filenames",
"in",
"subdirectories",
"of",
"*",
"path",
"*",
"with",
"names",
"ending",
"with",
"*",
"extensions",
"*",
"Directory",
"names",
"*",
"excluded_dirnames",
"*",
"will",
"be",
"ignored"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/misc.py#L96-L131 | train |
spyder-ide/spyder | spyder/utils/misc.py | remove_backslashes | def remove_backslashes(path):
"""Remove backslashes in *path*
For Windows platforms only.
Returns the path unchanged on other platforms.
This is especially useful when formatting path strings on
Windows platforms for which folder paths may contain backslashes
and provoke unicode decoding errors in Python 3 (or in Python 2
when future 'unicode_literals' symbol has been imported)."""
if os.name == 'nt':
# Removing trailing single backslash
if path.endswith('\\') and not path.endswith('\\\\'):
path = path[:-1]
# Replacing backslashes by slashes
path = path.replace('\\', '/')
path = path.replace('/\'', '\\\'')
return path | python | def remove_backslashes(path):
"""Remove backslashes in *path*
For Windows platforms only.
Returns the path unchanged on other platforms.
This is especially useful when formatting path strings on
Windows platforms for which folder paths may contain backslashes
and provoke unicode decoding errors in Python 3 (or in Python 2
when future 'unicode_literals' symbol has been imported)."""
if os.name == 'nt':
# Removing trailing single backslash
if path.endswith('\\') and not path.endswith('\\\\'):
path = path[:-1]
# Replacing backslashes by slashes
path = path.replace('\\', '/')
path = path.replace('/\'', '\\\'')
return path | [
"def",
"remove_backslashes",
"(",
"path",
")",
":",
"if",
"os",
".",
"name",
"==",
"'nt'",
":",
"# Removing trailing single backslash\r",
"if",
"path",
".",
"endswith",
"(",
"'\\\\'",
")",
"and",
"not",
"path",
".",
"endswith",
"(",
"'\\\\\\\\'",
")",
":",
"path",
"=",
"path",
"[",
":",
"-",
"1",
"]",
"# Replacing backslashes by slashes\r",
"path",
"=",
"path",
".",
"replace",
"(",
"'\\\\'",
",",
"'/'",
")",
"path",
"=",
"path",
".",
"replace",
"(",
"'/\\''",
",",
"'\\\\\\''",
")",
"return",
"path"
] | Remove backslashes in *path*
For Windows platforms only.
Returns the path unchanged on other platforms.
This is especially useful when formatting path strings on
Windows platforms for which folder paths may contain backslashes
and provoke unicode decoding errors in Python 3 (or in Python 2
when future 'unicode_literals' symbol has been imported). | [
"Remove",
"backslashes",
"in",
"*",
"path",
"*",
"For",
"Windows",
"platforms",
"only",
".",
"Returns",
"the",
"path",
"unchanged",
"on",
"other",
"platforms",
".",
"This",
"is",
"especially",
"useful",
"when",
"formatting",
"path",
"strings",
"on",
"Windows",
"platforms",
"for",
"which",
"folder",
"paths",
"may",
"contain",
"backslashes",
"and",
"provoke",
"unicode",
"decoding",
"errors",
"in",
"Python",
"3",
"(",
"or",
"in",
"Python",
"2",
"when",
"future",
"unicode_literals",
"symbol",
"has",
"been",
"imported",
")",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/misc.py#L134-L151 | train |
spyder-ide/spyder | spyder/utils/misc.py | monkeypatch_method | def monkeypatch_method(cls, patch_name):
# This function's code was inspired from the following thread:
# "[Python-Dev] Monkeypatching idioms -- elegant or ugly?"
# by Robert Brewer <fumanchu at aminus.org>
# (Tue Jan 15 19:13:25 CET 2008)
"""
Add the decorated method to the given class; replace as needed.
If the named method already exists on the given class, it will
be replaced, and a reference to the old method is created as
cls._old<patch_name><name>. If the "_old_<patch_name>_<name>" attribute
already exists, KeyError is raised.
"""
def decorator(func):
fname = func.__name__
old_func = getattr(cls, fname, None)
if old_func is not None:
# Add the old func to a list of old funcs.
old_ref = "_old_%s_%s" % (patch_name, fname)
old_attr = getattr(cls, old_ref, None)
if old_attr is None:
setattr(cls, old_ref, old_func)
else:
raise KeyError("%s.%s already exists."
% (cls.__name__, old_ref))
setattr(cls, fname, func)
return func
return decorator | python | def monkeypatch_method(cls, patch_name):
# This function's code was inspired from the following thread:
# "[Python-Dev] Monkeypatching idioms -- elegant or ugly?"
# by Robert Brewer <fumanchu at aminus.org>
# (Tue Jan 15 19:13:25 CET 2008)
"""
Add the decorated method to the given class; replace as needed.
If the named method already exists on the given class, it will
be replaced, and a reference to the old method is created as
cls._old<patch_name><name>. If the "_old_<patch_name>_<name>" attribute
already exists, KeyError is raised.
"""
def decorator(func):
fname = func.__name__
old_func = getattr(cls, fname, None)
if old_func is not None:
# Add the old func to a list of old funcs.
old_ref = "_old_%s_%s" % (patch_name, fname)
old_attr = getattr(cls, old_ref, None)
if old_attr is None:
setattr(cls, old_ref, old_func)
else:
raise KeyError("%s.%s already exists."
% (cls.__name__, old_ref))
setattr(cls, fname, func)
return func
return decorator | [
"def",
"monkeypatch_method",
"(",
"cls",
",",
"patch_name",
")",
":",
"# This function's code was inspired from the following thread:\r",
"# \"[Python-Dev] Monkeypatching idioms -- elegant or ugly?\"\r",
"# by Robert Brewer <fumanchu at aminus.org>\r",
"# (Tue Jan 15 19:13:25 CET 2008)\r",
"def",
"decorator",
"(",
"func",
")",
":",
"fname",
"=",
"func",
".",
"__name__",
"old_func",
"=",
"getattr",
"(",
"cls",
",",
"fname",
",",
"None",
")",
"if",
"old_func",
"is",
"not",
"None",
":",
"# Add the old func to a list of old funcs.\r",
"old_ref",
"=",
"\"_old_%s_%s\"",
"%",
"(",
"patch_name",
",",
"fname",
")",
"old_attr",
"=",
"getattr",
"(",
"cls",
",",
"old_ref",
",",
"None",
")",
"if",
"old_attr",
"is",
"None",
":",
"setattr",
"(",
"cls",
",",
"old_ref",
",",
"old_func",
")",
"else",
":",
"raise",
"KeyError",
"(",
"\"%s.%s already exists.\"",
"%",
"(",
"cls",
".",
"__name__",
",",
"old_ref",
")",
")",
"setattr",
"(",
"cls",
",",
"fname",
",",
"func",
")",
"return",
"func",
"return",
"decorator"
] | Add the decorated method to the given class; replace as needed.
If the named method already exists on the given class, it will
be replaced, and a reference to the old method is created as
cls._old<patch_name><name>. If the "_old_<patch_name>_<name>" attribute
already exists, KeyError is raised. | [
"Add",
"the",
"decorated",
"method",
"to",
"the",
"given",
"class",
";",
"replace",
"as",
"needed",
".",
"If",
"the",
"named",
"method",
"already",
"exists",
"on",
"the",
"given",
"class",
"it",
"will",
"be",
"replaced",
"and",
"a",
"reference",
"to",
"the",
"old",
"method",
"is",
"created",
"as",
"cls",
".",
"_old<patch_name",
">",
"<name",
">",
".",
"If",
"the",
"_old_<patch_name",
">",
"_<name",
">",
"attribute",
"already",
"exists",
"KeyError",
"is",
"raised",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/misc.py#L169-L197 | train |
spyder-ide/spyder | spyder/utils/misc.py | get_common_path | def get_common_path(pathlist):
"""Return common path for all paths in pathlist"""
common = osp.normpath(osp.commonprefix(pathlist))
if len(common) > 1:
if not osp.isdir(common):
return abspardir(common)
else:
for path in pathlist:
if not osp.isdir(osp.join(common, path[len(common)+1:])):
# `common` is not the real common prefix
return abspardir(common)
else:
return osp.abspath(common) | python | def get_common_path(pathlist):
"""Return common path for all paths in pathlist"""
common = osp.normpath(osp.commonprefix(pathlist))
if len(common) > 1:
if not osp.isdir(common):
return abspardir(common)
else:
for path in pathlist:
if not osp.isdir(osp.join(common, path[len(common)+1:])):
# `common` is not the real common prefix
return abspardir(common)
else:
return osp.abspath(common) | [
"def",
"get_common_path",
"(",
"pathlist",
")",
":",
"common",
"=",
"osp",
".",
"normpath",
"(",
"osp",
".",
"commonprefix",
"(",
"pathlist",
")",
")",
"if",
"len",
"(",
"common",
")",
">",
"1",
":",
"if",
"not",
"osp",
".",
"isdir",
"(",
"common",
")",
":",
"return",
"abspardir",
"(",
"common",
")",
"else",
":",
"for",
"path",
"in",
"pathlist",
":",
"if",
"not",
"osp",
".",
"isdir",
"(",
"osp",
".",
"join",
"(",
"common",
",",
"path",
"[",
"len",
"(",
"common",
")",
"+",
"1",
":",
"]",
")",
")",
":",
"# `common` is not the real common prefix\r",
"return",
"abspardir",
"(",
"common",
")",
"else",
":",
"return",
"osp",
".",
"abspath",
"(",
"common",
")"
] | Return common path for all paths in pathlist | [
"Return",
"common",
"path",
"for",
"all",
"paths",
"in",
"pathlist"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/misc.py#L210-L222 | train |
spyder-ide/spyder | spyder/utils/misc.py | memoize | def memoize(obj):
"""
Memoize objects to trade memory for execution speed
Use a limited size cache to store the value, which takes into account
The calling args and kwargs
See https://wiki.python.org/moin/PythonDecoratorLibrary#Memoize
"""
cache = obj.cache = {}
@functools.wraps(obj)
def memoizer(*args, **kwargs):
key = str(args) + str(kwargs)
if key not in cache:
cache[key] = obj(*args, **kwargs)
# only keep the most recent 100 entries
if len(cache) > 100:
cache.popitem(last=False)
return cache[key]
return memoizer | python | def memoize(obj):
"""
Memoize objects to trade memory for execution speed
Use a limited size cache to store the value, which takes into account
The calling args and kwargs
See https://wiki.python.org/moin/PythonDecoratorLibrary#Memoize
"""
cache = obj.cache = {}
@functools.wraps(obj)
def memoizer(*args, **kwargs):
key = str(args) + str(kwargs)
if key not in cache:
cache[key] = obj(*args, **kwargs)
# only keep the most recent 100 entries
if len(cache) > 100:
cache.popitem(last=False)
return cache[key]
return memoizer | [
"def",
"memoize",
"(",
"obj",
")",
":",
"cache",
"=",
"obj",
".",
"cache",
"=",
"{",
"}",
"@",
"functools",
".",
"wraps",
"(",
"obj",
")",
"def",
"memoizer",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"key",
"=",
"str",
"(",
"args",
")",
"+",
"str",
"(",
"kwargs",
")",
"if",
"key",
"not",
"in",
"cache",
":",
"cache",
"[",
"key",
"]",
"=",
"obj",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"# only keep the most recent 100 entries\r",
"if",
"len",
"(",
"cache",
")",
">",
"100",
":",
"cache",
".",
"popitem",
"(",
"last",
"=",
"False",
")",
"return",
"cache",
"[",
"key",
"]",
"return",
"memoizer"
] | Memoize objects to trade memory for execution speed
Use a limited size cache to store the value, which takes into account
The calling args and kwargs
See https://wiki.python.org/moin/PythonDecoratorLibrary#Memoize | [
"Memoize",
"objects",
"to",
"trade",
"memory",
"for",
"execution",
"speed",
"Use",
"a",
"limited",
"size",
"cache",
"to",
"store",
"the",
"value",
"which",
"takes",
"into",
"account",
"The",
"calling",
"args",
"and",
"kwargs",
"See",
"https",
":",
"//",
"wiki",
".",
"python",
".",
"org",
"/",
"moin",
"/",
"PythonDecoratorLibrary#Memoize"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/misc.py#L252-L272 | train |
spyder-ide/spyder | spyder/utils/misc.py | regexp_error_msg | def regexp_error_msg(pattern):
"""
Return None if the pattern is a valid regular expression or
a string describing why the pattern is invalid.
"""
try:
re.compile(pattern)
except re.error as e:
return str(e)
return None | python | def regexp_error_msg(pattern):
"""
Return None if the pattern is a valid regular expression or
a string describing why the pattern is invalid.
"""
try:
re.compile(pattern)
except re.error as e:
return str(e)
return None | [
"def",
"regexp_error_msg",
"(",
"pattern",
")",
":",
"try",
":",
"re",
".",
"compile",
"(",
"pattern",
")",
"except",
"re",
".",
"error",
"as",
"e",
":",
"return",
"str",
"(",
"e",
")",
"return",
"None"
] | Return None if the pattern is a valid regular expression or
a string describing why the pattern is invalid. | [
"Return",
"None",
"if",
"the",
"pattern",
"is",
"a",
"valid",
"regular",
"expression",
"or",
"a",
"string",
"describing",
"why",
"the",
"pattern",
"is",
"invalid",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/misc.py#L289-L298 | train |
spyder-ide/spyder | spyder/plugins/editor/utils/folding.py | FoldScope.get_range | def get_range(self, ignore_blank_lines=True):
"""
Gets the fold region range (start and end line).
.. note:: Start line do no encompass the trigger line.
:param ignore_blank_lines: True to ignore blank lines at the end of the
scope (the method will rewind to find that last meaningful block
that is part of the fold scope).
:returns: tuple(int, int)
"""
ref_lvl = self.trigger_level
first_line = self._trigger.blockNumber()
block = self._trigger.next()
last_line = block.blockNumber()
lvl = self.scope_level
if ref_lvl == lvl: # for zone set programmatically such as imports
# in pyqode.python
ref_lvl -= 1
while (block.isValid() and
TextBlockHelper.get_fold_lvl(block) > ref_lvl):
last_line = block.blockNumber()
block = block.next()
if ignore_blank_lines and last_line:
block = block.document().findBlockByNumber(last_line)
while block.blockNumber() and block.text().strip() == '':
block = block.previous()
last_line = block.blockNumber()
return first_line, last_line | python | def get_range(self, ignore_blank_lines=True):
"""
Gets the fold region range (start and end line).
.. note:: Start line do no encompass the trigger line.
:param ignore_blank_lines: True to ignore blank lines at the end of the
scope (the method will rewind to find that last meaningful block
that is part of the fold scope).
:returns: tuple(int, int)
"""
ref_lvl = self.trigger_level
first_line = self._trigger.blockNumber()
block = self._trigger.next()
last_line = block.blockNumber()
lvl = self.scope_level
if ref_lvl == lvl: # for zone set programmatically such as imports
# in pyqode.python
ref_lvl -= 1
while (block.isValid() and
TextBlockHelper.get_fold_lvl(block) > ref_lvl):
last_line = block.blockNumber()
block = block.next()
if ignore_blank_lines and last_line:
block = block.document().findBlockByNumber(last_line)
while block.blockNumber() and block.text().strip() == '':
block = block.previous()
last_line = block.blockNumber()
return first_line, last_line | [
"def",
"get_range",
"(",
"self",
",",
"ignore_blank_lines",
"=",
"True",
")",
":",
"ref_lvl",
"=",
"self",
".",
"trigger_level",
"first_line",
"=",
"self",
".",
"_trigger",
".",
"blockNumber",
"(",
")",
"block",
"=",
"self",
".",
"_trigger",
".",
"next",
"(",
")",
"last_line",
"=",
"block",
".",
"blockNumber",
"(",
")",
"lvl",
"=",
"self",
".",
"scope_level",
"if",
"ref_lvl",
"==",
"lvl",
":",
"# for zone set programmatically such as imports",
"# in pyqode.python",
"ref_lvl",
"-=",
"1",
"while",
"(",
"block",
".",
"isValid",
"(",
")",
"and",
"TextBlockHelper",
".",
"get_fold_lvl",
"(",
"block",
")",
">",
"ref_lvl",
")",
":",
"last_line",
"=",
"block",
".",
"blockNumber",
"(",
")",
"block",
"=",
"block",
".",
"next",
"(",
")",
"if",
"ignore_blank_lines",
"and",
"last_line",
":",
"block",
"=",
"block",
".",
"document",
"(",
")",
".",
"findBlockByNumber",
"(",
"last_line",
")",
"while",
"block",
".",
"blockNumber",
"(",
")",
"and",
"block",
".",
"text",
"(",
")",
".",
"strip",
"(",
")",
"==",
"''",
":",
"block",
"=",
"block",
".",
"previous",
"(",
")",
"last_line",
"=",
"block",
".",
"blockNumber",
"(",
")",
"return",
"first_line",
",",
"last_line"
] | Gets the fold region range (start and end line).
.. note:: Start line do no encompass the trigger line.
:param ignore_blank_lines: True to ignore blank lines at the end of the
scope (the method will rewind to find that last meaningful block
that is part of the fold scope).
:returns: tuple(int, int) | [
"Gets",
"the",
"fold",
"region",
"range",
"(",
"start",
"and",
"end",
"line",
")",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/utils/folding.py#L71-L100 | train |
spyder-ide/spyder | spyder/plugins/editor/utils/folding.py | FoldScope.fold | def fold(self):
"""Folds the region."""
start, end = self.get_range()
TextBlockHelper.set_collapsed(self._trigger, True)
block = self._trigger.next()
while block.blockNumber() <= end and block.isValid():
block.setVisible(False)
block = block.next() | python | def fold(self):
"""Folds the region."""
start, end = self.get_range()
TextBlockHelper.set_collapsed(self._trigger, True)
block = self._trigger.next()
while block.blockNumber() <= end and block.isValid():
block.setVisible(False)
block = block.next() | [
"def",
"fold",
"(",
"self",
")",
":",
"start",
",",
"end",
"=",
"self",
".",
"get_range",
"(",
")",
"TextBlockHelper",
".",
"set_collapsed",
"(",
"self",
".",
"_trigger",
",",
"True",
")",
"block",
"=",
"self",
".",
"_trigger",
".",
"next",
"(",
")",
"while",
"block",
".",
"blockNumber",
"(",
")",
"<=",
"end",
"and",
"block",
".",
"isValid",
"(",
")",
":",
"block",
".",
"setVisible",
"(",
"False",
")",
"block",
"=",
"block",
".",
"next",
"(",
")"
] | Folds the region. | [
"Folds",
"the",
"region",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/utils/folding.py#L102-L109 | train |
spyder-ide/spyder | spyder/plugins/editor/utils/folding.py | FoldScope.unfold | def unfold(self):
"""Unfolds the region."""
# set all direct child blocks which are not triggers to be visible
self._trigger.setVisible(True)
TextBlockHelper.set_collapsed(self._trigger, False)
for block in self.blocks(ignore_blank_lines=False):
block.setVisible(True)
if TextBlockHelper.is_fold_trigger(block):
TextBlockHelper.set_collapsed(block, False) | python | def unfold(self):
"""Unfolds the region."""
# set all direct child blocks which are not triggers to be visible
self._trigger.setVisible(True)
TextBlockHelper.set_collapsed(self._trigger, False)
for block in self.blocks(ignore_blank_lines=False):
block.setVisible(True)
if TextBlockHelper.is_fold_trigger(block):
TextBlockHelper.set_collapsed(block, False) | [
"def",
"unfold",
"(",
"self",
")",
":",
"# set all direct child blocks which are not triggers to be visible",
"self",
".",
"_trigger",
".",
"setVisible",
"(",
"True",
")",
"TextBlockHelper",
".",
"set_collapsed",
"(",
"self",
".",
"_trigger",
",",
"False",
")",
"for",
"block",
"in",
"self",
".",
"blocks",
"(",
"ignore_blank_lines",
"=",
"False",
")",
":",
"block",
".",
"setVisible",
"(",
"True",
")",
"if",
"TextBlockHelper",
".",
"is_fold_trigger",
"(",
"block",
")",
":",
"TextBlockHelper",
".",
"set_collapsed",
"(",
"block",
",",
"False",
")"
] | Unfolds the region. | [
"Unfolds",
"the",
"region",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/utils/folding.py#L111-L119 | train |
spyder-ide/spyder | spyder/plugins/editor/utils/folding.py | FoldScope.blocks | def blocks(self, ignore_blank_lines=True):
"""
This generator generates the list of blocks directly under the fold
region. This list does not contain blocks from child regions.
:param ignore_blank_lines: True to ignore last blank lines.
"""
start, end = self.get_range(ignore_blank_lines=ignore_blank_lines)
block = self._trigger.next()
while block.blockNumber() <= end and block.isValid():
yield block
block = block.next() | python | def blocks(self, ignore_blank_lines=True):
"""
This generator generates the list of blocks directly under the fold
region. This list does not contain blocks from child regions.
:param ignore_blank_lines: True to ignore last blank lines.
"""
start, end = self.get_range(ignore_blank_lines=ignore_blank_lines)
block = self._trigger.next()
while block.blockNumber() <= end and block.isValid():
yield block
block = block.next() | [
"def",
"blocks",
"(",
"self",
",",
"ignore_blank_lines",
"=",
"True",
")",
":",
"start",
",",
"end",
"=",
"self",
".",
"get_range",
"(",
"ignore_blank_lines",
"=",
"ignore_blank_lines",
")",
"block",
"=",
"self",
".",
"_trigger",
".",
"next",
"(",
")",
"while",
"block",
".",
"blockNumber",
"(",
")",
"<=",
"end",
"and",
"block",
".",
"isValid",
"(",
")",
":",
"yield",
"block",
"block",
"=",
"block",
".",
"next",
"(",
")"
] | This generator generates the list of blocks directly under the fold
region. This list does not contain blocks from child regions.
:param ignore_blank_lines: True to ignore last blank lines. | [
"This",
"generator",
"generates",
"the",
"list",
"of",
"blocks",
"directly",
"under",
"the",
"fold",
"region",
".",
"This",
"list",
"does",
"not",
"contain",
"blocks",
"from",
"child",
"regions",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/utils/folding.py#L121-L132 | train |
spyder-ide/spyder | spyder/plugins/editor/utils/folding.py | FoldScope.child_regions | def child_regions(self):
"""This generator generates the list of direct child regions."""
start, end = self.get_range()
block = self._trigger.next()
ref_lvl = self.scope_level
while block.blockNumber() <= end and block.isValid():
lvl = TextBlockHelper.get_fold_lvl(block)
trigger = TextBlockHelper.is_fold_trigger(block)
if lvl == ref_lvl and trigger:
yield FoldScope(block)
block = block.next() | python | def child_regions(self):
"""This generator generates the list of direct child regions."""
start, end = self.get_range()
block = self._trigger.next()
ref_lvl = self.scope_level
while block.blockNumber() <= end and block.isValid():
lvl = TextBlockHelper.get_fold_lvl(block)
trigger = TextBlockHelper.is_fold_trigger(block)
if lvl == ref_lvl and trigger:
yield FoldScope(block)
block = block.next() | [
"def",
"child_regions",
"(",
"self",
")",
":",
"start",
",",
"end",
"=",
"self",
".",
"get_range",
"(",
")",
"block",
"=",
"self",
".",
"_trigger",
".",
"next",
"(",
")",
"ref_lvl",
"=",
"self",
".",
"scope_level",
"while",
"block",
".",
"blockNumber",
"(",
")",
"<=",
"end",
"and",
"block",
".",
"isValid",
"(",
")",
":",
"lvl",
"=",
"TextBlockHelper",
".",
"get_fold_lvl",
"(",
"block",
")",
"trigger",
"=",
"TextBlockHelper",
".",
"is_fold_trigger",
"(",
"block",
")",
"if",
"lvl",
"==",
"ref_lvl",
"and",
"trigger",
":",
"yield",
"FoldScope",
"(",
"block",
")",
"block",
"=",
"block",
".",
"next",
"(",
")"
] | This generator generates the list of direct child regions. | [
"This",
"generator",
"generates",
"the",
"list",
"of",
"direct",
"child",
"regions",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/utils/folding.py#L134-L144 | train |
spyder-ide/spyder | spyder/plugins/editor/utils/folding.py | FoldScope.parent | def parent(self):
"""
Return the parent scope.
:return: FoldScope or None
"""
if TextBlockHelper.get_fold_lvl(self._trigger) > 0 and \
self._trigger.blockNumber():
block = self._trigger.previous()
ref_lvl = self.trigger_level - 1
while (block.blockNumber() and
(not TextBlockHelper.is_fold_trigger(block) or
TextBlockHelper.get_fold_lvl(block) > ref_lvl)):
block = block.previous()
try:
return FoldScope(block)
except ValueError:
return None
return None | python | def parent(self):
"""
Return the parent scope.
:return: FoldScope or None
"""
if TextBlockHelper.get_fold_lvl(self._trigger) > 0 and \
self._trigger.blockNumber():
block = self._trigger.previous()
ref_lvl = self.trigger_level - 1
while (block.blockNumber() and
(not TextBlockHelper.is_fold_trigger(block) or
TextBlockHelper.get_fold_lvl(block) > ref_lvl)):
block = block.previous()
try:
return FoldScope(block)
except ValueError:
return None
return None | [
"def",
"parent",
"(",
"self",
")",
":",
"if",
"TextBlockHelper",
".",
"get_fold_lvl",
"(",
"self",
".",
"_trigger",
")",
">",
"0",
"and",
"self",
".",
"_trigger",
".",
"blockNumber",
"(",
")",
":",
"block",
"=",
"self",
".",
"_trigger",
".",
"previous",
"(",
")",
"ref_lvl",
"=",
"self",
".",
"trigger_level",
"-",
"1",
"while",
"(",
"block",
".",
"blockNumber",
"(",
")",
"and",
"(",
"not",
"TextBlockHelper",
".",
"is_fold_trigger",
"(",
"block",
")",
"or",
"TextBlockHelper",
".",
"get_fold_lvl",
"(",
"block",
")",
">",
"ref_lvl",
")",
")",
":",
"block",
"=",
"block",
".",
"previous",
"(",
")",
"try",
":",
"return",
"FoldScope",
"(",
"block",
")",
"except",
"ValueError",
":",
"return",
"None",
"return",
"None"
] | Return the parent scope.
:return: FoldScope or None | [
"Return",
"the",
"parent",
"scope",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/utils/folding.py#L146-L164 | train |
spyder-ide/spyder | spyder/plugins/editor/utils/folding.py | FoldScope.text | def text(self, max_lines=sys.maxsize):
"""
Get the scope text, with a possible maximum number of lines.
:param max_lines: limit the number of lines returned to a maximum.
:return: str
"""
ret_val = []
block = self._trigger.next()
_, end = self.get_range()
while (block.isValid() and block.blockNumber() <= end and
len(ret_val) < max_lines):
ret_val.append(block.text())
block = block.next()
return '\n'.join(ret_val) | python | def text(self, max_lines=sys.maxsize):
"""
Get the scope text, with a possible maximum number of lines.
:param max_lines: limit the number of lines returned to a maximum.
:return: str
"""
ret_val = []
block = self._trigger.next()
_, end = self.get_range()
while (block.isValid() and block.blockNumber() <= end and
len(ret_val) < max_lines):
ret_val.append(block.text())
block = block.next()
return '\n'.join(ret_val) | [
"def",
"text",
"(",
"self",
",",
"max_lines",
"=",
"sys",
".",
"maxsize",
")",
":",
"ret_val",
"=",
"[",
"]",
"block",
"=",
"self",
".",
"_trigger",
".",
"next",
"(",
")",
"_",
",",
"end",
"=",
"self",
".",
"get_range",
"(",
")",
"while",
"(",
"block",
".",
"isValid",
"(",
")",
"and",
"block",
".",
"blockNumber",
"(",
")",
"<=",
"end",
"and",
"len",
"(",
"ret_val",
")",
"<",
"max_lines",
")",
":",
"ret_val",
".",
"append",
"(",
"block",
".",
"text",
"(",
")",
")",
"block",
"=",
"block",
".",
"next",
"(",
")",
"return",
"'\\n'",
".",
"join",
"(",
"ret_val",
")"
] | Get the scope text, with a possible maximum number of lines.
:param max_lines: limit the number of lines returned to a maximum.
:return: str | [
"Get",
"the",
"scope",
"text",
"with",
"a",
"possible",
"maximum",
"number",
"of",
"lines",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/utils/folding.py#L166-L180 | train |
spyder-ide/spyder | spyder/plugins/editor/utils/folding.py | IndentFoldDetector.detect_fold_level | def detect_fold_level(self, prev_block, block):
"""
Detects fold level by looking at the block indentation.
:param prev_block: previous text block
:param block: current block to highlight
"""
text = block.text()
prev_lvl = TextBlockHelper().get_fold_lvl(prev_block)
# round down to previous indentation guide to ensure contiguous block
# fold level evolution.
indent_len = 0
if (prev_lvl and prev_block is not None and
not self.editor.is_comment(prev_block)):
# ignore commented lines (could have arbitary indentation)
prev_text = prev_block.text()
indent_len = (len(prev_text) - len(prev_text.lstrip())) // prev_lvl
if indent_len == 0:
indent_len = len(self.editor.indent_chars)
return (len(text) - len(text.lstrip())) // indent_len | python | def detect_fold_level(self, prev_block, block):
"""
Detects fold level by looking at the block indentation.
:param prev_block: previous text block
:param block: current block to highlight
"""
text = block.text()
prev_lvl = TextBlockHelper().get_fold_lvl(prev_block)
# round down to previous indentation guide to ensure contiguous block
# fold level evolution.
indent_len = 0
if (prev_lvl and prev_block is not None and
not self.editor.is_comment(prev_block)):
# ignore commented lines (could have arbitary indentation)
prev_text = prev_block.text()
indent_len = (len(prev_text) - len(prev_text.lstrip())) // prev_lvl
if indent_len == 0:
indent_len = len(self.editor.indent_chars)
return (len(text) - len(text.lstrip())) // indent_len | [
"def",
"detect_fold_level",
"(",
"self",
",",
"prev_block",
",",
"block",
")",
":",
"text",
"=",
"block",
".",
"text",
"(",
")",
"prev_lvl",
"=",
"TextBlockHelper",
"(",
")",
".",
"get_fold_lvl",
"(",
"prev_block",
")",
"# round down to previous indentation guide to ensure contiguous block",
"# fold level evolution.",
"indent_len",
"=",
"0",
"if",
"(",
"prev_lvl",
"and",
"prev_block",
"is",
"not",
"None",
"and",
"not",
"self",
".",
"editor",
".",
"is_comment",
"(",
"prev_block",
")",
")",
":",
"# ignore commented lines (could have arbitary indentation)",
"prev_text",
"=",
"prev_block",
".",
"text",
"(",
")",
"indent_len",
"=",
"(",
"len",
"(",
"prev_text",
")",
"-",
"len",
"(",
"prev_text",
".",
"lstrip",
"(",
")",
")",
")",
"//",
"prev_lvl",
"if",
"indent_len",
"==",
"0",
":",
"indent_len",
"=",
"len",
"(",
"self",
".",
"editor",
".",
"indent_chars",
")",
"return",
"(",
"len",
"(",
"text",
")",
"-",
"len",
"(",
"text",
".",
"lstrip",
"(",
")",
")",
")",
"//",
"indent_len"
] | Detects fold level by looking at the block indentation.
:param prev_block: previous text block
:param block: current block to highlight | [
"Detects",
"fold",
"level",
"by",
"looking",
"at",
"the",
"block",
"indentation",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/utils/folding.py#L216-L236 | train |
spyder-ide/spyder | spyder/plugins/editor/extensions/manager.py | EditorExtensionsManager.add | def add(self, extension):
"""
Add a extension to the editor.
:param extension: The extension instance to add.
"""
logger.debug('adding extension {}'.format(extension.name))
self._extensions[extension.name] = extension
extension.on_install(self.editor)
return extension | python | def add(self, extension):
"""
Add a extension to the editor.
:param extension: The extension instance to add.
"""
logger.debug('adding extension {}'.format(extension.name))
self._extensions[extension.name] = extension
extension.on_install(self.editor)
return extension | [
"def",
"add",
"(",
"self",
",",
"extension",
")",
":",
"logger",
".",
"debug",
"(",
"'adding extension {}'",
".",
"format",
"(",
"extension",
".",
"name",
")",
")",
"self",
".",
"_extensions",
"[",
"extension",
".",
"name",
"]",
"=",
"extension",
"extension",
".",
"on_install",
"(",
"self",
".",
"editor",
")",
"return",
"extension"
] | Add a extension to the editor.
:param extension: The extension instance to add. | [
"Add",
"a",
"extension",
"to",
"the",
"editor",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/extensions/manager.py#L37-L47 | train |
spyder-ide/spyder | spyder/plugins/editor/extensions/manager.py | EditorExtensionsManager.remove | def remove(self, name_or_klass):
"""
Remove a extension from the editor.
:param name_or_klass: The name (or class) of the extension to remove.
:returns: The removed extension.
"""
logger.debug('removing extension {}'.format(name_or_klass))
extension = self.get(name_or_klass)
extension.on_uninstall()
self._extensions.pop(extension.name)
return extension | python | def remove(self, name_or_klass):
"""
Remove a extension from the editor.
:param name_or_klass: The name (or class) of the extension to remove.
:returns: The removed extension.
"""
logger.debug('removing extension {}'.format(name_or_klass))
extension = self.get(name_or_klass)
extension.on_uninstall()
self._extensions.pop(extension.name)
return extension | [
"def",
"remove",
"(",
"self",
",",
"name_or_klass",
")",
":",
"logger",
".",
"debug",
"(",
"'removing extension {}'",
".",
"format",
"(",
"name_or_klass",
")",
")",
"extension",
"=",
"self",
".",
"get",
"(",
"name_or_klass",
")",
"extension",
".",
"on_uninstall",
"(",
")",
"self",
".",
"_extensions",
".",
"pop",
"(",
"extension",
".",
"name",
")",
"return",
"extension"
] | Remove a extension from the editor.
:param name_or_klass: The name (or class) of the extension to remove.
:returns: The removed extension. | [
"Remove",
"a",
"extension",
"from",
"the",
"editor",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/extensions/manager.py#L49-L60 | train |
spyder-ide/spyder | spyder/plugins/editor/extensions/manager.py | EditorExtensionsManager.clear | def clear(self):
"""
Remove all extensions from the editor.
All extensions are removed fromlist and deleted.
"""
while len(self._extensions):
key = sorted(list(self._extensions.keys()))[0]
self.remove(key) | python | def clear(self):
"""
Remove all extensions from the editor.
All extensions are removed fromlist and deleted.
"""
while len(self._extensions):
key = sorted(list(self._extensions.keys()))[0]
self.remove(key) | [
"def",
"clear",
"(",
"self",
")",
":",
"while",
"len",
"(",
"self",
".",
"_extensions",
")",
":",
"key",
"=",
"sorted",
"(",
"list",
"(",
"self",
".",
"_extensions",
".",
"keys",
"(",
")",
")",
")",
"[",
"0",
"]",
"self",
".",
"remove",
"(",
"key",
")"
] | Remove all extensions from the editor.
All extensions are removed fromlist and deleted. | [
"Remove",
"all",
"extensions",
"from",
"the",
"editor",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/extensions/manager.py#L62-L70 | train |
spyder-ide/spyder | spyder/plugins/editor/extensions/manager.py | EditorExtensionsManager.get | def get(self, name_or_klass):
"""
Get a extension by name (or class).
:param name_or_klass: The name or the class of the extension to get
:type name_or_klass: str or type
:rtype: spyder.api.mode.EditorExtension
"""
if not isinstance(name_or_klass, str):
name_or_klass = name_or_klass.__name__
return self._extensions[name_or_klass] | python | def get(self, name_or_klass):
"""
Get a extension by name (or class).
:param name_or_klass: The name or the class of the extension to get
:type name_or_klass: str or type
:rtype: spyder.api.mode.EditorExtension
"""
if not isinstance(name_or_klass, str):
name_or_klass = name_or_klass.__name__
return self._extensions[name_or_klass] | [
"def",
"get",
"(",
"self",
",",
"name_or_klass",
")",
":",
"if",
"not",
"isinstance",
"(",
"name_or_klass",
",",
"str",
")",
":",
"name_or_klass",
"=",
"name_or_klass",
".",
"__name__",
"return",
"self",
".",
"_extensions",
"[",
"name_or_klass",
"]"
] | Get a extension by name (or class).
:param name_or_klass: The name or the class of the extension to get
:type name_or_klass: str or type
:rtype: spyder.api.mode.EditorExtension | [
"Get",
"a",
"extension",
"by",
"name",
"(",
"or",
"class",
")",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/extensions/manager.py#L72-L82 | train |
spyder-ide/spyder | spyder/plugins/console/widgets/console.py | insert_text_to | def insert_text_to(cursor, text, fmt):
"""Helper to print text, taking into account backspaces"""
while True:
index = text.find(chr(8)) # backspace
if index == -1:
break
cursor.insertText(text[:index], fmt)
if cursor.positionInBlock() > 0:
cursor.deletePreviousChar()
text = text[index+1:]
cursor.insertText(text, fmt) | python | def insert_text_to(cursor, text, fmt):
"""Helper to print text, taking into account backspaces"""
while True:
index = text.find(chr(8)) # backspace
if index == -1:
break
cursor.insertText(text[:index], fmt)
if cursor.positionInBlock() > 0:
cursor.deletePreviousChar()
text = text[index+1:]
cursor.insertText(text, fmt) | [
"def",
"insert_text_to",
"(",
"cursor",
",",
"text",
",",
"fmt",
")",
":",
"while",
"True",
":",
"index",
"=",
"text",
".",
"find",
"(",
"chr",
"(",
"8",
")",
")",
"# backspace",
"if",
"index",
"==",
"-",
"1",
":",
"break",
"cursor",
".",
"insertText",
"(",
"text",
"[",
":",
"index",
"]",
",",
"fmt",
")",
"if",
"cursor",
".",
"positionInBlock",
"(",
")",
">",
"0",
":",
"cursor",
".",
"deletePreviousChar",
"(",
")",
"text",
"=",
"text",
"[",
"index",
"+",
"1",
":",
"]",
"cursor",
".",
"insertText",
"(",
"text",
",",
"fmt",
")"
] | Helper to print text, taking into account backspaces | [
"Helper",
"to",
"print",
"text",
"taking",
"into",
"account",
"backspaces"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/console.py#L35-L45 | train |
spyder-ide/spyder | spyder/plugins/console/widgets/console.py | QtANSIEscapeCodeHandler.set_color_scheme | def set_color_scheme(self, foreground_color, background_color):
"""Set color scheme (foreground and background)."""
if dark_color(foreground_color):
self.default_foreground_color = 30
else:
self.default_foreground_color = 37
if dark_color(background_color):
self.default_background_color = 47
else:
self.default_background_color = 40 | python | def set_color_scheme(self, foreground_color, background_color):
"""Set color scheme (foreground and background)."""
if dark_color(foreground_color):
self.default_foreground_color = 30
else:
self.default_foreground_color = 37
if dark_color(background_color):
self.default_background_color = 47
else:
self.default_background_color = 40 | [
"def",
"set_color_scheme",
"(",
"self",
",",
"foreground_color",
",",
"background_color",
")",
":",
"if",
"dark_color",
"(",
"foreground_color",
")",
":",
"self",
".",
"default_foreground_color",
"=",
"30",
"else",
":",
"self",
".",
"default_foreground_color",
"=",
"37",
"if",
"dark_color",
"(",
"background_color",
")",
":",
"self",
".",
"default_background_color",
"=",
"47",
"else",
":",
"self",
".",
"default_background_color",
"=",
"40"
] | Set color scheme (foreground and background). | [
"Set",
"color",
"scheme",
"(",
"foreground",
"and",
"background",
")",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/console.py#L54-L64 | train |
spyder-ide/spyder | spyder/plugins/console/widgets/console.py | QtANSIEscapeCodeHandler.set_style | def set_style(self):
"""
Set font style with the following attributes:
'foreground_color', 'background_color', 'italic',
'bold' and 'underline'
"""
if self.current_format is None:
assert self.base_format is not None
self.current_format = QTextCharFormat(self.base_format)
# Foreground color
if self.foreground_color is None:
qcolor = self.base_format.foreground()
else:
cstr = self.ANSI_COLORS[self.foreground_color-30][self.intensity]
qcolor = QColor(cstr)
self.current_format.setForeground(qcolor)
# Background color
if self.background_color is None:
qcolor = self.base_format.background()
else:
cstr = self.ANSI_COLORS[self.background_color-40][self.intensity]
qcolor = QColor(cstr)
self.current_format.setBackground(qcolor)
font = self.current_format.font()
# Italic
if self.italic is None:
italic = self.base_format.fontItalic()
else:
italic = self.italic
font.setItalic(italic)
# Bold
if self.bold is None:
bold = self.base_format.font().bold()
else:
bold = self.bold
font.setBold(bold)
# Underline
if self.underline is None:
underline = self.base_format.font().underline()
else:
underline = self.underline
font.setUnderline(underline)
self.current_format.setFont(font) | python | def set_style(self):
"""
Set font style with the following attributes:
'foreground_color', 'background_color', 'italic',
'bold' and 'underline'
"""
if self.current_format is None:
assert self.base_format is not None
self.current_format = QTextCharFormat(self.base_format)
# Foreground color
if self.foreground_color is None:
qcolor = self.base_format.foreground()
else:
cstr = self.ANSI_COLORS[self.foreground_color-30][self.intensity]
qcolor = QColor(cstr)
self.current_format.setForeground(qcolor)
# Background color
if self.background_color is None:
qcolor = self.base_format.background()
else:
cstr = self.ANSI_COLORS[self.background_color-40][self.intensity]
qcolor = QColor(cstr)
self.current_format.setBackground(qcolor)
font = self.current_format.font()
# Italic
if self.italic is None:
italic = self.base_format.fontItalic()
else:
italic = self.italic
font.setItalic(italic)
# Bold
if self.bold is None:
bold = self.base_format.font().bold()
else:
bold = self.bold
font.setBold(bold)
# Underline
if self.underline is None:
underline = self.base_format.font().underline()
else:
underline = self.underline
font.setUnderline(underline)
self.current_format.setFont(font) | [
"def",
"set_style",
"(",
"self",
")",
":",
"if",
"self",
".",
"current_format",
"is",
"None",
":",
"assert",
"self",
".",
"base_format",
"is",
"not",
"None",
"self",
".",
"current_format",
"=",
"QTextCharFormat",
"(",
"self",
".",
"base_format",
")",
"# Foreground color",
"if",
"self",
".",
"foreground_color",
"is",
"None",
":",
"qcolor",
"=",
"self",
".",
"base_format",
".",
"foreground",
"(",
")",
"else",
":",
"cstr",
"=",
"self",
".",
"ANSI_COLORS",
"[",
"self",
".",
"foreground_color",
"-",
"30",
"]",
"[",
"self",
".",
"intensity",
"]",
"qcolor",
"=",
"QColor",
"(",
"cstr",
")",
"self",
".",
"current_format",
".",
"setForeground",
"(",
"qcolor",
")",
"# Background color",
"if",
"self",
".",
"background_color",
"is",
"None",
":",
"qcolor",
"=",
"self",
".",
"base_format",
".",
"background",
"(",
")",
"else",
":",
"cstr",
"=",
"self",
".",
"ANSI_COLORS",
"[",
"self",
".",
"background_color",
"-",
"40",
"]",
"[",
"self",
".",
"intensity",
"]",
"qcolor",
"=",
"QColor",
"(",
"cstr",
")",
"self",
".",
"current_format",
".",
"setBackground",
"(",
"qcolor",
")",
"font",
"=",
"self",
".",
"current_format",
".",
"font",
"(",
")",
"# Italic",
"if",
"self",
".",
"italic",
"is",
"None",
":",
"italic",
"=",
"self",
".",
"base_format",
".",
"fontItalic",
"(",
")",
"else",
":",
"italic",
"=",
"self",
".",
"italic",
"font",
".",
"setItalic",
"(",
"italic",
")",
"# Bold",
"if",
"self",
".",
"bold",
"is",
"None",
":",
"bold",
"=",
"self",
".",
"base_format",
".",
"font",
"(",
")",
".",
"bold",
"(",
")",
"else",
":",
"bold",
"=",
"self",
".",
"bold",
"font",
".",
"setBold",
"(",
"bold",
")",
"# Underline",
"if",
"self",
".",
"underline",
"is",
"None",
":",
"underline",
"=",
"self",
".",
"base_format",
".",
"font",
"(",
")",
".",
"underline",
"(",
")",
"else",
":",
"underline",
"=",
"self",
".",
"underline",
"font",
".",
"setUnderline",
"(",
"underline",
")",
"self",
".",
"current_format",
".",
"setFont",
"(",
"font",
")"
] | Set font style with the following attributes:
'foreground_color', 'background_color', 'italic',
'bold' and 'underline' | [
"Set",
"font",
"style",
"with",
"the",
"following",
"attributes",
":",
"foreground_color",
"background_color",
"italic",
"bold",
"and",
"underline"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/console.py#L72-L115 | train |
spyder-ide/spyder | spyder/plugins/console/widgets/console.py | ConsoleBaseWidget.set_color_scheme | def set_color_scheme(self, foreground_color, background_color):
"""Set color scheme of the console (foreground and background)."""
self.ansi_handler.set_color_scheme(foreground_color, background_color)
background_color = QColor(background_color)
foreground_color = QColor(foreground_color)
self.set_palette(background=background_color,
foreground=foreground_color)
self.set_pythonshell_font() | python | def set_color_scheme(self, foreground_color, background_color):
"""Set color scheme of the console (foreground and background)."""
self.ansi_handler.set_color_scheme(foreground_color, background_color)
background_color = QColor(background_color)
foreground_color = QColor(foreground_color)
self.set_palette(background=background_color,
foreground=foreground_color)
self.set_pythonshell_font() | [
"def",
"set_color_scheme",
"(",
"self",
",",
"foreground_color",
",",
"background_color",
")",
":",
"self",
".",
"ansi_handler",
".",
"set_color_scheme",
"(",
"foreground_color",
",",
"background_color",
")",
"background_color",
"=",
"QColor",
"(",
"background_color",
")",
"foreground_color",
"=",
"QColor",
"(",
"foreground_color",
")",
"self",
".",
"set_palette",
"(",
"background",
"=",
"background_color",
",",
"foreground",
"=",
"foreground_color",
")",
"self",
".",
"set_pythonshell_font",
"(",
")"
] | Set color scheme of the console (foreground and background). | [
"Set",
"color",
"scheme",
"of",
"the",
"console",
"(",
"foreground",
"and",
"background",
")",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/console.py#L202-L212 | train |
spyder-ide/spyder | spyder/plugins/console/widgets/console.py | ConsoleBaseWidget.insert_text | def insert_text(self, text):
"""Reimplement TextEditBaseWidget method"""
# Eventually this maybe should wrap to insert_text_to if
# backspace-handling is required
self.textCursor().insertText(text, self.default_style.format) | python | def insert_text(self, text):
"""Reimplement TextEditBaseWidget method"""
# Eventually this maybe should wrap to insert_text_to if
# backspace-handling is required
self.textCursor().insertText(text, self.default_style.format) | [
"def",
"insert_text",
"(",
"self",
",",
"text",
")",
":",
"# Eventually this maybe should wrap to insert_text_to if",
"# backspace-handling is required",
"self",
".",
"textCursor",
"(",
")",
".",
"insertText",
"(",
"text",
",",
"self",
".",
"default_style",
".",
"format",
")"
] | Reimplement TextEditBaseWidget method | [
"Reimplement",
"TextEditBaseWidget",
"method"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/console.py#L215-L219 | train |
spyder-ide/spyder | spyder/plugins/console/widgets/console.py | ConsoleBaseWidget.paste | def paste(self):
"""Reimplement Qt method"""
if self.has_selected_text():
self.remove_selected_text()
self.insert_text(QApplication.clipboard().text()) | python | def paste(self):
"""Reimplement Qt method"""
if self.has_selected_text():
self.remove_selected_text()
self.insert_text(QApplication.clipboard().text()) | [
"def",
"paste",
"(",
"self",
")",
":",
"if",
"self",
".",
"has_selected_text",
"(",
")",
":",
"self",
".",
"remove_selected_text",
"(",
")",
"self",
".",
"insert_text",
"(",
"QApplication",
".",
"clipboard",
"(",
")",
".",
"text",
"(",
")",
")"
] | Reimplement Qt method | [
"Reimplement",
"Qt",
"method"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/console.py#L221-L225 | train |
spyder-ide/spyder | spyder/plugins/console/widgets/console.py | ConsoleBaseWidget.append_text_to_shell | def append_text_to_shell(self, text, error, prompt):
"""
Append text to Python shell
In a way, this method overrides the method 'insert_text' when text is
inserted at the end of the text widget for a Python shell
Handles error messages and show blue underlined links
Handles ANSI color sequences
Handles ANSI FF sequence
"""
cursor = self.textCursor()
cursor.movePosition(QTextCursor.End)
if '\r' in text: # replace \r\n with \n
text = text.replace('\r\n', '\n')
text = text.replace('\r', '\n')
while True:
index = text.find(chr(12))
if index == -1:
break
text = text[index+1:]
self.clear()
if error:
is_traceback = False
for text in text.splitlines(True):
if (text.startswith(' File')
and not text.startswith(' File "<')):
is_traceback = True
# Show error links in blue underlined text
cursor.insertText(' ', self.default_style.format)
cursor.insertText(text[2:],
self.traceback_link_style.format)
else:
# Show error/warning messages in red
cursor.insertText(text, self.error_style.format)
self.exception_occurred.emit(text, is_traceback)
elif prompt:
# Show prompt in green
insert_text_to(cursor, text, self.prompt_style.format)
else:
# Show other outputs in black
last_end = 0
for match in self.COLOR_PATTERN.finditer(text):
insert_text_to(cursor, text[last_end:match.start()],
self.default_style.format)
last_end = match.end()
try:
for code in [int(_c) for _c in match.group(1).split(';')]:
self.ansi_handler.set_code(code)
except ValueError:
pass
self.default_style.format = self.ansi_handler.get_format()
insert_text_to(cursor, text[last_end:], self.default_style.format)
# # Slower alternative:
# segments = self.COLOR_PATTERN.split(text)
# cursor.insertText(segments.pop(0), self.default_style.format)
# if segments:
# for ansi_tags, text in zip(segments[::2], segments[1::2]):
# for ansi_tag in ansi_tags.split(';'):
# self.ansi_handler.set_code(int(ansi_tag))
# self.default_style.format = self.ansi_handler.get_format()
# cursor.insertText(text, self.default_style.format)
self.set_cursor_position('eof')
self.setCurrentCharFormat(self.default_style.format) | python | def append_text_to_shell(self, text, error, prompt):
"""
Append text to Python shell
In a way, this method overrides the method 'insert_text' when text is
inserted at the end of the text widget for a Python shell
Handles error messages and show blue underlined links
Handles ANSI color sequences
Handles ANSI FF sequence
"""
cursor = self.textCursor()
cursor.movePosition(QTextCursor.End)
if '\r' in text: # replace \r\n with \n
text = text.replace('\r\n', '\n')
text = text.replace('\r', '\n')
while True:
index = text.find(chr(12))
if index == -1:
break
text = text[index+1:]
self.clear()
if error:
is_traceback = False
for text in text.splitlines(True):
if (text.startswith(' File')
and not text.startswith(' File "<')):
is_traceback = True
# Show error links in blue underlined text
cursor.insertText(' ', self.default_style.format)
cursor.insertText(text[2:],
self.traceback_link_style.format)
else:
# Show error/warning messages in red
cursor.insertText(text, self.error_style.format)
self.exception_occurred.emit(text, is_traceback)
elif prompt:
# Show prompt in green
insert_text_to(cursor, text, self.prompt_style.format)
else:
# Show other outputs in black
last_end = 0
for match in self.COLOR_PATTERN.finditer(text):
insert_text_to(cursor, text[last_end:match.start()],
self.default_style.format)
last_end = match.end()
try:
for code in [int(_c) for _c in match.group(1).split(';')]:
self.ansi_handler.set_code(code)
except ValueError:
pass
self.default_style.format = self.ansi_handler.get_format()
insert_text_to(cursor, text[last_end:], self.default_style.format)
# # Slower alternative:
# segments = self.COLOR_PATTERN.split(text)
# cursor.insertText(segments.pop(0), self.default_style.format)
# if segments:
# for ansi_tags, text in zip(segments[::2], segments[1::2]):
# for ansi_tag in ansi_tags.split(';'):
# self.ansi_handler.set_code(int(ansi_tag))
# self.default_style.format = self.ansi_handler.get_format()
# cursor.insertText(text, self.default_style.format)
self.set_cursor_position('eof')
self.setCurrentCharFormat(self.default_style.format) | [
"def",
"append_text_to_shell",
"(",
"self",
",",
"text",
",",
"error",
",",
"prompt",
")",
":",
"cursor",
"=",
"self",
".",
"textCursor",
"(",
")",
"cursor",
".",
"movePosition",
"(",
"QTextCursor",
".",
"End",
")",
"if",
"'\\r'",
"in",
"text",
":",
"# replace \\r\\n with \\n",
"text",
"=",
"text",
".",
"replace",
"(",
"'\\r\\n'",
",",
"'\\n'",
")",
"text",
"=",
"text",
".",
"replace",
"(",
"'\\r'",
",",
"'\\n'",
")",
"while",
"True",
":",
"index",
"=",
"text",
".",
"find",
"(",
"chr",
"(",
"12",
")",
")",
"if",
"index",
"==",
"-",
"1",
":",
"break",
"text",
"=",
"text",
"[",
"index",
"+",
"1",
":",
"]",
"self",
".",
"clear",
"(",
")",
"if",
"error",
":",
"is_traceback",
"=",
"False",
"for",
"text",
"in",
"text",
".",
"splitlines",
"(",
"True",
")",
":",
"if",
"(",
"text",
".",
"startswith",
"(",
"' File'",
")",
"and",
"not",
"text",
".",
"startswith",
"(",
"' File \"<'",
")",
")",
":",
"is_traceback",
"=",
"True",
"# Show error links in blue underlined text",
"cursor",
".",
"insertText",
"(",
"' '",
",",
"self",
".",
"default_style",
".",
"format",
")",
"cursor",
".",
"insertText",
"(",
"text",
"[",
"2",
":",
"]",
",",
"self",
".",
"traceback_link_style",
".",
"format",
")",
"else",
":",
"# Show error/warning messages in red",
"cursor",
".",
"insertText",
"(",
"text",
",",
"self",
".",
"error_style",
".",
"format",
")",
"self",
".",
"exception_occurred",
".",
"emit",
"(",
"text",
",",
"is_traceback",
")",
"elif",
"prompt",
":",
"# Show prompt in green",
"insert_text_to",
"(",
"cursor",
",",
"text",
",",
"self",
".",
"prompt_style",
".",
"format",
")",
"else",
":",
"# Show other outputs in black",
"last_end",
"=",
"0",
"for",
"match",
"in",
"self",
".",
"COLOR_PATTERN",
".",
"finditer",
"(",
"text",
")",
":",
"insert_text_to",
"(",
"cursor",
",",
"text",
"[",
"last_end",
":",
"match",
".",
"start",
"(",
")",
"]",
",",
"self",
".",
"default_style",
".",
"format",
")",
"last_end",
"=",
"match",
".",
"end",
"(",
")",
"try",
":",
"for",
"code",
"in",
"[",
"int",
"(",
"_c",
")",
"for",
"_c",
"in",
"match",
".",
"group",
"(",
"1",
")",
".",
"split",
"(",
"';'",
")",
"]",
":",
"self",
".",
"ansi_handler",
".",
"set_code",
"(",
"code",
")",
"except",
"ValueError",
":",
"pass",
"self",
".",
"default_style",
".",
"format",
"=",
"self",
".",
"ansi_handler",
".",
"get_format",
"(",
")",
"insert_text_to",
"(",
"cursor",
",",
"text",
"[",
"last_end",
":",
"]",
",",
"self",
".",
"default_style",
".",
"format",
")",
"# # Slower alternative:",
"# segments = self.COLOR_PATTERN.split(text)",
"# cursor.insertText(segments.pop(0), self.default_style.format)",
"# if segments:",
"# for ansi_tags, text in zip(segments[::2], segments[1::2]):",
"# for ansi_tag in ansi_tags.split(';'):",
"# self.ansi_handler.set_code(int(ansi_tag))",
"# self.default_style.format = self.ansi_handler.get_format()",
"# cursor.insertText(text, self.default_style.format)",
"self",
".",
"set_cursor_position",
"(",
"'eof'",
")",
"self",
".",
"setCurrentCharFormat",
"(",
"self",
".",
"default_style",
".",
"format",
")"
] | Append text to Python shell
In a way, this method overrides the method 'insert_text' when text is
inserted at the end of the text widget for a Python shell
Handles error messages and show blue underlined links
Handles ANSI color sequences
Handles ANSI FF sequence | [
"Append",
"text",
"to",
"Python",
"shell",
"In",
"a",
"way",
"this",
"method",
"overrides",
"the",
"method",
"insert_text",
"when",
"text",
"is",
"inserted",
"at",
"the",
"end",
"of",
"the",
"text",
"widget",
"for",
"a",
"Python",
"shell"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/console.py#L227-L289 | train |
spyder-ide/spyder | spyder/plugins/console/widgets/console.py | ConsoleBaseWidget.set_pythonshell_font | def set_pythonshell_font(self, font=None):
"""Python Shell only"""
if font is None:
font = QFont()
for style in self.font_styles:
style.apply_style(font=font,
is_default=style is self.default_style)
self.ansi_handler.set_base_format(self.default_style.format) | python | def set_pythonshell_font(self, font=None):
"""Python Shell only"""
if font is None:
font = QFont()
for style in self.font_styles:
style.apply_style(font=font,
is_default=style is self.default_style)
self.ansi_handler.set_base_format(self.default_style.format) | [
"def",
"set_pythonshell_font",
"(",
"self",
",",
"font",
"=",
"None",
")",
":",
"if",
"font",
"is",
"None",
":",
"font",
"=",
"QFont",
"(",
")",
"for",
"style",
"in",
"self",
".",
"font_styles",
":",
"style",
".",
"apply_style",
"(",
"font",
"=",
"font",
",",
"is_default",
"=",
"style",
"is",
"self",
".",
"default_style",
")",
"self",
".",
"ansi_handler",
".",
"set_base_format",
"(",
"self",
".",
"default_style",
".",
"format",
")"
] | Python Shell only | [
"Python",
"Shell",
"only"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/widgets/console.py#L291-L298 | train |
spyder-ide/spyder | spyder/plugins/pylint/plugin.py | Pylint.get_plugin_icon | def get_plugin_icon(self):
"""Return widget icon"""
path = osp.join(self.PLUGIN_PATH, self.IMG_PATH)
return ima.icon('pylint', icon_path=path) | python | def get_plugin_icon(self):
"""Return widget icon"""
path = osp.join(self.PLUGIN_PATH, self.IMG_PATH)
return ima.icon('pylint', icon_path=path) | [
"def",
"get_plugin_icon",
"(",
"self",
")",
":",
"path",
"=",
"osp",
".",
"join",
"(",
"self",
".",
"PLUGIN_PATH",
",",
"self",
".",
"IMG_PATH",
")",
"return",
"ima",
".",
"icon",
"(",
"'pylint'",
",",
"icon_path",
"=",
"path",
")"
] | Return widget icon | [
"Return",
"widget",
"icon"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/pylint/plugin.py#L75-L78 | train |
spyder-ide/spyder | spyder/plugins/pylint/plugin.py | Pylint.register_plugin | def register_plugin(self):
"""Register plugin in Spyder's main window"""
self.pylint.treewidget.sig_edit_goto.connect(self.main.editor.load)
self.pylint.redirect_stdio.connect(
self.main.redirect_internalshell_stdio)
self.main.add_dockwidget(self)
pylint_act = create_action(self, _("Run static code analysis"),
triggered=self.run_pylint)
pylint_act.setEnabled(is_module_installed('pylint'))
self.register_shortcut(pylint_act, context="Pylint",
name="Run analysis")
self.main.source_menu_actions += [MENU_SEPARATOR, pylint_act]
self.main.editor.pythonfile_dependent_actions += [pylint_act] | python | def register_plugin(self):
"""Register plugin in Spyder's main window"""
self.pylint.treewidget.sig_edit_goto.connect(self.main.editor.load)
self.pylint.redirect_stdio.connect(
self.main.redirect_internalshell_stdio)
self.main.add_dockwidget(self)
pylint_act = create_action(self, _("Run static code analysis"),
triggered=self.run_pylint)
pylint_act.setEnabled(is_module_installed('pylint'))
self.register_shortcut(pylint_act, context="Pylint",
name="Run analysis")
self.main.source_menu_actions += [MENU_SEPARATOR, pylint_act]
self.main.editor.pythonfile_dependent_actions += [pylint_act] | [
"def",
"register_plugin",
"(",
"self",
")",
":",
"self",
".",
"pylint",
".",
"treewidget",
".",
"sig_edit_goto",
".",
"connect",
"(",
"self",
".",
"main",
".",
"editor",
".",
"load",
")",
"self",
".",
"pylint",
".",
"redirect_stdio",
".",
"connect",
"(",
"self",
".",
"main",
".",
"redirect_internalshell_stdio",
")",
"self",
".",
"main",
".",
"add_dockwidget",
"(",
"self",
")",
"pylint_act",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Run static code analysis\"",
")",
",",
"triggered",
"=",
"self",
".",
"run_pylint",
")",
"pylint_act",
".",
"setEnabled",
"(",
"is_module_installed",
"(",
"'pylint'",
")",
")",
"self",
".",
"register_shortcut",
"(",
"pylint_act",
",",
"context",
"=",
"\"Pylint\"",
",",
"name",
"=",
"\"Run analysis\"",
")",
"self",
".",
"main",
".",
"source_menu_actions",
"+=",
"[",
"MENU_SEPARATOR",
",",
"pylint_act",
"]",
"self",
".",
"main",
".",
"editor",
".",
"pythonfile_dependent_actions",
"+=",
"[",
"pylint_act",
"]"
] | Register plugin in Spyder's main window | [
"Register",
"plugin",
"in",
"Spyder",
"s",
"main",
"window"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/pylint/plugin.py#L96-L110 | train |
spyder-ide/spyder | spyder/plugins/pylint/plugin.py | Pylint.run_pylint | def run_pylint(self):
"""Run pylint code analysis"""
if (self.get_option('save_before', True)
and not self.main.editor.save()):
return
self.switch_to_plugin()
self.analyze(self.main.editor.get_current_filename()) | python | def run_pylint(self):
"""Run pylint code analysis"""
if (self.get_option('save_before', True)
and not self.main.editor.save()):
return
self.switch_to_plugin()
self.analyze(self.main.editor.get_current_filename()) | [
"def",
"run_pylint",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"get_option",
"(",
"'save_before'",
",",
"True",
")",
"and",
"not",
"self",
".",
"main",
".",
"editor",
".",
"save",
"(",
")",
")",
":",
"return",
"self",
".",
"switch_to_plugin",
"(",
")",
"self",
".",
"analyze",
"(",
"self",
".",
"main",
".",
"editor",
".",
"get_current_filename",
"(",
")",
")"
] | Run pylint code analysis | [
"Run",
"pylint",
"code",
"analysis"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/pylint/plugin.py#L138-L144 | train |
spyder-ide/spyder | spyder/plugins/pylint/plugin.py | Pylint.analyze | def analyze(self, filename):
"""Reimplement analyze method"""
if self.dockwidget and not self.ismaximized:
self.dockwidget.setVisible(True)
self.dockwidget.setFocus()
self.dockwidget.raise_()
self.pylint.analyze(filename) | python | def analyze(self, filename):
"""Reimplement analyze method"""
if self.dockwidget and not self.ismaximized:
self.dockwidget.setVisible(True)
self.dockwidget.setFocus()
self.dockwidget.raise_()
self.pylint.analyze(filename) | [
"def",
"analyze",
"(",
"self",
",",
"filename",
")",
":",
"if",
"self",
".",
"dockwidget",
"and",
"not",
"self",
".",
"ismaximized",
":",
"self",
".",
"dockwidget",
".",
"setVisible",
"(",
"True",
")",
"self",
".",
"dockwidget",
".",
"setFocus",
"(",
")",
"self",
".",
"dockwidget",
".",
"raise_",
"(",
")",
"self",
".",
"pylint",
".",
"analyze",
"(",
"filename",
")"
] | Reimplement analyze method | [
"Reimplement",
"analyze",
"method"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/pylint/plugin.py#L146-L152 | train |
spyder-ide/spyder | spyder/preferences/appearance.py | AppearanceConfigPage.set_font | def set_font(self, font, option):
"""Set global font used in Spyder."""
# Update fonts in all plugins
set_font(font, option=option)
plugins = self.main.widgetlist + self.main.thirdparty_plugins
for plugin in plugins:
plugin.update_font() | python | def set_font(self, font, option):
"""Set global font used in Spyder."""
# Update fonts in all plugins
set_font(font, option=option)
plugins = self.main.widgetlist + self.main.thirdparty_plugins
for plugin in plugins:
plugin.update_font() | [
"def",
"set_font",
"(",
"self",
",",
"font",
",",
"option",
")",
":",
"# Update fonts in all plugins",
"set_font",
"(",
"font",
",",
"option",
"=",
"option",
")",
"plugins",
"=",
"self",
".",
"main",
".",
"widgetlist",
"+",
"self",
".",
"main",
".",
"thirdparty_plugins",
"for",
"plugin",
"in",
"plugins",
":",
"plugin",
".",
"update_font",
"(",
")"
] | Set global font used in Spyder. | [
"Set",
"global",
"font",
"used",
"in",
"Spyder",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/appearance.py#L182-L188 | train |
spyder-ide/spyder | spyder/preferences/appearance.py | AppearanceConfigPage.update_qt_style_combobox | def update_qt_style_combobox(self):
"""Enable/disable the Qt style combobox."""
if is_dark_interface():
self.style_combobox.setEnabled(False)
else:
self.style_combobox.setEnabled(True) | python | def update_qt_style_combobox(self):
"""Enable/disable the Qt style combobox."""
if is_dark_interface():
self.style_combobox.setEnabled(False)
else:
self.style_combobox.setEnabled(True) | [
"def",
"update_qt_style_combobox",
"(",
"self",
")",
":",
"if",
"is_dark_interface",
"(",
")",
":",
"self",
".",
"style_combobox",
".",
"setEnabled",
"(",
"False",
")",
"else",
":",
"self",
".",
"style_combobox",
".",
"setEnabled",
"(",
"True",
")"
] | Enable/disable the Qt style combobox. | [
"Enable",
"/",
"disable",
"the",
"Qt",
"style",
"combobox",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/appearance.py#L248-L253 | train |
spyder-ide/spyder | spyder/preferences/appearance.py | AppearanceConfigPage.update_combobox | def update_combobox(self):
"""Recreates the combobox contents."""
index = self.current_scheme_index
self.schemes_combobox.blockSignals(True)
names = self.get_option("names")
try:
names.pop(names.index(u'Custom'))
except ValueError:
pass
custom_names = self.get_option("custom_names", [])
# Useful for retrieving the actual data
for n in names + custom_names:
self.scheme_choices_dict[self.get_option('{0}/name'.format(n))] = n
if custom_names:
choices = names + [None] + custom_names
else:
choices = names
combobox = self.schemes_combobox
combobox.clear()
for name in choices:
if name is None:
continue
combobox.addItem(self.get_option('{0}/name'.format(name)), name)
if custom_names:
combobox.insertSeparator(len(names))
self.schemes_combobox.blockSignals(False)
self.schemes_combobox.setCurrentIndex(index) | python | def update_combobox(self):
"""Recreates the combobox contents."""
index = self.current_scheme_index
self.schemes_combobox.blockSignals(True)
names = self.get_option("names")
try:
names.pop(names.index(u'Custom'))
except ValueError:
pass
custom_names = self.get_option("custom_names", [])
# Useful for retrieving the actual data
for n in names + custom_names:
self.scheme_choices_dict[self.get_option('{0}/name'.format(n))] = n
if custom_names:
choices = names + [None] + custom_names
else:
choices = names
combobox = self.schemes_combobox
combobox.clear()
for name in choices:
if name is None:
continue
combobox.addItem(self.get_option('{0}/name'.format(name)), name)
if custom_names:
combobox.insertSeparator(len(names))
self.schemes_combobox.blockSignals(False)
self.schemes_combobox.setCurrentIndex(index) | [
"def",
"update_combobox",
"(",
"self",
")",
":",
"index",
"=",
"self",
".",
"current_scheme_index",
"self",
".",
"schemes_combobox",
".",
"blockSignals",
"(",
"True",
")",
"names",
"=",
"self",
".",
"get_option",
"(",
"\"names\"",
")",
"try",
":",
"names",
".",
"pop",
"(",
"names",
".",
"index",
"(",
"u'Custom'",
")",
")",
"except",
"ValueError",
":",
"pass",
"custom_names",
"=",
"self",
".",
"get_option",
"(",
"\"custom_names\"",
",",
"[",
"]",
")",
"# Useful for retrieving the actual data",
"for",
"n",
"in",
"names",
"+",
"custom_names",
":",
"self",
".",
"scheme_choices_dict",
"[",
"self",
".",
"get_option",
"(",
"'{0}/name'",
".",
"format",
"(",
"n",
")",
")",
"]",
"=",
"n",
"if",
"custom_names",
":",
"choices",
"=",
"names",
"+",
"[",
"None",
"]",
"+",
"custom_names",
"else",
":",
"choices",
"=",
"names",
"combobox",
"=",
"self",
".",
"schemes_combobox",
"combobox",
".",
"clear",
"(",
")",
"for",
"name",
"in",
"choices",
":",
"if",
"name",
"is",
"None",
":",
"continue",
"combobox",
".",
"addItem",
"(",
"self",
".",
"get_option",
"(",
"'{0}/name'",
".",
"format",
"(",
"name",
")",
")",
",",
"name",
")",
"if",
"custom_names",
":",
"combobox",
".",
"insertSeparator",
"(",
"len",
"(",
"names",
")",
")",
"self",
".",
"schemes_combobox",
".",
"blockSignals",
"(",
"False",
")",
"self",
".",
"schemes_combobox",
".",
"setCurrentIndex",
"(",
"index",
")"
] | Recreates the combobox contents. | [
"Recreates",
"the",
"combobox",
"contents",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/appearance.py#L255-L287 | train |
spyder-ide/spyder | spyder/preferences/appearance.py | AppearanceConfigPage.update_buttons | def update_buttons(self):
"""Updates the enable status of delete and reset buttons."""
current_scheme = self.current_scheme
names = self.get_option("names")
try:
names.pop(names.index(u'Custom'))
except ValueError:
pass
delete_enabled = current_scheme not in names
self.delete_button.setEnabled(delete_enabled)
self.reset_button.setEnabled(not delete_enabled) | python | def update_buttons(self):
"""Updates the enable status of delete and reset buttons."""
current_scheme = self.current_scheme
names = self.get_option("names")
try:
names.pop(names.index(u'Custom'))
except ValueError:
pass
delete_enabled = current_scheme not in names
self.delete_button.setEnabled(delete_enabled)
self.reset_button.setEnabled(not delete_enabled) | [
"def",
"update_buttons",
"(",
"self",
")",
":",
"current_scheme",
"=",
"self",
".",
"current_scheme",
"names",
"=",
"self",
".",
"get_option",
"(",
"\"names\"",
")",
"try",
":",
"names",
".",
"pop",
"(",
"names",
".",
"index",
"(",
"u'Custom'",
")",
")",
"except",
"ValueError",
":",
"pass",
"delete_enabled",
"=",
"current_scheme",
"not",
"in",
"names",
"self",
".",
"delete_button",
".",
"setEnabled",
"(",
"delete_enabled",
")",
"self",
".",
"reset_button",
".",
"setEnabled",
"(",
"not",
"delete_enabled",
")"
] | Updates the enable status of delete and reset buttons. | [
"Updates",
"the",
"enable",
"status",
"of",
"delete",
"and",
"reset",
"buttons",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/appearance.py#L289-L299 | train |
spyder-ide/spyder | spyder/preferences/appearance.py | AppearanceConfigPage.update_preview | def update_preview(self, index=None, scheme_name=None):
"""
Update the color scheme of the preview editor and adds text.
Note
----
'index' is needed, because this is triggered by a signal that sends
the selected index.
"""
text = ('"""A string"""\n\n'
'# A comment\n\n'
'# %% A cell\n\n'
'class Foo(object):\n'
' def __init__(self):\n'
' bar = 42\n'
' print(bar)\n'
)
show_blanks = CONF.get('editor', 'blank_spaces')
update_scrollbar = CONF.get('editor', 'scroll_past_end')
if scheme_name is None:
scheme_name = self.current_scheme
self.preview_editor.setup_editor(linenumbers=True,
markers=True,
tab_mode=False,
font=get_font(),
show_blanks=show_blanks,
color_scheme=scheme_name,
scroll_past_end=update_scrollbar)
self.preview_editor.set_text(text)
self.preview_editor.set_language('Python') | python | def update_preview(self, index=None, scheme_name=None):
"""
Update the color scheme of the preview editor and adds text.
Note
----
'index' is needed, because this is triggered by a signal that sends
the selected index.
"""
text = ('"""A string"""\n\n'
'# A comment\n\n'
'# %% A cell\n\n'
'class Foo(object):\n'
' def __init__(self):\n'
' bar = 42\n'
' print(bar)\n'
)
show_blanks = CONF.get('editor', 'blank_spaces')
update_scrollbar = CONF.get('editor', 'scroll_past_end')
if scheme_name is None:
scheme_name = self.current_scheme
self.preview_editor.setup_editor(linenumbers=True,
markers=True,
tab_mode=False,
font=get_font(),
show_blanks=show_blanks,
color_scheme=scheme_name,
scroll_past_end=update_scrollbar)
self.preview_editor.set_text(text)
self.preview_editor.set_language('Python') | [
"def",
"update_preview",
"(",
"self",
",",
"index",
"=",
"None",
",",
"scheme_name",
"=",
"None",
")",
":",
"text",
"=",
"(",
"'\"\"\"A string\"\"\"\\n\\n'",
"'# A comment\\n\\n'",
"'# %% A cell\\n\\n'",
"'class Foo(object):\\n'",
"' def __init__(self):\\n'",
"' bar = 42\\n'",
"' print(bar)\\n'",
")",
"show_blanks",
"=",
"CONF",
".",
"get",
"(",
"'editor'",
",",
"'blank_spaces'",
")",
"update_scrollbar",
"=",
"CONF",
".",
"get",
"(",
"'editor'",
",",
"'scroll_past_end'",
")",
"if",
"scheme_name",
"is",
"None",
":",
"scheme_name",
"=",
"self",
".",
"current_scheme",
"self",
".",
"preview_editor",
".",
"setup_editor",
"(",
"linenumbers",
"=",
"True",
",",
"markers",
"=",
"True",
",",
"tab_mode",
"=",
"False",
",",
"font",
"=",
"get_font",
"(",
")",
",",
"show_blanks",
"=",
"show_blanks",
",",
"color_scheme",
"=",
"scheme_name",
",",
"scroll_past_end",
"=",
"update_scrollbar",
")",
"self",
".",
"preview_editor",
".",
"set_text",
"(",
"text",
")",
"self",
".",
"preview_editor",
".",
"set_language",
"(",
"'Python'",
")"
] | Update the color scheme of the preview editor and adds text.
Note
----
'index' is needed, because this is triggered by a signal that sends
the selected index. | [
"Update",
"the",
"color",
"scheme",
"of",
"the",
"preview",
"editor",
"and",
"adds",
"text",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/appearance.py#L301-L330 | train |
spyder-ide/spyder | spyder/preferences/appearance.py | AppearanceConfigPage.create_new_scheme | def create_new_scheme(self):
"""Creates a new color scheme with a custom name."""
names = self.get_option('names')
custom_names = self.get_option('custom_names', [])
# Get the available number this new color scheme
counter = len(custom_names) - 1
custom_index = [int(n.split('-')[-1]) for n in custom_names]
for i in range(len(custom_names)):
if custom_index[i] != i:
counter = i - 1
break
custom_name = "custom-{0}".format(counter+1)
# Add the config settings, based on the current one.
custom_names.append(custom_name)
self.set_option('custom_names', custom_names)
for key in syntaxhighlighters.COLOR_SCHEME_KEYS:
name = "{0}/{1}".format(custom_name, key)
default_name = "{0}/{1}".format(self.current_scheme, key)
option = self.get_option(default_name)
self.set_option(name, option)
self.set_option('{0}/name'.format(custom_name), custom_name)
# Now they need to be loaded! how to make a partial load_from_conf?
dlg = self.scheme_editor_dialog
dlg.add_color_scheme_stack(custom_name, custom=True)
dlg.set_scheme(custom_name)
self.load_from_conf()
if dlg.exec_():
# This is needed to have the custom name updated on the combobox
name = dlg.get_scheme_name()
self.set_option('{0}/name'.format(custom_name), name)
# The +1 is needed because of the separator in the combobox
index = (names + custom_names).index(custom_name) + 1
self.update_combobox()
self.schemes_combobox.setCurrentIndex(index)
else:
# Delete the config ....
custom_names.remove(custom_name)
self.set_option('custom_names', custom_names)
dlg.delete_color_scheme_stack(custom_name) | python | def create_new_scheme(self):
"""Creates a new color scheme with a custom name."""
names = self.get_option('names')
custom_names = self.get_option('custom_names', [])
# Get the available number this new color scheme
counter = len(custom_names) - 1
custom_index = [int(n.split('-')[-1]) for n in custom_names]
for i in range(len(custom_names)):
if custom_index[i] != i:
counter = i - 1
break
custom_name = "custom-{0}".format(counter+1)
# Add the config settings, based on the current one.
custom_names.append(custom_name)
self.set_option('custom_names', custom_names)
for key in syntaxhighlighters.COLOR_SCHEME_KEYS:
name = "{0}/{1}".format(custom_name, key)
default_name = "{0}/{1}".format(self.current_scheme, key)
option = self.get_option(default_name)
self.set_option(name, option)
self.set_option('{0}/name'.format(custom_name), custom_name)
# Now they need to be loaded! how to make a partial load_from_conf?
dlg = self.scheme_editor_dialog
dlg.add_color_scheme_stack(custom_name, custom=True)
dlg.set_scheme(custom_name)
self.load_from_conf()
if dlg.exec_():
# This is needed to have the custom name updated on the combobox
name = dlg.get_scheme_name()
self.set_option('{0}/name'.format(custom_name), name)
# The +1 is needed because of the separator in the combobox
index = (names + custom_names).index(custom_name) + 1
self.update_combobox()
self.schemes_combobox.setCurrentIndex(index)
else:
# Delete the config ....
custom_names.remove(custom_name)
self.set_option('custom_names', custom_names)
dlg.delete_color_scheme_stack(custom_name) | [
"def",
"create_new_scheme",
"(",
"self",
")",
":",
"names",
"=",
"self",
".",
"get_option",
"(",
"'names'",
")",
"custom_names",
"=",
"self",
".",
"get_option",
"(",
"'custom_names'",
",",
"[",
"]",
")",
"# Get the available number this new color scheme",
"counter",
"=",
"len",
"(",
"custom_names",
")",
"-",
"1",
"custom_index",
"=",
"[",
"int",
"(",
"n",
".",
"split",
"(",
"'-'",
")",
"[",
"-",
"1",
"]",
")",
"for",
"n",
"in",
"custom_names",
"]",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"custom_names",
")",
")",
":",
"if",
"custom_index",
"[",
"i",
"]",
"!=",
"i",
":",
"counter",
"=",
"i",
"-",
"1",
"break",
"custom_name",
"=",
"\"custom-{0}\"",
".",
"format",
"(",
"counter",
"+",
"1",
")",
"# Add the config settings, based on the current one.",
"custom_names",
".",
"append",
"(",
"custom_name",
")",
"self",
".",
"set_option",
"(",
"'custom_names'",
",",
"custom_names",
")",
"for",
"key",
"in",
"syntaxhighlighters",
".",
"COLOR_SCHEME_KEYS",
":",
"name",
"=",
"\"{0}/{1}\"",
".",
"format",
"(",
"custom_name",
",",
"key",
")",
"default_name",
"=",
"\"{0}/{1}\"",
".",
"format",
"(",
"self",
".",
"current_scheme",
",",
"key",
")",
"option",
"=",
"self",
".",
"get_option",
"(",
"default_name",
")",
"self",
".",
"set_option",
"(",
"name",
",",
"option",
")",
"self",
".",
"set_option",
"(",
"'{0}/name'",
".",
"format",
"(",
"custom_name",
")",
",",
"custom_name",
")",
"# Now they need to be loaded! how to make a partial load_from_conf?",
"dlg",
"=",
"self",
".",
"scheme_editor_dialog",
"dlg",
".",
"add_color_scheme_stack",
"(",
"custom_name",
",",
"custom",
"=",
"True",
")",
"dlg",
".",
"set_scheme",
"(",
"custom_name",
")",
"self",
".",
"load_from_conf",
"(",
")",
"if",
"dlg",
".",
"exec_",
"(",
")",
":",
"# This is needed to have the custom name updated on the combobox",
"name",
"=",
"dlg",
".",
"get_scheme_name",
"(",
")",
"self",
".",
"set_option",
"(",
"'{0}/name'",
".",
"format",
"(",
"custom_name",
")",
",",
"name",
")",
"# The +1 is needed because of the separator in the combobox",
"index",
"=",
"(",
"names",
"+",
"custom_names",
")",
".",
"index",
"(",
"custom_name",
")",
"+",
"1",
"self",
".",
"update_combobox",
"(",
")",
"self",
".",
"schemes_combobox",
".",
"setCurrentIndex",
"(",
"index",
")",
"else",
":",
"# Delete the config ....",
"custom_names",
".",
"remove",
"(",
"custom_name",
")",
"self",
".",
"set_option",
"(",
"'custom_names'",
",",
"custom_names",
")",
"dlg",
".",
"delete_color_scheme_stack",
"(",
"custom_name",
")"
] | Creates a new color scheme with a custom name. | [
"Creates",
"a",
"new",
"color",
"scheme",
"with",
"a",
"custom",
"name",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/appearance.py#L334-L377 | train |
spyder-ide/spyder | spyder/preferences/appearance.py | AppearanceConfigPage.edit_scheme | def edit_scheme(self):
"""Edit current scheme."""
dlg = self.scheme_editor_dialog
dlg.set_scheme(self.current_scheme)
if dlg.exec_():
# Update temp scheme to reflect instant edits on the preview
temporal_color_scheme = dlg.get_edited_color_scheme()
for key in temporal_color_scheme:
option = "temp/{0}".format(key)
value = temporal_color_scheme[key]
self.set_option(option, value)
self.update_preview(scheme_name='temp') | python | def edit_scheme(self):
"""Edit current scheme."""
dlg = self.scheme_editor_dialog
dlg.set_scheme(self.current_scheme)
if dlg.exec_():
# Update temp scheme to reflect instant edits on the preview
temporal_color_scheme = dlg.get_edited_color_scheme()
for key in temporal_color_scheme:
option = "temp/{0}".format(key)
value = temporal_color_scheme[key]
self.set_option(option, value)
self.update_preview(scheme_name='temp') | [
"def",
"edit_scheme",
"(",
"self",
")",
":",
"dlg",
"=",
"self",
".",
"scheme_editor_dialog",
"dlg",
".",
"set_scheme",
"(",
"self",
".",
"current_scheme",
")",
"if",
"dlg",
".",
"exec_",
"(",
")",
":",
"# Update temp scheme to reflect instant edits on the preview",
"temporal_color_scheme",
"=",
"dlg",
".",
"get_edited_color_scheme",
"(",
")",
"for",
"key",
"in",
"temporal_color_scheme",
":",
"option",
"=",
"\"temp/{0}\"",
".",
"format",
"(",
"key",
")",
"value",
"=",
"temporal_color_scheme",
"[",
"key",
"]",
"self",
".",
"set_option",
"(",
"option",
",",
"value",
")",
"self",
".",
"update_preview",
"(",
"scheme_name",
"=",
"'temp'",
")"
] | Edit current scheme. | [
"Edit",
"current",
"scheme",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/appearance.py#L379-L391 | train |
spyder-ide/spyder | spyder/preferences/appearance.py | AppearanceConfigPage.delete_scheme | def delete_scheme(self):
"""Deletes the currently selected custom color scheme."""
scheme_name = self.current_scheme
answer = QMessageBox.warning(self, _("Warning"),
_("Are you sure you want to delete "
"this scheme?"),
QMessageBox.Yes | QMessageBox.No)
if answer == QMessageBox.Yes:
# Put the combobox in Spyder by default, when deleting a scheme
names = self.get_option('names')
self.set_scheme('spyder')
self.schemes_combobox.setCurrentIndex(names.index('spyder'))
self.set_option('selected', 'spyder')
# Delete from custom_names
custom_names = self.get_option('custom_names', [])
if scheme_name in custom_names:
custom_names.remove(scheme_name)
self.set_option('custom_names', custom_names)
# Delete config options
for key in syntaxhighlighters.COLOR_SCHEME_KEYS:
option = "{0}/{1}".format(scheme_name, key)
CONF.remove_option(self.CONF_SECTION, option)
CONF.remove_option(self.CONF_SECTION,
"{0}/name".format(scheme_name))
self.update_combobox()
self.update_preview() | python | def delete_scheme(self):
"""Deletes the currently selected custom color scheme."""
scheme_name = self.current_scheme
answer = QMessageBox.warning(self, _("Warning"),
_("Are you sure you want to delete "
"this scheme?"),
QMessageBox.Yes | QMessageBox.No)
if answer == QMessageBox.Yes:
# Put the combobox in Spyder by default, when deleting a scheme
names = self.get_option('names')
self.set_scheme('spyder')
self.schemes_combobox.setCurrentIndex(names.index('spyder'))
self.set_option('selected', 'spyder')
# Delete from custom_names
custom_names = self.get_option('custom_names', [])
if scheme_name in custom_names:
custom_names.remove(scheme_name)
self.set_option('custom_names', custom_names)
# Delete config options
for key in syntaxhighlighters.COLOR_SCHEME_KEYS:
option = "{0}/{1}".format(scheme_name, key)
CONF.remove_option(self.CONF_SECTION, option)
CONF.remove_option(self.CONF_SECTION,
"{0}/name".format(scheme_name))
self.update_combobox()
self.update_preview() | [
"def",
"delete_scheme",
"(",
"self",
")",
":",
"scheme_name",
"=",
"self",
".",
"current_scheme",
"answer",
"=",
"QMessageBox",
".",
"warning",
"(",
"self",
",",
"_",
"(",
"\"Warning\"",
")",
",",
"_",
"(",
"\"Are you sure you want to delete \"",
"\"this scheme?\"",
")",
",",
"QMessageBox",
".",
"Yes",
"|",
"QMessageBox",
".",
"No",
")",
"if",
"answer",
"==",
"QMessageBox",
".",
"Yes",
":",
"# Put the combobox in Spyder by default, when deleting a scheme",
"names",
"=",
"self",
".",
"get_option",
"(",
"'names'",
")",
"self",
".",
"set_scheme",
"(",
"'spyder'",
")",
"self",
".",
"schemes_combobox",
".",
"setCurrentIndex",
"(",
"names",
".",
"index",
"(",
"'spyder'",
")",
")",
"self",
".",
"set_option",
"(",
"'selected'",
",",
"'spyder'",
")",
"# Delete from custom_names",
"custom_names",
"=",
"self",
".",
"get_option",
"(",
"'custom_names'",
",",
"[",
"]",
")",
"if",
"scheme_name",
"in",
"custom_names",
":",
"custom_names",
".",
"remove",
"(",
"scheme_name",
")",
"self",
".",
"set_option",
"(",
"'custom_names'",
",",
"custom_names",
")",
"# Delete config options",
"for",
"key",
"in",
"syntaxhighlighters",
".",
"COLOR_SCHEME_KEYS",
":",
"option",
"=",
"\"{0}/{1}\"",
".",
"format",
"(",
"scheme_name",
",",
"key",
")",
"CONF",
".",
"remove_option",
"(",
"self",
".",
"CONF_SECTION",
",",
"option",
")",
"CONF",
".",
"remove_option",
"(",
"self",
".",
"CONF_SECTION",
",",
"\"{0}/name\"",
".",
"format",
"(",
"scheme_name",
")",
")",
"self",
".",
"update_combobox",
"(",
")",
"self",
".",
"update_preview",
"(",
")"
] | Deletes the currently selected custom color scheme. | [
"Deletes",
"the",
"currently",
"selected",
"custom",
"color",
"scheme",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/appearance.py#L393-L422 | train |
spyder-ide/spyder | spyder/preferences/appearance.py | AppearanceConfigPage.reset_to_default | def reset_to_default(self):
"""Restore initial values for default color schemes."""
# Checks that this is indeed a default scheme
scheme = self.current_scheme
names = self.get_option('names')
if scheme in names:
for key in syntaxhighlighters.COLOR_SCHEME_KEYS:
option = "{0}/{1}".format(scheme, key)
value = CONF.get_default(self.CONF_SECTION, option)
self.set_option(option, value)
self.load_from_conf() | python | def reset_to_default(self):
"""Restore initial values for default color schemes."""
# Checks that this is indeed a default scheme
scheme = self.current_scheme
names = self.get_option('names')
if scheme in names:
for key in syntaxhighlighters.COLOR_SCHEME_KEYS:
option = "{0}/{1}".format(scheme, key)
value = CONF.get_default(self.CONF_SECTION, option)
self.set_option(option, value)
self.load_from_conf() | [
"def",
"reset_to_default",
"(",
"self",
")",
":",
"# Checks that this is indeed a default scheme",
"scheme",
"=",
"self",
".",
"current_scheme",
"names",
"=",
"self",
".",
"get_option",
"(",
"'names'",
")",
"if",
"scheme",
"in",
"names",
":",
"for",
"key",
"in",
"syntaxhighlighters",
".",
"COLOR_SCHEME_KEYS",
":",
"option",
"=",
"\"{0}/{1}\"",
".",
"format",
"(",
"scheme",
",",
"key",
")",
"value",
"=",
"CONF",
".",
"get_default",
"(",
"self",
".",
"CONF_SECTION",
",",
"option",
")",
"self",
".",
"set_option",
"(",
"option",
",",
"value",
")",
"self",
".",
"load_from_conf",
"(",
")"
] | Restore initial values for default color schemes. | [
"Restore",
"initial",
"values",
"for",
"default",
"color",
"schemes",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/appearance.py#L432-L443 | train |
spyder-ide/spyder | spyder/preferences/appearance.py | SchemeEditor.set_scheme | def set_scheme(self, scheme_name):
"""Set the current stack by 'scheme_name'."""
self.stack.setCurrentIndex(self.order.index(scheme_name))
self.last_used_scheme = scheme_name | python | def set_scheme(self, scheme_name):
"""Set the current stack by 'scheme_name'."""
self.stack.setCurrentIndex(self.order.index(scheme_name))
self.last_used_scheme = scheme_name | [
"def",
"set_scheme",
"(",
"self",
",",
"scheme_name",
")",
":",
"self",
".",
"stack",
".",
"setCurrentIndex",
"(",
"self",
".",
"order",
".",
"index",
"(",
"scheme_name",
")",
")",
"self",
".",
"last_used_scheme",
"=",
"scheme_name"
] | Set the current stack by 'scheme_name'. | [
"Set",
"the",
"current",
"stack",
"by",
"scheme_name",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/appearance.py#L476-L479 | train |
spyder-ide/spyder | spyder/preferences/appearance.py | SchemeEditor.get_edited_color_scheme | def get_edited_color_scheme(self):
"""
Get the values of the last edited color scheme to be used in an instant
preview in the preview editor, without using `apply`.
"""
color_scheme = {}
scheme_name = self.last_used_scheme
for key in self.widgets[scheme_name]:
items = self.widgets[scheme_name][key]
if len(items) == 1:
# ColorLayout
value = items[0].text()
else:
# ColorLayout + checkboxes
value = (items[0].text(), items[1].isChecked(),
items[2].isChecked())
color_scheme[key] = value
return color_scheme | python | def get_edited_color_scheme(self):
"""
Get the values of the last edited color scheme to be used in an instant
preview in the preview editor, without using `apply`.
"""
color_scheme = {}
scheme_name = self.last_used_scheme
for key in self.widgets[scheme_name]:
items = self.widgets[scheme_name][key]
if len(items) == 1:
# ColorLayout
value = items[0].text()
else:
# ColorLayout + checkboxes
value = (items[0].text(), items[1].isChecked(),
items[2].isChecked())
color_scheme[key] = value
return color_scheme | [
"def",
"get_edited_color_scheme",
"(",
"self",
")",
":",
"color_scheme",
"=",
"{",
"}",
"scheme_name",
"=",
"self",
".",
"last_used_scheme",
"for",
"key",
"in",
"self",
".",
"widgets",
"[",
"scheme_name",
"]",
":",
"items",
"=",
"self",
".",
"widgets",
"[",
"scheme_name",
"]",
"[",
"key",
"]",
"if",
"len",
"(",
"items",
")",
"==",
"1",
":",
"# ColorLayout",
"value",
"=",
"items",
"[",
"0",
"]",
".",
"text",
"(",
")",
"else",
":",
"# ColorLayout + checkboxes",
"value",
"=",
"(",
"items",
"[",
"0",
"]",
".",
"text",
"(",
")",
",",
"items",
"[",
"1",
"]",
".",
"isChecked",
"(",
")",
",",
"items",
"[",
"2",
"]",
".",
"isChecked",
"(",
")",
")",
"color_scheme",
"[",
"key",
"]",
"=",
"value",
"return",
"color_scheme"
] | Get the values of the last edited color scheme to be used in an instant
preview in the preview editor, without using `apply`. | [
"Get",
"the",
"values",
"of",
"the",
"last",
"edited",
"color",
"scheme",
"to",
"be",
"used",
"in",
"an",
"instant",
"preview",
"in",
"the",
"preview",
"editor",
"without",
"using",
"apply",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/appearance.py#L488-L509 | train |
spyder-ide/spyder | spyder/preferences/appearance.py | SchemeEditor.add_color_scheme_stack | def add_color_scheme_stack(self, scheme_name, custom=False):
"""Add a stack for a given scheme and connects the CONF values."""
color_scheme_groups = [
(_('Text'), ["normal", "comment", "string", "number", "keyword",
"builtin", "definition", "instance", ]),
(_('Highlight'), ["currentcell", "currentline", "occurrence",
"matched_p", "unmatched_p", "ctrlclick"]),
(_('Background'), ["background", "sideareas"])
]
parent = self.parent
line_edit = parent.create_lineedit(_("Scheme name:"),
'{0}/name'.format(scheme_name))
self.widgets[scheme_name] = {}
# Widget setup
line_edit.label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
self.setWindowTitle(_('Color scheme editor'))
# Layout
name_layout = QHBoxLayout()
name_layout.addWidget(line_edit.label)
name_layout.addWidget(line_edit.textbox)
self.scheme_name_textbox[scheme_name] = line_edit.textbox
if not custom:
line_edit.textbox.setDisabled(True)
if not self.isVisible():
line_edit.setVisible(False)
cs_layout = QVBoxLayout()
cs_layout.addLayout(name_layout)
h_layout = QHBoxLayout()
v_layout = QVBoxLayout()
for index, item in enumerate(color_scheme_groups):
group_name, keys = item
group_layout = QGridLayout()
for row, key in enumerate(keys):
option = "{0}/{1}".format(scheme_name, key)
value = self.parent.get_option(option)
name = syntaxhighlighters.COLOR_SCHEME_KEYS[key]
if is_text_string(value):
label, clayout = parent.create_coloredit(
name,
option,
without_layout=True,
)
label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
group_layout.addWidget(label, row+1, 0)
group_layout.addLayout(clayout, row+1, 1)
# Needed to update temp scheme to obtain instant preview
self.widgets[scheme_name][key] = [clayout]
else:
label, clayout, cb_bold, cb_italic = parent.create_scedit(
name,
option,
without_layout=True,
)
label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
group_layout.addWidget(label, row+1, 0)
group_layout.addLayout(clayout, row+1, 1)
group_layout.addWidget(cb_bold, row+1, 2)
group_layout.addWidget(cb_italic, row+1, 3)
# Needed to update temp scheme to obtain instant preview
self.widgets[scheme_name][key] = [clayout, cb_bold,
cb_italic]
group_box = QGroupBox(group_name)
group_box.setLayout(group_layout)
if index == 0:
h_layout.addWidget(group_box)
else:
v_layout.addWidget(group_box)
h_layout.addLayout(v_layout)
cs_layout.addLayout(h_layout)
stackitem = QWidget()
stackitem.setLayout(cs_layout)
self.stack.addWidget(stackitem)
self.order.append(scheme_name) | python | def add_color_scheme_stack(self, scheme_name, custom=False):
"""Add a stack for a given scheme and connects the CONF values."""
color_scheme_groups = [
(_('Text'), ["normal", "comment", "string", "number", "keyword",
"builtin", "definition", "instance", ]),
(_('Highlight'), ["currentcell", "currentline", "occurrence",
"matched_p", "unmatched_p", "ctrlclick"]),
(_('Background'), ["background", "sideareas"])
]
parent = self.parent
line_edit = parent.create_lineedit(_("Scheme name:"),
'{0}/name'.format(scheme_name))
self.widgets[scheme_name] = {}
# Widget setup
line_edit.label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
self.setWindowTitle(_('Color scheme editor'))
# Layout
name_layout = QHBoxLayout()
name_layout.addWidget(line_edit.label)
name_layout.addWidget(line_edit.textbox)
self.scheme_name_textbox[scheme_name] = line_edit.textbox
if not custom:
line_edit.textbox.setDisabled(True)
if not self.isVisible():
line_edit.setVisible(False)
cs_layout = QVBoxLayout()
cs_layout.addLayout(name_layout)
h_layout = QHBoxLayout()
v_layout = QVBoxLayout()
for index, item in enumerate(color_scheme_groups):
group_name, keys = item
group_layout = QGridLayout()
for row, key in enumerate(keys):
option = "{0}/{1}".format(scheme_name, key)
value = self.parent.get_option(option)
name = syntaxhighlighters.COLOR_SCHEME_KEYS[key]
if is_text_string(value):
label, clayout = parent.create_coloredit(
name,
option,
without_layout=True,
)
label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
group_layout.addWidget(label, row+1, 0)
group_layout.addLayout(clayout, row+1, 1)
# Needed to update temp scheme to obtain instant preview
self.widgets[scheme_name][key] = [clayout]
else:
label, clayout, cb_bold, cb_italic = parent.create_scedit(
name,
option,
without_layout=True,
)
label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
group_layout.addWidget(label, row+1, 0)
group_layout.addLayout(clayout, row+1, 1)
group_layout.addWidget(cb_bold, row+1, 2)
group_layout.addWidget(cb_italic, row+1, 3)
# Needed to update temp scheme to obtain instant preview
self.widgets[scheme_name][key] = [clayout, cb_bold,
cb_italic]
group_box = QGroupBox(group_name)
group_box.setLayout(group_layout)
if index == 0:
h_layout.addWidget(group_box)
else:
v_layout.addWidget(group_box)
h_layout.addLayout(v_layout)
cs_layout.addLayout(h_layout)
stackitem = QWidget()
stackitem.setLayout(cs_layout)
self.stack.addWidget(stackitem)
self.order.append(scheme_name) | [
"def",
"add_color_scheme_stack",
"(",
"self",
",",
"scheme_name",
",",
"custom",
"=",
"False",
")",
":",
"color_scheme_groups",
"=",
"[",
"(",
"_",
"(",
"'Text'",
")",
",",
"[",
"\"normal\"",
",",
"\"comment\"",
",",
"\"string\"",
",",
"\"number\"",
",",
"\"keyword\"",
",",
"\"builtin\"",
",",
"\"definition\"",
",",
"\"instance\"",
",",
"]",
")",
",",
"(",
"_",
"(",
"'Highlight'",
")",
",",
"[",
"\"currentcell\"",
",",
"\"currentline\"",
",",
"\"occurrence\"",
",",
"\"matched_p\"",
",",
"\"unmatched_p\"",
",",
"\"ctrlclick\"",
"]",
")",
",",
"(",
"_",
"(",
"'Background'",
")",
",",
"[",
"\"background\"",
",",
"\"sideareas\"",
"]",
")",
"]",
"parent",
"=",
"self",
".",
"parent",
"line_edit",
"=",
"parent",
".",
"create_lineedit",
"(",
"_",
"(",
"\"Scheme name:\"",
")",
",",
"'{0}/name'",
".",
"format",
"(",
"scheme_name",
")",
")",
"self",
".",
"widgets",
"[",
"scheme_name",
"]",
"=",
"{",
"}",
"# Widget setup",
"line_edit",
".",
"label",
".",
"setAlignment",
"(",
"Qt",
".",
"AlignRight",
"|",
"Qt",
".",
"AlignVCenter",
")",
"self",
".",
"setWindowTitle",
"(",
"_",
"(",
"'Color scheme editor'",
")",
")",
"# Layout",
"name_layout",
"=",
"QHBoxLayout",
"(",
")",
"name_layout",
".",
"addWidget",
"(",
"line_edit",
".",
"label",
")",
"name_layout",
".",
"addWidget",
"(",
"line_edit",
".",
"textbox",
")",
"self",
".",
"scheme_name_textbox",
"[",
"scheme_name",
"]",
"=",
"line_edit",
".",
"textbox",
"if",
"not",
"custom",
":",
"line_edit",
".",
"textbox",
".",
"setDisabled",
"(",
"True",
")",
"if",
"not",
"self",
".",
"isVisible",
"(",
")",
":",
"line_edit",
".",
"setVisible",
"(",
"False",
")",
"cs_layout",
"=",
"QVBoxLayout",
"(",
")",
"cs_layout",
".",
"addLayout",
"(",
"name_layout",
")",
"h_layout",
"=",
"QHBoxLayout",
"(",
")",
"v_layout",
"=",
"QVBoxLayout",
"(",
")",
"for",
"index",
",",
"item",
"in",
"enumerate",
"(",
"color_scheme_groups",
")",
":",
"group_name",
",",
"keys",
"=",
"item",
"group_layout",
"=",
"QGridLayout",
"(",
")",
"for",
"row",
",",
"key",
"in",
"enumerate",
"(",
"keys",
")",
":",
"option",
"=",
"\"{0}/{1}\"",
".",
"format",
"(",
"scheme_name",
",",
"key",
")",
"value",
"=",
"self",
".",
"parent",
".",
"get_option",
"(",
"option",
")",
"name",
"=",
"syntaxhighlighters",
".",
"COLOR_SCHEME_KEYS",
"[",
"key",
"]",
"if",
"is_text_string",
"(",
"value",
")",
":",
"label",
",",
"clayout",
"=",
"parent",
".",
"create_coloredit",
"(",
"name",
",",
"option",
",",
"without_layout",
"=",
"True",
",",
")",
"label",
".",
"setAlignment",
"(",
"Qt",
".",
"AlignRight",
"|",
"Qt",
".",
"AlignVCenter",
")",
"group_layout",
".",
"addWidget",
"(",
"label",
",",
"row",
"+",
"1",
",",
"0",
")",
"group_layout",
".",
"addLayout",
"(",
"clayout",
",",
"row",
"+",
"1",
",",
"1",
")",
"# Needed to update temp scheme to obtain instant preview",
"self",
".",
"widgets",
"[",
"scheme_name",
"]",
"[",
"key",
"]",
"=",
"[",
"clayout",
"]",
"else",
":",
"label",
",",
"clayout",
",",
"cb_bold",
",",
"cb_italic",
"=",
"parent",
".",
"create_scedit",
"(",
"name",
",",
"option",
",",
"without_layout",
"=",
"True",
",",
")",
"label",
".",
"setAlignment",
"(",
"Qt",
".",
"AlignRight",
"|",
"Qt",
".",
"AlignVCenter",
")",
"group_layout",
".",
"addWidget",
"(",
"label",
",",
"row",
"+",
"1",
",",
"0",
")",
"group_layout",
".",
"addLayout",
"(",
"clayout",
",",
"row",
"+",
"1",
",",
"1",
")",
"group_layout",
".",
"addWidget",
"(",
"cb_bold",
",",
"row",
"+",
"1",
",",
"2",
")",
"group_layout",
".",
"addWidget",
"(",
"cb_italic",
",",
"row",
"+",
"1",
",",
"3",
")",
"# Needed to update temp scheme to obtain instant preview",
"self",
".",
"widgets",
"[",
"scheme_name",
"]",
"[",
"key",
"]",
"=",
"[",
"clayout",
",",
"cb_bold",
",",
"cb_italic",
"]",
"group_box",
"=",
"QGroupBox",
"(",
"group_name",
")",
"group_box",
".",
"setLayout",
"(",
"group_layout",
")",
"if",
"index",
"==",
"0",
":",
"h_layout",
".",
"addWidget",
"(",
"group_box",
")",
"else",
":",
"v_layout",
".",
"addWidget",
"(",
"group_box",
")",
"h_layout",
".",
"addLayout",
"(",
"v_layout",
")",
"cs_layout",
".",
"addLayout",
"(",
"h_layout",
")",
"stackitem",
"=",
"QWidget",
"(",
")",
"stackitem",
".",
"setLayout",
"(",
"cs_layout",
")",
"self",
".",
"stack",
".",
"addWidget",
"(",
"stackitem",
")",
"self",
".",
"order",
".",
"append",
"(",
"scheme_name",
")"
] | Add a stack for a given scheme and connects the CONF values. | [
"Add",
"a",
"stack",
"for",
"a",
"given",
"scheme",
"and",
"connects",
"the",
"CONF",
"values",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/appearance.py#L513-L601 | train |
spyder-ide/spyder | spyder/preferences/appearance.py | SchemeEditor.delete_color_scheme_stack | def delete_color_scheme_stack(self, scheme_name):
"""Remove stack widget by 'scheme_name'."""
self.set_scheme(scheme_name)
widget = self.stack.currentWidget()
self.stack.removeWidget(widget)
index = self.order.index(scheme_name)
self.order.pop(index) | python | def delete_color_scheme_stack(self, scheme_name):
"""Remove stack widget by 'scheme_name'."""
self.set_scheme(scheme_name)
widget = self.stack.currentWidget()
self.stack.removeWidget(widget)
index = self.order.index(scheme_name)
self.order.pop(index) | [
"def",
"delete_color_scheme_stack",
"(",
"self",
",",
"scheme_name",
")",
":",
"self",
".",
"set_scheme",
"(",
"scheme_name",
")",
"widget",
"=",
"self",
".",
"stack",
".",
"currentWidget",
"(",
")",
"self",
".",
"stack",
".",
"removeWidget",
"(",
"widget",
")",
"index",
"=",
"self",
".",
"order",
".",
"index",
"(",
"scheme_name",
")",
"self",
".",
"order",
".",
"pop",
"(",
"index",
")"
] | Remove stack widget by 'scheme_name'. | [
"Remove",
"stack",
"widget",
"by",
"scheme_name",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/appearance.py#L603-L609 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.get_plugin_actions | def get_plugin_actions(self):
"""Return a list of actions related to plugin"""
self.new_project_action = create_action(self,
_("New Project..."),
triggered=self.create_new_project)
self.open_project_action = create_action(self,
_("Open Project..."),
triggered=lambda v: self.open_project())
self.close_project_action = create_action(self,
_("Close Project"),
triggered=self.close_project)
self.delete_project_action = create_action(self,
_("Delete Project"),
triggered=self.delete_project)
self.clear_recent_projects_action =\
create_action(self, _("Clear this list"),
triggered=self.clear_recent_projects)
self.edit_project_preferences_action =\
create_action(self, _("Project Preferences"),
triggered=self.edit_project_preferences)
self.recent_project_menu = QMenu(_("Recent Projects"), self)
if self.main is not None:
self.main.projects_menu_actions += [self.new_project_action,
MENU_SEPARATOR,
self.open_project_action,
self.close_project_action,
self.delete_project_action,
MENU_SEPARATOR,
self.recent_project_menu,
self.toggle_view_action]
self.setup_menu_actions()
return [] | python | def get_plugin_actions(self):
"""Return a list of actions related to plugin"""
self.new_project_action = create_action(self,
_("New Project..."),
triggered=self.create_new_project)
self.open_project_action = create_action(self,
_("Open Project..."),
triggered=lambda v: self.open_project())
self.close_project_action = create_action(self,
_("Close Project"),
triggered=self.close_project)
self.delete_project_action = create_action(self,
_("Delete Project"),
triggered=self.delete_project)
self.clear_recent_projects_action =\
create_action(self, _("Clear this list"),
triggered=self.clear_recent_projects)
self.edit_project_preferences_action =\
create_action(self, _("Project Preferences"),
triggered=self.edit_project_preferences)
self.recent_project_menu = QMenu(_("Recent Projects"), self)
if self.main is not None:
self.main.projects_menu_actions += [self.new_project_action,
MENU_SEPARATOR,
self.open_project_action,
self.close_project_action,
self.delete_project_action,
MENU_SEPARATOR,
self.recent_project_menu,
self.toggle_view_action]
self.setup_menu_actions()
return [] | [
"def",
"get_plugin_actions",
"(",
"self",
")",
":",
"self",
".",
"new_project_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"New Project...\"",
")",
",",
"triggered",
"=",
"self",
".",
"create_new_project",
")",
"self",
".",
"open_project_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Open Project...\"",
")",
",",
"triggered",
"=",
"lambda",
"v",
":",
"self",
".",
"open_project",
"(",
")",
")",
"self",
".",
"close_project_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Close Project\"",
")",
",",
"triggered",
"=",
"self",
".",
"close_project",
")",
"self",
".",
"delete_project_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Delete Project\"",
")",
",",
"triggered",
"=",
"self",
".",
"delete_project",
")",
"self",
".",
"clear_recent_projects_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Clear this list\"",
")",
",",
"triggered",
"=",
"self",
".",
"clear_recent_projects",
")",
"self",
".",
"edit_project_preferences_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Project Preferences\"",
")",
",",
"triggered",
"=",
"self",
".",
"edit_project_preferences",
")",
"self",
".",
"recent_project_menu",
"=",
"QMenu",
"(",
"_",
"(",
"\"Recent Projects\"",
")",
",",
"self",
")",
"if",
"self",
".",
"main",
"is",
"not",
"None",
":",
"self",
".",
"main",
".",
"projects_menu_actions",
"+=",
"[",
"self",
".",
"new_project_action",
",",
"MENU_SEPARATOR",
",",
"self",
".",
"open_project_action",
",",
"self",
".",
"close_project_action",
",",
"self",
".",
"delete_project_action",
",",
"MENU_SEPARATOR",
",",
"self",
".",
"recent_project_menu",
",",
"self",
".",
"toggle_view_action",
"]",
"self",
".",
"setup_menu_actions",
"(",
")",
"return",
"[",
"]"
] | Return a list of actions related to plugin | [
"Return",
"a",
"list",
"of",
"actions",
"related",
"to",
"plugin"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L80-L113 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.register_plugin | def register_plugin(self):
"""Register plugin in Spyder's main window"""
ipyconsole = self.main.ipyconsole
treewidget = self.explorer.treewidget
lspmgr = self.main.lspmanager
self.main.add_dockwidget(self)
self.explorer.sig_open_file.connect(self.main.open_file)
self.register_widget_shortcuts(treewidget)
treewidget.sig_delete_project.connect(self.delete_project)
treewidget.sig_edit.connect(self.main.editor.load)
treewidget.sig_removed.connect(self.main.editor.removed)
treewidget.sig_removed_tree.connect(self.main.editor.removed_tree)
treewidget.sig_renamed.connect(self.main.editor.renamed)
treewidget.sig_renamed_tree.connect(self.main.editor.renamed_tree)
treewidget.sig_create_module.connect(self.main.editor.new)
treewidget.sig_new_file.connect(
lambda t: self.main.editor.new(text=t))
treewidget.sig_open_interpreter.connect(
ipyconsole.create_client_from_path)
treewidget.redirect_stdio.connect(
self.main.redirect_internalshell_stdio)
treewidget.sig_run.connect(
lambda fname:
ipyconsole.run_script(fname, osp.dirname(fname), '', False, False,
False, True))
# New project connections. Order matters!
self.sig_project_loaded.connect(
lambda v: self.main.workingdirectory.chdir(v))
self.sig_project_loaded.connect(
lambda v: self.main.set_window_title())
self.sig_project_loaded.connect(lspmgr.reinitialize_all_clients)
self.sig_project_loaded.connect(
lambda v: self.main.editor.setup_open_files())
self.sig_project_loaded.connect(self.update_explorer)
self.sig_project_closed[object].connect(
lambda v: self.main.workingdirectory.chdir(
self.get_last_working_dir()))
self.sig_project_closed.connect(
lambda v: self.main.set_window_title())
self.sig_project_closed.connect(lspmgr.reinitialize_all_clients)
self.sig_project_closed.connect(
lambda v: self.main.editor.setup_open_files())
self.recent_project_menu.aboutToShow.connect(self.setup_menu_actions)
self.main.pythonpath_changed()
self.main.restore_scrollbar_position.connect(
self.restore_scrollbar_position)
self.sig_pythonpath_changed.connect(self.main.pythonpath_changed)
self.main.editor.set_projects(self) | python | def register_plugin(self):
"""Register plugin in Spyder's main window"""
ipyconsole = self.main.ipyconsole
treewidget = self.explorer.treewidget
lspmgr = self.main.lspmanager
self.main.add_dockwidget(self)
self.explorer.sig_open_file.connect(self.main.open_file)
self.register_widget_shortcuts(treewidget)
treewidget.sig_delete_project.connect(self.delete_project)
treewidget.sig_edit.connect(self.main.editor.load)
treewidget.sig_removed.connect(self.main.editor.removed)
treewidget.sig_removed_tree.connect(self.main.editor.removed_tree)
treewidget.sig_renamed.connect(self.main.editor.renamed)
treewidget.sig_renamed_tree.connect(self.main.editor.renamed_tree)
treewidget.sig_create_module.connect(self.main.editor.new)
treewidget.sig_new_file.connect(
lambda t: self.main.editor.new(text=t))
treewidget.sig_open_interpreter.connect(
ipyconsole.create_client_from_path)
treewidget.redirect_stdio.connect(
self.main.redirect_internalshell_stdio)
treewidget.sig_run.connect(
lambda fname:
ipyconsole.run_script(fname, osp.dirname(fname), '', False, False,
False, True))
# New project connections. Order matters!
self.sig_project_loaded.connect(
lambda v: self.main.workingdirectory.chdir(v))
self.sig_project_loaded.connect(
lambda v: self.main.set_window_title())
self.sig_project_loaded.connect(lspmgr.reinitialize_all_clients)
self.sig_project_loaded.connect(
lambda v: self.main.editor.setup_open_files())
self.sig_project_loaded.connect(self.update_explorer)
self.sig_project_closed[object].connect(
lambda v: self.main.workingdirectory.chdir(
self.get_last_working_dir()))
self.sig_project_closed.connect(
lambda v: self.main.set_window_title())
self.sig_project_closed.connect(lspmgr.reinitialize_all_clients)
self.sig_project_closed.connect(
lambda v: self.main.editor.setup_open_files())
self.recent_project_menu.aboutToShow.connect(self.setup_menu_actions)
self.main.pythonpath_changed()
self.main.restore_scrollbar_position.connect(
self.restore_scrollbar_position)
self.sig_pythonpath_changed.connect(self.main.pythonpath_changed)
self.main.editor.set_projects(self) | [
"def",
"register_plugin",
"(",
"self",
")",
":",
"ipyconsole",
"=",
"self",
".",
"main",
".",
"ipyconsole",
"treewidget",
"=",
"self",
".",
"explorer",
".",
"treewidget",
"lspmgr",
"=",
"self",
".",
"main",
".",
"lspmanager",
"self",
".",
"main",
".",
"add_dockwidget",
"(",
"self",
")",
"self",
".",
"explorer",
".",
"sig_open_file",
".",
"connect",
"(",
"self",
".",
"main",
".",
"open_file",
")",
"self",
".",
"register_widget_shortcuts",
"(",
"treewidget",
")",
"treewidget",
".",
"sig_delete_project",
".",
"connect",
"(",
"self",
".",
"delete_project",
")",
"treewidget",
".",
"sig_edit",
".",
"connect",
"(",
"self",
".",
"main",
".",
"editor",
".",
"load",
")",
"treewidget",
".",
"sig_removed",
".",
"connect",
"(",
"self",
".",
"main",
".",
"editor",
".",
"removed",
")",
"treewidget",
".",
"sig_removed_tree",
".",
"connect",
"(",
"self",
".",
"main",
".",
"editor",
".",
"removed_tree",
")",
"treewidget",
".",
"sig_renamed",
".",
"connect",
"(",
"self",
".",
"main",
".",
"editor",
".",
"renamed",
")",
"treewidget",
".",
"sig_renamed_tree",
".",
"connect",
"(",
"self",
".",
"main",
".",
"editor",
".",
"renamed_tree",
")",
"treewidget",
".",
"sig_create_module",
".",
"connect",
"(",
"self",
".",
"main",
".",
"editor",
".",
"new",
")",
"treewidget",
".",
"sig_new_file",
".",
"connect",
"(",
"lambda",
"t",
":",
"self",
".",
"main",
".",
"editor",
".",
"new",
"(",
"text",
"=",
"t",
")",
")",
"treewidget",
".",
"sig_open_interpreter",
".",
"connect",
"(",
"ipyconsole",
".",
"create_client_from_path",
")",
"treewidget",
".",
"redirect_stdio",
".",
"connect",
"(",
"self",
".",
"main",
".",
"redirect_internalshell_stdio",
")",
"treewidget",
".",
"sig_run",
".",
"connect",
"(",
"lambda",
"fname",
":",
"ipyconsole",
".",
"run_script",
"(",
"fname",
",",
"osp",
".",
"dirname",
"(",
"fname",
")",
",",
"''",
",",
"False",
",",
"False",
",",
"False",
",",
"True",
")",
")",
"# New project connections. Order matters!\r",
"self",
".",
"sig_project_loaded",
".",
"connect",
"(",
"lambda",
"v",
":",
"self",
".",
"main",
".",
"workingdirectory",
".",
"chdir",
"(",
"v",
")",
")",
"self",
".",
"sig_project_loaded",
".",
"connect",
"(",
"lambda",
"v",
":",
"self",
".",
"main",
".",
"set_window_title",
"(",
")",
")",
"self",
".",
"sig_project_loaded",
".",
"connect",
"(",
"lspmgr",
".",
"reinitialize_all_clients",
")",
"self",
".",
"sig_project_loaded",
".",
"connect",
"(",
"lambda",
"v",
":",
"self",
".",
"main",
".",
"editor",
".",
"setup_open_files",
"(",
")",
")",
"self",
".",
"sig_project_loaded",
".",
"connect",
"(",
"self",
".",
"update_explorer",
")",
"self",
".",
"sig_project_closed",
"[",
"object",
"]",
".",
"connect",
"(",
"lambda",
"v",
":",
"self",
".",
"main",
".",
"workingdirectory",
".",
"chdir",
"(",
"self",
".",
"get_last_working_dir",
"(",
")",
")",
")",
"self",
".",
"sig_project_closed",
".",
"connect",
"(",
"lambda",
"v",
":",
"self",
".",
"main",
".",
"set_window_title",
"(",
")",
")",
"self",
".",
"sig_project_closed",
".",
"connect",
"(",
"lspmgr",
".",
"reinitialize_all_clients",
")",
"self",
".",
"sig_project_closed",
".",
"connect",
"(",
"lambda",
"v",
":",
"self",
".",
"main",
".",
"editor",
".",
"setup_open_files",
"(",
")",
")",
"self",
".",
"recent_project_menu",
".",
"aboutToShow",
".",
"connect",
"(",
"self",
".",
"setup_menu_actions",
")",
"self",
".",
"main",
".",
"pythonpath_changed",
"(",
")",
"self",
".",
"main",
".",
"restore_scrollbar_position",
".",
"connect",
"(",
"self",
".",
"restore_scrollbar_position",
")",
"self",
".",
"sig_pythonpath_changed",
".",
"connect",
"(",
"self",
".",
"main",
".",
"pythonpath_changed",
")",
"self",
".",
"main",
".",
"editor",
".",
"set_projects",
"(",
"self",
")"
] | Register plugin in Spyder's main window | [
"Register",
"plugin",
"in",
"Spyder",
"s",
"main",
"window"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L115-L166 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.closing_plugin | def closing_plugin(self, cancelable=False):
"""Perform actions before parent main window is closed"""
self.save_config()
self.explorer.closing_widget()
return True | python | def closing_plugin(self, cancelable=False):
"""Perform actions before parent main window is closed"""
self.save_config()
self.explorer.closing_widget()
return True | [
"def",
"closing_plugin",
"(",
"self",
",",
"cancelable",
"=",
"False",
")",
":",
"self",
".",
"save_config",
"(",
")",
"self",
".",
"explorer",
".",
"closing_widget",
"(",
")",
"return",
"True"
] | Perform actions before parent main window is closed | [
"Perform",
"actions",
"before",
"parent",
"main",
"window",
"is",
"closed"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L172-L176 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.switch_to_plugin | def switch_to_plugin(self):
"""Switch to plugin."""
# Unmaxizime currently maximized plugin
if (self.main.last_plugin is not None and
self.main.last_plugin.ismaximized and
self.main.last_plugin is not self):
self.main.maximize_dockwidget()
# Show plugin only if it was already visible
if self.get_option('visible_if_project_open'):
if not self.toggle_view_action.isChecked():
self.toggle_view_action.setChecked(True)
self.visibility_changed(True) | python | def switch_to_plugin(self):
"""Switch to plugin."""
# Unmaxizime currently maximized plugin
if (self.main.last_plugin is not None and
self.main.last_plugin.ismaximized and
self.main.last_plugin is not self):
self.main.maximize_dockwidget()
# Show plugin only if it was already visible
if self.get_option('visible_if_project_open'):
if not self.toggle_view_action.isChecked():
self.toggle_view_action.setChecked(True)
self.visibility_changed(True) | [
"def",
"switch_to_plugin",
"(",
"self",
")",
":",
"# Unmaxizime currently maximized plugin\r",
"if",
"(",
"self",
".",
"main",
".",
"last_plugin",
"is",
"not",
"None",
"and",
"self",
".",
"main",
".",
"last_plugin",
".",
"ismaximized",
"and",
"self",
".",
"main",
".",
"last_plugin",
"is",
"not",
"self",
")",
":",
"self",
".",
"main",
".",
"maximize_dockwidget",
"(",
")",
"# Show plugin only if it was already visible\r",
"if",
"self",
".",
"get_option",
"(",
"'visible_if_project_open'",
")",
":",
"if",
"not",
"self",
".",
"toggle_view_action",
".",
"isChecked",
"(",
")",
":",
"self",
".",
"toggle_view_action",
".",
"setChecked",
"(",
"True",
")",
"self",
".",
"visibility_changed",
"(",
"True",
")"
] | Switch to plugin. | [
"Switch",
"to",
"plugin",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L178-L190 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.setup_menu_actions | def setup_menu_actions(self):
"""Setup and update the menu actions."""
self.recent_project_menu.clear()
self.recent_projects_actions = []
if self.recent_projects:
for project in self.recent_projects:
if self.is_valid_project(project):
name = project.replace(get_home_dir(), '~')
action = create_action(
self,
name,
icon=ima.icon('project'),
triggered=(
lambda _, p=project: self.open_project(path=p))
)
self.recent_projects_actions.append(action)
else:
self.recent_projects.remove(project)
self.recent_projects_actions += [None,
self.clear_recent_projects_action]
else:
self.recent_projects_actions = [self.clear_recent_projects_action]
add_actions(self.recent_project_menu, self.recent_projects_actions)
self.update_project_actions() | python | def setup_menu_actions(self):
"""Setup and update the menu actions."""
self.recent_project_menu.clear()
self.recent_projects_actions = []
if self.recent_projects:
for project in self.recent_projects:
if self.is_valid_project(project):
name = project.replace(get_home_dir(), '~')
action = create_action(
self,
name,
icon=ima.icon('project'),
triggered=(
lambda _, p=project: self.open_project(path=p))
)
self.recent_projects_actions.append(action)
else:
self.recent_projects.remove(project)
self.recent_projects_actions += [None,
self.clear_recent_projects_action]
else:
self.recent_projects_actions = [self.clear_recent_projects_action]
add_actions(self.recent_project_menu, self.recent_projects_actions)
self.update_project_actions() | [
"def",
"setup_menu_actions",
"(",
"self",
")",
":",
"self",
".",
"recent_project_menu",
".",
"clear",
"(",
")",
"self",
".",
"recent_projects_actions",
"=",
"[",
"]",
"if",
"self",
".",
"recent_projects",
":",
"for",
"project",
"in",
"self",
".",
"recent_projects",
":",
"if",
"self",
".",
"is_valid_project",
"(",
"project",
")",
":",
"name",
"=",
"project",
".",
"replace",
"(",
"get_home_dir",
"(",
")",
",",
"'~'",
")",
"action",
"=",
"create_action",
"(",
"self",
",",
"name",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'project'",
")",
",",
"triggered",
"=",
"(",
"lambda",
"_",
",",
"p",
"=",
"project",
":",
"self",
".",
"open_project",
"(",
"path",
"=",
"p",
")",
")",
")",
"self",
".",
"recent_projects_actions",
".",
"append",
"(",
"action",
")",
"else",
":",
"self",
".",
"recent_projects",
".",
"remove",
"(",
"project",
")",
"self",
".",
"recent_projects_actions",
"+=",
"[",
"None",
",",
"self",
".",
"clear_recent_projects_action",
"]",
"else",
":",
"self",
".",
"recent_projects_actions",
"=",
"[",
"self",
".",
"clear_recent_projects_action",
"]",
"add_actions",
"(",
"self",
".",
"recent_project_menu",
",",
"self",
".",
"recent_projects_actions",
")",
"self",
".",
"update_project_actions",
"(",
")"
] | Setup and update the menu actions. | [
"Setup",
"and",
"update",
"the",
"menu",
"actions",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L193-L216 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.update_project_actions | def update_project_actions(self):
"""Update actions of the Projects menu"""
if self.recent_projects:
self.clear_recent_projects_action.setEnabled(True)
else:
self.clear_recent_projects_action.setEnabled(False)
active = bool(self.get_active_project_path())
self.close_project_action.setEnabled(active)
self.delete_project_action.setEnabled(active)
self.edit_project_preferences_action.setEnabled(active) | python | def update_project_actions(self):
"""Update actions of the Projects menu"""
if self.recent_projects:
self.clear_recent_projects_action.setEnabled(True)
else:
self.clear_recent_projects_action.setEnabled(False)
active = bool(self.get_active_project_path())
self.close_project_action.setEnabled(active)
self.delete_project_action.setEnabled(active)
self.edit_project_preferences_action.setEnabled(active) | [
"def",
"update_project_actions",
"(",
"self",
")",
":",
"if",
"self",
".",
"recent_projects",
":",
"self",
".",
"clear_recent_projects_action",
".",
"setEnabled",
"(",
"True",
")",
"else",
":",
"self",
".",
"clear_recent_projects_action",
".",
"setEnabled",
"(",
"False",
")",
"active",
"=",
"bool",
"(",
"self",
".",
"get_active_project_path",
"(",
")",
")",
"self",
".",
"close_project_action",
".",
"setEnabled",
"(",
"active",
")",
"self",
".",
"delete_project_action",
".",
"setEnabled",
"(",
"active",
")",
"self",
".",
"edit_project_preferences_action",
".",
"setEnabled",
"(",
"active",
")"
] | Update actions of the Projects menu | [
"Update",
"actions",
"of",
"the",
"Projects",
"menu"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L218-L228 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.edit_project_preferences | def edit_project_preferences(self):
"""Edit Spyder active project preferences"""
from spyder.plugins.projects.confpage import ProjectPreferences
if self.project_active:
active_project = self.project_list[0]
dlg = ProjectPreferences(self, active_project)
# dlg.size_change.connect(self.set_project_prefs_size)
# if self.projects_prefs_dialog_size is not None:
# dlg.resize(self.projects_prefs_dialog_size)
dlg.show()
# dlg.check_all_settings()
# dlg.pages_widget.currentChanged.connect(self.__preference_page_changed)
dlg.exec_() | python | def edit_project_preferences(self):
"""Edit Spyder active project preferences"""
from spyder.plugins.projects.confpage import ProjectPreferences
if self.project_active:
active_project = self.project_list[0]
dlg = ProjectPreferences(self, active_project)
# dlg.size_change.connect(self.set_project_prefs_size)
# if self.projects_prefs_dialog_size is not None:
# dlg.resize(self.projects_prefs_dialog_size)
dlg.show()
# dlg.check_all_settings()
# dlg.pages_widget.currentChanged.connect(self.__preference_page_changed)
dlg.exec_() | [
"def",
"edit_project_preferences",
"(",
"self",
")",
":",
"from",
"spyder",
".",
"plugins",
".",
"projects",
".",
"confpage",
"import",
"ProjectPreferences",
"if",
"self",
".",
"project_active",
":",
"active_project",
"=",
"self",
".",
"project_list",
"[",
"0",
"]",
"dlg",
"=",
"ProjectPreferences",
"(",
"self",
",",
"active_project",
")",
"# dlg.size_change.connect(self.set_project_prefs_size)\r",
"# if self.projects_prefs_dialog_size is not None:\r",
"# dlg.resize(self.projects_prefs_dialog_size)\r",
"dlg",
".",
"show",
"(",
")",
"# dlg.check_all_settings()\r",
"# dlg.pages_widget.currentChanged.connect(self.__preference_page_changed)\r",
"dlg",
".",
"exec_",
"(",
")"
] | Edit Spyder active project preferences | [
"Edit",
"Spyder",
"active",
"project",
"preferences"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L230-L242 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.create_new_project | def create_new_project(self):
"""Create new project"""
self.switch_to_plugin()
active_project = self.current_active_project
dlg = ProjectDialog(self)
dlg.sig_project_creation_requested.connect(self._create_project)
dlg.sig_project_creation_requested.connect(self.sig_project_created)
if dlg.exec_():
if (active_project is None
and self.get_option('visible_if_project_open')):
self.show_explorer()
self.sig_pythonpath_changed.emit()
self.restart_consoles() | python | def create_new_project(self):
"""Create new project"""
self.switch_to_plugin()
active_project = self.current_active_project
dlg = ProjectDialog(self)
dlg.sig_project_creation_requested.connect(self._create_project)
dlg.sig_project_creation_requested.connect(self.sig_project_created)
if dlg.exec_():
if (active_project is None
and self.get_option('visible_if_project_open')):
self.show_explorer()
self.sig_pythonpath_changed.emit()
self.restart_consoles() | [
"def",
"create_new_project",
"(",
"self",
")",
":",
"self",
".",
"switch_to_plugin",
"(",
")",
"active_project",
"=",
"self",
".",
"current_active_project",
"dlg",
"=",
"ProjectDialog",
"(",
"self",
")",
"dlg",
".",
"sig_project_creation_requested",
".",
"connect",
"(",
"self",
".",
"_create_project",
")",
"dlg",
".",
"sig_project_creation_requested",
".",
"connect",
"(",
"self",
".",
"sig_project_created",
")",
"if",
"dlg",
".",
"exec_",
"(",
")",
":",
"if",
"(",
"active_project",
"is",
"None",
"and",
"self",
".",
"get_option",
"(",
"'visible_if_project_open'",
")",
")",
":",
"self",
".",
"show_explorer",
"(",
")",
"self",
".",
"sig_pythonpath_changed",
".",
"emit",
"(",
")",
"self",
".",
"restart_consoles",
"(",
")"
] | Create new project | [
"Create",
"new",
"project"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L245-L257 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects._create_project | def _create_project(self, path):
"""Create a new project."""
self.open_project(path=path)
self.setup_menu_actions()
self.add_to_recent(path) | python | def _create_project(self, path):
"""Create a new project."""
self.open_project(path=path)
self.setup_menu_actions()
self.add_to_recent(path) | [
"def",
"_create_project",
"(",
"self",
",",
"path",
")",
":",
"self",
".",
"open_project",
"(",
"path",
"=",
"path",
")",
"self",
".",
"setup_menu_actions",
"(",
")",
"self",
".",
"add_to_recent",
"(",
"path",
")"
] | Create a new project. | [
"Create",
"a",
"new",
"project",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L259-L263 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.open_project | def open_project(self, path=None, restart_consoles=True,
save_previous_files=True):
"""Open the project located in `path`"""
self.switch_to_plugin()
if path is None:
basedir = get_home_dir()
path = getexistingdirectory(parent=self,
caption=_("Open project"),
basedir=basedir)
path = encoding.to_unicode_from_fs(path)
if not self.is_valid_project(path):
if path:
QMessageBox.critical(self, _('Error'),
_("<b>%s</b> is not a Spyder project!") % path)
return
else:
path = encoding.to_unicode_from_fs(path)
self.add_to_recent(path)
# A project was not open before
if self.current_active_project is None:
if save_previous_files and self.main.editor is not None:
self.main.editor.save_open_files()
if self.main.editor is not None:
self.main.editor.set_option('last_working_dir',
getcwd_or_home())
if self.get_option('visible_if_project_open'):
self.show_explorer()
else:
# We are switching projects
if self.main.editor is not None:
self.set_project_filenames(
self.main.editor.get_open_filenames())
self.current_active_project = EmptyProject(path)
self.latest_project = EmptyProject(path)
self.set_option('current_project_path', self.get_active_project_path())
self.setup_menu_actions()
self.sig_project_loaded.emit(path)
self.sig_pythonpath_changed.emit()
if restart_consoles:
self.restart_consoles() | python | def open_project(self, path=None, restart_consoles=True,
save_previous_files=True):
"""Open the project located in `path`"""
self.switch_to_plugin()
if path is None:
basedir = get_home_dir()
path = getexistingdirectory(parent=self,
caption=_("Open project"),
basedir=basedir)
path = encoding.to_unicode_from_fs(path)
if not self.is_valid_project(path):
if path:
QMessageBox.critical(self, _('Error'),
_("<b>%s</b> is not a Spyder project!") % path)
return
else:
path = encoding.to_unicode_from_fs(path)
self.add_to_recent(path)
# A project was not open before
if self.current_active_project is None:
if save_previous_files and self.main.editor is not None:
self.main.editor.save_open_files()
if self.main.editor is not None:
self.main.editor.set_option('last_working_dir',
getcwd_or_home())
if self.get_option('visible_if_project_open'):
self.show_explorer()
else:
# We are switching projects
if self.main.editor is not None:
self.set_project_filenames(
self.main.editor.get_open_filenames())
self.current_active_project = EmptyProject(path)
self.latest_project = EmptyProject(path)
self.set_option('current_project_path', self.get_active_project_path())
self.setup_menu_actions()
self.sig_project_loaded.emit(path)
self.sig_pythonpath_changed.emit()
if restart_consoles:
self.restart_consoles() | [
"def",
"open_project",
"(",
"self",
",",
"path",
"=",
"None",
",",
"restart_consoles",
"=",
"True",
",",
"save_previous_files",
"=",
"True",
")",
":",
"self",
".",
"switch_to_plugin",
"(",
")",
"if",
"path",
"is",
"None",
":",
"basedir",
"=",
"get_home_dir",
"(",
")",
"path",
"=",
"getexistingdirectory",
"(",
"parent",
"=",
"self",
",",
"caption",
"=",
"_",
"(",
"\"Open project\"",
")",
",",
"basedir",
"=",
"basedir",
")",
"path",
"=",
"encoding",
".",
"to_unicode_from_fs",
"(",
"path",
")",
"if",
"not",
"self",
".",
"is_valid_project",
"(",
"path",
")",
":",
"if",
"path",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"'Error'",
")",
",",
"_",
"(",
"\"<b>%s</b> is not a Spyder project!\"",
")",
"%",
"path",
")",
"return",
"else",
":",
"path",
"=",
"encoding",
".",
"to_unicode_from_fs",
"(",
"path",
")",
"self",
".",
"add_to_recent",
"(",
"path",
")",
"# A project was not open before\r",
"if",
"self",
".",
"current_active_project",
"is",
"None",
":",
"if",
"save_previous_files",
"and",
"self",
".",
"main",
".",
"editor",
"is",
"not",
"None",
":",
"self",
".",
"main",
".",
"editor",
".",
"save_open_files",
"(",
")",
"if",
"self",
".",
"main",
".",
"editor",
"is",
"not",
"None",
":",
"self",
".",
"main",
".",
"editor",
".",
"set_option",
"(",
"'last_working_dir'",
",",
"getcwd_or_home",
"(",
")",
")",
"if",
"self",
".",
"get_option",
"(",
"'visible_if_project_open'",
")",
":",
"self",
".",
"show_explorer",
"(",
")",
"else",
":",
"# We are switching projects\r",
"if",
"self",
".",
"main",
".",
"editor",
"is",
"not",
"None",
":",
"self",
".",
"set_project_filenames",
"(",
"self",
".",
"main",
".",
"editor",
".",
"get_open_filenames",
"(",
")",
")",
"self",
".",
"current_active_project",
"=",
"EmptyProject",
"(",
"path",
")",
"self",
".",
"latest_project",
"=",
"EmptyProject",
"(",
"path",
")",
"self",
".",
"set_option",
"(",
"'current_project_path'",
",",
"self",
".",
"get_active_project_path",
"(",
")",
")",
"self",
".",
"setup_menu_actions",
"(",
")",
"self",
".",
"sig_project_loaded",
".",
"emit",
"(",
"path",
")",
"self",
".",
"sig_pythonpath_changed",
".",
"emit",
"(",
")",
"if",
"restart_consoles",
":",
"self",
".",
"restart_consoles",
"(",
")"
] | Open the project located in `path` | [
"Open",
"the",
"project",
"located",
"in",
"path"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L265-L309 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.close_project | def close_project(self):
"""
Close current project and return to a window without an active
project
"""
if self.current_active_project:
self.switch_to_plugin()
if self.main.editor is not None:
self.set_project_filenames(
self.main.editor.get_open_filenames())
path = self.current_active_project.root_path
self.current_active_project = None
self.set_option('current_project_path', None)
self.setup_menu_actions()
self.sig_project_closed.emit(path)
self.sig_pythonpath_changed.emit()
if self.dockwidget is not None:
self.set_option('visible_if_project_open',
self.dockwidget.isVisible())
self.dockwidget.close()
self.explorer.clear()
self.restart_consoles() | python | def close_project(self):
"""
Close current project and return to a window without an active
project
"""
if self.current_active_project:
self.switch_to_plugin()
if self.main.editor is not None:
self.set_project_filenames(
self.main.editor.get_open_filenames())
path = self.current_active_project.root_path
self.current_active_project = None
self.set_option('current_project_path', None)
self.setup_menu_actions()
self.sig_project_closed.emit(path)
self.sig_pythonpath_changed.emit()
if self.dockwidget is not None:
self.set_option('visible_if_project_open',
self.dockwidget.isVisible())
self.dockwidget.close()
self.explorer.clear()
self.restart_consoles() | [
"def",
"close_project",
"(",
"self",
")",
":",
"if",
"self",
".",
"current_active_project",
":",
"self",
".",
"switch_to_plugin",
"(",
")",
"if",
"self",
".",
"main",
".",
"editor",
"is",
"not",
"None",
":",
"self",
".",
"set_project_filenames",
"(",
"self",
".",
"main",
".",
"editor",
".",
"get_open_filenames",
"(",
")",
")",
"path",
"=",
"self",
".",
"current_active_project",
".",
"root_path",
"self",
".",
"current_active_project",
"=",
"None",
"self",
".",
"set_option",
"(",
"'current_project_path'",
",",
"None",
")",
"self",
".",
"setup_menu_actions",
"(",
")",
"self",
".",
"sig_project_closed",
".",
"emit",
"(",
"path",
")",
"self",
".",
"sig_pythonpath_changed",
".",
"emit",
"(",
")",
"if",
"self",
".",
"dockwidget",
"is",
"not",
"None",
":",
"self",
".",
"set_option",
"(",
"'visible_if_project_open'",
",",
"self",
".",
"dockwidget",
".",
"isVisible",
"(",
")",
")",
"self",
".",
"dockwidget",
".",
"close",
"(",
")",
"self",
".",
"explorer",
".",
"clear",
"(",
")",
"self",
".",
"restart_consoles",
"(",
")"
] | Close current project and return to a window without an active
project | [
"Close",
"current",
"project",
"and",
"return",
"to",
"a",
"window",
"without",
"an",
"active",
"project"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L311-L335 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.delete_project | def delete_project(self):
"""
Delete the current project without deleting the files in the directory.
"""
if self.current_active_project:
self.switch_to_plugin()
path = self.current_active_project.root_path
buttons = QMessageBox.Yes | QMessageBox.No
answer = QMessageBox.warning(
self,
_("Delete"),
_("Do you really want to delete <b>{filename}</b>?<br><br>"
"<b>Note:</b> This action will only delete the project. "
"Its files are going to be preserved on disk."
).format(filename=osp.basename(path)),
buttons)
if answer == QMessageBox.Yes:
try:
self.close_project()
shutil.rmtree(osp.join(path, '.spyproject'))
except EnvironmentError as error:
QMessageBox.critical(
self,
_("Project Explorer"),
_("<b>Unable to delete <i>{varpath}</i></b>"
"<br><br>The error message was:<br>{error}"
).format(varpath=path, error=to_text_string(error))) | python | def delete_project(self):
"""
Delete the current project without deleting the files in the directory.
"""
if self.current_active_project:
self.switch_to_plugin()
path = self.current_active_project.root_path
buttons = QMessageBox.Yes | QMessageBox.No
answer = QMessageBox.warning(
self,
_("Delete"),
_("Do you really want to delete <b>{filename}</b>?<br><br>"
"<b>Note:</b> This action will only delete the project. "
"Its files are going to be preserved on disk."
).format(filename=osp.basename(path)),
buttons)
if answer == QMessageBox.Yes:
try:
self.close_project()
shutil.rmtree(osp.join(path, '.spyproject'))
except EnvironmentError as error:
QMessageBox.critical(
self,
_("Project Explorer"),
_("<b>Unable to delete <i>{varpath}</i></b>"
"<br><br>The error message was:<br>{error}"
).format(varpath=path, error=to_text_string(error))) | [
"def",
"delete_project",
"(",
"self",
")",
":",
"if",
"self",
".",
"current_active_project",
":",
"self",
".",
"switch_to_plugin",
"(",
")",
"path",
"=",
"self",
".",
"current_active_project",
".",
"root_path",
"buttons",
"=",
"QMessageBox",
".",
"Yes",
"|",
"QMessageBox",
".",
"No",
"answer",
"=",
"QMessageBox",
".",
"warning",
"(",
"self",
",",
"_",
"(",
"\"Delete\"",
")",
",",
"_",
"(",
"\"Do you really want to delete <b>{filename}</b>?<br><br>\"",
"\"<b>Note:</b> This action will only delete the project. \"",
"\"Its files are going to be preserved on disk.\"",
")",
".",
"format",
"(",
"filename",
"=",
"osp",
".",
"basename",
"(",
"path",
")",
")",
",",
"buttons",
")",
"if",
"answer",
"==",
"QMessageBox",
".",
"Yes",
":",
"try",
":",
"self",
".",
"close_project",
"(",
")",
"shutil",
".",
"rmtree",
"(",
"osp",
".",
"join",
"(",
"path",
",",
"'.spyproject'",
")",
")",
"except",
"EnvironmentError",
"as",
"error",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"\"Project Explorer\"",
")",
",",
"_",
"(",
"\"<b>Unable to delete <i>{varpath}</i></b>\"",
"\"<br><br>The error message was:<br>{error}\"",
")",
".",
"format",
"(",
"varpath",
"=",
"path",
",",
"error",
"=",
"to_text_string",
"(",
"error",
")",
")",
")"
] | Delete the current project without deleting the files in the directory. | [
"Delete",
"the",
"current",
"project",
"without",
"deleting",
"the",
"files",
"in",
"the",
"directory",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L337-L363 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.reopen_last_project | def reopen_last_project(self):
"""
Reopen the active project when Spyder was closed last time, if any
"""
current_project_path = self.get_option('current_project_path',
default=None)
# Needs a safer test of project existence!
if current_project_path and \
self.is_valid_project(current_project_path):
self.open_project(path=current_project_path,
restart_consoles=False,
save_previous_files=False)
self.load_config() | python | def reopen_last_project(self):
"""
Reopen the active project when Spyder was closed last time, if any
"""
current_project_path = self.get_option('current_project_path',
default=None)
# Needs a safer test of project existence!
if current_project_path and \
self.is_valid_project(current_project_path):
self.open_project(path=current_project_path,
restart_consoles=False,
save_previous_files=False)
self.load_config() | [
"def",
"reopen_last_project",
"(",
"self",
")",
":",
"current_project_path",
"=",
"self",
".",
"get_option",
"(",
"'current_project_path'",
",",
"default",
"=",
"None",
")",
"# Needs a safer test of project existence!\r",
"if",
"current_project_path",
"and",
"self",
".",
"is_valid_project",
"(",
"current_project_path",
")",
":",
"self",
".",
"open_project",
"(",
"path",
"=",
"current_project_path",
",",
"restart_consoles",
"=",
"False",
",",
"save_previous_files",
"=",
"False",
")",
"self",
".",
"load_config",
"(",
")"
] | Reopen the active project when Spyder was closed last time, if any | [
"Reopen",
"the",
"active",
"project",
"when",
"Spyder",
"was",
"closed",
"last",
"time",
"if",
"any"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L374-L387 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.get_project_filenames | def get_project_filenames(self):
"""Get the list of recent filenames of a project"""
recent_files = []
if self.current_active_project:
recent_files = self.current_active_project.get_recent_files()
elif self.latest_project:
recent_files = self.latest_project.get_recent_files()
return recent_files | python | def get_project_filenames(self):
"""Get the list of recent filenames of a project"""
recent_files = []
if self.current_active_project:
recent_files = self.current_active_project.get_recent_files()
elif self.latest_project:
recent_files = self.latest_project.get_recent_files()
return recent_files | [
"def",
"get_project_filenames",
"(",
"self",
")",
":",
"recent_files",
"=",
"[",
"]",
"if",
"self",
".",
"current_active_project",
":",
"recent_files",
"=",
"self",
".",
"current_active_project",
".",
"get_recent_files",
"(",
")",
"elif",
"self",
".",
"latest_project",
":",
"recent_files",
"=",
"self",
".",
"latest_project",
".",
"get_recent_files",
"(",
")",
"return",
"recent_files"
] | Get the list of recent filenames of a project | [
"Get",
"the",
"list",
"of",
"recent",
"filenames",
"of",
"a",
"project"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L389-L396 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.set_project_filenames | def set_project_filenames(self, recent_files):
"""Set the list of open file names in a project"""
if (self.current_active_project
and self.is_valid_project(
self.current_active_project.root_path)):
self.current_active_project.set_recent_files(recent_files) | python | def set_project_filenames(self, recent_files):
"""Set the list of open file names in a project"""
if (self.current_active_project
and self.is_valid_project(
self.current_active_project.root_path)):
self.current_active_project.set_recent_files(recent_files) | [
"def",
"set_project_filenames",
"(",
"self",
",",
"recent_files",
")",
":",
"if",
"(",
"self",
".",
"current_active_project",
"and",
"self",
".",
"is_valid_project",
"(",
"self",
".",
"current_active_project",
".",
"root_path",
")",
")",
":",
"self",
".",
"current_active_project",
".",
"set_recent_files",
"(",
"recent_files",
")"
] | Set the list of open file names in a project | [
"Set",
"the",
"list",
"of",
"open",
"file",
"names",
"in",
"a",
"project"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L398-L403 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.get_active_project_path | def get_active_project_path(self):
"""Get path of the active project"""
active_project_path = None
if self.current_active_project:
active_project_path = self.current_active_project.root_path
return active_project_path | python | def get_active_project_path(self):
"""Get path of the active project"""
active_project_path = None
if self.current_active_project:
active_project_path = self.current_active_project.root_path
return active_project_path | [
"def",
"get_active_project_path",
"(",
"self",
")",
":",
"active_project_path",
"=",
"None",
"if",
"self",
".",
"current_active_project",
":",
"active_project_path",
"=",
"self",
".",
"current_active_project",
".",
"root_path",
"return",
"active_project_path"
] | Get path of the active project | [
"Get",
"path",
"of",
"the",
"active",
"project"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L405-L410 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.get_pythonpath | def get_pythonpath(self, at_start=False):
"""Get project path as a list to be added to PYTHONPATH"""
if at_start:
current_path = self.get_option('current_project_path',
default=None)
else:
current_path = self.get_active_project_path()
if current_path is None:
return []
else:
return [current_path] | python | def get_pythonpath(self, at_start=False):
"""Get project path as a list to be added to PYTHONPATH"""
if at_start:
current_path = self.get_option('current_project_path',
default=None)
else:
current_path = self.get_active_project_path()
if current_path is None:
return []
else:
return [current_path] | [
"def",
"get_pythonpath",
"(",
"self",
",",
"at_start",
"=",
"False",
")",
":",
"if",
"at_start",
":",
"current_path",
"=",
"self",
".",
"get_option",
"(",
"'current_project_path'",
",",
"default",
"=",
"None",
")",
"else",
":",
"current_path",
"=",
"self",
".",
"get_active_project_path",
"(",
")",
"if",
"current_path",
"is",
"None",
":",
"return",
"[",
"]",
"else",
":",
"return",
"[",
"current_path",
"]"
] | Get project path as a list to be added to PYTHONPATH | [
"Get",
"project",
"path",
"as",
"a",
"list",
"to",
"be",
"added",
"to",
"PYTHONPATH"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L412-L422 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.save_config | def save_config(self):
"""
Save configuration: opened projects & tree widget state.
Also save whether dock widget is visible if a project is open.
"""
self.set_option('recent_projects', self.recent_projects)
self.set_option('expanded_state',
self.explorer.treewidget.get_expanded_state())
self.set_option('scrollbar_position',
self.explorer.treewidget.get_scrollbar_position())
if self.current_active_project and self.dockwidget:
self.set_option('visible_if_project_open',
self.dockwidget.isVisible()) | python | def save_config(self):
"""
Save configuration: opened projects & tree widget state.
Also save whether dock widget is visible if a project is open.
"""
self.set_option('recent_projects', self.recent_projects)
self.set_option('expanded_state',
self.explorer.treewidget.get_expanded_state())
self.set_option('scrollbar_position',
self.explorer.treewidget.get_scrollbar_position())
if self.current_active_project and self.dockwidget:
self.set_option('visible_if_project_open',
self.dockwidget.isVisible()) | [
"def",
"save_config",
"(",
"self",
")",
":",
"self",
".",
"set_option",
"(",
"'recent_projects'",
",",
"self",
".",
"recent_projects",
")",
"self",
".",
"set_option",
"(",
"'expanded_state'",
",",
"self",
".",
"explorer",
".",
"treewidget",
".",
"get_expanded_state",
"(",
")",
")",
"self",
".",
"set_option",
"(",
"'scrollbar_position'",
",",
"self",
".",
"explorer",
".",
"treewidget",
".",
"get_scrollbar_position",
"(",
")",
")",
"if",
"self",
".",
"current_active_project",
"and",
"self",
".",
"dockwidget",
":",
"self",
".",
"set_option",
"(",
"'visible_if_project_open'",
",",
"self",
".",
"dockwidget",
".",
"isVisible",
"(",
")",
")"
] | Save configuration: opened projects & tree widget state.
Also save whether dock widget is visible if a project is open. | [
"Save",
"configuration",
":",
"opened",
"projects",
"&",
"tree",
"widget",
"state",
".",
"Also",
"save",
"whether",
"dock",
"widget",
"is",
"visible",
"if",
"a",
"project",
"is",
"open",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L429-L442 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.show_explorer | def show_explorer(self):
"""Show the explorer"""
if self.dockwidget is not None:
if self.dockwidget.isHidden():
self.dockwidget.show()
self.dockwidget.raise_()
self.dockwidget.update() | python | def show_explorer(self):
"""Show the explorer"""
if self.dockwidget is not None:
if self.dockwidget.isHidden():
self.dockwidget.show()
self.dockwidget.raise_()
self.dockwidget.update() | [
"def",
"show_explorer",
"(",
"self",
")",
":",
"if",
"self",
".",
"dockwidget",
"is",
"not",
"None",
":",
"if",
"self",
".",
"dockwidget",
".",
"isHidden",
"(",
")",
":",
"self",
".",
"dockwidget",
".",
"show",
"(",
")",
"self",
".",
"dockwidget",
".",
"raise_",
"(",
")",
"self",
".",
"dockwidget",
".",
"update",
"(",
")"
] | Show the explorer | [
"Show",
"the",
"explorer"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L465-L471 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.is_valid_project | def is_valid_project(self, path):
"""Check if a directory is a valid Spyder project"""
spy_project_dir = osp.join(path, '.spyproject')
if osp.isdir(path) and osp.isdir(spy_project_dir):
return True
else:
return False | python | def is_valid_project(self, path):
"""Check if a directory is a valid Spyder project"""
spy_project_dir = osp.join(path, '.spyproject')
if osp.isdir(path) and osp.isdir(spy_project_dir):
return True
else:
return False | [
"def",
"is_valid_project",
"(",
"self",
",",
"path",
")",
":",
"spy_project_dir",
"=",
"osp",
".",
"join",
"(",
"path",
",",
"'.spyproject'",
")",
"if",
"osp",
".",
"isdir",
"(",
"path",
")",
"and",
"osp",
".",
"isdir",
"(",
"spy_project_dir",
")",
":",
"return",
"True",
"else",
":",
"return",
"False"
] | Check if a directory is a valid Spyder project | [
"Check",
"if",
"a",
"directory",
"is",
"a",
"valid",
"Spyder",
"project"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L478-L484 | train |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | Projects.add_to_recent | def add_to_recent(self, project):
"""
Add an entry to recent projetcs
We only maintain the list of the 10 most recent projects
"""
if project not in self.recent_projects:
self.recent_projects.insert(0, project)
self.recent_projects = self.recent_projects[:10] | python | def add_to_recent(self, project):
"""
Add an entry to recent projetcs
We only maintain the list of the 10 most recent projects
"""
if project not in self.recent_projects:
self.recent_projects.insert(0, project)
self.recent_projects = self.recent_projects[:10] | [
"def",
"add_to_recent",
"(",
"self",
",",
"project",
")",
":",
"if",
"project",
"not",
"in",
"self",
".",
"recent_projects",
":",
"self",
".",
"recent_projects",
".",
"insert",
"(",
"0",
",",
"project",
")",
"self",
".",
"recent_projects",
"=",
"self",
".",
"recent_projects",
"[",
":",
"10",
"]"
] | Add an entry to recent projetcs
We only maintain the list of the 10 most recent projects | [
"Add",
"an",
"entry",
"to",
"recent",
"projetcs",
"We",
"only",
"maintain",
"the",
"list",
"of",
"the",
"10",
"most",
"recent",
"projects"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L486-L494 | train |
spyder-ide/spyder | spyder/utils/windows.py | set_attached_console_visible | def set_attached_console_visible(state):
"""Show/hide system console window attached to current process.
Return it's previous state.
Availability: Windows"""
flag = {True: SW_SHOW, False: SW_HIDE}
return bool(ShowWindow(console_window_handle, flag[state])) | python | def set_attached_console_visible(state):
"""Show/hide system console window attached to current process.
Return it's previous state.
Availability: Windows"""
flag = {True: SW_SHOW, False: SW_HIDE}
return bool(ShowWindow(console_window_handle, flag[state])) | [
"def",
"set_attached_console_visible",
"(",
"state",
")",
":",
"flag",
"=",
"{",
"True",
":",
"SW_SHOW",
",",
"False",
":",
"SW_HIDE",
"}",
"return",
"bool",
"(",
"ShowWindow",
"(",
"console_window_handle",
",",
"flag",
"[",
"state",
"]",
")",
")"
] | Show/hide system console window attached to current process.
Return it's previous state.
Availability: Windows | [
"Show",
"/",
"hide",
"system",
"console",
"window",
"attached",
"to",
"current",
"process",
".",
"Return",
"it",
"s",
"previous",
"state",
".",
"Availability",
":",
"Windows"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/windows.py#L27-L33 | train |
spyder-ide/spyder | spyder/config/gui.py | get_family | def get_family(families):
"""Return the first installed font family in family list"""
if not isinstance(families, list):
families = [ families ]
for family in families:
if font_is_installed(family):
return family
else:
print("Warning: None of the following fonts is installed: %r" % families) # spyder: test-skip
return QFont().family() | python | def get_family(families):
"""Return the first installed font family in family list"""
if not isinstance(families, list):
families = [ families ]
for family in families:
if font_is_installed(family):
return family
else:
print("Warning: None of the following fonts is installed: %r" % families) # spyder: test-skip
return QFont().family() | [
"def",
"get_family",
"(",
"families",
")",
":",
"if",
"not",
"isinstance",
"(",
"families",
",",
"list",
")",
":",
"families",
"=",
"[",
"families",
"]",
"for",
"family",
"in",
"families",
":",
"if",
"font_is_installed",
"(",
"family",
")",
":",
"return",
"family",
"else",
":",
"print",
"(",
"\"Warning: None of the following fonts is installed: %r\"",
"%",
"families",
")",
"# spyder: test-skip",
"return",
"QFont",
"(",
")",
".",
"family",
"(",
")"
] | Return the first installed font family in family list | [
"Return",
"the",
"first",
"installed",
"font",
"family",
"in",
"family",
"list"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/gui.py#L45-L54 | train |
spyder-ide/spyder | spyder/config/gui.py | get_font | def get_font(section='appearance', option='font', font_size_delta=0):
"""Get console font properties depending on OS and user options"""
font = FONT_CACHE.get((section, option))
if font is None:
families = CONF.get(section, option+"/family", None)
if families is None:
return QFont()
family = get_family(families)
weight = QFont.Normal
italic = CONF.get(section, option+'/italic', False)
if CONF.get(section, option+'/bold', False):
weight = QFont.Bold
size = CONF.get(section, option+'/size', 9) + font_size_delta
font = QFont(family, size, weight)
font.setItalic(italic)
FONT_CACHE[(section, option)] = font
size = CONF.get(section, option+'/size', 9) + font_size_delta
font.setPointSize(size)
return font | python | def get_font(section='appearance', option='font', font_size_delta=0):
"""Get console font properties depending on OS and user options"""
font = FONT_CACHE.get((section, option))
if font is None:
families = CONF.get(section, option+"/family", None)
if families is None:
return QFont()
family = get_family(families)
weight = QFont.Normal
italic = CONF.get(section, option+'/italic', False)
if CONF.get(section, option+'/bold', False):
weight = QFont.Bold
size = CONF.get(section, option+'/size', 9) + font_size_delta
font = QFont(family, size, weight)
font.setItalic(italic)
FONT_CACHE[(section, option)] = font
size = CONF.get(section, option+'/size', 9) + font_size_delta
font.setPointSize(size)
return font | [
"def",
"get_font",
"(",
"section",
"=",
"'appearance'",
",",
"option",
"=",
"'font'",
",",
"font_size_delta",
"=",
"0",
")",
":",
"font",
"=",
"FONT_CACHE",
".",
"get",
"(",
"(",
"section",
",",
"option",
")",
")",
"if",
"font",
"is",
"None",
":",
"families",
"=",
"CONF",
".",
"get",
"(",
"section",
",",
"option",
"+",
"\"/family\"",
",",
"None",
")",
"if",
"families",
"is",
"None",
":",
"return",
"QFont",
"(",
")",
"family",
"=",
"get_family",
"(",
"families",
")",
"weight",
"=",
"QFont",
".",
"Normal",
"italic",
"=",
"CONF",
".",
"get",
"(",
"section",
",",
"option",
"+",
"'/italic'",
",",
"False",
")",
"if",
"CONF",
".",
"get",
"(",
"section",
",",
"option",
"+",
"'/bold'",
",",
"False",
")",
":",
"weight",
"=",
"QFont",
".",
"Bold",
"size",
"=",
"CONF",
".",
"get",
"(",
"section",
",",
"option",
"+",
"'/size'",
",",
"9",
")",
"+",
"font_size_delta",
"font",
"=",
"QFont",
"(",
"family",
",",
"size",
",",
"weight",
")",
"font",
".",
"setItalic",
"(",
"italic",
")",
"FONT_CACHE",
"[",
"(",
"section",
",",
"option",
")",
"]",
"=",
"font",
"size",
"=",
"CONF",
".",
"get",
"(",
"section",
",",
"option",
"+",
"'/size'",
",",
"9",
")",
"+",
"font_size_delta",
"font",
".",
"setPointSize",
"(",
"size",
")",
"return",
"font"
] | Get console font properties depending on OS and user options | [
"Get",
"console",
"font",
"properties",
"depending",
"on",
"OS",
"and",
"user",
"options"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/gui.py#L59-L83 | train |
spyder-ide/spyder | spyder/config/gui.py | set_font | def set_font(font, section='appearance', option='font'):
"""Set font"""
CONF.set(section, option+'/family', to_text_string(font.family()))
CONF.set(section, option+'/size', float(font.pointSize()))
CONF.set(section, option+'/italic', int(font.italic()))
CONF.set(section, option+'/bold', int(font.bold()))
FONT_CACHE[(section, option)] = font | python | def set_font(font, section='appearance', option='font'):
"""Set font"""
CONF.set(section, option+'/family', to_text_string(font.family()))
CONF.set(section, option+'/size', float(font.pointSize()))
CONF.set(section, option+'/italic', int(font.italic()))
CONF.set(section, option+'/bold', int(font.bold()))
FONT_CACHE[(section, option)] = font | [
"def",
"set_font",
"(",
"font",
",",
"section",
"=",
"'appearance'",
",",
"option",
"=",
"'font'",
")",
":",
"CONF",
".",
"set",
"(",
"section",
",",
"option",
"+",
"'/family'",
",",
"to_text_string",
"(",
"font",
".",
"family",
"(",
")",
")",
")",
"CONF",
".",
"set",
"(",
"section",
",",
"option",
"+",
"'/size'",
",",
"float",
"(",
"font",
".",
"pointSize",
"(",
")",
")",
")",
"CONF",
".",
"set",
"(",
"section",
",",
"option",
"+",
"'/italic'",
",",
"int",
"(",
"font",
".",
"italic",
"(",
")",
")",
")",
"CONF",
".",
"set",
"(",
"section",
",",
"option",
"+",
"'/bold'",
",",
"int",
"(",
"font",
".",
"bold",
"(",
")",
")",
")",
"FONT_CACHE",
"[",
"(",
"section",
",",
"option",
")",
"]",
"=",
"font"
] | Set font | [
"Set",
"font"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/gui.py#L86-L92 | train |
spyder-ide/spyder | spyder/config/gui.py | fixed_shortcut | def fixed_shortcut(keystr, parent, action):
"""
DEPRECATED: This function will be removed in Spyder 4.0
Define a fixed shortcut according to a keysequence string
"""
sc = QShortcut(QKeySequence(keystr), parent, action)
sc.setContext(Qt.WidgetWithChildrenShortcut)
return sc | python | def fixed_shortcut(keystr, parent, action):
"""
DEPRECATED: This function will be removed in Spyder 4.0
Define a fixed shortcut according to a keysequence string
"""
sc = QShortcut(QKeySequence(keystr), parent, action)
sc.setContext(Qt.WidgetWithChildrenShortcut)
return sc | [
"def",
"fixed_shortcut",
"(",
"keystr",
",",
"parent",
",",
"action",
")",
":",
"sc",
"=",
"QShortcut",
"(",
"QKeySequence",
"(",
"keystr",
")",
",",
"parent",
",",
"action",
")",
"sc",
".",
"setContext",
"(",
"Qt",
".",
"WidgetWithChildrenShortcut",
")",
"return",
"sc"
] | DEPRECATED: This function will be removed in Spyder 4.0
Define a fixed shortcut according to a keysequence string | [
"DEPRECATED",
":",
"This",
"function",
"will",
"be",
"removed",
"in",
"Spyder",
"4",
".",
"0"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/gui.py#L105-L113 | train |
spyder-ide/spyder | spyder/config/gui.py | config_shortcut | def config_shortcut(action, context, name, parent):
"""
Create a Shortcut namedtuple for a widget
The data contained in this tuple will be registered in
our shortcuts preferences page
"""
keystr = get_shortcut(context, name)
qsc = QShortcut(QKeySequence(keystr), parent, action)
qsc.setContext(Qt.WidgetWithChildrenShortcut)
sc = Shortcut(data=(qsc, context, name))
return sc | python | def config_shortcut(action, context, name, parent):
"""
Create a Shortcut namedtuple for a widget
The data contained in this tuple will be registered in
our shortcuts preferences page
"""
keystr = get_shortcut(context, name)
qsc = QShortcut(QKeySequence(keystr), parent, action)
qsc.setContext(Qt.WidgetWithChildrenShortcut)
sc = Shortcut(data=(qsc, context, name))
return sc | [
"def",
"config_shortcut",
"(",
"action",
",",
"context",
",",
"name",
",",
"parent",
")",
":",
"keystr",
"=",
"get_shortcut",
"(",
"context",
",",
"name",
")",
"qsc",
"=",
"QShortcut",
"(",
"QKeySequence",
"(",
"keystr",
")",
",",
"parent",
",",
"action",
")",
"qsc",
".",
"setContext",
"(",
"Qt",
".",
"WidgetWithChildrenShortcut",
")",
"sc",
"=",
"Shortcut",
"(",
"data",
"=",
"(",
"qsc",
",",
"context",
",",
"name",
")",
")",
"return",
"sc"
] | Create a Shortcut namedtuple for a widget
The data contained in this tuple will be registered in
our shortcuts preferences page | [
"Create",
"a",
"Shortcut",
"namedtuple",
"for",
"a",
"widget",
"The",
"data",
"contained",
"in",
"this",
"tuple",
"will",
"be",
"registered",
"in",
"our",
"shortcuts",
"preferences",
"page"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/gui.py#L116-L127 | train |
spyder-ide/spyder | spyder/config/gui.py | iter_shortcuts | def iter_shortcuts():
"""Iterate over keyboard shortcuts."""
for context_name, keystr in CONF.items('shortcuts'):
context, name = context_name.split("/", 1)
yield context, name, keystr | python | def iter_shortcuts():
"""Iterate over keyboard shortcuts."""
for context_name, keystr in CONF.items('shortcuts'):
context, name = context_name.split("/", 1)
yield context, name, keystr | [
"def",
"iter_shortcuts",
"(",
")",
":",
"for",
"context_name",
",",
"keystr",
"in",
"CONF",
".",
"items",
"(",
"'shortcuts'",
")",
":",
"context",
",",
"name",
"=",
"context_name",
".",
"split",
"(",
"\"/\"",
",",
"1",
")",
"yield",
"context",
",",
"name",
",",
"keystr"
] | Iterate over keyboard shortcuts. | [
"Iterate",
"over",
"keyboard",
"shortcuts",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/gui.py#L130-L134 | train |
spyder-ide/spyder | spyder/config/gui.py | get_color_scheme | def get_color_scheme(name):
"""Get syntax color scheme"""
color_scheme = {}
for key in sh.COLOR_SCHEME_KEYS:
color_scheme[key] = CONF.get("appearance", "%s/%s" % (name, key))
return color_scheme | python | def get_color_scheme(name):
"""Get syntax color scheme"""
color_scheme = {}
for key in sh.COLOR_SCHEME_KEYS:
color_scheme[key] = CONF.get("appearance", "%s/%s" % (name, key))
return color_scheme | [
"def",
"get_color_scheme",
"(",
"name",
")",
":",
"color_scheme",
"=",
"{",
"}",
"for",
"key",
"in",
"sh",
".",
"COLOR_SCHEME_KEYS",
":",
"color_scheme",
"[",
"key",
"]",
"=",
"CONF",
".",
"get",
"(",
"\"appearance\"",
",",
"\"%s/%s\"",
"%",
"(",
"name",
",",
"key",
")",
")",
"return",
"color_scheme"
] | Get syntax color scheme | [
"Get",
"syntax",
"color",
"scheme"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/gui.py#L142-L147 | train |
spyder-ide/spyder | spyder/config/gui.py | set_color_scheme | def set_color_scheme(name, color_scheme, replace=True):
"""Set syntax color scheme"""
section = "appearance"
names = CONF.get("appearance", "names", [])
for key in sh.COLOR_SCHEME_KEYS:
option = "%s/%s" % (name, key)
value = CONF.get(section, option, default=None)
if value is None or replace or name not in names:
CONF.set(section, option, color_scheme[key])
names.append(to_text_string(name))
CONF.set(section, "names", sorted(list(set(names)))) | python | def set_color_scheme(name, color_scheme, replace=True):
"""Set syntax color scheme"""
section = "appearance"
names = CONF.get("appearance", "names", [])
for key in sh.COLOR_SCHEME_KEYS:
option = "%s/%s" % (name, key)
value = CONF.get(section, option, default=None)
if value is None or replace or name not in names:
CONF.set(section, option, color_scheme[key])
names.append(to_text_string(name))
CONF.set(section, "names", sorted(list(set(names)))) | [
"def",
"set_color_scheme",
"(",
"name",
",",
"color_scheme",
",",
"replace",
"=",
"True",
")",
":",
"section",
"=",
"\"appearance\"",
"names",
"=",
"CONF",
".",
"get",
"(",
"\"appearance\"",
",",
"\"names\"",
",",
"[",
"]",
")",
"for",
"key",
"in",
"sh",
".",
"COLOR_SCHEME_KEYS",
":",
"option",
"=",
"\"%s/%s\"",
"%",
"(",
"name",
",",
"key",
")",
"value",
"=",
"CONF",
".",
"get",
"(",
"section",
",",
"option",
",",
"default",
"=",
"None",
")",
"if",
"value",
"is",
"None",
"or",
"replace",
"or",
"name",
"not",
"in",
"names",
":",
"CONF",
".",
"set",
"(",
"section",
",",
"option",
",",
"color_scheme",
"[",
"key",
"]",
")",
"names",
".",
"append",
"(",
"to_text_string",
"(",
"name",
")",
")",
"CONF",
".",
"set",
"(",
"section",
",",
"\"names\"",
",",
"sorted",
"(",
"list",
"(",
"set",
"(",
"names",
")",
")",
")",
")"
] | Set syntax color scheme | [
"Set",
"syntax",
"color",
"scheme"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/gui.py#L150-L160 | train |
spyder-ide/spyder | spyder/config/gui.py | set_default_color_scheme | def set_default_color_scheme(name, replace=True):
"""Reset color scheme to default values"""
assert name in sh.COLOR_SCHEME_NAMES
set_color_scheme(name, sh.get_color_scheme(name), replace=replace) | python | def set_default_color_scheme(name, replace=True):
"""Reset color scheme to default values"""
assert name in sh.COLOR_SCHEME_NAMES
set_color_scheme(name, sh.get_color_scheme(name), replace=replace) | [
"def",
"set_default_color_scheme",
"(",
"name",
",",
"replace",
"=",
"True",
")",
":",
"assert",
"name",
"in",
"sh",
".",
"COLOR_SCHEME_NAMES",
"set_color_scheme",
"(",
"name",
",",
"sh",
".",
"get_color_scheme",
"(",
"name",
")",
",",
"replace",
"=",
"replace",
")"
] | Reset color scheme to default values | [
"Reset",
"color",
"scheme",
"to",
"default",
"values"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/gui.py#L163-L166 | train |
spyder-ide/spyder | spyder/config/gui.py | is_dark_font_color | def is_dark_font_color(color_scheme):
"""Check if the font color used in the color scheme is dark."""
color_scheme = get_color_scheme(color_scheme)
font_color, fon_fw, fon_fs = color_scheme['normal']
return dark_color(font_color) | python | def is_dark_font_color(color_scheme):
"""Check if the font color used in the color scheme is dark."""
color_scheme = get_color_scheme(color_scheme)
font_color, fon_fw, fon_fs = color_scheme['normal']
return dark_color(font_color) | [
"def",
"is_dark_font_color",
"(",
"color_scheme",
")",
":",
"color_scheme",
"=",
"get_color_scheme",
"(",
"color_scheme",
")",
"font_color",
",",
"fon_fw",
",",
"fon_fs",
"=",
"color_scheme",
"[",
"'normal'",
"]",
"return",
"dark_color",
"(",
"font_color",
")"
] | Check if the font color used in the color scheme is dark. | [
"Check",
"if",
"the",
"font",
"color",
"used",
"in",
"the",
"color",
"scheme",
"is",
"dark",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/config/gui.py#L169-L173 | train |
spyder-ide/spyder | spyder/widgets/dock.py | TabFilter.eventFilter | def eventFilter(self, obj, event):
"""Filter mouse press events.
Events that are captured and not propagated return True. Events that
are not captured and are propagated return False.
"""
event_type = event.type()
if event_type == QEvent.MouseButtonPress:
self.tab_pressed(event)
return False
return False | python | def eventFilter(self, obj, event):
"""Filter mouse press events.
Events that are captured and not propagated return True. Events that
are not captured and are propagated return False.
"""
event_type = event.type()
if event_type == QEvent.MouseButtonPress:
self.tab_pressed(event)
return False
return False | [
"def",
"eventFilter",
"(",
"self",
",",
"obj",
",",
"event",
")",
":",
"event_type",
"=",
"event",
".",
"type",
"(",
")",
"if",
"event_type",
"==",
"QEvent",
".",
"MouseButtonPress",
":",
"self",
".",
"tab_pressed",
"(",
"event",
")",
"return",
"False",
"return",
"False"
] | Filter mouse press events.
Events that are captured and not propagated return True. Events that
are not captured and are propagated return False. | [
"Filter",
"mouse",
"press",
"events",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/dock.py#L32-L42 | train |
spyder-ide/spyder | spyder/widgets/dock.py | TabFilter.tab_pressed | def tab_pressed(self, event):
"""Method called when a tab from a QTabBar has been pressed."""
self.from_index = self.dock_tabbar.tabAt(event.pos())
self.dock_tabbar.setCurrentIndex(self.from_index)
if event.button() == Qt.RightButton:
if self.from_index == -1:
self.show_nontab_menu(event)
else:
self.show_tab_menu(event) | python | def tab_pressed(self, event):
"""Method called when a tab from a QTabBar has been pressed."""
self.from_index = self.dock_tabbar.tabAt(event.pos())
self.dock_tabbar.setCurrentIndex(self.from_index)
if event.button() == Qt.RightButton:
if self.from_index == -1:
self.show_nontab_menu(event)
else:
self.show_tab_menu(event) | [
"def",
"tab_pressed",
"(",
"self",
",",
"event",
")",
":",
"self",
".",
"from_index",
"=",
"self",
".",
"dock_tabbar",
".",
"tabAt",
"(",
"event",
".",
"pos",
"(",
")",
")",
"self",
".",
"dock_tabbar",
".",
"setCurrentIndex",
"(",
"self",
".",
"from_index",
")",
"if",
"event",
".",
"button",
"(",
")",
"==",
"Qt",
".",
"RightButton",
":",
"if",
"self",
".",
"from_index",
"==",
"-",
"1",
":",
"self",
".",
"show_nontab_menu",
"(",
"event",
")",
"else",
":",
"self",
".",
"show_tab_menu",
"(",
"event",
")"
] | Method called when a tab from a QTabBar has been pressed. | [
"Method",
"called",
"when",
"a",
"tab",
"from",
"a",
"QTabBar",
"has",
"been",
"pressed",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/dock.py#L44-L53 | train |
spyder-ide/spyder | spyder/widgets/dock.py | TabFilter.show_nontab_menu | def show_nontab_menu(self, event):
"""Show the context menu assigned to nontabs section."""
menu = self.main.createPopupMenu()
menu.exec_(self.dock_tabbar.mapToGlobal(event.pos())) | python | def show_nontab_menu(self, event):
"""Show the context menu assigned to nontabs section."""
menu = self.main.createPopupMenu()
menu.exec_(self.dock_tabbar.mapToGlobal(event.pos())) | [
"def",
"show_nontab_menu",
"(",
"self",
",",
"event",
")",
":",
"menu",
"=",
"self",
".",
"main",
".",
"createPopupMenu",
"(",
")",
"menu",
".",
"exec_",
"(",
"self",
".",
"dock_tabbar",
".",
"mapToGlobal",
"(",
"event",
".",
"pos",
"(",
")",
")",
")"
] | Show the context menu assigned to nontabs section. | [
"Show",
"the",
"context",
"menu",
"assigned",
"to",
"nontabs",
"section",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/dock.py#L59-L62 | train |
spyder-ide/spyder | spyder/widgets/dock.py | SpyderDockWidget.install_tab_event_filter | def install_tab_event_filter(self, value):
"""
Install an event filter to capture mouse events in the tabs of a
QTabBar holding tabified dockwidgets.
"""
dock_tabbar = None
tabbars = self.main.findChildren(QTabBar)
for tabbar in tabbars:
for tab in range(tabbar.count()):
title = tabbar.tabText(tab)
if title == self.title:
dock_tabbar = tabbar
break
if dock_tabbar is not None:
self.dock_tabbar = dock_tabbar
# Install filter only once per QTabBar
if getattr(self.dock_tabbar, 'filter', None) is None:
self.dock_tabbar.filter = TabFilter(self.dock_tabbar,
self.main)
self.dock_tabbar.installEventFilter(self.dock_tabbar.filter) | python | def install_tab_event_filter(self, value):
"""
Install an event filter to capture mouse events in the tabs of a
QTabBar holding tabified dockwidgets.
"""
dock_tabbar = None
tabbars = self.main.findChildren(QTabBar)
for tabbar in tabbars:
for tab in range(tabbar.count()):
title = tabbar.tabText(tab)
if title == self.title:
dock_tabbar = tabbar
break
if dock_tabbar is not None:
self.dock_tabbar = dock_tabbar
# Install filter only once per QTabBar
if getattr(self.dock_tabbar, 'filter', None) is None:
self.dock_tabbar.filter = TabFilter(self.dock_tabbar,
self.main)
self.dock_tabbar.installEventFilter(self.dock_tabbar.filter) | [
"def",
"install_tab_event_filter",
"(",
"self",
",",
"value",
")",
":",
"dock_tabbar",
"=",
"None",
"tabbars",
"=",
"self",
".",
"main",
".",
"findChildren",
"(",
"QTabBar",
")",
"for",
"tabbar",
"in",
"tabbars",
":",
"for",
"tab",
"in",
"range",
"(",
"tabbar",
".",
"count",
"(",
")",
")",
":",
"title",
"=",
"tabbar",
".",
"tabText",
"(",
"tab",
")",
"if",
"title",
"==",
"self",
".",
"title",
":",
"dock_tabbar",
"=",
"tabbar",
"break",
"if",
"dock_tabbar",
"is",
"not",
"None",
":",
"self",
".",
"dock_tabbar",
"=",
"dock_tabbar",
"# Install filter only once per QTabBar",
"if",
"getattr",
"(",
"self",
".",
"dock_tabbar",
",",
"'filter'",
",",
"None",
")",
"is",
"None",
":",
"self",
".",
"dock_tabbar",
".",
"filter",
"=",
"TabFilter",
"(",
"self",
".",
"dock_tabbar",
",",
"self",
".",
"main",
")",
"self",
".",
"dock_tabbar",
".",
"installEventFilter",
"(",
"self",
".",
"dock_tabbar",
".",
"filter",
")"
] | Install an event filter to capture mouse events in the tabs of a
QTabBar holding tabified dockwidgets. | [
"Install",
"an",
"event",
"filter",
"to",
"capture",
"mouse",
"events",
"in",
"the",
"tabs",
"of",
"a",
"QTabBar",
"holding",
"tabified",
"dockwidgets",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/dock.py#L208-L227 | train |
spyder-ide/spyder | spyder/plugins/editor/utils/bookmarks.py | _load_all_bookmarks | def _load_all_bookmarks():
"""Load all bookmarks from config."""
slots = CONF.get('editor', 'bookmarks', {})
for slot_num in list(slots.keys()):
if not osp.isfile(slots[slot_num][0]):
slots.pop(slot_num)
return slots | python | def _load_all_bookmarks():
"""Load all bookmarks from config."""
slots = CONF.get('editor', 'bookmarks', {})
for slot_num in list(slots.keys()):
if not osp.isfile(slots[slot_num][0]):
slots.pop(slot_num)
return slots | [
"def",
"_load_all_bookmarks",
"(",
")",
":",
"slots",
"=",
"CONF",
".",
"get",
"(",
"'editor'",
",",
"'bookmarks'",
",",
"{",
"}",
")",
"for",
"slot_num",
"in",
"list",
"(",
"slots",
".",
"keys",
"(",
")",
")",
":",
"if",
"not",
"osp",
".",
"isfile",
"(",
"slots",
"[",
"slot_num",
"]",
"[",
"0",
"]",
")",
":",
"slots",
".",
"pop",
"(",
"slot_num",
")",
"return",
"slots"
] | Load all bookmarks from config. | [
"Load",
"all",
"bookmarks",
"from",
"config",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/utils/bookmarks.py#L17-L23 | train |
spyder-ide/spyder | spyder/plugins/editor/utils/bookmarks.py | load_bookmarks | def load_bookmarks(filename):
"""Load all bookmarks for a specific file from config."""
bookmarks = _load_all_bookmarks()
return {k: v for k, v in bookmarks.items() if v[0] == filename} | python | def load_bookmarks(filename):
"""Load all bookmarks for a specific file from config."""
bookmarks = _load_all_bookmarks()
return {k: v for k, v in bookmarks.items() if v[0] == filename} | [
"def",
"load_bookmarks",
"(",
"filename",
")",
":",
"bookmarks",
"=",
"_load_all_bookmarks",
"(",
")",
"return",
"{",
"k",
":",
"v",
"for",
"k",
",",
"v",
"in",
"bookmarks",
".",
"items",
"(",
")",
"if",
"v",
"[",
"0",
"]",
"==",
"filename",
"}"
] | Load all bookmarks for a specific file from config. | [
"Load",
"all",
"bookmarks",
"for",
"a",
"specific",
"file",
"from",
"config",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/utils/bookmarks.py#L26-L29 | train |
spyder-ide/spyder | spyder/plugins/editor/utils/bookmarks.py | load_bookmarks_without_file | def load_bookmarks_without_file(filename):
"""Load all bookmarks but those from a specific file."""
bookmarks = _load_all_bookmarks()
return {k: v for k, v in bookmarks.items() if v[0] != filename} | python | def load_bookmarks_without_file(filename):
"""Load all bookmarks but those from a specific file."""
bookmarks = _load_all_bookmarks()
return {k: v for k, v in bookmarks.items() if v[0] != filename} | [
"def",
"load_bookmarks_without_file",
"(",
"filename",
")",
":",
"bookmarks",
"=",
"_load_all_bookmarks",
"(",
")",
"return",
"{",
"k",
":",
"v",
"for",
"k",
",",
"v",
"in",
"bookmarks",
".",
"items",
"(",
")",
"if",
"v",
"[",
"0",
"]",
"!=",
"filename",
"}"
] | Load all bookmarks but those from a specific file. | [
"Load",
"all",
"bookmarks",
"but",
"those",
"from",
"a",
"specific",
"file",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/utils/bookmarks.py#L32-L35 | train |
spyder-ide/spyder | spyder/plugins/editor/utils/bookmarks.py | save_bookmarks | def save_bookmarks(filename, bookmarks):
"""Save all bookmarks from specific file to config."""
if not osp.isfile(filename):
return
slots = load_bookmarks_without_file(filename)
for slot_num, content in bookmarks.items():
slots[slot_num] = [filename, content[0], content[1]]
CONF.set('editor', 'bookmarks', slots) | python | def save_bookmarks(filename, bookmarks):
"""Save all bookmarks from specific file to config."""
if not osp.isfile(filename):
return
slots = load_bookmarks_without_file(filename)
for slot_num, content in bookmarks.items():
slots[slot_num] = [filename, content[0], content[1]]
CONF.set('editor', 'bookmarks', slots) | [
"def",
"save_bookmarks",
"(",
"filename",
",",
"bookmarks",
")",
":",
"if",
"not",
"osp",
".",
"isfile",
"(",
"filename",
")",
":",
"return",
"slots",
"=",
"load_bookmarks_without_file",
"(",
"filename",
")",
"for",
"slot_num",
",",
"content",
"in",
"bookmarks",
".",
"items",
"(",
")",
":",
"slots",
"[",
"slot_num",
"]",
"=",
"[",
"filename",
",",
"content",
"[",
"0",
"]",
",",
"content",
"[",
"1",
"]",
"]",
"CONF",
".",
"set",
"(",
"'editor'",
",",
"'bookmarks'",
",",
"slots",
")"
] | Save all bookmarks from specific file to config. | [
"Save",
"all",
"bookmarks",
"from",
"specific",
"file",
"to",
"config",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/utils/bookmarks.py#L38-L45 | train |
spyder-ide/spyder | spyder/plugins/editor/plugin.py | Editor.report_open_file | def report_open_file(self, options):
"""Request to start a LSP server to attend a language."""
filename = options['filename']
logger.debug('Call LSP for %s' % filename)
language = options['language']
callback = options['codeeditor']
stat = self.main.lspmanager.start_client(language.lower())
self.main.lspmanager.register_file(
language.lower(), filename, callback)
if stat:
if language.lower() in self.lsp_editor_settings:
self.lsp_server_ready(
language.lower(), self.lsp_editor_settings[
language.lower()])
else:
editor = self.get_current_editor()
editor.lsp_ready = False | python | def report_open_file(self, options):
"""Request to start a LSP server to attend a language."""
filename = options['filename']
logger.debug('Call LSP for %s' % filename)
language = options['language']
callback = options['codeeditor']
stat = self.main.lspmanager.start_client(language.lower())
self.main.lspmanager.register_file(
language.lower(), filename, callback)
if stat:
if language.lower() in self.lsp_editor_settings:
self.lsp_server_ready(
language.lower(), self.lsp_editor_settings[
language.lower()])
else:
editor = self.get_current_editor()
editor.lsp_ready = False | [
"def",
"report_open_file",
"(",
"self",
",",
"options",
")",
":",
"filename",
"=",
"options",
"[",
"'filename'",
"]",
"logger",
".",
"debug",
"(",
"'Call LSP for %s'",
"%",
"filename",
")",
"language",
"=",
"options",
"[",
"'language'",
"]",
"callback",
"=",
"options",
"[",
"'codeeditor'",
"]",
"stat",
"=",
"self",
".",
"main",
".",
"lspmanager",
".",
"start_client",
"(",
"language",
".",
"lower",
"(",
")",
")",
"self",
".",
"main",
".",
"lspmanager",
".",
"register_file",
"(",
"language",
".",
"lower",
"(",
")",
",",
"filename",
",",
"callback",
")",
"if",
"stat",
":",
"if",
"language",
".",
"lower",
"(",
")",
"in",
"self",
".",
"lsp_editor_settings",
":",
"self",
".",
"lsp_server_ready",
"(",
"language",
".",
"lower",
"(",
")",
",",
"self",
".",
"lsp_editor_settings",
"[",
"language",
".",
"lower",
"(",
")",
"]",
")",
"else",
":",
"editor",
"=",
"self",
".",
"get_current_editor",
"(",
")",
"editor",
".",
"lsp_ready",
"=",
"False"
] | Request to start a LSP server to attend a language. | [
"Request",
"to",
"start",
"a",
"LSP",
"server",
"to",
"attend",
"a",
"language",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/plugin.py#L275-L291 | train |
spyder-ide/spyder | spyder/plugins/editor/plugin.py | Editor.register_lsp_server_settings | def register_lsp_server_settings(self, settings, language):
"""Register LSP server settings."""
self.lsp_editor_settings[language] = settings
logger.debug('LSP server settings for {!s} are: {!r}'.format(
language, settings))
self.lsp_server_ready(language, self.lsp_editor_settings[language]) | python | def register_lsp_server_settings(self, settings, language):
"""Register LSP server settings."""
self.lsp_editor_settings[language] = settings
logger.debug('LSP server settings for {!s} are: {!r}'.format(
language, settings))
self.lsp_server_ready(language, self.lsp_editor_settings[language]) | [
"def",
"register_lsp_server_settings",
"(",
"self",
",",
"settings",
",",
"language",
")",
":",
"self",
".",
"lsp_editor_settings",
"[",
"language",
"]",
"=",
"settings",
"logger",
".",
"debug",
"(",
"'LSP server settings for {!s} are: {!r}'",
".",
"format",
"(",
"language",
",",
"settings",
")",
")",
"self",
".",
"lsp_server_ready",
"(",
"language",
",",
"self",
".",
"lsp_editor_settings",
"[",
"language",
"]",
")"
] | Register LSP server settings. | [
"Register",
"LSP",
"server",
"settings",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/plugin.py#L294-L299 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.