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/editor/widgets/editor.py
EditorMainWindow.get_layout_settings
def get_layout_settings(self): """Return layout state""" splitsettings = self.editorwidget.editorsplitter.get_layout_settings() return dict(size=(self.window_size.width(), self.window_size.height()), pos=(self.pos().x(), self.pos().y()), is_maximized=self.isMaximized(), is_fullscreen=self.isFullScreen(), hexstate=qbytearray_to_str(self.saveState()), splitsettings=splitsettings)
python
def get_layout_settings(self): """Return layout state""" splitsettings = self.editorwidget.editorsplitter.get_layout_settings() return dict(size=(self.window_size.width(), self.window_size.height()), pos=(self.pos().x(), self.pos().y()), is_maximized=self.isMaximized(), is_fullscreen=self.isFullScreen(), hexstate=qbytearray_to_str(self.saveState()), splitsettings=splitsettings)
[ "def", "get_layout_settings", "(", "self", ")", ":", "splitsettings", "=", "self", ".", "editorwidget", ".", "editorsplitter", ".", "get_layout_settings", "(", ")", "return", "dict", "(", "size", "=", "(", "self", ".", "window_size", ".", "width", "(", ")", ",", "self", ".", "window_size", ".", "height", "(", ")", ")", ",", "pos", "=", "(", "self", ".", "pos", "(", ")", ".", "x", "(", ")", ",", "self", ".", "pos", "(", ")", ".", "y", "(", ")", ")", ",", "is_maximized", "=", "self", ".", "isMaximized", "(", ")", ",", "is_fullscreen", "=", "self", ".", "isFullScreen", "(", ")", ",", "hexstate", "=", "qbytearray_to_str", "(", "self", ".", "saveState", "(", ")", ")", ",", "splitsettings", "=", "splitsettings", ")" ]
Return layout state
[ "Return", "layout", "state" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/widgets/editor.py#L2970-L2978
train
spyder-ide/spyder
spyder/plugins/editor/widgets/editor.py
EditorMainWindow.set_layout_settings
def set_layout_settings(self, settings): """Restore layout state""" size = settings.get('size') if size is not None: self.resize( QSize(*size) ) self.window_size = self.size() pos = settings.get('pos') if pos is not None: self.move( QPoint(*pos) ) hexstate = settings.get('hexstate') if hexstate is not None: self.restoreState( QByteArray().fromHex( str(hexstate).encode('utf-8')) ) if settings.get('is_maximized'): self.setWindowState(Qt.WindowMaximized) if settings.get('is_fullscreen'): self.setWindowState(Qt.WindowFullScreen) splitsettings = settings.get('splitsettings') if splitsettings is not None: self.editorwidget.editorsplitter.set_layout_settings(splitsettings)
python
def set_layout_settings(self, settings): """Restore layout state""" size = settings.get('size') if size is not None: self.resize( QSize(*size) ) self.window_size = self.size() pos = settings.get('pos') if pos is not None: self.move( QPoint(*pos) ) hexstate = settings.get('hexstate') if hexstate is not None: self.restoreState( QByteArray().fromHex( str(hexstate).encode('utf-8')) ) if settings.get('is_maximized'): self.setWindowState(Qt.WindowMaximized) if settings.get('is_fullscreen'): self.setWindowState(Qt.WindowFullScreen) splitsettings = settings.get('splitsettings') if splitsettings is not None: self.editorwidget.editorsplitter.set_layout_settings(splitsettings)
[ "def", "set_layout_settings", "(", "self", ",", "settings", ")", ":", "size", "=", "settings", ".", "get", "(", "'size'", ")", "if", "size", "is", "not", "None", ":", "self", ".", "resize", "(", "QSize", "(", "*", "size", ")", ")", "self", ".", "window_size", "=", "self", ".", "size", "(", ")", "pos", "=", "settings", ".", "get", "(", "'pos'", ")", "if", "pos", "is", "not", "None", ":", "self", ".", "move", "(", "QPoint", "(", "*", "pos", ")", ")", "hexstate", "=", "settings", ".", "get", "(", "'hexstate'", ")", "if", "hexstate", "is", "not", "None", ":", "self", ".", "restoreState", "(", "QByteArray", "(", ")", ".", "fromHex", "(", "str", "(", "hexstate", ")", ".", "encode", "(", "'utf-8'", ")", ")", ")", "if", "settings", ".", "get", "(", "'is_maximized'", ")", ":", "self", ".", "setWindowState", "(", "Qt", ".", "WindowMaximized", ")", "if", "settings", ".", "get", "(", "'is_fullscreen'", ")", ":", "self", ".", "setWindowState", "(", "Qt", ".", "WindowFullScreen", ")", "splitsettings", "=", "settings", ".", "get", "(", "'splitsettings'", ")", "if", "splitsettings", "is", "not", "None", ":", "self", ".", "editorwidget", ".", "editorsplitter", ".", "set_layout_settings", "(", "splitsettings", ")" ]
Restore layout state
[ "Restore", "layout", "state" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/widgets/editor.py#L2980-L2999
train
spyder-ide/spyder
spyder/plugins/editor/widgets/editor.py
EditorPluginExample.file_saved_in_editorstack
def file_saved_in_editorstack(self, editorstack_id_str, original_filename, filename): """A file was saved in editorstack, this notifies others""" for editorstack in self.editorstacks: if str(id(editorstack)) != editorstack_id_str: editorstack.file_saved_in_other_editorstack(original_filename, filename)
python
def file_saved_in_editorstack(self, editorstack_id_str, original_filename, filename): """A file was saved in editorstack, this notifies others""" for editorstack in self.editorstacks: if str(id(editorstack)) != editorstack_id_str: editorstack.file_saved_in_other_editorstack(original_filename, filename)
[ "def", "file_saved_in_editorstack", "(", "self", ",", "editorstack_id_str", ",", "original_filename", ",", "filename", ")", ":", "for", "editorstack", "in", "self", ".", "editorstacks", ":", "if", "str", "(", "id", "(", "editorstack", ")", ")", "!=", "editorstack_id_str", ":", "editorstack", ".", "file_saved_in_other_editorstack", "(", "original_filename", ",", "filename", ")" ]
A file was saved in editorstack, this notifies others
[ "A", "file", "was", "saved", "in", "editorstack", "this", "notifies", "others" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/widgets/editor.py#L3131-L3137
train
spyder-ide/spyder
spyder/plugins/editor/widgets/editor.py
EditorPluginExample.file_renamed_in_data_in_editorstack
def file_renamed_in_data_in_editorstack(self, editorstack_id_str, original_filename, filename): """A file was renamed in data in editorstack, this notifies others""" for editorstack in self.editorstacks: if str(id(editorstack)) != editorstack_id_str: editorstack.rename_in_data(original_filename, filename)
python
def file_renamed_in_data_in_editorstack(self, editorstack_id_str, original_filename, filename): """A file was renamed in data in editorstack, this notifies others""" for editorstack in self.editorstacks: if str(id(editorstack)) != editorstack_id_str: editorstack.rename_in_data(original_filename, filename)
[ "def", "file_renamed_in_data_in_editorstack", "(", "self", ",", "editorstack_id_str", ",", "original_filename", ",", "filename", ")", ":", "for", "editorstack", "in", "self", ".", "editorstacks", ":", "if", "str", "(", "id", "(", "editorstack", ")", ")", "!=", "editorstack_id_str", ":", "editorstack", ".", "rename_in_data", "(", "original_filename", ",", "filename", ")" ]
A file was renamed in data in editorstack, this notifies others
[ "A", "file", "was", "renamed", "in", "data", "in", "editorstack", "this", "notifies", "others" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/widgets/editor.py#L3142-L3147
train
spyder-ide/spyder
spyder/plugins/findinfiles/plugin.py
FindInFiles.findinfiles_callback
def findinfiles_callback(self): """Find in files callback""" widget = QApplication.focusWidget() if not self.ismaximized: self.dockwidget.setVisible(True) self.dockwidget.raise_() text = '' try: if widget.has_selected_text(): text = widget.get_selected_text() except AttributeError: # This is not a text widget deriving from TextEditBaseWidget pass self.findinfiles.set_search_text(text) if text: self.findinfiles.find()
python
def findinfiles_callback(self): """Find in files callback""" widget = QApplication.focusWidget() if not self.ismaximized: self.dockwidget.setVisible(True) self.dockwidget.raise_() text = '' try: if widget.has_selected_text(): text = widget.get_selected_text() except AttributeError: # This is not a text widget deriving from TextEditBaseWidget pass self.findinfiles.set_search_text(text) if text: self.findinfiles.find()
[ "def", "findinfiles_callback", "(", "self", ")", ":", "widget", "=", "QApplication", ".", "focusWidget", "(", ")", "if", "not", "self", ".", "ismaximized", ":", "self", ".", "dockwidget", ".", "setVisible", "(", "True", ")", "self", ".", "dockwidget", ".", "raise_", "(", ")", "text", "=", "''", "try", ":", "if", "widget", ".", "has_selected_text", "(", ")", ":", "text", "=", "widget", ".", "get_selected_text", "(", ")", "except", "AttributeError", ":", "# This is not a text widget deriving from TextEditBaseWidget\r", "pass", "self", ".", "findinfiles", ".", "set_search_text", "(", "text", ")", "if", "text", ":", "self", ".", "findinfiles", ".", "find", "(", ")" ]
Find in files callback
[ "Find", "in", "files", "callback" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/findinfiles/plugin.py#L98-L113
train
spyder-ide/spyder
spyder/plugins/findinfiles/plugin.py
FindInFiles.register_plugin
def register_plugin(self): """Register plugin in Spyder's main window""" self.main.add_dockwidget(self) self.findinfiles.result_browser.sig_edit_goto.connect( self.main.editor.load) self.findinfiles.find_options.redirect_stdio.connect( self.main.redirect_internalshell_stdio) self.main.workingdirectory.refresh_findinfiles.connect(self.refreshdir) self.main.projects.sig_project_loaded.connect(self.set_project_path) self.main.projects.sig_project_closed.connect(self.unset_project_path) self.main.editor.open_file_update.connect(self.set_current_opened_file) findinfiles_action = create_action( self, _("&Find in files"), icon=ima.icon('findf'), triggered=self.switch_to_plugin, shortcut=QKeySequence(self.shortcut), context=Qt.WidgetShortcut, tip=_("Search text in multiple files")) self.main.search_menu_actions += [MENU_SEPARATOR, findinfiles_action] self.main.search_toolbar_actions += [MENU_SEPARATOR, findinfiles_action] self.refreshdir()
python
def register_plugin(self): """Register plugin in Spyder's main window""" self.main.add_dockwidget(self) self.findinfiles.result_browser.sig_edit_goto.connect( self.main.editor.load) self.findinfiles.find_options.redirect_stdio.connect( self.main.redirect_internalshell_stdio) self.main.workingdirectory.refresh_findinfiles.connect(self.refreshdir) self.main.projects.sig_project_loaded.connect(self.set_project_path) self.main.projects.sig_project_closed.connect(self.unset_project_path) self.main.editor.open_file_update.connect(self.set_current_opened_file) findinfiles_action = create_action( self, _("&Find in files"), icon=ima.icon('findf'), triggered=self.switch_to_plugin, shortcut=QKeySequence(self.shortcut), context=Qt.WidgetShortcut, tip=_("Search text in multiple files")) self.main.search_menu_actions += [MENU_SEPARATOR, findinfiles_action] self.main.search_toolbar_actions += [MENU_SEPARATOR, findinfiles_action] self.refreshdir()
[ "def", "register_plugin", "(", "self", ")", ":", "self", ".", "main", ".", "add_dockwidget", "(", "self", ")", "self", ".", "findinfiles", ".", "result_browser", ".", "sig_edit_goto", ".", "connect", "(", "self", ".", "main", ".", "editor", ".", "load", ")", "self", ".", "findinfiles", ".", "find_options", ".", "redirect_stdio", ".", "connect", "(", "self", ".", "main", ".", "redirect_internalshell_stdio", ")", "self", ".", "main", ".", "workingdirectory", ".", "refresh_findinfiles", ".", "connect", "(", "self", ".", "refreshdir", ")", "self", ".", "main", ".", "projects", ".", "sig_project_loaded", ".", "connect", "(", "self", ".", "set_project_path", ")", "self", ".", "main", ".", "projects", ".", "sig_project_closed", ".", "connect", "(", "self", ".", "unset_project_path", ")", "self", ".", "main", ".", "editor", ".", "open_file_update", ".", "connect", "(", "self", ".", "set_current_opened_file", ")", "findinfiles_action", "=", "create_action", "(", "self", ",", "_", "(", "\"&Find in files\"", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'findf'", ")", ",", "triggered", "=", "self", ".", "switch_to_plugin", ",", "shortcut", "=", "QKeySequence", "(", "self", ".", "shortcut", ")", ",", "context", "=", "Qt", ".", "WidgetShortcut", ",", "tip", "=", "_", "(", "\"Search text in multiple files\"", ")", ")", "self", ".", "main", ".", "search_menu_actions", "+=", "[", "MENU_SEPARATOR", ",", "findinfiles_action", "]", "self", ".", "main", ".", "search_toolbar_actions", "+=", "[", "MENU_SEPARATOR", ",", "findinfiles_action", "]", "self", ".", "refreshdir", "(", ")" ]
Register plugin in Spyder's main window
[ "Register", "plugin", "in", "Spyder", "s", "main", "window" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/findinfiles/plugin.py#L138-L161
train
spyder-ide/spyder
spyder/plugins/findinfiles/plugin.py
FindInFiles.closing_plugin
def closing_plugin(self, cancelable=False): """Perform actions before parent main window is closed""" self.findinfiles.closing_widget() # stop search thread and clean-up options = self.findinfiles.find_options.get_options(to_save=True) if options is not None: (search_text, text_re, exclude, exclude_idx, exclude_re, more_options, case_sensitive, path_history) = options hist_limit = 15 search_text = search_text[:hist_limit] exclude = exclude[:hist_limit] path_history = path_history[-hist_limit:] self.set_option('search_text', search_text) self.set_option('search_text_regexp', text_re) self.set_option('exclude', exclude) self.set_option('exclude_idx', exclude_idx) self.set_option('exclude_regexp', exclude_re) self.set_option('more_options', more_options) self.set_option('case_sensitive', case_sensitive) self.set_option('path_history', path_history) return True
python
def closing_plugin(self, cancelable=False): """Perform actions before parent main window is closed""" self.findinfiles.closing_widget() # stop search thread and clean-up options = self.findinfiles.find_options.get_options(to_save=True) if options is not None: (search_text, text_re, exclude, exclude_idx, exclude_re, more_options, case_sensitive, path_history) = options hist_limit = 15 search_text = search_text[:hist_limit] exclude = exclude[:hist_limit] path_history = path_history[-hist_limit:] self.set_option('search_text', search_text) self.set_option('search_text_regexp', text_re) self.set_option('exclude', exclude) self.set_option('exclude_idx', exclude_idx) self.set_option('exclude_regexp', exclude_re) self.set_option('more_options', more_options) self.set_option('case_sensitive', case_sensitive) self.set_option('path_history', path_history) return True
[ "def", "closing_plugin", "(", "self", ",", "cancelable", "=", "False", ")", ":", "self", ".", "findinfiles", ".", "closing_widget", "(", ")", "# stop search thread and clean-up\r", "options", "=", "self", ".", "findinfiles", ".", "find_options", ".", "get_options", "(", "to_save", "=", "True", ")", "if", "options", "is", "not", "None", ":", "(", "search_text", ",", "text_re", ",", "exclude", ",", "exclude_idx", ",", "exclude_re", ",", "more_options", ",", "case_sensitive", ",", "path_history", ")", "=", "options", "hist_limit", "=", "15", "search_text", "=", "search_text", "[", ":", "hist_limit", "]", "exclude", "=", "exclude", "[", ":", "hist_limit", "]", "path_history", "=", "path_history", "[", "-", "hist_limit", ":", "]", "self", ".", "set_option", "(", "'search_text'", ",", "search_text", ")", "self", ".", "set_option", "(", "'search_text_regexp'", ",", "text_re", ")", "self", ".", "set_option", "(", "'exclude'", ",", "exclude", ")", "self", ".", "set_option", "(", "'exclude_idx'", ",", "exclude_idx", ")", "self", ".", "set_option", "(", "'exclude_regexp'", ",", "exclude_re", ")", "self", ".", "set_option", "(", "'more_options'", ",", "more_options", ")", "self", ".", "set_option", "(", "'case_sensitive'", ",", "case_sensitive", ")", "self", ".", "set_option", "(", "'path_history'", ",", "path_history", ")", "return", "True" ]
Perform actions before parent main window is closed
[ "Perform", "actions", "before", "parent", "main", "window", "is", "closed" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/findinfiles/plugin.py#L167-L188
train
spyder-ide/spyder
spyder/plugins/editor/panels/codefolding.py
FoldingPanel._draw_fold_region_background
def _draw_fold_region_background(self, block, painter): """ Draw the fold region when the mouse is over and non collapsed indicator. :param top: Top position :param block: Current block. :param painter: QPainter """ r = FoldScope(block) th = TextHelper(self.editor) start, end = r.get_range(ignore_blank_lines=True) if start > 0: top = th.line_pos_from_number(start) else: top = 0 bottom = th.line_pos_from_number(end + 1) h = bottom - top if h == 0: h = self.sizeHint().height() w = self.sizeHint().width() self._draw_rect(QRectF(0, top, w, h), painter)
python
def _draw_fold_region_background(self, block, painter): """ Draw the fold region when the mouse is over and non collapsed indicator. :param top: Top position :param block: Current block. :param painter: QPainter """ r = FoldScope(block) th = TextHelper(self.editor) start, end = r.get_range(ignore_blank_lines=True) if start > 0: top = th.line_pos_from_number(start) else: top = 0 bottom = th.line_pos_from_number(end + 1) h = bottom - top if h == 0: h = self.sizeHint().height() w = self.sizeHint().width() self._draw_rect(QRectF(0, top, w, h), painter)
[ "def", "_draw_fold_region_background", "(", "self", ",", "block", ",", "painter", ")", ":", "r", "=", "FoldScope", "(", "block", ")", "th", "=", "TextHelper", "(", "self", ".", "editor", ")", "start", ",", "end", "=", "r", ".", "get_range", "(", "ignore_blank_lines", "=", "True", ")", "if", "start", ">", "0", ":", "top", "=", "th", ".", "line_pos_from_number", "(", "start", ")", "else", ":", "top", "=", "0", "bottom", "=", "th", ".", "line_pos_from_number", "(", "end", "+", "1", ")", "h", "=", "bottom", "-", "top", "if", "h", "==", "0", ":", "h", "=", "self", ".", "sizeHint", "(", ")", ".", "height", "(", ")", "w", "=", "self", ".", "sizeHint", "(", ")", ".", "width", "(", ")", "self", ".", "_draw_rect", "(", "QRectF", "(", "0", ",", "top", ",", "w", ",", "h", ")", ",", "painter", ")" ]
Draw the fold region when the mouse is over and non collapsed indicator. :param top: Top position :param block: Current block. :param painter: QPainter
[ "Draw", "the", "fold", "region", "when", "the", "mouse", "is", "over", "and", "non", "collapsed", "indicator", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/codefolding.py#L226-L247
train
spyder-ide/spyder
spyder/plugins/editor/panels/codefolding.py
FoldingPanel._draw_rect
def _draw_rect(self, rect, painter): """ Draw the background rectangle using the current style primitive color. :param rect: The fold zone rect to draw :param painter: The widget's painter. """ c = self.editor.sideareas_color grad = QLinearGradient(rect.topLeft(), rect.topRight()) if sys.platform == 'darwin': grad.setColorAt(0, c.lighter(100)) grad.setColorAt(1, c.lighter(110)) outline = c.darker(110) else: grad.setColorAt(0, c.lighter(110)) grad.setColorAt(1, c.lighter(130)) outline = c.darker(100) painter.fillRect(rect, grad) painter.setPen(QPen(outline)) painter.drawLine(rect.topLeft() + QPointF(1, 0), rect.topRight() - QPointF(1, 0)) painter.drawLine(rect.bottomLeft() + QPointF(1, 0), rect.bottomRight() - QPointF(1, 0)) painter.drawLine(rect.topRight() + QPointF(0, 1), rect.bottomRight() - QPointF(0, 1)) painter.drawLine(rect.topLeft() + QPointF(0, 1), rect.bottomLeft() - QPointF(0, 1))
python
def _draw_rect(self, rect, painter): """ Draw the background rectangle using the current style primitive color. :param rect: The fold zone rect to draw :param painter: The widget's painter. """ c = self.editor.sideareas_color grad = QLinearGradient(rect.topLeft(), rect.topRight()) if sys.platform == 'darwin': grad.setColorAt(0, c.lighter(100)) grad.setColorAt(1, c.lighter(110)) outline = c.darker(110) else: grad.setColorAt(0, c.lighter(110)) grad.setColorAt(1, c.lighter(130)) outline = c.darker(100) painter.fillRect(rect, grad) painter.setPen(QPen(outline)) painter.drawLine(rect.topLeft() + QPointF(1, 0), rect.topRight() - QPointF(1, 0)) painter.drawLine(rect.bottomLeft() + QPointF(1, 0), rect.bottomRight() - QPointF(1, 0)) painter.drawLine(rect.topRight() + QPointF(0, 1), rect.bottomRight() - QPointF(0, 1)) painter.drawLine(rect.topLeft() + QPointF(0, 1), rect.bottomLeft() - QPointF(0, 1))
[ "def", "_draw_rect", "(", "self", ",", "rect", ",", "painter", ")", ":", "c", "=", "self", ".", "editor", ".", "sideareas_color", "grad", "=", "QLinearGradient", "(", "rect", ".", "topLeft", "(", ")", ",", "rect", ".", "topRight", "(", ")", ")", "if", "sys", ".", "platform", "==", "'darwin'", ":", "grad", ".", "setColorAt", "(", "0", ",", "c", ".", "lighter", "(", "100", ")", ")", "grad", ".", "setColorAt", "(", "1", ",", "c", ".", "lighter", "(", "110", ")", ")", "outline", "=", "c", ".", "darker", "(", "110", ")", "else", ":", "grad", ".", "setColorAt", "(", "0", ",", "c", ".", "lighter", "(", "110", ")", ")", "grad", ".", "setColorAt", "(", "1", ",", "c", ".", "lighter", "(", "130", ")", ")", "outline", "=", "c", ".", "darker", "(", "100", ")", "painter", ".", "fillRect", "(", "rect", ",", "grad", ")", "painter", ".", "setPen", "(", "QPen", "(", "outline", ")", ")", "painter", ".", "drawLine", "(", "rect", ".", "topLeft", "(", ")", "+", "QPointF", "(", "1", ",", "0", ")", ",", "rect", ".", "topRight", "(", ")", "-", "QPointF", "(", "1", ",", "0", ")", ")", "painter", ".", "drawLine", "(", "rect", ".", "bottomLeft", "(", ")", "+", "QPointF", "(", "1", ",", "0", ")", ",", "rect", ".", "bottomRight", "(", ")", "-", "QPointF", "(", "1", ",", "0", ")", ")", "painter", ".", "drawLine", "(", "rect", ".", "topRight", "(", ")", "+", "QPointF", "(", "0", ",", "1", ")", ",", "rect", ".", "bottomRight", "(", ")", "-", "QPointF", "(", "0", ",", "1", ")", ")", "painter", ".", "drawLine", "(", "rect", ".", "topLeft", "(", ")", "+", "QPointF", "(", "0", ",", "1", ")", ",", "rect", ".", "bottomLeft", "(", ")", "-", "QPointF", "(", "0", ",", "1", ")", ")" ]
Draw the background rectangle using the current style primitive color. :param rect: The fold zone rect to draw :param painter: The widget's painter.
[ "Draw", "the", "background", "rectangle", "using", "the", "current", "style", "primitive", "color", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/codefolding.py#L249-L285
train
spyder-ide/spyder
spyder/plugins/editor/panels/codefolding.py
FoldingPanel._draw_fold_indicator
def _draw_fold_indicator(self, top, mouse_over, collapsed, painter): """ Draw the fold indicator/trigger (arrow). :param top: Top position :param mouse_over: Whether the mouse is over the indicator :param collapsed: Whether the trigger is collapsed or not. :param painter: QPainter """ rect = QRect(0, top, self.sizeHint().width(), self.sizeHint().height()) if self._native_icons: opt = QStyleOptionViewItem() opt.rect = rect opt.state = (QStyle.State_Active | QStyle.State_Item | QStyle.State_Children) if not collapsed: opt.state |= QStyle.State_Open if mouse_over: opt.state |= (QStyle.State_MouseOver | QStyle.State_Enabled | QStyle.State_Selected) opt.palette.setBrush(QPalette.Window, self.palette().highlight()) opt.rect.translate(-2, 0) self.style().drawPrimitive(QStyle.PE_IndicatorBranch, opt, painter, self) else: index = 0 if not collapsed: index = 2 if mouse_over: index += 1 ima.icon(self._indicators_icons[index]).paint(painter, rect)
python
def _draw_fold_indicator(self, top, mouse_over, collapsed, painter): """ Draw the fold indicator/trigger (arrow). :param top: Top position :param mouse_over: Whether the mouse is over the indicator :param collapsed: Whether the trigger is collapsed or not. :param painter: QPainter """ rect = QRect(0, top, self.sizeHint().width(), self.sizeHint().height()) if self._native_icons: opt = QStyleOptionViewItem() opt.rect = rect opt.state = (QStyle.State_Active | QStyle.State_Item | QStyle.State_Children) if not collapsed: opt.state |= QStyle.State_Open if mouse_over: opt.state |= (QStyle.State_MouseOver | QStyle.State_Enabled | QStyle.State_Selected) opt.palette.setBrush(QPalette.Window, self.palette().highlight()) opt.rect.translate(-2, 0) self.style().drawPrimitive(QStyle.PE_IndicatorBranch, opt, painter, self) else: index = 0 if not collapsed: index = 2 if mouse_over: index += 1 ima.icon(self._indicators_icons[index]).paint(painter, rect)
[ "def", "_draw_fold_indicator", "(", "self", ",", "top", ",", "mouse_over", ",", "collapsed", ",", "painter", ")", ":", "rect", "=", "QRect", "(", "0", ",", "top", ",", "self", ".", "sizeHint", "(", ")", ".", "width", "(", ")", ",", "self", ".", "sizeHint", "(", ")", ".", "height", "(", ")", ")", "if", "self", ".", "_native_icons", ":", "opt", "=", "QStyleOptionViewItem", "(", ")", "opt", ".", "rect", "=", "rect", "opt", ".", "state", "=", "(", "QStyle", ".", "State_Active", "|", "QStyle", ".", "State_Item", "|", "QStyle", ".", "State_Children", ")", "if", "not", "collapsed", ":", "opt", ".", "state", "|=", "QStyle", ".", "State_Open", "if", "mouse_over", ":", "opt", ".", "state", "|=", "(", "QStyle", ".", "State_MouseOver", "|", "QStyle", ".", "State_Enabled", "|", "QStyle", ".", "State_Selected", ")", "opt", ".", "palette", ".", "setBrush", "(", "QPalette", ".", "Window", ",", "self", ".", "palette", "(", ")", ".", "highlight", "(", ")", ")", "opt", ".", "rect", ".", "translate", "(", "-", "2", ",", "0", ")", "self", ".", "style", "(", ")", ".", "drawPrimitive", "(", "QStyle", ".", "PE_IndicatorBranch", ",", "opt", ",", "painter", ",", "self", ")", "else", ":", "index", "=", "0", "if", "not", "collapsed", ":", "index", "=", "2", "if", "mouse_over", ":", "index", "+=", "1", "ima", ".", "icon", "(", "self", ".", "_indicators_icons", "[", "index", "]", ")", ".", "paint", "(", "painter", ",", "rect", ")" ]
Draw the fold indicator/trigger (arrow). :param top: Top position :param mouse_over: Whether the mouse is over the indicator :param collapsed: Whether the trigger is collapsed or not. :param painter: QPainter
[ "Draw", "the", "fold", "indicator", "/", "trigger", "(", "arrow", ")", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/codefolding.py#L287-L322
train
spyder-ide/spyder
spyder/plugins/editor/panels/codefolding.py
FoldingPanel.find_parent_scope
def find_parent_scope(block): """Find parent scope, if the block is not a fold trigger.""" original = block if not TextBlockHelper.is_fold_trigger(block): # search level of next non blank line while block.text().strip() == '' and block.isValid(): block = block.next() ref_lvl = TextBlockHelper.get_fold_lvl(block) - 1 block = original while (block.blockNumber() and (not TextBlockHelper.is_fold_trigger(block) or TextBlockHelper.get_fold_lvl(block) > ref_lvl)): block = block.previous() return block
python
def find_parent_scope(block): """Find parent scope, if the block is not a fold trigger.""" original = block if not TextBlockHelper.is_fold_trigger(block): # search level of next non blank line while block.text().strip() == '' and block.isValid(): block = block.next() ref_lvl = TextBlockHelper.get_fold_lvl(block) - 1 block = original while (block.blockNumber() and (not TextBlockHelper.is_fold_trigger(block) or TextBlockHelper.get_fold_lvl(block) > ref_lvl)): block = block.previous() return block
[ "def", "find_parent_scope", "(", "block", ")", ":", "original", "=", "block", "if", "not", "TextBlockHelper", ".", "is_fold_trigger", "(", "block", ")", ":", "# search level of next non blank line", "while", "block", ".", "text", "(", ")", ".", "strip", "(", ")", "==", "''", "and", "block", ".", "isValid", "(", ")", ":", "block", "=", "block", ".", "next", "(", ")", "ref_lvl", "=", "TextBlockHelper", ".", "get_fold_lvl", "(", "block", ")", "-", "1", "block", "=", "original", "while", "(", "block", ".", "blockNumber", "(", ")", "and", "(", "not", "TextBlockHelper", ".", "is_fold_trigger", "(", "block", ")", "or", "TextBlockHelper", ".", "get_fold_lvl", "(", "block", ")", ">", "ref_lvl", ")", ")", ":", "block", "=", "block", ".", "previous", "(", ")", "return", "block" ]
Find parent scope, if the block is not a fold trigger.
[ "Find", "parent", "scope", "if", "the", "block", "is", "not", "a", "fold", "trigger", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/codefolding.py#L325-L338
train
spyder-ide/spyder
spyder/plugins/editor/panels/codefolding.py
FoldingPanel._clear_scope_decos
def _clear_scope_decos(self): """Clear scope decorations (on the editor)""" for deco in self._scope_decos: self.editor.decorations.remove(deco) self._scope_decos[:] = []
python
def _clear_scope_decos(self): """Clear scope decorations (on the editor)""" for deco in self._scope_decos: self.editor.decorations.remove(deco) self._scope_decos[:] = []
[ "def", "_clear_scope_decos", "(", "self", ")", ":", "for", "deco", "in", "self", ".", "_scope_decos", ":", "self", ".", "editor", ".", "decorations", ".", "remove", "(", "deco", ")", "self", ".", "_scope_decos", "[", ":", "]", "=", "[", "]" ]
Clear scope decorations (on the editor)
[ "Clear", "scope", "decorations", "(", "on", "the", "editor", ")" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/codefolding.py#L340-L344
train
spyder-ide/spyder
spyder/plugins/editor/panels/codefolding.py
FoldingPanel._get_scope_highlight_color
def _get_scope_highlight_color(self): """ Gets the base scope highlight color (derivated from the editor background) For lighter themes will be a darker color, and for darker ones will be a lighter color """ color = self.editor.sideareas_color if color.lightness() < 128: color = drift_color(color, 130) else: color = drift_color(color, 105) return color
python
def _get_scope_highlight_color(self): """ Gets the base scope highlight color (derivated from the editor background) For lighter themes will be a darker color, and for darker ones will be a lighter color """ color = self.editor.sideareas_color if color.lightness() < 128: color = drift_color(color, 130) else: color = drift_color(color, 105) return color
[ "def", "_get_scope_highlight_color", "(", "self", ")", ":", "color", "=", "self", ".", "editor", ".", "sideareas_color", "if", "color", ".", "lightness", "(", ")", "<", "128", ":", "color", "=", "drift_color", "(", "color", ",", "130", ")", "else", ":", "color", "=", "drift_color", "(", "color", ",", "105", ")", "return", "color" ]
Gets the base scope highlight color (derivated from the editor background) For lighter themes will be a darker color, and for darker ones will be a lighter color
[ "Gets", "the", "base", "scope", "highlight", "color", "(", "derivated", "from", "the", "editor", "background", ")" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/codefolding.py#L346-L359
train
spyder-ide/spyder
spyder/plugins/editor/panels/codefolding.py
FoldingPanel._decorate_block
def _decorate_block(self, start, end): """ Create a decoration and add it to the editor. Args: start (int) start line of the decoration end (int) end line of the decoration """ color = self._get_scope_highlight_color() draw_order = DRAW_ORDERS.get('codefolding') d = TextDecoration(self.editor.document(), start_line=start, end_line=end+1, draw_order=draw_order) d.set_background(color) d.set_full_width(True, clear=False) self.editor.decorations.add(d) self._scope_decos.append(d)
python
def _decorate_block(self, start, end): """ Create a decoration and add it to the editor. Args: start (int) start line of the decoration end (int) end line of the decoration """ color = self._get_scope_highlight_color() draw_order = DRAW_ORDERS.get('codefolding') d = TextDecoration(self.editor.document(), start_line=start, end_line=end+1, draw_order=draw_order) d.set_background(color) d.set_full_width(True, clear=False) self.editor.decorations.add(d) self._scope_decos.append(d)
[ "def", "_decorate_block", "(", "self", ",", "start", ",", "end", ")", ":", "color", "=", "self", ".", "_get_scope_highlight_color", "(", ")", "draw_order", "=", "DRAW_ORDERS", ".", "get", "(", "'codefolding'", ")", "d", "=", "TextDecoration", "(", "self", ".", "editor", ".", "document", "(", ")", ",", "start_line", "=", "start", ",", "end_line", "=", "end", "+", "1", ",", "draw_order", "=", "draw_order", ")", "d", ".", "set_background", "(", "color", ")", "d", ".", "set_full_width", "(", "True", ",", "clear", "=", "False", ")", "self", ".", "editor", ".", "decorations", ".", "add", "(", "d", ")", "self", ".", "_scope_decos", ".", "append", "(", "d", ")" ]
Create a decoration and add it to the editor. Args: start (int) start line of the decoration end (int) end line of the decoration
[ "Create", "a", "decoration", "and", "add", "it", "to", "the", "editor", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/codefolding.py#L361-L376
train
spyder-ide/spyder
spyder/plugins/editor/panels/codefolding.py
FoldingPanel._highlight_block
def _highlight_block(self, block): """ Highlights the current fold scope. :param block: Block that starts the current fold scope. """ scope = FoldScope(block) if (self._current_scope is None or self._current_scope.get_range() != scope.get_range()): self._current_scope = scope self._clear_scope_decos() # highlight current scope with darker or lighter color start, end = scope.get_range() if not TextBlockHelper.is_collapsed(block): self._decorate_block(start, end)
python
def _highlight_block(self, block): """ Highlights the current fold scope. :param block: Block that starts the current fold scope. """ scope = FoldScope(block) if (self._current_scope is None or self._current_scope.get_range() != scope.get_range()): self._current_scope = scope self._clear_scope_decos() # highlight current scope with darker or lighter color start, end = scope.get_range() if not TextBlockHelper.is_collapsed(block): self._decorate_block(start, end)
[ "def", "_highlight_block", "(", "self", ",", "block", ")", ":", "scope", "=", "FoldScope", "(", "block", ")", "if", "(", "self", ".", "_current_scope", "is", "None", "or", "self", ".", "_current_scope", ".", "get_range", "(", ")", "!=", "scope", ".", "get_range", "(", ")", ")", ":", "self", ".", "_current_scope", "=", "scope", "self", ".", "_clear_scope_decos", "(", ")", "# highlight current scope with darker or lighter color", "start", ",", "end", "=", "scope", ".", "get_range", "(", ")", "if", "not", "TextBlockHelper", ".", "is_collapsed", "(", "block", ")", ":", "self", ".", "_decorate_block", "(", "start", ",", "end", ")" ]
Highlights the current fold scope. :param block: Block that starts the current fold scope.
[ "Highlights", "the", "current", "fold", "scope", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/codefolding.py#L378-L392
train
spyder-ide/spyder
spyder/plugins/editor/panels/codefolding.py
FoldingPanel.mouseMoveEvent
def mouseMoveEvent(self, event): """ Detect mouser over indicator and highlight the current scope in the editor (up and down decoration arround the foldable text when the mouse is over an indicator). :param event: event """ super(FoldingPanel, self).mouseMoveEvent(event) th = TextHelper(self.editor) line = th.line_nbr_from_position(event.pos().y()) if line >= 0: block = FoldScope.find_parent_scope( self.editor.document().findBlockByNumber(line-1)) if TextBlockHelper.is_fold_trigger(block): if self._mouse_over_line is None: # mouse enter fold scope QApplication.setOverrideCursor( QCursor(Qt.PointingHandCursor)) if self._mouse_over_line != block.blockNumber() and \ self._mouse_over_line is not None: # fold scope changed, a previous block was highlighter so # we quickly update our highlighting self._mouse_over_line = block.blockNumber() self._highlight_block(block) else: # same fold scope, request highlight self._mouse_over_line = block.blockNumber() self._highlight_runner.request_job( self._highlight_block, block) self._highight_block = block else: # no fold scope to highlight, cancel any pending requests self._highlight_runner.cancel_requests() self._mouse_over_line = None QApplication.restoreOverrideCursor() self.repaint()
python
def mouseMoveEvent(self, event): """ Detect mouser over indicator and highlight the current scope in the editor (up and down decoration arround the foldable text when the mouse is over an indicator). :param event: event """ super(FoldingPanel, self).mouseMoveEvent(event) th = TextHelper(self.editor) line = th.line_nbr_from_position(event.pos().y()) if line >= 0: block = FoldScope.find_parent_scope( self.editor.document().findBlockByNumber(line-1)) if TextBlockHelper.is_fold_trigger(block): if self._mouse_over_line is None: # mouse enter fold scope QApplication.setOverrideCursor( QCursor(Qt.PointingHandCursor)) if self._mouse_over_line != block.blockNumber() and \ self._mouse_over_line is not None: # fold scope changed, a previous block was highlighter so # we quickly update our highlighting self._mouse_over_line = block.blockNumber() self._highlight_block(block) else: # same fold scope, request highlight self._mouse_over_line = block.blockNumber() self._highlight_runner.request_job( self._highlight_block, block) self._highight_block = block else: # no fold scope to highlight, cancel any pending requests self._highlight_runner.cancel_requests() self._mouse_over_line = None QApplication.restoreOverrideCursor() self.repaint()
[ "def", "mouseMoveEvent", "(", "self", ",", "event", ")", ":", "super", "(", "FoldingPanel", ",", "self", ")", ".", "mouseMoveEvent", "(", "event", ")", "th", "=", "TextHelper", "(", "self", ".", "editor", ")", "line", "=", "th", ".", "line_nbr_from_position", "(", "event", ".", "pos", "(", ")", ".", "y", "(", ")", ")", "if", "line", ">=", "0", ":", "block", "=", "FoldScope", ".", "find_parent_scope", "(", "self", ".", "editor", ".", "document", "(", ")", ".", "findBlockByNumber", "(", "line", "-", "1", ")", ")", "if", "TextBlockHelper", ".", "is_fold_trigger", "(", "block", ")", ":", "if", "self", ".", "_mouse_over_line", "is", "None", ":", "# mouse enter fold scope", "QApplication", ".", "setOverrideCursor", "(", "QCursor", "(", "Qt", ".", "PointingHandCursor", ")", ")", "if", "self", ".", "_mouse_over_line", "!=", "block", ".", "blockNumber", "(", ")", "and", "self", ".", "_mouse_over_line", "is", "not", "None", ":", "# fold scope changed, a previous block was highlighter so", "# we quickly update our highlighting", "self", ".", "_mouse_over_line", "=", "block", ".", "blockNumber", "(", ")", "self", ".", "_highlight_block", "(", "block", ")", "else", ":", "# same fold scope, request highlight", "self", ".", "_mouse_over_line", "=", "block", ".", "blockNumber", "(", ")", "self", ".", "_highlight_runner", ".", "request_job", "(", "self", ".", "_highlight_block", ",", "block", ")", "self", ".", "_highight_block", "=", "block", "else", ":", "# no fold scope to highlight, cancel any pending requests", "self", ".", "_highlight_runner", ".", "cancel_requests", "(", ")", "self", ".", "_mouse_over_line", "=", "None", "QApplication", ".", "restoreOverrideCursor", "(", ")", "self", ".", "repaint", "(", ")" ]
Detect mouser over indicator and highlight the current scope in the editor (up and down decoration arround the foldable text when the mouse is over an indicator). :param event: event
[ "Detect", "mouser", "over", "indicator", "and", "highlight", "the", "current", "scope", "in", "the", "editor", "(", "up", "and", "down", "decoration", "arround", "the", "foldable", "text", "when", "the", "mouse", "is", "over", "an", "indicator", ")", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/codefolding.py#L394-L430
train
spyder-ide/spyder
spyder/plugins/editor/panels/codefolding.py
FoldingPanel.mousePressEvent
def mousePressEvent(self, event): """Folds/unfolds the pressed indicator if any.""" if self._mouse_over_line is not None: block = self.editor.document().findBlockByNumber( self._mouse_over_line) self.toggle_fold_trigger(block)
python
def mousePressEvent(self, event): """Folds/unfolds the pressed indicator if any.""" if self._mouse_over_line is not None: block = self.editor.document().findBlockByNumber( self._mouse_over_line) self.toggle_fold_trigger(block)
[ "def", "mousePressEvent", "(", "self", ",", "event", ")", ":", "if", "self", ".", "_mouse_over_line", "is", "not", "None", ":", "block", "=", "self", ".", "editor", ".", "document", "(", ")", ".", "findBlockByNumber", "(", "self", ".", "_mouse_over_line", ")", "self", ".", "toggle_fold_trigger", "(", "block", ")" ]
Folds/unfolds the pressed indicator if any.
[ "Folds", "/", "unfolds", "the", "pressed", "indicator", "if", "any", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/codefolding.py#L487-L492
train
spyder-ide/spyder
spyder/plugins/editor/panels/codefolding.py
FoldingPanel._show_previous_blank_lines
def _show_previous_blank_lines(block): """ Show the block previous blank lines """ # set previous blank lines visibles pblock = block.previous() while (pblock.text().strip() == '' and pblock.blockNumber() >= 0): pblock.setVisible(True) pblock = pblock.previous()
python
def _show_previous_blank_lines(block): """ Show the block previous blank lines """ # set previous blank lines visibles pblock = block.previous() while (pblock.text().strip() == '' and pblock.blockNumber() >= 0): pblock.setVisible(True) pblock = pblock.previous()
[ "def", "_show_previous_blank_lines", "(", "block", ")", ":", "# set previous blank lines visibles", "pblock", "=", "block", ".", "previous", "(", ")", "while", "(", "pblock", ".", "text", "(", ")", ".", "strip", "(", ")", "==", "''", "and", "pblock", ".", "blockNumber", "(", ")", ">=", "0", ")", ":", "pblock", ".", "setVisible", "(", "True", ")", "pblock", "=", "pblock", ".", "previous", "(", ")" ]
Show the block previous blank lines
[ "Show", "the", "block", "previous", "blank", "lines" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/codefolding.py#L552-L561
train
spyder-ide/spyder
spyder/plugins/editor/panels/codefolding.py
FoldingPanel.refresh_decorations
def refresh_decorations(self, force=False): """ Refresh decorations colors. This function is called by the syntax highlighter when the style changed so that we may update our decorations colors according to the new style. """ cursor = self.editor.textCursor() if (self._prev_cursor is None or force or self._prev_cursor.blockNumber() != cursor.blockNumber()): for deco in self._block_decos: self.editor.decorations.remove(deco) for deco in self._block_decos: deco.set_outline(drift_color( self._get_scope_highlight_color(), 110)) deco.set_background(self._get_scope_highlight_color()) self.editor.decorations.add(deco) self._prev_cursor = cursor
python
def refresh_decorations(self, force=False): """ Refresh decorations colors. This function is called by the syntax highlighter when the style changed so that we may update our decorations colors according to the new style. """ cursor = self.editor.textCursor() if (self._prev_cursor is None or force or self._prev_cursor.blockNumber() != cursor.blockNumber()): for deco in self._block_decos: self.editor.decorations.remove(deco) for deco in self._block_decos: deco.set_outline(drift_color( self._get_scope_highlight_color(), 110)) deco.set_background(self._get_scope_highlight_color()) self.editor.decorations.add(deco) self._prev_cursor = cursor
[ "def", "refresh_decorations", "(", "self", ",", "force", "=", "False", ")", ":", "cursor", "=", "self", ".", "editor", ".", "textCursor", "(", ")", "if", "(", "self", ".", "_prev_cursor", "is", "None", "or", "force", "or", "self", ".", "_prev_cursor", ".", "blockNumber", "(", ")", "!=", "cursor", ".", "blockNumber", "(", ")", ")", ":", "for", "deco", "in", "self", ".", "_block_decos", ":", "self", ".", "editor", ".", "decorations", ".", "remove", "(", "deco", ")", "for", "deco", "in", "self", ".", "_block_decos", ":", "deco", ".", "set_outline", "(", "drift_color", "(", "self", ".", "_get_scope_highlight_color", "(", ")", ",", "110", ")", ")", "deco", ".", "set_background", "(", "self", ".", "_get_scope_highlight_color", "(", ")", ")", "self", ".", "editor", ".", "decorations", ".", "add", "(", "deco", ")", "self", ".", "_prev_cursor", "=", "cursor" ]
Refresh decorations colors. This function is called by the syntax highlighter when the style changed so that we may update our decorations colors according to the new style.
[ "Refresh", "decorations", "colors", ".", "This", "function", "is", "called", "by", "the", "syntax", "highlighter", "when", "the", "style", "changed", "so", "that", "we", "may", "update", "our", "decorations", "colors", "according", "to", "the", "new", "style", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/codefolding.py#L563-L579
train
spyder-ide/spyder
spyder/plugins/editor/panels/codefolding.py
FoldingPanel._refresh_editor_and_scrollbars
def _refresh_editor_and_scrollbars(self): """ Refrehes editor content and scollbars. We generate a fake resize event to refresh scroll bar. We have the same problem as described here: http://www.qtcentre.org/threads/44803 and we apply the same solution (don't worry, there is no visual effect, the editor does not grow up at all, even with a value = 500) """ TextHelper(self.editor).mark_whole_doc_dirty() self.editor.repaint() s = self.editor.size() s.setWidth(s.width() + 1) self.editor.resizeEvent(QResizeEvent(self.editor.size(), s))
python
def _refresh_editor_and_scrollbars(self): """ Refrehes editor content and scollbars. We generate a fake resize event to refresh scroll bar. We have the same problem as described here: http://www.qtcentre.org/threads/44803 and we apply the same solution (don't worry, there is no visual effect, the editor does not grow up at all, even with a value = 500) """ TextHelper(self.editor).mark_whole_doc_dirty() self.editor.repaint() s = self.editor.size() s.setWidth(s.width() + 1) self.editor.resizeEvent(QResizeEvent(self.editor.size(), s))
[ "def", "_refresh_editor_and_scrollbars", "(", "self", ")", ":", "TextHelper", "(", "self", ".", "editor", ")", ".", "mark_whole_doc_dirty", "(", ")", "self", ".", "editor", ".", "repaint", "(", ")", "s", "=", "self", ".", "editor", ".", "size", "(", ")", "s", ".", "setWidth", "(", "s", ".", "width", "(", ")", "+", "1", ")", "self", ".", "editor", ".", "resizeEvent", "(", "QResizeEvent", "(", "self", ".", "editor", ".", "size", "(", ")", ",", "s", ")", ")" ]
Refrehes editor content and scollbars. We generate a fake resize event to refresh scroll bar. We have the same problem as described here: http://www.qtcentre.org/threads/44803 and we apply the same solution (don't worry, there is no visual effect, the editor does not grow up at all, even with a value = 500)
[ "Refrehes", "editor", "content", "and", "scollbars", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/codefolding.py#L581-L596
train
spyder-ide/spyder
spyder/plugins/editor/panels/codefolding.py
FoldingPanel.collapse_all
def collapse_all(self): """ Collapses all triggers and makes all blocks with fold level > 0 invisible. """ self._clear_block_deco() block = self.editor.document().firstBlock() last = self.editor.document().lastBlock() while block.isValid(): lvl = TextBlockHelper.get_fold_lvl(block) trigger = TextBlockHelper.is_fold_trigger(block) if trigger: if lvl == 0: self._show_previous_blank_lines(block) TextBlockHelper.set_collapsed(block, True) block.setVisible(lvl == 0) if block == last and block.text().strip() == '': block.setVisible(True) self._show_previous_blank_lines(block) block = block.next() self._refresh_editor_and_scrollbars() tc = self.editor.textCursor() tc.movePosition(tc.Start) self.editor.setTextCursor(tc) self.collapse_all_triggered.emit()
python
def collapse_all(self): """ Collapses all triggers and makes all blocks with fold level > 0 invisible. """ self._clear_block_deco() block = self.editor.document().firstBlock() last = self.editor.document().lastBlock() while block.isValid(): lvl = TextBlockHelper.get_fold_lvl(block) trigger = TextBlockHelper.is_fold_trigger(block) if trigger: if lvl == 0: self._show_previous_blank_lines(block) TextBlockHelper.set_collapsed(block, True) block.setVisible(lvl == 0) if block == last and block.text().strip() == '': block.setVisible(True) self._show_previous_blank_lines(block) block = block.next() self._refresh_editor_and_scrollbars() tc = self.editor.textCursor() tc.movePosition(tc.Start) self.editor.setTextCursor(tc) self.collapse_all_triggered.emit()
[ "def", "collapse_all", "(", "self", ")", ":", "self", ".", "_clear_block_deco", "(", ")", "block", "=", "self", ".", "editor", ".", "document", "(", ")", ".", "firstBlock", "(", ")", "last", "=", "self", ".", "editor", ".", "document", "(", ")", ".", "lastBlock", "(", ")", "while", "block", ".", "isValid", "(", ")", ":", "lvl", "=", "TextBlockHelper", ".", "get_fold_lvl", "(", "block", ")", "trigger", "=", "TextBlockHelper", ".", "is_fold_trigger", "(", "block", ")", "if", "trigger", ":", "if", "lvl", "==", "0", ":", "self", ".", "_show_previous_blank_lines", "(", "block", ")", "TextBlockHelper", ".", "set_collapsed", "(", "block", ",", "True", ")", "block", ".", "setVisible", "(", "lvl", "==", "0", ")", "if", "block", "==", "last", "and", "block", ".", "text", "(", ")", ".", "strip", "(", ")", "==", "''", ":", "block", ".", "setVisible", "(", "True", ")", "self", ".", "_show_previous_blank_lines", "(", "block", ")", "block", "=", "block", ".", "next", "(", ")", "self", ".", "_refresh_editor_and_scrollbars", "(", ")", "tc", "=", "self", ".", "editor", ".", "textCursor", "(", ")", "tc", ".", "movePosition", "(", "tc", ".", "Start", ")", "self", ".", "editor", ".", "setTextCursor", "(", "tc", ")", "self", ".", "collapse_all_triggered", ".", "emit", "(", ")" ]
Collapses all triggers and makes all blocks with fold level > 0 invisible.
[ "Collapses", "all", "triggers", "and", "makes", "all", "blocks", "with", "fold", "level", ">", "0", "invisible", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/codefolding.py#L598-L622
train
spyder-ide/spyder
spyder/plugins/editor/panels/codefolding.py
FoldingPanel._clear_block_deco
def _clear_block_deco(self): """Clear the folded block decorations.""" for deco in self._block_decos: self.editor.decorations.remove(deco) self._block_decos[:] = []
python
def _clear_block_deco(self): """Clear the folded block decorations.""" for deco in self._block_decos: self.editor.decorations.remove(deco) self._block_decos[:] = []
[ "def", "_clear_block_deco", "(", "self", ")", ":", "for", "deco", "in", "self", ".", "_block_decos", ":", "self", ".", "editor", ".", "decorations", ".", "remove", "(", "deco", ")", "self", ".", "_block_decos", "[", ":", "]", "=", "[", "]" ]
Clear the folded block decorations.
[ "Clear", "the", "folded", "block", "decorations", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/codefolding.py#L624-L628
train
spyder-ide/spyder
spyder/plugins/editor/panels/codefolding.py
FoldingPanel.expand_all
def expand_all(self): """Expands all fold triggers.""" block = self.editor.document().firstBlock() while block.isValid(): TextBlockHelper.set_collapsed(block, False) block.setVisible(True) block = block.next() self._clear_block_deco() self._refresh_editor_and_scrollbars() self.expand_all_triggered.emit()
python
def expand_all(self): """Expands all fold triggers.""" block = self.editor.document().firstBlock() while block.isValid(): TextBlockHelper.set_collapsed(block, False) block.setVisible(True) block = block.next() self._clear_block_deco() self._refresh_editor_and_scrollbars() self.expand_all_triggered.emit()
[ "def", "expand_all", "(", "self", ")", ":", "block", "=", "self", ".", "editor", ".", "document", "(", ")", ".", "firstBlock", "(", ")", "while", "block", ".", "isValid", "(", ")", ":", "TextBlockHelper", ".", "set_collapsed", "(", "block", ",", "False", ")", "block", ".", "setVisible", "(", "True", ")", "block", "=", "block", ".", "next", "(", ")", "self", ".", "_clear_block_deco", "(", ")", "self", ".", "_refresh_editor_and_scrollbars", "(", ")", "self", ".", "expand_all_triggered", ".", "emit", "(", ")" ]
Expands all fold triggers.
[ "Expands", "all", "fold", "triggers", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/codefolding.py#L630-L639
train
spyder-ide/spyder
spyder/plugins/editor/panels/codefolding.py
FoldingPanel._on_action_toggle
def _on_action_toggle(self): """Toggle the current fold trigger.""" block = FoldScope.find_parent_scope(self.editor.textCursor().block()) self.toggle_fold_trigger(block)
python
def _on_action_toggle(self): """Toggle the current fold trigger.""" block = FoldScope.find_parent_scope(self.editor.textCursor().block()) self.toggle_fold_trigger(block)
[ "def", "_on_action_toggle", "(", "self", ")", ":", "block", "=", "FoldScope", ".", "find_parent_scope", "(", "self", ".", "editor", ".", "textCursor", "(", ")", ".", "block", "(", ")", ")", "self", ".", "toggle_fold_trigger", "(", "block", ")" ]
Toggle the current fold trigger.
[ "Toggle", "the", "current", "fold", "trigger", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/codefolding.py#L641-L644
train
spyder-ide/spyder
spyder/plugins/editor/panels/codefolding.py
FoldingPanel._highlight_caret_scope
def _highlight_caret_scope(self): """ Highlight the scope of the current caret position. This get called only if :attr:` spyder.widgets.panels.FoldingPanel.highlight_care_scope` is True. """ cursor = self.editor.textCursor() block_nbr = cursor.blockNumber() if self._block_nbr != block_nbr: block = FoldScope.find_parent_scope( self.editor.textCursor().block()) try: s = FoldScope(block) except ValueError: self._clear_scope_decos() else: self._mouse_over_line = block.blockNumber() if TextBlockHelper.is_fold_trigger(block): self._highlight_block(block) self._block_nbr = block_nbr
python
def _highlight_caret_scope(self): """ Highlight the scope of the current caret position. This get called only if :attr:` spyder.widgets.panels.FoldingPanel.highlight_care_scope` is True. """ cursor = self.editor.textCursor() block_nbr = cursor.blockNumber() if self._block_nbr != block_nbr: block = FoldScope.find_parent_scope( self.editor.textCursor().block()) try: s = FoldScope(block) except ValueError: self._clear_scope_decos() else: self._mouse_over_line = block.blockNumber() if TextBlockHelper.is_fold_trigger(block): self._highlight_block(block) self._block_nbr = block_nbr
[ "def", "_highlight_caret_scope", "(", "self", ")", ":", "cursor", "=", "self", ".", "editor", ".", "textCursor", "(", ")", "block_nbr", "=", "cursor", ".", "blockNumber", "(", ")", "if", "self", ".", "_block_nbr", "!=", "block_nbr", ":", "block", "=", "FoldScope", ".", "find_parent_scope", "(", "self", ".", "editor", ".", "textCursor", "(", ")", ".", "block", "(", ")", ")", "try", ":", "s", "=", "FoldScope", "(", "block", ")", "except", "ValueError", ":", "self", ".", "_clear_scope_decos", "(", ")", "else", ":", "self", ".", "_mouse_over_line", "=", "block", ".", "blockNumber", "(", ")", "if", "TextBlockHelper", ".", "is_fold_trigger", "(", "block", ")", ":", "self", ".", "_highlight_block", "(", "block", ")", "self", ".", "_block_nbr", "=", "block_nbr" ]
Highlight the scope of the current caret position. This get called only if :attr:` spyder.widgets.panels.FoldingPanel.highlight_care_scope` is True.
[ "Highlight", "the", "scope", "of", "the", "current", "caret", "position", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/codefolding.py#L657-L677
train
spyder-ide/spyder
spyder/plugins/history/widgets.py
History.set_menu_actions
def set_menu_actions(self, menu_actions): """Add options to corner menu.""" if self.menu_actions is not None: add_actions(self.menu, self.menu_actions)
python
def set_menu_actions(self, menu_actions): """Add options to corner menu.""" if self.menu_actions is not None: add_actions(self.menu, self.menu_actions)
[ "def", "set_menu_actions", "(", "self", ",", "menu_actions", ")", ":", "if", "self", ".", "menu_actions", "is", "not", "None", ":", "add_actions", "(", "self", ".", "menu", ",", "self", ".", "menu_actions", ")" ]
Add options to corner menu.
[ "Add", "options", "to", "corner", "menu", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/history/widgets.py#L76-L79
train
spyder-ide/spyder
spyder/plugins/history/widgets.py
History.refresh
def refresh(self): """Refresh tabwidget.""" if self.tabwidget.count(): editor = self.tabwidget.currentWidget() else: editor = None self.find_widget.set_editor(editor)
python
def refresh(self): """Refresh tabwidget.""" if self.tabwidget.count(): editor = self.tabwidget.currentWidget() else: editor = None self.find_widget.set_editor(editor)
[ "def", "refresh", "(", "self", ")", ":", "if", "self", ".", "tabwidget", ".", "count", "(", ")", ":", "editor", "=", "self", ".", "tabwidget", ".", "currentWidget", "(", ")", "else", ":", "editor", "=", "None", "self", ".", "find_widget", ".", "set_editor", "(", "editor", ")" ]
Refresh tabwidget.
[ "Refresh", "tabwidget", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/history/widgets.py#L81-L87
train
spyder-ide/spyder
spyder/plugins/history/widgets.py
History.move_tab
def move_tab(self, index_from, index_to): """ Move tab. (tabs themselves have already been moved by the history.tabwidget) """ filename = self.filenames.pop(index_from) editor = self.editors.pop(index_from) self.filenames.insert(index_to, filename) self.editors.insert(index_to, editor)
python
def move_tab(self, index_from, index_to): """ Move tab. (tabs themselves have already been moved by the history.tabwidget) """ filename = self.filenames.pop(index_from) editor = self.editors.pop(index_from) self.filenames.insert(index_to, filename) self.editors.insert(index_to, editor)
[ "def", "move_tab", "(", "self", ",", "index_from", ",", "index_to", ")", ":", "filename", "=", "self", ".", "filenames", ".", "pop", "(", "index_from", ")", "editor", "=", "self", ".", "editors", ".", "pop", "(", "index_from", ")", "self", ".", "filenames", ".", "insert", "(", "index_to", ",", "filename", ")", "self", ".", "editors", ".", "insert", "(", "index_to", ",", "editor", ")" ]
Move tab. (tabs themselves have already been moved by the history.tabwidget)
[ "Move", "tab", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/history/widgets.py#L89-L99
train
spyder-ide/spyder
spyder/plugins/history/widgets.py
History.add_history
def add_history(self, filename, color_scheme, font, wrap): """ Add new history tab. Args: filename (str): file to be loaded in a new tab. """ filename = encoding.to_unicode_from_fs(filename) if filename in self.filenames: return editor = codeeditor.CodeEditor(self) if osp.splitext(filename)[1] == '.py': language = 'py' else: language = 'bat' editor.setup_editor(linenumbers=False, language=language, scrollflagarea=False, show_class_func_dropdown=False) editor.focus_changed.connect(lambda: self.focus_changed.emit()) editor.setReadOnly(True) editor.set_font(font, color_scheme) editor.toggle_wrap_mode(wrap) text, _ = encoding.read(filename) editor.set_text(text) editor.set_cursor_position('eof') self.editors.append(editor) self.filenames.append(filename) index = self.tabwidget.addTab(editor, osp.basename(filename)) self.find_widget.set_editor(editor) self.tabwidget.setTabToolTip(index, filename) self.tabwidget.setCurrentIndex(index)
python
def add_history(self, filename, color_scheme, font, wrap): """ Add new history tab. Args: filename (str): file to be loaded in a new tab. """ filename = encoding.to_unicode_from_fs(filename) if filename in self.filenames: return editor = codeeditor.CodeEditor(self) if osp.splitext(filename)[1] == '.py': language = 'py' else: language = 'bat' editor.setup_editor(linenumbers=False, language=language, scrollflagarea=False, show_class_func_dropdown=False) editor.focus_changed.connect(lambda: self.focus_changed.emit()) editor.setReadOnly(True) editor.set_font(font, color_scheme) editor.toggle_wrap_mode(wrap) text, _ = encoding.read(filename) editor.set_text(text) editor.set_cursor_position('eof') self.editors.append(editor) self.filenames.append(filename) index = self.tabwidget.addTab(editor, osp.basename(filename)) self.find_widget.set_editor(editor) self.tabwidget.setTabToolTip(index, filename) self.tabwidget.setCurrentIndex(index)
[ "def", "add_history", "(", "self", ",", "filename", ",", "color_scheme", ",", "font", ",", "wrap", ")", ":", "filename", "=", "encoding", ".", "to_unicode_from_fs", "(", "filename", ")", "if", "filename", "in", "self", ".", "filenames", ":", "return", "editor", "=", "codeeditor", ".", "CodeEditor", "(", "self", ")", "if", "osp", ".", "splitext", "(", "filename", ")", "[", "1", "]", "==", "'.py'", ":", "language", "=", "'py'", "else", ":", "language", "=", "'bat'", "editor", ".", "setup_editor", "(", "linenumbers", "=", "False", ",", "language", "=", "language", ",", "scrollflagarea", "=", "False", ",", "show_class_func_dropdown", "=", "False", ")", "editor", ".", "focus_changed", ".", "connect", "(", "lambda", ":", "self", ".", "focus_changed", ".", "emit", "(", ")", ")", "editor", ".", "setReadOnly", "(", "True", ")", "editor", ".", "set_font", "(", "font", ",", "color_scheme", ")", "editor", ".", "toggle_wrap_mode", "(", "wrap", ")", "text", ",", "_", "=", "encoding", ".", "read", "(", "filename", ")", "editor", ".", "set_text", "(", "text", ")", "editor", ".", "set_cursor_position", "(", "'eof'", ")", "self", ".", "editors", ".", "append", "(", "editor", ")", "self", ".", "filenames", ".", "append", "(", "filename", ")", "index", "=", "self", ".", "tabwidget", ".", "addTab", "(", "editor", ",", "osp", ".", "basename", "(", "filename", ")", ")", "self", ".", "find_widget", ".", "set_editor", "(", "editor", ")", "self", ".", "tabwidget", ".", "setTabToolTip", "(", "index", ",", "filename", ")", "self", ".", "tabwidget", ".", "setCurrentIndex", "(", "index", ")" ]
Add new history tab. Args: filename (str): file to be loaded in a new tab.
[ "Add", "new", "history", "tab", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/history/widgets.py#L101-L135
train
spyder-ide/spyder
spyder/plugins/history/widgets.py
History.append_to_history
def append_to_history(self, filename, command, go_to_eof): """ Append an entry to history filename. Args: filename (str): file to be updated in a new tab. command (str): line to be added. go_to_eof (bool): scroll to the end of file. """ if not is_text_string(filename): # filename is a QString filename = to_text_string(filename.toUtf8(), 'utf-8') command = to_text_string(command) index = self.filenames.index(filename) self.editors[index].append(command) if go_to_eof: self.editors[index].set_cursor_position('eof') self.tabwidget.setCurrentIndex(index)
python
def append_to_history(self, filename, command, go_to_eof): """ Append an entry to history filename. Args: filename (str): file to be updated in a new tab. command (str): line to be added. go_to_eof (bool): scroll to the end of file. """ if not is_text_string(filename): # filename is a QString filename = to_text_string(filename.toUtf8(), 'utf-8') command = to_text_string(command) index = self.filenames.index(filename) self.editors[index].append(command) if go_to_eof: self.editors[index].set_cursor_position('eof') self.tabwidget.setCurrentIndex(index)
[ "def", "append_to_history", "(", "self", ",", "filename", ",", "command", ",", "go_to_eof", ")", ":", "if", "not", "is_text_string", "(", "filename", ")", ":", "# filename is a QString", "filename", "=", "to_text_string", "(", "filename", ".", "toUtf8", "(", ")", ",", "'utf-8'", ")", "command", "=", "to_text_string", "(", "command", ")", "index", "=", "self", ".", "filenames", ".", "index", "(", "filename", ")", "self", ".", "editors", "[", "index", "]", ".", "append", "(", "command", ")", "if", "go_to_eof", ":", "self", ".", "editors", "[", "index", "]", ".", "set_cursor_position", "(", "'eof'", ")", "self", ".", "tabwidget", ".", "setCurrentIndex", "(", "index", ")" ]
Append an entry to history filename. Args: filename (str): file to be updated in a new tab. command (str): line to be added. go_to_eof (bool): scroll to the end of file.
[ "Append", "an", "entry", "to", "history", "filename", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/history/widgets.py#L137-L153
train
spyder-ide/spyder
spyder/plugins/editor/utils/lsp.py
request
def request(req=None, method=None, requires_response=True): """Call function req and then emit its results to the LSP server.""" if req is None: return functools.partial(request, method=method, requires_response=requires_response) @functools.wraps(req) def wrapper(self, *args, **kwargs): if self.lsp_ready: params = req(self, *args, **kwargs) if params is not None: self.emit_request(method, params, requires_response) return wrapper
python
def request(req=None, method=None, requires_response=True): """Call function req and then emit its results to the LSP server.""" if req is None: return functools.partial(request, method=method, requires_response=requires_response) @functools.wraps(req) def wrapper(self, *args, **kwargs): if self.lsp_ready: params = req(self, *args, **kwargs) if params is not None: self.emit_request(method, params, requires_response) return wrapper
[ "def", "request", "(", "req", "=", "None", ",", "method", "=", "None", ",", "requires_response", "=", "True", ")", ":", "if", "req", "is", "None", ":", "return", "functools", ".", "partial", "(", "request", ",", "method", "=", "method", ",", "requires_response", "=", "requires_response", ")", "@", "functools", ".", "wraps", "(", "req", ")", "def", "wrapper", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "lsp_ready", ":", "params", "=", "req", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", "if", "params", "is", "not", "None", ":", "self", ".", "emit_request", "(", "method", ",", "params", ",", "requires_response", ")", "return", "wrapper" ]
Call function req and then emit its results to the LSP server.
[ "Call", "function", "req", "and", "then", "emit", "its", "results", "to", "the", "LSP", "server", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/utils/lsp.py#L12-L24
train
spyder-ide/spyder
spyder/plugins/editor/utils/lsp.py
class_register
def class_register(cls): """Class decorator that allows to map LSP method names to class methods.""" cls.handler_registry = {} for method_name in dir(cls): method = getattr(cls, method_name) if hasattr(method, '_handle'): cls.handler_registry.update({method._handle: method_name}) return cls
python
def class_register(cls): """Class decorator that allows to map LSP method names to class methods.""" cls.handler_registry = {} for method_name in dir(cls): method = getattr(cls, method_name) if hasattr(method, '_handle'): cls.handler_registry.update({method._handle: method_name}) return cls
[ "def", "class_register", "(", "cls", ")", ":", "cls", ".", "handler_registry", "=", "{", "}", "for", "method_name", "in", "dir", "(", "cls", ")", ":", "method", "=", "getattr", "(", "cls", ",", "method_name", ")", "if", "hasattr", "(", "method", ",", "'_handle'", ")", ":", "cls", ".", "handler_registry", ".", "update", "(", "{", "method", ".", "_handle", ":", "method_name", "}", ")", "return", "cls" ]
Class decorator that allows to map LSP method names to class methods.
[ "Class", "decorator", "that", "allows", "to", "map", "LSP", "method", "names", "to", "class", "methods", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/utils/lsp.py#L27-L34
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.update_font
def update_font(self): """Update font from Preferences""" font = self.get_plugin_font() for client in self.clients: client.set_font(font)
python
def update_font(self): """Update font from Preferences""" font = self.get_plugin_font() for client in self.clients: client.set_font(font)
[ "def", "update_font", "(", "self", ")", ":", "font", "=", "self", ".", "get_plugin_font", "(", ")", "for", "client", "in", "self", ".", "clients", ":", "client", ".", "set_font", "(", "font", ")" ]
Update font from Preferences
[ "Update", "font", "from", "Preferences" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L185-L189
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.apply_plugin_settings
def apply_plugin_settings(self, options): """Apply configuration file's plugin settings""" font_n = 'plugin_font' font_o = self.get_plugin_font() help_n = 'connect_to_oi' help_o = CONF.get('help', 'connect/ipython_console') color_scheme_n = 'color_scheme_name' color_scheme_o = CONF.get('appearance', 'selected') show_time_n = 'show_elapsed_time' show_time_o = self.get_option(show_time_n) reset_namespace_n = 'show_reset_namespace_warning' reset_namespace_o = self.get_option(reset_namespace_n) ask_before_restart_n = 'ask_before_restart' ask_before_restart_o = self.get_option(ask_before_restart_n) for client in self.clients: control = client.get_control() if font_n in options: client.set_font(font_o) if help_n in options and control is not None: control.set_help_enabled(help_o) if color_scheme_n in options: client.set_color_scheme(color_scheme_o) if show_time_n in options: client.show_time_action.setChecked(show_time_o) client.set_elapsed_time_visible(show_time_o) if reset_namespace_n in options: client.reset_warning = reset_namespace_o if ask_before_restart_n in options: client.ask_before_restart = ask_before_restart_o
python
def apply_plugin_settings(self, options): """Apply configuration file's plugin settings""" font_n = 'plugin_font' font_o = self.get_plugin_font() help_n = 'connect_to_oi' help_o = CONF.get('help', 'connect/ipython_console') color_scheme_n = 'color_scheme_name' color_scheme_o = CONF.get('appearance', 'selected') show_time_n = 'show_elapsed_time' show_time_o = self.get_option(show_time_n) reset_namespace_n = 'show_reset_namespace_warning' reset_namespace_o = self.get_option(reset_namespace_n) ask_before_restart_n = 'ask_before_restart' ask_before_restart_o = self.get_option(ask_before_restart_n) for client in self.clients: control = client.get_control() if font_n in options: client.set_font(font_o) if help_n in options and control is not None: control.set_help_enabled(help_o) if color_scheme_n in options: client.set_color_scheme(color_scheme_o) if show_time_n in options: client.show_time_action.setChecked(show_time_o) client.set_elapsed_time_visible(show_time_o) if reset_namespace_n in options: client.reset_warning = reset_namespace_o if ask_before_restart_n in options: client.ask_before_restart = ask_before_restart_o
[ "def", "apply_plugin_settings", "(", "self", ",", "options", ")", ":", "font_n", "=", "'plugin_font'", "font_o", "=", "self", ".", "get_plugin_font", "(", ")", "help_n", "=", "'connect_to_oi'", "help_o", "=", "CONF", ".", "get", "(", "'help'", ",", "'connect/ipython_console'", ")", "color_scheme_n", "=", "'color_scheme_name'", "color_scheme_o", "=", "CONF", ".", "get", "(", "'appearance'", ",", "'selected'", ")", "show_time_n", "=", "'show_elapsed_time'", "show_time_o", "=", "self", ".", "get_option", "(", "show_time_n", ")", "reset_namespace_n", "=", "'show_reset_namespace_warning'", "reset_namespace_o", "=", "self", ".", "get_option", "(", "reset_namespace_n", ")", "ask_before_restart_n", "=", "'ask_before_restart'", "ask_before_restart_o", "=", "self", ".", "get_option", "(", "ask_before_restart_n", ")", "for", "client", "in", "self", ".", "clients", ":", "control", "=", "client", ".", "get_control", "(", ")", "if", "font_n", "in", "options", ":", "client", ".", "set_font", "(", "font_o", ")", "if", "help_n", "in", "options", "and", "control", "is", "not", "None", ":", "control", ".", "set_help_enabled", "(", "help_o", ")", "if", "color_scheme_n", "in", "options", ":", "client", ".", "set_color_scheme", "(", "color_scheme_o", ")", "if", "show_time_n", "in", "options", ":", "client", ".", "show_time_action", ".", "setChecked", "(", "show_time_o", ")", "client", ".", "set_elapsed_time_visible", "(", "show_time_o", ")", "if", "reset_namespace_n", "in", "options", ":", "client", ".", "reset_warning", "=", "reset_namespace_o", "if", "ask_before_restart_n", "in", "options", ":", "client", ".", "ask_before_restart", "=", "ask_before_restart_o" ]
Apply configuration file's plugin settings
[ "Apply", "configuration", "file", "s", "plugin", "settings" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L191-L219
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.toggle_view
def toggle_view(self, checked): """Toggle view""" if checked: self.dockwidget.show() self.dockwidget.raise_() # Start a client in case there are none shown if not self.clients: if self.main.is_setting_up: self.create_new_client(give_focus=False) else: self.create_new_client(give_focus=True) else: self.dockwidget.hide()
python
def toggle_view(self, checked): """Toggle view""" if checked: self.dockwidget.show() self.dockwidget.raise_() # Start a client in case there are none shown if not self.clients: if self.main.is_setting_up: self.create_new_client(give_focus=False) else: self.create_new_client(give_focus=True) else: self.dockwidget.hide()
[ "def", "toggle_view", "(", "self", ",", "checked", ")", ":", "if", "checked", ":", "self", ".", "dockwidget", ".", "show", "(", ")", "self", ".", "dockwidget", ".", "raise_", "(", ")", "# Start a client in case there are none shown\r", "if", "not", "self", ".", "clients", ":", "if", "self", ".", "main", ".", "is_setting_up", ":", "self", ".", "create_new_client", "(", "give_focus", "=", "False", ")", "else", ":", "self", ".", "create_new_client", "(", "give_focus", "=", "True", ")", "else", ":", "self", ".", "dockwidget", ".", "hide", "(", ")" ]
Toggle view
[ "Toggle", "view" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L221-L233
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.closing_plugin
def closing_plugin(self, cancelable=False): """Perform actions before parent main window is closed""" self.mainwindow_close = True for client in self.clients: client.shutdown() client.remove_stderr_file() client.dialog_manager.close_all() client.close() return True
python
def closing_plugin(self, cancelable=False): """Perform actions before parent main window is closed""" self.mainwindow_close = True for client in self.clients: client.shutdown() client.remove_stderr_file() client.dialog_manager.close_all() client.close() return True
[ "def", "closing_plugin", "(", "self", ",", "cancelable", "=", "False", ")", ":", "self", ".", "mainwindow_close", "=", "True", "for", "client", "in", "self", ".", "clients", ":", "client", ".", "shutdown", "(", ")", "client", ".", "remove_stderr_file", "(", ")", "client", ".", "dialog_manager", ".", "close_all", "(", ")", "client", ".", "close", "(", ")", "return", "True" ]
Perform actions before parent main window is closed
[ "Perform", "actions", "before", "parent", "main", "window", "is", "closed" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L253-L261
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.refresh_plugin
def refresh_plugin(self): """Refresh tabwidget""" client = None if self.tabwidget.count(): client = self.tabwidget.currentWidget() # Decide what to show for each client if client.info_page != client.blank_page: # Show info_page if it has content client.set_info_page() client.shellwidget.hide() client.layout.addWidget(self.infowidget) self.infowidget.show() else: self.infowidget.hide() client.shellwidget.show() # Give focus to the control widget of the selected tab control = client.get_control() control.setFocus() # Create corner widgets buttons = [[b, -7] for b in client.get_toolbar_buttons()] buttons = sum(buttons, [])[:-1] widgets = [client.create_time_label()] + buttons else: control = None widgets = [] self.find_widget.set_editor(control) self.tabwidget.set_corner_widgets({Qt.TopRightCorner: widgets}) if client: sw = client.shellwidget self.main.variableexplorer.set_shellwidget_from_id(id(sw)) self.main.plots.set_shellwidget_from_id(id(sw)) self.main.help.set_shell(sw) self.update_tabs_text() self.sig_update_plugin_title.emit()
python
def refresh_plugin(self): """Refresh tabwidget""" client = None if self.tabwidget.count(): client = self.tabwidget.currentWidget() # Decide what to show for each client if client.info_page != client.blank_page: # Show info_page if it has content client.set_info_page() client.shellwidget.hide() client.layout.addWidget(self.infowidget) self.infowidget.show() else: self.infowidget.hide() client.shellwidget.show() # Give focus to the control widget of the selected tab control = client.get_control() control.setFocus() # Create corner widgets buttons = [[b, -7] for b in client.get_toolbar_buttons()] buttons = sum(buttons, [])[:-1] widgets = [client.create_time_label()] + buttons else: control = None widgets = [] self.find_widget.set_editor(control) self.tabwidget.set_corner_widgets({Qt.TopRightCorner: widgets}) if client: sw = client.shellwidget self.main.variableexplorer.set_shellwidget_from_id(id(sw)) self.main.plots.set_shellwidget_from_id(id(sw)) self.main.help.set_shell(sw) self.update_tabs_text() self.sig_update_plugin_title.emit()
[ "def", "refresh_plugin", "(", "self", ")", ":", "client", "=", "None", "if", "self", ".", "tabwidget", ".", "count", "(", ")", ":", "client", "=", "self", ".", "tabwidget", ".", "currentWidget", "(", ")", "# Decide what to show for each client\r", "if", "client", ".", "info_page", "!=", "client", ".", "blank_page", ":", "# Show info_page if it has content\r", "client", ".", "set_info_page", "(", ")", "client", ".", "shellwidget", ".", "hide", "(", ")", "client", ".", "layout", ".", "addWidget", "(", "self", ".", "infowidget", ")", "self", ".", "infowidget", ".", "show", "(", ")", "else", ":", "self", ".", "infowidget", ".", "hide", "(", ")", "client", ".", "shellwidget", ".", "show", "(", ")", "# Give focus to the control widget of the selected tab\r", "control", "=", "client", ".", "get_control", "(", ")", "control", ".", "setFocus", "(", ")", "# Create corner widgets\r", "buttons", "=", "[", "[", "b", ",", "-", "7", "]", "for", "b", "in", "client", ".", "get_toolbar_buttons", "(", ")", "]", "buttons", "=", "sum", "(", "buttons", ",", "[", "]", ")", "[", ":", "-", "1", "]", "widgets", "=", "[", "client", ".", "create_time_label", "(", ")", "]", "+", "buttons", "else", ":", "control", "=", "None", "widgets", "=", "[", "]", "self", ".", "find_widget", ".", "set_editor", "(", "control", ")", "self", ".", "tabwidget", ".", "set_corner_widgets", "(", "{", "Qt", ".", "TopRightCorner", ":", "widgets", "}", ")", "if", "client", ":", "sw", "=", "client", ".", "shellwidget", "self", ".", "main", ".", "variableexplorer", ".", "set_shellwidget_from_id", "(", "id", "(", "sw", ")", ")", "self", ".", "main", ".", "plots", ".", "set_shellwidget_from_id", "(", "id", "(", "sw", ")", ")", "self", ".", "main", ".", "help", ".", "set_shell", "(", "sw", ")", "self", ".", "update_tabs_text", "(", ")", "self", ".", "sig_update_plugin_title", ".", "emit", "(", ")" ]
Refresh tabwidget
[ "Refresh", "tabwidget" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L263-L299
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.get_plugin_actions
def get_plugin_actions(self): """Return a list of actions related to plugin.""" create_client_action = create_action( self, _("New console (default settings)"), icon=ima.icon('ipython_console'), triggered=self.create_new_client, context=Qt.WidgetWithChildrenShortcut) self.register_shortcut(create_client_action, context="ipython_console", name="New tab") create_pylab_action = create_action( self, _("New Pylab console (data plotting)"), icon=ima.icon('ipython_console'), triggered=self.create_pylab_client, context=Qt.WidgetWithChildrenShortcut) create_sympy_action = create_action( self, _("New SymPy console (symbolic math)"), icon=ima.icon('ipython_console'), triggered=self.create_sympy_client, context=Qt.WidgetWithChildrenShortcut) create_cython_action = create_action( self, _("New Cython console (Python with " "C extensions)"), icon=ima.icon('ipython_console'), triggered=self.create_cython_client, context=Qt.WidgetWithChildrenShortcut) special_console_action_group = QActionGroup(self) special_console_actions = (create_pylab_action, create_sympy_action, create_cython_action) add_actions(special_console_action_group, special_console_actions) special_console_menu = QMenu(_("New special console"), self) add_actions(special_console_menu, special_console_actions) restart_action = create_action(self, _("Restart kernel"), icon=ima.icon('restart'), triggered=self.restart_kernel, context=Qt.WidgetWithChildrenShortcut) reset_action = create_action(self, _("Remove all variables"), icon=ima.icon('editdelete'), triggered=self.reset_kernel, context=Qt.WidgetWithChildrenShortcut) if self.interrupt_action is None: self.interrupt_action = create_action( self, _("Interrupt kernel"), icon=ima.icon('stop'), triggered=self.interrupt_kernel, context=Qt.WidgetWithChildrenShortcut) self.register_shortcut(restart_action, context="ipython_console", name="Restart kernel") connect_to_kernel_action = create_action(self, _("Connect to an existing kernel"), None, None, _("Open a new IPython console connected to an existing kernel"), triggered=self.create_client_for_kernel) rename_tab_action = create_action(self, _("Rename tab"), icon=ima.icon('rename'), triggered=self.tab_name_editor) # Add the action to the 'Consoles' menu on the main window main_consoles_menu = self.main.consoles_menu_actions main_consoles_menu.insert(0, create_client_action) main_consoles_menu += [special_console_menu, connect_to_kernel_action, MENU_SEPARATOR, self.interrupt_action, restart_action, reset_action] # Plugin actions self.menu_actions = [create_client_action, special_console_menu, connect_to_kernel_action, MENU_SEPARATOR, self.interrupt_action, restart_action, reset_action, rename_tab_action] self.update_execution_state_kernel() # Check for a current client. Since it manages more actions. client = self.get_current_client() if client: return client.get_options_menu() return self.menu_actions
python
def get_plugin_actions(self): """Return a list of actions related to plugin.""" create_client_action = create_action( self, _("New console (default settings)"), icon=ima.icon('ipython_console'), triggered=self.create_new_client, context=Qt.WidgetWithChildrenShortcut) self.register_shortcut(create_client_action, context="ipython_console", name="New tab") create_pylab_action = create_action( self, _("New Pylab console (data plotting)"), icon=ima.icon('ipython_console'), triggered=self.create_pylab_client, context=Qt.WidgetWithChildrenShortcut) create_sympy_action = create_action( self, _("New SymPy console (symbolic math)"), icon=ima.icon('ipython_console'), triggered=self.create_sympy_client, context=Qt.WidgetWithChildrenShortcut) create_cython_action = create_action( self, _("New Cython console (Python with " "C extensions)"), icon=ima.icon('ipython_console'), triggered=self.create_cython_client, context=Qt.WidgetWithChildrenShortcut) special_console_action_group = QActionGroup(self) special_console_actions = (create_pylab_action, create_sympy_action, create_cython_action) add_actions(special_console_action_group, special_console_actions) special_console_menu = QMenu(_("New special console"), self) add_actions(special_console_menu, special_console_actions) restart_action = create_action(self, _("Restart kernel"), icon=ima.icon('restart'), triggered=self.restart_kernel, context=Qt.WidgetWithChildrenShortcut) reset_action = create_action(self, _("Remove all variables"), icon=ima.icon('editdelete'), triggered=self.reset_kernel, context=Qt.WidgetWithChildrenShortcut) if self.interrupt_action is None: self.interrupt_action = create_action( self, _("Interrupt kernel"), icon=ima.icon('stop'), triggered=self.interrupt_kernel, context=Qt.WidgetWithChildrenShortcut) self.register_shortcut(restart_action, context="ipython_console", name="Restart kernel") connect_to_kernel_action = create_action(self, _("Connect to an existing kernel"), None, None, _("Open a new IPython console connected to an existing kernel"), triggered=self.create_client_for_kernel) rename_tab_action = create_action(self, _("Rename tab"), icon=ima.icon('rename'), triggered=self.tab_name_editor) # Add the action to the 'Consoles' menu on the main window main_consoles_menu = self.main.consoles_menu_actions main_consoles_menu.insert(0, create_client_action) main_consoles_menu += [special_console_menu, connect_to_kernel_action, MENU_SEPARATOR, self.interrupt_action, restart_action, reset_action] # Plugin actions self.menu_actions = [create_client_action, special_console_menu, connect_to_kernel_action, MENU_SEPARATOR, self.interrupt_action, restart_action, reset_action, rename_tab_action] self.update_execution_state_kernel() # Check for a current client. Since it manages more actions. client = self.get_current_client() if client: return client.get_options_menu() return self.menu_actions
[ "def", "get_plugin_actions", "(", "self", ")", ":", "create_client_action", "=", "create_action", "(", "self", ",", "_", "(", "\"New console (default settings)\"", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'ipython_console'", ")", ",", "triggered", "=", "self", ".", "create_new_client", ",", "context", "=", "Qt", ".", "WidgetWithChildrenShortcut", ")", "self", ".", "register_shortcut", "(", "create_client_action", ",", "context", "=", "\"ipython_console\"", ",", "name", "=", "\"New tab\"", ")", "create_pylab_action", "=", "create_action", "(", "self", ",", "_", "(", "\"New Pylab console (data plotting)\"", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'ipython_console'", ")", ",", "triggered", "=", "self", ".", "create_pylab_client", ",", "context", "=", "Qt", ".", "WidgetWithChildrenShortcut", ")", "create_sympy_action", "=", "create_action", "(", "self", ",", "_", "(", "\"New SymPy console (symbolic math)\"", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'ipython_console'", ")", ",", "triggered", "=", "self", ".", "create_sympy_client", ",", "context", "=", "Qt", ".", "WidgetWithChildrenShortcut", ")", "create_cython_action", "=", "create_action", "(", "self", ",", "_", "(", "\"New Cython console (Python with \"", "\"C extensions)\"", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'ipython_console'", ")", ",", "triggered", "=", "self", ".", "create_cython_client", ",", "context", "=", "Qt", ".", "WidgetWithChildrenShortcut", ")", "special_console_action_group", "=", "QActionGroup", "(", "self", ")", "special_console_actions", "=", "(", "create_pylab_action", ",", "create_sympy_action", ",", "create_cython_action", ")", "add_actions", "(", "special_console_action_group", ",", "special_console_actions", ")", "special_console_menu", "=", "QMenu", "(", "_", "(", "\"New special console\"", ")", ",", "self", ")", "add_actions", "(", "special_console_menu", ",", "special_console_actions", ")", "restart_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Restart kernel\"", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'restart'", ")", ",", "triggered", "=", "self", ".", "restart_kernel", ",", "context", "=", "Qt", ".", "WidgetWithChildrenShortcut", ")", "reset_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Remove all variables\"", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'editdelete'", ")", ",", "triggered", "=", "self", ".", "reset_kernel", ",", "context", "=", "Qt", ".", "WidgetWithChildrenShortcut", ")", "if", "self", ".", "interrupt_action", "is", "None", ":", "self", ".", "interrupt_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Interrupt kernel\"", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'stop'", ")", ",", "triggered", "=", "self", ".", "interrupt_kernel", ",", "context", "=", "Qt", ".", "WidgetWithChildrenShortcut", ")", "self", ".", "register_shortcut", "(", "restart_action", ",", "context", "=", "\"ipython_console\"", ",", "name", "=", "\"Restart kernel\"", ")", "connect_to_kernel_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Connect to an existing kernel\"", ")", ",", "None", ",", "None", ",", "_", "(", "\"Open a new IPython console connected to an existing kernel\"", ")", ",", "triggered", "=", "self", ".", "create_client_for_kernel", ")", "rename_tab_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Rename tab\"", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'rename'", ")", ",", "triggered", "=", "self", ".", "tab_name_editor", ")", "# Add the action to the 'Consoles' menu on the main window\r", "main_consoles_menu", "=", "self", ".", "main", ".", "consoles_menu_actions", "main_consoles_menu", ".", "insert", "(", "0", ",", "create_client_action", ")", "main_consoles_menu", "+=", "[", "special_console_menu", ",", "connect_to_kernel_action", ",", "MENU_SEPARATOR", ",", "self", ".", "interrupt_action", ",", "restart_action", ",", "reset_action", "]", "# Plugin actions\r", "self", ".", "menu_actions", "=", "[", "create_client_action", ",", "special_console_menu", ",", "connect_to_kernel_action", ",", "MENU_SEPARATOR", ",", "self", ".", "interrupt_action", ",", "restart_action", ",", "reset_action", ",", "rename_tab_action", "]", "self", ".", "update_execution_state_kernel", "(", ")", "# Check for a current client. Since it manages more actions.\r", "client", "=", "self", ".", "get_current_client", "(", ")", "if", "client", ":", "return", "client", ".", "get_options_menu", "(", ")", "return", "self", ".", "menu_actions" ]
Return a list of actions related to plugin.
[ "Return", "a", "list", "of", "actions", "related", "to", "plugin", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L301-L390
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.register_plugin
def register_plugin(self): """Register plugin in Spyder's main window""" self.main.add_dockwidget(self) self.focus_changed.connect(self.main.plugin_focus_changed) self.edit_goto.connect(self.main.editor.load) self.edit_goto[str, int, str, bool].connect( lambda fname, lineno, word, processevents: self.main.editor.load(fname, lineno, word, processevents=processevents)) self.main.editor.breakpoints_saved.connect(self.set_spyder_breakpoints) self.main.editor.run_in_current_ipyclient.connect(self.run_script) self.main.editor.run_cell_in_ipyclient.connect(self.run_cell) self.main.workingdirectory.set_current_console_wd.connect( self.set_current_client_working_directory) self.tabwidget.currentChanged.connect(self.update_working_directory) self._remove_old_stderr_files()
python
def register_plugin(self): """Register plugin in Spyder's main window""" self.main.add_dockwidget(self) self.focus_changed.connect(self.main.plugin_focus_changed) self.edit_goto.connect(self.main.editor.load) self.edit_goto[str, int, str, bool].connect( lambda fname, lineno, word, processevents: self.main.editor.load(fname, lineno, word, processevents=processevents)) self.main.editor.breakpoints_saved.connect(self.set_spyder_breakpoints) self.main.editor.run_in_current_ipyclient.connect(self.run_script) self.main.editor.run_cell_in_ipyclient.connect(self.run_cell) self.main.workingdirectory.set_current_console_wd.connect( self.set_current_client_working_directory) self.tabwidget.currentChanged.connect(self.update_working_directory) self._remove_old_stderr_files()
[ "def", "register_plugin", "(", "self", ")", ":", "self", ".", "main", ".", "add_dockwidget", "(", "self", ")", "self", ".", "focus_changed", ".", "connect", "(", "self", ".", "main", ".", "plugin_focus_changed", ")", "self", ".", "edit_goto", ".", "connect", "(", "self", ".", "main", ".", "editor", ".", "load", ")", "self", ".", "edit_goto", "[", "str", ",", "int", ",", "str", ",", "bool", "]", ".", "connect", "(", "lambda", "fname", ",", "lineno", ",", "word", ",", "processevents", ":", "self", ".", "main", ".", "editor", ".", "load", "(", "fname", ",", "lineno", ",", "word", ",", "processevents", "=", "processevents", ")", ")", "self", ".", "main", ".", "editor", ".", "breakpoints_saved", ".", "connect", "(", "self", ".", "set_spyder_breakpoints", ")", "self", ".", "main", ".", "editor", ".", "run_in_current_ipyclient", ".", "connect", "(", "self", ".", "run_script", ")", "self", ".", "main", ".", "editor", ".", "run_cell_in_ipyclient", ".", "connect", "(", "self", ".", "run_cell", ")", "self", ".", "main", ".", "workingdirectory", ".", "set_current_console_wd", ".", "connect", "(", "self", ".", "set_current_client_working_directory", ")", "self", ".", "tabwidget", ".", "currentChanged", ".", "connect", "(", "self", ".", "update_working_directory", ")", "self", ".", "_remove_old_stderr_files", "(", ")" ]
Register plugin in Spyder's main window
[ "Register", "plugin", "in", "Spyder", "s", "main", "window" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L392-L410
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.get_focus_client
def get_focus_client(self): """Return current client with focus, if any""" widget = QApplication.focusWidget() for client in self.get_clients(): if widget is client or widget is client.get_control(): return client
python
def get_focus_client(self): """Return current client with focus, if any""" widget = QApplication.focusWidget() for client in self.get_clients(): if widget is client or widget is client.get_control(): return client
[ "def", "get_focus_client", "(", "self", ")", ":", "widget", "=", "QApplication", ".", "focusWidget", "(", ")", "for", "client", "in", "self", ".", "get_clients", "(", ")", ":", "if", "widget", "is", "client", "or", "widget", "is", "client", ".", "get_control", "(", ")", ":", "return", "client" ]
Return current client with focus, if any
[ "Return", "current", "client", "with", "focus", "if", "any" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L417-L422
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.run_script
def run_script(self, filename, wdir, args, debug, post_mortem, current_client, clear_variables): """Run script in current or dedicated client""" norm = lambda text: remove_backslashes(to_text_string(text)) # Run Cython files in a dedicated console is_cython = osp.splitext(filename)[1] == '.pyx' if is_cython: current_client = False # Select client to execute code on it is_new_client = False if current_client: client = self.get_current_client() else: client = self.get_client_for_file(filename) if client is None: self.create_client_for_file(filename, is_cython=is_cython) client = self.get_current_client() is_new_client = True if client is not None: # Internal kernels, use runfile if client.get_kernel() is not None: line = "%s('%s'" % ('debugfile' if debug else 'runfile', norm(filename)) if args: line += ", args='%s'" % norm(args) if wdir: line += ", wdir='%s'" % norm(wdir) if post_mortem: line += ", post_mortem=True" line += ")" else: # External kernels, use %run line = "%run " if debug: line += "-d " line += "\"%s\"" % to_text_string(filename) if args: line += " %s" % norm(args) try: if client.shellwidget._executing: # Don't allow multiple executions when there's # still an execution taking place # Fixes issue 7293 pass elif client.shellwidget._reading: client.shellwidget._append_html( _("<br><b>Please exit from debugging before trying to " "run a file in this console.</b>\n<hr><br>"), before_prompt=True) return elif current_client: self.execute_code(line, current_client, clear_variables) else: if is_new_client: client.shellwidget.silent_execute('%clear') else: client.shellwidget.execute('%clear') client.shellwidget.sig_prompt_ready.connect( lambda: self.execute_code(line, current_client, clear_variables)) except AttributeError: pass self.switch_to_plugin() else: #XXX: not sure it can really happen QMessageBox.warning(self, _('Warning'), _("No IPython console is currently available to run <b>%s</b>." "<br><br>Please open a new one and try again." ) % osp.basename(filename), QMessageBox.Ok)
python
def run_script(self, filename, wdir, args, debug, post_mortem, current_client, clear_variables): """Run script in current or dedicated client""" norm = lambda text: remove_backslashes(to_text_string(text)) # Run Cython files in a dedicated console is_cython = osp.splitext(filename)[1] == '.pyx' if is_cython: current_client = False # Select client to execute code on it is_new_client = False if current_client: client = self.get_current_client() else: client = self.get_client_for_file(filename) if client is None: self.create_client_for_file(filename, is_cython=is_cython) client = self.get_current_client() is_new_client = True if client is not None: # Internal kernels, use runfile if client.get_kernel() is not None: line = "%s('%s'" % ('debugfile' if debug else 'runfile', norm(filename)) if args: line += ", args='%s'" % norm(args) if wdir: line += ", wdir='%s'" % norm(wdir) if post_mortem: line += ", post_mortem=True" line += ")" else: # External kernels, use %run line = "%run " if debug: line += "-d " line += "\"%s\"" % to_text_string(filename) if args: line += " %s" % norm(args) try: if client.shellwidget._executing: # Don't allow multiple executions when there's # still an execution taking place # Fixes issue 7293 pass elif client.shellwidget._reading: client.shellwidget._append_html( _("<br><b>Please exit from debugging before trying to " "run a file in this console.</b>\n<hr><br>"), before_prompt=True) return elif current_client: self.execute_code(line, current_client, clear_variables) else: if is_new_client: client.shellwidget.silent_execute('%clear') else: client.shellwidget.execute('%clear') client.shellwidget.sig_prompt_ready.connect( lambda: self.execute_code(line, current_client, clear_variables)) except AttributeError: pass self.switch_to_plugin() else: #XXX: not sure it can really happen QMessageBox.warning(self, _('Warning'), _("No IPython console is currently available to run <b>%s</b>." "<br><br>Please open a new one and try again." ) % osp.basename(filename), QMessageBox.Ok)
[ "def", "run_script", "(", "self", ",", "filename", ",", "wdir", ",", "args", ",", "debug", ",", "post_mortem", ",", "current_client", ",", "clear_variables", ")", ":", "norm", "=", "lambda", "text", ":", "remove_backslashes", "(", "to_text_string", "(", "text", ")", ")", "# Run Cython files in a dedicated console\r", "is_cython", "=", "osp", ".", "splitext", "(", "filename", ")", "[", "1", "]", "==", "'.pyx'", "if", "is_cython", ":", "current_client", "=", "False", "# Select client to execute code on it\r", "is_new_client", "=", "False", "if", "current_client", ":", "client", "=", "self", ".", "get_current_client", "(", ")", "else", ":", "client", "=", "self", ".", "get_client_for_file", "(", "filename", ")", "if", "client", "is", "None", ":", "self", ".", "create_client_for_file", "(", "filename", ",", "is_cython", "=", "is_cython", ")", "client", "=", "self", ".", "get_current_client", "(", ")", "is_new_client", "=", "True", "if", "client", "is", "not", "None", ":", "# Internal kernels, use runfile\r", "if", "client", ".", "get_kernel", "(", ")", "is", "not", "None", ":", "line", "=", "\"%s('%s'\"", "%", "(", "'debugfile'", "if", "debug", "else", "'runfile'", ",", "norm", "(", "filename", ")", ")", "if", "args", ":", "line", "+=", "\", args='%s'\"", "%", "norm", "(", "args", ")", "if", "wdir", ":", "line", "+=", "\", wdir='%s'\"", "%", "norm", "(", "wdir", ")", "if", "post_mortem", ":", "line", "+=", "\", post_mortem=True\"", "line", "+=", "\")\"", "else", ":", "# External kernels, use %run\r", "line", "=", "\"%run \"", "if", "debug", ":", "line", "+=", "\"-d \"", "line", "+=", "\"\\\"%s\\\"\"", "%", "to_text_string", "(", "filename", ")", "if", "args", ":", "line", "+=", "\" %s\"", "%", "norm", "(", "args", ")", "try", ":", "if", "client", ".", "shellwidget", ".", "_executing", ":", "# Don't allow multiple executions when there's\r", "# still an execution taking place\r", "# Fixes issue 7293\r", "pass", "elif", "client", ".", "shellwidget", ".", "_reading", ":", "client", ".", "shellwidget", ".", "_append_html", "(", "_", "(", "\"<br><b>Please exit from debugging before trying to \"", "\"run a file in this console.</b>\\n<hr><br>\"", ")", ",", "before_prompt", "=", "True", ")", "return", "elif", "current_client", ":", "self", ".", "execute_code", "(", "line", ",", "current_client", ",", "clear_variables", ")", "else", ":", "if", "is_new_client", ":", "client", ".", "shellwidget", ".", "silent_execute", "(", "'%clear'", ")", "else", ":", "client", ".", "shellwidget", ".", "execute", "(", "'%clear'", ")", "client", ".", "shellwidget", ".", "sig_prompt_ready", ".", "connect", "(", "lambda", ":", "self", ".", "execute_code", "(", "line", ",", "current_client", ",", "clear_variables", ")", ")", "except", "AttributeError", ":", "pass", "self", ".", "switch_to_plugin", "(", ")", "else", ":", "#XXX: not sure it can really happen\r", "QMessageBox", ".", "warning", "(", "self", ",", "_", "(", "'Warning'", ")", ",", "_", "(", "\"No IPython console is currently available to run <b>%s</b>.\"", "\"<br><br>Please open a new one and try again.\"", ")", "%", "osp", ".", "basename", "(", "filename", ")", ",", "QMessageBox", ".", "Ok", ")" ]
Run script in current or dedicated client
[ "Run", "script", "in", "current", "or", "dedicated", "client" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L436-L507
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.run_cell
def run_cell(self, code, cell_name, filename, run_cell_copy): """Run cell in current or dedicated client.""" def norm(text): return remove_backslashes(to_text_string(text)) self.run_cell_filename = filename # Select client to execute code on it client = self.get_client_for_file(filename) if client is None: client = self.get_current_client() is_internal_kernel = False if client is not None: # Internal kernels, use runcell if client.get_kernel() is not None and not run_cell_copy: line = (to_text_string("{}('{}','{}')") .format(to_text_string('runcell'), (to_text_string(cell_name).replace("\\","\\\\") .replace("'", r"\'")), norm(filename).replace("'", r"\'"))) is_internal_kernel = True # External kernels and run_cell_copy, just execute the code else: line = code.strip() try: if client.shellwidget._executing: # Don't allow multiple executions when there's # still an execution taking place # Fixes issue 7293 pass elif client.shellwidget._reading: client.shellwidget._append_html( _("<br><b>Exit the debugger before trying to " "run a cell in this console.</b>\n<hr><br>"), before_prompt=True) return else: if is_internal_kernel: client.shellwidget.silent_execute( to_text_string('get_ipython().cell_code = ' '"""{}"""') .format(to_text_string(code) .replace('\\', r'\\') .replace('"""', r'\"\"\"'))) self.execute_code(line) except AttributeError: pass self.visibility_changed(True) self.raise_() else: # XXX: not sure it can really happen QMessageBox.warning(self, _('Warning'), _("No IPython console is currently available " "to run <b>{}</b>.<br><br>Please open a new " "one and try again." ).format(osp.basename(filename)), QMessageBox.Ok)
python
def run_cell(self, code, cell_name, filename, run_cell_copy): """Run cell in current or dedicated client.""" def norm(text): return remove_backslashes(to_text_string(text)) self.run_cell_filename = filename # Select client to execute code on it client = self.get_client_for_file(filename) if client is None: client = self.get_current_client() is_internal_kernel = False if client is not None: # Internal kernels, use runcell if client.get_kernel() is not None and not run_cell_copy: line = (to_text_string("{}('{}','{}')") .format(to_text_string('runcell'), (to_text_string(cell_name).replace("\\","\\\\") .replace("'", r"\'")), norm(filename).replace("'", r"\'"))) is_internal_kernel = True # External kernels and run_cell_copy, just execute the code else: line = code.strip() try: if client.shellwidget._executing: # Don't allow multiple executions when there's # still an execution taking place # Fixes issue 7293 pass elif client.shellwidget._reading: client.shellwidget._append_html( _("<br><b>Exit the debugger before trying to " "run a cell in this console.</b>\n<hr><br>"), before_prompt=True) return else: if is_internal_kernel: client.shellwidget.silent_execute( to_text_string('get_ipython().cell_code = ' '"""{}"""') .format(to_text_string(code) .replace('\\', r'\\') .replace('"""', r'\"\"\"'))) self.execute_code(line) except AttributeError: pass self.visibility_changed(True) self.raise_() else: # XXX: not sure it can really happen QMessageBox.warning(self, _('Warning'), _("No IPython console is currently available " "to run <b>{}</b>.<br><br>Please open a new " "one and try again." ).format(osp.basename(filename)), QMessageBox.Ok)
[ "def", "run_cell", "(", "self", ",", "code", ",", "cell_name", ",", "filename", ",", "run_cell_copy", ")", ":", "def", "norm", "(", "text", ")", ":", "return", "remove_backslashes", "(", "to_text_string", "(", "text", ")", ")", "self", ".", "run_cell_filename", "=", "filename", "# Select client to execute code on it\r", "client", "=", "self", ".", "get_client_for_file", "(", "filename", ")", "if", "client", "is", "None", ":", "client", "=", "self", ".", "get_current_client", "(", ")", "is_internal_kernel", "=", "False", "if", "client", "is", "not", "None", ":", "# Internal kernels, use runcell\r", "if", "client", ".", "get_kernel", "(", ")", "is", "not", "None", "and", "not", "run_cell_copy", ":", "line", "=", "(", "to_text_string", "(", "\"{}('{}','{}')\"", ")", ".", "format", "(", "to_text_string", "(", "'runcell'", ")", ",", "(", "to_text_string", "(", "cell_name", ")", ".", "replace", "(", "\"\\\\\"", ",", "\"\\\\\\\\\"", ")", ".", "replace", "(", "\"'\"", ",", "r\"\\'\"", ")", ")", ",", "norm", "(", "filename", ")", ".", "replace", "(", "\"'\"", ",", "r\"\\'\"", ")", ")", ")", "is_internal_kernel", "=", "True", "# External kernels and run_cell_copy, just execute the code\r", "else", ":", "line", "=", "code", ".", "strip", "(", ")", "try", ":", "if", "client", ".", "shellwidget", ".", "_executing", ":", "# Don't allow multiple executions when there's\r", "# still an execution taking place\r", "# Fixes issue 7293\r", "pass", "elif", "client", ".", "shellwidget", ".", "_reading", ":", "client", ".", "shellwidget", ".", "_append_html", "(", "_", "(", "\"<br><b>Exit the debugger before trying to \"", "\"run a cell in this console.</b>\\n<hr><br>\"", ")", ",", "before_prompt", "=", "True", ")", "return", "else", ":", "if", "is_internal_kernel", ":", "client", ".", "shellwidget", ".", "silent_execute", "(", "to_text_string", "(", "'get_ipython().cell_code = '", "'\"\"\"{}\"\"\"'", ")", ".", "format", "(", "to_text_string", "(", "code", ")", ".", "replace", "(", "'\\\\'", ",", "r'\\\\'", ")", ".", "replace", "(", "'\"\"\"'", ",", "r'\\\"\\\"\\\"'", ")", ")", ")", "self", ".", "execute_code", "(", "line", ")", "except", "AttributeError", ":", "pass", "self", ".", "visibility_changed", "(", "True", ")", "self", ".", "raise_", "(", ")", "else", ":", "# XXX: not sure it can really happen\r", "QMessageBox", ".", "warning", "(", "self", ",", "_", "(", "'Warning'", ")", ",", "_", "(", "\"No IPython console is currently available \"", "\"to run <b>{}</b>.<br><br>Please open a new \"", "\"one and try again.\"", ")", ".", "format", "(", "osp", ".", "basename", "(", "filename", ")", ")", ",", "QMessageBox", ".", "Ok", ")" ]
Run cell in current or dedicated client.
[ "Run", "cell", "in", "current", "or", "dedicated", "client", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L509-L569
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.set_current_client_working_directory
def set_current_client_working_directory(self, directory): """Set current client working directory.""" shellwidget = self.get_current_shellwidget() if shellwidget is not None: shellwidget.set_cwd(directory)
python
def set_current_client_working_directory(self, directory): """Set current client working directory.""" shellwidget = self.get_current_shellwidget() if shellwidget is not None: shellwidget.set_cwd(directory)
[ "def", "set_current_client_working_directory", "(", "self", ",", "directory", ")", ":", "shellwidget", "=", "self", ".", "get_current_shellwidget", "(", ")", "if", "shellwidget", "is", "not", "None", ":", "shellwidget", ".", "set_cwd", "(", "directory", ")" ]
Set current client working directory.
[ "Set", "current", "client", "working", "directory", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L571-L575
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.set_working_directory
def set_working_directory(self, dirname): """Set current working directory. In the workingdirectory and explorer plugins. """ if dirname: self.main.workingdirectory.chdir(dirname, refresh_explorer=True, refresh_console=False)
python
def set_working_directory(self, dirname): """Set current working directory. In the workingdirectory and explorer plugins. """ if dirname: self.main.workingdirectory.chdir(dirname, refresh_explorer=True, refresh_console=False)
[ "def", "set_working_directory", "(", "self", ",", "dirname", ")", ":", "if", "dirname", ":", "self", ".", "main", ".", "workingdirectory", ".", "chdir", "(", "dirname", ",", "refresh_explorer", "=", "True", ",", "refresh_console", "=", "False", ")" ]
Set current working directory. In the workingdirectory and explorer plugins.
[ "Set", "current", "working", "directory", ".", "In", "the", "workingdirectory", "and", "explorer", "plugins", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L577-L583
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.execute_code
def execute_code(self, lines, current_client=True, clear_variables=False): """Execute code instructions.""" sw = self.get_current_shellwidget() if sw is not None: if sw._reading: pass else: if not current_client: # Clear console and reset namespace for # dedicated clients # See issue 5748 try: sw.sig_prompt_ready.disconnect() except TypeError: pass sw.reset_namespace(warning=False) elif current_client and clear_variables: sw.reset_namespace(warning=False) # Needed to handle an error when kernel_client is none # See issue 6308 try: sw.execute(to_text_string(lines)) except AttributeError: pass self.activateWindow() self.get_current_client().get_control().setFocus()
python
def execute_code(self, lines, current_client=True, clear_variables=False): """Execute code instructions.""" sw = self.get_current_shellwidget() if sw is not None: if sw._reading: pass else: if not current_client: # Clear console and reset namespace for # dedicated clients # See issue 5748 try: sw.sig_prompt_ready.disconnect() except TypeError: pass sw.reset_namespace(warning=False) elif current_client and clear_variables: sw.reset_namespace(warning=False) # Needed to handle an error when kernel_client is none # See issue 6308 try: sw.execute(to_text_string(lines)) except AttributeError: pass self.activateWindow() self.get_current_client().get_control().setFocus()
[ "def", "execute_code", "(", "self", ",", "lines", ",", "current_client", "=", "True", ",", "clear_variables", "=", "False", ")", ":", "sw", "=", "self", ".", "get_current_shellwidget", "(", ")", "if", "sw", "is", "not", "None", ":", "if", "sw", ".", "_reading", ":", "pass", "else", ":", "if", "not", "current_client", ":", "# Clear console and reset namespace for\r", "# dedicated clients\r", "# See issue 5748\r", "try", ":", "sw", ".", "sig_prompt_ready", ".", "disconnect", "(", ")", "except", "TypeError", ":", "pass", "sw", ".", "reset_namespace", "(", "warning", "=", "False", ")", "elif", "current_client", "and", "clear_variables", ":", "sw", ".", "reset_namespace", "(", "warning", "=", "False", ")", "# Needed to handle an error when kernel_client is none\r", "# See issue 6308\r", "try", ":", "sw", ".", "execute", "(", "to_text_string", "(", "lines", ")", ")", "except", "AttributeError", ":", "pass", "self", ".", "activateWindow", "(", ")", "self", ".", "get_current_client", "(", ")", ".", "get_control", "(", ")", ".", "setFocus", "(", ")" ]
Execute code instructions.
[ "Execute", "code", "instructions", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L591-L616
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.create_new_client
def create_new_client(self, give_focus=True, filename='', is_cython=False, is_pylab=False, is_sympy=False, given_name=None): """Create a new client""" self.master_clients += 1 client_id = dict(int_id=to_text_string(self.master_clients), str_id='A') cf = self._new_connection_file() show_elapsed_time = self.get_option('show_elapsed_time') reset_warning = self.get_option('show_reset_namespace_warning') ask_before_restart = self.get_option('ask_before_restart') client = ClientWidget(self, id_=client_id, history_filename=get_conf_path('history.py'), config_options=self.config_options(), additional_options=self.additional_options( is_pylab=is_pylab, is_sympy=is_sympy), interpreter_versions=self.interpreter_versions(), connection_file=cf, menu_actions=self.menu_actions, options_button=self.options_button, show_elapsed_time=show_elapsed_time, reset_warning=reset_warning, given_name=given_name, ask_before_restart=ask_before_restart, css_path=self.css_path) # Change stderr_dir if requested if self.test_dir is not None: client.stderr_dir = self.test_dir self.add_tab(client, name=client.get_name(), filename=filename) if cf is None: error_msg = self.permission_error_msg.format(jupyter_runtime_dir()) client.show_kernel_error(error_msg) return # Check if ipykernel is present in the external interpreter. # Else we won't be able to create a client if not CONF.get('main_interpreter', 'default'): pyexec = CONF.get('main_interpreter', 'executable') has_spyder_kernels = programs.is_module_installed( 'spyder_kernels', interpreter=pyexec, version='>=1.0.0') if not has_spyder_kernels: client.show_kernel_error( _("Your Python environment or installation doesn't " "have the <tt>spyder-kernels</tt> module or the " "right version of it installed. " "Without this module is not possible for " "Spyder to create a console for you.<br><br>" "You can install it by running in a system terminal:" "<br><br>" "<tt>conda install spyder-kernels</tt>" "<br><br>or<br><br>" "<tt>pip install spyder-kernels</tt>")) return self.connect_client_to_kernel(client, is_cython=is_cython, is_pylab=is_pylab, is_sympy=is_sympy) if client.shellwidget.kernel_manager is None: return self.register_client(client)
python
def create_new_client(self, give_focus=True, filename='', is_cython=False, is_pylab=False, is_sympy=False, given_name=None): """Create a new client""" self.master_clients += 1 client_id = dict(int_id=to_text_string(self.master_clients), str_id='A') cf = self._new_connection_file() show_elapsed_time = self.get_option('show_elapsed_time') reset_warning = self.get_option('show_reset_namespace_warning') ask_before_restart = self.get_option('ask_before_restart') client = ClientWidget(self, id_=client_id, history_filename=get_conf_path('history.py'), config_options=self.config_options(), additional_options=self.additional_options( is_pylab=is_pylab, is_sympy=is_sympy), interpreter_versions=self.interpreter_versions(), connection_file=cf, menu_actions=self.menu_actions, options_button=self.options_button, show_elapsed_time=show_elapsed_time, reset_warning=reset_warning, given_name=given_name, ask_before_restart=ask_before_restart, css_path=self.css_path) # Change stderr_dir if requested if self.test_dir is not None: client.stderr_dir = self.test_dir self.add_tab(client, name=client.get_name(), filename=filename) if cf is None: error_msg = self.permission_error_msg.format(jupyter_runtime_dir()) client.show_kernel_error(error_msg) return # Check if ipykernel is present in the external interpreter. # Else we won't be able to create a client if not CONF.get('main_interpreter', 'default'): pyexec = CONF.get('main_interpreter', 'executable') has_spyder_kernels = programs.is_module_installed( 'spyder_kernels', interpreter=pyexec, version='>=1.0.0') if not has_spyder_kernels: client.show_kernel_error( _("Your Python environment or installation doesn't " "have the <tt>spyder-kernels</tt> module or the " "right version of it installed. " "Without this module is not possible for " "Spyder to create a console for you.<br><br>" "You can install it by running in a system terminal:" "<br><br>" "<tt>conda install spyder-kernels</tt>" "<br><br>or<br><br>" "<tt>pip install spyder-kernels</tt>")) return self.connect_client_to_kernel(client, is_cython=is_cython, is_pylab=is_pylab, is_sympy=is_sympy) if client.shellwidget.kernel_manager is None: return self.register_client(client)
[ "def", "create_new_client", "(", "self", ",", "give_focus", "=", "True", ",", "filename", "=", "''", ",", "is_cython", "=", "False", ",", "is_pylab", "=", "False", ",", "is_sympy", "=", "False", ",", "given_name", "=", "None", ")", ":", "self", ".", "master_clients", "+=", "1", "client_id", "=", "dict", "(", "int_id", "=", "to_text_string", "(", "self", ".", "master_clients", ")", ",", "str_id", "=", "'A'", ")", "cf", "=", "self", ".", "_new_connection_file", "(", ")", "show_elapsed_time", "=", "self", ".", "get_option", "(", "'show_elapsed_time'", ")", "reset_warning", "=", "self", ".", "get_option", "(", "'show_reset_namespace_warning'", ")", "ask_before_restart", "=", "self", ".", "get_option", "(", "'ask_before_restart'", ")", "client", "=", "ClientWidget", "(", "self", ",", "id_", "=", "client_id", ",", "history_filename", "=", "get_conf_path", "(", "'history.py'", ")", ",", "config_options", "=", "self", ".", "config_options", "(", ")", ",", "additional_options", "=", "self", ".", "additional_options", "(", "is_pylab", "=", "is_pylab", ",", "is_sympy", "=", "is_sympy", ")", ",", "interpreter_versions", "=", "self", ".", "interpreter_versions", "(", ")", ",", "connection_file", "=", "cf", ",", "menu_actions", "=", "self", ".", "menu_actions", ",", "options_button", "=", "self", ".", "options_button", ",", "show_elapsed_time", "=", "show_elapsed_time", ",", "reset_warning", "=", "reset_warning", ",", "given_name", "=", "given_name", ",", "ask_before_restart", "=", "ask_before_restart", ",", "css_path", "=", "self", ".", "css_path", ")", "# Change stderr_dir if requested\r", "if", "self", ".", "test_dir", "is", "not", "None", ":", "client", ".", "stderr_dir", "=", "self", ".", "test_dir", "self", ".", "add_tab", "(", "client", ",", "name", "=", "client", ".", "get_name", "(", ")", ",", "filename", "=", "filename", ")", "if", "cf", "is", "None", ":", "error_msg", "=", "self", ".", "permission_error_msg", ".", "format", "(", "jupyter_runtime_dir", "(", ")", ")", "client", ".", "show_kernel_error", "(", "error_msg", ")", "return", "# Check if ipykernel is present in the external interpreter.\r", "# Else we won't be able to create a client\r", "if", "not", "CONF", ".", "get", "(", "'main_interpreter'", ",", "'default'", ")", ":", "pyexec", "=", "CONF", ".", "get", "(", "'main_interpreter'", ",", "'executable'", ")", "has_spyder_kernels", "=", "programs", ".", "is_module_installed", "(", "'spyder_kernels'", ",", "interpreter", "=", "pyexec", ",", "version", "=", "'>=1.0.0'", ")", "if", "not", "has_spyder_kernels", ":", "client", ".", "show_kernel_error", "(", "_", "(", "\"Your Python environment or installation doesn't \"", "\"have the <tt>spyder-kernels</tt> module or the \"", "\"right version of it installed. \"", "\"Without this module is not possible for \"", "\"Spyder to create a console for you.<br><br>\"", "\"You can install it by running in a system terminal:\"", "\"<br><br>\"", "\"<tt>conda install spyder-kernels</tt>\"", "\"<br><br>or<br><br>\"", "\"<tt>pip install spyder-kernels</tt>\"", ")", ")", "return", "self", ".", "connect_client_to_kernel", "(", "client", ",", "is_cython", "=", "is_cython", ",", "is_pylab", "=", "is_pylab", ",", "is_sympy", "=", "is_sympy", ")", "if", "client", ".", "shellwidget", ".", "kernel_manager", "is", "None", ":", "return", "self", ".", "register_client", "(", "client", ")" ]
Create a new client
[ "Create", "a", "new", "client" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L634-L697
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.create_client_for_kernel
def create_client_for_kernel(self): """Create a client connected to an existing kernel""" connect_output = KernelConnectionDialog.get_connection_parameters(self) (connection_file, hostname, sshkey, password, ok) = connect_output if not ok: return else: self._create_client_for_kernel(connection_file, hostname, sshkey, password)
python
def create_client_for_kernel(self): """Create a client connected to an existing kernel""" connect_output = KernelConnectionDialog.get_connection_parameters(self) (connection_file, hostname, sshkey, password, ok) = connect_output if not ok: return else: self._create_client_for_kernel(connection_file, hostname, sshkey, password)
[ "def", "create_client_for_kernel", "(", "self", ")", ":", "connect_output", "=", "KernelConnectionDialog", ".", "get_connection_parameters", "(", "self", ")", "(", "connection_file", ",", "hostname", ",", "sshkey", ",", "password", ",", "ok", ")", "=", "connect_output", "if", "not", "ok", ":", "return", "else", ":", "self", ".", "_create_client_for_kernel", "(", "connection_file", ",", "hostname", ",", "sshkey", ",", "password", ")" ]
Create a client connected to an existing kernel
[ "Create", "a", "client", "connected", "to", "an", "existing", "kernel" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L712-L720
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.connect_client_to_kernel
def connect_client_to_kernel(self, client, is_cython=False, is_pylab=False, is_sympy=False): """Connect a client to its kernel""" connection_file = client.connection_file stderr_handle = None if self.test_no_stderr else client.stderr_handle km, kc = self.create_kernel_manager_and_kernel_client( connection_file, stderr_handle, is_cython=is_cython, is_pylab=is_pylab, is_sympy=is_sympy) # An error occurred if this is True if is_string(km) and kc is None: client.shellwidget.kernel_manager = None client.show_kernel_error(km) return # This avoids a recurrent, spurious NameError when running our # tests in our CIs if not self.testing: kc.started_channels.connect( lambda c=client: self.process_started(c)) kc.stopped_channels.connect( lambda c=client: self.process_finished(c)) kc.start_channels(shell=True, iopub=True) shellwidget = client.shellwidget shellwidget.kernel_manager = km shellwidget.kernel_client = kc
python
def connect_client_to_kernel(self, client, is_cython=False, is_pylab=False, is_sympy=False): """Connect a client to its kernel""" connection_file = client.connection_file stderr_handle = None if self.test_no_stderr else client.stderr_handle km, kc = self.create_kernel_manager_and_kernel_client( connection_file, stderr_handle, is_cython=is_cython, is_pylab=is_pylab, is_sympy=is_sympy) # An error occurred if this is True if is_string(km) and kc is None: client.shellwidget.kernel_manager = None client.show_kernel_error(km) return # This avoids a recurrent, spurious NameError when running our # tests in our CIs if not self.testing: kc.started_channels.connect( lambda c=client: self.process_started(c)) kc.stopped_channels.connect( lambda c=client: self.process_finished(c)) kc.start_channels(shell=True, iopub=True) shellwidget = client.shellwidget shellwidget.kernel_manager = km shellwidget.kernel_client = kc
[ "def", "connect_client_to_kernel", "(", "self", ",", "client", ",", "is_cython", "=", "False", ",", "is_pylab", "=", "False", ",", "is_sympy", "=", "False", ")", ":", "connection_file", "=", "client", ".", "connection_file", "stderr_handle", "=", "None", "if", "self", ".", "test_no_stderr", "else", "client", ".", "stderr_handle", "km", ",", "kc", "=", "self", ".", "create_kernel_manager_and_kernel_client", "(", "connection_file", ",", "stderr_handle", ",", "is_cython", "=", "is_cython", ",", "is_pylab", "=", "is_pylab", ",", "is_sympy", "=", "is_sympy", ")", "# An error occurred if this is True\r", "if", "is_string", "(", "km", ")", "and", "kc", "is", "None", ":", "client", ".", "shellwidget", ".", "kernel_manager", "=", "None", "client", ".", "show_kernel_error", "(", "km", ")", "return", "# This avoids a recurrent, spurious NameError when running our\r", "# tests in our CIs\r", "if", "not", "self", ".", "testing", ":", "kc", ".", "started_channels", ".", "connect", "(", "lambda", "c", "=", "client", ":", "self", ".", "process_started", "(", "c", ")", ")", "kc", ".", "stopped_channels", ".", "connect", "(", "lambda", "c", "=", "client", ":", "self", ".", "process_finished", "(", "c", ")", ")", "kc", ".", "start_channels", "(", "shell", "=", "True", ",", "iopub", "=", "True", ")", "shellwidget", "=", "client", ".", "shellwidget", "shellwidget", ".", "kernel_manager", "=", "km", "shellwidget", ".", "kernel_client", "=", "kc" ]
Connect a client to its kernel
[ "Connect", "a", "client", "to", "its", "kernel" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L722-L751
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.edit_file
def edit_file(self, filename, line): """Handle %edit magic petitions.""" if encoding.is_text_file(filename): # The default line number sent by ipykernel is always the last # one, but we prefer to use the first. self.edit_goto.emit(filename, 1, '')
python
def edit_file(self, filename, line): """Handle %edit magic petitions.""" if encoding.is_text_file(filename): # The default line number sent by ipykernel is always the last # one, but we prefer to use the first. self.edit_goto.emit(filename, 1, '')
[ "def", "edit_file", "(", "self", ",", "filename", ",", "line", ")", ":", "if", "encoding", ".", "is_text_file", "(", "filename", ")", ":", "# The default line number sent by ipykernel is always the last\r", "# one, but we prefer to use the first.\r", "self", ".", "edit_goto", ".", "emit", "(", "filename", ",", "1", ",", "''", ")" ]
Handle %edit magic petitions.
[ "Handle", "%edit", "magic", "petitions", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L754-L759
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.config_options
def config_options(self): """ Generate a Trailets Config instance for shell widgets using our config system This lets us create each widget with its own config """ # ---- Jupyter config ---- try: full_cfg = load_pyconfig_files(['jupyter_qtconsole_config.py'], jupyter_config_dir()) # From the full config we only select the JupyterWidget section # because the others have no effect here. cfg = Config({'JupyterWidget': full_cfg.JupyterWidget}) except: cfg = Config() # ---- Spyder config ---- spy_cfg = Config() # Make the pager widget a rich one (i.e a QTextEdit) spy_cfg.JupyterWidget.kind = 'rich' # Gui completion widget completion_type_o = self.get_option('completion_type') completions = {0: "droplist", 1: "ncurses", 2: "plain"} spy_cfg.JupyterWidget.gui_completion = completions[completion_type_o] # Pager pager_o = self.get_option('use_pager') if pager_o: spy_cfg.JupyterWidget.paging = 'inside' else: spy_cfg.JupyterWidget.paging = 'none' # Calltips calltips_o = self.get_option('show_calltips') spy_cfg.JupyterWidget.enable_calltips = calltips_o # Buffer size buffer_size_o = self.get_option('buffer_size') spy_cfg.JupyterWidget.buffer_size = buffer_size_o # Prompts in_prompt_o = self.get_option('in_prompt') out_prompt_o = self.get_option('out_prompt') if in_prompt_o: spy_cfg.JupyterWidget.in_prompt = in_prompt_o if out_prompt_o: spy_cfg.JupyterWidget.out_prompt = out_prompt_o # Style color_scheme = CONF.get('appearance', 'selected') style_sheet = create_qss_style(color_scheme)[0] spy_cfg.JupyterWidget.style_sheet = style_sheet spy_cfg.JupyterWidget.syntax_style = color_scheme # Merge QtConsole and Spyder configs. Spyder prefs will have # prevalence over QtConsole ones cfg._merge(spy_cfg) return cfg
python
def config_options(self): """ Generate a Trailets Config instance for shell widgets using our config system This lets us create each widget with its own config """ # ---- Jupyter config ---- try: full_cfg = load_pyconfig_files(['jupyter_qtconsole_config.py'], jupyter_config_dir()) # From the full config we only select the JupyterWidget section # because the others have no effect here. cfg = Config({'JupyterWidget': full_cfg.JupyterWidget}) except: cfg = Config() # ---- Spyder config ---- spy_cfg = Config() # Make the pager widget a rich one (i.e a QTextEdit) spy_cfg.JupyterWidget.kind = 'rich' # Gui completion widget completion_type_o = self.get_option('completion_type') completions = {0: "droplist", 1: "ncurses", 2: "plain"} spy_cfg.JupyterWidget.gui_completion = completions[completion_type_o] # Pager pager_o = self.get_option('use_pager') if pager_o: spy_cfg.JupyterWidget.paging = 'inside' else: spy_cfg.JupyterWidget.paging = 'none' # Calltips calltips_o = self.get_option('show_calltips') spy_cfg.JupyterWidget.enable_calltips = calltips_o # Buffer size buffer_size_o = self.get_option('buffer_size') spy_cfg.JupyterWidget.buffer_size = buffer_size_o # Prompts in_prompt_o = self.get_option('in_prompt') out_prompt_o = self.get_option('out_prompt') if in_prompt_o: spy_cfg.JupyterWidget.in_prompt = in_prompt_o if out_prompt_o: spy_cfg.JupyterWidget.out_prompt = out_prompt_o # Style color_scheme = CONF.get('appearance', 'selected') style_sheet = create_qss_style(color_scheme)[0] spy_cfg.JupyterWidget.style_sheet = style_sheet spy_cfg.JupyterWidget.syntax_style = color_scheme # Merge QtConsole and Spyder configs. Spyder prefs will have # prevalence over QtConsole ones cfg._merge(spy_cfg) return cfg
[ "def", "config_options", "(", "self", ")", ":", "# ---- Jupyter config ----\r", "try", ":", "full_cfg", "=", "load_pyconfig_files", "(", "[", "'jupyter_qtconsole_config.py'", "]", ",", "jupyter_config_dir", "(", ")", ")", "# From the full config we only select the JupyterWidget section\r", "# because the others have no effect here.\r", "cfg", "=", "Config", "(", "{", "'JupyterWidget'", ":", "full_cfg", ".", "JupyterWidget", "}", ")", "except", ":", "cfg", "=", "Config", "(", ")", "# ---- Spyder config ----\r", "spy_cfg", "=", "Config", "(", ")", "# Make the pager widget a rich one (i.e a QTextEdit)\r", "spy_cfg", ".", "JupyterWidget", ".", "kind", "=", "'rich'", "# Gui completion widget\r", "completion_type_o", "=", "self", ".", "get_option", "(", "'completion_type'", ")", "completions", "=", "{", "0", ":", "\"droplist\"", ",", "1", ":", "\"ncurses\"", ",", "2", ":", "\"plain\"", "}", "spy_cfg", ".", "JupyterWidget", ".", "gui_completion", "=", "completions", "[", "completion_type_o", "]", "# Pager\r", "pager_o", "=", "self", ".", "get_option", "(", "'use_pager'", ")", "if", "pager_o", ":", "spy_cfg", ".", "JupyterWidget", ".", "paging", "=", "'inside'", "else", ":", "spy_cfg", ".", "JupyterWidget", ".", "paging", "=", "'none'", "# Calltips\r", "calltips_o", "=", "self", ".", "get_option", "(", "'show_calltips'", ")", "spy_cfg", ".", "JupyterWidget", ".", "enable_calltips", "=", "calltips_o", "# Buffer size\r", "buffer_size_o", "=", "self", ".", "get_option", "(", "'buffer_size'", ")", "spy_cfg", ".", "JupyterWidget", ".", "buffer_size", "=", "buffer_size_o", "# Prompts\r", "in_prompt_o", "=", "self", ".", "get_option", "(", "'in_prompt'", ")", "out_prompt_o", "=", "self", ".", "get_option", "(", "'out_prompt'", ")", "if", "in_prompt_o", ":", "spy_cfg", ".", "JupyterWidget", ".", "in_prompt", "=", "in_prompt_o", "if", "out_prompt_o", ":", "spy_cfg", ".", "JupyterWidget", ".", "out_prompt", "=", "out_prompt_o", "# Style\r", "color_scheme", "=", "CONF", ".", "get", "(", "'appearance'", ",", "'selected'", ")", "style_sheet", "=", "create_qss_style", "(", "color_scheme", ")", "[", "0", "]", "spy_cfg", ".", "JupyterWidget", ".", "style_sheet", "=", "style_sheet", "spy_cfg", ".", "JupyterWidget", ".", "syntax_style", "=", "color_scheme", "# Merge QtConsole and Spyder configs. Spyder prefs will have\r", "# prevalence over QtConsole ones\r", "cfg", ".", "_merge", "(", "spy_cfg", ")", "return", "cfg" ]
Generate a Trailets Config instance for shell widgets using our config system This lets us create each widget with its own config
[ "Generate", "a", "Trailets", "Config", "instance", "for", "shell", "widgets", "using", "our", "config", "system", "This", "lets", "us", "create", "each", "widget", "with", "its", "own", "config" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L761-L822
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.interpreter_versions
def interpreter_versions(self): """Python and IPython versions used by clients""" if CONF.get('main_interpreter', 'default'): from IPython.core import release versions = dict( python_version = sys.version.split("\n")[0].strip(), ipython_version = release.version ) else: import subprocess versions = {} pyexec = CONF.get('main_interpreter', 'executable') py_cmd = "%s -c 'import sys; print(sys.version.split(\"\\n\")[0])'" % \ pyexec ipy_cmd = "%s -c 'import IPython.core.release as r; print(r.version)'" \ % pyexec for cmd in [py_cmd, ipy_cmd]: try: proc = programs.run_shell_command(cmd) output, _err = proc.communicate() except subprocess.CalledProcessError: output = '' output = output.decode().split('\n')[0].strip() if 'IPython' in cmd: versions['ipython_version'] = output else: versions['python_version'] = output return versions
python
def interpreter_versions(self): """Python and IPython versions used by clients""" if CONF.get('main_interpreter', 'default'): from IPython.core import release versions = dict( python_version = sys.version.split("\n")[0].strip(), ipython_version = release.version ) else: import subprocess versions = {} pyexec = CONF.get('main_interpreter', 'executable') py_cmd = "%s -c 'import sys; print(sys.version.split(\"\\n\")[0])'" % \ pyexec ipy_cmd = "%s -c 'import IPython.core.release as r; print(r.version)'" \ % pyexec for cmd in [py_cmd, ipy_cmd]: try: proc = programs.run_shell_command(cmd) output, _err = proc.communicate() except subprocess.CalledProcessError: output = '' output = output.decode().split('\n')[0].strip() if 'IPython' in cmd: versions['ipython_version'] = output else: versions['python_version'] = output return versions
[ "def", "interpreter_versions", "(", "self", ")", ":", "if", "CONF", ".", "get", "(", "'main_interpreter'", ",", "'default'", ")", ":", "from", "IPython", ".", "core", "import", "release", "versions", "=", "dict", "(", "python_version", "=", "sys", ".", "version", ".", "split", "(", "\"\\n\"", ")", "[", "0", "]", ".", "strip", "(", ")", ",", "ipython_version", "=", "release", ".", "version", ")", "else", ":", "import", "subprocess", "versions", "=", "{", "}", "pyexec", "=", "CONF", ".", "get", "(", "'main_interpreter'", ",", "'executable'", ")", "py_cmd", "=", "\"%s -c 'import sys; print(sys.version.split(\\\"\\\\n\\\")[0])'\"", "%", "pyexec", "ipy_cmd", "=", "\"%s -c 'import IPython.core.release as r; print(r.version)'\"", "%", "pyexec", "for", "cmd", "in", "[", "py_cmd", ",", "ipy_cmd", "]", ":", "try", ":", "proc", "=", "programs", ".", "run_shell_command", "(", "cmd", ")", "output", ",", "_err", "=", "proc", ".", "communicate", "(", ")", "except", "subprocess", ".", "CalledProcessError", ":", "output", "=", "''", "output", "=", "output", ".", "decode", "(", ")", ".", "split", "(", "'\\n'", ")", "[", "0", "]", ".", "strip", "(", ")", "if", "'IPython'", "in", "cmd", ":", "versions", "[", "'ipython_version'", "]", "=", "output", "else", ":", "versions", "[", "'python_version'", "]", "=", "output", "return", "versions" ]
Python and IPython versions used by clients
[ "Python", "and", "IPython", "versions", "used", "by", "clients" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L824-L852
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.additional_options
def additional_options(self, is_pylab=False, is_sympy=False): """ Additional options for shell widgets that are not defined in JupyterWidget config options """ options = dict( pylab=self.get_option('pylab'), autoload_pylab=self.get_option('pylab/autoload'), sympy=self.get_option('symbolic_math'), show_banner=self.get_option('show_banner') ) if is_pylab is True: options['autoload_pylab'] = True options['sympy'] = False if is_sympy is True: options['autoload_pylab'] = False options['sympy'] = True return options
python
def additional_options(self, is_pylab=False, is_sympy=False): """ Additional options for shell widgets that are not defined in JupyterWidget config options """ options = dict( pylab=self.get_option('pylab'), autoload_pylab=self.get_option('pylab/autoload'), sympy=self.get_option('symbolic_math'), show_banner=self.get_option('show_banner') ) if is_pylab is True: options['autoload_pylab'] = True options['sympy'] = False if is_sympy is True: options['autoload_pylab'] = False options['sympy'] = True return options
[ "def", "additional_options", "(", "self", ",", "is_pylab", "=", "False", ",", "is_sympy", "=", "False", ")", ":", "options", "=", "dict", "(", "pylab", "=", "self", ".", "get_option", "(", "'pylab'", ")", ",", "autoload_pylab", "=", "self", ".", "get_option", "(", "'pylab/autoload'", ")", ",", "sympy", "=", "self", ".", "get_option", "(", "'symbolic_math'", ")", ",", "show_banner", "=", "self", ".", "get_option", "(", "'show_banner'", ")", ")", "if", "is_pylab", "is", "True", ":", "options", "[", "'autoload_pylab'", "]", "=", "True", "options", "[", "'sympy'", "]", "=", "False", "if", "is_sympy", "is", "True", ":", "options", "[", "'autoload_pylab'", "]", "=", "False", "options", "[", "'sympy'", "]", "=", "True", "return", "options" ]
Additional options for shell widgets that are not defined in JupyterWidget config options
[ "Additional", "options", "for", "shell", "widgets", "that", "are", "not", "defined", "in", "JupyterWidget", "config", "options" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L854-L873
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.register_client
def register_client(self, client, give_focus=True): """Register new client""" client.configure_shellwidget(give_focus=give_focus) # Local vars shellwidget = client.shellwidget control = shellwidget._control page_control = shellwidget._page_control # Create new clients with Ctrl+T shortcut shellwidget.new_client.connect(self.create_new_client) # For tracebacks control.go_to_error.connect(self.go_to_error) shellwidget.sig_pdb_step.connect( lambda fname, lineno, shellwidget=shellwidget: self.pdb_has_stopped(fname, lineno, shellwidget)) # To handle %edit magic petitions shellwidget.custom_edit_requested.connect(self.edit_file) # Set shell cwd according to preferences cwd_path = '' if CONF.get('workingdir', 'console/use_project_or_home_directory'): cwd_path = get_home_dir() if (self.main.projects is not None and self.main.projects.get_active_project() is not None): cwd_path = self.main.projects.get_active_project_path() elif CONF.get('workingdir', 'console/use_fixed_directory'): cwd_path = CONF.get('workingdir', 'console/fixed_directory') if osp.isdir(cwd_path) and self.main is not None: shellwidget.set_cwd(cwd_path) if give_focus: # Syncronice cwd with explorer and cwd widget shellwidget.get_cwd() # Connect text widget to Help if self.main.help is not None: control.set_help(self.main.help) control.set_help_enabled(CONF.get('help', 'connect/ipython_console')) # Connect client to our history log if self.main.historylog is not None: self.main.historylog.add_history(client.history_filename) client.append_to_history.connect( self.main.historylog.append_to_history) # Set font for client client.set_font( self.get_plugin_font() ) # Connect focus signal to client's control widget control.focus_changed.connect(lambda: self.focus_changed.emit()) shellwidget.sig_change_cwd.connect(self.set_working_directory) # Update the find widget if focus changes between control and # page_control self.find_widget.set_editor(control) if page_control: page_control.focus_changed.connect(lambda: self.focus_changed.emit()) control.visibility_changed.connect(self.refresh_plugin) page_control.visibility_changed.connect(self.refresh_plugin) page_control.show_find_widget.connect(self.find_widget.show)
python
def register_client(self, client, give_focus=True): """Register new client""" client.configure_shellwidget(give_focus=give_focus) # Local vars shellwidget = client.shellwidget control = shellwidget._control page_control = shellwidget._page_control # Create new clients with Ctrl+T shortcut shellwidget.new_client.connect(self.create_new_client) # For tracebacks control.go_to_error.connect(self.go_to_error) shellwidget.sig_pdb_step.connect( lambda fname, lineno, shellwidget=shellwidget: self.pdb_has_stopped(fname, lineno, shellwidget)) # To handle %edit magic petitions shellwidget.custom_edit_requested.connect(self.edit_file) # Set shell cwd according to preferences cwd_path = '' if CONF.get('workingdir', 'console/use_project_or_home_directory'): cwd_path = get_home_dir() if (self.main.projects is not None and self.main.projects.get_active_project() is not None): cwd_path = self.main.projects.get_active_project_path() elif CONF.get('workingdir', 'console/use_fixed_directory'): cwd_path = CONF.get('workingdir', 'console/fixed_directory') if osp.isdir(cwd_path) and self.main is not None: shellwidget.set_cwd(cwd_path) if give_focus: # Syncronice cwd with explorer and cwd widget shellwidget.get_cwd() # Connect text widget to Help if self.main.help is not None: control.set_help(self.main.help) control.set_help_enabled(CONF.get('help', 'connect/ipython_console')) # Connect client to our history log if self.main.historylog is not None: self.main.historylog.add_history(client.history_filename) client.append_to_history.connect( self.main.historylog.append_to_history) # Set font for client client.set_font( self.get_plugin_font() ) # Connect focus signal to client's control widget control.focus_changed.connect(lambda: self.focus_changed.emit()) shellwidget.sig_change_cwd.connect(self.set_working_directory) # Update the find widget if focus changes between control and # page_control self.find_widget.set_editor(control) if page_control: page_control.focus_changed.connect(lambda: self.focus_changed.emit()) control.visibility_changed.connect(self.refresh_plugin) page_control.visibility_changed.connect(self.refresh_plugin) page_control.show_find_widget.connect(self.find_widget.show)
[ "def", "register_client", "(", "self", ",", "client", ",", "give_focus", "=", "True", ")", ":", "client", ".", "configure_shellwidget", "(", "give_focus", "=", "give_focus", ")", "# Local vars\r", "shellwidget", "=", "client", ".", "shellwidget", "control", "=", "shellwidget", ".", "_control", "page_control", "=", "shellwidget", ".", "_page_control", "# Create new clients with Ctrl+T shortcut\r", "shellwidget", ".", "new_client", ".", "connect", "(", "self", ".", "create_new_client", ")", "# For tracebacks\r", "control", ".", "go_to_error", ".", "connect", "(", "self", ".", "go_to_error", ")", "shellwidget", ".", "sig_pdb_step", ".", "connect", "(", "lambda", "fname", ",", "lineno", ",", "shellwidget", "=", "shellwidget", ":", "self", ".", "pdb_has_stopped", "(", "fname", ",", "lineno", ",", "shellwidget", ")", ")", "# To handle %edit magic petitions\r", "shellwidget", ".", "custom_edit_requested", ".", "connect", "(", "self", ".", "edit_file", ")", "# Set shell cwd according to preferences\r", "cwd_path", "=", "''", "if", "CONF", ".", "get", "(", "'workingdir'", ",", "'console/use_project_or_home_directory'", ")", ":", "cwd_path", "=", "get_home_dir", "(", ")", "if", "(", "self", ".", "main", ".", "projects", "is", "not", "None", "and", "self", ".", "main", ".", "projects", ".", "get_active_project", "(", ")", "is", "not", "None", ")", ":", "cwd_path", "=", "self", ".", "main", ".", "projects", ".", "get_active_project_path", "(", ")", "elif", "CONF", ".", "get", "(", "'workingdir'", ",", "'console/use_fixed_directory'", ")", ":", "cwd_path", "=", "CONF", ".", "get", "(", "'workingdir'", ",", "'console/fixed_directory'", ")", "if", "osp", ".", "isdir", "(", "cwd_path", ")", "and", "self", ".", "main", "is", "not", "None", ":", "shellwidget", ".", "set_cwd", "(", "cwd_path", ")", "if", "give_focus", ":", "# Syncronice cwd with explorer and cwd widget\r", "shellwidget", ".", "get_cwd", "(", ")", "# Connect text widget to Help\r", "if", "self", ".", "main", ".", "help", "is", "not", "None", ":", "control", ".", "set_help", "(", "self", ".", "main", ".", "help", ")", "control", ".", "set_help_enabled", "(", "CONF", ".", "get", "(", "'help'", ",", "'connect/ipython_console'", ")", ")", "# Connect client to our history log\r", "if", "self", ".", "main", ".", "historylog", "is", "not", "None", ":", "self", ".", "main", ".", "historylog", ".", "add_history", "(", "client", ".", "history_filename", ")", "client", ".", "append_to_history", ".", "connect", "(", "self", ".", "main", ".", "historylog", ".", "append_to_history", ")", "# Set font for client\r", "client", ".", "set_font", "(", "self", ".", "get_plugin_font", "(", ")", ")", "# Connect focus signal to client's control widget\r", "control", ".", "focus_changed", ".", "connect", "(", "lambda", ":", "self", ".", "focus_changed", ".", "emit", "(", ")", ")", "shellwidget", ".", "sig_change_cwd", ".", "connect", "(", "self", ".", "set_working_directory", ")", "# Update the find widget if focus changes between control and\r", "# page_control\r", "self", ".", "find_widget", ".", "set_editor", "(", "control", ")", "if", "page_control", ":", "page_control", ".", "focus_changed", ".", "connect", "(", "lambda", ":", "self", ".", "focus_changed", ".", "emit", "(", ")", ")", "control", ".", "visibility_changed", ".", "connect", "(", "self", ".", "refresh_plugin", ")", "page_control", ".", "visibility_changed", ".", "connect", "(", "self", ".", "refresh_plugin", ")", "page_control", ".", "show_find_widget", ".", "connect", "(", "self", ".", "find_widget", ".", "show", ")" ]
Register new client
[ "Register", "new", "client" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L875-L939
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.close_client
def close_client(self, index=None, client=None, force=False): """Close client tab from index or widget (or close current tab)""" if not self.tabwidget.count(): return if client is not None: index = self.tabwidget.indexOf(client) # if index is not found in tabwidget it's because this client was # already closed and the call was performed by the exit callback if index == -1: return if index is None and client is None: index = self.tabwidget.currentIndex() if index is not None: client = self.tabwidget.widget(index) # Needed to handle a RuntimeError. See issue 5568. try: # Close client client.stop_button_click_handler() except RuntimeError: pass # Disconnect timer needed to update elapsed time try: client.timer.timeout.disconnect(client.show_time) except (RuntimeError, TypeError): pass # Check if related clients or kernels are opened # and eventually ask before closing them if not self.mainwindow_close and not force: close_all = True if self.get_option('ask_before_closing'): close = QMessageBox.question(self, self.get_plugin_title(), _("Do you want to close this console?"), QMessageBox.Yes | QMessageBox.No) if close == QMessageBox.No: return if len(self.get_related_clients(client)) > 0: close_all = QMessageBox.question(self, self.get_plugin_title(), _("Do you want to close all other consoles connected " "to the same kernel as this one?"), QMessageBox.Yes | QMessageBox.No) client.shutdown() if close_all == QMessageBox.Yes: self.close_related_clients(client) # if there aren't related clients we can remove stderr_file related_clients = self.get_related_clients(client) if len(related_clients) == 0 and osp.exists(client.stderr_file): client.remove_stderr_file() client.dialog_manager.close_all() client.close() # Note: client index may have changed after closing related widgets self.tabwidget.removeTab(self.tabwidget.indexOf(client)) self.clients.remove(client) # This is needed to prevent that hanged consoles make reference # to an index that doesn't exist. See issue 4881 try: self.filenames.pop(index) except IndexError: pass self.update_tabs_text() # Create a new client if the console is about to become empty if not self.tabwidget.count() and self.create_new_client_if_empty: self.create_new_client() self.sig_update_plugin_title.emit()
python
def close_client(self, index=None, client=None, force=False): """Close client tab from index or widget (or close current tab)""" if not self.tabwidget.count(): return if client is not None: index = self.tabwidget.indexOf(client) # if index is not found in tabwidget it's because this client was # already closed and the call was performed by the exit callback if index == -1: return if index is None and client is None: index = self.tabwidget.currentIndex() if index is not None: client = self.tabwidget.widget(index) # Needed to handle a RuntimeError. See issue 5568. try: # Close client client.stop_button_click_handler() except RuntimeError: pass # Disconnect timer needed to update elapsed time try: client.timer.timeout.disconnect(client.show_time) except (RuntimeError, TypeError): pass # Check if related clients or kernels are opened # and eventually ask before closing them if not self.mainwindow_close and not force: close_all = True if self.get_option('ask_before_closing'): close = QMessageBox.question(self, self.get_plugin_title(), _("Do you want to close this console?"), QMessageBox.Yes | QMessageBox.No) if close == QMessageBox.No: return if len(self.get_related_clients(client)) > 0: close_all = QMessageBox.question(self, self.get_plugin_title(), _("Do you want to close all other consoles connected " "to the same kernel as this one?"), QMessageBox.Yes | QMessageBox.No) client.shutdown() if close_all == QMessageBox.Yes: self.close_related_clients(client) # if there aren't related clients we can remove stderr_file related_clients = self.get_related_clients(client) if len(related_clients) == 0 and osp.exists(client.stderr_file): client.remove_stderr_file() client.dialog_manager.close_all() client.close() # Note: client index may have changed after closing related widgets self.tabwidget.removeTab(self.tabwidget.indexOf(client)) self.clients.remove(client) # This is needed to prevent that hanged consoles make reference # to an index that doesn't exist. See issue 4881 try: self.filenames.pop(index) except IndexError: pass self.update_tabs_text() # Create a new client if the console is about to become empty if not self.tabwidget.count() and self.create_new_client_if_empty: self.create_new_client() self.sig_update_plugin_title.emit()
[ "def", "close_client", "(", "self", ",", "index", "=", "None", ",", "client", "=", "None", ",", "force", "=", "False", ")", ":", "if", "not", "self", ".", "tabwidget", ".", "count", "(", ")", ":", "return", "if", "client", "is", "not", "None", ":", "index", "=", "self", ".", "tabwidget", ".", "indexOf", "(", "client", ")", "# if index is not found in tabwidget it's because this client was\r", "# already closed and the call was performed by the exit callback\r", "if", "index", "==", "-", "1", ":", "return", "if", "index", "is", "None", "and", "client", "is", "None", ":", "index", "=", "self", ".", "tabwidget", ".", "currentIndex", "(", ")", "if", "index", "is", "not", "None", ":", "client", "=", "self", ".", "tabwidget", ".", "widget", "(", "index", ")", "# Needed to handle a RuntimeError. See issue 5568.\r", "try", ":", "# Close client\r", "client", ".", "stop_button_click_handler", "(", ")", "except", "RuntimeError", ":", "pass", "# Disconnect timer needed to update elapsed time\r", "try", ":", "client", ".", "timer", ".", "timeout", ".", "disconnect", "(", "client", ".", "show_time", ")", "except", "(", "RuntimeError", ",", "TypeError", ")", ":", "pass", "# Check if related clients or kernels are opened\r", "# and eventually ask before closing them\r", "if", "not", "self", ".", "mainwindow_close", "and", "not", "force", ":", "close_all", "=", "True", "if", "self", ".", "get_option", "(", "'ask_before_closing'", ")", ":", "close", "=", "QMessageBox", ".", "question", "(", "self", ",", "self", ".", "get_plugin_title", "(", ")", ",", "_", "(", "\"Do you want to close this console?\"", ")", ",", "QMessageBox", ".", "Yes", "|", "QMessageBox", ".", "No", ")", "if", "close", "==", "QMessageBox", ".", "No", ":", "return", "if", "len", "(", "self", ".", "get_related_clients", "(", "client", ")", ")", ">", "0", ":", "close_all", "=", "QMessageBox", ".", "question", "(", "self", ",", "self", ".", "get_plugin_title", "(", ")", ",", "_", "(", "\"Do you want to close all other consoles connected \"", "\"to the same kernel as this one?\"", ")", ",", "QMessageBox", ".", "Yes", "|", "QMessageBox", ".", "No", ")", "client", ".", "shutdown", "(", ")", "if", "close_all", "==", "QMessageBox", ".", "Yes", ":", "self", ".", "close_related_clients", "(", "client", ")", "# if there aren't related clients we can remove stderr_file\r", "related_clients", "=", "self", ".", "get_related_clients", "(", "client", ")", "if", "len", "(", "related_clients", ")", "==", "0", "and", "osp", ".", "exists", "(", "client", ".", "stderr_file", ")", ":", "client", ".", "remove_stderr_file", "(", ")", "client", ".", "dialog_manager", ".", "close_all", "(", ")", "client", ".", "close", "(", ")", "# Note: client index may have changed after closing related widgets\r", "self", ".", "tabwidget", ".", "removeTab", "(", "self", ".", "tabwidget", ".", "indexOf", "(", "client", ")", ")", "self", ".", "clients", ".", "remove", "(", "client", ")", "# This is needed to prevent that hanged consoles make reference\r", "# to an index that doesn't exist. See issue 4881\r", "try", ":", "self", ".", "filenames", ".", "pop", "(", "index", ")", "except", "IndexError", ":", "pass", "self", ".", "update_tabs_text", "(", ")", "# Create a new client if the console is about to become empty\r", "if", "not", "self", ".", "tabwidget", ".", "count", "(", ")", "and", "self", ".", "create_new_client_if_empty", ":", "self", ".", "create_new_client", "(", ")", "self", ".", "sig_update_plugin_title", ".", "emit", "(", ")" ]
Close client tab from index or widget (or close current tab)
[ "Close", "client", "tab", "from", "index", "or", "widget", "(", "or", "close", "current", "tab", ")" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L941-L1014
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.get_client_index_from_id
def get_client_index_from_id(self, client_id): """Return client index from id""" for index, client in enumerate(self.clients): if id(client) == client_id: return index
python
def get_client_index_from_id(self, client_id): """Return client index from id""" for index, client in enumerate(self.clients): if id(client) == client_id: return index
[ "def", "get_client_index_from_id", "(", "self", ",", "client_id", ")", ":", "for", "index", ",", "client", "in", "enumerate", "(", "self", ".", "clients", ")", ":", "if", "id", "(", "client", ")", "==", "client_id", ":", "return", "index" ]
Return client index from id
[ "Return", "client", "index", "from", "id" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1016-L1020
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.get_related_clients
def get_related_clients(self, client): """ Get all other clients that are connected to the same kernel as `client` """ related_clients = [] for cl in self.get_clients(): if cl.connection_file == client.connection_file and \ cl is not client: related_clients.append(cl) return related_clients
python
def get_related_clients(self, client): """ Get all other clients that are connected to the same kernel as `client` """ related_clients = [] for cl in self.get_clients(): if cl.connection_file == client.connection_file and \ cl is not client: related_clients.append(cl) return related_clients
[ "def", "get_related_clients", "(", "self", ",", "client", ")", ":", "related_clients", "=", "[", "]", "for", "cl", "in", "self", ".", "get_clients", "(", ")", ":", "if", "cl", ".", "connection_file", "==", "client", ".", "connection_file", "and", "cl", "is", "not", "client", ":", "related_clients", ".", "append", "(", "cl", ")", "return", "related_clients" ]
Get all other clients that are connected to the same kernel as `client`
[ "Get", "all", "other", "clients", "that", "are", "connected", "to", "the", "same", "kernel", "as", "client" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1022-L1031
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.close_related_clients
def close_related_clients(self, client): """Close all clients related to *client*, except itself""" related_clients = self.get_related_clients(client) for cl in related_clients: self.close_client(client=cl, force=True)
python
def close_related_clients(self, client): """Close all clients related to *client*, except itself""" related_clients = self.get_related_clients(client) for cl in related_clients: self.close_client(client=cl, force=True)
[ "def", "close_related_clients", "(", "self", ",", "client", ")", ":", "related_clients", "=", "self", ".", "get_related_clients", "(", "client", ")", "for", "cl", "in", "related_clients", ":", "self", ".", "close_client", "(", "client", "=", "cl", ",", "force", "=", "True", ")" ]
Close all clients related to *client*, except itself
[ "Close", "all", "clients", "related", "to", "*", "client", "*", "except", "itself" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1033-L1037
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.restart
def restart(self): """ Restart the console This is needed when we switch projects to update PYTHONPATH and the selected interpreter """ self.master_clients = 0 self.create_new_client_if_empty = False for i in range(len(self.clients)): client = self.clients[-1] try: client.shutdown() except Exception as e: QMessageBox.warning(self, _('Warning'), _("It was not possible to restart the IPython console " "when switching to this project. The error was<br><br>" "<tt>{0}</tt>").format(e), QMessageBox.Ok) self.close_client(client=client, force=True) self.create_new_client(give_focus=False) self.create_new_client_if_empty = True
python
def restart(self): """ Restart the console This is needed when we switch projects to update PYTHONPATH and the selected interpreter """ self.master_clients = 0 self.create_new_client_if_empty = False for i in range(len(self.clients)): client = self.clients[-1] try: client.shutdown() except Exception as e: QMessageBox.warning(self, _('Warning'), _("It was not possible to restart the IPython console " "when switching to this project. The error was<br><br>" "<tt>{0}</tt>").format(e), QMessageBox.Ok) self.close_client(client=client, force=True) self.create_new_client(give_focus=False) self.create_new_client_if_empty = True
[ "def", "restart", "(", "self", ")", ":", "self", ".", "master_clients", "=", "0", "self", ".", "create_new_client_if_empty", "=", "False", "for", "i", "in", "range", "(", "len", "(", "self", ".", "clients", ")", ")", ":", "client", "=", "self", ".", "clients", "[", "-", "1", "]", "try", ":", "client", ".", "shutdown", "(", ")", "except", "Exception", "as", "e", ":", "QMessageBox", ".", "warning", "(", "self", ",", "_", "(", "'Warning'", ")", ",", "_", "(", "\"It was not possible to restart the IPython console \"", "\"when switching to this project. The error was<br><br>\"", "\"<tt>{0}</tt>\"", ")", ".", "format", "(", "e", ")", ",", "QMessageBox", ".", "Ok", ")", "self", ".", "close_client", "(", "client", "=", "client", ",", "force", "=", "True", ")", "self", ".", "create_new_client", "(", "give_focus", "=", "False", ")", "self", ".", "create_new_client_if_empty", "=", "True" ]
Restart the console This is needed when we switch projects to update PYTHONPATH and the selected interpreter
[ "Restart", "the", "console", "This", "is", "needed", "when", "we", "switch", "projects", "to", "update", "PYTHONPATH", "and", "the", "selected", "interpreter" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1039-L1059
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.pdb_has_stopped
def pdb_has_stopped(self, fname, lineno, shellwidget): """Python debugger has just stopped at frame (fname, lineno)""" # This is a unique form of the edit_goto signal that is intended to # prevent keyboard input from accidentally entering the editor # during repeated, rapid entry of debugging commands. self.edit_goto[str, int, str, bool].emit(fname, lineno, '', False) self.activateWindow() shellwidget._control.setFocus()
python
def pdb_has_stopped(self, fname, lineno, shellwidget): """Python debugger has just stopped at frame (fname, lineno)""" # This is a unique form of the edit_goto signal that is intended to # prevent keyboard input from accidentally entering the editor # during repeated, rapid entry of debugging commands. self.edit_goto[str, int, str, bool].emit(fname, lineno, '', False) self.activateWindow() shellwidget._control.setFocus()
[ "def", "pdb_has_stopped", "(", "self", ",", "fname", ",", "lineno", ",", "shellwidget", ")", ":", "# This is a unique form of the edit_goto signal that is intended to\r", "# prevent keyboard input from accidentally entering the editor\r", "# during repeated, rapid entry of debugging commands.\r", "self", ".", "edit_goto", "[", "str", ",", "int", ",", "str", ",", "bool", "]", ".", "emit", "(", "fname", ",", "lineno", ",", "''", ",", "False", ")", "self", ".", "activateWindow", "(", ")", "shellwidget", ".", "_control", ".", "setFocus", "(", ")" ]
Python debugger has just stopped at frame (fname, lineno)
[ "Python", "debugger", "has", "just", "stopped", "at", "frame", "(", "fname", "lineno", ")" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1061-L1068
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.create_client_from_path
def create_client_from_path(self, path): """Create a client with its cwd pointing to path.""" self.create_new_client() sw = self.get_current_shellwidget() sw.set_cwd(path)
python
def create_client_from_path(self, path): """Create a client with its cwd pointing to path.""" self.create_new_client() sw = self.get_current_shellwidget() sw.set_cwd(path)
[ "def", "create_client_from_path", "(", "self", ",", "path", ")", ":", "self", ".", "create_new_client", "(", ")", "sw", "=", "self", ".", "get_current_shellwidget", "(", ")", "sw", ".", "set_cwd", "(", "path", ")" ]
Create a client with its cwd pointing to path.
[ "Create", "a", "client", "with", "its", "cwd", "pointing", "to", "path", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1076-L1080
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.create_client_for_file
def create_client_for_file(self, filename, is_cython=False): """Create a client to execute code related to a file.""" # Create client self.create_new_client(filename=filename, is_cython=is_cython) # Don't increase the count of master clients self.master_clients -= 1 # Rename client tab with filename client = self.get_current_client() client.allow_rename = False tab_text = self.disambiguate_fname(filename) self.rename_client_tab(client, tab_text)
python
def create_client_for_file(self, filename, is_cython=False): """Create a client to execute code related to a file.""" # Create client self.create_new_client(filename=filename, is_cython=is_cython) # Don't increase the count of master clients self.master_clients -= 1 # Rename client tab with filename client = self.get_current_client() client.allow_rename = False tab_text = self.disambiguate_fname(filename) self.rename_client_tab(client, tab_text)
[ "def", "create_client_for_file", "(", "self", ",", "filename", ",", "is_cython", "=", "False", ")", ":", "# Create client\r", "self", ".", "create_new_client", "(", "filename", "=", "filename", ",", "is_cython", "=", "is_cython", ")", "# Don't increase the count of master clients\r", "self", ".", "master_clients", "-=", "1", "# Rename client tab with filename\r", "client", "=", "self", ".", "get_current_client", "(", ")", "client", ".", "allow_rename", "=", "False", "tab_text", "=", "self", ".", "disambiguate_fname", "(", "filename", ")", "self", ".", "rename_client_tab", "(", "client", ",", "tab_text", ")" ]
Create a client to execute code related to a file.
[ "Create", "a", "client", "to", "execute", "code", "related", "to", "a", "file", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1082-L1094
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.get_client_for_file
def get_client_for_file(self, filename): """Get client associated with a given file.""" client = None for idx, cl in enumerate(self.get_clients()): if self.filenames[idx] == filename: self.tabwidget.setCurrentIndex(idx) client = cl break return client
python
def get_client_for_file(self, filename): """Get client associated with a given file.""" client = None for idx, cl in enumerate(self.get_clients()): if self.filenames[idx] == filename: self.tabwidget.setCurrentIndex(idx) client = cl break return client
[ "def", "get_client_for_file", "(", "self", ",", "filename", ")", ":", "client", "=", "None", "for", "idx", ",", "cl", "in", "enumerate", "(", "self", ".", "get_clients", "(", ")", ")", ":", "if", "self", ".", "filenames", "[", "idx", "]", "==", "filename", ":", "self", ".", "tabwidget", ".", "setCurrentIndex", "(", "idx", ")", "client", "=", "cl", "break", "return", "client" ]
Get client associated with a given file.
[ "Get", "client", "associated", "with", "a", "given", "file", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1096-L1104
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.set_elapsed_time
def set_elapsed_time(self, client): """Set elapsed time for slave clients.""" related_clients = self.get_related_clients(client) for cl in related_clients: if cl.timer is not None: client.create_time_label() client.t0 = cl.t0 client.timer.timeout.connect(client.show_time) client.timer.start(1000) break
python
def set_elapsed_time(self, client): """Set elapsed time for slave clients.""" related_clients = self.get_related_clients(client) for cl in related_clients: if cl.timer is not None: client.create_time_label() client.t0 = cl.t0 client.timer.timeout.connect(client.show_time) client.timer.start(1000) break
[ "def", "set_elapsed_time", "(", "self", ",", "client", ")", ":", "related_clients", "=", "self", ".", "get_related_clients", "(", "client", ")", "for", "cl", "in", "related_clients", ":", "if", "cl", ".", "timer", "is", "not", "None", ":", "client", ".", "create_time_label", "(", ")", "client", ".", "t0", "=", "cl", ".", "t0", "client", ".", "timer", ".", "timeout", ".", "connect", "(", "client", ".", "show_time", ")", "client", ".", "timer", ".", "start", "(", "1000", ")", "break" ]
Set elapsed time for slave clients.
[ "Set", "elapsed", "time", "for", "slave", "clients", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1106-L1115
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.tunnel_to_kernel
def tunnel_to_kernel(self, connection_info, hostname, sshkey=None, password=None, timeout=10): """ Tunnel connections to a kernel via ssh. Remote ports are specified in the connection info ci. """ lports = zmqtunnel.select_random_ports(4) rports = (connection_info['shell_port'], connection_info['iopub_port'], connection_info['stdin_port'], connection_info['hb_port']) remote_ip = connection_info['ip'] for lp, rp in zip(lports, rports): self.ssh_tunnel(lp, rp, hostname, remote_ip, sshkey, password, timeout) return tuple(lports)
python
def tunnel_to_kernel(self, connection_info, hostname, sshkey=None, password=None, timeout=10): """ Tunnel connections to a kernel via ssh. Remote ports are specified in the connection info ci. """ lports = zmqtunnel.select_random_ports(4) rports = (connection_info['shell_port'], connection_info['iopub_port'], connection_info['stdin_port'], connection_info['hb_port']) remote_ip = connection_info['ip'] for lp, rp in zip(lports, rports): self.ssh_tunnel(lp, rp, hostname, remote_ip, sshkey, password, timeout) return tuple(lports)
[ "def", "tunnel_to_kernel", "(", "self", ",", "connection_info", ",", "hostname", ",", "sshkey", "=", "None", ",", "password", "=", "None", ",", "timeout", "=", "10", ")", ":", "lports", "=", "zmqtunnel", ".", "select_random_ports", "(", "4", ")", "rports", "=", "(", "connection_info", "[", "'shell_port'", "]", ",", "connection_info", "[", "'iopub_port'", "]", ",", "connection_info", "[", "'stdin_port'", "]", ",", "connection_info", "[", "'hb_port'", "]", ")", "remote_ip", "=", "connection_info", "[", "'ip'", "]", "for", "lp", ",", "rp", "in", "zip", "(", "lports", ",", "rports", ")", ":", "self", ".", "ssh_tunnel", "(", "lp", ",", "rp", ",", "hostname", ",", "remote_ip", ",", "sshkey", ",", "password", ",", "timeout", ")", "return", "tuple", "(", "lports", ")" ]
Tunnel connections to a kernel via ssh. Remote ports are specified in the connection info ci.
[ "Tunnel", "connections", "to", "a", "kernel", "via", "ssh", ".", "Remote", "ports", "are", "specified", "in", "the", "connection", "info", "ci", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1129-L1143
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.create_kernel_spec
def create_kernel_spec(self, is_cython=False, is_pylab=False, is_sympy=False): """Create a kernel spec for our own kernels""" # Before creating our kernel spec, we always need to # set this value in spyder.ini CONF.set('main', 'spyder_pythonpath', self.main.get_spyder_pythonpath()) return SpyderKernelSpec(is_cython=is_cython, is_pylab=is_pylab, is_sympy=is_sympy)
python
def create_kernel_spec(self, is_cython=False, is_pylab=False, is_sympy=False): """Create a kernel spec for our own kernels""" # Before creating our kernel spec, we always need to # set this value in spyder.ini CONF.set('main', 'spyder_pythonpath', self.main.get_spyder_pythonpath()) return SpyderKernelSpec(is_cython=is_cython, is_pylab=is_pylab, is_sympy=is_sympy)
[ "def", "create_kernel_spec", "(", "self", ",", "is_cython", "=", "False", ",", "is_pylab", "=", "False", ",", "is_sympy", "=", "False", ")", ":", "# Before creating our kernel spec, we always need to\r", "# set this value in spyder.ini\r", "CONF", ".", "set", "(", "'main'", ",", "'spyder_pythonpath'", ",", "self", ".", "main", ".", "get_spyder_pythonpath", "(", ")", ")", "return", "SpyderKernelSpec", "(", "is_cython", "=", "is_cython", ",", "is_pylab", "=", "is_pylab", ",", "is_sympy", "=", "is_sympy", ")" ]
Create a kernel spec for our own kernels
[ "Create", "a", "kernel", "spec", "for", "our", "own", "kernels" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1145-L1154
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.create_kernel_manager_and_kernel_client
def create_kernel_manager_and_kernel_client(self, connection_file, stderr_handle, is_cython=False, is_pylab=False, is_sympy=False): """Create kernel manager and client.""" # Kernel spec kernel_spec = self.create_kernel_spec(is_cython=is_cython, is_pylab=is_pylab, is_sympy=is_sympy) # Kernel manager try: kernel_manager = QtKernelManager(connection_file=connection_file, config=None, autorestart=True) except Exception: error_msg = _("The error is:<br><br>" "<tt>{}</tt>").format(traceback.format_exc()) return (error_msg, None) kernel_manager._kernel_spec = kernel_spec kwargs = {} if os.name == 'nt': # avoid closing fds on win+Python 3.7 # which prevents interrupts # jupyter_client > 5.2.3 will do this by default kwargs['close_fds'] = False # Catch any error generated when trying to start the kernel # See issue 7302 try: kernel_manager.start_kernel(stderr=stderr_handle, **kwargs) except Exception: error_msg = _("The error is:<br><br>" "<tt>{}</tt>").format(traceback.format_exc()) return (error_msg, None) # Kernel client kernel_client = kernel_manager.client() # Increase time to detect if a kernel is alive # See Issue 3444 kernel_client.hb_channel.time_to_dead = 18.0 return kernel_manager, kernel_client
python
def create_kernel_manager_and_kernel_client(self, connection_file, stderr_handle, is_cython=False, is_pylab=False, is_sympy=False): """Create kernel manager and client.""" # Kernel spec kernel_spec = self.create_kernel_spec(is_cython=is_cython, is_pylab=is_pylab, is_sympy=is_sympy) # Kernel manager try: kernel_manager = QtKernelManager(connection_file=connection_file, config=None, autorestart=True) except Exception: error_msg = _("The error is:<br><br>" "<tt>{}</tt>").format(traceback.format_exc()) return (error_msg, None) kernel_manager._kernel_spec = kernel_spec kwargs = {} if os.name == 'nt': # avoid closing fds on win+Python 3.7 # which prevents interrupts # jupyter_client > 5.2.3 will do this by default kwargs['close_fds'] = False # Catch any error generated when trying to start the kernel # See issue 7302 try: kernel_manager.start_kernel(stderr=stderr_handle, **kwargs) except Exception: error_msg = _("The error is:<br><br>" "<tt>{}</tt>").format(traceback.format_exc()) return (error_msg, None) # Kernel client kernel_client = kernel_manager.client() # Increase time to detect if a kernel is alive # See Issue 3444 kernel_client.hb_channel.time_to_dead = 18.0 return kernel_manager, kernel_client
[ "def", "create_kernel_manager_and_kernel_client", "(", "self", ",", "connection_file", ",", "stderr_handle", ",", "is_cython", "=", "False", ",", "is_pylab", "=", "False", ",", "is_sympy", "=", "False", ")", ":", "# Kernel spec\r", "kernel_spec", "=", "self", ".", "create_kernel_spec", "(", "is_cython", "=", "is_cython", ",", "is_pylab", "=", "is_pylab", ",", "is_sympy", "=", "is_sympy", ")", "# Kernel manager\r", "try", ":", "kernel_manager", "=", "QtKernelManager", "(", "connection_file", "=", "connection_file", ",", "config", "=", "None", ",", "autorestart", "=", "True", ")", "except", "Exception", ":", "error_msg", "=", "_", "(", "\"The error is:<br><br>\"", "\"<tt>{}</tt>\"", ")", ".", "format", "(", "traceback", ".", "format_exc", "(", ")", ")", "return", "(", "error_msg", ",", "None", ")", "kernel_manager", ".", "_kernel_spec", "=", "kernel_spec", "kwargs", "=", "{", "}", "if", "os", ".", "name", "==", "'nt'", ":", "# avoid closing fds on win+Python 3.7\r", "# which prevents interrupts\r", "# jupyter_client > 5.2.3 will do this by default\r", "kwargs", "[", "'close_fds'", "]", "=", "False", "# Catch any error generated when trying to start the kernel\r", "# See issue 7302\r", "try", ":", "kernel_manager", ".", "start_kernel", "(", "stderr", "=", "stderr_handle", ",", "*", "*", "kwargs", ")", "except", "Exception", ":", "error_msg", "=", "_", "(", "\"The error is:<br><br>\"", "\"<tt>{}</tt>\"", ")", ".", "format", "(", "traceback", ".", "format_exc", "(", ")", ")", "return", "(", "error_msg", ",", "None", ")", "# Kernel client\r", "kernel_client", "=", "kernel_manager", ".", "client", "(", ")", "# Increase time to detect if a kernel is alive\r", "# See Issue 3444\r", "kernel_client", ".", "hb_channel", ".", "time_to_dead", "=", "18.0", "return", "kernel_manager", ",", "kernel_client" ]
Create kernel manager and client.
[ "Create", "kernel", "manager", "and", "client", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1156-L1199
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.restart_kernel
def restart_kernel(self): """Restart kernel of current client.""" client = self.get_current_client() if client is not None: self.switch_to_plugin() client.restart_kernel()
python
def restart_kernel(self): """Restart kernel of current client.""" client = self.get_current_client() if client is not None: self.switch_to_plugin() client.restart_kernel()
[ "def", "restart_kernel", "(", "self", ")", ":", "client", "=", "self", ".", "get_current_client", "(", ")", "if", "client", "is", "not", "None", ":", "self", ".", "switch_to_plugin", "(", ")", "client", ".", "restart_kernel", "(", ")" ]
Restart kernel of current client.
[ "Restart", "kernel", "of", "current", "client", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1201-L1206
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.reset_kernel
def reset_kernel(self): """Reset kernel of current client.""" client = self.get_current_client() if client is not None: self.switch_to_plugin() client.reset_namespace()
python
def reset_kernel(self): """Reset kernel of current client.""" client = self.get_current_client() if client is not None: self.switch_to_plugin() client.reset_namespace()
[ "def", "reset_kernel", "(", "self", ")", ":", "client", "=", "self", ".", "get_current_client", "(", ")", "if", "client", "is", "not", "None", ":", "self", ".", "switch_to_plugin", "(", ")", "client", ".", "reset_namespace", "(", ")" ]
Reset kernel of current client.
[ "Reset", "kernel", "of", "current", "client", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1208-L1213
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.interrupt_kernel
def interrupt_kernel(self): """Interrupt kernel of current client.""" client = self.get_current_client() if client is not None: self.switch_to_plugin() client.stop_button_click_handler()
python
def interrupt_kernel(self): """Interrupt kernel of current client.""" client = self.get_current_client() if client is not None: self.switch_to_plugin() client.stop_button_click_handler()
[ "def", "interrupt_kernel", "(", "self", ")", ":", "client", "=", "self", ".", "get_current_client", "(", ")", "if", "client", "is", "not", "None", ":", "self", ".", "switch_to_plugin", "(", ")", "client", ".", "stop_button_click_handler", "(", ")" ]
Interrupt kernel of current client.
[ "Interrupt", "kernel", "of", "current", "client", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1215-L1220
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.update_execution_state_kernel
def update_execution_state_kernel(self): """Update actions following the execution state of the kernel.""" client = self.get_current_client() if client is not None: executing = client.stop_button.isEnabled() self.interrupt_action.setEnabled(executing)
python
def update_execution_state_kernel(self): """Update actions following the execution state of the kernel.""" client = self.get_current_client() if client is not None: executing = client.stop_button.isEnabled() self.interrupt_action.setEnabled(executing)
[ "def", "update_execution_state_kernel", "(", "self", ")", ":", "client", "=", "self", ".", "get_current_client", "(", ")", "if", "client", "is", "not", "None", ":", "executing", "=", "client", ".", "stop_button", ".", "isEnabled", "(", ")", "self", ".", "interrupt_action", ".", "setEnabled", "(", "executing", ")" ]
Update actions following the execution state of the kernel.
[ "Update", "actions", "following", "the", "execution", "state", "of", "the", "kernel", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1222-L1227
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.connect_external_kernel
def connect_external_kernel(self, shellwidget): """ Connect an external kernel to the Variable Explorer and Help, if it is a Spyder kernel. """ sw = shellwidget kc = shellwidget.kernel_client if self.main.help is not None: self.main.help.set_shell(sw) if self.main.variableexplorer is not None: self.main.variableexplorer.add_shellwidget(sw) sw.set_namespace_view_settings() sw.refresh_namespacebrowser() kc.stopped_channels.connect(lambda : self.main.variableexplorer.remove_shellwidget(id(sw)))
python
def connect_external_kernel(self, shellwidget): """ Connect an external kernel to the Variable Explorer and Help, if it is a Spyder kernel. """ sw = shellwidget kc = shellwidget.kernel_client if self.main.help is not None: self.main.help.set_shell(sw) if self.main.variableexplorer is not None: self.main.variableexplorer.add_shellwidget(sw) sw.set_namespace_view_settings() sw.refresh_namespacebrowser() kc.stopped_channels.connect(lambda : self.main.variableexplorer.remove_shellwidget(id(sw)))
[ "def", "connect_external_kernel", "(", "self", ",", "shellwidget", ")", ":", "sw", "=", "shellwidget", "kc", "=", "shellwidget", ".", "kernel_client", "if", "self", ".", "main", ".", "help", "is", "not", "None", ":", "self", ".", "main", ".", "help", ".", "set_shell", "(", "sw", ")", "if", "self", ".", "main", ".", "variableexplorer", "is", "not", "None", ":", "self", ".", "main", ".", "variableexplorer", ".", "add_shellwidget", "(", "sw", ")", "sw", ".", "set_namespace_view_settings", "(", ")", "sw", ".", "refresh_namespacebrowser", "(", ")", "kc", ".", "stopped_channels", ".", "connect", "(", "lambda", ":", "self", ".", "main", ".", "variableexplorer", ".", "remove_shellwidget", "(", "id", "(", "sw", ")", ")", ")" ]
Connect an external kernel to the Variable Explorer and Help, if it is a Spyder kernel.
[ "Connect", "an", "external", "kernel", "to", "the", "Variable", "Explorer", "and", "Help", "if", "it", "is", "a", "Spyder", "kernel", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1229-L1243
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.add_tab
def add_tab(self, widget, name, filename=''): """Add tab""" self.clients.append(widget) index = self.tabwidget.addTab(widget, name) self.filenames.insert(index, filename) self.tabwidget.setCurrentIndex(index) if self.dockwidget and not self.main.is_setting_up: self.switch_to_plugin() self.activateWindow() widget.get_control().setFocus() self.update_tabs_text()
python
def add_tab(self, widget, name, filename=''): """Add tab""" self.clients.append(widget) index = self.tabwidget.addTab(widget, name) self.filenames.insert(index, filename) self.tabwidget.setCurrentIndex(index) if self.dockwidget and not self.main.is_setting_up: self.switch_to_plugin() self.activateWindow() widget.get_control().setFocus() self.update_tabs_text()
[ "def", "add_tab", "(", "self", ",", "widget", ",", "name", ",", "filename", "=", "''", ")", ":", "self", ".", "clients", ".", "append", "(", "widget", ")", "index", "=", "self", ".", "tabwidget", ".", "addTab", "(", "widget", ",", "name", ")", "self", ".", "filenames", ".", "insert", "(", "index", ",", "filename", ")", "self", ".", "tabwidget", ".", "setCurrentIndex", "(", "index", ")", "if", "self", ".", "dockwidget", "and", "not", "self", ".", "main", ".", "is_setting_up", ":", "self", ".", "switch_to_plugin", "(", ")", "self", ".", "activateWindow", "(", ")", "widget", ".", "get_control", "(", ")", ".", "setFocus", "(", ")", "self", ".", "update_tabs_text", "(", ")" ]
Add tab
[ "Add", "tab" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1246-L1256
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.move_tab
def move_tab(self, index_from, index_to): """ Move tab (tabs themselves have already been moved by the tabwidget) """ filename = self.filenames.pop(index_from) client = self.clients.pop(index_from) self.filenames.insert(index_to, filename) self.clients.insert(index_to, client) self.update_tabs_text() self.sig_update_plugin_title.emit()
python
def move_tab(self, index_from, index_to): """ Move tab (tabs themselves have already been moved by the tabwidget) """ filename = self.filenames.pop(index_from) client = self.clients.pop(index_from) self.filenames.insert(index_to, filename) self.clients.insert(index_to, client) self.update_tabs_text() self.sig_update_plugin_title.emit()
[ "def", "move_tab", "(", "self", ",", "index_from", ",", "index_to", ")", ":", "filename", "=", "self", ".", "filenames", ".", "pop", "(", "index_from", ")", "client", "=", "self", ".", "clients", ".", "pop", "(", "index_from", ")", "self", ".", "filenames", ".", "insert", "(", "index_to", ",", "filename", ")", "self", ".", "clients", ".", "insert", "(", "index_to", ",", "client", ")", "self", ".", "update_tabs_text", "(", ")", "self", ".", "sig_update_plugin_title", ".", "emit", "(", ")" ]
Move tab (tabs themselves have already been moved by the tabwidget)
[ "Move", "tab", "(", "tabs", "themselves", "have", "already", "been", "moved", "by", "the", "tabwidget", ")" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1258-L1267
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.disambiguate_fname
def disambiguate_fname(self, fname): """Generate a file name without ambiguation.""" files_path_list = [filename for filename in self.filenames if filename] return sourcecode.disambiguate_fname(files_path_list, fname)
python
def disambiguate_fname(self, fname): """Generate a file name without ambiguation.""" files_path_list = [filename for filename in self.filenames if filename] return sourcecode.disambiguate_fname(files_path_list, fname)
[ "def", "disambiguate_fname", "(", "self", ",", "fname", ")", ":", "files_path_list", "=", "[", "filename", "for", "filename", "in", "self", ".", "filenames", "if", "filename", "]", "return", "sourcecode", ".", "disambiguate_fname", "(", "files_path_list", ",", "fname", ")" ]
Generate a file name without ambiguation.
[ "Generate", "a", "file", "name", "without", "ambiguation", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1269-L1273
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.update_tabs_text
def update_tabs_text(self): """Update the text from the tabs.""" # This is needed to prevent that hanged consoles make reference # to an index that doesn't exist. See issue 4881 try: for index, fname in enumerate(self.filenames): client = self.clients[index] if fname: self.rename_client_tab(client, self.disambiguate_fname(fname)) else: self.rename_client_tab(client, None) except IndexError: pass
python
def update_tabs_text(self): """Update the text from the tabs.""" # This is needed to prevent that hanged consoles make reference # to an index that doesn't exist. See issue 4881 try: for index, fname in enumerate(self.filenames): client = self.clients[index] if fname: self.rename_client_tab(client, self.disambiguate_fname(fname)) else: self.rename_client_tab(client, None) except IndexError: pass
[ "def", "update_tabs_text", "(", "self", ")", ":", "# This is needed to prevent that hanged consoles make reference\r", "# to an index that doesn't exist. See issue 4881\r", "try", ":", "for", "index", ",", "fname", "in", "enumerate", "(", "self", ".", "filenames", ")", ":", "client", "=", "self", ".", "clients", "[", "index", "]", "if", "fname", ":", "self", ".", "rename_client_tab", "(", "client", ",", "self", ".", "disambiguate_fname", "(", "fname", ")", ")", "else", ":", "self", ".", "rename_client_tab", "(", "client", ",", "None", ")", "except", "IndexError", ":", "pass" ]
Update the text from the tabs.
[ "Update", "the", "text", "from", "the", "tabs", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1275-L1288
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.rename_client_tab
def rename_client_tab(self, client, given_name): """Rename client's tab""" index = self.get_client_index_from_id(id(client)) if given_name is not None: client.given_name = given_name self.tabwidget.setTabText(index, client.get_name())
python
def rename_client_tab(self, client, given_name): """Rename client's tab""" index = self.get_client_index_from_id(id(client)) if given_name is not None: client.given_name = given_name self.tabwidget.setTabText(index, client.get_name())
[ "def", "rename_client_tab", "(", "self", ",", "client", ",", "given_name", ")", ":", "index", "=", "self", ".", "get_client_index_from_id", "(", "id", "(", "client", ")", ")", "if", "given_name", "is", "not", "None", ":", "client", ".", "given_name", "=", "given_name", "self", ".", "tabwidget", ".", "setTabText", "(", "index", ",", "client", ".", "get_name", "(", ")", ")" ]
Rename client's tab
[ "Rename", "client", "s", "tab" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1290-L1296
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.rename_tabs_after_change
def rename_tabs_after_change(self, given_name): """Rename tabs after a change in name.""" client = self.get_current_client() # Prevent renames that want to assign the same name of # a previous tab repeated = False for cl in self.get_clients(): if id(client) != id(cl) and given_name == cl.given_name: repeated = True break # Rename current client tab to add str_id if client.allow_rename and not u'/' in given_name and not repeated: self.rename_client_tab(client, given_name) else: self.rename_client_tab(client, None) # Rename related clients if client.allow_rename and not u'/' in given_name and not repeated: for cl in self.get_related_clients(client): self.rename_client_tab(cl, given_name)
python
def rename_tabs_after_change(self, given_name): """Rename tabs after a change in name.""" client = self.get_current_client() # Prevent renames that want to assign the same name of # a previous tab repeated = False for cl in self.get_clients(): if id(client) != id(cl) and given_name == cl.given_name: repeated = True break # Rename current client tab to add str_id if client.allow_rename and not u'/' in given_name and not repeated: self.rename_client_tab(client, given_name) else: self.rename_client_tab(client, None) # Rename related clients if client.allow_rename and not u'/' in given_name and not repeated: for cl in self.get_related_clients(client): self.rename_client_tab(cl, given_name)
[ "def", "rename_tabs_after_change", "(", "self", ",", "given_name", ")", ":", "client", "=", "self", ".", "get_current_client", "(", ")", "# Prevent renames that want to assign the same name of\r", "# a previous tab\r", "repeated", "=", "False", "for", "cl", "in", "self", ".", "get_clients", "(", ")", ":", "if", "id", "(", "client", ")", "!=", "id", "(", "cl", ")", "and", "given_name", "==", "cl", ".", "given_name", ":", "repeated", "=", "True", "break", "# Rename current client tab to add str_id\r", "if", "client", ".", "allow_rename", "and", "not", "u'/'", "in", "given_name", "and", "not", "repeated", ":", "self", ".", "rename_client_tab", "(", "client", ",", "given_name", ")", "else", ":", "self", ".", "rename_client_tab", "(", "client", ",", "None", ")", "# Rename related clients\r", "if", "client", ".", "allow_rename", "and", "not", "u'/'", "in", "given_name", "and", "not", "repeated", ":", "for", "cl", "in", "self", ".", "get_related_clients", "(", "client", ")", ":", "self", ".", "rename_client_tab", "(", "cl", ",", "given_name", ")" ]
Rename tabs after a change in name.
[ "Rename", "tabs", "after", "a", "change", "in", "name", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1298-L1319
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.tab_name_editor
def tab_name_editor(self): """Trigger the tab name editor.""" index = self.tabwidget.currentIndex() self.tabwidget.tabBar().tab_name_editor.edit_tab(index)
python
def tab_name_editor(self): """Trigger the tab name editor.""" index = self.tabwidget.currentIndex() self.tabwidget.tabBar().tab_name_editor.edit_tab(index)
[ "def", "tab_name_editor", "(", "self", ")", ":", "index", "=", "self", ".", "tabwidget", ".", "currentIndex", "(", ")", "self", ".", "tabwidget", ".", "tabBar", "(", ")", ".", "tab_name_editor", ".", "edit_tab", "(", "index", ")" ]
Trigger the tab name editor.
[ "Trigger", "the", "tab", "name", "editor", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1321-L1324
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.go_to_error
def go_to_error(self, text): """Go to error if relevant""" match = get_error_match(to_text_string(text)) if match: fname, lnb = match.groups() if ("<ipython-input-" in fname and self.run_cell_filename is not None): fname = self.run_cell_filename self.edit_goto.emit(osp.abspath(fname), int(lnb), '')
python
def go_to_error(self, text): """Go to error if relevant""" match = get_error_match(to_text_string(text)) if match: fname, lnb = match.groups() if ("<ipython-input-" in fname and self.run_cell_filename is not None): fname = self.run_cell_filename self.edit_goto.emit(osp.abspath(fname), int(lnb), '')
[ "def", "go_to_error", "(", "self", ",", "text", ")", ":", "match", "=", "get_error_match", "(", "to_text_string", "(", "text", ")", ")", "if", "match", ":", "fname", ",", "lnb", "=", "match", ".", "groups", "(", ")", "if", "(", "\"<ipython-input-\"", "in", "fname", "and", "self", ".", "run_cell_filename", "is", "not", "None", ")", ":", "fname", "=", "self", ".", "run_cell_filename", "self", ".", "edit_goto", ".", "emit", "(", "osp", ".", "abspath", "(", "fname", ")", ",", "int", "(", "lnb", ")", ",", "''", ")" ]
Go to error if relevant
[ "Go", "to", "error", "if", "relevant" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1327-L1335
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.show_intro
def show_intro(self): """Show intro to IPython help""" from IPython.core.usage import interactive_usage self.main.help.show_rich_text(interactive_usage)
python
def show_intro(self): """Show intro to IPython help""" from IPython.core.usage import interactive_usage self.main.help.show_rich_text(interactive_usage)
[ "def", "show_intro", "(", "self", ")", ":", "from", "IPython", ".", "core", ".", "usage", "import", "interactive_usage", "self", ".", "main", ".", "help", ".", "show_rich_text", "(", "interactive_usage", ")" ]
Show intro to IPython help
[ "Show", "intro", "to", "IPython", "help" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1338-L1341
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.show_guiref
def show_guiref(self): """Show qtconsole help""" from qtconsole.usage import gui_reference self.main.help.show_rich_text(gui_reference, collapse=True)
python
def show_guiref(self): """Show qtconsole help""" from qtconsole.usage import gui_reference self.main.help.show_rich_text(gui_reference, collapse=True)
[ "def", "show_guiref", "(", "self", ")", ":", "from", "qtconsole", ".", "usage", "import", "gui_reference", "self", ".", "main", ".", "help", ".", "show_rich_text", "(", "gui_reference", ",", "collapse", "=", "True", ")" ]
Show qtconsole help
[ "Show", "qtconsole", "help" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1344-L1347
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole.show_quickref
def show_quickref(self): """Show IPython Cheat Sheet""" from IPython.core.usage import quick_reference self.main.help.show_plain_text(quick_reference)
python
def show_quickref(self): """Show IPython Cheat Sheet""" from IPython.core.usage import quick_reference self.main.help.show_plain_text(quick_reference)
[ "def", "show_quickref", "(", "self", ")", ":", "from", "IPython", ".", "core", ".", "usage", "import", "quick_reference", "self", ".", "main", ".", "help", ".", "show_plain_text", "(", "quick_reference", ")" ]
Show IPython Cheat Sheet
[ "Show", "IPython", "Cheat", "Sheet" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1350-L1353
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole._new_connection_file
def _new_connection_file(self): """ Generate a new connection file Taken from jupyter_client/console_app.py Licensed under the BSD license """ # Check if jupyter_runtime_dir exists (Spyder addition) if not osp.isdir(jupyter_runtime_dir()): try: os.makedirs(jupyter_runtime_dir()) except (IOError, OSError): return None cf = '' while not cf: ident = str(uuid.uuid4()).split('-')[-1] cf = os.path.join(jupyter_runtime_dir(), 'kernel-%s.json' % ident) cf = cf if not os.path.exists(cf) else '' return cf
python
def _new_connection_file(self): """ Generate a new connection file Taken from jupyter_client/console_app.py Licensed under the BSD license """ # Check if jupyter_runtime_dir exists (Spyder addition) if not osp.isdir(jupyter_runtime_dir()): try: os.makedirs(jupyter_runtime_dir()) except (IOError, OSError): return None cf = '' while not cf: ident = str(uuid.uuid4()).split('-')[-1] cf = os.path.join(jupyter_runtime_dir(), 'kernel-%s.json' % ident) cf = cf if not os.path.exists(cf) else '' return cf
[ "def", "_new_connection_file", "(", "self", ")", ":", "# Check if jupyter_runtime_dir exists (Spyder addition)\r", "if", "not", "osp", ".", "isdir", "(", "jupyter_runtime_dir", "(", ")", ")", ":", "try", ":", "os", ".", "makedirs", "(", "jupyter_runtime_dir", "(", ")", ")", "except", "(", "IOError", ",", "OSError", ")", ":", "return", "None", "cf", "=", "''", "while", "not", "cf", ":", "ident", "=", "str", "(", "uuid", ".", "uuid4", "(", ")", ")", ".", "split", "(", "'-'", ")", "[", "-", "1", "]", "cf", "=", "os", ".", "path", ".", "join", "(", "jupyter_runtime_dir", "(", ")", ",", "'kernel-%s.json'", "%", "ident", ")", "cf", "=", "cf", "if", "not", "os", ".", "path", ".", "exists", "(", "cf", ")", "else", "''", "return", "cf" ]
Generate a new connection file Taken from jupyter_client/console_app.py Licensed under the BSD license
[ "Generate", "a", "new", "connection", "file", "Taken", "from", "jupyter_client", "/", "console_app", ".", "py", "Licensed", "under", "the", "BSD", "license" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1356-L1374
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/plugin.py
IPythonConsole._remove_old_stderr_files
def _remove_old_stderr_files(self): """ Remove stderr files left by previous Spyder instances. This is only required on Windows because we can't clean up stderr files while Spyder is running on it. """ if os.name == 'nt': tmpdir = get_temp_dir() for fname in os.listdir(tmpdir): if osp.splitext(fname)[1] == '.stderr': try: os.remove(osp.join(tmpdir, fname)) except Exception: pass
python
def _remove_old_stderr_files(self): """ Remove stderr files left by previous Spyder instances. This is only required on Windows because we can't clean up stderr files while Spyder is running on it. """ if os.name == 'nt': tmpdir = get_temp_dir() for fname in os.listdir(tmpdir): if osp.splitext(fname)[1] == '.stderr': try: os.remove(osp.join(tmpdir, fname)) except Exception: pass
[ "def", "_remove_old_stderr_files", "(", "self", ")", ":", "if", "os", ".", "name", "==", "'nt'", ":", "tmpdir", "=", "get_temp_dir", "(", ")", "for", "fname", "in", "os", ".", "listdir", "(", "tmpdir", ")", ":", "if", "osp", ".", "splitext", "(", "fname", ")", "[", "1", "]", "==", "'.stderr'", ":", "try", ":", "os", ".", "remove", "(", "osp", ".", "join", "(", "tmpdir", ",", "fname", ")", ")", "except", "Exception", ":", "pass" ]
Remove stderr files left by previous Spyder instances. This is only required on Windows because we can't clean up stderr files while Spyder is running on it.
[ "Remove", "stderr", "files", "left", "by", "previous", "Spyder", "instances", ".", "This", "is", "only", "required", "on", "Windows", "because", "we", "can", "t", "clean", "up", "stderr", "files", "while", "Spyder", "is", "running", "on", "it", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/plugin.py#L1504-L1518
train
spyder-ide/spyder
spyder/plugins/editor/utils/kill_ring.py
KillRing.rotate
def rotate(self): """ Rotate the kill ring, then yank back the new top. Returns ------- A text string or None. """ self._index -= 1 if self._index >= 0: return self._ring[self._index] return None
python
def rotate(self): """ Rotate the kill ring, then yank back the new top. Returns ------- A text string or None. """ self._index -= 1 if self._index >= 0: return self._ring[self._index] return None
[ "def", "rotate", "(", "self", ")", ":", "self", ".", "_index", "-=", "1", "if", "self", ".", "_index", ">=", "0", ":", "return", "self", ".", "_ring", "[", "self", ".", "_index", "]", "return", "None" ]
Rotate the kill ring, then yank back the new top. Returns ------- A text string or None.
[ "Rotate", "the", "kill", "ring", "then", "yank", "back", "the", "new", "top", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/utils/kill_ring.py#L55-L65
train
spyder-ide/spyder
spyder/plugins/editor/utils/kill_ring.py
QtKillRing.kill_cursor
def kill_cursor(self, cursor): """ Kills the text selected by the give cursor. """ text = cursor.selectedText() if text: cursor.removeSelectedText() self.kill(text)
python
def kill_cursor(self, cursor): """ Kills the text selected by the give cursor. """ text = cursor.selectedText() if text: cursor.removeSelectedText() self.kill(text)
[ "def", "kill_cursor", "(", "self", ",", "cursor", ")", ":", "text", "=", "cursor", ".", "selectedText", "(", ")", "if", "text", ":", "cursor", ".", "removeSelectedText", "(", ")", "self", ".", "kill", "(", "text", ")" ]
Kills the text selected by the give cursor.
[ "Kills", "the", "text", "selected", "by", "the", "give", "cursor", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/utils/kill_ring.py#L100-L106
train
spyder-ide/spyder
spyder/plugins/editor/utils/kill_ring.py
QtKillRing.yank
def yank(self): """ Yank back the most recently killed text. """ text = self._ring.yank() if text: self._skip_cursor = True cursor = self._text_edit.textCursor() cursor.insertText(text) self._prev_yank = text
python
def yank(self): """ Yank back the most recently killed text. """ text = self._ring.yank() if text: self._skip_cursor = True cursor = self._text_edit.textCursor() cursor.insertText(text) self._prev_yank = text
[ "def", "yank", "(", "self", ")", ":", "text", "=", "self", ".", "_ring", ".", "yank", "(", ")", "if", "text", ":", "self", ".", "_skip_cursor", "=", "True", "cursor", "=", "self", ".", "_text_edit", ".", "textCursor", "(", ")", "cursor", ".", "insertText", "(", "text", ")", "self", ".", "_prev_yank", "=", "text" ]
Yank back the most recently killed text.
[ "Yank", "back", "the", "most", "recently", "killed", "text", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/utils/kill_ring.py#L108-L116
train
spyder-ide/spyder
spyder/plugins/explorer/widgets.py
show_in_external_file_explorer
def show_in_external_file_explorer(fnames=None): """Show files in external file explorer Args: fnames (list): Names of files to show. """ if not isinstance(fnames, (tuple, list)): fnames = [fnames] for fname in fnames: open_file_in_external_explorer(fname)
python
def show_in_external_file_explorer(fnames=None): """Show files in external file explorer Args: fnames (list): Names of files to show. """ if not isinstance(fnames, (tuple, list)): fnames = [fnames] for fname in fnames: open_file_in_external_explorer(fname)
[ "def", "show_in_external_file_explorer", "(", "fnames", "=", "None", ")", ":", "if", "not", "isinstance", "(", "fnames", ",", "(", "tuple", ",", "list", ")", ")", ":", "fnames", "=", "[", "fnames", "]", "for", "fname", "in", "fnames", ":", "open_file_in_external_explorer", "(", "fname", ")" ]
Show files in external file explorer Args: fnames (list): Names of files to show.
[ "Show", "files", "in", "external", "file", "explorer", "Args", ":", "fnames", "(", "list", ")", ":", "Names", "of", "files", "to", "show", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L60-L69
train
spyder-ide/spyder
spyder/plugins/explorer/widgets.py
fixpath
def fixpath(path): """Normalize path fixing case, making absolute and removing symlinks""" norm = osp.normcase if os.name == 'nt' else osp.normpath return norm(osp.abspath(osp.realpath(path)))
python
def fixpath(path): """Normalize path fixing case, making absolute and removing symlinks""" norm = osp.normcase if os.name == 'nt' else osp.normpath return norm(osp.abspath(osp.realpath(path)))
[ "def", "fixpath", "(", "path", ")", ":", "norm", "=", "osp", ".", "normcase", "if", "os", ".", "name", "==", "'nt'", "else", "osp", ".", "normpath", "return", "norm", "(", "osp", ".", "abspath", "(", "osp", ".", "realpath", "(", "path", ")", ")", ")" ]
Normalize path fixing case, making absolute and removing symlinks
[ "Normalize", "path", "fixing", "case", "making", "absolute", "and", "removing", "symlinks" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L71-L74
train
spyder-ide/spyder
spyder/plugins/explorer/widgets.py
create_script
def create_script(fname): """Create a new Python script""" text = os.linesep.join(["# -*- coding: utf-8 -*-", "", ""]) try: encoding.write(to_text_string(text), fname, 'utf-8') except EnvironmentError as error: QMessageBox.critical(_("Save Error"), _("<b>Unable to save file '%s'</b>" "<br><br>Error message:<br>%s" ) % (osp.basename(fname), str(error)))
python
def create_script(fname): """Create a new Python script""" text = os.linesep.join(["# -*- coding: utf-8 -*-", "", ""]) try: encoding.write(to_text_string(text), fname, 'utf-8') except EnvironmentError as error: QMessageBox.critical(_("Save Error"), _("<b>Unable to save file '%s'</b>" "<br><br>Error message:<br>%s" ) % (osp.basename(fname), str(error)))
[ "def", "create_script", "(", "fname", ")", ":", "text", "=", "os", ".", "linesep", ".", "join", "(", "[", "\"# -*- coding: utf-8 -*-\"", ",", "\"\"", ",", "\"\"", "]", ")", "try", ":", "encoding", ".", "write", "(", "to_text_string", "(", "text", ")", ",", "fname", ",", "'utf-8'", ")", "except", "EnvironmentError", "as", "error", ":", "QMessageBox", ".", "critical", "(", "_", "(", "\"Save Error\"", ")", ",", "_", "(", "\"<b>Unable to save file '%s'</b>\"", "\"<br><br>Error message:<br>%s\"", ")", "%", "(", "osp", ".", "basename", "(", "fname", ")", ",", "str", "(", "error", ")", ")", ")" ]
Create a new Python script
[ "Create", "a", "new", "Python", "script" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L77-L86
train
spyder-ide/spyder
spyder/plugins/explorer/widgets.py
listdir
def listdir(path, include=r'.', exclude=r'\.pyc$|^\.', show_all=False, folders_only=False): """List files and directories""" namelist = [] dirlist = [to_text_string(osp.pardir)] for item in os.listdir(to_text_string(path)): if re.search(exclude, item) and not show_all: continue if osp.isdir(osp.join(path, item)): dirlist.append(item) elif folders_only: continue elif re.search(include, item) or show_all: namelist.append(item) return sorted(dirlist, key=str_lower) + \ sorted(namelist, key=str_lower)
python
def listdir(path, include=r'.', exclude=r'\.pyc$|^\.', show_all=False, folders_only=False): """List files and directories""" namelist = [] dirlist = [to_text_string(osp.pardir)] for item in os.listdir(to_text_string(path)): if re.search(exclude, item) and not show_all: continue if osp.isdir(osp.join(path, item)): dirlist.append(item) elif folders_only: continue elif re.search(include, item) or show_all: namelist.append(item) return sorted(dirlist, key=str_lower) + \ sorted(namelist, key=str_lower)
[ "def", "listdir", "(", "path", ",", "include", "=", "r'.'", ",", "exclude", "=", "r'\\.pyc$|^\\.'", ",", "show_all", "=", "False", ",", "folders_only", "=", "False", ")", ":", "namelist", "=", "[", "]", "dirlist", "=", "[", "to_text_string", "(", "osp", ".", "pardir", ")", "]", "for", "item", "in", "os", ".", "listdir", "(", "to_text_string", "(", "path", ")", ")", ":", "if", "re", ".", "search", "(", "exclude", ",", "item", ")", "and", "not", "show_all", ":", "continue", "if", "osp", ".", "isdir", "(", "osp", ".", "join", "(", "path", ",", "item", ")", ")", ":", "dirlist", ".", "append", "(", "item", ")", "elif", "folders_only", ":", "continue", "elif", "re", ".", "search", "(", "include", ",", "item", ")", "or", "show_all", ":", "namelist", ".", "append", "(", "item", ")", "return", "sorted", "(", "dirlist", ",", "key", "=", "str_lower", ")", "+", "sorted", "(", "namelist", ",", "key", "=", "str_lower", ")" ]
List files and directories
[ "List", "files", "and", "directories" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L88-L103
train
spyder-ide/spyder
spyder/plugins/explorer/widgets.py
has_subdirectories
def has_subdirectories(path, include, exclude, show_all): """Return True if path has subdirectories""" try: # > 1 because of '..' return len( listdir(path, include, exclude, show_all, folders_only=True) ) > 1 except (IOError, OSError): return False
python
def has_subdirectories(path, include, exclude, show_all): """Return True if path has subdirectories""" try: # > 1 because of '..' return len( listdir(path, include, exclude, show_all, folders_only=True) ) > 1 except (IOError, OSError): return False
[ "def", "has_subdirectories", "(", "path", ",", "include", ",", "exclude", ",", "show_all", ")", ":", "try", ":", "# > 1 because of '..'\r", "return", "len", "(", "listdir", "(", "path", ",", "include", ",", "exclude", ",", "show_all", ",", "folders_only", "=", "True", ")", ")", ">", "1", "except", "(", "IOError", ",", "OSError", ")", ":", "return", "False" ]
Return True if path has subdirectories
[ "Return", "True", "if", "path", "has", "subdirectories" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L106-L113
train
spyder-ide/spyder
spyder/plugins/explorer/widgets.py
IconProvider.icon
def icon(self, icontype_or_qfileinfo): """Reimplement Qt method""" if isinstance(icontype_or_qfileinfo, QFileIconProvider.IconType): return super(IconProvider, self).icon(icontype_or_qfileinfo) else: qfileinfo = icontype_or_qfileinfo fname = osp.normpath(to_text_string(qfileinfo.absoluteFilePath())) return ima.get_icon_by_extension(fname, scale_factor=1.0)
python
def icon(self, icontype_or_qfileinfo): """Reimplement Qt method""" if isinstance(icontype_or_qfileinfo, QFileIconProvider.IconType): return super(IconProvider, self).icon(icontype_or_qfileinfo) else: qfileinfo = icontype_or_qfileinfo fname = osp.normpath(to_text_string(qfileinfo.absoluteFilePath())) return ima.get_icon_by_extension(fname, scale_factor=1.0)
[ "def", "icon", "(", "self", ",", "icontype_or_qfileinfo", ")", ":", "if", "isinstance", "(", "icontype_or_qfileinfo", ",", "QFileIconProvider", ".", "IconType", ")", ":", "return", "super", "(", "IconProvider", ",", "self", ")", ".", "icon", "(", "icontype_or_qfileinfo", ")", "else", ":", "qfileinfo", "=", "icontype_or_qfileinfo", "fname", "=", "osp", ".", "normpath", "(", "to_text_string", "(", "qfileinfo", ".", "absoluteFilePath", "(", ")", ")", ")", "return", "ima", ".", "get_icon_by_extension", "(", "fname", ",", "scale_factor", "=", "1.0", ")" ]
Reimplement Qt method
[ "Reimplement", "Qt", "method" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L125-L132
train
spyder-ide/spyder
spyder/plugins/explorer/widgets.py
DirView.setup_fs_model
def setup_fs_model(self): """Setup filesystem model""" filters = QDir.AllDirs | QDir.Files | QDir.Drives | QDir.NoDotAndDotDot self.fsmodel = QFileSystemModel(self) self.fsmodel.setFilter(filters) self.fsmodel.setNameFilterDisables(False)
python
def setup_fs_model(self): """Setup filesystem model""" filters = QDir.AllDirs | QDir.Files | QDir.Drives | QDir.NoDotAndDotDot self.fsmodel = QFileSystemModel(self) self.fsmodel.setFilter(filters) self.fsmodel.setNameFilterDisables(False)
[ "def", "setup_fs_model", "(", "self", ")", ":", "filters", "=", "QDir", ".", "AllDirs", "|", "QDir", ".", "Files", "|", "QDir", ".", "Drives", "|", "QDir", ".", "NoDotAndDotDot", "self", ".", "fsmodel", "=", "QFileSystemModel", "(", "self", ")", "self", ".", "fsmodel", ".", "setFilter", "(", "filters", ")", "self", ".", "fsmodel", ".", "setNameFilterDisables", "(", "False", ")" ]
Setup filesystem model
[ "Setup", "filesystem", "model" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L167-L172
train
spyder-ide/spyder
spyder/plugins/explorer/widgets.py
DirView.setup_view
def setup_view(self): """Setup view""" self.install_model() self.fsmodel.directoryLoaded.connect( lambda: self.resizeColumnToContents(0)) self.setAnimated(False) self.setSortingEnabled(True) self.sortByColumn(0, Qt.AscendingOrder) self.fsmodel.modelReset.connect(self.reset_icon_provider) self.reset_icon_provider() # Disable the view of .spyproject. self.filter_directories()
python
def setup_view(self): """Setup view""" self.install_model() self.fsmodel.directoryLoaded.connect( lambda: self.resizeColumnToContents(0)) self.setAnimated(False) self.setSortingEnabled(True) self.sortByColumn(0, Qt.AscendingOrder) self.fsmodel.modelReset.connect(self.reset_icon_provider) self.reset_icon_provider() # Disable the view of .spyproject. self.filter_directories()
[ "def", "setup_view", "(", "self", ")", ":", "self", ".", "install_model", "(", ")", "self", ".", "fsmodel", ".", "directoryLoaded", ".", "connect", "(", "lambda", ":", "self", ".", "resizeColumnToContents", "(", "0", ")", ")", "self", ".", "setAnimated", "(", "False", ")", "self", ".", "setSortingEnabled", "(", "True", ")", "self", ".", "sortByColumn", "(", "0", ",", "Qt", ".", "AscendingOrder", ")", "self", ".", "fsmodel", ".", "modelReset", ".", "connect", "(", "self", ".", "reset_icon_provider", ")", "self", ".", "reset_icon_provider", "(", ")", "# Disable the view of .spyproject. \r", "self", ".", "filter_directories", "(", ")" ]
Setup view
[ "Setup", "view" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L178-L189
train
spyder-ide/spyder
spyder/plugins/explorer/widgets.py
DirView.set_single_click_to_open
def set_single_click_to_open(self, value): """Set single click to open items.""" self.single_click_to_open = value self.parent_widget.sig_option_changed.emit('single_click_to_open', value)
python
def set_single_click_to_open(self, value): """Set single click to open items.""" self.single_click_to_open = value self.parent_widget.sig_option_changed.emit('single_click_to_open', value)
[ "def", "set_single_click_to_open", "(", "self", ",", "value", ")", ":", "self", ".", "single_click_to_open", "=", "value", "self", ".", "parent_widget", ".", "sig_option_changed", ".", "emit", "(", "'single_click_to_open'", ",", "value", ")" ]
Set single click to open items.
[ "Set", "single", "click", "to", "open", "items", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L191-L195
train
spyder-ide/spyder
spyder/plugins/explorer/widgets.py
DirView.set_name_filters
def set_name_filters(self, name_filters): """Set name filters""" self.name_filters = name_filters self.fsmodel.setNameFilters(name_filters)
python
def set_name_filters(self, name_filters): """Set name filters""" self.name_filters = name_filters self.fsmodel.setNameFilters(name_filters)
[ "def", "set_name_filters", "(", "self", ",", "name_filters", ")", ":", "self", ".", "name_filters", "=", "name_filters", "self", ".", "fsmodel", ".", "setNameFilters", "(", "name_filters", ")" ]
Set name filters
[ "Set", "name", "filters" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L197-L200
train
spyder-ide/spyder
spyder/plugins/explorer/widgets.py
DirView.set_show_all
def set_show_all(self, state): """Toggle 'show all files' state""" if state: self.fsmodel.setNameFilters([]) else: self.fsmodel.setNameFilters(self.name_filters)
python
def set_show_all(self, state): """Toggle 'show all files' state""" if state: self.fsmodel.setNameFilters([]) else: self.fsmodel.setNameFilters(self.name_filters)
[ "def", "set_show_all", "(", "self", ",", "state", ")", ":", "if", "state", ":", "self", ".", "fsmodel", ".", "setNameFilters", "(", "[", "]", ")", "else", ":", "self", ".", "fsmodel", ".", "setNameFilters", "(", "self", ".", "name_filters", ")" ]
Toggle 'show all files' state
[ "Toggle", "show", "all", "files", "state" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L202-L207
train
spyder-ide/spyder
spyder/plugins/explorer/widgets.py
DirView.get_filename
def get_filename(self, index): """Return filename associated with *index*""" if index: return osp.normpath(to_text_string(self.fsmodel.filePath(index)))
python
def get_filename(self, index): """Return filename associated with *index*""" if index: return osp.normpath(to_text_string(self.fsmodel.filePath(index)))
[ "def", "get_filename", "(", "self", ",", "index", ")", ":", "if", "index", ":", "return", "osp", ".", "normpath", "(", "to_text_string", "(", "self", ".", "fsmodel", ".", "filePath", "(", "index", ")", ")", ")" ]
Return filename associated with *index*
[ "Return", "filename", "associated", "with", "*", "index", "*" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L209-L212
train
spyder-ide/spyder
spyder/plugins/explorer/widgets.py
DirView.get_selected_filenames
def get_selected_filenames(self): """Return selected filenames""" if self.selectionMode() == self.ExtendedSelection: if self.selectionModel() is None: return [] return [self.get_filename(idx) for idx in self.selectionModel().selectedRows()] else: return [self.get_filename(self.currentIndex())]
python
def get_selected_filenames(self): """Return selected filenames""" if self.selectionMode() == self.ExtendedSelection: if self.selectionModel() is None: return [] return [self.get_filename(idx) for idx in self.selectionModel().selectedRows()] else: return [self.get_filename(self.currentIndex())]
[ "def", "get_selected_filenames", "(", "self", ")", ":", "if", "self", ".", "selectionMode", "(", ")", "==", "self", ".", "ExtendedSelection", ":", "if", "self", ".", "selectionModel", "(", ")", "is", "None", ":", "return", "[", "]", "return", "[", "self", ".", "get_filename", "(", "idx", ")", "for", "idx", "in", "self", ".", "selectionModel", "(", ")", ".", "selectedRows", "(", ")", "]", "else", ":", "return", "[", "self", ".", "get_filename", "(", "self", ".", "currentIndex", "(", ")", ")", "]" ]
Return selected filenames
[ "Return", "selected", "filenames" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L218-L226
train