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/variableexplorer/widgets/collectionseditor.py | CollectionsEditor.save_and_close_enable | def save_and_close_enable(self):
"""Handle the data change event to enable the save and close button."""
if self.btn_save_and_close:
self.btn_save_and_close.setEnabled(True)
self.btn_save_and_close.setAutoDefault(True)
self.btn_save_and_close.setDefault(True) | python | def save_and_close_enable(self):
"""Handle the data change event to enable the save and close button."""
if self.btn_save_and_close:
self.btn_save_and_close.setEnabled(True)
self.btn_save_and_close.setAutoDefault(True)
self.btn_save_and_close.setDefault(True) | [
"def",
"save_and_close_enable",
"(",
"self",
")",
":",
"if",
"self",
".",
"btn_save_and_close",
":",
"self",
".",
"btn_save_and_close",
".",
"setEnabled",
"(",
"True",
")",
"self",
".",
"btn_save_and_close",
".",
"setAutoDefault",
"(",
"True",
")",
"self",
".",
"btn_save_and_close",
".",
"setDefault",
"(",
"True",
")"
] | Handle the data change event to enable the save and close button. | [
"Handle",
"the",
"data",
"change",
"event",
"to",
"enable",
"the",
"save",
"and",
"close",
"button",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/collectionseditor.py#L1500-L1505 | train |
spyder-ide/spyder | spyder/plugins/variableexplorer/widgets/collectionseditor.py | RemoteCollectionsEditorTableView.get_value | def get_value(self, name):
"""Get the value of a variable"""
value = self.shellwidget.get_value(name)
# Reset temporal variable where value is saved to
# save memory
self.shellwidget._kernel_value = None
return value | python | def get_value(self, name):
"""Get the value of a variable"""
value = self.shellwidget.get_value(name)
# Reset temporal variable where value is saved to
# save memory
self.shellwidget._kernel_value = None
return value | [
"def",
"get_value",
"(",
"self",
",",
"name",
")",
":",
"value",
"=",
"self",
".",
"shellwidget",
".",
"get_value",
"(",
"name",
")",
"# Reset temporal variable where value is saved to\r",
"# save memory\r",
"self",
".",
"shellwidget",
".",
"_kernel_value",
"=",
"None",
"return",
"value"
] | Get the value of a variable | [
"Get",
"the",
"value",
"of",
"a",
"variable"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/collectionseditor.py#L1560-L1566 | train |
spyder-ide/spyder | spyder/plugins/variableexplorer/widgets/collectionseditor.py | RemoteCollectionsEditorTableView.new_value | def new_value(self, name, value):
"""Create new value in data"""
try:
# We need to enclose values in a list to be able to send
# them to the kernel in Python 2
svalue = [cloudpickle.dumps(value, protocol=PICKLE_PROTOCOL)]
# Needed to prevent memory leaks. See issue 7158
if len(svalue) < MAX_SERIALIZED_LENGHT:
self.shellwidget.set_value(name, svalue)
else:
QMessageBox.warning(self, _("Warning"),
_("The object you are trying to modify is "
"too big to be sent back to the kernel. "
"Therefore, your modifications won't "
"take place."))
except TypeError as e:
QMessageBox.critical(self, _("Error"),
"TypeError: %s" % to_text_string(e))
self.shellwidget.refresh_namespacebrowser() | python | def new_value(self, name, value):
"""Create new value in data"""
try:
# We need to enclose values in a list to be able to send
# them to the kernel in Python 2
svalue = [cloudpickle.dumps(value, protocol=PICKLE_PROTOCOL)]
# Needed to prevent memory leaks. See issue 7158
if len(svalue) < MAX_SERIALIZED_LENGHT:
self.shellwidget.set_value(name, svalue)
else:
QMessageBox.warning(self, _("Warning"),
_("The object you are trying to modify is "
"too big to be sent back to the kernel. "
"Therefore, your modifications won't "
"take place."))
except TypeError as e:
QMessageBox.critical(self, _("Error"),
"TypeError: %s" % to_text_string(e))
self.shellwidget.refresh_namespacebrowser() | [
"def",
"new_value",
"(",
"self",
",",
"name",
",",
"value",
")",
":",
"try",
":",
"# We need to enclose values in a list to be able to send\r",
"# them to the kernel in Python 2\r",
"svalue",
"=",
"[",
"cloudpickle",
".",
"dumps",
"(",
"value",
",",
"protocol",
"=",
"PICKLE_PROTOCOL",
")",
"]",
"# Needed to prevent memory leaks. See issue 7158\r",
"if",
"len",
"(",
"svalue",
")",
"<",
"MAX_SERIALIZED_LENGHT",
":",
"self",
".",
"shellwidget",
".",
"set_value",
"(",
"name",
",",
"svalue",
")",
"else",
":",
"QMessageBox",
".",
"warning",
"(",
"self",
",",
"_",
"(",
"\"Warning\"",
")",
",",
"_",
"(",
"\"The object you are trying to modify is \"",
"\"too big to be sent back to the kernel. \"",
"\"Therefore, your modifications won't \"",
"\"take place.\"",
")",
")",
"except",
"TypeError",
"as",
"e",
":",
"QMessageBox",
".",
"critical",
"(",
"self",
",",
"_",
"(",
"\"Error\"",
")",
",",
"\"TypeError: %s\"",
"%",
"to_text_string",
"(",
"e",
")",
")",
"self",
".",
"shellwidget",
".",
"refresh_namespacebrowser",
"(",
")"
] | Create new value in data | [
"Create",
"new",
"value",
"in",
"data"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/collectionseditor.py#L1568-L1587 | train |
spyder-ide/spyder | spyder/plugins/variableexplorer/widgets/collectionseditor.py | RemoteCollectionsEditorTableView.remove_values | def remove_values(self, names):
"""Remove values from data"""
for name in names:
self.shellwidget.remove_value(name)
self.shellwidget.refresh_namespacebrowser() | python | def remove_values(self, names):
"""Remove values from data"""
for name in names:
self.shellwidget.remove_value(name)
self.shellwidget.refresh_namespacebrowser() | [
"def",
"remove_values",
"(",
"self",
",",
"names",
")",
":",
"for",
"name",
"in",
"names",
":",
"self",
".",
"shellwidget",
".",
"remove_value",
"(",
"name",
")",
"self",
".",
"shellwidget",
".",
"refresh_namespacebrowser",
"(",
")"
] | Remove values from data | [
"Remove",
"values",
"from",
"data"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/collectionseditor.py#L1589-L1593 | train |
spyder-ide/spyder | spyder/plugins/variableexplorer/widgets/collectionseditor.py | RemoteCollectionsEditorTableView.copy_value | def copy_value(self, orig_name, new_name):
"""Copy value"""
self.shellwidget.copy_value(orig_name, new_name)
self.shellwidget.refresh_namespacebrowser() | python | def copy_value(self, orig_name, new_name):
"""Copy value"""
self.shellwidget.copy_value(orig_name, new_name)
self.shellwidget.refresh_namespacebrowser() | [
"def",
"copy_value",
"(",
"self",
",",
"orig_name",
",",
"new_name",
")",
":",
"self",
".",
"shellwidget",
".",
"copy_value",
"(",
"orig_name",
",",
"new_name",
")",
"self",
".",
"shellwidget",
".",
"refresh_namespacebrowser",
"(",
")"
] | Copy value | [
"Copy",
"value"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/collectionseditor.py#L1595-L1598 | train |
spyder-ide/spyder | spyder/plugins/variableexplorer/widgets/collectionseditor.py | RemoteCollectionsEditorTableView.plot | def plot(self, name, funcname):
"""Plot item"""
sw = self.shellwidget
if sw._reading:
sw.dbg_exec_magic('varexp', '--%s %s' % (funcname, name))
else:
sw.execute("%%varexp --%s %s" % (funcname, name)) | python | def plot(self, name, funcname):
"""Plot item"""
sw = self.shellwidget
if sw._reading:
sw.dbg_exec_magic('varexp', '--%s %s' % (funcname, name))
else:
sw.execute("%%varexp --%s %s" % (funcname, name)) | [
"def",
"plot",
"(",
"self",
",",
"name",
",",
"funcname",
")",
":",
"sw",
"=",
"self",
".",
"shellwidget",
"if",
"sw",
".",
"_reading",
":",
"sw",
".",
"dbg_exec_magic",
"(",
"'varexp'",
",",
"'--%s %s'",
"%",
"(",
"funcname",
",",
"name",
")",
")",
"else",
":",
"sw",
".",
"execute",
"(",
"\"%%varexp --%s %s\"",
"%",
"(",
"funcname",
",",
"name",
")",
")"
] | Plot item | [
"Plot",
"item"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/collectionseditor.py#L1636-L1642 | train |
spyder-ide/spyder | spyder/plugins/variableexplorer/widgets/collectionseditor.py | RemoteCollectionsEditorTableView.imshow | def imshow(self, name):
"""Show item's image"""
sw = self.shellwidget
if sw._reading:
sw.dbg_exec_magic('varexp', '--imshow %s' % name)
else:
sw.execute("%%varexp --imshow %s" % name) | python | def imshow(self, name):
"""Show item's image"""
sw = self.shellwidget
if sw._reading:
sw.dbg_exec_magic('varexp', '--imshow %s' % name)
else:
sw.execute("%%varexp --imshow %s" % name) | [
"def",
"imshow",
"(",
"self",
",",
"name",
")",
":",
"sw",
"=",
"self",
".",
"shellwidget",
"if",
"sw",
".",
"_reading",
":",
"sw",
".",
"dbg_exec_magic",
"(",
"'varexp'",
",",
"'--imshow %s'",
"%",
"name",
")",
"else",
":",
"sw",
".",
"execute",
"(",
"\"%%varexp --imshow %s\"",
"%",
"name",
")"
] | Show item's image | [
"Show",
"item",
"s",
"image"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/collectionseditor.py#L1644-L1650 | train |
spyder-ide/spyder | spyder/plugins/variableexplorer/widgets/collectionseditor.py | RemoteCollectionsEditorTableView.show_image | def show_image(self, name):
"""Show image (item is a PIL image)"""
command = "%s.show()" % name
sw = self.shellwidget
if sw._reading:
sw.kernel_client.input(command)
else:
sw.execute(command) | python | def show_image(self, name):
"""Show image (item is a PIL image)"""
command = "%s.show()" % name
sw = self.shellwidget
if sw._reading:
sw.kernel_client.input(command)
else:
sw.execute(command) | [
"def",
"show_image",
"(",
"self",
",",
"name",
")",
":",
"command",
"=",
"\"%s.show()\"",
"%",
"name",
"sw",
"=",
"self",
".",
"shellwidget",
"if",
"sw",
".",
"_reading",
":",
"sw",
".",
"kernel_client",
".",
"input",
"(",
"command",
")",
"else",
":",
"sw",
".",
"execute",
"(",
"command",
")"
] | Show image (item is a PIL image) | [
"Show",
"image",
"(",
"item",
"is",
"a",
"PIL",
"image",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/collectionseditor.py#L1652-L1659 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.kernel_id | def kernel_id(self):
"""Get kernel id"""
if self.connection_file is not None:
json_file = osp.basename(self.connection_file)
return json_file.split('.json')[0] | python | def kernel_id(self):
"""Get kernel id"""
if self.connection_file is not None:
json_file = osp.basename(self.connection_file)
return json_file.split('.json')[0] | [
"def",
"kernel_id",
"(",
"self",
")",
":",
"if",
"self",
".",
"connection_file",
"is",
"not",
"None",
":",
"json_file",
"=",
"osp",
".",
"basename",
"(",
"self",
".",
"connection_file",
")",
"return",
"json_file",
".",
"split",
"(",
"'.json'",
")",
"[",
"0",
"]"
] | Get kernel id | [
"Get",
"kernel",
"id"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L194-L198 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.stderr_file | def stderr_file(self):
"""Filename to save kernel stderr output."""
stderr_file = None
if self.connection_file is not None:
stderr_file = self.kernel_id + '.stderr'
if self.stderr_dir is not None:
stderr_file = osp.join(self.stderr_dir, stderr_file)
else:
try:
stderr_file = osp.join(get_temp_dir(), stderr_file)
except (IOError, OSError):
stderr_file = None
return stderr_file | python | def stderr_file(self):
"""Filename to save kernel stderr output."""
stderr_file = None
if self.connection_file is not None:
stderr_file = self.kernel_id + '.stderr'
if self.stderr_dir is not None:
stderr_file = osp.join(self.stderr_dir, stderr_file)
else:
try:
stderr_file = osp.join(get_temp_dir(), stderr_file)
except (IOError, OSError):
stderr_file = None
return stderr_file | [
"def",
"stderr_file",
"(",
"self",
")",
":",
"stderr_file",
"=",
"None",
"if",
"self",
".",
"connection_file",
"is",
"not",
"None",
":",
"stderr_file",
"=",
"self",
".",
"kernel_id",
"+",
"'.stderr'",
"if",
"self",
".",
"stderr_dir",
"is",
"not",
"None",
":",
"stderr_file",
"=",
"osp",
".",
"join",
"(",
"self",
".",
"stderr_dir",
",",
"stderr_file",
")",
"else",
":",
"try",
":",
"stderr_file",
"=",
"osp",
".",
"join",
"(",
"get_temp_dir",
"(",
")",
",",
"stderr_file",
")",
"except",
"(",
"IOError",
",",
"OSError",
")",
":",
"stderr_file",
"=",
"None",
"return",
"stderr_file"
] | Filename to save kernel stderr output. | [
"Filename",
"to",
"save",
"kernel",
"stderr",
"output",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L201-L213 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.stderr_handle | def stderr_handle(self):
"""Get handle to stderr_file."""
if self.stderr_file is not None:
# Needed to prevent any error that could appear.
# See issue 6267
try:
handle = codecs.open(self.stderr_file, 'w', encoding='utf-8')
except Exception:
handle = None
else:
handle = None
return handle | python | def stderr_handle(self):
"""Get handle to stderr_file."""
if self.stderr_file is not None:
# Needed to prevent any error that could appear.
# See issue 6267
try:
handle = codecs.open(self.stderr_file, 'w', encoding='utf-8')
except Exception:
handle = None
else:
handle = None
return handle | [
"def",
"stderr_handle",
"(",
"self",
")",
":",
"if",
"self",
".",
"stderr_file",
"is",
"not",
"None",
":",
"# Needed to prevent any error that could appear.\r",
"# See issue 6267\r",
"try",
":",
"handle",
"=",
"codecs",
".",
"open",
"(",
"self",
".",
"stderr_file",
",",
"'w'",
",",
"encoding",
"=",
"'utf-8'",
")",
"except",
"Exception",
":",
"handle",
"=",
"None",
"else",
":",
"handle",
"=",
"None",
"return",
"handle"
] | Get handle to stderr_file. | [
"Get",
"handle",
"to",
"stderr_file",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L216-L228 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.remove_stderr_file | def remove_stderr_file(self):
"""Remove stderr_file associated with the client."""
try:
# Defer closing the stderr_handle until the client
# is closed because jupyter_client needs it open
# while it tries to restart the kernel
self.stderr_handle.close()
os.remove(self.stderr_file)
except Exception:
pass | python | def remove_stderr_file(self):
"""Remove stderr_file associated with the client."""
try:
# Defer closing the stderr_handle until the client
# is closed because jupyter_client needs it open
# while it tries to restart the kernel
self.stderr_handle.close()
os.remove(self.stderr_file)
except Exception:
pass | [
"def",
"remove_stderr_file",
"(",
"self",
")",
":",
"try",
":",
"# Defer closing the stderr_handle until the client\r",
"# is closed because jupyter_client needs it open\r",
"# while it tries to restart the kernel\r",
"self",
".",
"stderr_handle",
".",
"close",
"(",
")",
"os",
".",
"remove",
"(",
"self",
".",
"stderr_file",
")",
"except",
"Exception",
":",
"pass"
] | Remove stderr_file associated with the client. | [
"Remove",
"stderr_file",
"associated",
"with",
"the",
"client",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L230-L239 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.configure_shellwidget | def configure_shellwidget(self, give_focus=True):
"""Configure shellwidget after kernel is started"""
if give_focus:
self.get_control().setFocus()
# Set exit callback
self.shellwidget.set_exit_callback()
# To save history
self.shellwidget.executing.connect(self.add_to_history)
# For Mayavi to run correctly
self.shellwidget.executing.connect(
self.shellwidget.set_backend_for_mayavi)
# To update history after execution
self.shellwidget.executed.connect(self.update_history)
# To update the Variable Explorer after execution
self.shellwidget.executed.connect(
self.shellwidget.refresh_namespacebrowser)
# To enable the stop button when executing a process
self.shellwidget.executing.connect(self.enable_stop_button)
# To disable the stop button after execution stopped
self.shellwidget.executed.connect(self.disable_stop_button)
# To show kernel restarted/died messages
self.shellwidget.sig_kernel_restarted.connect(
self.kernel_restarted_message)
# To correctly change Matplotlib backend interactively
self.shellwidget.executing.connect(
self.shellwidget.change_mpl_backend)
# To show env and sys.path contents
self.shellwidget.sig_show_syspath.connect(self.show_syspath)
self.shellwidget.sig_show_env.connect(self.show_env)
# To sync with working directory toolbar
self.shellwidget.executed.connect(self.shellwidget.get_cwd)
# To apply style
self.set_color_scheme(self.shellwidget.syntax_style, reset=False)
# To hide the loading page
self.shellwidget.sig_prompt_ready.connect(self._hide_loading_page)
# Show possible errors when setting Matplotlib backend
self.shellwidget.sig_prompt_ready.connect(
self._show_mpl_backend_errors) | python | def configure_shellwidget(self, give_focus=True):
"""Configure shellwidget after kernel is started"""
if give_focus:
self.get_control().setFocus()
# Set exit callback
self.shellwidget.set_exit_callback()
# To save history
self.shellwidget.executing.connect(self.add_to_history)
# For Mayavi to run correctly
self.shellwidget.executing.connect(
self.shellwidget.set_backend_for_mayavi)
# To update history after execution
self.shellwidget.executed.connect(self.update_history)
# To update the Variable Explorer after execution
self.shellwidget.executed.connect(
self.shellwidget.refresh_namespacebrowser)
# To enable the stop button when executing a process
self.shellwidget.executing.connect(self.enable_stop_button)
# To disable the stop button after execution stopped
self.shellwidget.executed.connect(self.disable_stop_button)
# To show kernel restarted/died messages
self.shellwidget.sig_kernel_restarted.connect(
self.kernel_restarted_message)
# To correctly change Matplotlib backend interactively
self.shellwidget.executing.connect(
self.shellwidget.change_mpl_backend)
# To show env and sys.path contents
self.shellwidget.sig_show_syspath.connect(self.show_syspath)
self.shellwidget.sig_show_env.connect(self.show_env)
# To sync with working directory toolbar
self.shellwidget.executed.connect(self.shellwidget.get_cwd)
# To apply style
self.set_color_scheme(self.shellwidget.syntax_style, reset=False)
# To hide the loading page
self.shellwidget.sig_prompt_ready.connect(self._hide_loading_page)
# Show possible errors when setting Matplotlib backend
self.shellwidget.sig_prompt_ready.connect(
self._show_mpl_backend_errors) | [
"def",
"configure_shellwidget",
"(",
"self",
",",
"give_focus",
"=",
"True",
")",
":",
"if",
"give_focus",
":",
"self",
".",
"get_control",
"(",
")",
".",
"setFocus",
"(",
")",
"# Set exit callback\r",
"self",
".",
"shellwidget",
".",
"set_exit_callback",
"(",
")",
"# To save history\r",
"self",
".",
"shellwidget",
".",
"executing",
".",
"connect",
"(",
"self",
".",
"add_to_history",
")",
"# For Mayavi to run correctly\r",
"self",
".",
"shellwidget",
".",
"executing",
".",
"connect",
"(",
"self",
".",
"shellwidget",
".",
"set_backend_for_mayavi",
")",
"# To update history after execution\r",
"self",
".",
"shellwidget",
".",
"executed",
".",
"connect",
"(",
"self",
".",
"update_history",
")",
"# To update the Variable Explorer after execution\r",
"self",
".",
"shellwidget",
".",
"executed",
".",
"connect",
"(",
"self",
".",
"shellwidget",
".",
"refresh_namespacebrowser",
")",
"# To enable the stop button when executing a process\r",
"self",
".",
"shellwidget",
".",
"executing",
".",
"connect",
"(",
"self",
".",
"enable_stop_button",
")",
"# To disable the stop button after execution stopped\r",
"self",
".",
"shellwidget",
".",
"executed",
".",
"connect",
"(",
"self",
".",
"disable_stop_button",
")",
"# To show kernel restarted/died messages\r",
"self",
".",
"shellwidget",
".",
"sig_kernel_restarted",
".",
"connect",
"(",
"self",
".",
"kernel_restarted_message",
")",
"# To correctly change Matplotlib backend interactively\r",
"self",
".",
"shellwidget",
".",
"executing",
".",
"connect",
"(",
"self",
".",
"shellwidget",
".",
"change_mpl_backend",
")",
"# To show env and sys.path contents\r",
"self",
".",
"shellwidget",
".",
"sig_show_syspath",
".",
"connect",
"(",
"self",
".",
"show_syspath",
")",
"self",
".",
"shellwidget",
".",
"sig_show_env",
".",
"connect",
"(",
"self",
".",
"show_env",
")",
"# To sync with working directory toolbar\r",
"self",
".",
"shellwidget",
".",
"executed",
".",
"connect",
"(",
"self",
".",
"shellwidget",
".",
"get_cwd",
")",
"# To apply style\r",
"self",
".",
"set_color_scheme",
"(",
"self",
".",
"shellwidget",
".",
"syntax_style",
",",
"reset",
"=",
"False",
")",
"# To hide the loading page\r",
"self",
".",
"shellwidget",
".",
"sig_prompt_ready",
".",
"connect",
"(",
"self",
".",
"_hide_loading_page",
")",
"# Show possible errors when setting Matplotlib backend\r",
"self",
".",
"shellwidget",
".",
"sig_prompt_ready",
".",
"connect",
"(",
"self",
".",
"_show_mpl_backend_errors",
")"
] | Configure shellwidget after kernel is started | [
"Configure",
"shellwidget",
"after",
"kernel",
"is",
"started"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L241-L292 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.stop_button_click_handler | def stop_button_click_handler(self):
"""Method to handle what to do when the stop button is pressed"""
self.stop_button.setDisabled(True)
# Interrupt computations or stop debugging
if not self.shellwidget._reading:
self.interrupt_kernel()
else:
self.shellwidget.write_to_stdin('exit') | python | def stop_button_click_handler(self):
"""Method to handle what to do when the stop button is pressed"""
self.stop_button.setDisabled(True)
# Interrupt computations or stop debugging
if not self.shellwidget._reading:
self.interrupt_kernel()
else:
self.shellwidget.write_to_stdin('exit') | [
"def",
"stop_button_click_handler",
"(",
"self",
")",
":",
"self",
".",
"stop_button",
".",
"setDisabled",
"(",
"True",
")",
"# Interrupt computations or stop debugging\r",
"if",
"not",
"self",
".",
"shellwidget",
".",
"_reading",
":",
"self",
".",
"interrupt_kernel",
"(",
")",
"else",
":",
"self",
".",
"shellwidget",
".",
"write_to_stdin",
"(",
"'exit'",
")"
] | Method to handle what to do when the stop button is pressed | [
"Method",
"to",
"handle",
"what",
"to",
"do",
"when",
"the",
"stop",
"button",
"is",
"pressed"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L305-L312 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.show_kernel_error | def show_kernel_error(self, error):
"""Show kernel initialization errors in infowidget."""
# Replace end of line chars with <br>
eol = sourcecode.get_eol_chars(error)
if eol:
error = error.replace(eol, '<br>')
# Don't break lines in hyphens
# From https://stackoverflow.com/q/7691569/438386
error = error.replace('-', '‑')
# Create error page
message = _("An error ocurred while starting the kernel")
kernel_error_template = Template(KERNEL_ERROR)
self.info_page = kernel_error_template.substitute(
css_path=self.css_path,
message=message,
error=error)
# Show error
self.set_info_page()
self.shellwidget.hide()
self.infowidget.show()
# Tell the client we're in error mode
self.is_error_shown = True | python | def show_kernel_error(self, error):
"""Show kernel initialization errors in infowidget."""
# Replace end of line chars with <br>
eol = sourcecode.get_eol_chars(error)
if eol:
error = error.replace(eol, '<br>')
# Don't break lines in hyphens
# From https://stackoverflow.com/q/7691569/438386
error = error.replace('-', '‑')
# Create error page
message = _("An error ocurred while starting the kernel")
kernel_error_template = Template(KERNEL_ERROR)
self.info_page = kernel_error_template.substitute(
css_path=self.css_path,
message=message,
error=error)
# Show error
self.set_info_page()
self.shellwidget.hide()
self.infowidget.show()
# Tell the client we're in error mode
self.is_error_shown = True | [
"def",
"show_kernel_error",
"(",
"self",
",",
"error",
")",
":",
"# Replace end of line chars with <br>\r",
"eol",
"=",
"sourcecode",
".",
"get_eol_chars",
"(",
"error",
")",
"if",
"eol",
":",
"error",
"=",
"error",
".",
"replace",
"(",
"eol",
",",
"'<br>'",
")",
"# Don't break lines in hyphens\r",
"# From https://stackoverflow.com/q/7691569/438386\r",
"error",
"=",
"error",
".",
"replace",
"(",
"'-'",
",",
"'‑'",
")",
"# Create error page\r",
"message",
"=",
"_",
"(",
"\"An error ocurred while starting the kernel\"",
")",
"kernel_error_template",
"=",
"Template",
"(",
"KERNEL_ERROR",
")",
"self",
".",
"info_page",
"=",
"kernel_error_template",
".",
"substitute",
"(",
"css_path",
"=",
"self",
".",
"css_path",
",",
"message",
"=",
"message",
",",
"error",
"=",
"error",
")",
"# Show error\r",
"self",
".",
"set_info_page",
"(",
")",
"self",
".",
"shellwidget",
".",
"hide",
"(",
")",
"self",
".",
"infowidget",
".",
"show",
"(",
")",
"# Tell the client we're in error mode\r",
"self",
".",
"is_error_shown",
"=",
"True"
] | Show kernel initialization errors in infowidget. | [
"Show",
"kernel",
"initialization",
"errors",
"in",
"infowidget",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L314-L339 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.get_name | def get_name(self):
"""Return client name"""
if self.given_name is None:
# Name according to host
if self.hostname is None:
name = _("Console")
else:
name = self.hostname
# Adding id to name
client_id = self.id_['int_id'] + u'/' + self.id_['str_id']
name = name + u' ' + client_id
elif self.given_name in ["Pylab", "SymPy", "Cython"]:
client_id = self.id_['int_id'] + u'/' + self.id_['str_id']
name = self.given_name + u' ' + client_id
else:
name = self.given_name + u'/' + self.id_['str_id']
return name | python | def get_name(self):
"""Return client name"""
if self.given_name is None:
# Name according to host
if self.hostname is None:
name = _("Console")
else:
name = self.hostname
# Adding id to name
client_id = self.id_['int_id'] + u'/' + self.id_['str_id']
name = name + u' ' + client_id
elif self.given_name in ["Pylab", "SymPy", "Cython"]:
client_id = self.id_['int_id'] + u'/' + self.id_['str_id']
name = self.given_name + u' ' + client_id
else:
name = self.given_name + u'/' + self.id_['str_id']
return name | [
"def",
"get_name",
"(",
"self",
")",
":",
"if",
"self",
".",
"given_name",
"is",
"None",
":",
"# Name according to host\r",
"if",
"self",
".",
"hostname",
"is",
"None",
":",
"name",
"=",
"_",
"(",
"\"Console\"",
")",
"else",
":",
"name",
"=",
"self",
".",
"hostname",
"# Adding id to name\r",
"client_id",
"=",
"self",
".",
"id_",
"[",
"'int_id'",
"]",
"+",
"u'/'",
"+",
"self",
".",
"id_",
"[",
"'str_id'",
"]",
"name",
"=",
"name",
"+",
"u' '",
"+",
"client_id",
"elif",
"self",
".",
"given_name",
"in",
"[",
"\"Pylab\"",
",",
"\"SymPy\"",
",",
"\"Cython\"",
"]",
":",
"client_id",
"=",
"self",
".",
"id_",
"[",
"'int_id'",
"]",
"+",
"u'/'",
"+",
"self",
".",
"id_",
"[",
"'str_id'",
"]",
"name",
"=",
"self",
".",
"given_name",
"+",
"u' '",
"+",
"client_id",
"else",
":",
"name",
"=",
"self",
".",
"given_name",
"+",
"u'/'",
"+",
"self",
".",
"id_",
"[",
"'str_id'",
"]",
"return",
"name"
] | Return client name | [
"Return",
"client",
"name"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L341-L357 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.get_control | def get_control(self):
"""Return the text widget (or similar) to give focus to"""
# page_control is the widget used for paging
page_control = self.shellwidget._page_control
if page_control and page_control.isVisible():
return page_control
else:
return self.shellwidget._control | python | def get_control(self):
"""Return the text widget (or similar) to give focus to"""
# page_control is the widget used for paging
page_control = self.shellwidget._page_control
if page_control and page_control.isVisible():
return page_control
else:
return self.shellwidget._control | [
"def",
"get_control",
"(",
"self",
")",
":",
"# page_control is the widget used for paging\r",
"page_control",
"=",
"self",
".",
"shellwidget",
".",
"_page_control",
"if",
"page_control",
"and",
"page_control",
".",
"isVisible",
"(",
")",
":",
"return",
"page_control",
"else",
":",
"return",
"self",
".",
"shellwidget",
".",
"_control"
] | Return the text widget (or similar) to give focus to | [
"Return",
"the",
"text",
"widget",
"(",
"or",
"similar",
")",
"to",
"give",
"focus",
"to"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L359-L366 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.get_options_menu | def get_options_menu(self):
"""Return options menu"""
env_action = create_action(
self,
_("Show environment variables"),
icon=ima.icon('environ'),
triggered=self.shellwidget.get_env
)
syspath_action = create_action(
self,
_("Show sys.path contents"),
icon=ima.icon('syspath'),
triggered=self.shellwidget.get_syspath
)
self.show_time_action.setChecked(self.show_elapsed_time)
additional_actions = [MENU_SEPARATOR,
env_action,
syspath_action,
self.show_time_action]
if self.menu_actions is not None:
console_menu = self.menu_actions + additional_actions
return console_menu
else:
return additional_actions | python | def get_options_menu(self):
"""Return options menu"""
env_action = create_action(
self,
_("Show environment variables"),
icon=ima.icon('environ'),
triggered=self.shellwidget.get_env
)
syspath_action = create_action(
self,
_("Show sys.path contents"),
icon=ima.icon('syspath'),
triggered=self.shellwidget.get_syspath
)
self.show_time_action.setChecked(self.show_elapsed_time)
additional_actions = [MENU_SEPARATOR,
env_action,
syspath_action,
self.show_time_action]
if self.menu_actions is not None:
console_menu = self.menu_actions + additional_actions
return console_menu
else:
return additional_actions | [
"def",
"get_options_menu",
"(",
"self",
")",
":",
"env_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Show environment variables\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'environ'",
")",
",",
"triggered",
"=",
"self",
".",
"shellwidget",
".",
"get_env",
")",
"syspath_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Show sys.path contents\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'syspath'",
")",
",",
"triggered",
"=",
"self",
".",
"shellwidget",
".",
"get_syspath",
")",
"self",
".",
"show_time_action",
".",
"setChecked",
"(",
"self",
".",
"show_elapsed_time",
")",
"additional_actions",
"=",
"[",
"MENU_SEPARATOR",
",",
"env_action",
",",
"syspath_action",
",",
"self",
".",
"show_time_action",
"]",
"if",
"self",
".",
"menu_actions",
"is",
"not",
"None",
":",
"console_menu",
"=",
"self",
".",
"menu_actions",
"+",
"additional_actions",
"return",
"console_menu",
"else",
":",
"return",
"additional_actions"
] | Return options menu | [
"Return",
"options",
"menu"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L372-L399 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.get_toolbar_buttons | def get_toolbar_buttons(self):
"""Return toolbar buttons list."""
buttons = []
# Code to add the stop button
if self.stop_button is None:
self.stop_button = create_toolbutton(
self,
text=_("Stop"),
icon=self.stop_icon,
tip=_("Stop the current command"))
self.disable_stop_button()
# set click event handler
self.stop_button.clicked.connect(self.stop_button_click_handler)
if is_dark_interface():
self.stop_button.setStyleSheet("QToolButton{padding: 3px;}")
if self.stop_button is not None:
buttons.append(self.stop_button)
# Reset namespace button
if self.reset_button is None:
self.reset_button = create_toolbutton(
self,
text=_("Remove"),
icon=ima.icon('editdelete'),
tip=_("Remove all variables"),
triggered=self.reset_namespace)
if is_dark_interface():
self.reset_button.setStyleSheet("QToolButton{padding: 3px;}")
if self.reset_button is not None:
buttons.append(self.reset_button)
if self.options_button is None:
options = self.get_options_menu()
if options:
self.options_button = create_toolbutton(self,
text=_('Options'), icon=ima.icon('tooloptions'))
self.options_button.setPopupMode(QToolButton.InstantPopup)
menu = QMenu(self)
add_actions(menu, options)
self.options_button.setMenu(menu)
if self.options_button is not None:
buttons.append(self.options_button)
return buttons | python | def get_toolbar_buttons(self):
"""Return toolbar buttons list."""
buttons = []
# Code to add the stop button
if self.stop_button is None:
self.stop_button = create_toolbutton(
self,
text=_("Stop"),
icon=self.stop_icon,
tip=_("Stop the current command"))
self.disable_stop_button()
# set click event handler
self.stop_button.clicked.connect(self.stop_button_click_handler)
if is_dark_interface():
self.stop_button.setStyleSheet("QToolButton{padding: 3px;}")
if self.stop_button is not None:
buttons.append(self.stop_button)
# Reset namespace button
if self.reset_button is None:
self.reset_button = create_toolbutton(
self,
text=_("Remove"),
icon=ima.icon('editdelete'),
tip=_("Remove all variables"),
triggered=self.reset_namespace)
if is_dark_interface():
self.reset_button.setStyleSheet("QToolButton{padding: 3px;}")
if self.reset_button is not None:
buttons.append(self.reset_button)
if self.options_button is None:
options = self.get_options_menu()
if options:
self.options_button = create_toolbutton(self,
text=_('Options'), icon=ima.icon('tooloptions'))
self.options_button.setPopupMode(QToolButton.InstantPopup)
menu = QMenu(self)
add_actions(menu, options)
self.options_button.setMenu(menu)
if self.options_button is not None:
buttons.append(self.options_button)
return buttons | [
"def",
"get_toolbar_buttons",
"(",
"self",
")",
":",
"buttons",
"=",
"[",
"]",
"# Code to add the stop button\r",
"if",
"self",
".",
"stop_button",
"is",
"None",
":",
"self",
".",
"stop_button",
"=",
"create_toolbutton",
"(",
"self",
",",
"text",
"=",
"_",
"(",
"\"Stop\"",
")",
",",
"icon",
"=",
"self",
".",
"stop_icon",
",",
"tip",
"=",
"_",
"(",
"\"Stop the current command\"",
")",
")",
"self",
".",
"disable_stop_button",
"(",
")",
"# set click event handler\r",
"self",
".",
"stop_button",
".",
"clicked",
".",
"connect",
"(",
"self",
".",
"stop_button_click_handler",
")",
"if",
"is_dark_interface",
"(",
")",
":",
"self",
".",
"stop_button",
".",
"setStyleSheet",
"(",
"\"QToolButton{padding: 3px;}\"",
")",
"if",
"self",
".",
"stop_button",
"is",
"not",
"None",
":",
"buttons",
".",
"append",
"(",
"self",
".",
"stop_button",
")",
"# Reset namespace button\r",
"if",
"self",
".",
"reset_button",
"is",
"None",
":",
"self",
".",
"reset_button",
"=",
"create_toolbutton",
"(",
"self",
",",
"text",
"=",
"_",
"(",
"\"Remove\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'editdelete'",
")",
",",
"tip",
"=",
"_",
"(",
"\"Remove all variables\"",
")",
",",
"triggered",
"=",
"self",
".",
"reset_namespace",
")",
"if",
"is_dark_interface",
"(",
")",
":",
"self",
".",
"reset_button",
".",
"setStyleSheet",
"(",
"\"QToolButton{padding: 3px;}\"",
")",
"if",
"self",
".",
"reset_button",
"is",
"not",
"None",
":",
"buttons",
".",
"append",
"(",
"self",
".",
"reset_button",
")",
"if",
"self",
".",
"options_button",
"is",
"None",
":",
"options",
"=",
"self",
".",
"get_options_menu",
"(",
")",
"if",
"options",
":",
"self",
".",
"options_button",
"=",
"create_toolbutton",
"(",
"self",
",",
"text",
"=",
"_",
"(",
"'Options'",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'tooloptions'",
")",
")",
"self",
".",
"options_button",
".",
"setPopupMode",
"(",
"QToolButton",
".",
"InstantPopup",
")",
"menu",
"=",
"QMenu",
"(",
"self",
")",
"add_actions",
"(",
"menu",
",",
"options",
")",
"self",
".",
"options_button",
".",
"setMenu",
"(",
"menu",
")",
"if",
"self",
".",
"options_button",
"is",
"not",
"None",
":",
"buttons",
".",
"append",
"(",
"self",
".",
"options_button",
")",
"return",
"buttons"
] | Return toolbar buttons list. | [
"Return",
"toolbar",
"buttons",
"list",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L401-L445 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.add_actions_to_context_menu | def add_actions_to_context_menu(self, menu):
"""Add actions to IPython widget context menu"""
inspect_action = create_action(self, _("Inspect current object"),
QKeySequence(get_shortcut('console',
'inspect current object')),
icon=ima.icon('MessageBoxInformation'),
triggered=self.inspect_object)
clear_line_action = create_action(self, _("Clear line or block"),
QKeySequence(get_shortcut(
'console',
'clear line')),
triggered=self.clear_line)
reset_namespace_action = create_action(self, _("Remove all variables"),
QKeySequence(get_shortcut(
'ipython_console',
'reset namespace')),
icon=ima.icon('editdelete'),
triggered=self.reset_namespace)
clear_console_action = create_action(self, _("Clear console"),
QKeySequence(get_shortcut('console',
'clear shell')),
triggered=self.clear_console)
quit_action = create_action(self, _("&Quit"), icon=ima.icon('exit'),
triggered=self.exit_callback)
add_actions(menu, (None, inspect_action, clear_line_action,
clear_console_action, reset_namespace_action,
None, quit_action))
return menu | python | def add_actions_to_context_menu(self, menu):
"""Add actions to IPython widget context menu"""
inspect_action = create_action(self, _("Inspect current object"),
QKeySequence(get_shortcut('console',
'inspect current object')),
icon=ima.icon('MessageBoxInformation'),
triggered=self.inspect_object)
clear_line_action = create_action(self, _("Clear line or block"),
QKeySequence(get_shortcut(
'console',
'clear line')),
triggered=self.clear_line)
reset_namespace_action = create_action(self, _("Remove all variables"),
QKeySequence(get_shortcut(
'ipython_console',
'reset namespace')),
icon=ima.icon('editdelete'),
triggered=self.reset_namespace)
clear_console_action = create_action(self, _("Clear console"),
QKeySequence(get_shortcut('console',
'clear shell')),
triggered=self.clear_console)
quit_action = create_action(self, _("&Quit"), icon=ima.icon('exit'),
triggered=self.exit_callback)
add_actions(menu, (None, inspect_action, clear_line_action,
clear_console_action, reset_namespace_action,
None, quit_action))
return menu | [
"def",
"add_actions_to_context_menu",
"(",
"self",
",",
"menu",
")",
":",
"inspect_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Inspect current object\"",
")",
",",
"QKeySequence",
"(",
"get_shortcut",
"(",
"'console'",
",",
"'inspect current object'",
")",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'MessageBoxInformation'",
")",
",",
"triggered",
"=",
"self",
".",
"inspect_object",
")",
"clear_line_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Clear line or block\"",
")",
",",
"QKeySequence",
"(",
"get_shortcut",
"(",
"'console'",
",",
"'clear line'",
")",
")",
",",
"triggered",
"=",
"self",
".",
"clear_line",
")",
"reset_namespace_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Remove all variables\"",
")",
",",
"QKeySequence",
"(",
"get_shortcut",
"(",
"'ipython_console'",
",",
"'reset namespace'",
")",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'editdelete'",
")",
",",
"triggered",
"=",
"self",
".",
"reset_namespace",
")",
"clear_console_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"Clear console\"",
")",
",",
"QKeySequence",
"(",
"get_shortcut",
"(",
"'console'",
",",
"'clear shell'",
")",
")",
",",
"triggered",
"=",
"self",
".",
"clear_console",
")",
"quit_action",
"=",
"create_action",
"(",
"self",
",",
"_",
"(",
"\"&Quit\"",
")",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'exit'",
")",
",",
"triggered",
"=",
"self",
".",
"exit_callback",
")",
"add_actions",
"(",
"menu",
",",
"(",
"None",
",",
"inspect_action",
",",
"clear_line_action",
",",
"clear_console_action",
",",
"reset_namespace_action",
",",
"None",
",",
"quit_action",
")",
")",
"return",
"menu"
] | Add actions to IPython widget context menu | [
"Add",
"actions",
"to",
"IPython",
"widget",
"context",
"menu"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L447-L479 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.set_font | def set_font(self, font):
"""Set IPython widget's font"""
self.shellwidget._control.setFont(font)
self.shellwidget.font = font | python | def set_font(self, font):
"""Set IPython widget's font"""
self.shellwidget._control.setFont(font)
self.shellwidget.font = font | [
"def",
"set_font",
"(",
"self",
",",
"font",
")",
":",
"self",
".",
"shellwidget",
".",
"_control",
".",
"setFont",
"(",
"font",
")",
"self",
".",
"shellwidget",
".",
"font",
"=",
"font"
] | Set IPython widget's font | [
"Set",
"IPython",
"widget",
"s",
"font"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L481-L484 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.set_color_scheme | def set_color_scheme(self, color_scheme, reset=True):
"""Set IPython color scheme."""
# Needed to handle not initialized kernel_client
# See issue 6996
try:
self.shellwidget.set_color_scheme(color_scheme, reset)
except AttributeError:
pass | python | def set_color_scheme(self, color_scheme, reset=True):
"""Set IPython color scheme."""
# Needed to handle not initialized kernel_client
# See issue 6996
try:
self.shellwidget.set_color_scheme(color_scheme, reset)
except AttributeError:
pass | [
"def",
"set_color_scheme",
"(",
"self",
",",
"color_scheme",
",",
"reset",
"=",
"True",
")",
":",
"# Needed to handle not initialized kernel_client\r",
"# See issue 6996\r",
"try",
":",
"self",
".",
"shellwidget",
".",
"set_color_scheme",
"(",
"color_scheme",
",",
"reset",
")",
"except",
"AttributeError",
":",
"pass"
] | Set IPython color scheme. | [
"Set",
"IPython",
"color",
"scheme",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L486-L493 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.shutdown | def shutdown(self):
"""Shutdown kernel"""
if self.get_kernel() is not None and not self.slave:
self.shellwidget.kernel_manager.shutdown_kernel()
if self.shellwidget.kernel_client is not None:
background(self.shellwidget.kernel_client.stop_channels) | python | def shutdown(self):
"""Shutdown kernel"""
if self.get_kernel() is not None and not self.slave:
self.shellwidget.kernel_manager.shutdown_kernel()
if self.shellwidget.kernel_client is not None:
background(self.shellwidget.kernel_client.stop_channels) | [
"def",
"shutdown",
"(",
"self",
")",
":",
"if",
"self",
".",
"get_kernel",
"(",
")",
"is",
"not",
"None",
"and",
"not",
"self",
".",
"slave",
":",
"self",
".",
"shellwidget",
".",
"kernel_manager",
".",
"shutdown_kernel",
"(",
")",
"if",
"self",
".",
"shellwidget",
".",
"kernel_client",
"is",
"not",
"None",
":",
"background",
"(",
"self",
".",
"shellwidget",
".",
"kernel_client",
".",
"stop_channels",
")"
] | Shutdown kernel | [
"Shutdown",
"kernel"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L495-L500 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.restart_kernel | def restart_kernel(self):
"""
Restart the associated kernel.
Took this code from the qtconsole project
Licensed under the BSD license
"""
sw = self.shellwidget
if not running_under_pytest() and self.ask_before_restart:
message = _('Are you sure you want to restart the kernel?')
buttons = QMessageBox.Yes | QMessageBox.No
result = QMessageBox.question(self, _('Restart kernel?'),
message, buttons)
else:
result = None
if (result == QMessageBox.Yes or
running_under_pytest() or
not self.ask_before_restart):
if sw.kernel_manager:
if self.infowidget.isVisible():
self.infowidget.hide()
sw.show()
try:
sw.kernel_manager.restart_kernel(
stderr=self.stderr_handle)
except RuntimeError as e:
sw._append_plain_text(
_('Error restarting kernel: %s\n') % e,
before_prompt=True
)
else:
# For issue 6235. IPython was changing the setting of
# %colors on windows by assuming it was using a dark
# background. This corrects it based on the scheme.
self.set_color_scheme(sw.syntax_style)
sw._append_html(_("<br>Restarting kernel...\n<hr><br>"),
before_prompt=False)
else:
sw._append_plain_text(
_('Cannot restart a kernel not started by Spyder\n'),
before_prompt=True
) | python | def restart_kernel(self):
"""
Restart the associated kernel.
Took this code from the qtconsole project
Licensed under the BSD license
"""
sw = self.shellwidget
if not running_under_pytest() and self.ask_before_restart:
message = _('Are you sure you want to restart the kernel?')
buttons = QMessageBox.Yes | QMessageBox.No
result = QMessageBox.question(self, _('Restart kernel?'),
message, buttons)
else:
result = None
if (result == QMessageBox.Yes or
running_under_pytest() or
not self.ask_before_restart):
if sw.kernel_manager:
if self.infowidget.isVisible():
self.infowidget.hide()
sw.show()
try:
sw.kernel_manager.restart_kernel(
stderr=self.stderr_handle)
except RuntimeError as e:
sw._append_plain_text(
_('Error restarting kernel: %s\n') % e,
before_prompt=True
)
else:
# For issue 6235. IPython was changing the setting of
# %colors on windows by assuming it was using a dark
# background. This corrects it based on the scheme.
self.set_color_scheme(sw.syntax_style)
sw._append_html(_("<br>Restarting kernel...\n<hr><br>"),
before_prompt=False)
else:
sw._append_plain_text(
_('Cannot restart a kernel not started by Spyder\n'),
before_prompt=True
) | [
"def",
"restart_kernel",
"(",
"self",
")",
":",
"sw",
"=",
"self",
".",
"shellwidget",
"if",
"not",
"running_under_pytest",
"(",
")",
"and",
"self",
".",
"ask_before_restart",
":",
"message",
"=",
"_",
"(",
"'Are you sure you want to restart the kernel?'",
")",
"buttons",
"=",
"QMessageBox",
".",
"Yes",
"|",
"QMessageBox",
".",
"No",
"result",
"=",
"QMessageBox",
".",
"question",
"(",
"self",
",",
"_",
"(",
"'Restart kernel?'",
")",
",",
"message",
",",
"buttons",
")",
"else",
":",
"result",
"=",
"None",
"if",
"(",
"result",
"==",
"QMessageBox",
".",
"Yes",
"or",
"running_under_pytest",
"(",
")",
"or",
"not",
"self",
".",
"ask_before_restart",
")",
":",
"if",
"sw",
".",
"kernel_manager",
":",
"if",
"self",
".",
"infowidget",
".",
"isVisible",
"(",
")",
":",
"self",
".",
"infowidget",
".",
"hide",
"(",
")",
"sw",
".",
"show",
"(",
")",
"try",
":",
"sw",
".",
"kernel_manager",
".",
"restart_kernel",
"(",
"stderr",
"=",
"self",
".",
"stderr_handle",
")",
"except",
"RuntimeError",
"as",
"e",
":",
"sw",
".",
"_append_plain_text",
"(",
"_",
"(",
"'Error restarting kernel: %s\\n'",
")",
"%",
"e",
",",
"before_prompt",
"=",
"True",
")",
"else",
":",
"# For issue 6235. IPython was changing the setting of\r",
"# %colors on windows by assuming it was using a dark\r",
"# background. This corrects it based on the scheme.\r",
"self",
".",
"set_color_scheme",
"(",
"sw",
".",
"syntax_style",
")",
"sw",
".",
"_append_html",
"(",
"_",
"(",
"\"<br>Restarting kernel...\\n<hr><br>\"",
")",
",",
"before_prompt",
"=",
"False",
")",
"else",
":",
"sw",
".",
"_append_plain_text",
"(",
"_",
"(",
"'Cannot restart a kernel not started by Spyder\\n'",
")",
",",
"before_prompt",
"=",
"True",
")"
] | Restart the associated kernel.
Took this code from the qtconsole project
Licensed under the BSD license | [
"Restart",
"the",
"associated",
"kernel",
".",
"Took",
"this",
"code",
"from",
"the",
"qtconsole",
"project",
"Licensed",
"under",
"the",
"BSD",
"license"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L512-L555 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.kernel_restarted_message | def kernel_restarted_message(self, msg):
"""Show kernel restarted/died messages."""
if not self.is_error_shown:
# If there are kernel creation errors, jupyter_client will
# try to restart the kernel and qtconsole prints a
# message about it.
# So we read the kernel's stderr_file and display its
# contents in the client instead of the usual message shown
# by qtconsole.
try:
stderr = self._read_stderr()
except Exception:
stderr = None
if stderr:
self.show_kernel_error('<tt>%s</tt>' % stderr)
else:
self.shellwidget._append_html("<br>%s<hr><br>" % msg,
before_prompt=False) | python | def kernel_restarted_message(self, msg):
"""Show kernel restarted/died messages."""
if not self.is_error_shown:
# If there are kernel creation errors, jupyter_client will
# try to restart the kernel and qtconsole prints a
# message about it.
# So we read the kernel's stderr_file and display its
# contents in the client instead of the usual message shown
# by qtconsole.
try:
stderr = self._read_stderr()
except Exception:
stderr = None
if stderr:
self.show_kernel_error('<tt>%s</tt>' % stderr)
else:
self.shellwidget._append_html("<br>%s<hr><br>" % msg,
before_prompt=False) | [
"def",
"kernel_restarted_message",
"(",
"self",
",",
"msg",
")",
":",
"if",
"not",
"self",
".",
"is_error_shown",
":",
"# If there are kernel creation errors, jupyter_client will\r",
"# try to restart the kernel and qtconsole prints a\r",
"# message about it.\r",
"# So we read the kernel's stderr_file and display its\r",
"# contents in the client instead of the usual message shown\r",
"# by qtconsole.\r",
"try",
":",
"stderr",
"=",
"self",
".",
"_read_stderr",
"(",
")",
"except",
"Exception",
":",
"stderr",
"=",
"None",
"if",
"stderr",
":",
"self",
".",
"show_kernel_error",
"(",
"'<tt>%s</tt>'",
"%",
"stderr",
")",
"else",
":",
"self",
".",
"shellwidget",
".",
"_append_html",
"(",
"\"<br>%s<hr><br>\"",
"%",
"msg",
",",
"before_prompt",
"=",
"False",
")"
] | Show kernel restarted/died messages. | [
"Show",
"kernel",
"restarted",
"/",
"died",
"messages",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L558-L575 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.reset_namespace | def reset_namespace(self):
"""Resets the namespace by removing all names defined by the user"""
self.shellwidget.reset_namespace(warning=self.reset_warning,
message=True) | python | def reset_namespace(self):
"""Resets the namespace by removing all names defined by the user"""
self.shellwidget.reset_namespace(warning=self.reset_warning,
message=True) | [
"def",
"reset_namespace",
"(",
"self",
")",
":",
"self",
".",
"shellwidget",
".",
"reset_namespace",
"(",
"warning",
"=",
"self",
".",
"reset_warning",
",",
"message",
"=",
"True",
")"
] | Resets the namespace by removing all names defined by the user | [
"Resets",
"the",
"namespace",
"by",
"removing",
"all",
"names",
"defined",
"by",
"the",
"user"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L593-L596 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.show_syspath | def show_syspath(self, syspath):
"""Show sys.path contents."""
if syspath is not None:
editor = CollectionsEditor(self)
editor.setup(syspath, title="sys.path contents", readonly=True,
width=600, icon=ima.icon('syspath'))
self.dialog_manager.show(editor)
else:
return | python | def show_syspath(self, syspath):
"""Show sys.path contents."""
if syspath is not None:
editor = CollectionsEditor(self)
editor.setup(syspath, title="sys.path contents", readonly=True,
width=600, icon=ima.icon('syspath'))
self.dialog_manager.show(editor)
else:
return | [
"def",
"show_syspath",
"(",
"self",
",",
"syspath",
")",
":",
"if",
"syspath",
"is",
"not",
"None",
":",
"editor",
"=",
"CollectionsEditor",
"(",
"self",
")",
"editor",
".",
"setup",
"(",
"syspath",
",",
"title",
"=",
"\"sys.path contents\"",
",",
"readonly",
"=",
"True",
",",
"width",
"=",
"600",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'syspath'",
")",
")",
"self",
".",
"dialog_manager",
".",
"show",
"(",
"editor",
")",
"else",
":",
"return"
] | Show sys.path contents. | [
"Show",
"sys",
".",
"path",
"contents",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L602-L610 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.show_env | def show_env(self, env):
"""Show environment variables."""
self.dialog_manager.show(RemoteEnvDialog(env, parent=self)) | python | def show_env(self, env):
"""Show environment variables."""
self.dialog_manager.show(RemoteEnvDialog(env, parent=self)) | [
"def",
"show_env",
"(",
"self",
",",
"env",
")",
":",
"self",
".",
"dialog_manager",
".",
"show",
"(",
"RemoteEnvDialog",
"(",
"env",
",",
"parent",
"=",
"self",
")",
")"
] | Show environment variables. | [
"Show",
"environment",
"variables",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L613-L615 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.show_time | def show_time(self, end=False):
"""Text to show in time_label."""
if self.time_label is None:
return
elapsed_time = time.monotonic() - self.t0
# System time changed to past date, so reset start.
if elapsed_time < 0:
self.t0 = time.monotonic()
elapsed_time = 0
if elapsed_time > 24 * 3600: # More than a day...!
fmt = "%d %H:%M:%S"
else:
fmt = "%H:%M:%S"
if end:
color = "#AAAAAA"
else:
color = "#AA6655"
text = "<span style=\'color: %s\'><b>%s" \
"</b></span>" % (color,
time.strftime(fmt, time.gmtime(elapsed_time)))
self.time_label.setText(text) | python | def show_time(self, end=False):
"""Text to show in time_label."""
if self.time_label is None:
return
elapsed_time = time.monotonic() - self.t0
# System time changed to past date, so reset start.
if elapsed_time < 0:
self.t0 = time.monotonic()
elapsed_time = 0
if elapsed_time > 24 * 3600: # More than a day...!
fmt = "%d %H:%M:%S"
else:
fmt = "%H:%M:%S"
if end:
color = "#AAAAAA"
else:
color = "#AA6655"
text = "<span style=\'color: %s\'><b>%s" \
"</b></span>" % (color,
time.strftime(fmt, time.gmtime(elapsed_time)))
self.time_label.setText(text) | [
"def",
"show_time",
"(",
"self",
",",
"end",
"=",
"False",
")",
":",
"if",
"self",
".",
"time_label",
"is",
"None",
":",
"return",
"elapsed_time",
"=",
"time",
".",
"monotonic",
"(",
")",
"-",
"self",
".",
"t0",
"# System time changed to past date, so reset start.\r",
"if",
"elapsed_time",
"<",
"0",
":",
"self",
".",
"t0",
"=",
"time",
".",
"monotonic",
"(",
")",
"elapsed_time",
"=",
"0",
"if",
"elapsed_time",
">",
"24",
"*",
"3600",
":",
"# More than a day...!\r",
"fmt",
"=",
"\"%d %H:%M:%S\"",
"else",
":",
"fmt",
"=",
"\"%H:%M:%S\"",
"if",
"end",
":",
"color",
"=",
"\"#AAAAAA\"",
"else",
":",
"color",
"=",
"\"#AA6655\"",
"text",
"=",
"\"<span style=\\'color: %s\\'><b>%s\"",
"\"</b></span>\"",
"%",
"(",
"color",
",",
"time",
".",
"strftime",
"(",
"fmt",
",",
"time",
".",
"gmtime",
"(",
"elapsed_time",
")",
")",
")",
"self",
".",
"time_label",
".",
"setText",
"(",
"text",
")"
] | Text to show in time_label. | [
"Text",
"to",
"show",
"in",
"time_label",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L623-L644 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.set_elapsed_time_visible | def set_elapsed_time_visible(self, state):
"""Slot to show/hide elapsed time label."""
self.show_elapsed_time = state
if self.time_label is not None:
self.time_label.setVisible(state) | python | def set_elapsed_time_visible(self, state):
"""Slot to show/hide elapsed time label."""
self.show_elapsed_time = state
if self.time_label is not None:
self.time_label.setVisible(state) | [
"def",
"set_elapsed_time_visible",
"(",
"self",
",",
"state",
")",
":",
"self",
".",
"show_elapsed_time",
"=",
"state",
"if",
"self",
".",
"time_label",
"is",
"not",
"None",
":",
"self",
".",
"time_label",
".",
"setVisible",
"(",
"state",
")"
] | Slot to show/hide elapsed time label. | [
"Slot",
"to",
"show",
"/",
"hide",
"elapsed",
"time",
"label",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L651-L655 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget.set_info_page | def set_info_page(self):
"""Set current info_page."""
if self.info_page is not None:
self.infowidget.setHtml(
self.info_page,
QUrl.fromLocalFile(self.css_path)
) | python | def set_info_page(self):
"""Set current info_page."""
if self.info_page is not None:
self.infowidget.setHtml(
self.info_page,
QUrl.fromLocalFile(self.css_path)
) | [
"def",
"set_info_page",
"(",
"self",
")",
":",
"if",
"self",
".",
"info_page",
"is",
"not",
"None",
":",
"self",
".",
"infowidget",
".",
"setHtml",
"(",
"self",
".",
"info_page",
",",
"QUrl",
".",
"fromLocalFile",
"(",
"self",
".",
"css_path",
")",
")"
] | Set current info_page. | [
"Set",
"current",
"info_page",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L657-L663 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget._create_loading_page | def _create_loading_page(self):
"""Create html page to show while the kernel is starting"""
loading_template = Template(LOADING)
loading_img = get_image_path('loading_sprites.png')
if os.name == 'nt':
loading_img = loading_img.replace('\\', '/')
message = _("Connecting to kernel...")
page = loading_template.substitute(css_path=self.css_path,
loading_img=loading_img,
message=message)
return page | python | def _create_loading_page(self):
"""Create html page to show while the kernel is starting"""
loading_template = Template(LOADING)
loading_img = get_image_path('loading_sprites.png')
if os.name == 'nt':
loading_img = loading_img.replace('\\', '/')
message = _("Connecting to kernel...")
page = loading_template.substitute(css_path=self.css_path,
loading_img=loading_img,
message=message)
return page | [
"def",
"_create_loading_page",
"(",
"self",
")",
":",
"loading_template",
"=",
"Template",
"(",
"LOADING",
")",
"loading_img",
"=",
"get_image_path",
"(",
"'loading_sprites.png'",
")",
"if",
"os",
".",
"name",
"==",
"'nt'",
":",
"loading_img",
"=",
"loading_img",
".",
"replace",
"(",
"'\\\\'",
",",
"'/'",
")",
"message",
"=",
"_",
"(",
"\"Connecting to kernel...\"",
")",
"page",
"=",
"loading_template",
".",
"substitute",
"(",
"css_path",
"=",
"self",
".",
"css_path",
",",
"loading_img",
"=",
"loading_img",
",",
"message",
"=",
"message",
")",
"return",
"page"
] | Create html page to show while the kernel is starting | [
"Create",
"html",
"page",
"to",
"show",
"while",
"the",
"kernel",
"is",
"starting"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L666-L676 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget._create_blank_page | def _create_blank_page(self):
"""Create html page to show while the kernel is starting"""
loading_template = Template(BLANK)
page = loading_template.substitute(css_path=self.css_path)
return page | python | def _create_blank_page(self):
"""Create html page to show while the kernel is starting"""
loading_template = Template(BLANK)
page = loading_template.substitute(css_path=self.css_path)
return page | [
"def",
"_create_blank_page",
"(",
"self",
")",
":",
"loading_template",
"=",
"Template",
"(",
"BLANK",
")",
"page",
"=",
"loading_template",
".",
"substitute",
"(",
"css_path",
"=",
"self",
".",
"css_path",
")",
"return",
"page"
] | Create html page to show while the kernel is starting | [
"Create",
"html",
"page",
"to",
"show",
"while",
"the",
"kernel",
"is",
"starting"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L678-L682 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget._show_loading_page | def _show_loading_page(self):
"""Show animation while the kernel is loading."""
self.shellwidget.hide()
self.infowidget.show()
self.info_page = self.loading_page
self.set_info_page() | python | def _show_loading_page(self):
"""Show animation while the kernel is loading."""
self.shellwidget.hide()
self.infowidget.show()
self.info_page = self.loading_page
self.set_info_page() | [
"def",
"_show_loading_page",
"(",
"self",
")",
":",
"self",
".",
"shellwidget",
".",
"hide",
"(",
")",
"self",
".",
"infowidget",
".",
"show",
"(",
")",
"self",
".",
"info_page",
"=",
"self",
".",
"loading_page",
"self",
".",
"set_info_page",
"(",
")"
] | Show animation while the kernel is loading. | [
"Show",
"animation",
"while",
"the",
"kernel",
"is",
"loading",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L684-L689 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget._hide_loading_page | def _hide_loading_page(self):
"""Hide animation shown while the kernel is loading."""
self.infowidget.hide()
self.shellwidget.show()
self.info_page = self.blank_page
self.set_info_page()
self.shellwidget.sig_prompt_ready.disconnect(self._hide_loading_page) | python | def _hide_loading_page(self):
"""Hide animation shown while the kernel is loading."""
self.infowidget.hide()
self.shellwidget.show()
self.info_page = self.blank_page
self.set_info_page()
self.shellwidget.sig_prompt_ready.disconnect(self._hide_loading_page) | [
"def",
"_hide_loading_page",
"(",
"self",
")",
":",
"self",
".",
"infowidget",
".",
"hide",
"(",
")",
"self",
".",
"shellwidget",
".",
"show",
"(",
")",
"self",
".",
"info_page",
"=",
"self",
".",
"blank_page",
"self",
".",
"set_info_page",
"(",
")",
"self",
".",
"shellwidget",
".",
"sig_prompt_ready",
".",
"disconnect",
"(",
"self",
".",
"_hide_loading_page",
")"
] | Hide animation shown while the kernel is loading. | [
"Hide",
"animation",
"shown",
"while",
"the",
"kernel",
"is",
"loading",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L691-L697 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget._read_stderr | def _read_stderr(self):
"""Read the stderr file of the kernel."""
# We need to read stderr_file as bytes to be able to
# detect its encoding with chardet
f = open(self.stderr_file, 'rb')
try:
stderr_text = f.read()
# This is needed to avoid showing an empty error message
# when the kernel takes too much time to start.
# See issue 8581
if not stderr_text:
return ''
# This is needed since the stderr file could be encoded
# in something different to utf-8.
# See issue 4191
encoding = get_coding(stderr_text)
stderr_text = to_text_string(stderr_text, encoding)
return stderr_text
finally:
f.close() | python | def _read_stderr(self):
"""Read the stderr file of the kernel."""
# We need to read stderr_file as bytes to be able to
# detect its encoding with chardet
f = open(self.stderr_file, 'rb')
try:
stderr_text = f.read()
# This is needed to avoid showing an empty error message
# when the kernel takes too much time to start.
# See issue 8581
if not stderr_text:
return ''
# This is needed since the stderr file could be encoded
# in something different to utf-8.
# See issue 4191
encoding = get_coding(stderr_text)
stderr_text = to_text_string(stderr_text, encoding)
return stderr_text
finally:
f.close() | [
"def",
"_read_stderr",
"(",
"self",
")",
":",
"# We need to read stderr_file as bytes to be able to\r",
"# detect its encoding with chardet\r",
"f",
"=",
"open",
"(",
"self",
".",
"stderr_file",
",",
"'rb'",
")",
"try",
":",
"stderr_text",
"=",
"f",
".",
"read",
"(",
")",
"# This is needed to avoid showing an empty error message\r",
"# when the kernel takes too much time to start.\r",
"# See issue 8581\r",
"if",
"not",
"stderr_text",
":",
"return",
"''",
"# This is needed since the stderr file could be encoded\r",
"# in something different to utf-8.\r",
"# See issue 4191\r",
"encoding",
"=",
"get_coding",
"(",
"stderr_text",
")",
"stderr_text",
"=",
"to_text_string",
"(",
"stderr_text",
",",
"encoding",
")",
"return",
"stderr_text",
"finally",
":",
"f",
".",
"close",
"(",
")"
] | Read the stderr file of the kernel. | [
"Read",
"the",
"stderr",
"file",
"of",
"the",
"kernel",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L699-L721 | train |
spyder-ide/spyder | spyder/plugins/ipythonconsole/widgets/client.py | ClientWidget._show_mpl_backend_errors | def _show_mpl_backend_errors(self):
"""
Show possible errors when setting the selected Matplotlib backend.
"""
if not self.external_kernel:
self.shellwidget.silent_execute(
"get_ipython().kernel._show_mpl_backend_errors()")
self.shellwidget.sig_prompt_ready.disconnect(
self._show_mpl_backend_errors) | python | def _show_mpl_backend_errors(self):
"""
Show possible errors when setting the selected Matplotlib backend.
"""
if not self.external_kernel:
self.shellwidget.silent_execute(
"get_ipython().kernel._show_mpl_backend_errors()")
self.shellwidget.sig_prompt_ready.disconnect(
self._show_mpl_backend_errors) | [
"def",
"_show_mpl_backend_errors",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"external_kernel",
":",
"self",
".",
"shellwidget",
".",
"silent_execute",
"(",
"\"get_ipython().kernel._show_mpl_backend_errors()\"",
")",
"self",
".",
"shellwidget",
".",
"sig_prompt_ready",
".",
"disconnect",
"(",
"self",
".",
"_show_mpl_backend_errors",
")"
] | Show possible errors when setting the selected Matplotlib backend. | [
"Show",
"possible",
"errors",
"when",
"setting",
"the",
"selected",
"Matplotlib",
"backend",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/client.py#L723-L731 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin._calculate_position | def _calculate_position(self, at_line=None, at_position=None,
at_point=None):
"""
Calculate a global point position `QPoint(x, y)`, for a given
line, local cursor position, or local point.
"""
# Check that no option or only one option is given:
if [at_line, at_position, at_point].count(None) < 2:
raise Exception('Provide no argument or only one argument!')
# Saving cursor position:
if at_position is None:
at_position = self.get_position('cursor')
# FIXME: What id this used for?
self.calltip_position = at_position
if at_point is not None:
# Showing tooltip at point position
cx, cy = at_point.x(), at_point.y()
elif at_line is not None:
# Showing tooltip at line
cx = 5
cursor = QTextCursor(self.document().findBlockByNumber(at_line-1))
cy = self.cursorRect(cursor).top()
else:
# Showing tooltip at cursor position
# FIXME: why is at_position not being used to calculate the
# coordinates?
cx, cy = self.get_coordinates('cursor')
# Calculate vertical delta
font = self.font()
delta = font.pointSize() + 5
# Map to global coordinates
point = self.mapToGlobal(QPoint(cx, cy))
point = self.calculate_real_position(point)
point.setY(point.y() + delta)
return point | python | def _calculate_position(self, at_line=None, at_position=None,
at_point=None):
"""
Calculate a global point position `QPoint(x, y)`, for a given
line, local cursor position, or local point.
"""
# Check that no option or only one option is given:
if [at_line, at_position, at_point].count(None) < 2:
raise Exception('Provide no argument or only one argument!')
# Saving cursor position:
if at_position is None:
at_position = self.get_position('cursor')
# FIXME: What id this used for?
self.calltip_position = at_position
if at_point is not None:
# Showing tooltip at point position
cx, cy = at_point.x(), at_point.y()
elif at_line is not None:
# Showing tooltip at line
cx = 5
cursor = QTextCursor(self.document().findBlockByNumber(at_line-1))
cy = self.cursorRect(cursor).top()
else:
# Showing tooltip at cursor position
# FIXME: why is at_position not being used to calculate the
# coordinates?
cx, cy = self.get_coordinates('cursor')
# Calculate vertical delta
font = self.font()
delta = font.pointSize() + 5
# Map to global coordinates
point = self.mapToGlobal(QPoint(cx, cy))
point = self.calculate_real_position(point)
point.setY(point.y() + delta)
return point | [
"def",
"_calculate_position",
"(",
"self",
",",
"at_line",
"=",
"None",
",",
"at_position",
"=",
"None",
",",
"at_point",
"=",
"None",
")",
":",
"# Check that no option or only one option is given:\r",
"if",
"[",
"at_line",
",",
"at_position",
",",
"at_point",
"]",
".",
"count",
"(",
"None",
")",
"<",
"2",
":",
"raise",
"Exception",
"(",
"'Provide no argument or only one argument!'",
")",
"# Saving cursor position:\r",
"if",
"at_position",
"is",
"None",
":",
"at_position",
"=",
"self",
".",
"get_position",
"(",
"'cursor'",
")",
"# FIXME: What id this used for?\r",
"self",
".",
"calltip_position",
"=",
"at_position",
"if",
"at_point",
"is",
"not",
"None",
":",
"# Showing tooltip at point position\r",
"cx",
",",
"cy",
"=",
"at_point",
".",
"x",
"(",
")",
",",
"at_point",
".",
"y",
"(",
")",
"elif",
"at_line",
"is",
"not",
"None",
":",
"# Showing tooltip at line\r",
"cx",
"=",
"5",
"cursor",
"=",
"QTextCursor",
"(",
"self",
".",
"document",
"(",
")",
".",
"findBlockByNumber",
"(",
"at_line",
"-",
"1",
")",
")",
"cy",
"=",
"self",
".",
"cursorRect",
"(",
"cursor",
")",
".",
"top",
"(",
")",
"else",
":",
"# Showing tooltip at cursor position\r",
"# FIXME: why is at_position not being used to calculate the\r",
"# coordinates?\r",
"cx",
",",
"cy",
"=",
"self",
".",
"get_coordinates",
"(",
"'cursor'",
")",
"# Calculate vertical delta\r",
"font",
"=",
"self",
".",
"font",
"(",
")",
"delta",
"=",
"font",
".",
"pointSize",
"(",
")",
"+",
"5",
"# Map to global coordinates\r",
"point",
"=",
"self",
".",
"mapToGlobal",
"(",
"QPoint",
"(",
"cx",
",",
"cy",
")",
")",
"point",
"=",
"self",
".",
"calculate_real_position",
"(",
"point",
")",
"point",
".",
"setY",
"(",
"point",
".",
"y",
"(",
")",
"+",
"delta",
")",
"return",
"point"
] | Calculate a global point position `QPoint(x, y)`, for a given
line, local cursor position, or local point. | [
"Calculate",
"a",
"global",
"point",
"position",
"QPoint",
"(",
"x",
"y",
")",
"for",
"a",
"given",
"line",
"local",
"cursor",
"position",
"or",
"local",
"point",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L74-L114 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin._update_stylesheet | def _update_stylesheet(self, widget):
"""Update the background stylesheet to make it lighter."""
if is_dark_interface():
css = qdarkstyle.load_stylesheet_from_environment()
widget.setStyleSheet(css)
palette = widget.palette()
background = palette.color(palette.Window).lighter(150).name()
border = palette.color(palette.Window).lighter(200).name()
name = widget.__class__.__name__
widget.setObjectName(name)
extra_css = '''
{0}#{0} {{
background-color:{1};
border: 1px solid {2};
}}'''.format(name, background, border)
widget.setStyleSheet(css + extra_css) | python | def _update_stylesheet(self, widget):
"""Update the background stylesheet to make it lighter."""
if is_dark_interface():
css = qdarkstyle.load_stylesheet_from_environment()
widget.setStyleSheet(css)
palette = widget.palette()
background = palette.color(palette.Window).lighter(150).name()
border = palette.color(palette.Window).lighter(200).name()
name = widget.__class__.__name__
widget.setObjectName(name)
extra_css = '''
{0}#{0} {{
background-color:{1};
border: 1px solid {2};
}}'''.format(name, background, border)
widget.setStyleSheet(css + extra_css) | [
"def",
"_update_stylesheet",
"(",
"self",
",",
"widget",
")",
":",
"if",
"is_dark_interface",
"(",
")",
":",
"css",
"=",
"qdarkstyle",
".",
"load_stylesheet_from_environment",
"(",
")",
"widget",
".",
"setStyleSheet",
"(",
"css",
")",
"palette",
"=",
"widget",
".",
"palette",
"(",
")",
"background",
"=",
"palette",
".",
"color",
"(",
"palette",
".",
"Window",
")",
".",
"lighter",
"(",
"150",
")",
".",
"name",
"(",
")",
"border",
"=",
"palette",
".",
"color",
"(",
"palette",
".",
"Window",
")",
".",
"lighter",
"(",
"200",
")",
".",
"name",
"(",
")",
"name",
"=",
"widget",
".",
"__class__",
".",
"__name__",
"widget",
".",
"setObjectName",
"(",
"name",
")",
"extra_css",
"=",
"'''\r\n {0}#{0} {{\r\n background-color:{1};\r\n border: 1px solid {2};\r\n }}'''",
".",
"format",
"(",
"name",
",",
"background",
",",
"border",
")",
"widget",
".",
"setStyleSheet",
"(",
"css",
"+",
"extra_css",
")"
] | Update the background stylesheet to make it lighter. | [
"Update",
"the",
"background",
"stylesheet",
"to",
"make",
"it",
"lighter",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L116-L131 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin._format_text | def _format_text(self, title, text, color, ellide=False):
"""
Create HTML template for calltips and tooltips.
This will display title and text as separate sections and add `...`
if `ellide` is True and the text is too long.
"""
template = '''
<div style=\'font-family: "{font_family}";
font-size: {title_size}pt;
color: {color}\'>
<b>{title}</b>
</div>
'''
if text:
template += '''
<hr>
<div style=\'font-family: "{font_family}";
font-size: {text_size}pt;
color: {color_text}\'>
{text}
</div>
'''
# Prepare text
if isinstance(text, list):
text = "\n ".join(text)
text = text.replace('\n', '<br>')
# Ellide the text if it is too long
if ellide and len(text) > self.calltip_size:
text = text[:self.calltip_size] + " ..."
# Get current font properties
font = self.font()
font_family = font.family()
title_size = font.pointSize()
text_size = title_size - 1 if title_size > 9 else title_size
tiptext = template.format(
font_family=font_family,
title_size=title_size,
text_size=text_size,
color=color,
color_text=self._DEFAULT_TEXT_COLOR,
title=title,
text=text,
)
return tiptext | python | def _format_text(self, title, text, color, ellide=False):
"""
Create HTML template for calltips and tooltips.
This will display title and text as separate sections and add `...`
if `ellide` is True and the text is too long.
"""
template = '''
<div style=\'font-family: "{font_family}";
font-size: {title_size}pt;
color: {color}\'>
<b>{title}</b>
</div>
'''
if text:
template += '''
<hr>
<div style=\'font-family: "{font_family}";
font-size: {text_size}pt;
color: {color_text}\'>
{text}
</div>
'''
# Prepare text
if isinstance(text, list):
text = "\n ".join(text)
text = text.replace('\n', '<br>')
# Ellide the text if it is too long
if ellide and len(text) > self.calltip_size:
text = text[:self.calltip_size] + " ..."
# Get current font properties
font = self.font()
font_family = font.family()
title_size = font.pointSize()
text_size = title_size - 1 if title_size > 9 else title_size
tiptext = template.format(
font_family=font_family,
title_size=title_size,
text_size=text_size,
color=color,
color_text=self._DEFAULT_TEXT_COLOR,
title=title,
text=text,
)
return tiptext | [
"def",
"_format_text",
"(",
"self",
",",
"title",
",",
"text",
",",
"color",
",",
"ellide",
"=",
"False",
")",
":",
"template",
"=",
"'''\r\n <div style=\\'font-family: \"{font_family}\";\r\n font-size: {title_size}pt;\r\n color: {color}\\'>\r\n <b>{title}</b>\r\n </div>\r\n '''",
"if",
"text",
":",
"template",
"+=",
"'''\r\n <hr>\r\n <div style=\\'font-family: \"{font_family}\";\r\n font-size: {text_size}pt;\r\n color: {color_text}\\'>\r\n {text}\r\n </div>\r\n '''",
"# Prepare text\r",
"if",
"isinstance",
"(",
"text",
",",
"list",
")",
":",
"text",
"=",
"\"\\n \"",
".",
"join",
"(",
"text",
")",
"text",
"=",
"text",
".",
"replace",
"(",
"'\\n'",
",",
"'<br>'",
")",
"# Ellide the text if it is too long\r",
"if",
"ellide",
"and",
"len",
"(",
"text",
")",
">",
"self",
".",
"calltip_size",
":",
"text",
"=",
"text",
"[",
":",
"self",
".",
"calltip_size",
"]",
"+",
"\" ...\"",
"# Get current font properties\r",
"font",
"=",
"self",
".",
"font",
"(",
")",
"font_family",
"=",
"font",
".",
"family",
"(",
")",
"title_size",
"=",
"font",
".",
"pointSize",
"(",
")",
"text_size",
"=",
"title_size",
"-",
"1",
"if",
"title_size",
">",
"9",
"else",
"title_size",
"tiptext",
"=",
"template",
".",
"format",
"(",
"font_family",
"=",
"font_family",
",",
"title_size",
"=",
"title_size",
",",
"text_size",
"=",
"text_size",
",",
"color",
"=",
"color",
",",
"color_text",
"=",
"self",
".",
"_DEFAULT_TEXT_COLOR",
",",
"title",
"=",
"title",
",",
"text",
"=",
"text",
",",
")",
"return",
"tiptext"
] | Create HTML template for calltips and tooltips.
This will display title and text as separate sections and add `...`
if `ellide` is True and the text is too long. | [
"Create",
"HTML",
"template",
"for",
"calltips",
"and",
"tooltips",
".",
"This",
"will",
"display",
"title",
"and",
"text",
"as",
"separate",
"sections",
"and",
"add",
"...",
"if",
"ellide",
"is",
"True",
"and",
"the",
"text",
"is",
"too",
"long",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L133-L183 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin._format_signature | def _format_signature(self, signature, doc='', parameter='',
parameter_doc='', color=_DEFAULT_TITLE_COLOR,
is_python=False):
"""
Create HTML template for signature.
This template will include indent after the method name, a highlight
color for the active parameter and highlights for special chars.
"""
active_parameter_template = (
'<span style=\'font-family:"{font_family}";'
'font-size:{font_size}pt;'
'color:{color}\'>'
'<b>{parameter}</b>'
'</span>'
)
chars_template = (
'<span style="color:{0};'.format(self._CHAR_HIGHLIGHT_COLOR) +
'font-weight:bold">{char}'
'</span>'
)
def handle_sub(matchobj):
"""
Handle substitution of active parameter template.
This ensures the correct highlight of the active parameter.
"""
match = matchobj.group(0)
new = match.replace(parameter, active_parameter_template)
return new
# Remove duplicate spaces
signature = ' '.join(signature.split())
# Replace ay initial spaces
signature = signature.replace('( ', '(')
# Process signature template
pattern = r'[\*|(|\s](' + parameter + r')[,|)|\s|=]'
formatted_lines = []
name = signature.split('(')[0]
indent = ' ' * (len(name) + 1)
rows = textwrap.wrap(signature, width=60, subsequent_indent=indent)
for row in rows:
# Add template to highlight the active parameter
row = re.sub(pattern, handle_sub, row)
row = row.replace(' ', ' ')
row = row.replace('span ', 'span ')
if is_python:
for char in ['(', ')', ',', '*', '**']:
new_char = chars_template.format(char=char)
row = row.replace(char, new_char)
formatted_lines.append(row)
title_template = '<br>'.join(formatted_lines)
# Get current font properties
font = self.font()
font_size = font.pointSize()
font_family = font.family()
# Format title to display active parameter
title = title_template.format(
font_size=font_size,
font_family=font_family,
color=self._PARAMETER_HIGHLIGHT_COLOR,
parameter=parameter,
)
# Process documentation
# TODO: To be included in a separate PR
# active = active_parameter_template.format(
# font_size=font_size,
# font_family=font_family,
# color=self._PARAMETER_HIGHLIGHT_COLOR,
# parameter=parameter,
# )
# if doc is not None and len(doc) > 0:
# text_doc = doc.split('\n')[0]
# else:
# text_doc = ''
# if parameter_doc is not None and len(parameter_doc) > 0:
# text_prefix = text_doc + '<br><hr><br>param: ' + active
# text = parameter_doc
# else:
# text_prefix = ''
# text = ''
# formatted_lines = []
# rows = textwrap.wrap(text, width=60)
# for row in rows:
# row = row.replace(' ', ' ')
# if text_prefix:
# text = text_prefix + '<br><br>' + '<br>'.join(rows)
# else:
# text = '<br>'.join(rows)
# text += '<br>'
# Format text
tiptext = self._format_text(title, '', color)
return tiptext, rows | python | def _format_signature(self, signature, doc='', parameter='',
parameter_doc='', color=_DEFAULT_TITLE_COLOR,
is_python=False):
"""
Create HTML template for signature.
This template will include indent after the method name, a highlight
color for the active parameter and highlights for special chars.
"""
active_parameter_template = (
'<span style=\'font-family:"{font_family}";'
'font-size:{font_size}pt;'
'color:{color}\'>'
'<b>{parameter}</b>'
'</span>'
)
chars_template = (
'<span style="color:{0};'.format(self._CHAR_HIGHLIGHT_COLOR) +
'font-weight:bold">{char}'
'</span>'
)
def handle_sub(matchobj):
"""
Handle substitution of active parameter template.
This ensures the correct highlight of the active parameter.
"""
match = matchobj.group(0)
new = match.replace(parameter, active_parameter_template)
return new
# Remove duplicate spaces
signature = ' '.join(signature.split())
# Replace ay initial spaces
signature = signature.replace('( ', '(')
# Process signature template
pattern = r'[\*|(|\s](' + parameter + r')[,|)|\s|=]'
formatted_lines = []
name = signature.split('(')[0]
indent = ' ' * (len(name) + 1)
rows = textwrap.wrap(signature, width=60, subsequent_indent=indent)
for row in rows:
# Add template to highlight the active parameter
row = re.sub(pattern, handle_sub, row)
row = row.replace(' ', ' ')
row = row.replace('span ', 'span ')
if is_python:
for char in ['(', ')', ',', '*', '**']:
new_char = chars_template.format(char=char)
row = row.replace(char, new_char)
formatted_lines.append(row)
title_template = '<br>'.join(formatted_lines)
# Get current font properties
font = self.font()
font_size = font.pointSize()
font_family = font.family()
# Format title to display active parameter
title = title_template.format(
font_size=font_size,
font_family=font_family,
color=self._PARAMETER_HIGHLIGHT_COLOR,
parameter=parameter,
)
# Process documentation
# TODO: To be included in a separate PR
# active = active_parameter_template.format(
# font_size=font_size,
# font_family=font_family,
# color=self._PARAMETER_HIGHLIGHT_COLOR,
# parameter=parameter,
# )
# if doc is not None and len(doc) > 0:
# text_doc = doc.split('\n')[0]
# else:
# text_doc = ''
# if parameter_doc is not None and len(parameter_doc) > 0:
# text_prefix = text_doc + '<br><hr><br>param: ' + active
# text = parameter_doc
# else:
# text_prefix = ''
# text = ''
# formatted_lines = []
# rows = textwrap.wrap(text, width=60)
# for row in rows:
# row = row.replace(' ', ' ')
# if text_prefix:
# text = text_prefix + '<br><br>' + '<br>'.join(rows)
# else:
# text = '<br>'.join(rows)
# text += '<br>'
# Format text
tiptext = self._format_text(title, '', color)
return tiptext, rows | [
"def",
"_format_signature",
"(",
"self",
",",
"signature",
",",
"doc",
"=",
"''",
",",
"parameter",
"=",
"''",
",",
"parameter_doc",
"=",
"''",
",",
"color",
"=",
"_DEFAULT_TITLE_COLOR",
",",
"is_python",
"=",
"False",
")",
":",
"active_parameter_template",
"=",
"(",
"'<span style=\\'font-family:\"{font_family}\";'",
"'font-size:{font_size}pt;'",
"'color:{color}\\'>'",
"'<b>{parameter}</b>'",
"'</span>'",
")",
"chars_template",
"=",
"(",
"'<span style=\"color:{0};'",
".",
"format",
"(",
"self",
".",
"_CHAR_HIGHLIGHT_COLOR",
")",
"+",
"'font-weight:bold\">{char}'",
"'</span>'",
")",
"def",
"handle_sub",
"(",
"matchobj",
")",
":",
"\"\"\"\r\n Handle substitution of active parameter template.\r\n\r\n This ensures the correct highlight of the active parameter.\r\n \"\"\"",
"match",
"=",
"matchobj",
".",
"group",
"(",
"0",
")",
"new",
"=",
"match",
".",
"replace",
"(",
"parameter",
",",
"active_parameter_template",
")",
"return",
"new",
"# Remove duplicate spaces\r",
"signature",
"=",
"' '",
".",
"join",
"(",
"signature",
".",
"split",
"(",
")",
")",
"# Replace ay initial spaces\r",
"signature",
"=",
"signature",
".",
"replace",
"(",
"'( '",
",",
"'('",
")",
"# Process signature template\r",
"pattern",
"=",
"r'[\\*|(|\\s]('",
"+",
"parameter",
"+",
"r')[,|)|\\s|=]'",
"formatted_lines",
"=",
"[",
"]",
"name",
"=",
"signature",
".",
"split",
"(",
"'('",
")",
"[",
"0",
"]",
"indent",
"=",
"' '",
"*",
"(",
"len",
"(",
"name",
")",
"+",
"1",
")",
"rows",
"=",
"textwrap",
".",
"wrap",
"(",
"signature",
",",
"width",
"=",
"60",
",",
"subsequent_indent",
"=",
"indent",
")",
"for",
"row",
"in",
"rows",
":",
"# Add template to highlight the active parameter\r",
"row",
"=",
"re",
".",
"sub",
"(",
"pattern",
",",
"handle_sub",
",",
"row",
")",
"row",
"=",
"row",
".",
"replace",
"(",
"' '",
",",
"' '",
")",
"row",
"=",
"row",
".",
"replace",
"(",
"'span '",
",",
"'span '",
")",
"if",
"is_python",
":",
"for",
"char",
"in",
"[",
"'('",
",",
"')'",
",",
"','",
",",
"'*'",
",",
"'**'",
"]",
":",
"new_char",
"=",
"chars_template",
".",
"format",
"(",
"char",
"=",
"char",
")",
"row",
"=",
"row",
".",
"replace",
"(",
"char",
",",
"new_char",
")",
"formatted_lines",
".",
"append",
"(",
"row",
")",
"title_template",
"=",
"'<br>'",
".",
"join",
"(",
"formatted_lines",
")",
"# Get current font properties\r",
"font",
"=",
"self",
".",
"font",
"(",
")",
"font_size",
"=",
"font",
".",
"pointSize",
"(",
")",
"font_family",
"=",
"font",
".",
"family",
"(",
")",
"# Format title to display active parameter\r",
"title",
"=",
"title_template",
".",
"format",
"(",
"font_size",
"=",
"font_size",
",",
"font_family",
"=",
"font_family",
",",
"color",
"=",
"self",
".",
"_PARAMETER_HIGHLIGHT_COLOR",
",",
"parameter",
"=",
"parameter",
",",
")",
"# Process documentation\r",
"# TODO: To be included in a separate PR\r",
"# active = active_parameter_template.format(\r",
"# font_size=font_size,\r",
"# font_family=font_family,\r",
"# color=self._PARAMETER_HIGHLIGHT_COLOR,\r",
"# parameter=parameter,\r",
"# )\r",
"# if doc is not None and len(doc) > 0:\r",
"# text_doc = doc.split('\\n')[0]\r",
"# else:\r",
"# text_doc = ''\r",
"# if parameter_doc is not None and len(parameter_doc) > 0:\r",
"# text_prefix = text_doc + '<br><hr><br>param: ' + active\r",
"# text = parameter_doc\r",
"# else:\r",
"# text_prefix = ''\r",
"# text = ''\r",
"# formatted_lines = []\r",
"# rows = textwrap.wrap(text, width=60)\r",
"# for row in rows:\r",
"# row = row.replace(' ', ' ')\r",
"# if text_prefix:\r",
"# text = text_prefix + '<br><br>' + '<br>'.join(rows)\r",
"# else:\r",
"# text = '<br>'.join(rows)\r",
"# text += '<br>'\r",
"# Format text\r",
"tiptext",
"=",
"self",
".",
"_format_text",
"(",
"title",
",",
"''",
",",
"color",
")",
"return",
"tiptext",
",",
"rows"
] | Create HTML template for signature.
This template will include indent after the method name, a highlight
color for the active parameter and highlights for special chars. | [
"Create",
"HTML",
"template",
"for",
"signature",
".",
"This",
"template",
"will",
"include",
"indent",
"after",
"the",
"method",
"name",
"a",
"highlight",
"color",
"for",
"the",
"active",
"parameter",
"and",
"highlights",
"for",
"special",
"chars",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L185-L288 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.show_calltip | def show_calltip(self, signature, doc='', parameter='', parameter_doc='',
color=_DEFAULT_TITLE_COLOR, is_python=False):
"""
Show calltip.
Calltips look like tooltips but will not disappear if mouse hovers
them. They are useful for displaying signature information on methods
and functions.
"""
# Find position of calltip
point = self._calculate_position()
# Format text
tiptext, wrapped_lines = self._format_signature(
signature,
doc,
parameter,
parameter_doc,
color,
is_python,
)
self._update_stylesheet(self.calltip_widget)
# Show calltip
self.calltip_widget.show_tip(point, tiptext, wrapped_lines) | python | def show_calltip(self, signature, doc='', parameter='', parameter_doc='',
color=_DEFAULT_TITLE_COLOR, is_python=False):
"""
Show calltip.
Calltips look like tooltips but will not disappear if mouse hovers
them. They are useful for displaying signature information on methods
and functions.
"""
# Find position of calltip
point = self._calculate_position()
# Format text
tiptext, wrapped_lines = self._format_signature(
signature,
doc,
parameter,
parameter_doc,
color,
is_python,
)
self._update_stylesheet(self.calltip_widget)
# Show calltip
self.calltip_widget.show_tip(point, tiptext, wrapped_lines) | [
"def",
"show_calltip",
"(",
"self",
",",
"signature",
",",
"doc",
"=",
"''",
",",
"parameter",
"=",
"''",
",",
"parameter_doc",
"=",
"''",
",",
"color",
"=",
"_DEFAULT_TITLE_COLOR",
",",
"is_python",
"=",
"False",
")",
":",
"# Find position of calltip\r",
"point",
"=",
"self",
".",
"_calculate_position",
"(",
")",
"# Format text\r",
"tiptext",
",",
"wrapped_lines",
"=",
"self",
".",
"_format_signature",
"(",
"signature",
",",
"doc",
",",
"parameter",
",",
"parameter_doc",
",",
"color",
",",
"is_python",
",",
")",
"self",
".",
"_update_stylesheet",
"(",
"self",
".",
"calltip_widget",
")",
"# Show calltip\r",
"self",
".",
"calltip_widget",
".",
"show_tip",
"(",
"point",
",",
"tiptext",
",",
"wrapped_lines",
")"
] | Show calltip.
Calltips look like tooltips but will not disappear if mouse hovers
them. They are useful for displaying signature information on methods
and functions. | [
"Show",
"calltip",
".",
"Calltips",
"look",
"like",
"tooltips",
"but",
"will",
"not",
"disappear",
"if",
"mouse",
"hovers",
"them",
".",
"They",
"are",
"useful",
"for",
"displaying",
"signature",
"information",
"on",
"methods",
"and",
"functions",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L290-L315 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.show_tooltip | def show_tooltip(self, title, text, color=_DEFAULT_TITLE_COLOR,
at_line=None, at_position=None, at_point=None):
"""
Show tooltip.
Tooltips will disappear if mouse hovers them. They are meant for quick
inspections.
"""
if text is not None and len(text) != 0:
# Find position of calltip
point = self._calculate_position(
at_line=at_line,
at_position=at_position,
at_point=at_point,
)
# Format text
tiptext = self._format_text(title, text, color, ellide=True)
self._update_stylesheet(self.tooltip_widget)
# Display tooltip
self.tooltip_widget.show_tip(point, tiptext)
self.tooltip_widget.show() | python | def show_tooltip(self, title, text, color=_DEFAULT_TITLE_COLOR,
at_line=None, at_position=None, at_point=None):
"""
Show tooltip.
Tooltips will disappear if mouse hovers them. They are meant for quick
inspections.
"""
if text is not None and len(text) != 0:
# Find position of calltip
point = self._calculate_position(
at_line=at_line,
at_position=at_position,
at_point=at_point,
)
# Format text
tiptext = self._format_text(title, text, color, ellide=True)
self._update_stylesheet(self.tooltip_widget)
# Display tooltip
self.tooltip_widget.show_tip(point, tiptext)
self.tooltip_widget.show() | [
"def",
"show_tooltip",
"(",
"self",
",",
"title",
",",
"text",
",",
"color",
"=",
"_DEFAULT_TITLE_COLOR",
",",
"at_line",
"=",
"None",
",",
"at_position",
"=",
"None",
",",
"at_point",
"=",
"None",
")",
":",
"if",
"text",
"is",
"not",
"None",
"and",
"len",
"(",
"text",
")",
"!=",
"0",
":",
"# Find position of calltip\r",
"point",
"=",
"self",
".",
"_calculate_position",
"(",
"at_line",
"=",
"at_line",
",",
"at_position",
"=",
"at_position",
",",
"at_point",
"=",
"at_point",
",",
")",
"# Format text\r",
"tiptext",
"=",
"self",
".",
"_format_text",
"(",
"title",
",",
"text",
",",
"color",
",",
"ellide",
"=",
"True",
")",
"self",
".",
"_update_stylesheet",
"(",
"self",
".",
"tooltip_widget",
")",
"# Display tooltip\r",
"self",
".",
"tooltip_widget",
".",
"show_tip",
"(",
"point",
",",
"tiptext",
")",
"self",
".",
"tooltip_widget",
".",
"show",
"(",
")"
] | Show tooltip.
Tooltips will disappear if mouse hovers them. They are meant for quick
inspections. | [
"Show",
"tooltip",
".",
"Tooltips",
"will",
"disappear",
"if",
"mouse",
"hovers",
"them",
".",
"They",
"are",
"meant",
"for",
"quick",
"inspections",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L317-L340 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.set_eol_chars | def set_eol_chars(self, text):
"""Set widget end-of-line (EOL) characters from text (analyzes text)"""
if not is_text_string(text): # testing for QString (PyQt API#1)
text = to_text_string(text)
eol_chars = sourcecode.get_eol_chars(text)
is_document_modified = eol_chars is not None and self.eol_chars is not None
self.eol_chars = eol_chars
if is_document_modified:
self.document().setModified(True)
if self.sig_eol_chars_changed is not None:
self.sig_eol_chars_changed.emit(eol_chars) | python | def set_eol_chars(self, text):
"""Set widget end-of-line (EOL) characters from text (analyzes text)"""
if not is_text_string(text): # testing for QString (PyQt API#1)
text = to_text_string(text)
eol_chars = sourcecode.get_eol_chars(text)
is_document_modified = eol_chars is not None and self.eol_chars is not None
self.eol_chars = eol_chars
if is_document_modified:
self.document().setModified(True)
if self.sig_eol_chars_changed is not None:
self.sig_eol_chars_changed.emit(eol_chars) | [
"def",
"set_eol_chars",
"(",
"self",
",",
"text",
")",
":",
"if",
"not",
"is_text_string",
"(",
"text",
")",
":",
"# testing for QString (PyQt API#1)\r",
"text",
"=",
"to_text_string",
"(",
"text",
")",
"eol_chars",
"=",
"sourcecode",
".",
"get_eol_chars",
"(",
"text",
")",
"is_document_modified",
"=",
"eol_chars",
"is",
"not",
"None",
"and",
"self",
".",
"eol_chars",
"is",
"not",
"None",
"self",
".",
"eol_chars",
"=",
"eol_chars",
"if",
"is_document_modified",
":",
"self",
".",
"document",
"(",
")",
".",
"setModified",
"(",
"True",
")",
"if",
"self",
".",
"sig_eol_chars_changed",
"is",
"not",
"None",
":",
"self",
".",
"sig_eol_chars_changed",
".",
"emit",
"(",
"eol_chars",
")"
] | Set widget end-of-line (EOL) characters from text (analyzes text) | [
"Set",
"widget",
"end",
"-",
"of",
"-",
"line",
"(",
"EOL",
")",
"characters",
"from",
"text",
"(",
"analyzes",
"text",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L343-L353 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.get_text_with_eol | def get_text_with_eol(self):
"""Same as 'toPlainText', replace '\n'
by correct end-of-line characters"""
utext = to_text_string(self.toPlainText())
lines = utext.splitlines()
linesep = self.get_line_separator()
txt = linesep.join(lines)
if utext.endswith('\n'):
txt += linesep
return txt | python | def get_text_with_eol(self):
"""Same as 'toPlainText', replace '\n'
by correct end-of-line characters"""
utext = to_text_string(self.toPlainText())
lines = utext.splitlines()
linesep = self.get_line_separator()
txt = linesep.join(lines)
if utext.endswith('\n'):
txt += linesep
return txt | [
"def",
"get_text_with_eol",
"(",
"self",
")",
":",
"utext",
"=",
"to_text_string",
"(",
"self",
".",
"toPlainText",
"(",
")",
")",
"lines",
"=",
"utext",
".",
"splitlines",
"(",
")",
"linesep",
"=",
"self",
".",
"get_line_separator",
"(",
")",
"txt",
"=",
"linesep",
".",
"join",
"(",
"lines",
")",
"if",
"utext",
".",
"endswith",
"(",
"'\\n'",
")",
":",
"txt",
"+=",
"linesep",
"return",
"txt"
] | Same as 'toPlainText', replace '\n'
by correct end-of-line characters | [
"Same",
"as",
"toPlainText",
"replace",
"\\",
"n",
"by",
"correct",
"end",
"-",
"of",
"-",
"line",
"characters"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L362-L371 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.get_position | def get_position(self, subject):
"""Get offset in character for the given subject from the start of
text edit area"""
cursor = self.textCursor()
if subject == 'cursor':
pass
elif subject == 'sol':
cursor.movePosition(QTextCursor.StartOfBlock)
elif subject == 'eol':
cursor.movePosition(QTextCursor.EndOfBlock)
elif subject == 'eof':
cursor.movePosition(QTextCursor.End)
elif subject == 'sof':
cursor.movePosition(QTextCursor.Start)
else:
# Assuming that input argument was already a position
return subject
return cursor.position() | python | def get_position(self, subject):
"""Get offset in character for the given subject from the start of
text edit area"""
cursor = self.textCursor()
if subject == 'cursor':
pass
elif subject == 'sol':
cursor.movePosition(QTextCursor.StartOfBlock)
elif subject == 'eol':
cursor.movePosition(QTextCursor.EndOfBlock)
elif subject == 'eof':
cursor.movePosition(QTextCursor.End)
elif subject == 'sof':
cursor.movePosition(QTextCursor.Start)
else:
# Assuming that input argument was already a position
return subject
return cursor.position() | [
"def",
"get_position",
"(",
"self",
",",
"subject",
")",
":",
"cursor",
"=",
"self",
".",
"textCursor",
"(",
")",
"if",
"subject",
"==",
"'cursor'",
":",
"pass",
"elif",
"subject",
"==",
"'sol'",
":",
"cursor",
".",
"movePosition",
"(",
"QTextCursor",
".",
"StartOfBlock",
")",
"elif",
"subject",
"==",
"'eol'",
":",
"cursor",
".",
"movePosition",
"(",
"QTextCursor",
".",
"EndOfBlock",
")",
"elif",
"subject",
"==",
"'eof'",
":",
"cursor",
".",
"movePosition",
"(",
"QTextCursor",
".",
"End",
")",
"elif",
"subject",
"==",
"'sof'",
":",
"cursor",
".",
"movePosition",
"(",
"QTextCursor",
".",
"Start",
")",
"else",
":",
"# Assuming that input argument was already a position\r",
"return",
"subject",
"return",
"cursor",
".",
"position",
"(",
")"
] | Get offset in character for the given subject from the start of
text edit area | [
"Get",
"offset",
"in",
"character",
"for",
"the",
"given",
"subject",
"from",
"the",
"start",
"of",
"text",
"edit",
"area"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L375-L392 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.set_cursor_position | def set_cursor_position(self, position):
"""Set cursor position"""
position = self.get_position(position)
cursor = self.textCursor()
cursor.setPosition(position)
self.setTextCursor(cursor)
self.ensureCursorVisible() | python | def set_cursor_position(self, position):
"""Set cursor position"""
position = self.get_position(position)
cursor = self.textCursor()
cursor.setPosition(position)
self.setTextCursor(cursor)
self.ensureCursorVisible() | [
"def",
"set_cursor_position",
"(",
"self",
",",
"position",
")",
":",
"position",
"=",
"self",
".",
"get_position",
"(",
"position",
")",
"cursor",
"=",
"self",
".",
"textCursor",
"(",
")",
"cursor",
".",
"setPosition",
"(",
"position",
")",
"self",
".",
"setTextCursor",
"(",
"cursor",
")",
"self",
".",
"ensureCursorVisible",
"(",
")"
] | Set cursor position | [
"Set",
"cursor",
"position"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L410-L416 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.move_cursor | def move_cursor(self, chars=0):
"""Move cursor to left or right (unit: characters)"""
direction = QTextCursor.Right if chars > 0 else QTextCursor.Left
for _i in range(abs(chars)):
self.moveCursor(direction, QTextCursor.MoveAnchor) | python | def move_cursor(self, chars=0):
"""Move cursor to left or right (unit: characters)"""
direction = QTextCursor.Right if chars > 0 else QTextCursor.Left
for _i in range(abs(chars)):
self.moveCursor(direction, QTextCursor.MoveAnchor) | [
"def",
"move_cursor",
"(",
"self",
",",
"chars",
"=",
"0",
")",
":",
"direction",
"=",
"QTextCursor",
".",
"Right",
"if",
"chars",
">",
"0",
"else",
"QTextCursor",
".",
"Left",
"for",
"_i",
"in",
"range",
"(",
"abs",
"(",
"chars",
")",
")",
":",
"self",
".",
"moveCursor",
"(",
"direction",
",",
"QTextCursor",
".",
"MoveAnchor",
")"
] | Move cursor to left or right (unit: characters) | [
"Move",
"cursor",
"to",
"left",
"or",
"right",
"(",
"unit",
":",
"characters",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L418-L422 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.is_cursor_on_first_line | def is_cursor_on_first_line(self):
"""Return True if cursor is on the first line"""
cursor = self.textCursor()
cursor.movePosition(QTextCursor.StartOfBlock)
return cursor.atStart() | python | def is_cursor_on_first_line(self):
"""Return True if cursor is on the first line"""
cursor = self.textCursor()
cursor.movePosition(QTextCursor.StartOfBlock)
return cursor.atStart() | [
"def",
"is_cursor_on_first_line",
"(",
"self",
")",
":",
"cursor",
"=",
"self",
".",
"textCursor",
"(",
")",
"cursor",
".",
"movePosition",
"(",
"QTextCursor",
".",
"StartOfBlock",
")",
"return",
"cursor",
".",
"atStart",
"(",
")"
] | Return True if cursor is on the first line | [
"Return",
"True",
"if",
"cursor",
"is",
"on",
"the",
"first",
"line"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L424-L428 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.is_cursor_on_last_line | def is_cursor_on_last_line(self):
"""Return True if cursor is on the last line"""
cursor = self.textCursor()
cursor.movePosition(QTextCursor.EndOfBlock)
return cursor.atEnd() | python | def is_cursor_on_last_line(self):
"""Return True if cursor is on the last line"""
cursor = self.textCursor()
cursor.movePosition(QTextCursor.EndOfBlock)
return cursor.atEnd() | [
"def",
"is_cursor_on_last_line",
"(",
"self",
")",
":",
"cursor",
"=",
"self",
".",
"textCursor",
"(",
")",
"cursor",
".",
"movePosition",
"(",
"QTextCursor",
".",
"EndOfBlock",
")",
"return",
"cursor",
".",
"atEnd",
"(",
")"
] | Return True if cursor is on the last line | [
"Return",
"True",
"if",
"cursor",
"is",
"on",
"the",
"last",
"line"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L430-L434 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.is_cursor_before | def is_cursor_before(self, position, char_offset=0):
"""Return True if cursor is before *position*"""
position = self.get_position(position) + char_offset
cursor = self.textCursor()
cursor.movePosition(QTextCursor.End)
if position < cursor.position():
cursor.setPosition(position)
return self.textCursor() < cursor | python | def is_cursor_before(self, position, char_offset=0):
"""Return True if cursor is before *position*"""
position = self.get_position(position) + char_offset
cursor = self.textCursor()
cursor.movePosition(QTextCursor.End)
if position < cursor.position():
cursor.setPosition(position)
return self.textCursor() < cursor | [
"def",
"is_cursor_before",
"(",
"self",
",",
"position",
",",
"char_offset",
"=",
"0",
")",
":",
"position",
"=",
"self",
".",
"get_position",
"(",
"position",
")",
"+",
"char_offset",
"cursor",
"=",
"self",
".",
"textCursor",
"(",
")",
"cursor",
".",
"movePosition",
"(",
"QTextCursor",
".",
"End",
")",
"if",
"position",
"<",
"cursor",
".",
"position",
"(",
")",
":",
"cursor",
".",
"setPosition",
"(",
"position",
")",
"return",
"self",
".",
"textCursor",
"(",
")",
"<",
"cursor"
] | Return True if cursor is before *position* | [
"Return",
"True",
"if",
"cursor",
"is",
"before",
"*",
"position",
"*"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L440-L447 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.move_cursor_to_next | def move_cursor_to_next(self, what='word', direction='left'):
"""
Move cursor to next *what* ('word' or 'character')
toward *direction* ('left' or 'right')
"""
self.__move_cursor_anchor(what, direction, QTextCursor.MoveAnchor) | python | def move_cursor_to_next(self, what='word', direction='left'):
"""
Move cursor to next *what* ('word' or 'character')
toward *direction* ('left' or 'right')
"""
self.__move_cursor_anchor(what, direction, QTextCursor.MoveAnchor) | [
"def",
"move_cursor_to_next",
"(",
"self",
",",
"what",
"=",
"'word'",
",",
"direction",
"=",
"'left'",
")",
":",
"self",
".",
"__move_cursor_anchor",
"(",
"what",
",",
"direction",
",",
"QTextCursor",
".",
"MoveAnchor",
")"
] | Move cursor to next *what* ('word' or 'character')
toward *direction* ('left' or 'right') | [
"Move",
"cursor",
"to",
"next",
"*",
"what",
"*",
"(",
"word",
"or",
"character",
")",
"toward",
"*",
"direction",
"*",
"(",
"left",
"or",
"right",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L467-L472 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.clear_selection | def clear_selection(self):
"""Clear current selection"""
cursor = self.textCursor()
cursor.clearSelection()
self.setTextCursor(cursor) | python | def clear_selection(self):
"""Clear current selection"""
cursor = self.textCursor()
cursor.clearSelection()
self.setTextCursor(cursor) | [
"def",
"clear_selection",
"(",
"self",
")",
":",
"cursor",
"=",
"self",
".",
"textCursor",
"(",
")",
"cursor",
".",
"clearSelection",
"(",
")",
"self",
".",
"setTextCursor",
"(",
"cursor",
")"
] | Clear current selection | [
"Clear",
"current",
"selection"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L476-L480 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.extend_selection_to_next | def extend_selection_to_next(self, what='word', direction='left'):
"""
Extend selection to next *what* ('word' or 'character')
toward *direction* ('left' or 'right')
"""
self.__move_cursor_anchor(what, direction, QTextCursor.KeepAnchor) | python | def extend_selection_to_next(self, what='word', direction='left'):
"""
Extend selection to next *what* ('word' or 'character')
toward *direction* ('left' or 'right')
"""
self.__move_cursor_anchor(what, direction, QTextCursor.KeepAnchor) | [
"def",
"extend_selection_to_next",
"(",
"self",
",",
"what",
"=",
"'word'",
",",
"direction",
"=",
"'left'",
")",
":",
"self",
".",
"__move_cursor_anchor",
"(",
"what",
",",
"direction",
",",
"QTextCursor",
".",
"KeepAnchor",
")"
] | Extend selection to next *what* ('word' or 'character')
toward *direction* ('left' or 'right') | [
"Extend",
"selection",
"to",
"next",
"*",
"what",
"*",
"(",
"word",
"or",
"character",
")",
"toward",
"*",
"direction",
"*",
"(",
"left",
"or",
"right",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L482-L487 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.get_text_line | def get_text_line(self, line_nb):
"""Return text line at line number *line_nb*"""
# Taking into account the case when a file ends in an empty line,
# since splitlines doesn't return that line as the last element
# TODO: Make this function more efficient
try:
return to_text_string(self.toPlainText()).splitlines()[line_nb]
except IndexError:
return self.get_line_separator() | python | def get_text_line(self, line_nb):
"""Return text line at line number *line_nb*"""
# Taking into account the case when a file ends in an empty line,
# since splitlines doesn't return that line as the last element
# TODO: Make this function more efficient
try:
return to_text_string(self.toPlainText()).splitlines()[line_nb]
except IndexError:
return self.get_line_separator() | [
"def",
"get_text_line",
"(",
"self",
",",
"line_nb",
")",
":",
"# Taking into account the case when a file ends in an empty line,\r",
"# since splitlines doesn't return that line as the last element\r",
"# TODO: Make this function more efficient\r",
"try",
":",
"return",
"to_text_string",
"(",
"self",
".",
"toPlainText",
"(",
")",
")",
".",
"splitlines",
"(",
")",
"[",
"line_nb",
"]",
"except",
"IndexError",
":",
"return",
"self",
".",
"get_line_separator",
"(",
")"
] | Return text line at line number *line_nb* | [
"Return",
"text",
"line",
"at",
"line",
"number",
"*",
"line_nb",
"*"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L499-L507 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.get_text | def get_text(self, position_from, position_to):
"""
Return text between *position_from* and *position_to*
Positions may be positions or 'sol', 'eol', 'sof', 'eof' or 'cursor'
"""
cursor = self.__select_text(position_from, position_to)
text = to_text_string(cursor.selectedText())
all_text = position_from == 'sof' and position_to == 'eof'
if text and not all_text:
while text.endswith("\n"):
text = text[:-1]
while text.endswith(u"\u2029"):
text = text[:-1]
return text | python | def get_text(self, position_from, position_to):
"""
Return text between *position_from* and *position_to*
Positions may be positions or 'sol', 'eol', 'sof', 'eof' or 'cursor'
"""
cursor = self.__select_text(position_from, position_to)
text = to_text_string(cursor.selectedText())
all_text = position_from == 'sof' and position_to == 'eof'
if text and not all_text:
while text.endswith("\n"):
text = text[:-1]
while text.endswith(u"\u2029"):
text = text[:-1]
return text | [
"def",
"get_text",
"(",
"self",
",",
"position_from",
",",
"position_to",
")",
":",
"cursor",
"=",
"self",
".",
"__select_text",
"(",
"position_from",
",",
"position_to",
")",
"text",
"=",
"to_text_string",
"(",
"cursor",
".",
"selectedText",
"(",
")",
")",
"all_text",
"=",
"position_from",
"==",
"'sof'",
"and",
"position_to",
"==",
"'eof'",
"if",
"text",
"and",
"not",
"all_text",
":",
"while",
"text",
".",
"endswith",
"(",
"\"\\n\"",
")",
":",
"text",
"=",
"text",
"[",
":",
"-",
"1",
"]",
"while",
"text",
".",
"endswith",
"(",
"u\"\\u2029\"",
")",
":",
"text",
"=",
"text",
"[",
":",
"-",
"1",
"]",
"return",
"text"
] | Return text between *position_from* and *position_to*
Positions may be positions or 'sol', 'eol', 'sof', 'eof' or 'cursor' | [
"Return",
"text",
"between",
"*",
"position_from",
"*",
"and",
"*",
"position_to",
"*",
"Positions",
"may",
"be",
"positions",
"or",
"sol",
"eol",
"sof",
"eof",
"or",
"cursor"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L509-L522 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.get_character | def get_character(self, position, offset=0):
"""Return character at *position* with the given offset."""
position = self.get_position(position) + offset
cursor = self.textCursor()
cursor.movePosition(QTextCursor.End)
if position < cursor.position():
cursor.setPosition(position)
cursor.movePosition(QTextCursor.Right,
QTextCursor.KeepAnchor)
return to_text_string(cursor.selectedText())
else:
return '' | python | def get_character(self, position, offset=0):
"""Return character at *position* with the given offset."""
position = self.get_position(position) + offset
cursor = self.textCursor()
cursor.movePosition(QTextCursor.End)
if position < cursor.position():
cursor.setPosition(position)
cursor.movePosition(QTextCursor.Right,
QTextCursor.KeepAnchor)
return to_text_string(cursor.selectedText())
else:
return '' | [
"def",
"get_character",
"(",
"self",
",",
"position",
",",
"offset",
"=",
"0",
")",
":",
"position",
"=",
"self",
".",
"get_position",
"(",
"position",
")",
"+",
"offset",
"cursor",
"=",
"self",
".",
"textCursor",
"(",
")",
"cursor",
".",
"movePosition",
"(",
"QTextCursor",
".",
"End",
")",
"if",
"position",
"<",
"cursor",
".",
"position",
"(",
")",
":",
"cursor",
".",
"setPosition",
"(",
"position",
")",
"cursor",
".",
"movePosition",
"(",
"QTextCursor",
".",
"Right",
",",
"QTextCursor",
".",
"KeepAnchor",
")",
"return",
"to_text_string",
"(",
"cursor",
".",
"selectedText",
"(",
")",
")",
"else",
":",
"return",
"''"
] | Return character at *position* with the given offset. | [
"Return",
"character",
"at",
"*",
"position",
"*",
"with",
"the",
"given",
"offset",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L524-L535 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.get_current_word_and_position | def get_current_word_and_position(self, completion=False):
"""Return current word, i.e. word at cursor position,
and the start position"""
cursor = self.textCursor()
if cursor.hasSelection():
# Removes the selection and moves the cursor to the left side
# of the selection: this is required to be able to properly
# select the whole word under cursor (otherwise, the same word is
# not selected when the cursor is at the right side of it):
cursor.setPosition(min([cursor.selectionStart(),
cursor.selectionEnd()]))
else:
# Checks if the first character to the right is a white space
# and if not, moves the cursor one word to the left (otherwise,
# if the character to the left do not match the "word regexp"
# (see below), the word to the left of the cursor won't be
# selected), but only if the first character to the left is not a
# white space too.
def is_space(move):
curs = self.textCursor()
curs.movePosition(move, QTextCursor.KeepAnchor)
return not to_text_string(curs.selectedText()).strip()
if not completion:
if is_space(QTextCursor.NextCharacter):
if is_space(QTextCursor.PreviousCharacter):
return
cursor.movePosition(QTextCursor.WordLeft)
else:
def is_special_character(move):
curs = self.textCursor()
curs.movePosition(move, QTextCursor.KeepAnchor)
text_cursor = to_text_string(curs.selectedText()).strip()
return len(re.findall(r'([^\d\W]\w*)',
text_cursor, re.UNICODE)) == 0
if is_space(QTextCursor.PreviousCharacter):
return
if (is_special_character(QTextCursor.NextCharacter)):
cursor.movePosition(QTextCursor.WordLeft)
cursor.select(QTextCursor.WordUnderCursor)
text = to_text_string(cursor.selectedText())
# find a valid python variable name
match = re.findall(r'([^\d\W]\w*)', text, re.UNICODE)
if match:
return match[0], cursor.selectionStart() | python | def get_current_word_and_position(self, completion=False):
"""Return current word, i.e. word at cursor position,
and the start position"""
cursor = self.textCursor()
if cursor.hasSelection():
# Removes the selection and moves the cursor to the left side
# of the selection: this is required to be able to properly
# select the whole word under cursor (otherwise, the same word is
# not selected when the cursor is at the right side of it):
cursor.setPosition(min([cursor.selectionStart(),
cursor.selectionEnd()]))
else:
# Checks if the first character to the right is a white space
# and if not, moves the cursor one word to the left (otherwise,
# if the character to the left do not match the "word regexp"
# (see below), the word to the left of the cursor won't be
# selected), but only if the first character to the left is not a
# white space too.
def is_space(move):
curs = self.textCursor()
curs.movePosition(move, QTextCursor.KeepAnchor)
return not to_text_string(curs.selectedText()).strip()
if not completion:
if is_space(QTextCursor.NextCharacter):
if is_space(QTextCursor.PreviousCharacter):
return
cursor.movePosition(QTextCursor.WordLeft)
else:
def is_special_character(move):
curs = self.textCursor()
curs.movePosition(move, QTextCursor.KeepAnchor)
text_cursor = to_text_string(curs.selectedText()).strip()
return len(re.findall(r'([^\d\W]\w*)',
text_cursor, re.UNICODE)) == 0
if is_space(QTextCursor.PreviousCharacter):
return
if (is_special_character(QTextCursor.NextCharacter)):
cursor.movePosition(QTextCursor.WordLeft)
cursor.select(QTextCursor.WordUnderCursor)
text = to_text_string(cursor.selectedText())
# find a valid python variable name
match = re.findall(r'([^\d\W]\w*)', text, re.UNICODE)
if match:
return match[0], cursor.selectionStart() | [
"def",
"get_current_word_and_position",
"(",
"self",
",",
"completion",
"=",
"False",
")",
":",
"cursor",
"=",
"self",
".",
"textCursor",
"(",
")",
"if",
"cursor",
".",
"hasSelection",
"(",
")",
":",
"# Removes the selection and moves the cursor to the left side\r",
"# of the selection: this is required to be able to properly\r",
"# select the whole word under cursor (otherwise, the same word is\r",
"# not selected when the cursor is at the right side of it):\r",
"cursor",
".",
"setPosition",
"(",
"min",
"(",
"[",
"cursor",
".",
"selectionStart",
"(",
")",
",",
"cursor",
".",
"selectionEnd",
"(",
")",
"]",
")",
")",
"else",
":",
"# Checks if the first character to the right is a white space\r",
"# and if not, moves the cursor one word to the left (otherwise,\r",
"# if the character to the left do not match the \"word regexp\"\r",
"# (see below), the word to the left of the cursor won't be\r",
"# selected), but only if the first character to the left is not a\r",
"# white space too.\r",
"def",
"is_space",
"(",
"move",
")",
":",
"curs",
"=",
"self",
".",
"textCursor",
"(",
")",
"curs",
".",
"movePosition",
"(",
"move",
",",
"QTextCursor",
".",
"KeepAnchor",
")",
"return",
"not",
"to_text_string",
"(",
"curs",
".",
"selectedText",
"(",
")",
")",
".",
"strip",
"(",
")",
"if",
"not",
"completion",
":",
"if",
"is_space",
"(",
"QTextCursor",
".",
"NextCharacter",
")",
":",
"if",
"is_space",
"(",
"QTextCursor",
".",
"PreviousCharacter",
")",
":",
"return",
"cursor",
".",
"movePosition",
"(",
"QTextCursor",
".",
"WordLeft",
")",
"else",
":",
"def",
"is_special_character",
"(",
"move",
")",
":",
"curs",
"=",
"self",
".",
"textCursor",
"(",
")",
"curs",
".",
"movePosition",
"(",
"move",
",",
"QTextCursor",
".",
"KeepAnchor",
")",
"text_cursor",
"=",
"to_text_string",
"(",
"curs",
".",
"selectedText",
"(",
")",
")",
".",
"strip",
"(",
")",
"return",
"len",
"(",
"re",
".",
"findall",
"(",
"r'([^\\d\\W]\\w*)'",
",",
"text_cursor",
",",
"re",
".",
"UNICODE",
")",
")",
"==",
"0",
"if",
"is_space",
"(",
"QTextCursor",
".",
"PreviousCharacter",
")",
":",
"return",
"if",
"(",
"is_special_character",
"(",
"QTextCursor",
".",
"NextCharacter",
")",
")",
":",
"cursor",
".",
"movePosition",
"(",
"QTextCursor",
".",
"WordLeft",
")",
"cursor",
".",
"select",
"(",
"QTextCursor",
".",
"WordUnderCursor",
")",
"text",
"=",
"to_text_string",
"(",
"cursor",
".",
"selectedText",
"(",
")",
")",
"# find a valid python variable name\r",
"match",
"=",
"re",
".",
"findall",
"(",
"r'([^\\d\\W]\\w*)'",
",",
"text",
",",
"re",
".",
"UNICODE",
")",
"if",
"match",
":",
"return",
"match",
"[",
"0",
"]",
",",
"cursor",
".",
"selectionStart",
"(",
")"
] | Return current word, i.e. word at cursor position,
and the start position | [
"Return",
"current",
"word",
"i",
".",
"e",
".",
"word",
"at",
"cursor",
"position",
"and",
"the",
"start",
"position"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L551-L596 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.get_current_word | def get_current_word(self, completion=False):
"""Return current word, i.e. word at cursor position"""
ret = self.get_current_word_and_position(completion)
if ret is not None:
return ret[0] | python | def get_current_word(self, completion=False):
"""Return current word, i.e. word at cursor position"""
ret = self.get_current_word_and_position(completion)
if ret is not None:
return ret[0] | [
"def",
"get_current_word",
"(",
"self",
",",
"completion",
"=",
"False",
")",
":",
"ret",
"=",
"self",
".",
"get_current_word_and_position",
"(",
"completion",
")",
"if",
"ret",
"is",
"not",
"None",
":",
"return",
"ret",
"[",
"0",
"]"
] | Return current word, i.e. word at cursor position | [
"Return",
"current",
"word",
"i",
".",
"e",
".",
"word",
"at",
"cursor",
"position"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L598-L602 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.get_current_line | def get_current_line(self):
"""Return current line's text"""
cursor = self.textCursor()
cursor.select(QTextCursor.BlockUnderCursor)
return to_text_string(cursor.selectedText()) | python | def get_current_line(self):
"""Return current line's text"""
cursor = self.textCursor()
cursor.select(QTextCursor.BlockUnderCursor)
return to_text_string(cursor.selectedText()) | [
"def",
"get_current_line",
"(",
"self",
")",
":",
"cursor",
"=",
"self",
".",
"textCursor",
"(",
")",
"cursor",
".",
"select",
"(",
"QTextCursor",
".",
"BlockUnderCursor",
")",
"return",
"to_text_string",
"(",
"cursor",
".",
"selectedText",
"(",
")",
")"
] | Return current line's text | [
"Return",
"current",
"line",
"s",
"text"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L604-L608 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.get_line_at | def get_line_at(self, coordinates):
"""Return line at *coordinates* (QPoint)"""
cursor = self.cursorForPosition(coordinates)
cursor.select(QTextCursor.BlockUnderCursor)
return to_text_string(cursor.selectedText()).replace(u'\u2029', '') | python | def get_line_at(self, coordinates):
"""Return line at *coordinates* (QPoint)"""
cursor = self.cursorForPosition(coordinates)
cursor.select(QTextCursor.BlockUnderCursor)
return to_text_string(cursor.selectedText()).replace(u'\u2029', '') | [
"def",
"get_line_at",
"(",
"self",
",",
"coordinates",
")",
":",
"cursor",
"=",
"self",
".",
"cursorForPosition",
"(",
"coordinates",
")",
"cursor",
".",
"select",
"(",
"QTextCursor",
".",
"BlockUnderCursor",
")",
"return",
"to_text_string",
"(",
"cursor",
".",
"selectedText",
"(",
")",
")",
".",
"replace",
"(",
"u'\\u2029'",
",",
"''",
")"
] | Return line at *coordinates* (QPoint) | [
"Return",
"line",
"at",
"*",
"coordinates",
"*",
"(",
"QPoint",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L619-L623 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.get_word_at | def get_word_at(self, coordinates):
"""Return word at *coordinates* (QPoint)"""
cursor = self.cursorForPosition(coordinates)
cursor.select(QTextCursor.WordUnderCursor)
return to_text_string(cursor.selectedText()) | python | def get_word_at(self, coordinates):
"""Return word at *coordinates* (QPoint)"""
cursor = self.cursorForPosition(coordinates)
cursor.select(QTextCursor.WordUnderCursor)
return to_text_string(cursor.selectedText()) | [
"def",
"get_word_at",
"(",
"self",
",",
"coordinates",
")",
":",
"cursor",
"=",
"self",
".",
"cursorForPosition",
"(",
"coordinates",
")",
"cursor",
".",
"select",
"(",
"QTextCursor",
".",
"WordUnderCursor",
")",
"return",
"to_text_string",
"(",
"cursor",
".",
"selectedText",
"(",
")",
")"
] | Return word at *coordinates* (QPoint) | [
"Return",
"word",
"at",
"*",
"coordinates",
"*",
"(",
"QPoint",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L625-L629 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.get_block_indentation | def get_block_indentation(self, block_nb):
"""Return line indentation (character number)"""
text = to_text_string(self.document().findBlockByNumber(block_nb).text())
text = text.replace("\t", " "*self.tab_stop_width_spaces)
return len(text)-len(text.lstrip()) | python | def get_block_indentation(self, block_nb):
"""Return line indentation (character number)"""
text = to_text_string(self.document().findBlockByNumber(block_nb).text())
text = text.replace("\t", " "*self.tab_stop_width_spaces)
return len(text)-len(text.lstrip()) | [
"def",
"get_block_indentation",
"(",
"self",
",",
"block_nb",
")",
":",
"text",
"=",
"to_text_string",
"(",
"self",
".",
"document",
"(",
")",
".",
"findBlockByNumber",
"(",
"block_nb",
")",
".",
"text",
"(",
")",
")",
"text",
"=",
"text",
".",
"replace",
"(",
"\"\\t\"",
",",
"\" \"",
"*",
"self",
".",
"tab_stop_width_spaces",
")",
"return",
"len",
"(",
"text",
")",
"-",
"len",
"(",
"text",
".",
"lstrip",
"(",
")",
")"
] | Return line indentation (character number) | [
"Return",
"line",
"indentation",
"(",
"character",
"number",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L631-L635 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.get_selection_bounds | def get_selection_bounds(self):
"""Return selection bounds (block numbers)"""
cursor = self.textCursor()
start, end = cursor.selectionStart(), cursor.selectionEnd()
block_start = self.document().findBlock(start)
block_end = self.document().findBlock(end)
return sorted([block_start.blockNumber(), block_end.blockNumber()]) | python | def get_selection_bounds(self):
"""Return selection bounds (block numbers)"""
cursor = self.textCursor()
start, end = cursor.selectionStart(), cursor.selectionEnd()
block_start = self.document().findBlock(start)
block_end = self.document().findBlock(end)
return sorted([block_start.blockNumber(), block_end.blockNumber()]) | [
"def",
"get_selection_bounds",
"(",
"self",
")",
":",
"cursor",
"=",
"self",
".",
"textCursor",
"(",
")",
"start",
",",
"end",
"=",
"cursor",
".",
"selectionStart",
"(",
")",
",",
"cursor",
".",
"selectionEnd",
"(",
")",
"block_start",
"=",
"self",
".",
"document",
"(",
")",
".",
"findBlock",
"(",
"start",
")",
"block_end",
"=",
"self",
".",
"document",
"(",
")",
".",
"findBlock",
"(",
"end",
")",
"return",
"sorted",
"(",
"[",
"block_start",
".",
"blockNumber",
"(",
")",
",",
"block_end",
".",
"blockNumber",
"(",
")",
"]",
")"
] | Return selection bounds (block numbers) | [
"Return",
"selection",
"bounds",
"(",
"block",
"numbers",
")"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L637-L643 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.get_selected_text | def get_selected_text(self):
"""
Return text selected by current text cursor, converted in unicode
Replace the unicode line separator character \u2029 by
the line separator characters returned by get_line_separator
"""
return to_text_string(self.textCursor().selectedText()).replace(u"\u2029",
self.get_line_separator()) | python | def get_selected_text(self):
"""
Return text selected by current text cursor, converted in unicode
Replace the unicode line separator character \u2029 by
the line separator characters returned by get_line_separator
"""
return to_text_string(self.textCursor().selectedText()).replace(u"\u2029",
self.get_line_separator()) | [
"def",
"get_selected_text",
"(",
"self",
")",
":",
"return",
"to_text_string",
"(",
"self",
".",
"textCursor",
"(",
")",
".",
"selectedText",
"(",
")",
")",
".",
"replace",
"(",
"u\"\\u2029\"",
",",
"self",
".",
"get_line_separator",
"(",
")",
")"
] | Return text selected by current text cursor, converted in unicode
Replace the unicode line separator character \u2029 by
the line separator characters returned by get_line_separator | [
"Return",
"text",
"selected",
"by",
"current",
"text",
"cursor",
"converted",
"in",
"unicode",
"Replace",
"the",
"unicode",
"line",
"separator",
"character",
"\\",
"u2029",
"by",
"the",
"line",
"separator",
"characters",
"returned",
"by",
"get_line_separator"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L651-L659 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.replace | def replace(self, text, pattern=None):
"""Replace selected text by *text*
If *pattern* is not None, replacing selected text using regular
expression text substitution"""
cursor = self.textCursor()
cursor.beginEditBlock()
if pattern is not None:
seltxt = to_text_string(cursor.selectedText())
cursor.removeSelectedText()
if pattern is not None:
text = re.sub(to_text_string(pattern),
to_text_string(text), to_text_string(seltxt))
cursor.insertText(text)
cursor.endEditBlock() | python | def replace(self, text, pattern=None):
"""Replace selected text by *text*
If *pattern* is not None, replacing selected text using regular
expression text substitution"""
cursor = self.textCursor()
cursor.beginEditBlock()
if pattern is not None:
seltxt = to_text_string(cursor.selectedText())
cursor.removeSelectedText()
if pattern is not None:
text = re.sub(to_text_string(pattern),
to_text_string(text), to_text_string(seltxt))
cursor.insertText(text)
cursor.endEditBlock() | [
"def",
"replace",
"(",
"self",
",",
"text",
",",
"pattern",
"=",
"None",
")",
":",
"cursor",
"=",
"self",
".",
"textCursor",
"(",
")",
"cursor",
".",
"beginEditBlock",
"(",
")",
"if",
"pattern",
"is",
"not",
"None",
":",
"seltxt",
"=",
"to_text_string",
"(",
"cursor",
".",
"selectedText",
"(",
")",
")",
"cursor",
".",
"removeSelectedText",
"(",
")",
"if",
"pattern",
"is",
"not",
"None",
":",
"text",
"=",
"re",
".",
"sub",
"(",
"to_text_string",
"(",
"pattern",
")",
",",
"to_text_string",
"(",
"text",
")",
",",
"to_text_string",
"(",
"seltxt",
")",
")",
"cursor",
".",
"insertText",
"(",
"text",
")",
"cursor",
".",
"endEditBlock",
"(",
")"
] | Replace selected text by *text*
If *pattern* is not None, replacing selected text using regular
expression text substitution | [
"Replace",
"selected",
"text",
"by",
"*",
"text",
"*",
"If",
"*",
"pattern",
"*",
"is",
"not",
"None",
"replacing",
"selected",
"text",
"using",
"regular",
"expression",
"text",
"substitution"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L665-L678 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.find_multiline_pattern | def find_multiline_pattern(self, regexp, cursor, findflag):
"""Reimplement QTextDocument's find method
Add support for *multiline* regular expressions"""
pattern = to_text_string(regexp.pattern())
text = to_text_string(self.toPlainText())
try:
regobj = re.compile(pattern)
except sre_constants.error:
return
if findflag & QTextDocument.FindBackward:
# Find backward
offset = min([cursor.selectionEnd(), cursor.selectionStart()])
text = text[:offset]
matches = [_m for _m in regobj.finditer(text, 0, offset)]
if matches:
match = matches[-1]
else:
return
else:
# Find forward
offset = max([cursor.selectionEnd(), cursor.selectionStart()])
match = regobj.search(text, offset)
if match:
pos1, pos2 = match.span()
fcursor = self.textCursor()
fcursor.setPosition(pos1)
fcursor.setPosition(pos2, QTextCursor.KeepAnchor)
return fcursor | python | def find_multiline_pattern(self, regexp, cursor, findflag):
"""Reimplement QTextDocument's find method
Add support for *multiline* regular expressions"""
pattern = to_text_string(regexp.pattern())
text = to_text_string(self.toPlainText())
try:
regobj = re.compile(pattern)
except sre_constants.error:
return
if findflag & QTextDocument.FindBackward:
# Find backward
offset = min([cursor.selectionEnd(), cursor.selectionStart()])
text = text[:offset]
matches = [_m for _m in regobj.finditer(text, 0, offset)]
if matches:
match = matches[-1]
else:
return
else:
# Find forward
offset = max([cursor.selectionEnd(), cursor.selectionStart()])
match = regobj.search(text, offset)
if match:
pos1, pos2 = match.span()
fcursor = self.textCursor()
fcursor.setPosition(pos1)
fcursor.setPosition(pos2, QTextCursor.KeepAnchor)
return fcursor | [
"def",
"find_multiline_pattern",
"(",
"self",
",",
"regexp",
",",
"cursor",
",",
"findflag",
")",
":",
"pattern",
"=",
"to_text_string",
"(",
"regexp",
".",
"pattern",
"(",
")",
")",
"text",
"=",
"to_text_string",
"(",
"self",
".",
"toPlainText",
"(",
")",
")",
"try",
":",
"regobj",
"=",
"re",
".",
"compile",
"(",
"pattern",
")",
"except",
"sre_constants",
".",
"error",
":",
"return",
"if",
"findflag",
"&",
"QTextDocument",
".",
"FindBackward",
":",
"# Find backward\r",
"offset",
"=",
"min",
"(",
"[",
"cursor",
".",
"selectionEnd",
"(",
")",
",",
"cursor",
".",
"selectionStart",
"(",
")",
"]",
")",
"text",
"=",
"text",
"[",
":",
"offset",
"]",
"matches",
"=",
"[",
"_m",
"for",
"_m",
"in",
"regobj",
".",
"finditer",
"(",
"text",
",",
"0",
",",
"offset",
")",
"]",
"if",
"matches",
":",
"match",
"=",
"matches",
"[",
"-",
"1",
"]",
"else",
":",
"return",
"else",
":",
"# Find forward\r",
"offset",
"=",
"max",
"(",
"[",
"cursor",
".",
"selectionEnd",
"(",
")",
",",
"cursor",
".",
"selectionStart",
"(",
")",
"]",
")",
"match",
"=",
"regobj",
".",
"search",
"(",
"text",
",",
"offset",
")",
"if",
"match",
":",
"pos1",
",",
"pos2",
"=",
"match",
".",
"span",
"(",
")",
"fcursor",
"=",
"self",
".",
"textCursor",
"(",
")",
"fcursor",
".",
"setPosition",
"(",
"pos1",
")",
"fcursor",
".",
"setPosition",
"(",
"pos2",
",",
"QTextCursor",
".",
"KeepAnchor",
")",
"return",
"fcursor"
] | Reimplement QTextDocument's find method
Add support for *multiline* regular expressions | [
"Reimplement",
"QTextDocument",
"s",
"find",
"method",
"Add",
"support",
"for",
"*",
"multiline",
"*",
"regular",
"expressions"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L682-L710 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.find_text | def find_text(self, text, changed=True, forward=True, case=False,
words=False, regexp=False):
"""Find text"""
cursor = self.textCursor()
findflag = QTextDocument.FindFlag()
if not forward:
findflag = findflag | QTextDocument.FindBackward
if case:
findflag = findflag | QTextDocument.FindCaseSensitively
moves = [QTextCursor.NoMove]
if forward:
moves += [QTextCursor.NextWord, QTextCursor.Start]
if changed:
if to_text_string(cursor.selectedText()):
new_position = min([cursor.selectionStart(),
cursor.selectionEnd()])
cursor.setPosition(new_position)
else:
cursor.movePosition(QTextCursor.PreviousWord)
else:
moves += [QTextCursor.End]
if regexp:
text = to_text_string(text)
else:
text = re.escape(to_text_string(text))
if QT55_VERSION:
pattern = QRegularExpression(u"\\b{}\\b".format(text) if words else
text)
if case:
pattern.setPatternOptions(
QRegularExpression.CaseInsensitiveOption)
else:
pattern = QRegExp(u"\\b{}\\b".format(text)
if words else text, Qt.CaseSensitive if case else
Qt.CaseInsensitive, QRegExp.RegExp2)
for move in moves:
cursor.movePosition(move)
if regexp and '\\n' in text:
# Multiline regular expression
found_cursor = self.find_multiline_pattern(pattern, cursor,
findflag)
else:
# Single line find: using the QTextDocument's find function,
# probably much more efficient than ours
found_cursor = self.document().find(pattern, cursor, findflag)
if found_cursor is not None and not found_cursor.isNull():
self.setTextCursor(found_cursor)
return True
return False | python | def find_text(self, text, changed=True, forward=True, case=False,
words=False, regexp=False):
"""Find text"""
cursor = self.textCursor()
findflag = QTextDocument.FindFlag()
if not forward:
findflag = findflag | QTextDocument.FindBackward
if case:
findflag = findflag | QTextDocument.FindCaseSensitively
moves = [QTextCursor.NoMove]
if forward:
moves += [QTextCursor.NextWord, QTextCursor.Start]
if changed:
if to_text_string(cursor.selectedText()):
new_position = min([cursor.selectionStart(),
cursor.selectionEnd()])
cursor.setPosition(new_position)
else:
cursor.movePosition(QTextCursor.PreviousWord)
else:
moves += [QTextCursor.End]
if regexp:
text = to_text_string(text)
else:
text = re.escape(to_text_string(text))
if QT55_VERSION:
pattern = QRegularExpression(u"\\b{}\\b".format(text) if words else
text)
if case:
pattern.setPatternOptions(
QRegularExpression.CaseInsensitiveOption)
else:
pattern = QRegExp(u"\\b{}\\b".format(text)
if words else text, Qt.CaseSensitive if case else
Qt.CaseInsensitive, QRegExp.RegExp2)
for move in moves:
cursor.movePosition(move)
if regexp and '\\n' in text:
# Multiline regular expression
found_cursor = self.find_multiline_pattern(pattern, cursor,
findflag)
else:
# Single line find: using the QTextDocument's find function,
# probably much more efficient than ours
found_cursor = self.document().find(pattern, cursor, findflag)
if found_cursor is not None and not found_cursor.isNull():
self.setTextCursor(found_cursor)
return True
return False | [
"def",
"find_text",
"(",
"self",
",",
"text",
",",
"changed",
"=",
"True",
",",
"forward",
"=",
"True",
",",
"case",
"=",
"False",
",",
"words",
"=",
"False",
",",
"regexp",
"=",
"False",
")",
":",
"cursor",
"=",
"self",
".",
"textCursor",
"(",
")",
"findflag",
"=",
"QTextDocument",
".",
"FindFlag",
"(",
")",
"if",
"not",
"forward",
":",
"findflag",
"=",
"findflag",
"|",
"QTextDocument",
".",
"FindBackward",
"if",
"case",
":",
"findflag",
"=",
"findflag",
"|",
"QTextDocument",
".",
"FindCaseSensitively",
"moves",
"=",
"[",
"QTextCursor",
".",
"NoMove",
"]",
"if",
"forward",
":",
"moves",
"+=",
"[",
"QTextCursor",
".",
"NextWord",
",",
"QTextCursor",
".",
"Start",
"]",
"if",
"changed",
":",
"if",
"to_text_string",
"(",
"cursor",
".",
"selectedText",
"(",
")",
")",
":",
"new_position",
"=",
"min",
"(",
"[",
"cursor",
".",
"selectionStart",
"(",
")",
",",
"cursor",
".",
"selectionEnd",
"(",
")",
"]",
")",
"cursor",
".",
"setPosition",
"(",
"new_position",
")",
"else",
":",
"cursor",
".",
"movePosition",
"(",
"QTextCursor",
".",
"PreviousWord",
")",
"else",
":",
"moves",
"+=",
"[",
"QTextCursor",
".",
"End",
"]",
"if",
"regexp",
":",
"text",
"=",
"to_text_string",
"(",
"text",
")",
"else",
":",
"text",
"=",
"re",
".",
"escape",
"(",
"to_text_string",
"(",
"text",
")",
")",
"if",
"QT55_VERSION",
":",
"pattern",
"=",
"QRegularExpression",
"(",
"u\"\\\\b{}\\\\b\"",
".",
"format",
"(",
"text",
")",
"if",
"words",
"else",
"text",
")",
"if",
"case",
":",
"pattern",
".",
"setPatternOptions",
"(",
"QRegularExpression",
".",
"CaseInsensitiveOption",
")",
"else",
":",
"pattern",
"=",
"QRegExp",
"(",
"u\"\\\\b{}\\\\b\"",
".",
"format",
"(",
"text",
")",
"if",
"words",
"else",
"text",
",",
"Qt",
".",
"CaseSensitive",
"if",
"case",
"else",
"Qt",
".",
"CaseInsensitive",
",",
"QRegExp",
".",
"RegExp2",
")",
"for",
"move",
"in",
"moves",
":",
"cursor",
".",
"movePosition",
"(",
"move",
")",
"if",
"regexp",
"and",
"'\\\\n'",
"in",
"text",
":",
"# Multiline regular expression\r",
"found_cursor",
"=",
"self",
".",
"find_multiline_pattern",
"(",
"pattern",
",",
"cursor",
",",
"findflag",
")",
"else",
":",
"# Single line find: using the QTextDocument's find function,\r",
"# probably much more efficient than ours\r",
"found_cursor",
"=",
"self",
".",
"document",
"(",
")",
".",
"find",
"(",
"pattern",
",",
"cursor",
",",
"findflag",
")",
"if",
"found_cursor",
"is",
"not",
"None",
"and",
"not",
"found_cursor",
".",
"isNull",
"(",
")",
":",
"self",
".",
"setTextCursor",
"(",
"found_cursor",
")",
"return",
"True",
"return",
"False"
] | Find text | [
"Find",
"text"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L712-L767 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.get_number_matches | def get_number_matches(self, pattern, source_text='', case=False,
regexp=False):
"""Get the number of matches for the searched text."""
pattern = to_text_string(pattern)
if not pattern:
return 0
if not regexp:
pattern = re.escape(pattern)
if not source_text:
source_text = to_text_string(self.toPlainText())
try:
if case:
regobj = re.compile(pattern)
else:
regobj = re.compile(pattern, re.IGNORECASE)
except sre_constants.error:
return None
number_matches = 0
for match in regobj.finditer(source_text):
number_matches += 1
return number_matches | python | def get_number_matches(self, pattern, source_text='', case=False,
regexp=False):
"""Get the number of matches for the searched text."""
pattern = to_text_string(pattern)
if not pattern:
return 0
if not regexp:
pattern = re.escape(pattern)
if not source_text:
source_text = to_text_string(self.toPlainText())
try:
if case:
regobj = re.compile(pattern)
else:
regobj = re.compile(pattern, re.IGNORECASE)
except sre_constants.error:
return None
number_matches = 0
for match in regobj.finditer(source_text):
number_matches += 1
return number_matches | [
"def",
"get_number_matches",
"(",
"self",
",",
"pattern",
",",
"source_text",
"=",
"''",
",",
"case",
"=",
"False",
",",
"regexp",
"=",
"False",
")",
":",
"pattern",
"=",
"to_text_string",
"(",
"pattern",
")",
"if",
"not",
"pattern",
":",
"return",
"0",
"if",
"not",
"regexp",
":",
"pattern",
"=",
"re",
".",
"escape",
"(",
"pattern",
")",
"if",
"not",
"source_text",
":",
"source_text",
"=",
"to_text_string",
"(",
"self",
".",
"toPlainText",
"(",
")",
")",
"try",
":",
"if",
"case",
":",
"regobj",
"=",
"re",
".",
"compile",
"(",
"pattern",
")",
"else",
":",
"regobj",
"=",
"re",
".",
"compile",
"(",
"pattern",
",",
"re",
".",
"IGNORECASE",
")",
"except",
"sre_constants",
".",
"error",
":",
"return",
"None",
"number_matches",
"=",
"0",
"for",
"match",
"in",
"regobj",
".",
"finditer",
"(",
"source_text",
")",
":",
"number_matches",
"+=",
"1",
"return",
"number_matches"
] | Get the number of matches for the searched text. | [
"Get",
"the",
"number",
"of",
"matches",
"for",
"the",
"searched",
"text",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L773-L798 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BaseEditMixin.get_match_number | def get_match_number(self, pattern, case=False, regexp=False):
"""Get number of the match for the searched text."""
position = self.textCursor().position()
source_text = self.get_text(position_from='sof', position_to=position)
match_number = self.get_number_matches(pattern,
source_text=source_text,
case=case, regexp=regexp)
return match_number | python | def get_match_number(self, pattern, case=False, regexp=False):
"""Get number of the match for the searched text."""
position = self.textCursor().position()
source_text = self.get_text(position_from='sof', position_to=position)
match_number = self.get_number_matches(pattern,
source_text=source_text,
case=case, regexp=regexp)
return match_number | [
"def",
"get_match_number",
"(",
"self",
",",
"pattern",
",",
"case",
"=",
"False",
",",
"regexp",
"=",
"False",
")",
":",
"position",
"=",
"self",
".",
"textCursor",
"(",
")",
".",
"position",
"(",
")",
"source_text",
"=",
"self",
".",
"get_text",
"(",
"position_from",
"=",
"'sof'",
",",
"position_to",
"=",
"position",
")",
"match_number",
"=",
"self",
".",
"get_number_matches",
"(",
"pattern",
",",
"source_text",
"=",
"source_text",
",",
"case",
"=",
"case",
",",
"regexp",
"=",
"regexp",
")",
"return",
"match_number"
] | Get number of the match for the searched text. | [
"Get",
"number",
"of",
"the",
"match",
"for",
"the",
"searched",
"text",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L800-L807 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | TracebackLinksMixin.mouseReleaseEvent | def mouseReleaseEvent(self, event):
"""Go to error"""
self.QT_CLASS.mouseReleaseEvent(self, event)
text = self.get_line_at(event.pos())
if get_error_match(text) and not self.has_selected_text():
if self.go_to_error is not None:
self.go_to_error.emit(text) | python | def mouseReleaseEvent(self, event):
"""Go to error"""
self.QT_CLASS.mouseReleaseEvent(self, event)
text = self.get_line_at(event.pos())
if get_error_match(text) and not self.has_selected_text():
if self.go_to_error is not None:
self.go_to_error.emit(text) | [
"def",
"mouseReleaseEvent",
"(",
"self",
",",
"event",
")",
":",
"self",
".",
"QT_CLASS",
".",
"mouseReleaseEvent",
"(",
"self",
",",
"event",
")",
"text",
"=",
"self",
".",
"get_line_at",
"(",
"event",
".",
"pos",
"(",
")",
")",
"if",
"get_error_match",
"(",
"text",
")",
"and",
"not",
"self",
".",
"has_selected_text",
"(",
")",
":",
"if",
"self",
".",
"go_to_error",
"is",
"not",
"None",
":",
"self",
".",
"go_to_error",
".",
"emit",
"(",
"text",
")"
] | Go to error | [
"Go",
"to",
"error"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L862-L868 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | TracebackLinksMixin.mouseMoveEvent | def mouseMoveEvent(self, event):
"""Show Pointing Hand Cursor on error messages"""
text = self.get_line_at(event.pos())
if get_error_match(text):
if not self.__cursor_changed:
QApplication.setOverrideCursor(QCursor(Qt.PointingHandCursor))
self.__cursor_changed = True
event.accept()
return
if self.__cursor_changed:
QApplication.restoreOverrideCursor()
self.__cursor_changed = False
self.QT_CLASS.mouseMoveEvent(self, event) | python | def mouseMoveEvent(self, event):
"""Show Pointing Hand Cursor on error messages"""
text = self.get_line_at(event.pos())
if get_error_match(text):
if not self.__cursor_changed:
QApplication.setOverrideCursor(QCursor(Qt.PointingHandCursor))
self.__cursor_changed = True
event.accept()
return
if self.__cursor_changed:
QApplication.restoreOverrideCursor()
self.__cursor_changed = False
self.QT_CLASS.mouseMoveEvent(self, event) | [
"def",
"mouseMoveEvent",
"(",
"self",
",",
"event",
")",
":",
"text",
"=",
"self",
".",
"get_line_at",
"(",
"event",
".",
"pos",
"(",
")",
")",
"if",
"get_error_match",
"(",
"text",
")",
":",
"if",
"not",
"self",
".",
"__cursor_changed",
":",
"QApplication",
".",
"setOverrideCursor",
"(",
"QCursor",
"(",
"Qt",
".",
"PointingHandCursor",
")",
")",
"self",
".",
"__cursor_changed",
"=",
"True",
"event",
".",
"accept",
"(",
")",
"return",
"if",
"self",
".",
"__cursor_changed",
":",
"QApplication",
".",
"restoreOverrideCursor",
"(",
")",
"self",
".",
"__cursor_changed",
"=",
"False",
"self",
".",
"QT_CLASS",
".",
"mouseMoveEvent",
"(",
"self",
",",
"event",
")"
] | Show Pointing Hand Cursor on error messages | [
"Show",
"Pointing",
"Hand",
"Cursor",
"on",
"error",
"messages"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L870-L882 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | TracebackLinksMixin.leaveEvent | def leaveEvent(self, event):
"""If cursor has not been restored yet, do it now"""
if self.__cursor_changed:
QApplication.restoreOverrideCursor()
self.__cursor_changed = False
self.QT_CLASS.leaveEvent(self, event) | python | def leaveEvent(self, event):
"""If cursor has not been restored yet, do it now"""
if self.__cursor_changed:
QApplication.restoreOverrideCursor()
self.__cursor_changed = False
self.QT_CLASS.leaveEvent(self, event) | [
"def",
"leaveEvent",
"(",
"self",
",",
"event",
")",
":",
"if",
"self",
".",
"__cursor_changed",
":",
"QApplication",
".",
"restoreOverrideCursor",
"(",
")",
"self",
".",
"__cursor_changed",
"=",
"False",
"self",
".",
"QT_CLASS",
".",
"leaveEvent",
"(",
"self",
",",
"event",
")"
] | If cursor has not been restored yet, do it now | [
"If",
"cursor",
"has",
"not",
"been",
"restored",
"yet",
"do",
"it",
"now"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L884-L889 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | GetHelpMixin.show_object_info | def show_object_info(self, text, call=False, force=False):
"""Show signature calltip and/or docstring in the Help plugin"""
text = to_text_string(text)
# Show docstring
help_enabled = self.help_enabled or force
if force and self.help is not None:
self.help.dockwidget.setVisible(True)
self.help.dockwidget.raise_()
if help_enabled and (self.help is not None) and \
(self.help.dockwidget.isVisible()):
# Help widget exists and is visible
if hasattr(self, 'get_doc'):
self.help.set_shell(self)
else:
self.help.set_shell(self.parent())
self.help.set_object_text(text, ignore_unknown=False)
self.setFocus() # if help was not at top level, raising it to
# top will automatically give it focus because of
# the visibility_changed signal, so we must give
# focus back to shell
# Show calltip
if call and getattr(self, 'calltips', None):
# Display argument list if this is a function call
iscallable = self.iscallable(text)
if iscallable is not None:
if iscallable:
arglist = self.get_arglist(text)
name = text.split('.')[-1]
argspec = signature = ''
if isinstance(arglist, bool):
arglist = []
if arglist:
argspec = '(' + ''.join(arglist) + ')'
else:
doc = self.get__doc__(text)
if doc is not None:
# This covers cases like np.abs, whose docstring is
# the same as np.absolute and because of that a
# proper signature can't be obtained correctly
argspec = getargspecfromtext(doc)
if not argspec:
signature = getsignaturefromtext(doc, name)
if argspec or signature:
if argspec:
tiptext = name + argspec
else:
tiptext = signature
# TODO: Select language and pass it to call
self.show_calltip(tiptext, color='#2D62FF', is_python=True) | python | def show_object_info(self, text, call=False, force=False):
"""Show signature calltip and/or docstring in the Help plugin"""
text = to_text_string(text)
# Show docstring
help_enabled = self.help_enabled or force
if force and self.help is not None:
self.help.dockwidget.setVisible(True)
self.help.dockwidget.raise_()
if help_enabled and (self.help is not None) and \
(self.help.dockwidget.isVisible()):
# Help widget exists and is visible
if hasattr(self, 'get_doc'):
self.help.set_shell(self)
else:
self.help.set_shell(self.parent())
self.help.set_object_text(text, ignore_unknown=False)
self.setFocus() # if help was not at top level, raising it to
# top will automatically give it focus because of
# the visibility_changed signal, so we must give
# focus back to shell
# Show calltip
if call and getattr(self, 'calltips', None):
# Display argument list if this is a function call
iscallable = self.iscallable(text)
if iscallable is not None:
if iscallable:
arglist = self.get_arglist(text)
name = text.split('.')[-1]
argspec = signature = ''
if isinstance(arglist, bool):
arglist = []
if arglist:
argspec = '(' + ''.join(arglist) + ')'
else:
doc = self.get__doc__(text)
if doc is not None:
# This covers cases like np.abs, whose docstring is
# the same as np.absolute and because of that a
# proper signature can't be obtained correctly
argspec = getargspecfromtext(doc)
if not argspec:
signature = getsignaturefromtext(doc, name)
if argspec or signature:
if argspec:
tiptext = name + argspec
else:
tiptext = signature
# TODO: Select language and pass it to call
self.show_calltip(tiptext, color='#2D62FF', is_python=True) | [
"def",
"show_object_info",
"(",
"self",
",",
"text",
",",
"call",
"=",
"False",
",",
"force",
"=",
"False",
")",
":",
"text",
"=",
"to_text_string",
"(",
"text",
")",
"# Show docstring\r",
"help_enabled",
"=",
"self",
".",
"help_enabled",
"or",
"force",
"if",
"force",
"and",
"self",
".",
"help",
"is",
"not",
"None",
":",
"self",
".",
"help",
".",
"dockwidget",
".",
"setVisible",
"(",
"True",
")",
"self",
".",
"help",
".",
"dockwidget",
".",
"raise_",
"(",
")",
"if",
"help_enabled",
"and",
"(",
"self",
".",
"help",
"is",
"not",
"None",
")",
"and",
"(",
"self",
".",
"help",
".",
"dockwidget",
".",
"isVisible",
"(",
")",
")",
":",
"# Help widget exists and is visible\r",
"if",
"hasattr",
"(",
"self",
",",
"'get_doc'",
")",
":",
"self",
".",
"help",
".",
"set_shell",
"(",
"self",
")",
"else",
":",
"self",
".",
"help",
".",
"set_shell",
"(",
"self",
".",
"parent",
"(",
")",
")",
"self",
".",
"help",
".",
"set_object_text",
"(",
"text",
",",
"ignore_unknown",
"=",
"False",
")",
"self",
".",
"setFocus",
"(",
")",
"# if help was not at top level, raising it to\r",
"# top will automatically give it focus because of\r",
"# the visibility_changed signal, so we must give\r",
"# focus back to shell\r",
"# Show calltip\r",
"if",
"call",
"and",
"getattr",
"(",
"self",
",",
"'calltips'",
",",
"None",
")",
":",
"# Display argument list if this is a function call\r",
"iscallable",
"=",
"self",
".",
"iscallable",
"(",
"text",
")",
"if",
"iscallable",
"is",
"not",
"None",
":",
"if",
"iscallable",
":",
"arglist",
"=",
"self",
".",
"get_arglist",
"(",
"text",
")",
"name",
"=",
"text",
".",
"split",
"(",
"'.'",
")",
"[",
"-",
"1",
"]",
"argspec",
"=",
"signature",
"=",
"''",
"if",
"isinstance",
"(",
"arglist",
",",
"bool",
")",
":",
"arglist",
"=",
"[",
"]",
"if",
"arglist",
":",
"argspec",
"=",
"'('",
"+",
"''",
".",
"join",
"(",
"arglist",
")",
"+",
"')'",
"else",
":",
"doc",
"=",
"self",
".",
"get__doc__",
"(",
"text",
")",
"if",
"doc",
"is",
"not",
"None",
":",
"# This covers cases like np.abs, whose docstring is\r",
"# the same as np.absolute and because of that a\r",
"# proper signature can't be obtained correctly\r",
"argspec",
"=",
"getargspecfromtext",
"(",
"doc",
")",
"if",
"not",
"argspec",
":",
"signature",
"=",
"getsignaturefromtext",
"(",
"doc",
",",
"name",
")",
"if",
"argspec",
"or",
"signature",
":",
"if",
"argspec",
":",
"tiptext",
"=",
"name",
"+",
"argspec",
"else",
":",
"tiptext",
"=",
"signature",
"# TODO: Select language and pass it to call\r",
"self",
".",
"show_calltip",
"(",
"tiptext",
",",
"color",
"=",
"'#2D62FF'",
",",
"is_python",
"=",
"True",
")"
] | Show signature calltip and/or docstring in the Help plugin | [
"Show",
"signature",
"calltip",
"and",
"/",
"or",
"docstring",
"in",
"the",
"Help",
"plugin"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L917-L967 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | SaveHistoryMixin.create_history_filename | def create_history_filename(self):
"""Create history_filename with INITHISTORY if it doesn't exist."""
if self.history_filename and not osp.isfile(self.history_filename):
try:
encoding.writelines(self.INITHISTORY, self.history_filename)
except EnvironmentError:
pass | python | def create_history_filename(self):
"""Create history_filename with INITHISTORY if it doesn't exist."""
if self.history_filename and not osp.isfile(self.history_filename):
try:
encoding.writelines(self.INITHISTORY, self.history_filename)
except EnvironmentError:
pass | [
"def",
"create_history_filename",
"(",
"self",
")",
":",
"if",
"self",
".",
"history_filename",
"and",
"not",
"osp",
".",
"isfile",
"(",
"self",
".",
"history_filename",
")",
":",
"try",
":",
"encoding",
".",
"writelines",
"(",
"self",
".",
"INITHISTORY",
",",
"self",
".",
"history_filename",
")",
"except",
"EnvironmentError",
":",
"pass"
] | Create history_filename with INITHISTORY if it doesn't exist. | [
"Create",
"history_filename",
"with",
"INITHISTORY",
"if",
"it",
"doesn",
"t",
"exist",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L988-L994 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | SaveHistoryMixin.add_to_history | def add_to_history(self, command):
"""Add command to history"""
command = to_text_string(command)
if command in ['', '\n'] or command.startswith('Traceback'):
return
if command.endswith('\n'):
command = command[:-1]
self.histidx = None
if len(self.history) > 0 and self.history[-1] == command:
return
self.history.append(command)
text = os.linesep + command
# When the first entry will be written in history file,
# the separator will be append first:
if self.history_filename not in self.HISTORY_FILENAMES:
self.HISTORY_FILENAMES.append(self.history_filename)
text = self.SEPARATOR + text
# Needed to prevent errors when writing history to disk
# See issue 6431
try:
encoding.write(text, self.history_filename, mode='ab')
except EnvironmentError:
pass
if self.append_to_history is not None:
self.append_to_history.emit(self.history_filename, text) | python | def add_to_history(self, command):
"""Add command to history"""
command = to_text_string(command)
if command in ['', '\n'] or command.startswith('Traceback'):
return
if command.endswith('\n'):
command = command[:-1]
self.histidx = None
if len(self.history) > 0 and self.history[-1] == command:
return
self.history.append(command)
text = os.linesep + command
# When the first entry will be written in history file,
# the separator will be append first:
if self.history_filename not in self.HISTORY_FILENAMES:
self.HISTORY_FILENAMES.append(self.history_filename)
text = self.SEPARATOR + text
# Needed to prevent errors when writing history to disk
# See issue 6431
try:
encoding.write(text, self.history_filename, mode='ab')
except EnvironmentError:
pass
if self.append_to_history is not None:
self.append_to_history.emit(self.history_filename, text) | [
"def",
"add_to_history",
"(",
"self",
",",
"command",
")",
":",
"command",
"=",
"to_text_string",
"(",
"command",
")",
"if",
"command",
"in",
"[",
"''",
",",
"'\\n'",
"]",
"or",
"command",
".",
"startswith",
"(",
"'Traceback'",
")",
":",
"return",
"if",
"command",
".",
"endswith",
"(",
"'\\n'",
")",
":",
"command",
"=",
"command",
"[",
":",
"-",
"1",
"]",
"self",
".",
"histidx",
"=",
"None",
"if",
"len",
"(",
"self",
".",
"history",
")",
">",
"0",
"and",
"self",
".",
"history",
"[",
"-",
"1",
"]",
"==",
"command",
":",
"return",
"self",
".",
"history",
".",
"append",
"(",
"command",
")",
"text",
"=",
"os",
".",
"linesep",
"+",
"command",
"# When the first entry will be written in history file,\r",
"# the separator will be append first:\r",
"if",
"self",
".",
"history_filename",
"not",
"in",
"self",
".",
"HISTORY_FILENAMES",
":",
"self",
".",
"HISTORY_FILENAMES",
".",
"append",
"(",
"self",
".",
"history_filename",
")",
"text",
"=",
"self",
".",
"SEPARATOR",
"+",
"text",
"# Needed to prevent errors when writing history to disk\r",
"# See issue 6431\r",
"try",
":",
"encoding",
".",
"write",
"(",
"text",
",",
"self",
".",
"history_filename",
",",
"mode",
"=",
"'ab'",
")",
"except",
"EnvironmentError",
":",
"pass",
"if",
"self",
".",
"append_to_history",
"is",
"not",
"None",
":",
"self",
".",
"append_to_history",
".",
"emit",
"(",
"self",
".",
"history_filename",
",",
"text",
")"
] | Add command to history | [
"Add",
"command",
"to",
"history"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L996-L1021 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BrowseHistoryMixin.browse_history | def browse_history(self, backward):
"""Browse history"""
if self.is_cursor_before('eol') and self.hist_wholeline:
self.hist_wholeline = False
tocursor = self.get_current_line_to_cursor()
text, self.histidx = self.find_in_history(tocursor, self.histidx,
backward)
if text is not None:
if self.hist_wholeline:
self.clear_line()
self.insert_text(text)
else:
cursor_position = self.get_position('cursor')
# Removing text from cursor to the end of the line
self.remove_text('cursor', 'eol')
# Inserting history text
self.insert_text(text)
self.set_cursor_position(cursor_position) | python | def browse_history(self, backward):
"""Browse history"""
if self.is_cursor_before('eol') and self.hist_wholeline:
self.hist_wholeline = False
tocursor = self.get_current_line_to_cursor()
text, self.histidx = self.find_in_history(tocursor, self.histidx,
backward)
if text is not None:
if self.hist_wholeline:
self.clear_line()
self.insert_text(text)
else:
cursor_position = self.get_position('cursor')
# Removing text from cursor to the end of the line
self.remove_text('cursor', 'eol')
# Inserting history text
self.insert_text(text)
self.set_cursor_position(cursor_position) | [
"def",
"browse_history",
"(",
"self",
",",
"backward",
")",
":",
"if",
"self",
".",
"is_cursor_before",
"(",
"'eol'",
")",
"and",
"self",
".",
"hist_wholeline",
":",
"self",
".",
"hist_wholeline",
"=",
"False",
"tocursor",
"=",
"self",
".",
"get_current_line_to_cursor",
"(",
")",
"text",
",",
"self",
".",
"histidx",
"=",
"self",
".",
"find_in_history",
"(",
"tocursor",
",",
"self",
".",
"histidx",
",",
"backward",
")",
"if",
"text",
"is",
"not",
"None",
":",
"if",
"self",
".",
"hist_wholeline",
":",
"self",
".",
"clear_line",
"(",
")",
"self",
".",
"insert_text",
"(",
"text",
")",
"else",
":",
"cursor_position",
"=",
"self",
".",
"get_position",
"(",
"'cursor'",
")",
"# Removing text from cursor to the end of the line\r",
"self",
".",
"remove_text",
"(",
"'cursor'",
",",
"'eol'",
")",
"# Inserting history text\r",
"self",
".",
"insert_text",
"(",
"text",
")",
"self",
".",
"set_cursor_position",
"(",
"cursor_position",
")"
] | Browse history | [
"Browse",
"history"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L1035-L1052 | train |
spyder-ide/spyder | spyder/widgets/mixins.py | BrowseHistoryMixin.find_in_history | def find_in_history(self, tocursor, start_idx, backward):
"""Find text 'tocursor' in history, from index 'start_idx'"""
if start_idx is None:
start_idx = len(self.history)
# Finding text in history
step = -1 if backward else 1
idx = start_idx
if len(tocursor) == 0 or self.hist_wholeline:
idx += step
if idx >= len(self.history) or len(self.history) == 0:
return "", len(self.history)
elif idx < 0:
idx = 0
self.hist_wholeline = True
return self.history[idx], idx
else:
for index in range(len(self.history)):
idx = (start_idx+step*(index+1)) % len(self.history)
entry = self.history[idx]
if entry.startswith(tocursor):
return entry[len(tocursor):], idx
else:
return None, start_idx | python | def find_in_history(self, tocursor, start_idx, backward):
"""Find text 'tocursor' in history, from index 'start_idx'"""
if start_idx is None:
start_idx = len(self.history)
# Finding text in history
step = -1 if backward else 1
idx = start_idx
if len(tocursor) == 0 or self.hist_wholeline:
idx += step
if idx >= len(self.history) or len(self.history) == 0:
return "", len(self.history)
elif idx < 0:
idx = 0
self.hist_wholeline = True
return self.history[idx], idx
else:
for index in range(len(self.history)):
idx = (start_idx+step*(index+1)) % len(self.history)
entry = self.history[idx]
if entry.startswith(tocursor):
return entry[len(tocursor):], idx
else:
return None, start_idx | [
"def",
"find_in_history",
"(",
"self",
",",
"tocursor",
",",
"start_idx",
",",
"backward",
")",
":",
"if",
"start_idx",
"is",
"None",
":",
"start_idx",
"=",
"len",
"(",
"self",
".",
"history",
")",
"# Finding text in history\r",
"step",
"=",
"-",
"1",
"if",
"backward",
"else",
"1",
"idx",
"=",
"start_idx",
"if",
"len",
"(",
"tocursor",
")",
"==",
"0",
"or",
"self",
".",
"hist_wholeline",
":",
"idx",
"+=",
"step",
"if",
"idx",
">=",
"len",
"(",
"self",
".",
"history",
")",
"or",
"len",
"(",
"self",
".",
"history",
")",
"==",
"0",
":",
"return",
"\"\"",
",",
"len",
"(",
"self",
".",
"history",
")",
"elif",
"idx",
"<",
"0",
":",
"idx",
"=",
"0",
"self",
".",
"hist_wholeline",
"=",
"True",
"return",
"self",
".",
"history",
"[",
"idx",
"]",
",",
"idx",
"else",
":",
"for",
"index",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"history",
")",
")",
":",
"idx",
"=",
"(",
"start_idx",
"+",
"step",
"*",
"(",
"index",
"+",
"1",
")",
")",
"%",
"len",
"(",
"self",
".",
"history",
")",
"entry",
"=",
"self",
".",
"history",
"[",
"idx",
"]",
"if",
"entry",
".",
"startswith",
"(",
"tocursor",
")",
":",
"return",
"entry",
"[",
"len",
"(",
"tocursor",
")",
":",
"]",
",",
"idx",
"else",
":",
"return",
"None",
",",
"start_idx"
] | Find text 'tocursor' in history, from index 'start_idx | [
"Find",
"text",
"tocursor",
"in",
"history",
"from",
"index",
"start_idx"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/mixins.py#L1054-L1076 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutTranslator.keyevent_to_keyseq | def keyevent_to_keyseq(self, event):
"""Return a QKeySequence representation of the provided QKeyEvent."""
self.keyPressEvent(event)
event.accept()
return self.keySequence() | python | def keyevent_to_keyseq(self, event):
"""Return a QKeySequence representation of the provided QKeyEvent."""
self.keyPressEvent(event)
event.accept()
return self.keySequence() | [
"def",
"keyevent_to_keyseq",
"(",
"self",
",",
"event",
")",
":",
"self",
".",
"keyPressEvent",
"(",
"event",
")",
"event",
".",
"accept",
"(",
")",
"return",
"self",
".",
"keySequence",
"(",
")"
] | Return a QKeySequence representation of the provided QKeyEvent. | [
"Return",
"a",
"QKeySequence",
"representation",
"of",
"the",
"provided",
"QKeyEvent",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L74-L78 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutLineEdit.setText | def setText(self, sequence):
"""Qt method extension."""
self.setToolTip(sequence)
super(ShortcutLineEdit, self).setText(sequence) | python | def setText(self, sequence):
"""Qt method extension."""
self.setToolTip(sequence)
super(ShortcutLineEdit, self).setText(sequence) | [
"def",
"setText",
"(",
"self",
",",
"sequence",
")",
":",
"self",
".",
"setToolTip",
"(",
"sequence",
")",
"super",
"(",
"ShortcutLineEdit",
",",
"self",
")",
".",
"setText",
"(",
"sequence",
")"
] | Qt method extension. | [
"Qt",
"method",
"extension",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L115-L118 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutFinder.set_text | def set_text(self, text):
"""Set the filter text."""
text = text.strip()
new_text = self.text() + text
self.setText(new_text) | python | def set_text(self, text):
"""Set the filter text."""
text = text.strip()
new_text = self.text() + text
self.setText(new_text) | [
"def",
"set_text",
"(",
"self",
",",
"text",
")",
":",
"text",
"=",
"text",
".",
"strip",
"(",
")",
"new_text",
"=",
"self",
".",
"text",
"(",
")",
"+",
"text",
"self",
".",
"setText",
"(",
"new_text",
")"
] | Set the filter text. | [
"Set",
"the",
"filter",
"text",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L136-L140 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutFinder.keyPressEvent | def keyPressEvent(self, event):
"""Qt Override."""
key = event.key()
if key in [Qt.Key_Up]:
self._parent.previous_row()
elif key in [Qt.Key_Down]:
self._parent.next_row()
elif key in [Qt.Key_Enter, Qt.Key_Return]:
self._parent.show_editor()
else:
super(ShortcutFinder, self).keyPressEvent(event) | python | def keyPressEvent(self, event):
"""Qt Override."""
key = event.key()
if key in [Qt.Key_Up]:
self._parent.previous_row()
elif key in [Qt.Key_Down]:
self._parent.next_row()
elif key in [Qt.Key_Enter, Qt.Key_Return]:
self._parent.show_editor()
else:
super(ShortcutFinder, self).keyPressEvent(event) | [
"def",
"keyPressEvent",
"(",
"self",
",",
"event",
")",
":",
"key",
"=",
"event",
".",
"key",
"(",
")",
"if",
"key",
"in",
"[",
"Qt",
".",
"Key_Up",
"]",
":",
"self",
".",
"_parent",
".",
"previous_row",
"(",
")",
"elif",
"key",
"in",
"[",
"Qt",
".",
"Key_Down",
"]",
":",
"self",
".",
"_parent",
".",
"next_row",
"(",
")",
"elif",
"key",
"in",
"[",
"Qt",
".",
"Key_Enter",
",",
"Qt",
".",
"Key_Return",
"]",
":",
"self",
".",
"_parent",
".",
"show_editor",
"(",
")",
"else",
":",
"super",
"(",
"ShortcutFinder",
",",
"self",
")",
".",
"keyPressEvent",
"(",
"event",
")"
] | Qt Override. | [
"Qt",
"Override",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L142-L152 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutEditor.setup | def setup(self):
"""Setup the ShortcutEditor with the provided arguments."""
# Widgets
icon_info = HelperToolButton()
icon_info.setIcon(get_std_icon('MessageBoxInformation'))
layout_icon_info = QVBoxLayout()
layout_icon_info.setContentsMargins(0, 0, 0, 0)
layout_icon_info.setSpacing(0)
layout_icon_info.addWidget(icon_info)
layout_icon_info.addStretch(100)
self.label_info = QLabel()
self.label_info.setText(
_("Press the new shortcut and select 'Ok' to confirm, "
"click 'Cancel' to revert to the previous state, "
"or use 'Clear' to unbind the command from a shortcut."))
self.label_info.setAlignment(Qt.AlignTop | Qt.AlignLeft)
self.label_info.setWordWrap(True)
layout_info = QHBoxLayout()
layout_info.setContentsMargins(0, 0, 0, 0)
layout_info.addLayout(layout_icon_info)
layout_info.addWidget(self.label_info)
layout_info.setStretch(1, 100)
self.label_current_sequence = QLabel(_("Current shortcut:"))
self.text_current_sequence = QLabel(self.current_sequence)
self.label_new_sequence = QLabel(_("New shortcut:"))
self.text_new_sequence = ShortcutLineEdit(self)
self.text_new_sequence.setPlaceholderText(_("Press shortcut."))
self.helper_button = HelperToolButton()
self.helper_button.setIcon(QIcon())
self.label_warning = QLabel()
self.label_warning.setWordWrap(True)
self.label_warning.setAlignment(Qt.AlignTop | Qt.AlignLeft)
self.button_default = QPushButton(_('Default'))
self.button_ok = QPushButton(_('Ok'))
self.button_ok.setEnabled(False)
self.button_clear = QPushButton(_('Clear'))
self.button_cancel = QPushButton(_('Cancel'))
button_box = QHBoxLayout()
button_box.addWidget(self.button_default)
button_box.addStretch(100)
button_box.addWidget(self.button_ok)
button_box.addWidget(self.button_clear)
button_box.addWidget(self.button_cancel)
# New Sequence button box
self.btn_clear_sequence = create_toolbutton(
self, icon=ima.icon('editclear'),
tip=_("Clear all entered key sequences"),
triggered=self.clear_new_sequence)
self.button_back_sequence = create_toolbutton(
self, icon=ima.icon('ArrowBack'),
tip=_("Remove last key sequence entered"),
triggered=self.back_new_sequence)
newseq_btnbar = QHBoxLayout()
newseq_btnbar.setSpacing(0)
newseq_btnbar.setContentsMargins(0, 0, 0, 0)
newseq_btnbar.addWidget(self.button_back_sequence)
newseq_btnbar.addWidget(self.btn_clear_sequence)
# Setup widgets
self.setWindowTitle(_('Shortcut: {0}').format(self.name))
self.helper_button.setToolTip('')
style = """
QToolButton {
margin:1px;
border: 0px solid grey;
padding:0px;
border-radius: 0px;
}"""
self.helper_button.setStyleSheet(style)
icon_info.setToolTip('')
icon_info.setStyleSheet(style)
# Layout
layout_sequence = QGridLayout()
layout_sequence.setContentsMargins(0, 0, 0, 0)
layout_sequence.addLayout(layout_info, 0, 0, 1, 4)
layout_sequence.addItem(QSpacerItem(15, 15), 1, 0, 1, 4)
layout_sequence.addWidget(self.label_current_sequence, 2, 0)
layout_sequence.addWidget(self.text_current_sequence, 2, 2)
layout_sequence.addWidget(self.label_new_sequence, 3, 0)
layout_sequence.addWidget(self.helper_button, 3, 1)
layout_sequence.addWidget(self.text_new_sequence, 3, 2)
layout_sequence.addLayout(newseq_btnbar, 3, 3)
layout_sequence.addWidget(self.label_warning, 4, 2, 1, 2)
layout_sequence.setColumnStretch(2, 100)
layout_sequence.setRowStretch(4, 100)
layout = QVBoxLayout()
layout.addLayout(layout_sequence)
layout.addSpacing(5)
layout.addLayout(button_box)
self.setLayout(layout)
# Signals
self.button_ok.clicked.connect(self.accept_override)
self.button_clear.clicked.connect(self.unbind_shortcut)
self.button_cancel.clicked.connect(self.reject)
self.button_default.clicked.connect(self.set_sequence_to_default)
# Set all widget to no focus so that we can register <Tab> key
# press event.
widgets = (
self.label_warning, self.helper_button, self.text_new_sequence,
self.button_clear, self.button_default, self.button_cancel,
self.button_ok, self.btn_clear_sequence, self.button_back_sequence)
for w in widgets:
w.setFocusPolicy(Qt.NoFocus)
w.clearFocus() | python | def setup(self):
"""Setup the ShortcutEditor with the provided arguments."""
# Widgets
icon_info = HelperToolButton()
icon_info.setIcon(get_std_icon('MessageBoxInformation'))
layout_icon_info = QVBoxLayout()
layout_icon_info.setContentsMargins(0, 0, 0, 0)
layout_icon_info.setSpacing(0)
layout_icon_info.addWidget(icon_info)
layout_icon_info.addStretch(100)
self.label_info = QLabel()
self.label_info.setText(
_("Press the new shortcut and select 'Ok' to confirm, "
"click 'Cancel' to revert to the previous state, "
"or use 'Clear' to unbind the command from a shortcut."))
self.label_info.setAlignment(Qt.AlignTop | Qt.AlignLeft)
self.label_info.setWordWrap(True)
layout_info = QHBoxLayout()
layout_info.setContentsMargins(0, 0, 0, 0)
layout_info.addLayout(layout_icon_info)
layout_info.addWidget(self.label_info)
layout_info.setStretch(1, 100)
self.label_current_sequence = QLabel(_("Current shortcut:"))
self.text_current_sequence = QLabel(self.current_sequence)
self.label_new_sequence = QLabel(_("New shortcut:"))
self.text_new_sequence = ShortcutLineEdit(self)
self.text_new_sequence.setPlaceholderText(_("Press shortcut."))
self.helper_button = HelperToolButton()
self.helper_button.setIcon(QIcon())
self.label_warning = QLabel()
self.label_warning.setWordWrap(True)
self.label_warning.setAlignment(Qt.AlignTop | Qt.AlignLeft)
self.button_default = QPushButton(_('Default'))
self.button_ok = QPushButton(_('Ok'))
self.button_ok.setEnabled(False)
self.button_clear = QPushButton(_('Clear'))
self.button_cancel = QPushButton(_('Cancel'))
button_box = QHBoxLayout()
button_box.addWidget(self.button_default)
button_box.addStretch(100)
button_box.addWidget(self.button_ok)
button_box.addWidget(self.button_clear)
button_box.addWidget(self.button_cancel)
# New Sequence button box
self.btn_clear_sequence = create_toolbutton(
self, icon=ima.icon('editclear'),
tip=_("Clear all entered key sequences"),
triggered=self.clear_new_sequence)
self.button_back_sequence = create_toolbutton(
self, icon=ima.icon('ArrowBack'),
tip=_("Remove last key sequence entered"),
triggered=self.back_new_sequence)
newseq_btnbar = QHBoxLayout()
newseq_btnbar.setSpacing(0)
newseq_btnbar.setContentsMargins(0, 0, 0, 0)
newseq_btnbar.addWidget(self.button_back_sequence)
newseq_btnbar.addWidget(self.btn_clear_sequence)
# Setup widgets
self.setWindowTitle(_('Shortcut: {0}').format(self.name))
self.helper_button.setToolTip('')
style = """
QToolButton {
margin:1px;
border: 0px solid grey;
padding:0px;
border-radius: 0px;
}"""
self.helper_button.setStyleSheet(style)
icon_info.setToolTip('')
icon_info.setStyleSheet(style)
# Layout
layout_sequence = QGridLayout()
layout_sequence.setContentsMargins(0, 0, 0, 0)
layout_sequence.addLayout(layout_info, 0, 0, 1, 4)
layout_sequence.addItem(QSpacerItem(15, 15), 1, 0, 1, 4)
layout_sequence.addWidget(self.label_current_sequence, 2, 0)
layout_sequence.addWidget(self.text_current_sequence, 2, 2)
layout_sequence.addWidget(self.label_new_sequence, 3, 0)
layout_sequence.addWidget(self.helper_button, 3, 1)
layout_sequence.addWidget(self.text_new_sequence, 3, 2)
layout_sequence.addLayout(newseq_btnbar, 3, 3)
layout_sequence.addWidget(self.label_warning, 4, 2, 1, 2)
layout_sequence.setColumnStretch(2, 100)
layout_sequence.setRowStretch(4, 100)
layout = QVBoxLayout()
layout.addLayout(layout_sequence)
layout.addSpacing(5)
layout.addLayout(button_box)
self.setLayout(layout)
# Signals
self.button_ok.clicked.connect(self.accept_override)
self.button_clear.clicked.connect(self.unbind_shortcut)
self.button_cancel.clicked.connect(self.reject)
self.button_default.clicked.connect(self.set_sequence_to_default)
# Set all widget to no focus so that we can register <Tab> key
# press event.
widgets = (
self.label_warning, self.helper_button, self.text_new_sequence,
self.button_clear, self.button_default, self.button_cancel,
self.button_ok, self.btn_clear_sequence, self.button_back_sequence)
for w in widgets:
w.setFocusPolicy(Qt.NoFocus)
w.clearFocus() | [
"def",
"setup",
"(",
"self",
")",
":",
"# Widgets\r",
"icon_info",
"=",
"HelperToolButton",
"(",
")",
"icon_info",
".",
"setIcon",
"(",
"get_std_icon",
"(",
"'MessageBoxInformation'",
")",
")",
"layout_icon_info",
"=",
"QVBoxLayout",
"(",
")",
"layout_icon_info",
".",
"setContentsMargins",
"(",
"0",
",",
"0",
",",
"0",
",",
"0",
")",
"layout_icon_info",
".",
"setSpacing",
"(",
"0",
")",
"layout_icon_info",
".",
"addWidget",
"(",
"icon_info",
")",
"layout_icon_info",
".",
"addStretch",
"(",
"100",
")",
"self",
".",
"label_info",
"=",
"QLabel",
"(",
")",
"self",
".",
"label_info",
".",
"setText",
"(",
"_",
"(",
"\"Press the new shortcut and select 'Ok' to confirm, \"",
"\"click 'Cancel' to revert to the previous state, \"",
"\"or use 'Clear' to unbind the command from a shortcut.\"",
")",
")",
"self",
".",
"label_info",
".",
"setAlignment",
"(",
"Qt",
".",
"AlignTop",
"|",
"Qt",
".",
"AlignLeft",
")",
"self",
".",
"label_info",
".",
"setWordWrap",
"(",
"True",
")",
"layout_info",
"=",
"QHBoxLayout",
"(",
")",
"layout_info",
".",
"setContentsMargins",
"(",
"0",
",",
"0",
",",
"0",
",",
"0",
")",
"layout_info",
".",
"addLayout",
"(",
"layout_icon_info",
")",
"layout_info",
".",
"addWidget",
"(",
"self",
".",
"label_info",
")",
"layout_info",
".",
"setStretch",
"(",
"1",
",",
"100",
")",
"self",
".",
"label_current_sequence",
"=",
"QLabel",
"(",
"_",
"(",
"\"Current shortcut:\"",
")",
")",
"self",
".",
"text_current_sequence",
"=",
"QLabel",
"(",
"self",
".",
"current_sequence",
")",
"self",
".",
"label_new_sequence",
"=",
"QLabel",
"(",
"_",
"(",
"\"New shortcut:\"",
")",
")",
"self",
".",
"text_new_sequence",
"=",
"ShortcutLineEdit",
"(",
"self",
")",
"self",
".",
"text_new_sequence",
".",
"setPlaceholderText",
"(",
"_",
"(",
"\"Press shortcut.\"",
")",
")",
"self",
".",
"helper_button",
"=",
"HelperToolButton",
"(",
")",
"self",
".",
"helper_button",
".",
"setIcon",
"(",
"QIcon",
"(",
")",
")",
"self",
".",
"label_warning",
"=",
"QLabel",
"(",
")",
"self",
".",
"label_warning",
".",
"setWordWrap",
"(",
"True",
")",
"self",
".",
"label_warning",
".",
"setAlignment",
"(",
"Qt",
".",
"AlignTop",
"|",
"Qt",
".",
"AlignLeft",
")",
"self",
".",
"button_default",
"=",
"QPushButton",
"(",
"_",
"(",
"'Default'",
")",
")",
"self",
".",
"button_ok",
"=",
"QPushButton",
"(",
"_",
"(",
"'Ok'",
")",
")",
"self",
".",
"button_ok",
".",
"setEnabled",
"(",
"False",
")",
"self",
".",
"button_clear",
"=",
"QPushButton",
"(",
"_",
"(",
"'Clear'",
")",
")",
"self",
".",
"button_cancel",
"=",
"QPushButton",
"(",
"_",
"(",
"'Cancel'",
")",
")",
"button_box",
"=",
"QHBoxLayout",
"(",
")",
"button_box",
".",
"addWidget",
"(",
"self",
".",
"button_default",
")",
"button_box",
".",
"addStretch",
"(",
"100",
")",
"button_box",
".",
"addWidget",
"(",
"self",
".",
"button_ok",
")",
"button_box",
".",
"addWidget",
"(",
"self",
".",
"button_clear",
")",
"button_box",
".",
"addWidget",
"(",
"self",
".",
"button_cancel",
")",
"# New Sequence button box\r",
"self",
".",
"btn_clear_sequence",
"=",
"create_toolbutton",
"(",
"self",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'editclear'",
")",
",",
"tip",
"=",
"_",
"(",
"\"Clear all entered key sequences\"",
")",
",",
"triggered",
"=",
"self",
".",
"clear_new_sequence",
")",
"self",
".",
"button_back_sequence",
"=",
"create_toolbutton",
"(",
"self",
",",
"icon",
"=",
"ima",
".",
"icon",
"(",
"'ArrowBack'",
")",
",",
"tip",
"=",
"_",
"(",
"\"Remove last key sequence entered\"",
")",
",",
"triggered",
"=",
"self",
".",
"back_new_sequence",
")",
"newseq_btnbar",
"=",
"QHBoxLayout",
"(",
")",
"newseq_btnbar",
".",
"setSpacing",
"(",
"0",
")",
"newseq_btnbar",
".",
"setContentsMargins",
"(",
"0",
",",
"0",
",",
"0",
",",
"0",
")",
"newseq_btnbar",
".",
"addWidget",
"(",
"self",
".",
"button_back_sequence",
")",
"newseq_btnbar",
".",
"addWidget",
"(",
"self",
".",
"btn_clear_sequence",
")",
"# Setup widgets\r",
"self",
".",
"setWindowTitle",
"(",
"_",
"(",
"'Shortcut: {0}'",
")",
".",
"format",
"(",
"self",
".",
"name",
")",
")",
"self",
".",
"helper_button",
".",
"setToolTip",
"(",
"''",
")",
"style",
"=",
"\"\"\"\r\n QToolButton {\r\n margin:1px;\r\n border: 0px solid grey;\r\n padding:0px;\r\n border-radius: 0px;\r\n }\"\"\"",
"self",
".",
"helper_button",
".",
"setStyleSheet",
"(",
"style",
")",
"icon_info",
".",
"setToolTip",
"(",
"''",
")",
"icon_info",
".",
"setStyleSheet",
"(",
"style",
")",
"# Layout\r",
"layout_sequence",
"=",
"QGridLayout",
"(",
")",
"layout_sequence",
".",
"setContentsMargins",
"(",
"0",
",",
"0",
",",
"0",
",",
"0",
")",
"layout_sequence",
".",
"addLayout",
"(",
"layout_info",
",",
"0",
",",
"0",
",",
"1",
",",
"4",
")",
"layout_sequence",
".",
"addItem",
"(",
"QSpacerItem",
"(",
"15",
",",
"15",
")",
",",
"1",
",",
"0",
",",
"1",
",",
"4",
")",
"layout_sequence",
".",
"addWidget",
"(",
"self",
".",
"label_current_sequence",
",",
"2",
",",
"0",
")",
"layout_sequence",
".",
"addWidget",
"(",
"self",
".",
"text_current_sequence",
",",
"2",
",",
"2",
")",
"layout_sequence",
".",
"addWidget",
"(",
"self",
".",
"label_new_sequence",
",",
"3",
",",
"0",
")",
"layout_sequence",
".",
"addWidget",
"(",
"self",
".",
"helper_button",
",",
"3",
",",
"1",
")",
"layout_sequence",
".",
"addWidget",
"(",
"self",
".",
"text_new_sequence",
",",
"3",
",",
"2",
")",
"layout_sequence",
".",
"addLayout",
"(",
"newseq_btnbar",
",",
"3",
",",
"3",
")",
"layout_sequence",
".",
"addWidget",
"(",
"self",
".",
"label_warning",
",",
"4",
",",
"2",
",",
"1",
",",
"2",
")",
"layout_sequence",
".",
"setColumnStretch",
"(",
"2",
",",
"100",
")",
"layout_sequence",
".",
"setRowStretch",
"(",
"4",
",",
"100",
")",
"layout",
"=",
"QVBoxLayout",
"(",
")",
"layout",
".",
"addLayout",
"(",
"layout_sequence",
")",
"layout",
".",
"addSpacing",
"(",
"5",
")",
"layout",
".",
"addLayout",
"(",
"button_box",
")",
"self",
".",
"setLayout",
"(",
"layout",
")",
"# Signals\r",
"self",
".",
"button_ok",
".",
"clicked",
".",
"connect",
"(",
"self",
".",
"accept_override",
")",
"self",
".",
"button_clear",
".",
"clicked",
".",
"connect",
"(",
"self",
".",
"unbind_shortcut",
")",
"self",
".",
"button_cancel",
".",
"clicked",
".",
"connect",
"(",
"self",
".",
"reject",
")",
"self",
".",
"button_default",
".",
"clicked",
".",
"connect",
"(",
"self",
".",
"set_sequence_to_default",
")",
"# Set all widget to no focus so that we can register <Tab> key\r",
"# press event.\r",
"widgets",
"=",
"(",
"self",
".",
"label_warning",
",",
"self",
".",
"helper_button",
",",
"self",
".",
"text_new_sequence",
",",
"self",
".",
"button_clear",
",",
"self",
".",
"button_default",
",",
"self",
".",
"button_cancel",
",",
"self",
".",
"button_ok",
",",
"self",
".",
"btn_clear_sequence",
",",
"self",
".",
"button_back_sequence",
")",
"for",
"w",
"in",
"widgets",
":",
"w",
".",
"setFocusPolicy",
"(",
"Qt",
".",
"NoFocus",
")",
"w",
".",
"clearFocus",
"(",
")"
] | Setup the ShortcutEditor with the provided arguments. | [
"Setup",
"the",
"ShortcutEditor",
"with",
"the",
"provided",
"arguments",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L181-L295 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutEditor.event | def event(self, event):
"""Qt method override."""
if event.type() in (QEvent.Shortcut, QEvent.ShortcutOverride):
return True
else:
return super(ShortcutEditor, self).event(event) | python | def event(self, event):
"""Qt method override."""
if event.type() in (QEvent.Shortcut, QEvent.ShortcutOverride):
return True
else:
return super(ShortcutEditor, self).event(event) | [
"def",
"event",
"(",
"self",
",",
"event",
")",
":",
"if",
"event",
".",
"type",
"(",
")",
"in",
"(",
"QEvent",
".",
"Shortcut",
",",
"QEvent",
".",
"ShortcutOverride",
")",
":",
"return",
"True",
"else",
":",
"return",
"super",
"(",
"ShortcutEditor",
",",
"self",
")",
".",
"event",
"(",
"event",
")"
] | Qt method override. | [
"Qt",
"method",
"override",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L315-L320 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutEditor.keyPressEvent | def keyPressEvent(self, event):
"""Qt method override."""
event_key = event.key()
if not event_key or event_key == Qt.Key_unknown:
return
if len(self._qsequences) == 4:
# QKeySequence accepts a maximum of 4 different sequences.
return
if event_key in [Qt.Key_Control, Qt.Key_Shift,
Qt.Key_Alt, Qt.Key_Meta]:
# The event corresponds to just and only a special key.
return
translator = ShortcutTranslator()
event_keyseq = translator.keyevent_to_keyseq(event)
event_keystr = event_keyseq.toString(QKeySequence.PortableText)
self._qsequences.append(event_keystr)
self.update_warning() | python | def keyPressEvent(self, event):
"""Qt method override."""
event_key = event.key()
if not event_key or event_key == Qt.Key_unknown:
return
if len(self._qsequences) == 4:
# QKeySequence accepts a maximum of 4 different sequences.
return
if event_key in [Qt.Key_Control, Qt.Key_Shift,
Qt.Key_Alt, Qt.Key_Meta]:
# The event corresponds to just and only a special key.
return
translator = ShortcutTranslator()
event_keyseq = translator.keyevent_to_keyseq(event)
event_keystr = event_keyseq.toString(QKeySequence.PortableText)
self._qsequences.append(event_keystr)
self.update_warning() | [
"def",
"keyPressEvent",
"(",
"self",
",",
"event",
")",
":",
"event_key",
"=",
"event",
".",
"key",
"(",
")",
"if",
"not",
"event_key",
"or",
"event_key",
"==",
"Qt",
".",
"Key_unknown",
":",
"return",
"if",
"len",
"(",
"self",
".",
"_qsequences",
")",
"==",
"4",
":",
"# QKeySequence accepts a maximum of 4 different sequences.\r",
"return",
"if",
"event_key",
"in",
"[",
"Qt",
".",
"Key_Control",
",",
"Qt",
".",
"Key_Shift",
",",
"Qt",
".",
"Key_Alt",
",",
"Qt",
".",
"Key_Meta",
"]",
":",
"# The event corresponds to just and only a special key.\r",
"return",
"translator",
"=",
"ShortcutTranslator",
"(",
")",
"event_keyseq",
"=",
"translator",
".",
"keyevent_to_keyseq",
"(",
"event",
")",
"event_keystr",
"=",
"event_keyseq",
".",
"toString",
"(",
"QKeySequence",
".",
"PortableText",
")",
"self",
".",
"_qsequences",
".",
"append",
"(",
"event_keystr",
")",
"self",
".",
"update_warning",
"(",
")"
] | Qt method override. | [
"Qt",
"method",
"override",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L322-L339 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutEditor.check_conflicts | def check_conflicts(self):
"""Check shortcuts for conflicts."""
conflicts = []
if len(self._qsequences) == 0:
return conflicts
new_qsequence = self.new_qsequence
for shortcut in self.shortcuts:
shortcut_qsequence = QKeySequence.fromString(str(shortcut.key))
if shortcut_qsequence.isEmpty():
continue
if (shortcut.context, shortcut.name) == (self.context, self.name):
continue
if shortcut.context in [self.context, '_'] or self.context == '_':
if (shortcut_qsequence.matches(new_qsequence) or
new_qsequence.matches(shortcut_qsequence)):
conflicts.append(shortcut)
return conflicts | python | def check_conflicts(self):
"""Check shortcuts for conflicts."""
conflicts = []
if len(self._qsequences) == 0:
return conflicts
new_qsequence = self.new_qsequence
for shortcut in self.shortcuts:
shortcut_qsequence = QKeySequence.fromString(str(shortcut.key))
if shortcut_qsequence.isEmpty():
continue
if (shortcut.context, shortcut.name) == (self.context, self.name):
continue
if shortcut.context in [self.context, '_'] or self.context == '_':
if (shortcut_qsequence.matches(new_qsequence) or
new_qsequence.matches(shortcut_qsequence)):
conflicts.append(shortcut)
return conflicts | [
"def",
"check_conflicts",
"(",
"self",
")",
":",
"conflicts",
"=",
"[",
"]",
"if",
"len",
"(",
"self",
".",
"_qsequences",
")",
"==",
"0",
":",
"return",
"conflicts",
"new_qsequence",
"=",
"self",
".",
"new_qsequence",
"for",
"shortcut",
"in",
"self",
".",
"shortcuts",
":",
"shortcut_qsequence",
"=",
"QKeySequence",
".",
"fromString",
"(",
"str",
"(",
"shortcut",
".",
"key",
")",
")",
"if",
"shortcut_qsequence",
".",
"isEmpty",
"(",
")",
":",
"continue",
"if",
"(",
"shortcut",
".",
"context",
",",
"shortcut",
".",
"name",
")",
"==",
"(",
"self",
".",
"context",
",",
"self",
".",
"name",
")",
":",
"continue",
"if",
"shortcut",
".",
"context",
"in",
"[",
"self",
".",
"context",
",",
"'_'",
"]",
"or",
"self",
".",
"context",
"==",
"'_'",
":",
"if",
"(",
"shortcut_qsequence",
".",
"matches",
"(",
"new_qsequence",
")",
"or",
"new_qsequence",
".",
"matches",
"(",
"shortcut_qsequence",
")",
")",
":",
"conflicts",
".",
"append",
"(",
"shortcut",
")",
"return",
"conflicts"
] | Check shortcuts for conflicts. | [
"Check",
"shortcuts",
"for",
"conflicts",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L341-L358 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutEditor.check_singlekey | def check_singlekey(self):
"""Check if the first sub-sequence of the new key sequence is valid."""
if len(self._qsequences) == 0:
return True
else:
keystr = self._qsequences[0]
valid_single_keys = (EDITOR_SINGLE_KEYS if
self.context == 'editor' else SINGLE_KEYS)
if any((m in keystr for m in ('Ctrl', 'Alt', 'Shift', 'Meta'))):
return True
else:
# This means that the the first subsequence is composed of
# a single key with no modifier.
valid_single_keys = (EDITOR_SINGLE_KEYS if
self.context == 'editor' else SINGLE_KEYS)
if any((k == keystr for k in valid_single_keys)):
return True
else:
return False | python | def check_singlekey(self):
"""Check if the first sub-sequence of the new key sequence is valid."""
if len(self._qsequences) == 0:
return True
else:
keystr = self._qsequences[0]
valid_single_keys = (EDITOR_SINGLE_KEYS if
self.context == 'editor' else SINGLE_KEYS)
if any((m in keystr for m in ('Ctrl', 'Alt', 'Shift', 'Meta'))):
return True
else:
# This means that the the first subsequence is composed of
# a single key with no modifier.
valid_single_keys = (EDITOR_SINGLE_KEYS if
self.context == 'editor' else SINGLE_KEYS)
if any((k == keystr for k in valid_single_keys)):
return True
else:
return False | [
"def",
"check_singlekey",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"_qsequences",
")",
"==",
"0",
":",
"return",
"True",
"else",
":",
"keystr",
"=",
"self",
".",
"_qsequences",
"[",
"0",
"]",
"valid_single_keys",
"=",
"(",
"EDITOR_SINGLE_KEYS",
"if",
"self",
".",
"context",
"==",
"'editor'",
"else",
"SINGLE_KEYS",
")",
"if",
"any",
"(",
"(",
"m",
"in",
"keystr",
"for",
"m",
"in",
"(",
"'Ctrl'",
",",
"'Alt'",
",",
"'Shift'",
",",
"'Meta'",
")",
")",
")",
":",
"return",
"True",
"else",
":",
"# This means that the the first subsequence is composed of\r",
"# a single key with no modifier.\r",
"valid_single_keys",
"=",
"(",
"EDITOR_SINGLE_KEYS",
"if",
"self",
".",
"context",
"==",
"'editor'",
"else",
"SINGLE_KEYS",
")",
"if",
"any",
"(",
"(",
"k",
"==",
"keystr",
"for",
"k",
"in",
"valid_single_keys",
")",
")",
":",
"return",
"True",
"else",
":",
"return",
"False"
] | Check if the first sub-sequence of the new key sequence is valid. | [
"Check",
"if",
"the",
"first",
"sub",
"-",
"sequence",
"of",
"the",
"new",
"key",
"sequence",
"is",
"valid",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L372-L390 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutEditor.update_warning | def update_warning(self):
"""Update the warning label, buttons state and sequence text."""
new_qsequence = self.new_qsequence
new_sequence = self.new_sequence
self.text_new_sequence.setText(
new_qsequence.toString(QKeySequence.NativeText))
conflicts = self.check_conflicts()
if len(self._qsequences) == 0:
warning = SEQUENCE_EMPTY
tip = ''
icon = QIcon()
elif conflicts:
warning = SEQUENCE_CONFLICT
template = '<i>{0}<b>{1}</b>{2}</i>'
tip_title = _('The new shortcut conflicts with:') + '<br>'
tip_body = ''
for s in conflicts:
tip_body += ' - {0}: {1}<br>'.format(s.context, s.name)
tip_body = tip_body[:-4] # Removing last <br>
tip_override = '<br>Press <b>OK</b> to unbind '
tip_override += 'it' if len(conflicts) == 1 else 'them'
tip_override += ' and assign it to <b>{}</b>'.format(self.name)
tip = template.format(tip_title, tip_body, tip_override)
icon = get_std_icon('MessageBoxWarning')
elif new_sequence in BLACKLIST:
warning = IN_BLACKLIST
template = '<i>{0}<b>{1}</b></i>'
tip_title = _('Forbidden key sequence!') + '<br>'
tip_body = ''
use = BLACKLIST[new_sequence]
if use is not None:
tip_body = use
tip = template.format(tip_title, tip_body)
icon = get_std_icon('MessageBoxWarning')
elif self.check_singlekey() is False or self.check_ascii() is False:
warning = INVALID_KEY
template = '<i>{0}</i>'
tip = _('Invalid key sequence entered') + '<br>'
icon = get_std_icon('MessageBoxWarning')
else:
warning = NO_WARNING
tip = 'This shortcut is valid.'
icon = get_std_icon('DialogApplyButton')
self.warning = warning
self.conflicts = conflicts
self.helper_button.setIcon(icon)
self.button_ok.setEnabled(
self.warning in [NO_WARNING, SEQUENCE_CONFLICT])
self.label_warning.setText(tip)
# Everytime after update warning message, update the label height
new_height = self.label_warning.sizeHint().height()
self.label_warning.setMaximumHeight(new_height) | python | def update_warning(self):
"""Update the warning label, buttons state and sequence text."""
new_qsequence = self.new_qsequence
new_sequence = self.new_sequence
self.text_new_sequence.setText(
new_qsequence.toString(QKeySequence.NativeText))
conflicts = self.check_conflicts()
if len(self._qsequences) == 0:
warning = SEQUENCE_EMPTY
tip = ''
icon = QIcon()
elif conflicts:
warning = SEQUENCE_CONFLICT
template = '<i>{0}<b>{1}</b>{2}</i>'
tip_title = _('The new shortcut conflicts with:') + '<br>'
tip_body = ''
for s in conflicts:
tip_body += ' - {0}: {1}<br>'.format(s.context, s.name)
tip_body = tip_body[:-4] # Removing last <br>
tip_override = '<br>Press <b>OK</b> to unbind '
tip_override += 'it' if len(conflicts) == 1 else 'them'
tip_override += ' and assign it to <b>{}</b>'.format(self.name)
tip = template.format(tip_title, tip_body, tip_override)
icon = get_std_icon('MessageBoxWarning')
elif new_sequence in BLACKLIST:
warning = IN_BLACKLIST
template = '<i>{0}<b>{1}</b></i>'
tip_title = _('Forbidden key sequence!') + '<br>'
tip_body = ''
use = BLACKLIST[new_sequence]
if use is not None:
tip_body = use
tip = template.format(tip_title, tip_body)
icon = get_std_icon('MessageBoxWarning')
elif self.check_singlekey() is False or self.check_ascii() is False:
warning = INVALID_KEY
template = '<i>{0}</i>'
tip = _('Invalid key sequence entered') + '<br>'
icon = get_std_icon('MessageBoxWarning')
else:
warning = NO_WARNING
tip = 'This shortcut is valid.'
icon = get_std_icon('DialogApplyButton')
self.warning = warning
self.conflicts = conflicts
self.helper_button.setIcon(icon)
self.button_ok.setEnabled(
self.warning in [NO_WARNING, SEQUENCE_CONFLICT])
self.label_warning.setText(tip)
# Everytime after update warning message, update the label height
new_height = self.label_warning.sizeHint().height()
self.label_warning.setMaximumHeight(new_height) | [
"def",
"update_warning",
"(",
"self",
")",
":",
"new_qsequence",
"=",
"self",
".",
"new_qsequence",
"new_sequence",
"=",
"self",
".",
"new_sequence",
"self",
".",
"text_new_sequence",
".",
"setText",
"(",
"new_qsequence",
".",
"toString",
"(",
"QKeySequence",
".",
"NativeText",
")",
")",
"conflicts",
"=",
"self",
".",
"check_conflicts",
"(",
")",
"if",
"len",
"(",
"self",
".",
"_qsequences",
")",
"==",
"0",
":",
"warning",
"=",
"SEQUENCE_EMPTY",
"tip",
"=",
"''",
"icon",
"=",
"QIcon",
"(",
")",
"elif",
"conflicts",
":",
"warning",
"=",
"SEQUENCE_CONFLICT",
"template",
"=",
"'<i>{0}<b>{1}</b>{2}</i>'",
"tip_title",
"=",
"_",
"(",
"'The new shortcut conflicts with:'",
")",
"+",
"'<br>'",
"tip_body",
"=",
"''",
"for",
"s",
"in",
"conflicts",
":",
"tip_body",
"+=",
"' - {0}: {1}<br>'",
".",
"format",
"(",
"s",
".",
"context",
",",
"s",
".",
"name",
")",
"tip_body",
"=",
"tip_body",
"[",
":",
"-",
"4",
"]",
"# Removing last <br>\r",
"tip_override",
"=",
"'<br>Press <b>OK</b> to unbind '",
"tip_override",
"+=",
"'it'",
"if",
"len",
"(",
"conflicts",
")",
"==",
"1",
"else",
"'them'",
"tip_override",
"+=",
"' and assign it to <b>{}</b>'",
".",
"format",
"(",
"self",
".",
"name",
")",
"tip",
"=",
"template",
".",
"format",
"(",
"tip_title",
",",
"tip_body",
",",
"tip_override",
")",
"icon",
"=",
"get_std_icon",
"(",
"'MessageBoxWarning'",
")",
"elif",
"new_sequence",
"in",
"BLACKLIST",
":",
"warning",
"=",
"IN_BLACKLIST",
"template",
"=",
"'<i>{0}<b>{1}</b></i>'",
"tip_title",
"=",
"_",
"(",
"'Forbidden key sequence!'",
")",
"+",
"'<br>'",
"tip_body",
"=",
"''",
"use",
"=",
"BLACKLIST",
"[",
"new_sequence",
"]",
"if",
"use",
"is",
"not",
"None",
":",
"tip_body",
"=",
"use",
"tip",
"=",
"template",
".",
"format",
"(",
"tip_title",
",",
"tip_body",
")",
"icon",
"=",
"get_std_icon",
"(",
"'MessageBoxWarning'",
")",
"elif",
"self",
".",
"check_singlekey",
"(",
")",
"is",
"False",
"or",
"self",
".",
"check_ascii",
"(",
")",
"is",
"False",
":",
"warning",
"=",
"INVALID_KEY",
"template",
"=",
"'<i>{0}</i>'",
"tip",
"=",
"_",
"(",
"'Invalid key sequence entered'",
")",
"+",
"'<br>'",
"icon",
"=",
"get_std_icon",
"(",
"'MessageBoxWarning'",
")",
"else",
":",
"warning",
"=",
"NO_WARNING",
"tip",
"=",
"'This shortcut is valid.'",
"icon",
"=",
"get_std_icon",
"(",
"'DialogApplyButton'",
")",
"self",
".",
"warning",
"=",
"warning",
"self",
".",
"conflicts",
"=",
"conflicts",
"self",
".",
"helper_button",
".",
"setIcon",
"(",
"icon",
")",
"self",
".",
"button_ok",
".",
"setEnabled",
"(",
"self",
".",
"warning",
"in",
"[",
"NO_WARNING",
",",
"SEQUENCE_CONFLICT",
"]",
")",
"self",
".",
"label_warning",
".",
"setText",
"(",
"tip",
")",
"# Everytime after update warning message, update the label height\r",
"new_height",
"=",
"self",
".",
"label_warning",
".",
"sizeHint",
"(",
")",
".",
"height",
"(",
")",
"self",
".",
"label_warning",
".",
"setMaximumHeight",
"(",
"new_height",
")"
] | Update the warning label, buttons state and sequence text. | [
"Update",
"the",
"warning",
"label",
"buttons",
"state",
"and",
"sequence",
"text",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L392-L446 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutEditor.set_sequence_from_str | def set_sequence_from_str(self, sequence):
"""
This is a convenience method to set the new QKeySequence of the
shortcut editor from a string.
"""
self._qsequences = [QKeySequence(s) for s in sequence.split(', ')]
self.update_warning() | python | def set_sequence_from_str(self, sequence):
"""
This is a convenience method to set the new QKeySequence of the
shortcut editor from a string.
"""
self._qsequences = [QKeySequence(s) for s in sequence.split(', ')]
self.update_warning() | [
"def",
"set_sequence_from_str",
"(",
"self",
",",
"sequence",
")",
":",
"self",
".",
"_qsequences",
"=",
"[",
"QKeySequence",
"(",
"s",
")",
"for",
"s",
"in",
"sequence",
".",
"split",
"(",
"', '",
")",
"]",
"self",
".",
"update_warning",
"(",
")"
] | This is a convenience method to set the new QKeySequence of the
shortcut editor from a string. | [
"This",
"is",
"a",
"convenience",
"method",
"to",
"set",
"the",
"new",
"QKeySequence",
"of",
"the",
"shortcut",
"editor",
"from",
"a",
"string",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L448-L454 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutEditor.set_sequence_to_default | def set_sequence_to_default(self):
"""Set the new sequence to the default value defined in the config."""
sequence = CONF.get_default(
'shortcuts', "{}/{}".format(self.context, self.name))
self._qsequences = sequence.split(', ')
self.update_warning() | python | def set_sequence_to_default(self):
"""Set the new sequence to the default value defined in the config."""
sequence = CONF.get_default(
'shortcuts', "{}/{}".format(self.context, self.name))
self._qsequences = sequence.split(', ')
self.update_warning() | [
"def",
"set_sequence_to_default",
"(",
"self",
")",
":",
"sequence",
"=",
"CONF",
".",
"get_default",
"(",
"'shortcuts'",
",",
"\"{}/{}\"",
".",
"format",
"(",
"self",
".",
"context",
",",
"self",
".",
"name",
")",
")",
"self",
".",
"_qsequences",
"=",
"sequence",
".",
"split",
"(",
"', '",
")",
"self",
".",
"update_warning",
"(",
")"
] | Set the new sequence to the default value defined in the config. | [
"Set",
"the",
"new",
"sequence",
"to",
"the",
"default",
"value",
"defined",
"in",
"the",
"config",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L456-L461 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutEditor.accept_override | def accept_override(self):
"""Unbind all conflicted shortcuts, and accept the new one"""
conflicts = self.check_conflicts()
if conflicts:
for shortcut in conflicts:
shortcut.key = ''
self.accept() | python | def accept_override(self):
"""Unbind all conflicted shortcuts, and accept the new one"""
conflicts = self.check_conflicts()
if conflicts:
for shortcut in conflicts:
shortcut.key = ''
self.accept() | [
"def",
"accept_override",
"(",
"self",
")",
":",
"conflicts",
"=",
"self",
".",
"check_conflicts",
"(",
")",
"if",
"conflicts",
":",
"for",
"shortcut",
"in",
"conflicts",
":",
"shortcut",
".",
"key",
"=",
"''",
"self",
".",
"accept",
"(",
")"
] | Unbind all conflicted shortcuts, and accept the new one | [
"Unbind",
"all",
"conflicted",
"shortcuts",
"and",
"accept",
"the",
"new",
"one"
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L478-L484 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutsModel.current_index | def current_index(self):
"""Get the currently selected index in the parent table view."""
i = self._parent.proxy_model.mapToSource(self._parent.currentIndex())
return i | python | def current_index(self):
"""Get the currently selected index in the parent table view."""
i = self._parent.proxy_model.mapToSource(self._parent.currentIndex())
return i | [
"def",
"current_index",
"(",
"self",
")",
":",
"i",
"=",
"self",
".",
"_parent",
".",
"proxy_model",
".",
"mapToSource",
"(",
"self",
".",
"_parent",
".",
"currentIndex",
"(",
")",
")",
"return",
"i"
] | Get the currently selected index in the parent table view. | [
"Get",
"the",
"currently",
"selected",
"index",
"in",
"the",
"parent",
"table",
"view",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L537-L540 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutsModel.sortByName | def sortByName(self):
"""Qt Override."""
self.shortcuts = sorted(self.shortcuts,
key=lambda x: x.context+'/'+x.name)
self.reset() | python | def sortByName(self):
"""Qt Override."""
self.shortcuts = sorted(self.shortcuts,
key=lambda x: x.context+'/'+x.name)
self.reset() | [
"def",
"sortByName",
"(",
"self",
")",
":",
"self",
".",
"shortcuts",
"=",
"sorted",
"(",
"self",
".",
"shortcuts",
",",
"key",
"=",
"lambda",
"x",
":",
"x",
".",
"context",
"+",
"'/'",
"+",
"x",
".",
"name",
")",
"self",
".",
"reset",
"(",
")"
] | Qt Override. | [
"Qt",
"Override",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L542-L546 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutsModel.data | def data(self, index, role=Qt.DisplayRole):
"""Qt Override."""
row = index.row()
if not index.isValid() or not (0 <= row < len(self.shortcuts)):
return to_qvariant()
shortcut = self.shortcuts[row]
key = shortcut.key
column = index.column()
if role == Qt.DisplayRole:
if column == CONTEXT:
return to_qvariant(shortcut.context)
elif column == NAME:
color = self.text_color
if self._parent == QApplication.focusWidget():
if self.current_index().row() == row:
color = self.text_color_highlight
else:
color = self.text_color
text = self.rich_text[row]
text = '<p style="color:{0}">{1}</p>'.format(color, text)
return to_qvariant(text)
elif column == SEQUENCE:
text = QKeySequence(key).toString(QKeySequence.NativeText)
return to_qvariant(text)
elif column == SEARCH_SCORE:
# Treating search scores as a table column simplifies the
# sorting once a score for a specific string in the finder
# has been defined. This column however should always remain
# hidden.
return to_qvariant(self.scores[row])
elif role == Qt.TextAlignmentRole:
return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter))
return to_qvariant() | python | def data(self, index, role=Qt.DisplayRole):
"""Qt Override."""
row = index.row()
if not index.isValid() or not (0 <= row < len(self.shortcuts)):
return to_qvariant()
shortcut = self.shortcuts[row]
key = shortcut.key
column = index.column()
if role == Qt.DisplayRole:
if column == CONTEXT:
return to_qvariant(shortcut.context)
elif column == NAME:
color = self.text_color
if self._parent == QApplication.focusWidget():
if self.current_index().row() == row:
color = self.text_color_highlight
else:
color = self.text_color
text = self.rich_text[row]
text = '<p style="color:{0}">{1}</p>'.format(color, text)
return to_qvariant(text)
elif column == SEQUENCE:
text = QKeySequence(key).toString(QKeySequence.NativeText)
return to_qvariant(text)
elif column == SEARCH_SCORE:
# Treating search scores as a table column simplifies the
# sorting once a score for a specific string in the finder
# has been defined. This column however should always remain
# hidden.
return to_qvariant(self.scores[row])
elif role == Qt.TextAlignmentRole:
return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter))
return to_qvariant() | [
"def",
"data",
"(",
"self",
",",
"index",
",",
"role",
"=",
"Qt",
".",
"DisplayRole",
")",
":",
"row",
"=",
"index",
".",
"row",
"(",
")",
"if",
"not",
"index",
".",
"isValid",
"(",
")",
"or",
"not",
"(",
"0",
"<=",
"row",
"<",
"len",
"(",
"self",
".",
"shortcuts",
")",
")",
":",
"return",
"to_qvariant",
"(",
")",
"shortcut",
"=",
"self",
".",
"shortcuts",
"[",
"row",
"]",
"key",
"=",
"shortcut",
".",
"key",
"column",
"=",
"index",
".",
"column",
"(",
")",
"if",
"role",
"==",
"Qt",
".",
"DisplayRole",
":",
"if",
"column",
"==",
"CONTEXT",
":",
"return",
"to_qvariant",
"(",
"shortcut",
".",
"context",
")",
"elif",
"column",
"==",
"NAME",
":",
"color",
"=",
"self",
".",
"text_color",
"if",
"self",
".",
"_parent",
"==",
"QApplication",
".",
"focusWidget",
"(",
")",
":",
"if",
"self",
".",
"current_index",
"(",
")",
".",
"row",
"(",
")",
"==",
"row",
":",
"color",
"=",
"self",
".",
"text_color_highlight",
"else",
":",
"color",
"=",
"self",
".",
"text_color",
"text",
"=",
"self",
".",
"rich_text",
"[",
"row",
"]",
"text",
"=",
"'<p style=\"color:{0}\">{1}</p>'",
".",
"format",
"(",
"color",
",",
"text",
")",
"return",
"to_qvariant",
"(",
"text",
")",
"elif",
"column",
"==",
"SEQUENCE",
":",
"text",
"=",
"QKeySequence",
"(",
"key",
")",
".",
"toString",
"(",
"QKeySequence",
".",
"NativeText",
")",
"return",
"to_qvariant",
"(",
"text",
")",
"elif",
"column",
"==",
"SEARCH_SCORE",
":",
"# Treating search scores as a table column simplifies the\r",
"# sorting once a score for a specific string in the finder\r",
"# has been defined. This column however should always remain\r",
"# hidden.\r",
"return",
"to_qvariant",
"(",
"self",
".",
"scores",
"[",
"row",
"]",
")",
"elif",
"role",
"==",
"Qt",
".",
"TextAlignmentRole",
":",
"return",
"to_qvariant",
"(",
"int",
"(",
"Qt",
".",
"AlignHCenter",
"|",
"Qt",
".",
"AlignVCenter",
")",
")",
"return",
"to_qvariant",
"(",
")"
] | Qt Override. | [
"Qt",
"Override",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L554-L588 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutsModel.headerData | def headerData(self, section, orientation, role=Qt.DisplayRole):
"""Qt Override."""
if role == Qt.TextAlignmentRole:
if orientation == Qt.Horizontal:
return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter))
return to_qvariant(int(Qt.AlignRight | Qt.AlignVCenter))
if role != Qt.DisplayRole:
return to_qvariant()
if orientation == Qt.Horizontal:
if section == CONTEXT:
return to_qvariant(_("Context"))
elif section == NAME:
return to_qvariant(_("Name"))
elif section == SEQUENCE:
return to_qvariant(_("Shortcut"))
elif section == SEARCH_SCORE:
return to_qvariant(_("Score"))
return to_qvariant() | python | def headerData(self, section, orientation, role=Qt.DisplayRole):
"""Qt Override."""
if role == Qt.TextAlignmentRole:
if orientation == Qt.Horizontal:
return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter))
return to_qvariant(int(Qt.AlignRight | Qt.AlignVCenter))
if role != Qt.DisplayRole:
return to_qvariant()
if orientation == Qt.Horizontal:
if section == CONTEXT:
return to_qvariant(_("Context"))
elif section == NAME:
return to_qvariant(_("Name"))
elif section == SEQUENCE:
return to_qvariant(_("Shortcut"))
elif section == SEARCH_SCORE:
return to_qvariant(_("Score"))
return to_qvariant() | [
"def",
"headerData",
"(",
"self",
",",
"section",
",",
"orientation",
",",
"role",
"=",
"Qt",
".",
"DisplayRole",
")",
":",
"if",
"role",
"==",
"Qt",
".",
"TextAlignmentRole",
":",
"if",
"orientation",
"==",
"Qt",
".",
"Horizontal",
":",
"return",
"to_qvariant",
"(",
"int",
"(",
"Qt",
".",
"AlignHCenter",
"|",
"Qt",
".",
"AlignVCenter",
")",
")",
"return",
"to_qvariant",
"(",
"int",
"(",
"Qt",
".",
"AlignRight",
"|",
"Qt",
".",
"AlignVCenter",
")",
")",
"if",
"role",
"!=",
"Qt",
".",
"DisplayRole",
":",
"return",
"to_qvariant",
"(",
")",
"if",
"orientation",
"==",
"Qt",
".",
"Horizontal",
":",
"if",
"section",
"==",
"CONTEXT",
":",
"return",
"to_qvariant",
"(",
"_",
"(",
"\"Context\"",
")",
")",
"elif",
"section",
"==",
"NAME",
":",
"return",
"to_qvariant",
"(",
"_",
"(",
"\"Name\"",
")",
")",
"elif",
"section",
"==",
"SEQUENCE",
":",
"return",
"to_qvariant",
"(",
"_",
"(",
"\"Shortcut\"",
")",
")",
"elif",
"section",
"==",
"SEARCH_SCORE",
":",
"return",
"to_qvariant",
"(",
"_",
"(",
"\"Score\"",
")",
")",
"return",
"to_qvariant",
"(",
")"
] | Qt Override. | [
"Qt",
"Override",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L590-L607 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutsModel.setData | def setData(self, index, value, role=Qt.EditRole):
"""Qt Override."""
if index.isValid() and 0 <= index.row() < len(self.shortcuts):
shortcut = self.shortcuts[index.row()]
column = index.column()
text = from_qvariant(value, str)
if column == SEQUENCE:
shortcut.key = text
self.dataChanged.emit(index, index)
return True
return False | python | def setData(self, index, value, role=Qt.EditRole):
"""Qt Override."""
if index.isValid() and 0 <= index.row() < len(self.shortcuts):
shortcut = self.shortcuts[index.row()]
column = index.column()
text = from_qvariant(value, str)
if column == SEQUENCE:
shortcut.key = text
self.dataChanged.emit(index, index)
return True
return False | [
"def",
"setData",
"(",
"self",
",",
"index",
",",
"value",
",",
"role",
"=",
"Qt",
".",
"EditRole",
")",
":",
"if",
"index",
".",
"isValid",
"(",
")",
"and",
"0",
"<=",
"index",
".",
"row",
"(",
")",
"<",
"len",
"(",
"self",
".",
"shortcuts",
")",
":",
"shortcut",
"=",
"self",
".",
"shortcuts",
"[",
"index",
".",
"row",
"(",
")",
"]",
"column",
"=",
"index",
".",
"column",
"(",
")",
"text",
"=",
"from_qvariant",
"(",
"value",
",",
"str",
")",
"if",
"column",
"==",
"SEQUENCE",
":",
"shortcut",
".",
"key",
"=",
"text",
"self",
".",
"dataChanged",
".",
"emit",
"(",
"index",
",",
"index",
")",
"return",
"True",
"return",
"False"
] | Qt Override. | [
"Qt",
"Override",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L617-L627 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutsModel.update_search_letters | def update_search_letters(self, text):
"""Update search letters with text input in search box."""
self.letters = text
names = [shortcut.name for shortcut in self.shortcuts]
results = get_search_scores(text, names, template='<b>{0}</b>')
self.normal_text, self.rich_text, self.scores = zip(*results)
self.reset() | python | def update_search_letters(self, text):
"""Update search letters with text input in search box."""
self.letters = text
names = [shortcut.name for shortcut in self.shortcuts]
results = get_search_scores(text, names, template='<b>{0}</b>')
self.normal_text, self.rich_text, self.scores = zip(*results)
self.reset() | [
"def",
"update_search_letters",
"(",
"self",
",",
"text",
")",
":",
"self",
".",
"letters",
"=",
"text",
"names",
"=",
"[",
"shortcut",
".",
"name",
"for",
"shortcut",
"in",
"self",
".",
"shortcuts",
"]",
"results",
"=",
"get_search_scores",
"(",
"text",
",",
"names",
",",
"template",
"=",
"'<b>{0}</b>'",
")",
"self",
".",
"normal_text",
",",
"self",
".",
"rich_text",
",",
"self",
".",
"scores",
"=",
"zip",
"(",
"*",
"results",
")",
"self",
".",
"reset",
"(",
")"
] | Update search letters with text input in search box. | [
"Update",
"search",
"letters",
"with",
"text",
"input",
"in",
"search",
"box",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L629-L635 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | CustomSortFilterProxy.set_filter | def set_filter(self, text):
"""Set regular expression for filter."""
self.pattern = get_search_regex(text)
if self.pattern:
self._parent.setSortingEnabled(False)
else:
self._parent.setSortingEnabled(True)
self.invalidateFilter() | python | def set_filter(self, text):
"""Set regular expression for filter."""
self.pattern = get_search_regex(text)
if self.pattern:
self._parent.setSortingEnabled(False)
else:
self._parent.setSortingEnabled(True)
self.invalidateFilter() | [
"def",
"set_filter",
"(",
"self",
",",
"text",
")",
":",
"self",
".",
"pattern",
"=",
"get_search_regex",
"(",
"text",
")",
"if",
"self",
".",
"pattern",
":",
"self",
".",
"_parent",
".",
"setSortingEnabled",
"(",
"False",
")",
"else",
":",
"self",
".",
"_parent",
".",
"setSortingEnabled",
"(",
"True",
")",
"self",
".",
"invalidateFilter",
"(",
")"
] | Set regular expression for filter. | [
"Set",
"regular",
"expression",
"for",
"filter",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L659-L666 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | CustomSortFilterProxy.filterAcceptsRow | def filterAcceptsRow(self, row_num, parent):
"""Qt override.
Reimplemented from base class to allow the use of custom filtering.
"""
model = self.sourceModel()
name = model.row(row_num).name
r = re.search(self.pattern, name)
if r is None:
return False
else:
return True | python | def filterAcceptsRow(self, row_num, parent):
"""Qt override.
Reimplemented from base class to allow the use of custom filtering.
"""
model = self.sourceModel()
name = model.row(row_num).name
r = re.search(self.pattern, name)
if r is None:
return False
else:
return True | [
"def",
"filterAcceptsRow",
"(",
"self",
",",
"row_num",
",",
"parent",
")",
":",
"model",
"=",
"self",
".",
"sourceModel",
"(",
")",
"name",
"=",
"model",
".",
"row",
"(",
"row_num",
")",
".",
"name",
"r",
"=",
"re",
".",
"search",
"(",
"self",
".",
"pattern",
",",
"name",
")",
"if",
"r",
"is",
"None",
":",
"return",
"False",
"else",
":",
"return",
"True"
] | Qt override.
Reimplemented from base class to allow the use of custom filtering. | [
"Qt",
"override",
".",
"Reimplemented",
"from",
"base",
"class",
"to",
"allow",
"the",
"use",
"of",
"custom",
"filtering",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L668-L680 | train |
spyder-ide/spyder | spyder/preferences/shortcuts.py | ShortcutsTable.focusOutEvent | def focusOutEvent(self, e):
"""Qt Override."""
self.source_model.update_active_row()
super(ShortcutsTable, self).focusOutEvent(e) | python | def focusOutEvent(self, e):
"""Qt Override."""
self.source_model.update_active_row()
super(ShortcutsTable, self).focusOutEvent(e) | [
"def",
"focusOutEvent",
"(",
"self",
",",
"e",
")",
":",
"self",
".",
"source_model",
".",
"update_active_row",
"(",
")",
"super",
"(",
"ShortcutsTable",
",",
"self",
")",
".",
"focusOutEvent",
"(",
"e",
")"
] | Qt Override. | [
"Qt",
"Override",
"."
] | f76836ce1b924bcc4efd3f74f2960d26a4e528e0 | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/shortcuts.py#L714-L717 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.