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/widgets/fileswitcher.py
FileSwitcher.next_row
def next_row(self): """Select next row in list widget.""" if self.mode == self.SYMBOL_MODE: self.select_row(+1) return next_row = self.current_row() + 1 if next_row < self.count(): if '</b></big><br>' in self.list.item(next_row).text(): # Select the next next row, the one following is a title self.select_row(+2) else: self.select_row(+1)
python
def next_row(self): """Select next row in list widget.""" if self.mode == self.SYMBOL_MODE: self.select_row(+1) return next_row = self.current_row() + 1 if next_row < self.count(): if '</b></big><br>' in self.list.item(next_row).text(): # Select the next next row, the one following is a title self.select_row(+2) else: self.select_row(+1)
[ "def", "next_row", "(", "self", ")", ":", "if", "self", ".", "mode", "==", "self", ".", "SYMBOL_MODE", ":", "self", ".", "select_row", "(", "+", "1", ")", "return", "next_row", "=", "self", ".", "current_row", "(", ")", "+", "1", "if", "next_row", "<", "self", ".", "count", "(", ")", ":", "if", "'</b></big><br>'", "in", "self", ".", "list", ".", "item", "(", "next_row", ")", ".", "text", "(", ")", ":", "# Select the next next row, the one following is a title", "self", ".", "select_row", "(", "+", "2", ")", "else", ":", "self", ".", "select_row", "(", "+", "1", ")" ]
Select next row in list widget.
[ "Select", "next", "row", "in", "list", "widget", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L520-L531
train
spyder-ide/spyder
spyder/widgets/fileswitcher.py
FileSwitcher.get_stack_index
def get_stack_index(self, stack_index, plugin_index): """Get the real index of the selected item.""" other_plugins_count = sum([other_tabs[0].count() \ for other_tabs in \ self.plugins_tabs[:plugin_index]]) real_index = stack_index - other_plugins_count return real_index
python
def get_stack_index(self, stack_index, plugin_index): """Get the real index of the selected item.""" other_plugins_count = sum([other_tabs[0].count() \ for other_tabs in \ self.plugins_tabs[:plugin_index]]) real_index = stack_index - other_plugins_count return real_index
[ "def", "get_stack_index", "(", "self", ",", "stack_index", ",", "plugin_index", ")", ":", "other_plugins_count", "=", "sum", "(", "[", "other_tabs", "[", "0", "]", ".", "count", "(", ")", "for", "other_tabs", "in", "self", ".", "plugins_tabs", "[", ":", "plugin_index", "]", "]", ")", "real_index", "=", "stack_index", "-", "other_plugins_count", "return", "real_index" ]
Get the real index of the selected item.
[ "Get", "the", "real", "index", "of", "the", "selected", "item", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L533-L540
train
spyder-ide/spyder
spyder/widgets/fileswitcher.py
FileSwitcher.get_plugin_data
def get_plugin_data(self, plugin): """Get the data object of the plugin's current tab manager.""" # The data object is named "data" in the editor plugin while it is # named "clients" in the notebook plugin. try: data = plugin.get_current_tab_manager().data except AttributeError: data = plugin.get_current_tab_manager().clients return data
python
def get_plugin_data(self, plugin): """Get the data object of the plugin's current tab manager.""" # The data object is named "data" in the editor plugin while it is # named "clients" in the notebook plugin. try: data = plugin.get_current_tab_manager().data except AttributeError: data = plugin.get_current_tab_manager().clients return data
[ "def", "get_plugin_data", "(", "self", ",", "plugin", ")", ":", "# The data object is named \"data\" in the editor plugin while it is", "# named \"clients\" in the notebook plugin.", "try", ":", "data", "=", "plugin", ".", "get_current_tab_manager", "(", ")", ".", "data", "except", "AttributeError", ":", "data", "=", "plugin", ".", "get_current_tab_manager", "(", ")", ".", "clients", "return", "data" ]
Get the data object of the plugin's current tab manager.
[ "Get", "the", "data", "object", "of", "the", "plugin", "s", "current", "tab", "manager", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L543-L552
train
spyder-ide/spyder
spyder/widgets/fileswitcher.py
FileSwitcher.get_plugin_tabwidget
def get_plugin_tabwidget(self, plugin): """Get the tabwidget of the plugin's current tab manager.""" # The tab widget is named "tabs" in the editor plugin while it is # named "tabwidget" in the notebook plugin. try: tabwidget = plugin.get_current_tab_manager().tabs except AttributeError: tabwidget = plugin.get_current_tab_manager().tabwidget return tabwidget
python
def get_plugin_tabwidget(self, plugin): """Get the tabwidget of the plugin's current tab manager.""" # The tab widget is named "tabs" in the editor plugin while it is # named "tabwidget" in the notebook plugin. try: tabwidget = plugin.get_current_tab_manager().tabs except AttributeError: tabwidget = plugin.get_current_tab_manager().tabwidget return tabwidget
[ "def", "get_plugin_tabwidget", "(", "self", ",", "plugin", ")", ":", "# The tab widget is named \"tabs\" in the editor plugin while it is", "# named \"tabwidget\" in the notebook plugin.", "try", ":", "tabwidget", "=", "plugin", ".", "get_current_tab_manager", "(", ")", ".", "tabs", "except", "AttributeError", ":", "tabwidget", "=", "plugin", ".", "get_current_tab_manager", "(", ")", ".", "tabwidget", "return", "tabwidget" ]
Get the tabwidget of the plugin's current tab manager.
[ "Get", "the", "tabwidget", "of", "the", "plugin", "s", "current", "tab", "manager", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L554-L563
train
spyder-ide/spyder
spyder/widgets/fileswitcher.py
FileSwitcher.get_widget
def get_widget(self, index=None, path=None, tabs=None): """Get widget by index. If no tabs and index specified the current active widget is returned. """ if (index and tabs) or (path and tabs): return tabs.widget(index) elif self.plugin: return self.get_plugin_tabwidget(self.plugin).currentWidget() else: return self.plugins_tabs[0][0].currentWidget()
python
def get_widget(self, index=None, path=None, tabs=None): """Get widget by index. If no tabs and index specified the current active widget is returned. """ if (index and tabs) or (path and tabs): return tabs.widget(index) elif self.plugin: return self.get_plugin_tabwidget(self.plugin).currentWidget() else: return self.plugins_tabs[0][0].currentWidget()
[ "def", "get_widget", "(", "self", ",", "index", "=", "None", ",", "path", "=", "None", ",", "tabs", "=", "None", ")", ":", "if", "(", "index", "and", "tabs", ")", "or", "(", "path", "and", "tabs", ")", ":", "return", "tabs", ".", "widget", "(", "index", ")", "elif", "self", ".", "plugin", ":", "return", "self", ".", "get_plugin_tabwidget", "(", "self", ".", "plugin", ")", ".", "currentWidget", "(", ")", "else", ":", "return", "self", ".", "plugins_tabs", "[", "0", "]", "[", "0", "]", ".", "currentWidget", "(", ")" ]
Get widget by index. If no tabs and index specified the current active widget is returned.
[ "Get", "widget", "by", "index", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L565-L575
train
spyder-ide/spyder
spyder/widgets/fileswitcher.py
FileSwitcher.set_editor_cursor
def set_editor_cursor(self, editor, cursor): """Set the cursor of an editor.""" pos = cursor.position() anchor = cursor.anchor() new_cursor = QTextCursor() if pos == anchor: new_cursor.movePosition(pos) else: new_cursor.movePosition(anchor) new_cursor.movePosition(pos, QTextCursor.KeepAnchor) editor.setTextCursor(cursor)
python
def set_editor_cursor(self, editor, cursor): """Set the cursor of an editor.""" pos = cursor.position() anchor = cursor.anchor() new_cursor = QTextCursor() if pos == anchor: new_cursor.movePosition(pos) else: new_cursor.movePosition(anchor) new_cursor.movePosition(pos, QTextCursor.KeepAnchor) editor.setTextCursor(cursor)
[ "def", "set_editor_cursor", "(", "self", ",", "editor", ",", "cursor", ")", ":", "pos", "=", "cursor", ".", "position", "(", ")", "anchor", "=", "cursor", ".", "anchor", "(", ")", "new_cursor", "=", "QTextCursor", "(", ")", "if", "pos", "==", "anchor", ":", "new_cursor", ".", "movePosition", "(", "pos", ")", "else", ":", "new_cursor", ".", "movePosition", "(", "anchor", ")", "new_cursor", ".", "movePosition", "(", "pos", ",", "QTextCursor", ".", "KeepAnchor", ")", "editor", ".", "setTextCursor", "(", "cursor", ")" ]
Set the cursor of an editor.
[ "Set", "the", "cursor", "of", "an", "editor", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L577-L588
train
spyder-ide/spyder
spyder/widgets/fileswitcher.py
FileSwitcher.goto_line
def goto_line(self, line_number): """Go to specified line number in current active editor.""" if line_number: line_number = int(line_number) try: self.plugin.go_to_line(line_number) except AttributeError: pass
python
def goto_line(self, line_number): """Go to specified line number in current active editor.""" if line_number: line_number = int(line_number) try: self.plugin.go_to_line(line_number) except AttributeError: pass
[ "def", "goto_line", "(", "self", ",", "line_number", ")", ":", "if", "line_number", ":", "line_number", "=", "int", "(", "line_number", ")", "try", ":", "self", ".", "plugin", ".", "go_to_line", "(", "line_number", ")", "except", "AttributeError", ":", "pass" ]
Go to specified line number in current active editor.
[ "Go", "to", "specified", "line", "number", "in", "current", "active", "editor", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L590-L597
train
spyder-ide/spyder
spyder/widgets/fileswitcher.py
FileSwitcher.item_selection_changed
def item_selection_changed(self): """List widget item selection change handler.""" row = self.current_row() if self.count() and row >= 0: if '</b></big><br>' in self.list.currentItem().text() and row == 0: self.next_row() if self.mode == self.FILE_MODE: try: stack_index = self.paths.index(self.filtered_path[row]) self.plugin = self.widgets[stack_index][1] self.goto_line(self.line_number) try: self.plugin.switch_to_plugin() self.raise_() except AttributeError: # The widget using the fileswitcher is not a plugin pass self.edit.setFocus() except ValueError: pass else: line_number = self.filtered_symbol_lines[row] self.goto_line(line_number)
python
def item_selection_changed(self): """List widget item selection change handler.""" row = self.current_row() if self.count() and row >= 0: if '</b></big><br>' in self.list.currentItem().text() and row == 0: self.next_row() if self.mode == self.FILE_MODE: try: stack_index = self.paths.index(self.filtered_path[row]) self.plugin = self.widgets[stack_index][1] self.goto_line(self.line_number) try: self.plugin.switch_to_plugin() self.raise_() except AttributeError: # The widget using the fileswitcher is not a plugin pass self.edit.setFocus() except ValueError: pass else: line_number = self.filtered_symbol_lines[row] self.goto_line(line_number)
[ "def", "item_selection_changed", "(", "self", ")", ":", "row", "=", "self", ".", "current_row", "(", ")", "if", "self", ".", "count", "(", ")", "and", "row", ">=", "0", ":", "if", "'</b></big><br>'", "in", "self", ".", "list", ".", "currentItem", "(", ")", ".", "text", "(", ")", "and", "row", "==", "0", ":", "self", ".", "next_row", "(", ")", "if", "self", ".", "mode", "==", "self", ".", "FILE_MODE", ":", "try", ":", "stack_index", "=", "self", ".", "paths", ".", "index", "(", "self", ".", "filtered_path", "[", "row", "]", ")", "self", ".", "plugin", "=", "self", ".", "widgets", "[", "stack_index", "]", "[", "1", "]", "self", ".", "goto_line", "(", "self", ".", "line_number", ")", "try", ":", "self", ".", "plugin", ".", "switch_to_plugin", "(", ")", "self", ".", "raise_", "(", ")", "except", "AttributeError", ":", "# The widget using the fileswitcher is not a plugin", "pass", "self", ".", "edit", ".", "setFocus", "(", ")", "except", "ValueError", ":", "pass", "else", ":", "line_number", "=", "self", ".", "filtered_symbol_lines", "[", "row", "]", "self", ".", "goto_line", "(", "line_number", ")" ]
List widget item selection change handler.
[ "List", "widget", "item", "selection", "change", "handler", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L609-L631
train
spyder-ide/spyder
spyder/widgets/fileswitcher.py
FileSwitcher.setup_file_list
def setup_file_list(self, filter_text, current_path): """Setup list widget content for file list display.""" short_paths = shorten_paths(self.paths, self.save_status) paths = self.paths icons = self.icons results = [] trying_for_line_number = ':' in filter_text # Get optional line number if trying_for_line_number: filter_text, line_number = filter_text.split(':') if line_number == '': line_number = None # Get all the available filenames scores = get_search_scores('', self.filenames, template="<b>{0}</b>") else: line_number = None # Get all available filenames and get the scores for # "fuzzy" matching scores = get_search_scores(filter_text, self.filenames, template="<b>{0}</b>") # Get max width to determine if shortpaths should be used max_width = self.get_item_size(paths)[0] self.fix_size(paths) # Build the text that will appear on the list widget rich_font = CONF.get('appearance', 'rich_font/size', 10) if sys.platform == 'darwin': path_text_font_size = rich_font filename_text_font_size = path_text_font_size + 2 elif os.name == 'nt': path_text_font_size = rich_font filename_text_font_size = path_text_font_size + 1 elif is_ubuntu(): path_text_font_size = rich_font - 2 filename_text_font_size = path_text_font_size + 1 else: path_text_font_size = rich_font filename_text_font_size = path_text_font_size + 1 for index, score in enumerate(scores): text, rich_text, score_value = score if score_value != -1: text_item = ("<span style='color:{0:}; font-size:{1:}pt'>{2:}" "</span>").format(ima.MAIN_FG_COLOR, filename_text_font_size, rich_text.replace('&', '')) if trying_for_line_number: text_item += " [{0:} {1:}]".format(self.line_count[index], _("lines")) if max_width > self.list.width(): text_item += (u" &nbsp; <span style='color:{0:};" "font-size:{1:}pt'>{2:}" "</span>").format(self.PATH_FG_COLOR, path_text_font_size, short_paths[index]) else: text_item += (u" &nbsp; <span style='color:{0:};" "font-size:{1:}pt'>{2:}" "</span>").format(self.PATH_FG_COLOR, path_text_font_size, paths[index]) if (trying_for_line_number and self.line_count[index] != 0 or not trying_for_line_number): results.append((score_value, index, text_item)) # Sort the obtained scores and populate the list widget self.filtered_path = [] plugin = None for result in sorted(results): index = result[1] path = paths[index] if sys.platform == 'darwin': scale_factor = 0.9 elif os.name == 'nt': scale_factor = 0.8 elif is_ubuntu(): scale_factor = 0.6 else: scale_factor = 0.9 icon = ima.get_icon_by_extension(path, scale_factor) text = '' try: title = self.widgets[index][1].get_plugin_title().split(' - ') if plugin != title[0]: plugin = title[0] text += ("<br><big style='color:{0:}'>" "<b>{1:}</b></big><br>").format(ima.MAIN_FG_COLOR, plugin) item = QListWidgetItem(text) item.setToolTip(path) item.setSizeHint(QSize(0, 25)) item.setFlags(Qt.ItemIsEditable) self.list.addItem(item) self.filtered_path.append(path) except: # The widget using the fileswitcher is not a plugin pass text = '' text += result[-1] item = QListWidgetItem(icon, text) item.setToolTip(path) item.setSizeHint(QSize(0, 25)) self.list.addItem(item) self.filtered_path.append(path) # To adjust the delegate layout for KDE themes self.list.files_list = True # Move selected item in list accordingly and update list size if current_path in self.filtered_path: self.set_current_row(self.filtered_path.index(current_path)) elif self.filtered_path: self.set_current_row(0) # If a line number is searched look for it self.line_number = line_number self.goto_line(line_number)
python
def setup_file_list(self, filter_text, current_path): """Setup list widget content for file list display.""" short_paths = shorten_paths(self.paths, self.save_status) paths = self.paths icons = self.icons results = [] trying_for_line_number = ':' in filter_text # Get optional line number if trying_for_line_number: filter_text, line_number = filter_text.split(':') if line_number == '': line_number = None # Get all the available filenames scores = get_search_scores('', self.filenames, template="<b>{0}</b>") else: line_number = None # Get all available filenames and get the scores for # "fuzzy" matching scores = get_search_scores(filter_text, self.filenames, template="<b>{0}</b>") # Get max width to determine if shortpaths should be used max_width = self.get_item_size(paths)[0] self.fix_size(paths) # Build the text that will appear on the list widget rich_font = CONF.get('appearance', 'rich_font/size', 10) if sys.platform == 'darwin': path_text_font_size = rich_font filename_text_font_size = path_text_font_size + 2 elif os.name == 'nt': path_text_font_size = rich_font filename_text_font_size = path_text_font_size + 1 elif is_ubuntu(): path_text_font_size = rich_font - 2 filename_text_font_size = path_text_font_size + 1 else: path_text_font_size = rich_font filename_text_font_size = path_text_font_size + 1 for index, score in enumerate(scores): text, rich_text, score_value = score if score_value != -1: text_item = ("<span style='color:{0:}; font-size:{1:}pt'>{2:}" "</span>").format(ima.MAIN_FG_COLOR, filename_text_font_size, rich_text.replace('&', '')) if trying_for_line_number: text_item += " [{0:} {1:}]".format(self.line_count[index], _("lines")) if max_width > self.list.width(): text_item += (u" &nbsp; <span style='color:{0:};" "font-size:{1:}pt'>{2:}" "</span>").format(self.PATH_FG_COLOR, path_text_font_size, short_paths[index]) else: text_item += (u" &nbsp; <span style='color:{0:};" "font-size:{1:}pt'>{2:}" "</span>").format(self.PATH_FG_COLOR, path_text_font_size, paths[index]) if (trying_for_line_number and self.line_count[index] != 0 or not trying_for_line_number): results.append((score_value, index, text_item)) # Sort the obtained scores and populate the list widget self.filtered_path = [] plugin = None for result in sorted(results): index = result[1] path = paths[index] if sys.platform == 'darwin': scale_factor = 0.9 elif os.name == 'nt': scale_factor = 0.8 elif is_ubuntu(): scale_factor = 0.6 else: scale_factor = 0.9 icon = ima.get_icon_by_extension(path, scale_factor) text = '' try: title = self.widgets[index][1].get_plugin_title().split(' - ') if plugin != title[0]: plugin = title[0] text += ("<br><big style='color:{0:}'>" "<b>{1:}</b></big><br>").format(ima.MAIN_FG_COLOR, plugin) item = QListWidgetItem(text) item.setToolTip(path) item.setSizeHint(QSize(0, 25)) item.setFlags(Qt.ItemIsEditable) self.list.addItem(item) self.filtered_path.append(path) except: # The widget using the fileswitcher is not a plugin pass text = '' text += result[-1] item = QListWidgetItem(icon, text) item.setToolTip(path) item.setSizeHint(QSize(0, 25)) self.list.addItem(item) self.filtered_path.append(path) # To adjust the delegate layout for KDE themes self.list.files_list = True # Move selected item in list accordingly and update list size if current_path in self.filtered_path: self.set_current_row(self.filtered_path.index(current_path)) elif self.filtered_path: self.set_current_row(0) # If a line number is searched look for it self.line_number = line_number self.goto_line(line_number)
[ "def", "setup_file_list", "(", "self", ",", "filter_text", ",", "current_path", ")", ":", "short_paths", "=", "shorten_paths", "(", "self", ".", "paths", ",", "self", ".", "save_status", ")", "paths", "=", "self", ".", "paths", "icons", "=", "self", ".", "icons", "results", "=", "[", "]", "trying_for_line_number", "=", "':'", "in", "filter_text", "# Get optional line number", "if", "trying_for_line_number", ":", "filter_text", ",", "line_number", "=", "filter_text", ".", "split", "(", "':'", ")", "if", "line_number", "==", "''", ":", "line_number", "=", "None", "# Get all the available filenames", "scores", "=", "get_search_scores", "(", "''", ",", "self", ".", "filenames", ",", "template", "=", "\"<b>{0}</b>\"", ")", "else", ":", "line_number", "=", "None", "# Get all available filenames and get the scores for", "# \"fuzzy\" matching", "scores", "=", "get_search_scores", "(", "filter_text", ",", "self", ".", "filenames", ",", "template", "=", "\"<b>{0}</b>\"", ")", "# Get max width to determine if shortpaths should be used", "max_width", "=", "self", ".", "get_item_size", "(", "paths", ")", "[", "0", "]", "self", ".", "fix_size", "(", "paths", ")", "# Build the text that will appear on the list widget", "rich_font", "=", "CONF", ".", "get", "(", "'appearance'", ",", "'rich_font/size'", ",", "10", ")", "if", "sys", ".", "platform", "==", "'darwin'", ":", "path_text_font_size", "=", "rich_font", "filename_text_font_size", "=", "path_text_font_size", "+", "2", "elif", "os", ".", "name", "==", "'nt'", ":", "path_text_font_size", "=", "rich_font", "filename_text_font_size", "=", "path_text_font_size", "+", "1", "elif", "is_ubuntu", "(", ")", ":", "path_text_font_size", "=", "rich_font", "-", "2", "filename_text_font_size", "=", "path_text_font_size", "+", "1", "else", ":", "path_text_font_size", "=", "rich_font", "filename_text_font_size", "=", "path_text_font_size", "+", "1", "for", "index", ",", "score", "in", "enumerate", "(", "scores", ")", ":", "text", ",", "rich_text", ",", "score_value", "=", "score", "if", "score_value", "!=", "-", "1", ":", "text_item", "=", "(", "\"<span style='color:{0:}; font-size:{1:}pt'>{2:}\"", "\"</span>\"", ")", ".", "format", "(", "ima", ".", "MAIN_FG_COLOR", ",", "filename_text_font_size", ",", "rich_text", ".", "replace", "(", "'&'", ",", "''", ")", ")", "if", "trying_for_line_number", ":", "text_item", "+=", "\" [{0:} {1:}]\"", ".", "format", "(", "self", ".", "line_count", "[", "index", "]", ",", "_", "(", "\"lines\"", ")", ")", "if", "max_width", ">", "self", ".", "list", ".", "width", "(", ")", ":", "text_item", "+=", "(", "u\" &nbsp; <span style='color:{0:};\"", "\"font-size:{1:}pt'>{2:}\"", "\"</span>\"", ")", ".", "format", "(", "self", ".", "PATH_FG_COLOR", ",", "path_text_font_size", ",", "short_paths", "[", "index", "]", ")", "else", ":", "text_item", "+=", "(", "u\" &nbsp; <span style='color:{0:};\"", "\"font-size:{1:}pt'>{2:}\"", "\"</span>\"", ")", ".", "format", "(", "self", ".", "PATH_FG_COLOR", ",", "path_text_font_size", ",", "paths", "[", "index", "]", ")", "if", "(", "trying_for_line_number", "and", "self", ".", "line_count", "[", "index", "]", "!=", "0", "or", "not", "trying_for_line_number", ")", ":", "results", ".", "append", "(", "(", "score_value", ",", "index", ",", "text_item", ")", ")", "# Sort the obtained scores and populate the list widget", "self", ".", "filtered_path", "=", "[", "]", "plugin", "=", "None", "for", "result", "in", "sorted", "(", "results", ")", ":", "index", "=", "result", "[", "1", "]", "path", "=", "paths", "[", "index", "]", "if", "sys", ".", "platform", "==", "'darwin'", ":", "scale_factor", "=", "0.9", "elif", "os", ".", "name", "==", "'nt'", ":", "scale_factor", "=", "0.8", "elif", "is_ubuntu", "(", ")", ":", "scale_factor", "=", "0.6", "else", ":", "scale_factor", "=", "0.9", "icon", "=", "ima", ".", "get_icon_by_extension", "(", "path", ",", "scale_factor", ")", "text", "=", "''", "try", ":", "title", "=", "self", ".", "widgets", "[", "index", "]", "[", "1", "]", ".", "get_plugin_title", "(", ")", ".", "split", "(", "' - '", ")", "if", "plugin", "!=", "title", "[", "0", "]", ":", "plugin", "=", "title", "[", "0", "]", "text", "+=", "(", "\"<br><big style='color:{0:}'>\"", "\"<b>{1:}</b></big><br>\"", ")", ".", "format", "(", "ima", ".", "MAIN_FG_COLOR", ",", "plugin", ")", "item", "=", "QListWidgetItem", "(", "text", ")", "item", ".", "setToolTip", "(", "path", ")", "item", ".", "setSizeHint", "(", "QSize", "(", "0", ",", "25", ")", ")", "item", ".", "setFlags", "(", "Qt", ".", "ItemIsEditable", ")", "self", ".", "list", ".", "addItem", "(", "item", ")", "self", ".", "filtered_path", ".", "append", "(", "path", ")", "except", ":", "# The widget using the fileswitcher is not a plugin", "pass", "text", "=", "''", "text", "+=", "result", "[", "-", "1", "]", "item", "=", "QListWidgetItem", "(", "icon", ",", "text", ")", "item", ".", "setToolTip", "(", "path", ")", "item", ".", "setSizeHint", "(", "QSize", "(", "0", ",", "25", ")", ")", "self", ".", "list", ".", "addItem", "(", "item", ")", "self", ".", "filtered_path", ".", "append", "(", "path", ")", "# To adjust the delegate layout for KDE themes", "self", ".", "list", ".", "files_list", "=", "True", "# Move selected item in list accordingly and update list size", "if", "current_path", "in", "self", ".", "filtered_path", ":", "self", ".", "set_current_row", "(", "self", ".", "filtered_path", ".", "index", "(", "current_path", ")", ")", "elif", "self", ".", "filtered_path", ":", "self", ".", "set_current_row", "(", "0", ")", "# If a line number is searched look for it", "self", ".", "line_number", "=", "line_number", "self", ".", "goto_line", "(", "line_number", ")" ]
Setup list widget content for file list display.
[ "Setup", "list", "widget", "content", "for", "file", "list", "display", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L648-L767
train
spyder-ide/spyder
spyder/widgets/fileswitcher.py
FileSwitcher.setup_symbol_list
def setup_symbol_list(self, filter_text, current_path): """Setup list widget content for symbol list display.""" # Get optional symbol name filter_text, symbol_text = filter_text.split('@') # Fetch the Outline explorer data, get the icons and values oedata = self.get_symbol_list() icons = get_python_symbol_icons(oedata) # The list of paths here is needed in order to have the same # point of measurement for the list widget size as in the file list # See issue 4648 paths = self.paths # Update list size self.fix_size(paths) symbol_list = process_python_symbol_data(oedata) line_fold_token = [(item[0], item[2], item[3]) for item in symbol_list] choices = [item[1] for item in symbol_list] scores = get_search_scores(symbol_text, choices, template="<b>{0}</b>") # Build the text that will appear on the list widget results = [] lines = [] self.filtered_symbol_lines = [] for index, score in enumerate(scores): text, rich_text, score_value = score line, fold_level, token = line_fold_token[index] lines.append(text) if score_value != -1: results.append((score_value, line, text, rich_text, fold_level, icons[index], token)) template = '{{0}}<span style="color:{0}">{{1}}</span>'.format( ima.MAIN_FG_COLOR) for (score, line, text, rich_text, fold_level, icon, token) in sorted(results): fold_space = '&nbsp;'*(fold_level) line_number = line + 1 self.filtered_symbol_lines.append(line_number) textline = template.format(fold_space, rich_text) item = QListWidgetItem(icon, textline) item.setSizeHint(QSize(0, 16)) self.list.addItem(item) # To adjust the delegate layout for KDE themes self.list.files_list = False # Select edit line when using symbol search initially. # See issue 5661 self.edit.setFocus()
python
def setup_symbol_list(self, filter_text, current_path): """Setup list widget content for symbol list display.""" # Get optional symbol name filter_text, symbol_text = filter_text.split('@') # Fetch the Outline explorer data, get the icons and values oedata = self.get_symbol_list() icons = get_python_symbol_icons(oedata) # The list of paths here is needed in order to have the same # point of measurement for the list widget size as in the file list # See issue 4648 paths = self.paths # Update list size self.fix_size(paths) symbol_list = process_python_symbol_data(oedata) line_fold_token = [(item[0], item[2], item[3]) for item in symbol_list] choices = [item[1] for item in symbol_list] scores = get_search_scores(symbol_text, choices, template="<b>{0}</b>") # Build the text that will appear on the list widget results = [] lines = [] self.filtered_symbol_lines = [] for index, score in enumerate(scores): text, rich_text, score_value = score line, fold_level, token = line_fold_token[index] lines.append(text) if score_value != -1: results.append((score_value, line, text, rich_text, fold_level, icons[index], token)) template = '{{0}}<span style="color:{0}">{{1}}</span>'.format( ima.MAIN_FG_COLOR) for (score, line, text, rich_text, fold_level, icon, token) in sorted(results): fold_space = '&nbsp;'*(fold_level) line_number = line + 1 self.filtered_symbol_lines.append(line_number) textline = template.format(fold_space, rich_text) item = QListWidgetItem(icon, textline) item.setSizeHint(QSize(0, 16)) self.list.addItem(item) # To adjust the delegate layout for KDE themes self.list.files_list = False # Select edit line when using symbol search initially. # See issue 5661 self.edit.setFocus()
[ "def", "setup_symbol_list", "(", "self", ",", "filter_text", ",", "current_path", ")", ":", "# Get optional symbol name", "filter_text", ",", "symbol_text", "=", "filter_text", ".", "split", "(", "'@'", ")", "# Fetch the Outline explorer data, get the icons and values", "oedata", "=", "self", ".", "get_symbol_list", "(", ")", "icons", "=", "get_python_symbol_icons", "(", "oedata", ")", "# The list of paths here is needed in order to have the same", "# point of measurement for the list widget size as in the file list", "# See issue 4648", "paths", "=", "self", ".", "paths", "# Update list size", "self", ".", "fix_size", "(", "paths", ")", "symbol_list", "=", "process_python_symbol_data", "(", "oedata", ")", "line_fold_token", "=", "[", "(", "item", "[", "0", "]", ",", "item", "[", "2", "]", ",", "item", "[", "3", "]", ")", "for", "item", "in", "symbol_list", "]", "choices", "=", "[", "item", "[", "1", "]", "for", "item", "in", "symbol_list", "]", "scores", "=", "get_search_scores", "(", "symbol_text", ",", "choices", ",", "template", "=", "\"<b>{0}</b>\"", ")", "# Build the text that will appear on the list widget", "results", "=", "[", "]", "lines", "=", "[", "]", "self", ".", "filtered_symbol_lines", "=", "[", "]", "for", "index", ",", "score", "in", "enumerate", "(", "scores", ")", ":", "text", ",", "rich_text", ",", "score_value", "=", "score", "line", ",", "fold_level", ",", "token", "=", "line_fold_token", "[", "index", "]", "lines", ".", "append", "(", "text", ")", "if", "score_value", "!=", "-", "1", ":", "results", ".", "append", "(", "(", "score_value", ",", "line", ",", "text", ",", "rich_text", ",", "fold_level", ",", "icons", "[", "index", "]", ",", "token", ")", ")", "template", "=", "'{{0}}<span style=\"color:{0}\">{{1}}</span>'", ".", "format", "(", "ima", ".", "MAIN_FG_COLOR", ")", "for", "(", "score", ",", "line", ",", "text", ",", "rich_text", ",", "fold_level", ",", "icon", ",", "token", ")", "in", "sorted", "(", "results", ")", ":", "fold_space", "=", "'&nbsp;'", "*", "(", "fold_level", ")", "line_number", "=", "line", "+", "1", "self", ".", "filtered_symbol_lines", ".", "append", "(", "line_number", ")", "textline", "=", "template", ".", "format", "(", "fold_space", ",", "rich_text", ")", "item", "=", "QListWidgetItem", "(", "icon", ",", "textline", ")", "item", ".", "setSizeHint", "(", "QSize", "(", "0", ",", "16", ")", ")", "self", ".", "list", ".", "addItem", "(", "item", ")", "# To adjust the delegate layout for KDE themes", "self", ".", "list", ".", "files_list", "=", "False", "# Select edit line when using symbol search initially.", "# See issue 5661", "self", ".", "edit", ".", "setFocus", "(", ")" ]
Setup list widget content for symbol list display.
[ "Setup", "list", "widget", "content", "for", "symbol", "list", "display", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L769-L820
train
spyder-ide/spyder
spyder/widgets/fileswitcher.py
FileSwitcher.setup
def setup(self): """Setup list widget content.""" if len(self.plugins_tabs) == 0: self.close() return self.list.clear() current_path = self.current_path filter_text = self.filter_text # Get optional line or symbol to define mode and method handler trying_for_symbol = ('@' in self.filter_text) if trying_for_symbol: self.mode = self.SYMBOL_MODE self.setup_symbol_list(filter_text, current_path) else: self.mode = self.FILE_MODE self.setup_file_list(filter_text, current_path) # Set position according to size self.set_dialog_position()
python
def setup(self): """Setup list widget content.""" if len(self.plugins_tabs) == 0: self.close() return self.list.clear() current_path = self.current_path filter_text = self.filter_text # Get optional line or symbol to define mode and method handler trying_for_symbol = ('@' in self.filter_text) if trying_for_symbol: self.mode = self.SYMBOL_MODE self.setup_symbol_list(filter_text, current_path) else: self.mode = self.FILE_MODE self.setup_file_list(filter_text, current_path) # Set position according to size self.set_dialog_position()
[ "def", "setup", "(", "self", ")", ":", "if", "len", "(", "self", ".", "plugins_tabs", ")", "==", "0", ":", "self", ".", "close", "(", ")", "return", "self", ".", "list", ".", "clear", "(", ")", "current_path", "=", "self", ".", "current_path", "filter_text", "=", "self", ".", "filter_text", "# Get optional line or symbol to define mode and method handler", "trying_for_symbol", "=", "(", "'@'", "in", "self", ".", "filter_text", ")", "if", "trying_for_symbol", ":", "self", ".", "mode", "=", "self", ".", "SYMBOL_MODE", "self", ".", "setup_symbol_list", "(", "filter_text", ",", "current_path", ")", "else", ":", "self", ".", "mode", "=", "self", ".", "FILE_MODE", "self", ".", "setup_file_list", "(", "filter_text", ",", "current_path", ")", "# Set position according to size", "self", ".", "set_dialog_position", "(", ")" ]
Setup list widget content.
[ "Setup", "list", "widget", "content", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L831-L852
train
spyder-ide/spyder
spyder/widgets/fileswitcher.py
FileSwitcher.add_plugin
def add_plugin(self, plugin, tabs, data, icon): """Add a plugin to display its files.""" self.plugins_tabs.append((tabs, plugin)) self.plugins_data.append((data, icon)) self.plugins_instances.append(plugin)
python
def add_plugin(self, plugin, tabs, data, icon): """Add a plugin to display its files.""" self.plugins_tabs.append((tabs, plugin)) self.plugins_data.append((data, icon)) self.plugins_instances.append(plugin)
[ "def", "add_plugin", "(", "self", ",", "plugin", ",", "tabs", ",", "data", ",", "icon", ")", ":", "self", ".", "plugins_tabs", ".", "append", "(", "(", "tabs", ",", "plugin", ")", ")", "self", ".", "plugins_data", ".", "append", "(", "(", "data", ",", "icon", ")", ")", "self", ".", "plugins_instances", ".", "append", "(", "plugin", ")" ]
Add a plugin to display its files.
[ "Add", "a", "plugin", "to", "display", "its", "files", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/fileswitcher.py#L862-L866
train
spyder-ide/spyder
spyder/utils/external/binaryornot/check.py
is_binary
def is_binary(filename): """ :param filename: File to check. :returns: True if it's a binary file, otherwise False. """ logger.debug('is_binary: %(filename)r', locals()) # Check if the file extension is in a list of known binary types binary_extensions = ['pyc', 'iso', 'zip', 'pdf'] for ext in binary_extensions: if filename.endswith(ext): return True # Check if the starting chunk is a binary string chunk = get_starting_chunk(filename) return is_binary_string(chunk)
python
def is_binary(filename): """ :param filename: File to check. :returns: True if it's a binary file, otherwise False. """ logger.debug('is_binary: %(filename)r', locals()) # Check if the file extension is in a list of known binary types binary_extensions = ['pyc', 'iso', 'zip', 'pdf'] for ext in binary_extensions: if filename.endswith(ext): return True # Check if the starting chunk is a binary string chunk = get_starting_chunk(filename) return is_binary_string(chunk)
[ "def", "is_binary", "(", "filename", ")", ":", "logger", ".", "debug", "(", "'is_binary: %(filename)r'", ",", "locals", "(", ")", ")", "# Check if the file extension is in a list of known binary types", "binary_extensions", "=", "[", "'pyc'", ",", "'iso'", ",", "'zip'", ",", "'pdf'", "]", "for", "ext", "in", "binary_extensions", ":", "if", "filename", ".", "endswith", "(", "ext", ")", ":", "return", "True", "# Check if the starting chunk is a binary string", "chunk", "=", "get_starting_chunk", "(", "filename", ")", "return", "is_binary_string", "(", "chunk", ")" ]
:param filename: File to check. :returns: True if it's a binary file, otherwise False.
[ ":", "param", "filename", ":", "File", "to", "check", ".", ":", "returns", ":", "True", "if", "it", "s", "a", "binary", "file", "otherwise", "False", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/external/binaryornot/check.py#L28-L43
train
spyder-ide/spyder
spyder/utils/vcs.py
get_vcs_info
def get_vcs_info(path): """Return support status dict if path is under VCS root""" for info in SUPPORTED: vcs_path = osp.join(path, info['rootdir']) if osp.isdir(vcs_path): return info
python
def get_vcs_info(path): """Return support status dict if path is under VCS root""" for info in SUPPORTED: vcs_path = osp.join(path, info['rootdir']) if osp.isdir(vcs_path): return info
[ "def", "get_vcs_info", "(", "path", ")", ":", "for", "info", "in", "SUPPORTED", ":", "vcs_path", "=", "osp", ".", "join", "(", "path", ",", "info", "[", "'rootdir'", "]", ")", "if", "osp", ".", "isdir", "(", "vcs_path", ")", ":", "return", "info" ]
Return support status dict if path is under VCS root
[ "Return", "support", "status", "dict", "if", "path", "is", "under", "VCS", "root" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/vcs.py#L52-L57
train
spyder-ide/spyder
spyder/utils/vcs.py
get_vcs_root
def get_vcs_root(path): """Return VCS root directory path Return None if path is not within a supported VCS repository""" previous_path = path while get_vcs_info(path) is None: path = abspardir(path) if path == previous_path: return else: previous_path = path return osp.abspath(path)
python
def get_vcs_root(path): """Return VCS root directory path Return None if path is not within a supported VCS repository""" previous_path = path while get_vcs_info(path) is None: path = abspardir(path) if path == previous_path: return else: previous_path = path return osp.abspath(path)
[ "def", "get_vcs_root", "(", "path", ")", ":", "previous_path", "=", "path", "while", "get_vcs_info", "(", "path", ")", "is", "None", ":", "path", "=", "abspardir", "(", "path", ")", "if", "path", "==", "previous_path", ":", "return", "else", ":", "previous_path", "=", "path", "return", "osp", ".", "abspath", "(", "path", ")" ]
Return VCS root directory path Return None if path is not within a supported VCS repository
[ "Return", "VCS", "root", "directory", "path", "Return", "None", "if", "path", "is", "not", "within", "a", "supported", "VCS", "repository" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/vcs.py#L60-L70
train
spyder-ide/spyder
spyder/utils/vcs.py
run_vcs_tool
def run_vcs_tool(path, action): """If path is a valid VCS repository, run the corresponding VCS tool Supported VCS actions: 'commit', 'browse' Return False if the VCS tool is not installed""" info = get_vcs_info(get_vcs_root(path)) tools = info['actions'][action] for tool, args in tools: if programs.find_program(tool): if not running_under_pytest(): programs.run_program(tool, args, cwd=path) else: return True return else: cmdnames = [name for name, args in tools] raise ActionToolNotFound(info['name'], action, cmdnames)
python
def run_vcs_tool(path, action): """If path is a valid VCS repository, run the corresponding VCS tool Supported VCS actions: 'commit', 'browse' Return False if the VCS tool is not installed""" info = get_vcs_info(get_vcs_root(path)) tools = info['actions'][action] for tool, args in tools: if programs.find_program(tool): if not running_under_pytest(): programs.run_program(tool, args, cwd=path) else: return True return else: cmdnames = [name for name, args in tools] raise ActionToolNotFound(info['name'], action, cmdnames)
[ "def", "run_vcs_tool", "(", "path", ",", "action", ")", ":", "info", "=", "get_vcs_info", "(", "get_vcs_root", "(", "path", ")", ")", "tools", "=", "info", "[", "'actions'", "]", "[", "action", "]", "for", "tool", ",", "args", "in", "tools", ":", "if", "programs", ".", "find_program", "(", "tool", ")", ":", "if", "not", "running_under_pytest", "(", ")", ":", "programs", ".", "run_program", "(", "tool", ",", "args", ",", "cwd", "=", "path", ")", "else", ":", "return", "True", "return", "else", ":", "cmdnames", "=", "[", "name", "for", "name", ",", "args", "in", "tools", "]", "raise", "ActionToolNotFound", "(", "info", "[", "'name'", "]", ",", "action", ",", "cmdnames", ")" ]
If path is a valid VCS repository, run the corresponding VCS tool Supported VCS actions: 'commit', 'browse' Return False if the VCS tool is not installed
[ "If", "path", "is", "a", "valid", "VCS", "repository", "run", "the", "corresponding", "VCS", "tool", "Supported", "VCS", "actions", ":", "commit", "browse", "Return", "False", "if", "the", "VCS", "tool", "is", "not", "installed" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/vcs.py#L78-L93
train
spyder-ide/spyder
spyder/utils/vcs.py
get_hg_revision
def get_hg_revision(repopath): """Return Mercurial revision for the repository located at repopath Result is a tuple (global, local, branch), with None values on error For example: >>> get_hg_revision(".") ('eba7273c69df+', '2015+', 'default') """ try: assert osp.isdir(osp.join(repopath, '.hg')) proc = programs.run_program('hg', ['id', '-nib', repopath]) output, _err = proc.communicate() # output is now: ('eba7273c69df+ 2015+ default\n', None) # Split 2 times max to allow spaces in branch names. return tuple(output.decode().strip().split(None, 2)) except (subprocess.CalledProcessError, AssertionError, AttributeError, OSError): return (None, None, None)
python
def get_hg_revision(repopath): """Return Mercurial revision for the repository located at repopath Result is a tuple (global, local, branch), with None values on error For example: >>> get_hg_revision(".") ('eba7273c69df+', '2015+', 'default') """ try: assert osp.isdir(osp.join(repopath, '.hg')) proc = programs.run_program('hg', ['id', '-nib', repopath]) output, _err = proc.communicate() # output is now: ('eba7273c69df+ 2015+ default\n', None) # Split 2 times max to allow spaces in branch names. return tuple(output.decode().strip().split(None, 2)) except (subprocess.CalledProcessError, AssertionError, AttributeError, OSError): return (None, None, None)
[ "def", "get_hg_revision", "(", "repopath", ")", ":", "try", ":", "assert", "osp", ".", "isdir", "(", "osp", ".", "join", "(", "repopath", ",", "'.hg'", ")", ")", "proc", "=", "programs", ".", "run_program", "(", "'hg'", ",", "[", "'id'", ",", "'-nib'", ",", "repopath", "]", ")", "output", ",", "_err", "=", "proc", ".", "communicate", "(", ")", "# output is now: ('eba7273c69df+ 2015+ default\\n', None)\r", "# Split 2 times max to allow spaces in branch names.\r", "return", "tuple", "(", "output", ".", "decode", "(", ")", ".", "strip", "(", ")", ".", "split", "(", "None", ",", "2", ")", ")", "except", "(", "subprocess", ".", "CalledProcessError", ",", "AssertionError", ",", "AttributeError", ",", "OSError", ")", ":", "return", "(", "None", ",", "None", ",", "None", ")" ]
Return Mercurial revision for the repository located at repopath Result is a tuple (global, local, branch), with None values on error For example: >>> get_hg_revision(".") ('eba7273c69df+', '2015+', 'default')
[ "Return", "Mercurial", "revision", "for", "the", "repository", "located", "at", "repopath", "Result", "is", "a", "tuple", "(", "global", "local", "branch", ")", "with", "None", "values", "on", "error", "For", "example", ":", ">>>", "get_hg_revision", "(", ".", ")", "(", "eba7273c69df", "+", "2015", "+", "default", ")" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/vcs.py#L100-L116
train
spyder-ide/spyder
spyder/utils/vcs.py
get_git_revision
def get_git_revision(repopath): """ Return Git revision for the repository located at repopath Result is a tuple (latest commit hash, branch), with None values on error """ try: git = programs.find_program('git') assert git is not None and osp.isdir(osp.join(repopath, '.git')) commit = programs.run_program(git, ['rev-parse', '--short', 'HEAD'], cwd=repopath).communicate() commit = commit[0].strip() if PY3: commit = commit.decode(sys.getdefaultencoding()) # Branch branches = programs.run_program(git, ['branch'], cwd=repopath).communicate() branches = branches[0] if PY3: branches = branches.decode(sys.getdefaultencoding()) branches = branches.split('\n') active_branch = [b for b in branches if b.startswith('*')] if len(active_branch) != 1: branch = None else: branch = active_branch[0].split(None, 1)[1] return commit, branch except (subprocess.CalledProcessError, AssertionError, AttributeError, OSError): return None, None
python
def get_git_revision(repopath): """ Return Git revision for the repository located at repopath Result is a tuple (latest commit hash, branch), with None values on error """ try: git = programs.find_program('git') assert git is not None and osp.isdir(osp.join(repopath, '.git')) commit = programs.run_program(git, ['rev-parse', '--short', 'HEAD'], cwd=repopath).communicate() commit = commit[0].strip() if PY3: commit = commit.decode(sys.getdefaultencoding()) # Branch branches = programs.run_program(git, ['branch'], cwd=repopath).communicate() branches = branches[0] if PY3: branches = branches.decode(sys.getdefaultencoding()) branches = branches.split('\n') active_branch = [b for b in branches if b.startswith('*')] if len(active_branch) != 1: branch = None else: branch = active_branch[0].split(None, 1)[1] return commit, branch except (subprocess.CalledProcessError, AssertionError, AttributeError, OSError): return None, None
[ "def", "get_git_revision", "(", "repopath", ")", ":", "try", ":", "git", "=", "programs", ".", "find_program", "(", "'git'", ")", "assert", "git", "is", "not", "None", "and", "osp", ".", "isdir", "(", "osp", ".", "join", "(", "repopath", ",", "'.git'", ")", ")", "commit", "=", "programs", ".", "run_program", "(", "git", ",", "[", "'rev-parse'", ",", "'--short'", ",", "'HEAD'", "]", ",", "cwd", "=", "repopath", ")", ".", "communicate", "(", ")", "commit", "=", "commit", "[", "0", "]", ".", "strip", "(", ")", "if", "PY3", ":", "commit", "=", "commit", ".", "decode", "(", "sys", ".", "getdefaultencoding", "(", ")", ")", "# Branch\r", "branches", "=", "programs", ".", "run_program", "(", "git", ",", "[", "'branch'", "]", ",", "cwd", "=", "repopath", ")", ".", "communicate", "(", ")", "branches", "=", "branches", "[", "0", "]", "if", "PY3", ":", "branches", "=", "branches", ".", "decode", "(", "sys", ".", "getdefaultencoding", "(", ")", ")", "branches", "=", "branches", ".", "split", "(", "'\\n'", ")", "active_branch", "=", "[", "b", "for", "b", "in", "branches", "if", "b", ".", "startswith", "(", "'*'", ")", "]", "if", "len", "(", "active_branch", ")", "!=", "1", ":", "branch", "=", "None", "else", ":", "branch", "=", "active_branch", "[", "0", "]", ".", "split", "(", "None", ",", "1", ")", "[", "1", "]", "return", "commit", ",", "branch", "except", "(", "subprocess", ".", "CalledProcessError", ",", "AssertionError", ",", "AttributeError", ",", "OSError", ")", ":", "return", "None", ",", "None" ]
Return Git revision for the repository located at repopath Result is a tuple (latest commit hash, branch), with None values on error
[ "Return", "Git", "revision", "for", "the", "repository", "located", "at", "repopath", "Result", "is", "a", "tuple", "(", "latest", "commit", "hash", "branch", ")", "with", "None", "values", "on", "error" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/vcs.py#L119-L151
train
spyder-ide/spyder
spyder/utils/vcs.py
get_git_refs
def get_git_refs(repopath): """ Return Git active branch, state, branches (plus tags). """ tags = [] branches = [] branch = '' files_modifed = [] if os.path.isfile(repopath): repopath = os.path.dirname(repopath) try: git = programs.find_program('git') # Files modified out, err = programs.run_program( git, ['status', '-s'], cwd=repopath, ).communicate() if PY3: out = out.decode(sys.getdefaultencoding()) files_modifed = [line.strip() for line in out.split('\n') if line] # Tags out, err = programs.run_program( git, ['tag'], cwd=repopath, ).communicate() if PY3: out = out.decode(sys.getdefaultencoding()) tags = [line.strip() for line in out.split('\n') if line] # Branches out, err = programs.run_program( git, ['branch', '-a'], cwd=repopath, ).communicate() if PY3: out = out.decode(sys.getdefaultencoding()) lines = [line.strip() for line in out.split('\n') if line] for line in lines: if line.startswith('*'): line = line.replace('*', '').strip() branch = line branches.append(line) except (subprocess.CalledProcessError, AttributeError, OSError): pass return branches + tags, branch, files_modifed
python
def get_git_refs(repopath): """ Return Git active branch, state, branches (plus tags). """ tags = [] branches = [] branch = '' files_modifed = [] if os.path.isfile(repopath): repopath = os.path.dirname(repopath) try: git = programs.find_program('git') # Files modified out, err = programs.run_program( git, ['status', '-s'], cwd=repopath, ).communicate() if PY3: out = out.decode(sys.getdefaultencoding()) files_modifed = [line.strip() for line in out.split('\n') if line] # Tags out, err = programs.run_program( git, ['tag'], cwd=repopath, ).communicate() if PY3: out = out.decode(sys.getdefaultencoding()) tags = [line.strip() for line in out.split('\n') if line] # Branches out, err = programs.run_program( git, ['branch', '-a'], cwd=repopath, ).communicate() if PY3: out = out.decode(sys.getdefaultencoding()) lines = [line.strip() for line in out.split('\n') if line] for line in lines: if line.startswith('*'): line = line.replace('*', '').strip() branch = line branches.append(line) except (subprocess.CalledProcessError, AttributeError, OSError): pass return branches + tags, branch, files_modifed
[ "def", "get_git_refs", "(", "repopath", ")", ":", "tags", "=", "[", "]", "branches", "=", "[", "]", "branch", "=", "''", "files_modifed", "=", "[", "]", "if", "os", ".", "path", ".", "isfile", "(", "repopath", ")", ":", "repopath", "=", "os", ".", "path", ".", "dirname", "(", "repopath", ")", "try", ":", "git", "=", "programs", ".", "find_program", "(", "'git'", ")", "# Files modified\r", "out", ",", "err", "=", "programs", ".", "run_program", "(", "git", ",", "[", "'status'", ",", "'-s'", "]", ",", "cwd", "=", "repopath", ",", ")", ".", "communicate", "(", ")", "if", "PY3", ":", "out", "=", "out", ".", "decode", "(", "sys", ".", "getdefaultencoding", "(", ")", ")", "files_modifed", "=", "[", "line", ".", "strip", "(", ")", "for", "line", "in", "out", ".", "split", "(", "'\\n'", ")", "if", "line", "]", "# Tags\r", "out", ",", "err", "=", "programs", ".", "run_program", "(", "git", ",", "[", "'tag'", "]", ",", "cwd", "=", "repopath", ",", ")", ".", "communicate", "(", ")", "if", "PY3", ":", "out", "=", "out", ".", "decode", "(", "sys", ".", "getdefaultencoding", "(", ")", ")", "tags", "=", "[", "line", ".", "strip", "(", ")", "for", "line", "in", "out", ".", "split", "(", "'\\n'", ")", "if", "line", "]", "# Branches\r", "out", ",", "err", "=", "programs", ".", "run_program", "(", "git", ",", "[", "'branch'", ",", "'-a'", "]", ",", "cwd", "=", "repopath", ",", ")", ".", "communicate", "(", ")", "if", "PY3", ":", "out", "=", "out", ".", "decode", "(", "sys", ".", "getdefaultencoding", "(", ")", ")", "lines", "=", "[", "line", ".", "strip", "(", ")", "for", "line", "in", "out", ".", "split", "(", "'\\n'", ")", "if", "line", "]", "for", "line", "in", "lines", ":", "if", "line", ".", "startswith", "(", "'*'", ")", ":", "line", "=", "line", ".", "replace", "(", "'*'", ",", "''", ")", ".", "strip", "(", ")", "branch", "=", "line", "branches", ".", "append", "(", "line", ")", "except", "(", "subprocess", ".", "CalledProcessError", ",", "AttributeError", ",", "OSError", ")", ":", "pass", "return", "branches", "+", "tags", ",", "branch", ",", "files_modifed" ]
Return Git active branch, state, branches (plus tags).
[ "Return", "Git", "active", "branch", "state", "branches", "(", "plus", "tags", ")", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/vcs.py#L154-L210
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
is_module_or_package
def is_module_or_package(path): """Return True if path is a Python module/package""" is_module = osp.isfile(path) and osp.splitext(path)[1] in ('.py', '.pyw') is_package = osp.isdir(path) and osp.isfile(osp.join(path, '__init__.py')) return is_module or is_package
python
def is_module_or_package(path): """Return True if path is a Python module/package""" is_module = osp.isfile(path) and osp.splitext(path)[1] in ('.py', '.pyw') is_package = osp.isdir(path) and osp.isfile(osp.join(path, '__init__.py')) return is_module or is_package
[ "def", "is_module_or_package", "(", "path", ")", ":", "is_module", "=", "osp", ".", "isfile", "(", "path", ")", "and", "osp", ".", "splitext", "(", "path", ")", "[", "1", "]", "in", "(", "'.py'", ",", "'.pyw'", ")", "is_package", "=", "osp", ".", "isdir", "(", "path", ")", "and", "osp", ".", "isfile", "(", "osp", ".", "join", "(", "path", ",", "'__init__.py'", ")", ")", "return", "is_module", "or", "is_package" ]
Return True if path is a Python module/package
[ "Return", "True", "if", "path", "is", "a", "Python", "module", "/", "package" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L336-L340
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
BaseComboBox.event
def event(self, event): """Qt Override. Filter tab keys and process double tab keys. """ if (event.type() == QEvent.KeyPress) and (event.key() == Qt.Key_Tab): self.sig_tab_pressed.emit(True) self.numpress += 1 if self.numpress == 1: self.presstimer = QTimer.singleShot(400, self.handle_keypress) return True return QComboBox.event(self, event)
python
def event(self, event): """Qt Override. Filter tab keys and process double tab keys. """ if (event.type() == QEvent.KeyPress) and (event.key() == Qt.Key_Tab): self.sig_tab_pressed.emit(True) self.numpress += 1 if self.numpress == 1: self.presstimer = QTimer.singleShot(400, self.handle_keypress) return True return QComboBox.event(self, event)
[ "def", "event", "(", "self", ",", "event", ")", ":", "if", "(", "event", ".", "type", "(", ")", "==", "QEvent", ".", "KeyPress", ")", "and", "(", "event", ".", "key", "(", ")", "==", "Qt", ".", "Key_Tab", ")", ":", "self", ".", "sig_tab_pressed", ".", "emit", "(", "True", ")", "self", ".", "numpress", "+=", "1", "if", "self", ".", "numpress", "==", "1", ":", "self", ".", "presstimer", "=", "QTimer", ".", "singleShot", "(", "400", ",", "self", ".", "handle_keypress", ")", "return", "True", "return", "QComboBox", ".", "event", "(", "self", ",", "event", ")" ]
Qt Override. Filter tab keys and process double tab keys.
[ "Qt", "Override", ".", "Filter", "tab", "keys", "and", "process", "double", "tab", "keys", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L46-L57
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
BaseComboBox.keyPressEvent
def keyPressEvent(self, event): """Qt Override. Handle key press events. """ if event.key() == Qt.Key_Return or event.key() == Qt.Key_Enter: if self.add_current_text_if_valid(): self.selected() self.hide_completer() elif event.key() == Qt.Key_Escape: self.set_current_text(self.selected_text) self.hide_completer() else: QComboBox.keyPressEvent(self, event)
python
def keyPressEvent(self, event): """Qt Override. Handle key press events. """ if event.key() == Qt.Key_Return or event.key() == Qt.Key_Enter: if self.add_current_text_if_valid(): self.selected() self.hide_completer() elif event.key() == Qt.Key_Escape: self.set_current_text(self.selected_text) self.hide_completer() else: QComboBox.keyPressEvent(self, event)
[ "def", "keyPressEvent", "(", "self", ",", "event", ")", ":", "if", "event", ".", "key", "(", ")", "==", "Qt", ".", "Key_Return", "or", "event", ".", "key", "(", ")", "==", "Qt", ".", "Key_Enter", ":", "if", "self", ".", "add_current_text_if_valid", "(", ")", ":", "self", ".", "selected", "(", ")", "self", ".", "hide_completer", "(", ")", "elif", "event", ".", "key", "(", ")", "==", "Qt", ".", "Key_Escape", ":", "self", ".", "set_current_text", "(", "self", ".", "selected_text", ")", "self", ".", "hide_completer", "(", ")", "else", ":", "QComboBox", ".", "keyPressEvent", "(", "self", ",", "event", ")" ]
Qt Override. Handle key press events.
[ "Qt", "Override", ".", "Handle", "key", "press", "events", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L59-L72
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
BaseComboBox.handle_keypress
def handle_keypress(self): """When hitting tab, it handles if single or double tab""" if self.numpress == 2: self.sig_double_tab_pressed.emit(True) self.numpress = 0
python
def handle_keypress(self): """When hitting tab, it handles if single or double tab""" if self.numpress == 2: self.sig_double_tab_pressed.emit(True) self.numpress = 0
[ "def", "handle_keypress", "(", "self", ")", ":", "if", "self", ".", "numpress", "==", "2", ":", "self", ".", "sig_double_tab_pressed", ".", "emit", "(", "True", ")", "self", ".", "numpress", "=", "0" ]
When hitting tab, it handles if single or double tab
[ "When", "hitting", "tab", "it", "handles", "if", "single", "or", "double", "tab" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L75-L79
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
BaseComboBox.add_text
def add_text(self, text): """Add text to combo box: add a new item if text is not found in combo box items.""" index = self.findText(text) while index != -1: self.removeItem(index) index = self.findText(text) self.insertItem(0, text) index = self.findText('') if index != -1: self.removeItem(index) self.insertItem(0, '') if text != '': self.setCurrentIndex(1) else: self.setCurrentIndex(0) else: self.setCurrentIndex(0)
python
def add_text(self, text): """Add text to combo box: add a new item if text is not found in combo box items.""" index = self.findText(text) while index != -1: self.removeItem(index) index = self.findText(text) self.insertItem(0, text) index = self.findText('') if index != -1: self.removeItem(index) self.insertItem(0, '') if text != '': self.setCurrentIndex(1) else: self.setCurrentIndex(0) else: self.setCurrentIndex(0)
[ "def", "add_text", "(", "self", ",", "text", ")", ":", "index", "=", "self", ".", "findText", "(", "text", ")", "while", "index", "!=", "-", "1", ":", "self", ".", "removeItem", "(", "index", ")", "index", "=", "self", ".", "findText", "(", "text", ")", "self", ".", "insertItem", "(", "0", ",", "text", ")", "index", "=", "self", ".", "findText", "(", "''", ")", "if", "index", "!=", "-", "1", ":", "self", ".", "removeItem", "(", "index", ")", "self", ".", "insertItem", "(", "0", ",", "''", ")", "if", "text", "!=", "''", ":", "self", ".", "setCurrentIndex", "(", "1", ")", "else", ":", "self", ".", "setCurrentIndex", "(", "0", ")", "else", ":", "self", ".", "setCurrentIndex", "(", "0", ")" ]
Add text to combo box: add a new item if text is not found in combo box items.
[ "Add", "text", "to", "combo", "box", ":", "add", "a", "new", "item", "if", "text", "is", "not", "found", "in", "combo", "box", "items", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L92-L109
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
BaseComboBox.add_current_text_if_valid
def add_current_text_if_valid(self): """Add current text to combo box history if valid""" valid = self.is_valid(self.currentText()) if valid or valid is None: self.add_current_text() return True else: self.set_current_text(self.selected_text)
python
def add_current_text_if_valid(self): """Add current text to combo box history if valid""" valid = self.is_valid(self.currentText()) if valid or valid is None: self.add_current_text() return True else: self.set_current_text(self.selected_text)
[ "def", "add_current_text_if_valid", "(", "self", ")", ":", "valid", "=", "self", ".", "is_valid", "(", "self", ".", "currentText", "(", ")", ")", "if", "valid", "or", "valid", "is", "None", ":", "self", ".", "add_current_text", "(", ")", "return", "True", "else", ":", "self", ".", "set_current_text", "(", "self", ".", "selected_text", ")" ]
Add current text to combo box history if valid
[ "Add", "current", "text", "to", "combo", "box", "history", "if", "valid" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L120-L127
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
EditableComboBox.show_tip
def show_tip(self, tip=""): """Show tip""" QToolTip.showText(self.mapToGlobal(self.pos()), tip, self)
python
def show_tip(self, tip=""): """Show tip""" QToolTip.showText(self.mapToGlobal(self.pos()), tip, self)
[ "def", "show_tip", "(", "self", ",", "tip", "=", "\"\"", ")", ":", "QToolTip", ".", "showText", "(", "self", ".", "mapToGlobal", "(", "self", ".", "pos", "(", ")", ")", ",", "tip", ",", "self", ")" ]
Show tip
[ "Show", "tip" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L168-L170
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
EditableComboBox.validate
def validate(self, qstr, editing=True): """Validate entered path""" if self.selected_text == qstr and qstr != '': self.valid.emit(True, True) return valid = self.is_valid(qstr) if editing: if valid: self.valid.emit(True, False) else: self.valid.emit(False, False)
python
def validate(self, qstr, editing=True): """Validate entered path""" if self.selected_text == qstr and qstr != '': self.valid.emit(True, True) return valid = self.is_valid(qstr) if editing: if valid: self.valid.emit(True, False) else: self.valid.emit(False, False)
[ "def", "validate", "(", "self", ",", "qstr", ",", "editing", "=", "True", ")", ":", "if", "self", ".", "selected_text", "==", "qstr", "and", "qstr", "!=", "''", ":", "self", ".", "valid", ".", "emit", "(", "True", ",", "True", ")", "return", "valid", "=", "self", ".", "is_valid", "(", "qstr", ")", "if", "editing", ":", "if", "valid", ":", "self", ".", "valid", ".", "emit", "(", "True", ",", "False", ")", "else", ":", "self", ".", "valid", ".", "emit", "(", "False", ",", "False", ")" ]
Validate entered path
[ "Validate", "entered", "path" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L177-L188
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
PathComboBox.focusInEvent
def focusInEvent(self, event): """Handle focus in event restoring to display the status icon.""" show_status = getattr(self.lineEdit(), 'show_status_icon', None) if show_status: show_status() QComboBox.focusInEvent(self, event)
python
def focusInEvent(self, event): """Handle focus in event restoring to display the status icon.""" show_status = getattr(self.lineEdit(), 'show_status_icon', None) if show_status: show_status() QComboBox.focusInEvent(self, event)
[ "def", "focusInEvent", "(", "self", ",", "event", ")", ":", "show_status", "=", "getattr", "(", "self", ".", "lineEdit", "(", ")", ",", "'show_status_icon'", ",", "None", ")", "if", "show_status", ":", "show_status", "(", ")", "QComboBox", ".", "focusInEvent", "(", "self", ",", "event", ")" ]
Handle focus in event restoring to display the status icon.
[ "Handle", "focus", "in", "event", "restoring", "to", "display", "the", "status", "icon", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L220-L225
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
PathComboBox.focusOutEvent
def focusOutEvent(self, event): """Handle focus out event restoring the last valid selected path.""" # Calling asynchronously the 'add_current_text' to avoid crash # https://groups.google.com/group/spyderlib/browse_thread/thread/2257abf530e210bd if not self.is_valid(): lineedit = self.lineEdit() QTimer.singleShot(50, lambda: lineedit.setText(self.selected_text)) hide_status = getattr(self.lineEdit(), 'hide_status_icon', None) if hide_status: hide_status() QComboBox.focusOutEvent(self, event)
python
def focusOutEvent(self, event): """Handle focus out event restoring the last valid selected path.""" # Calling asynchronously the 'add_current_text' to avoid crash # https://groups.google.com/group/spyderlib/browse_thread/thread/2257abf530e210bd if not self.is_valid(): lineedit = self.lineEdit() QTimer.singleShot(50, lambda: lineedit.setText(self.selected_text)) hide_status = getattr(self.lineEdit(), 'hide_status_icon', None) if hide_status: hide_status() QComboBox.focusOutEvent(self, event)
[ "def", "focusOutEvent", "(", "self", ",", "event", ")", ":", "# Calling asynchronously the 'add_current_text' to avoid crash\r", "# https://groups.google.com/group/spyderlib/browse_thread/thread/2257abf530e210bd\r", "if", "not", "self", ".", "is_valid", "(", ")", ":", "lineedit", "=", "self", ".", "lineEdit", "(", ")", "QTimer", ".", "singleShot", "(", "50", ",", "lambda", ":", "lineedit", ".", "setText", "(", "self", ".", "selected_text", ")", ")", "hide_status", "=", "getattr", "(", "self", ".", "lineEdit", "(", ")", ",", "'hide_status_icon'", ",", "None", ")", "if", "hide_status", ":", "hide_status", "(", ")", "QComboBox", ".", "focusOutEvent", "(", "self", ",", "event", ")" ]
Handle focus out event restoring the last valid selected path.
[ "Handle", "focus", "out", "event", "restoring", "the", "last", "valid", "selected", "path", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L227-L238
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
PathComboBox._complete_options
def _complete_options(self): """Find available completion options.""" text = to_text_string(self.currentText()) opts = glob.glob(text + "*") opts = sorted([opt for opt in opts if osp.isdir(opt)]) self.setCompleter(QCompleter(opts, self)) return opts
python
def _complete_options(self): """Find available completion options.""" text = to_text_string(self.currentText()) opts = glob.glob(text + "*") opts = sorted([opt for opt in opts if osp.isdir(opt)]) self.setCompleter(QCompleter(opts, self)) return opts
[ "def", "_complete_options", "(", "self", ")", ":", "text", "=", "to_text_string", "(", "self", ".", "currentText", "(", ")", ")", "opts", "=", "glob", ".", "glob", "(", "text", "+", "\"*\"", ")", "opts", "=", "sorted", "(", "[", "opt", "for", "opt", "in", "opts", "if", "osp", ".", "isdir", "(", "opt", ")", "]", ")", "self", ".", "setCompleter", "(", "QCompleter", "(", "opts", ",", "self", ")", ")", "return", "opts" ]
Find available completion options.
[ "Find", "available", "completion", "options", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L241-L247
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
PathComboBox.double_tab_complete
def double_tab_complete(self): """If several options available a double tab displays options.""" opts = self._complete_options() if len(opts) > 1: self.completer().complete()
python
def double_tab_complete(self): """If several options available a double tab displays options.""" opts = self._complete_options() if len(opts) > 1: self.completer().complete()
[ "def", "double_tab_complete", "(", "self", ")", ":", "opts", "=", "self", ".", "_complete_options", "(", ")", "if", "len", "(", "opts", ")", ">", "1", ":", "self", ".", "completer", "(", ")", ".", "complete", "(", ")" ]
If several options available a double tab displays options.
[ "If", "several", "options", "available", "a", "double", "tab", "displays", "options", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L249-L253
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
PathComboBox.tab_complete
def tab_complete(self): """ If there is a single option available one tab completes the option. """ opts = self._complete_options() if len(opts) == 1: self.set_current_text(opts[0] + os.sep) self.hide_completer()
python
def tab_complete(self): """ If there is a single option available one tab completes the option. """ opts = self._complete_options() if len(opts) == 1: self.set_current_text(opts[0] + os.sep) self.hide_completer()
[ "def", "tab_complete", "(", "self", ")", ":", "opts", "=", "self", ".", "_complete_options", "(", ")", "if", "len", "(", "opts", ")", "==", "1", ":", "self", ".", "set_current_text", "(", "opts", "[", "0", "]", "+", "os", ".", "sep", ")", "self", ".", "hide_completer", "(", ")" ]
If there is a single option available one tab completes the option.
[ "If", "there", "is", "a", "single", "option", "available", "one", "tab", "completes", "the", "option", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L255-L262
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
PathComboBox.is_valid
def is_valid(self, qstr=None): """Return True if string is valid""" if qstr is None: qstr = self.currentText() return osp.isdir(to_text_string(qstr))
python
def is_valid(self, qstr=None): """Return True if string is valid""" if qstr is None: qstr = self.currentText() return osp.isdir(to_text_string(qstr))
[ "def", "is_valid", "(", "self", ",", "qstr", "=", "None", ")", ":", "if", "qstr", "is", "None", ":", "qstr", "=", "self", ".", "currentText", "(", ")", "return", "osp", ".", "isdir", "(", "to_text_string", "(", "qstr", ")", ")" ]
Return True if string is valid
[ "Return", "True", "if", "string", "is", "valid" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L264-L268
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
PathComboBox.selected
def selected(self): """Action to be executed when a valid item has been selected""" self.selected_text = self.currentText() self.valid.emit(True, True) self.open_dir.emit(self.selected_text)
python
def selected(self): """Action to be executed when a valid item has been selected""" self.selected_text = self.currentText() self.valid.emit(True, True) self.open_dir.emit(self.selected_text)
[ "def", "selected", "(", "self", ")", ":", "self", ".", "selected_text", "=", "self", ".", "currentText", "(", ")", "self", ".", "valid", ".", "emit", "(", "True", ",", "True", ")", "self", ".", "open_dir", ".", "emit", "(", "self", ".", "selected_text", ")" ]
Action to be executed when a valid item has been selected
[ "Action", "to", "be", "executed", "when", "a", "valid", "item", "has", "been", "selected" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L270-L274
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
PathComboBox.add_current_text
def add_current_text(self): """ Add current text to combo box history (convenient method). If path ends in os separator ("\" windows, "/" unix) remove it. """ text = self.currentText() if osp.isdir(text) and text: if text[-1] == os.sep: text = text[:-1] self.add_text(text)
python
def add_current_text(self): """ Add current text to combo box history (convenient method). If path ends in os separator ("\" windows, "/" unix) remove it. """ text = self.currentText() if osp.isdir(text) and text: if text[-1] == os.sep: text = text[:-1] self.add_text(text)
[ "def", "add_current_text", "(", "self", ")", ":", "text", "=", "self", ".", "currentText", "(", ")", "if", "osp", ".", "isdir", "(", "text", ")", "and", "text", ":", "if", "text", "[", "-", "1", "]", "==", "os", ".", "sep", ":", "text", "=", "text", "[", ":", "-", "1", "]", "self", ".", "add_text", "(", "text", ")" ]
Add current text to combo box history (convenient method). If path ends in os separator ("\" windows, "/" unix) remove it.
[ "Add", "current", "text", "to", "combo", "box", "history", "(", "convenient", "method", ")", ".", "If", "path", "ends", "in", "os", "separator", "(", "\\", "windows", "/", "unix", ")", "remove", "it", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L276-L285
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
PathComboBox.add_tooltip_to_highlighted_item
def add_tooltip_to_highlighted_item(self, index): """ Add a tooltip showing the full path of the currently highlighted item of the PathComboBox. """ self.setItemData(index, self.itemText(index), Qt.ToolTipRole)
python
def add_tooltip_to_highlighted_item(self, index): """ Add a tooltip showing the full path of the currently highlighted item of the PathComboBox. """ self.setItemData(index, self.itemText(index), Qt.ToolTipRole)
[ "def", "add_tooltip_to_highlighted_item", "(", "self", ",", "index", ")", ":", "self", ".", "setItemData", "(", "index", ",", "self", ".", "itemText", "(", "index", ")", ",", "Qt", ".", "ToolTipRole", ")" ]
Add a tooltip showing the full path of the currently highlighted item of the PathComboBox.
[ "Add", "a", "tooltip", "showing", "the", "full", "path", "of", "the", "currently", "highlighted", "item", "of", "the", "PathComboBox", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L287-L292
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
UrlComboBox.is_valid
def is_valid(self, qstr=None): """Return True if string is valid""" if qstr is None: qstr = self.currentText() return QUrl(qstr).isValid()
python
def is_valid(self, qstr=None): """Return True if string is valid""" if qstr is None: qstr = self.currentText() return QUrl(qstr).isValid()
[ "def", "is_valid", "(", "self", ",", "qstr", "=", "None", ")", ":", "if", "qstr", "is", "None", ":", "qstr", "=", "self", ".", "currentText", "(", ")", "return", "QUrl", "(", "qstr", ")", ".", "isValid", "(", ")" ]
Return True if string is valid
[ "Return", "True", "if", "string", "is", "valid" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L303-L307
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
FileComboBox.is_valid
def is_valid(self, qstr=None): """Return True if string is valid""" if qstr is None: qstr = self.currentText() return osp.isfile(to_text_string(qstr))
python
def is_valid(self, qstr=None): """Return True if string is valid""" if qstr is None: qstr = self.currentText() return osp.isfile(to_text_string(qstr))
[ "def", "is_valid", "(", "self", ",", "qstr", "=", "None", ")", ":", "if", "qstr", "is", "None", ":", "qstr", "=", "self", ".", "currentText", "(", ")", "return", "osp", ".", "isfile", "(", "to_text_string", "(", "qstr", ")", ")" ]
Return True if string is valid
[ "Return", "True", "if", "string", "is", "valid" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L329-L333
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
PythonModulesComboBox.is_valid
def is_valid(self, qstr=None): """Return True if string is valid""" if qstr is None: qstr = self.currentText() return is_module_or_package(to_text_string(qstr))
python
def is_valid(self, qstr=None): """Return True if string is valid""" if qstr is None: qstr = self.currentText() return is_module_or_package(to_text_string(qstr))
[ "def", "is_valid", "(", "self", ",", "qstr", "=", "None", ")", ":", "if", "qstr", "is", "None", ":", "qstr", "=", "self", ".", "currentText", "(", ")", "return", "is_module_or_package", "(", "to_text_string", "(", "qstr", ")", ")" ]
Return True if string is valid
[ "Return", "True", "if", "string", "is", "valid" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L351-L355
train
spyder-ide/spyder
spyder/widgets/comboboxes.py
PythonModulesComboBox.selected
def selected(self): """Action to be executed when a valid item has been selected""" EditableComboBox.selected(self) self.open_dir.emit(self.currentText())
python
def selected(self): """Action to be executed when a valid item has been selected""" EditableComboBox.selected(self) self.open_dir.emit(self.currentText())
[ "def", "selected", "(", "self", ")", ":", "EditableComboBox", ".", "selected", "(", "self", ")", "self", ".", "open_dir", ".", "emit", "(", "self", ".", "currentText", "(", ")", ")" ]
Action to be executed when a valid item has been selected
[ "Action", "to", "be", "executed", "when", "a", "valid", "item", "has", "been", "selected" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/comboboxes.py#L357-L360
train
spyder-ide/spyder
spyder/plugins/console/plugin.py
Console.set_historylog
def set_historylog(self, historylog): """Bind historylog instance to this console Not used anymore since v2.0""" historylog.add_history(self.shell.history_filename) self.shell.append_to_history.connect(historylog.append_to_history)
python
def set_historylog(self, historylog): """Bind historylog instance to this console Not used anymore since v2.0""" historylog.add_history(self.shell.history_filename) self.shell.append_to_history.connect(historylog.append_to_history)
[ "def", "set_historylog", "(", "self", ",", "historylog", ")", ":", "historylog", ".", "add_history", "(", "self", ".", "shell", ".", "history_filename", ")", "self", ".", "shell", ".", "append_to_history", ".", "connect", "(", "historylog", ".", "append_to_history", ")" ]
Bind historylog instance to this console Not used anymore since v2.0
[ "Bind", "historylog", "instance", "to", "this", "console", "Not", "used", "anymore", "since", "v2", ".", "0" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L106-L110
train
spyder-ide/spyder
spyder/plugins/console/plugin.py
Console.closing_plugin
def closing_plugin(self, cancelable=False): """Perform actions before parent main window is closed""" self.dialog_manager.close_all() self.shell.exit_interpreter() return True
python
def closing_plugin(self, cancelable=False): """Perform actions before parent main window is closed""" self.dialog_manager.close_all() self.shell.exit_interpreter() return True
[ "def", "closing_plugin", "(", "self", ",", "cancelable", "=", "False", ")", ":", "self", ".", "dialog_manager", ".", "close_all", "(", ")", "self", ".", "shell", ".", "exit_interpreter", "(", ")", "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/console/plugin.py#L133-L137
train
spyder-ide/spyder
spyder/plugins/console/plugin.py
Console.get_plugin_actions
def get_plugin_actions(self): """Return a list of actions related to plugin""" quit_action = create_action(self, _("&Quit"), icon=ima.icon('exit'), tip=_("Quit"), triggered=self.quit) self.register_shortcut(quit_action, "_", "Quit", "Ctrl+Q") run_action = create_action(self, _("&Run..."), None, ima.icon('run_small'), _("Run a Python script"), triggered=self.run_script) environ_action = create_action(self, _("Environment variables..."), icon=ima.icon('environ'), tip=_("Show and edit environment variables" " (for current session)"), triggered=self.show_env) syspath_action = create_action(self, _("Show sys.path contents..."), icon=ima.icon('syspath'), tip=_("Show (read-only) sys.path"), triggered=self.show_syspath) buffer_action = create_action(self, _("Buffer..."), None, tip=_("Set maximum line count"), triggered=self.change_max_line_count) exteditor_action = create_action(self, _("External editor path..."), None, None, _("Set external editor executable path"), triggered=self.change_exteditor) wrap_action = create_action(self, _("Wrap lines"), toggled=self.toggle_wrap_mode) wrap_action.setChecked(self.get_option('wrap')) codecompletion_action = create_action(self, _("Automatic code completion"), toggled=self.toggle_codecompletion) codecompletion_action.setChecked(self.get_option('codecompletion/auto')) option_menu = QMenu(_('Internal console settings'), self) option_menu.setIcon(ima.icon('tooloptions')) add_actions(option_menu, (buffer_action, wrap_action, codecompletion_action, exteditor_action)) plugin_actions = [None, run_action, environ_action, syspath_action, option_menu, MENU_SEPARATOR, quit_action, self.undock_action] return plugin_actions
python
def get_plugin_actions(self): """Return a list of actions related to plugin""" quit_action = create_action(self, _("&Quit"), icon=ima.icon('exit'), tip=_("Quit"), triggered=self.quit) self.register_shortcut(quit_action, "_", "Quit", "Ctrl+Q") run_action = create_action(self, _("&Run..."), None, ima.icon('run_small'), _("Run a Python script"), triggered=self.run_script) environ_action = create_action(self, _("Environment variables..."), icon=ima.icon('environ'), tip=_("Show and edit environment variables" " (for current session)"), triggered=self.show_env) syspath_action = create_action(self, _("Show sys.path contents..."), icon=ima.icon('syspath'), tip=_("Show (read-only) sys.path"), triggered=self.show_syspath) buffer_action = create_action(self, _("Buffer..."), None, tip=_("Set maximum line count"), triggered=self.change_max_line_count) exteditor_action = create_action(self, _("External editor path..."), None, None, _("Set external editor executable path"), triggered=self.change_exteditor) wrap_action = create_action(self, _("Wrap lines"), toggled=self.toggle_wrap_mode) wrap_action.setChecked(self.get_option('wrap')) codecompletion_action = create_action(self, _("Automatic code completion"), toggled=self.toggle_codecompletion) codecompletion_action.setChecked(self.get_option('codecompletion/auto')) option_menu = QMenu(_('Internal console settings'), self) option_menu.setIcon(ima.icon('tooloptions')) add_actions(option_menu, (buffer_action, wrap_action, codecompletion_action, exteditor_action)) plugin_actions = [None, run_action, environ_action, syspath_action, option_menu, MENU_SEPARATOR, quit_action, self.undock_action] return plugin_actions
[ "def", "get_plugin_actions", "(", "self", ")", ":", "quit_action", "=", "create_action", "(", "self", ",", "_", "(", "\"&Quit\"", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'exit'", ")", ",", "tip", "=", "_", "(", "\"Quit\"", ")", ",", "triggered", "=", "self", ".", "quit", ")", "self", ".", "register_shortcut", "(", "quit_action", ",", "\"_\"", ",", "\"Quit\"", ",", "\"Ctrl+Q\"", ")", "run_action", "=", "create_action", "(", "self", ",", "_", "(", "\"&Run...\"", ")", ",", "None", ",", "ima", ".", "icon", "(", "'run_small'", ")", ",", "_", "(", "\"Run a Python script\"", ")", ",", "triggered", "=", "self", ".", "run_script", ")", "environ_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Environment variables...\"", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'environ'", ")", ",", "tip", "=", "_", "(", "\"Show and edit environment variables\"", "\" (for current session)\"", ")", ",", "triggered", "=", "self", ".", "show_env", ")", "syspath_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Show sys.path contents...\"", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'syspath'", ")", ",", "tip", "=", "_", "(", "\"Show (read-only) sys.path\"", ")", ",", "triggered", "=", "self", ".", "show_syspath", ")", "buffer_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Buffer...\"", ")", ",", "None", ",", "tip", "=", "_", "(", "\"Set maximum line count\"", ")", ",", "triggered", "=", "self", ".", "change_max_line_count", ")", "exteditor_action", "=", "create_action", "(", "self", ",", "_", "(", "\"External editor path...\"", ")", ",", "None", ",", "None", ",", "_", "(", "\"Set external editor executable path\"", ")", ",", "triggered", "=", "self", ".", "change_exteditor", ")", "wrap_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Wrap lines\"", ")", ",", "toggled", "=", "self", ".", "toggle_wrap_mode", ")", "wrap_action", ".", "setChecked", "(", "self", ".", "get_option", "(", "'wrap'", ")", ")", "codecompletion_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Automatic code completion\"", ")", ",", "toggled", "=", "self", ".", "toggle_codecompletion", ")", "codecompletion_action", ".", "setChecked", "(", "self", ".", "get_option", "(", "'codecompletion/auto'", ")", ")", "option_menu", "=", "QMenu", "(", "_", "(", "'Internal console settings'", ")", ",", "self", ")", "option_menu", ".", "setIcon", "(", "ima", ".", "icon", "(", "'tooloptions'", ")", ")", "add_actions", "(", "option_menu", ",", "(", "buffer_action", ",", "wrap_action", ",", "codecompletion_action", ",", "exteditor_action", ")", ")", "plugin_actions", "=", "[", "None", ",", "run_action", ",", "environ_action", ",", "syspath_action", ",", "option_menu", ",", "MENU_SEPARATOR", ",", "quit_action", ",", "self", ".", "undock_action", "]", "return", "plugin_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/console/plugin.py#L142-L191
train
spyder-ide/spyder
spyder/plugins/console/plugin.py
Console.register_plugin
def register_plugin(self): """Register plugin in Spyder's main window""" self.focus_changed.connect(self.main.plugin_focus_changed) self.main.add_dockwidget(self) # Connecting the following signal once the dockwidget has been created: self.shell.exception_occurred.connect(self.exception_occurred)
python
def register_plugin(self): """Register plugin in Spyder's main window""" self.focus_changed.connect(self.main.plugin_focus_changed) self.main.add_dockwidget(self) # Connecting the following signal once the dockwidget has been created: self.shell.exception_occurred.connect(self.exception_occurred)
[ "def", "register_plugin", "(", "self", ")", ":", "self", ".", "focus_changed", ".", "connect", "(", "self", ".", "main", ".", "plugin_focus_changed", ")", "self", ".", "main", ".", "add_dockwidget", "(", "self", ")", "# Connecting the following signal once the dockwidget has been created:\r", "self", ".", "shell", ".", "exception_occurred", ".", "connect", "(", "self", ".", "exception_occurred", ")" ]
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/console/plugin.py#L193-L198
train
spyder-ide/spyder
spyder/plugins/console/plugin.py
Console.exception_occurred
def exception_occurred(self, text, is_traceback): """ Exception ocurred in the internal console. Show a QDialog or the internal console to warn the user. """ # Skip errors without traceback or dismiss if (not is_traceback and self.error_dlg is None) or self.dismiss_error: return if CONF.get('main', 'show_internal_errors'): if self.error_dlg is None: self.error_dlg = SpyderErrorDialog(self) self.error_dlg.close_btn.clicked.connect(self.close_error_dlg) self.error_dlg.rejected.connect(self.remove_error_dlg) self.error_dlg.details.go_to_error.connect(self.go_to_error) self.error_dlg.show() self.error_dlg.append_traceback(text) elif DEV or get_debug_level(): self.dockwidget.show() self.dockwidget.raise_()
python
def exception_occurred(self, text, is_traceback): """ Exception ocurred in the internal console. Show a QDialog or the internal console to warn the user. """ # Skip errors without traceback or dismiss if (not is_traceback and self.error_dlg is None) or self.dismiss_error: return if CONF.get('main', 'show_internal_errors'): if self.error_dlg is None: self.error_dlg = SpyderErrorDialog(self) self.error_dlg.close_btn.clicked.connect(self.close_error_dlg) self.error_dlg.rejected.connect(self.remove_error_dlg) self.error_dlg.details.go_to_error.connect(self.go_to_error) self.error_dlg.show() self.error_dlg.append_traceback(text) elif DEV or get_debug_level(): self.dockwidget.show() self.dockwidget.raise_()
[ "def", "exception_occurred", "(", "self", ",", "text", ",", "is_traceback", ")", ":", "# Skip errors without traceback or dismiss\r", "if", "(", "not", "is_traceback", "and", "self", ".", "error_dlg", "is", "None", ")", "or", "self", ".", "dismiss_error", ":", "return", "if", "CONF", ".", "get", "(", "'main'", ",", "'show_internal_errors'", ")", ":", "if", "self", ".", "error_dlg", "is", "None", ":", "self", ".", "error_dlg", "=", "SpyderErrorDialog", "(", "self", ")", "self", ".", "error_dlg", ".", "close_btn", ".", "clicked", ".", "connect", "(", "self", ".", "close_error_dlg", ")", "self", ".", "error_dlg", ".", "rejected", ".", "connect", "(", "self", ".", "remove_error_dlg", ")", "self", ".", "error_dlg", ".", "details", ".", "go_to_error", ".", "connect", "(", "self", ".", "go_to_error", ")", "self", ".", "error_dlg", ".", "show", "(", ")", "self", ".", "error_dlg", ".", "append_traceback", "(", "text", ")", "elif", "DEV", "or", "get_debug_level", "(", ")", ":", "self", ".", "dockwidget", ".", "show", "(", ")", "self", ".", "dockwidget", ".", "raise_", "(", ")" ]
Exception ocurred in the internal console. Show a QDialog or the internal console to warn the user.
[ "Exception", "ocurred", "in", "the", "internal", "console", ".", "Show", "a", "QDialog", "or", "the", "internal", "console", "to", "warn", "the", "user", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L200-L220
train
spyder-ide/spyder
spyder/plugins/console/plugin.py
Console.close_error_dlg
def close_error_dlg(self): """Close error dialog.""" if self.error_dlg.dismiss_box.isChecked(): self.dismiss_error = True self.error_dlg.reject()
python
def close_error_dlg(self): """Close error dialog.""" if self.error_dlg.dismiss_box.isChecked(): self.dismiss_error = True self.error_dlg.reject()
[ "def", "close_error_dlg", "(", "self", ")", ":", "if", "self", ".", "error_dlg", ".", "dismiss_box", ".", "isChecked", "(", ")", ":", "self", ".", "dismiss_error", "=", "True", "self", ".", "error_dlg", ".", "reject", "(", ")" ]
Close error dialog.
[ "Close", "error", "dialog", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L222-L226
train
spyder-ide/spyder
spyder/plugins/console/plugin.py
Console.show_syspath
def show_syspath(self): """Show sys.path""" editor = CollectionsEditor(parent=self) editor.setup(sys.path, title="sys.path", readonly=True, width=600, icon=ima.icon('syspath')) self.dialog_manager.show(editor)
python
def show_syspath(self): """Show sys.path""" editor = CollectionsEditor(parent=self) editor.setup(sys.path, title="sys.path", readonly=True, width=600, icon=ima.icon('syspath')) self.dialog_manager.show(editor)
[ "def", "show_syspath", "(", "self", ")", ":", "editor", "=", "CollectionsEditor", "(", "parent", "=", "self", ")", "editor", ".", "setup", "(", "sys", ".", "path", ",", "title", "=", "\"sys.path\"", ",", "readonly", "=", "True", ",", "width", "=", "600", ",", "icon", "=", "ima", ".", "icon", "(", "'syspath'", ")", ")", "self", ".", "dialog_manager", ".", "show", "(", "editor", ")" ]
Show sys.path
[ "Show", "sys", ".", "path" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L244-L249
train
spyder-ide/spyder
spyder/plugins/console/plugin.py
Console.run_script
def run_script(self, filename=None, silent=False, set_focus=False, args=None): """Run a Python script""" if filename is None: self.shell.interpreter.restore_stds() filename, _selfilter = getopenfilename( self, _("Run Python script"), getcwd_or_home(), _("Python scripts")+" (*.py ; *.pyw ; *.ipy)") self.shell.interpreter.redirect_stds() if filename: os.chdir( osp.dirname(filename) ) filename = osp.basename(filename) else: return logger.debug("Running script with %s", args) filename = osp.abspath(filename) rbs = remove_backslashes command = "runfile('%s', args='%s')" % (rbs(filename), rbs(args)) if set_focus: self.shell.setFocus() if self.dockwidget and not self.ismaximized: self.dockwidget.setVisible(True) self.dockwidget.raise_() self.shell.write(command+'\n') self.shell.run_command(command)
python
def run_script(self, filename=None, silent=False, set_focus=False, args=None): """Run a Python script""" if filename is None: self.shell.interpreter.restore_stds() filename, _selfilter = getopenfilename( self, _("Run Python script"), getcwd_or_home(), _("Python scripts")+" (*.py ; *.pyw ; *.ipy)") self.shell.interpreter.redirect_stds() if filename: os.chdir( osp.dirname(filename) ) filename = osp.basename(filename) else: return logger.debug("Running script with %s", args) filename = osp.abspath(filename) rbs = remove_backslashes command = "runfile('%s', args='%s')" % (rbs(filename), rbs(args)) if set_focus: self.shell.setFocus() if self.dockwidget and not self.ismaximized: self.dockwidget.setVisible(True) self.dockwidget.raise_() self.shell.write(command+'\n') self.shell.run_command(command)
[ "def", "run_script", "(", "self", ",", "filename", "=", "None", ",", "silent", "=", "False", ",", "set_focus", "=", "False", ",", "args", "=", "None", ")", ":", "if", "filename", "is", "None", ":", "self", ".", "shell", ".", "interpreter", ".", "restore_stds", "(", ")", "filename", ",", "_selfilter", "=", "getopenfilename", "(", "self", ",", "_", "(", "\"Run Python script\"", ")", ",", "getcwd_or_home", "(", ")", ",", "_", "(", "\"Python scripts\"", ")", "+", "\" (*.py ; *.pyw ; *.ipy)\"", ")", "self", ".", "shell", ".", "interpreter", ".", "redirect_stds", "(", ")", "if", "filename", ":", "os", ".", "chdir", "(", "osp", ".", "dirname", "(", "filename", ")", ")", "filename", "=", "osp", ".", "basename", "(", "filename", ")", "else", ":", "return", "logger", ".", "debug", "(", "\"Running script with %s\"", ",", "args", ")", "filename", "=", "osp", ".", "abspath", "(", "filename", ")", "rbs", "=", "remove_backslashes", "command", "=", "\"runfile('%s', args='%s')\"", "%", "(", "rbs", "(", "filename", ")", ",", "rbs", "(", "args", ")", ")", "if", "set_focus", ":", "self", ".", "shell", ".", "setFocus", "(", ")", "if", "self", ".", "dockwidget", "and", "not", "self", ".", "ismaximized", ":", "self", ".", "dockwidget", ".", "setVisible", "(", "True", ")", "self", ".", "dockwidget", ".", "raise_", "(", ")", "self", ".", "shell", ".", "write", "(", "command", "+", "'\\n'", ")", "self", ".", "shell", ".", "run_command", "(", "command", ")" ]
Run a Python script
[ "Run", "a", "Python", "script" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L252-L276
train
spyder-ide/spyder
spyder/plugins/console/plugin.py
Console.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() self.edit_script(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() self.edit_script(fname, int(lnb))
[ "def", "go_to_error", "(", "self", ",", "text", ")", ":", "match", "=", "get_error_match", "(", "to_text_string", "(", "text", ")", ")", "if", "match", ":", "fname", ",", "lnb", "=", "match", ".", "groups", "(", ")", "self", ".", "edit_script", "(", "fname", ",", "int", "(", "lnb", ")", ")" ]
Go to error if relevant
[ "Go", "to", "error", "if", "relevant" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L279-L284
train
spyder-ide/spyder
spyder/plugins/console/plugin.py
Console.edit_script
def edit_script(self, filename=None, goto=-1): """Edit script""" # Called from InternalShell if not hasattr(self, 'main') \ or not hasattr(self.main, 'editor'): self.shell.external_editor(filename, goto) return if filename is not None: self.edit_goto.emit(osp.abspath(filename), goto, '')
python
def edit_script(self, filename=None, goto=-1): """Edit script""" # Called from InternalShell if not hasattr(self, 'main') \ or not hasattr(self.main, 'editor'): self.shell.external_editor(filename, goto) return if filename is not None: self.edit_goto.emit(osp.abspath(filename), goto, '')
[ "def", "edit_script", "(", "self", ",", "filename", "=", "None", ",", "goto", "=", "-", "1", ")", ":", "# Called from InternalShell\r", "if", "not", "hasattr", "(", "self", ",", "'main'", ")", "or", "not", "hasattr", "(", "self", ".", "main", ",", "'editor'", ")", ":", "self", ".", "shell", ".", "external_editor", "(", "filename", ",", "goto", ")", "return", "if", "filename", "is", "not", "None", ":", "self", ".", "edit_goto", ".", "emit", "(", "osp", ".", "abspath", "(", "filename", ")", ",", "goto", ",", "''", ")" ]
Edit script
[ "Edit", "script" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L286-L294
train
spyder-ide/spyder
spyder/plugins/console/plugin.py
Console.execute_lines
def execute_lines(self, lines): """Execute lines and give focus to shell""" self.shell.execute_lines(to_text_string(lines)) self.shell.setFocus()
python
def execute_lines(self, lines): """Execute lines and give focus to shell""" self.shell.execute_lines(to_text_string(lines)) self.shell.setFocus()
[ "def", "execute_lines", "(", "self", ",", "lines", ")", ":", "self", ".", "shell", ".", "execute_lines", "(", "to_text_string", "(", "lines", ")", ")", "self", ".", "shell", ".", "setFocus", "(", ")" ]
Execute lines and give focus to shell
[ "Execute", "lines", "and", "give", "focus", "to", "shell" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L296-L299
train
spyder-ide/spyder
spyder/plugins/console/plugin.py
Console.change_exteditor
def change_exteditor(self): """Change external editor path""" path, valid = QInputDialog.getText(self, _('External editor'), _('External editor executable path:'), QLineEdit.Normal, self.get_option('external_editor/path')) if valid: self.set_option('external_editor/path', to_text_string(path))
python
def change_exteditor(self): """Change external editor path""" path, valid = QInputDialog.getText(self, _('External editor'), _('External editor executable path:'), QLineEdit.Normal, self.get_option('external_editor/path')) if valid: self.set_option('external_editor/path', to_text_string(path))
[ "def", "change_exteditor", "(", "self", ")", ":", "path", ",", "valid", "=", "QInputDialog", ".", "getText", "(", "self", ",", "_", "(", "'External editor'", ")", ",", "_", "(", "'External editor executable path:'", ")", ",", "QLineEdit", ".", "Normal", ",", "self", ".", "get_option", "(", "'external_editor/path'", ")", ")", "if", "valid", ":", "self", ".", "set_option", "(", "'external_editor/path'", ",", "to_text_string", "(", "path", ")", ")" ]
Change external editor path
[ "Change", "external", "editor", "path" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L313-L320
train
spyder-ide/spyder
spyder/plugins/console/plugin.py
Console.toggle_wrap_mode
def toggle_wrap_mode(self, checked): """Toggle wrap mode""" self.shell.toggle_wrap_mode(checked) self.set_option('wrap', checked)
python
def toggle_wrap_mode(self, checked): """Toggle wrap mode""" self.shell.toggle_wrap_mode(checked) self.set_option('wrap', checked)
[ "def", "toggle_wrap_mode", "(", "self", ",", "checked", ")", ":", "self", ".", "shell", ".", "toggle_wrap_mode", "(", "checked", ")", "self", ".", "set_option", "(", "'wrap'", ",", "checked", ")" ]
Toggle wrap mode
[ "Toggle", "wrap", "mode" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L323-L326
train
spyder-ide/spyder
spyder/plugins/console/plugin.py
Console.toggle_codecompletion
def toggle_codecompletion(self, checked): """Toggle automatic code completion""" self.shell.set_codecompletion_auto(checked) self.set_option('codecompletion/auto', checked)
python
def toggle_codecompletion(self, checked): """Toggle automatic code completion""" self.shell.set_codecompletion_auto(checked) self.set_option('codecompletion/auto', checked)
[ "def", "toggle_codecompletion", "(", "self", ",", "checked", ")", ":", "self", ".", "shell", ".", "set_codecompletion_auto", "(", "checked", ")", "self", ".", "set_option", "(", "'codecompletion/auto'", ",", "checked", ")" ]
Toggle automatic code completion
[ "Toggle", "automatic", "code", "completion" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L329-L332
train
spyder-ide/spyder
spyder/plugins/console/plugin.py
Console.dragEnterEvent
def dragEnterEvent(self, event): """Reimplement Qt method Inform Qt about the types of data that the widget accepts""" source = event.mimeData() if source.hasUrls(): if mimedata2url(source): event.acceptProposedAction() else: event.ignore() elif source.hasText(): event.acceptProposedAction()
python
def dragEnterEvent(self, event): """Reimplement Qt method Inform Qt about the types of data that the widget accepts""" source = event.mimeData() if source.hasUrls(): if mimedata2url(source): event.acceptProposedAction() else: event.ignore() elif source.hasText(): event.acceptProposedAction()
[ "def", "dragEnterEvent", "(", "self", ",", "event", ")", ":", "source", "=", "event", ".", "mimeData", "(", ")", "if", "source", ".", "hasUrls", "(", ")", ":", "if", "mimedata2url", "(", "source", ")", ":", "event", ".", "acceptProposedAction", "(", ")", "else", ":", "event", ".", "ignore", "(", ")", "elif", "source", ".", "hasText", "(", ")", ":", "event", ".", "acceptProposedAction", "(", ")" ]
Reimplement Qt method Inform Qt about the types of data that the widget accepts
[ "Reimplement", "Qt", "method", "Inform", "Qt", "about", "the", "types", "of", "data", "that", "the", "widget", "accepts" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L335-L345
train
spyder-ide/spyder
spyder/plugins/console/plugin.py
Console.dropEvent
def dropEvent(self, event): """Reimplement Qt method Unpack dropped data and handle it""" source = event.mimeData() if source.hasUrls(): pathlist = mimedata2url(source) self.shell.drop_pathlist(pathlist) elif source.hasText(): lines = to_text_string(source.text()) self.shell.set_cursor_position('eof') self.shell.execute_lines(lines) event.acceptProposedAction()
python
def dropEvent(self, event): """Reimplement Qt method Unpack dropped data and handle it""" source = event.mimeData() if source.hasUrls(): pathlist = mimedata2url(source) self.shell.drop_pathlist(pathlist) elif source.hasText(): lines = to_text_string(source.text()) self.shell.set_cursor_position('eof') self.shell.execute_lines(lines) event.acceptProposedAction()
[ "def", "dropEvent", "(", "self", ",", "event", ")", ":", "source", "=", "event", ".", "mimeData", "(", ")", "if", "source", ".", "hasUrls", "(", ")", ":", "pathlist", "=", "mimedata2url", "(", "source", ")", "self", ".", "shell", ".", "drop_pathlist", "(", "pathlist", ")", "elif", "source", ".", "hasText", "(", ")", ":", "lines", "=", "to_text_string", "(", "source", ".", "text", "(", ")", ")", "self", ".", "shell", ".", "set_cursor_position", "(", "'eof'", ")", "self", ".", "shell", ".", "execute_lines", "(", "lines", ")", "event", ".", "acceptProposedAction", "(", ")" ]
Reimplement Qt method Unpack dropped data and handle it
[ "Reimplement", "Qt", "method", "Unpack", "dropped", "data", "and", "handle", "it" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/console/plugin.py#L347-L358
train
spyder-ide/spyder
scripts/spyder_win_post_install.py
install
def install(): """Function executed when running the script with the -install switch""" # Create Spyder start menu folder # Don't use CSIDL_COMMON_PROGRAMS because it requres admin rights # This is consistent with use of CSIDL_DESKTOPDIRECTORY below # CSIDL_COMMON_PROGRAMS = # C:\ProgramData\Microsoft\Windows\Start Menu\Programs # CSIDL_PROGRAMS = # C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs start_menu = osp.join(get_special_folder_path('CSIDL_PROGRAMS'), 'Spyder (Py%i.%i %i bit)' % (sys.version_info[0], sys.version_info[1], struct.calcsize('P')*8)) if not osp.isdir(start_menu): os.mkdir(start_menu) directory_created(start_menu) # Create Spyder start menu entries python = osp.abspath(osp.join(sys.prefix, 'python.exe')) pythonw = osp.abspath(osp.join(sys.prefix, 'pythonw.exe')) script = osp.abspath(osp.join(sys.prefix, 'scripts', 'spyder')) if not osp.exists(script): # if not installed to the site scripts dir script = osp.abspath(osp.join(osp.dirname(osp.abspath(__file__)), 'spyder')) workdir = "%HOMEDRIVE%%HOMEPATH%" import distutils.sysconfig lib_dir = distutils.sysconfig.get_python_lib(plat_specific=1) ico_dir = osp.join(lib_dir, 'spyder', 'windows') # if user is running -install manually then icons are in Scripts/ if not osp.isdir(ico_dir): ico_dir = osp.dirname(osp.abspath(__file__)) desc = 'The Scientific Python Development Environment' fname = osp.join(start_menu, 'Spyder (full).lnk') create_shortcut(python, desc, fname, '"%s"' % script, workdir, osp.join(ico_dir, 'spyder.ico')) file_created(fname) fname = osp.join(start_menu, 'Spyder-Reset all settings.lnk') create_shortcut(python, 'Reset Spyder settings to defaults', fname, '"%s" --reset' % script, workdir) file_created(fname) current = True # only affects current user root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE winreg.SetValueEx(winreg.CreateKey(root, KEY_C1 % ("", EWS)), "", 0, winreg.REG_SZ, '"%s" "%s\Scripts\spyder" "%%1"' % (pythonw, sys.prefix)) winreg.SetValueEx(winreg.CreateKey(root, KEY_C1 % ("NoCon", EWS)), "", 0, winreg.REG_SZ, '"%s" "%s\Scripts\spyder" "%%1"' % (pythonw, sys.prefix)) # Create desktop shortcut file desktop_folder = get_special_folder_path("CSIDL_DESKTOPDIRECTORY") fname = osp.join(desktop_folder, 'Spyder.lnk') desc = 'The Scientific Python Development Environment' create_shortcut(pythonw, desc, fname, '"%s"' % script, workdir, osp.join(ico_dir, 'spyder.ico')) file_created(fname)
python
def install(): """Function executed when running the script with the -install switch""" # Create Spyder start menu folder # Don't use CSIDL_COMMON_PROGRAMS because it requres admin rights # This is consistent with use of CSIDL_DESKTOPDIRECTORY below # CSIDL_COMMON_PROGRAMS = # C:\ProgramData\Microsoft\Windows\Start Menu\Programs # CSIDL_PROGRAMS = # C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs start_menu = osp.join(get_special_folder_path('CSIDL_PROGRAMS'), 'Spyder (Py%i.%i %i bit)' % (sys.version_info[0], sys.version_info[1], struct.calcsize('P')*8)) if not osp.isdir(start_menu): os.mkdir(start_menu) directory_created(start_menu) # Create Spyder start menu entries python = osp.abspath(osp.join(sys.prefix, 'python.exe')) pythonw = osp.abspath(osp.join(sys.prefix, 'pythonw.exe')) script = osp.abspath(osp.join(sys.prefix, 'scripts', 'spyder')) if not osp.exists(script): # if not installed to the site scripts dir script = osp.abspath(osp.join(osp.dirname(osp.abspath(__file__)), 'spyder')) workdir = "%HOMEDRIVE%%HOMEPATH%" import distutils.sysconfig lib_dir = distutils.sysconfig.get_python_lib(plat_specific=1) ico_dir = osp.join(lib_dir, 'spyder', 'windows') # if user is running -install manually then icons are in Scripts/ if not osp.isdir(ico_dir): ico_dir = osp.dirname(osp.abspath(__file__)) desc = 'The Scientific Python Development Environment' fname = osp.join(start_menu, 'Spyder (full).lnk') create_shortcut(python, desc, fname, '"%s"' % script, workdir, osp.join(ico_dir, 'spyder.ico')) file_created(fname) fname = osp.join(start_menu, 'Spyder-Reset all settings.lnk') create_shortcut(python, 'Reset Spyder settings to defaults', fname, '"%s" --reset' % script, workdir) file_created(fname) current = True # only affects current user root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE winreg.SetValueEx(winreg.CreateKey(root, KEY_C1 % ("", EWS)), "", 0, winreg.REG_SZ, '"%s" "%s\Scripts\spyder" "%%1"' % (pythonw, sys.prefix)) winreg.SetValueEx(winreg.CreateKey(root, KEY_C1 % ("NoCon", EWS)), "", 0, winreg.REG_SZ, '"%s" "%s\Scripts\spyder" "%%1"' % (pythonw, sys.prefix)) # Create desktop shortcut file desktop_folder = get_special_folder_path("CSIDL_DESKTOPDIRECTORY") fname = osp.join(desktop_folder, 'Spyder.lnk') desc = 'The Scientific Python Development Environment' create_shortcut(pythonw, desc, fname, '"%s"' % script, workdir, osp.join(ico_dir, 'spyder.ico')) file_created(fname)
[ "def", "install", "(", ")", ":", "# Create Spyder start menu folder\r", "# Don't use CSIDL_COMMON_PROGRAMS because it requres admin rights\r", "# This is consistent with use of CSIDL_DESKTOPDIRECTORY below\r", "# CSIDL_COMMON_PROGRAMS =\r", "# C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\r", "# CSIDL_PROGRAMS =\r", "# C:\\Users\\<username>\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\r", "start_menu", "=", "osp", ".", "join", "(", "get_special_folder_path", "(", "'CSIDL_PROGRAMS'", ")", ",", "'Spyder (Py%i.%i %i bit)'", "%", "(", "sys", ".", "version_info", "[", "0", "]", ",", "sys", ".", "version_info", "[", "1", "]", ",", "struct", ".", "calcsize", "(", "'P'", ")", "*", "8", ")", ")", "if", "not", "osp", ".", "isdir", "(", "start_menu", ")", ":", "os", ".", "mkdir", "(", "start_menu", ")", "directory_created", "(", "start_menu", ")", "# Create Spyder start menu entries\r", "python", "=", "osp", ".", "abspath", "(", "osp", ".", "join", "(", "sys", ".", "prefix", ",", "'python.exe'", ")", ")", "pythonw", "=", "osp", ".", "abspath", "(", "osp", ".", "join", "(", "sys", ".", "prefix", ",", "'pythonw.exe'", ")", ")", "script", "=", "osp", ".", "abspath", "(", "osp", ".", "join", "(", "sys", ".", "prefix", ",", "'scripts'", ",", "'spyder'", ")", ")", "if", "not", "osp", ".", "exists", "(", "script", ")", ":", "# if not installed to the site scripts dir\r", "script", "=", "osp", ".", "abspath", "(", "osp", ".", "join", "(", "osp", ".", "dirname", "(", "osp", ".", "abspath", "(", "__file__", ")", ")", ",", "'spyder'", ")", ")", "workdir", "=", "\"%HOMEDRIVE%%HOMEPATH%\"", "import", "distutils", ".", "sysconfig", "lib_dir", "=", "distutils", ".", "sysconfig", ".", "get_python_lib", "(", "plat_specific", "=", "1", ")", "ico_dir", "=", "osp", ".", "join", "(", "lib_dir", ",", "'spyder'", ",", "'windows'", ")", "# if user is running -install manually then icons are in Scripts/\r", "if", "not", "osp", ".", "isdir", "(", "ico_dir", ")", ":", "ico_dir", "=", "osp", ".", "dirname", "(", "osp", ".", "abspath", "(", "__file__", ")", ")", "desc", "=", "'The Scientific Python Development Environment'", "fname", "=", "osp", ".", "join", "(", "start_menu", ",", "'Spyder (full).lnk'", ")", "create_shortcut", "(", "python", ",", "desc", ",", "fname", ",", "'\"%s\"'", "%", "script", ",", "workdir", ",", "osp", ".", "join", "(", "ico_dir", ",", "'spyder.ico'", ")", ")", "file_created", "(", "fname", ")", "fname", "=", "osp", ".", "join", "(", "start_menu", ",", "'Spyder-Reset all settings.lnk'", ")", "create_shortcut", "(", "python", ",", "'Reset Spyder settings to defaults'", ",", "fname", ",", "'\"%s\" --reset'", "%", "script", ",", "workdir", ")", "file_created", "(", "fname", ")", "current", "=", "True", "# only affects current user\r", "root", "=", "winreg", ".", "HKEY_CURRENT_USER", "if", "current", "else", "winreg", ".", "HKEY_LOCAL_MACHINE", "winreg", ".", "SetValueEx", "(", "winreg", ".", "CreateKey", "(", "root", ",", "KEY_C1", "%", "(", "\"\"", ",", "EWS", ")", ")", ",", "\"\"", ",", "0", ",", "winreg", ".", "REG_SZ", ",", "'\"%s\" \"%s\\Scripts\\spyder\" \"%%1\"'", "%", "(", "pythonw", ",", "sys", ".", "prefix", ")", ")", "winreg", ".", "SetValueEx", "(", "winreg", ".", "CreateKey", "(", "root", ",", "KEY_C1", "%", "(", "\"NoCon\"", ",", "EWS", ")", ")", ",", "\"\"", ",", "0", ",", "winreg", ".", "REG_SZ", ",", "'\"%s\" \"%s\\Scripts\\spyder\" \"%%1\"'", "%", "(", "pythonw", ",", "sys", ".", "prefix", ")", ")", "# Create desktop shortcut file\r", "desktop_folder", "=", "get_special_folder_path", "(", "\"CSIDL_DESKTOPDIRECTORY\"", ")", "fname", "=", "osp", ".", "join", "(", "desktop_folder", ",", "'Spyder.lnk'", ")", "desc", "=", "'The Scientific Python Development Environment'", "create_shortcut", "(", "pythonw", ",", "desc", ",", "fname", ",", "'\"%s\"'", "%", "script", ",", "workdir", ",", "osp", ".", "join", "(", "ico_dir", ",", "'spyder.ico'", ")", ")", "file_created", "(", "fname", ")" ]
Function executed when running the script with the -install switch
[ "Function", "executed", "when", "running", "the", "script", "with", "the", "-", "install", "switch" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/scripts/spyder_win_post_install.py#L113-L170
train
spyder-ide/spyder
scripts/spyder_win_post_install.py
remove
def remove(): """Function executed when running the script with the -remove switch""" current = True # only affects current user root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE for key in (KEY_C1 % ("", EWS), KEY_C1 % ("NoCon", EWS), KEY_C0 % ("", EWS), KEY_C0 % ("NoCon", EWS)): try: winreg.DeleteKey(root, key) except WindowsError: pass else: if not is_bdist_wininst: print("Successfully removed Spyder shortcuts from Windows "\ "Explorer context menu.", file=sys.stdout) if not is_bdist_wininst: # clean up desktop desktop_folder = get_special_folder_path("CSIDL_DESKTOPDIRECTORY") fname = osp.join(desktop_folder, 'Spyder.lnk') if osp.isfile(fname): try: os.remove(fname) except OSError: print("Failed to remove %s; you may be able to remove it "\ "manually." % fname, file=sys.stderr) else: print("Successfully removed Spyder shortcuts from your desktop.", file=sys.stdout) # clean up startmenu start_menu = osp.join(get_special_folder_path('CSIDL_PROGRAMS'), 'Spyder (Py%i.%i %i bit)' % (sys.version_info[0], sys.version_info[1], struct.calcsize('P')*8)) if osp.isdir(start_menu): for fname in os.listdir(start_menu): try: os.remove(osp.join(start_menu,fname)) except OSError: print("Failed to remove %s; you may be able to remove it "\ "manually." % fname, file=sys.stderr) else: print("Successfully removed Spyder shortcuts from your "\ " start menu.", file=sys.stdout) try: os.rmdir(start_menu) except OSError: print("Failed to remove %s; you may be able to remove it "\ "manually." % fname, file=sys.stderr) else: print("Successfully removed Spyder shortcut folder from your "\ " start menu.", file=sys.stdout)
python
def remove(): """Function executed when running the script with the -remove switch""" current = True # only affects current user root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE for key in (KEY_C1 % ("", EWS), KEY_C1 % ("NoCon", EWS), KEY_C0 % ("", EWS), KEY_C0 % ("NoCon", EWS)): try: winreg.DeleteKey(root, key) except WindowsError: pass else: if not is_bdist_wininst: print("Successfully removed Spyder shortcuts from Windows "\ "Explorer context menu.", file=sys.stdout) if not is_bdist_wininst: # clean up desktop desktop_folder = get_special_folder_path("CSIDL_DESKTOPDIRECTORY") fname = osp.join(desktop_folder, 'Spyder.lnk') if osp.isfile(fname): try: os.remove(fname) except OSError: print("Failed to remove %s; you may be able to remove it "\ "manually." % fname, file=sys.stderr) else: print("Successfully removed Spyder shortcuts from your desktop.", file=sys.stdout) # clean up startmenu start_menu = osp.join(get_special_folder_path('CSIDL_PROGRAMS'), 'Spyder (Py%i.%i %i bit)' % (sys.version_info[0], sys.version_info[1], struct.calcsize('P')*8)) if osp.isdir(start_menu): for fname in os.listdir(start_menu): try: os.remove(osp.join(start_menu,fname)) except OSError: print("Failed to remove %s; you may be able to remove it "\ "manually." % fname, file=sys.stderr) else: print("Successfully removed Spyder shortcuts from your "\ " start menu.", file=sys.stdout) try: os.rmdir(start_menu) except OSError: print("Failed to remove %s; you may be able to remove it "\ "manually." % fname, file=sys.stderr) else: print("Successfully removed Spyder shortcut folder from your "\ " start menu.", file=sys.stdout)
[ "def", "remove", "(", ")", ":", "current", "=", "True", "# only affects current user\r", "root", "=", "winreg", ".", "HKEY_CURRENT_USER", "if", "current", "else", "winreg", ".", "HKEY_LOCAL_MACHINE", "for", "key", "in", "(", "KEY_C1", "%", "(", "\"\"", ",", "EWS", ")", ",", "KEY_C1", "%", "(", "\"NoCon\"", ",", "EWS", ")", ",", "KEY_C0", "%", "(", "\"\"", ",", "EWS", ")", ",", "KEY_C0", "%", "(", "\"NoCon\"", ",", "EWS", ")", ")", ":", "try", ":", "winreg", ".", "DeleteKey", "(", "root", ",", "key", ")", "except", "WindowsError", ":", "pass", "else", ":", "if", "not", "is_bdist_wininst", ":", "print", "(", "\"Successfully removed Spyder shortcuts from Windows \"", "\"Explorer context menu.\"", ",", "file", "=", "sys", ".", "stdout", ")", "if", "not", "is_bdist_wininst", ":", "# clean up desktop\r", "desktop_folder", "=", "get_special_folder_path", "(", "\"CSIDL_DESKTOPDIRECTORY\"", ")", "fname", "=", "osp", ".", "join", "(", "desktop_folder", ",", "'Spyder.lnk'", ")", "if", "osp", ".", "isfile", "(", "fname", ")", ":", "try", ":", "os", ".", "remove", "(", "fname", ")", "except", "OSError", ":", "print", "(", "\"Failed to remove %s; you may be able to remove it \"", "\"manually.\"", "%", "fname", ",", "file", "=", "sys", ".", "stderr", ")", "else", ":", "print", "(", "\"Successfully removed Spyder shortcuts from your desktop.\"", ",", "file", "=", "sys", ".", "stdout", ")", "# clean up startmenu\r", "start_menu", "=", "osp", ".", "join", "(", "get_special_folder_path", "(", "'CSIDL_PROGRAMS'", ")", ",", "'Spyder (Py%i.%i %i bit)'", "%", "(", "sys", ".", "version_info", "[", "0", "]", ",", "sys", ".", "version_info", "[", "1", "]", ",", "struct", ".", "calcsize", "(", "'P'", ")", "*", "8", ")", ")", "if", "osp", ".", "isdir", "(", "start_menu", ")", ":", "for", "fname", "in", "os", ".", "listdir", "(", "start_menu", ")", ":", "try", ":", "os", ".", "remove", "(", "osp", ".", "join", "(", "start_menu", ",", "fname", ")", ")", "except", "OSError", ":", "print", "(", "\"Failed to remove %s; you may be able to remove it \"", "\"manually.\"", "%", "fname", ",", "file", "=", "sys", ".", "stderr", ")", "else", ":", "print", "(", "\"Successfully removed Spyder shortcuts from your \"", "\" start menu.\"", ",", "file", "=", "sys", ".", "stdout", ")", "try", ":", "os", ".", "rmdir", "(", "start_menu", ")", "except", "OSError", ":", "print", "(", "\"Failed to remove %s; you may be able to remove it \"", "\"manually.\"", "%", "fname", ",", "file", "=", "sys", ".", "stderr", ")", "else", ":", "print", "(", "\"Successfully removed Spyder shortcut folder from your \"", "\" start menu.\"", ",", "file", "=", "sys", ".", "stdout", ")" ]
Function executed when running the script with the -remove switch
[ "Function", "executed", "when", "running", "the", "script", "with", "the", "-", "remove", "switch" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/scripts/spyder_win_post_install.py#L173-L222
train
spyder-ide/spyder
spyder/app/tour.py
get_tour
def get_tour(index): """ This function generates a list of tours. The index argument is used to retrieve a particular tour. If None is passed, it will return the full list of tours. If instead -1 is given, this function will return a test tour To add more tours a new variable needs to be created to hold the list of dicts and the tours variable at the bottom of this function needs to be updated accordingly """ sw = SpyderWidgets qtconsole_link = "https://qtconsole.readthedocs.io/en/stable/index.html" # This test should serve as example of keys to use in the tour frame dics test = [{'title': "Welcome to Spyder introduction tour", 'content': "<b>Spyder</b> is an interactive development \ environment. This tip panel supports rich text. <br>\ <br> it also supports image insertion to the right so\ far", 'image': 'tour-spyder-logo.png'}, {'title': "Widget display", 'content': ("This show how a widget is displayed. The tip panel " "is adjusted based on the first widget in the list"), 'widgets': ['button1'], 'decoration': ['button2'], 'interact': True}, {'title': "Widget display", 'content': ("This show how a widget is displayed. The tip panel " "is adjusted based on the first widget in the list"), 'widgets': ['button1'], 'decoration': ['button1'], 'interact': True}, {'title': "Widget display", 'content': ("This show how a widget is displayed. The tip panel " "is adjusted based on the first widget in the list"), 'widgets': ['button1'], 'interact': True}, {'title': "Widget display and highlight", 'content': "This shows how a highlighted widget looks", 'widgets': ['button'], 'decoration': ['button'], 'interact': False}, ] intro = [{'title': _("Welcome to the Introduction tour"), 'content': _("<b>Spyder</b> is a powerful Interactive " "Development Environment (or IDE) for the Python " "programming language.<br><br>" "Here we are going to guide you through its most " "important features.<br><br>" "Please use the arrow keys or click on the buttons " "below to move along the tour."), 'image': 'tour-spyder-logo.png'}, {'title': _("The Editor"), 'content': _("This is the pane where you write Python code before " "evaluating it. You can get automatic suggestions " "and completions while writing, by pressing the " "<b>Tab</b> key next to a given text.<br><br>" "The Editor comes " "with a line number area (highlighted here in red), " "where Spyder shows warnings and syntax errors. They " "can help you to detect potential problems before " "running the code.<br><br>" "You can also set debug breakpoints in the line " "number area, by doing a double click next to " "a non-empty line."), 'widgets': [sw.editor], 'decoration': [sw.editor_line_number_area]}, {'title': _("The IPython console"), 'content': _("This is one of panes where you can run or " "execute the code you wrote on the Editor. To do it " "you need to press the <b>F5</b> key.<br><br>" "This console comes with several " "useful features that greatly improve your " "programming workflow (like syntax highlighting and " "inline plots). If you want to know more about them, " "please follow this <a href=\"{0}\">link</a>.<br><br>" "Please click on the button below to run some simple " "code in this console. This will be useful to show " "you other important features.").format( qtconsole_link), 'widgets': [sw.ipython_console], 'run': ["li = list(range(100))", "d = {'a': 1, 'b': 2}"] }, {'title': _("The Variable Explorer"), 'content': _("In this pane you can view and edit the variables " "generated during the execution of a program, or " "those entered directly in one of Spyder " "consoles.<br><br>" "As you can see, the Variable Explorer is showing " "the variables generated during the last step of " "this tour. By doing a double-click on any " "of them, a new window will be opened, where you " "can inspect and modify their contents."), 'widgets': [sw.variable_explorer], 'interact': True}, {'title': _("Help"), 'content': _("This pane displays documentation of the " "functions, classes, methods or modules you are " "currently using in the Editor or the Consoles.<br><br>" "To use it, you need to press <b>Ctrl+I</b> in " "front of an object. If that object has some " "documentation associated with it, it will be " "displayed here."), 'widgets': [sw.help_plugin], 'interact': True}, {'title': _("The File Explorer"), 'content': _("This pane lets you navigate through the directories " "and files present in your computer.<br><br>" "You can also open any of these files with its " "corresponding application, by doing a double " "click on it.<br><br>" "There is one exception to this rule: plain-text " "files will always be opened in the Spyder Editor."), 'widgets': [sw.file_explorer], 'interact': True}, {'title': _("The History Log"), 'content': _("This pane records all commands introduced in " "the Python and IPython consoles."), 'widgets': [sw.history_log], 'interact': True}, ] # ['The run toolbar', # 'Should be short', # ['self.run_toolbar'], None], # ['The debug toolbar', # '', # ['self.debug_toolbar'], None], # ['The main toolbar', # '', # ['self.main_toolbar'], None], # ['The editor', # 'Spyder has differnet bla bla bla', # ['self.editor.dockwidget'], None], # ['The editor', # 'Spyder has differnet bla bla bla', # ['self.outlineexplorer.dockwidget'], None], # # ['The menu bar', # 'Spyder has differnet bla bla bla', # ['self.menuBar()'], None], # # ['The menu bar', # 'Spyder has differnet bla bla bla', # ['self.statusBar()'], None], # # # ['The toolbars!', # 'Spyder has differnet bla bla bla', # ['self.variableexplorer.dockwidget'], None], # ['The toolbars MO!', # 'Spyder has differnet bla bla bla', # ['self.extconsole.dockwidget'], None], # ['The whole window?!', # 'Spyder has differnet bla bla bla', # ['self'], None], # ['Lets try something!', # 'Spyder has differnet bla bla bla', # ['self.extconsole.dockwidget', # 'self.variableexplorer.dockwidget'], None] # # ] feat30 = [{'title': "New features in Spyder 3.0", 'content': _("<b>Spyder</b> is an interactive development " "environment based on bla"), 'image': 'spyder.png'}, {'title': _("Welcome to Spyder introduction tour"), 'content': _("Spyder is an interactive development environment " "based on bla"), 'widgets': ['variableexplorer']}, ] tours = [{'name': _('Introduction tour'), 'tour': intro}, {'name': _('New features in version 3.0'), 'tour': feat30}] if index is None: return tours elif index == -1: return [test] else: return [tours[index]]
python
def get_tour(index): """ This function generates a list of tours. The index argument is used to retrieve a particular tour. If None is passed, it will return the full list of tours. If instead -1 is given, this function will return a test tour To add more tours a new variable needs to be created to hold the list of dicts and the tours variable at the bottom of this function needs to be updated accordingly """ sw = SpyderWidgets qtconsole_link = "https://qtconsole.readthedocs.io/en/stable/index.html" # This test should serve as example of keys to use in the tour frame dics test = [{'title': "Welcome to Spyder introduction tour", 'content': "<b>Spyder</b> is an interactive development \ environment. This tip panel supports rich text. <br>\ <br> it also supports image insertion to the right so\ far", 'image': 'tour-spyder-logo.png'}, {'title': "Widget display", 'content': ("This show how a widget is displayed. The tip panel " "is adjusted based on the first widget in the list"), 'widgets': ['button1'], 'decoration': ['button2'], 'interact': True}, {'title': "Widget display", 'content': ("This show how a widget is displayed. The tip panel " "is adjusted based on the first widget in the list"), 'widgets': ['button1'], 'decoration': ['button1'], 'interact': True}, {'title': "Widget display", 'content': ("This show how a widget is displayed. The tip panel " "is adjusted based on the first widget in the list"), 'widgets': ['button1'], 'interact': True}, {'title': "Widget display and highlight", 'content': "This shows how a highlighted widget looks", 'widgets': ['button'], 'decoration': ['button'], 'interact': False}, ] intro = [{'title': _("Welcome to the Introduction tour"), 'content': _("<b>Spyder</b> is a powerful Interactive " "Development Environment (or IDE) for the Python " "programming language.<br><br>" "Here we are going to guide you through its most " "important features.<br><br>" "Please use the arrow keys or click on the buttons " "below to move along the tour."), 'image': 'tour-spyder-logo.png'}, {'title': _("The Editor"), 'content': _("This is the pane where you write Python code before " "evaluating it. You can get automatic suggestions " "and completions while writing, by pressing the " "<b>Tab</b> key next to a given text.<br><br>" "The Editor comes " "with a line number area (highlighted here in red), " "where Spyder shows warnings and syntax errors. They " "can help you to detect potential problems before " "running the code.<br><br>" "You can also set debug breakpoints in the line " "number area, by doing a double click next to " "a non-empty line."), 'widgets': [sw.editor], 'decoration': [sw.editor_line_number_area]}, {'title': _("The IPython console"), 'content': _("This is one of panes where you can run or " "execute the code you wrote on the Editor. To do it " "you need to press the <b>F5</b> key.<br><br>" "This console comes with several " "useful features that greatly improve your " "programming workflow (like syntax highlighting and " "inline plots). If you want to know more about them, " "please follow this <a href=\"{0}\">link</a>.<br><br>" "Please click on the button below to run some simple " "code in this console. This will be useful to show " "you other important features.").format( qtconsole_link), 'widgets': [sw.ipython_console], 'run': ["li = list(range(100))", "d = {'a': 1, 'b': 2}"] }, {'title': _("The Variable Explorer"), 'content': _("In this pane you can view and edit the variables " "generated during the execution of a program, or " "those entered directly in one of Spyder " "consoles.<br><br>" "As you can see, the Variable Explorer is showing " "the variables generated during the last step of " "this tour. By doing a double-click on any " "of them, a new window will be opened, where you " "can inspect and modify their contents."), 'widgets': [sw.variable_explorer], 'interact': True}, {'title': _("Help"), 'content': _("This pane displays documentation of the " "functions, classes, methods or modules you are " "currently using in the Editor or the Consoles.<br><br>" "To use it, you need to press <b>Ctrl+I</b> in " "front of an object. If that object has some " "documentation associated with it, it will be " "displayed here."), 'widgets': [sw.help_plugin], 'interact': True}, {'title': _("The File Explorer"), 'content': _("This pane lets you navigate through the directories " "and files present in your computer.<br><br>" "You can also open any of these files with its " "corresponding application, by doing a double " "click on it.<br><br>" "There is one exception to this rule: plain-text " "files will always be opened in the Spyder Editor."), 'widgets': [sw.file_explorer], 'interact': True}, {'title': _("The History Log"), 'content': _("This pane records all commands introduced in " "the Python and IPython consoles."), 'widgets': [sw.history_log], 'interact': True}, ] # ['The run toolbar', # 'Should be short', # ['self.run_toolbar'], None], # ['The debug toolbar', # '', # ['self.debug_toolbar'], None], # ['The main toolbar', # '', # ['self.main_toolbar'], None], # ['The editor', # 'Spyder has differnet bla bla bla', # ['self.editor.dockwidget'], None], # ['The editor', # 'Spyder has differnet bla bla bla', # ['self.outlineexplorer.dockwidget'], None], # # ['The menu bar', # 'Spyder has differnet bla bla bla', # ['self.menuBar()'], None], # # ['The menu bar', # 'Spyder has differnet bla bla bla', # ['self.statusBar()'], None], # # # ['The toolbars!', # 'Spyder has differnet bla bla bla', # ['self.variableexplorer.dockwidget'], None], # ['The toolbars MO!', # 'Spyder has differnet bla bla bla', # ['self.extconsole.dockwidget'], None], # ['The whole window?!', # 'Spyder has differnet bla bla bla', # ['self'], None], # ['Lets try something!', # 'Spyder has differnet bla bla bla', # ['self.extconsole.dockwidget', # 'self.variableexplorer.dockwidget'], None] # # ] feat30 = [{'title': "New features in Spyder 3.0", 'content': _("<b>Spyder</b> is an interactive development " "environment based on bla"), 'image': 'spyder.png'}, {'title': _("Welcome to Spyder introduction tour"), 'content': _("Spyder is an interactive development environment " "based on bla"), 'widgets': ['variableexplorer']}, ] tours = [{'name': _('Introduction tour'), 'tour': intro}, {'name': _('New features in version 3.0'), 'tour': feat30}] if index is None: return tours elif index == -1: return [test] else: return [tours[index]]
[ "def", "get_tour", "(", "index", ")", ":", "sw", "=", "SpyderWidgets", "qtconsole_link", "=", "\"https://qtconsole.readthedocs.io/en/stable/index.html\"", "# This test should serve as example of keys to use in the tour frame dics\r", "test", "=", "[", "{", "'title'", ":", "\"Welcome to Spyder introduction tour\"", ",", "'content'", ":", "\"<b>Spyder</b> is an interactive development \\\r\n environment. This tip panel supports rich text. <br>\\\r\n <br> it also supports image insertion to the right so\\\r\n far\"", ",", "'image'", ":", "'tour-spyder-logo.png'", "}", ",", "{", "'title'", ":", "\"Widget display\"", ",", "'content'", ":", "(", "\"This show how a widget is displayed. The tip panel \"", "\"is adjusted based on the first widget in the list\"", ")", ",", "'widgets'", ":", "[", "'button1'", "]", ",", "'decoration'", ":", "[", "'button2'", "]", ",", "'interact'", ":", "True", "}", ",", "{", "'title'", ":", "\"Widget display\"", ",", "'content'", ":", "(", "\"This show how a widget is displayed. The tip panel \"", "\"is adjusted based on the first widget in the list\"", ")", ",", "'widgets'", ":", "[", "'button1'", "]", ",", "'decoration'", ":", "[", "'button1'", "]", ",", "'interact'", ":", "True", "}", ",", "{", "'title'", ":", "\"Widget display\"", ",", "'content'", ":", "(", "\"This show how a widget is displayed. The tip panel \"", "\"is adjusted based on the first widget in the list\"", ")", ",", "'widgets'", ":", "[", "'button1'", "]", ",", "'interact'", ":", "True", "}", ",", "{", "'title'", ":", "\"Widget display and highlight\"", ",", "'content'", ":", "\"This shows how a highlighted widget looks\"", ",", "'widgets'", ":", "[", "'button'", "]", ",", "'decoration'", ":", "[", "'button'", "]", ",", "'interact'", ":", "False", "}", ",", "]", "intro", "=", "[", "{", "'title'", ":", "_", "(", "\"Welcome to the Introduction tour\"", ")", ",", "'content'", ":", "_", "(", "\"<b>Spyder</b> is a powerful Interactive \"", "\"Development Environment (or IDE) for the Python \"", "\"programming language.<br><br>\"", "\"Here we are going to guide you through its most \"", "\"important features.<br><br>\"", "\"Please use the arrow keys or click on the buttons \"", "\"below to move along the tour.\"", ")", ",", "'image'", ":", "'tour-spyder-logo.png'", "}", ",", "{", "'title'", ":", "_", "(", "\"The Editor\"", ")", ",", "'content'", ":", "_", "(", "\"This is the pane where you write Python code before \"", "\"evaluating it. You can get automatic suggestions \"", "\"and completions while writing, by pressing the \"", "\"<b>Tab</b> key next to a given text.<br><br>\"", "\"The Editor comes \"", "\"with a line number area (highlighted here in red), \"", "\"where Spyder shows warnings and syntax errors. They \"", "\"can help you to detect potential problems before \"", "\"running the code.<br><br>\"", "\"You can also set debug breakpoints in the line \"", "\"number area, by doing a double click next to \"", "\"a non-empty line.\"", ")", ",", "'widgets'", ":", "[", "sw", ".", "editor", "]", ",", "'decoration'", ":", "[", "sw", ".", "editor_line_number_area", "]", "}", ",", "{", "'title'", ":", "_", "(", "\"The IPython console\"", ")", ",", "'content'", ":", "_", "(", "\"This is one of panes where you can run or \"", "\"execute the code you wrote on the Editor. To do it \"", "\"you need to press the <b>F5</b> key.<br><br>\"", "\"This console comes with several \"", "\"useful features that greatly improve your \"", "\"programming workflow (like syntax highlighting and \"", "\"inline plots). If you want to know more about them, \"", "\"please follow this <a href=\\\"{0}\\\">link</a>.<br><br>\"", "\"Please click on the button below to run some simple \"", "\"code in this console. This will be useful to show \"", "\"you other important features.\"", ")", ".", "format", "(", "qtconsole_link", ")", ",", "'widgets'", ":", "[", "sw", ".", "ipython_console", "]", ",", "'run'", ":", "[", "\"li = list(range(100))\"", ",", "\"d = {'a': 1, 'b': 2}\"", "]", "}", ",", "{", "'title'", ":", "_", "(", "\"The Variable Explorer\"", ")", ",", "'content'", ":", "_", "(", "\"In this pane you can view and edit the variables \"", "\"generated during the execution of a program, or \"", "\"those entered directly in one of Spyder \"", "\"consoles.<br><br>\"", "\"As you can see, the Variable Explorer is showing \"", "\"the variables generated during the last step of \"", "\"this tour. By doing a double-click on any \"", "\"of them, a new window will be opened, where you \"", "\"can inspect and modify their contents.\"", ")", ",", "'widgets'", ":", "[", "sw", ".", "variable_explorer", "]", ",", "'interact'", ":", "True", "}", ",", "{", "'title'", ":", "_", "(", "\"Help\"", ")", ",", "'content'", ":", "_", "(", "\"This pane displays documentation of the \"", "\"functions, classes, methods or modules you are \"", "\"currently using in the Editor or the Consoles.<br><br>\"", "\"To use it, you need to press <b>Ctrl+I</b> in \"", "\"front of an object. If that object has some \"", "\"documentation associated with it, it will be \"", "\"displayed here.\"", ")", ",", "'widgets'", ":", "[", "sw", ".", "help_plugin", "]", ",", "'interact'", ":", "True", "}", ",", "{", "'title'", ":", "_", "(", "\"The File Explorer\"", ")", ",", "'content'", ":", "_", "(", "\"This pane lets you navigate through the directories \"", "\"and files present in your computer.<br><br>\"", "\"You can also open any of these files with its \"", "\"corresponding application, by doing a double \"", "\"click on it.<br><br>\"", "\"There is one exception to this rule: plain-text \"", "\"files will always be opened in the Spyder Editor.\"", ")", ",", "'widgets'", ":", "[", "sw", ".", "file_explorer", "]", ",", "'interact'", ":", "True", "}", ",", "{", "'title'", ":", "_", "(", "\"The History Log\"", ")", ",", "'content'", ":", "_", "(", "\"This pane records all commands introduced in \"", "\"the Python and IPython consoles.\"", ")", ",", "'widgets'", ":", "[", "sw", ".", "history_log", "]", ",", "'interact'", ":", "True", "}", ",", "]", "# ['The run toolbar',\r", "# 'Should be short',\r", "# ['self.run_toolbar'], None],\r", "# ['The debug toolbar',\r", "# '',\r", "# ['self.debug_toolbar'], None],\r", "# ['The main toolbar',\r", "# '',\r", "# ['self.main_toolbar'], None],\r", "# ['The editor',\r", "# 'Spyder has differnet bla bla bla',\r", "# ['self.editor.dockwidget'], None],\r", "# ['The editor',\r", "# 'Spyder has differnet bla bla bla',\r", "# ['self.outlineexplorer.dockwidget'], None],\r", "#\r", "# ['The menu bar',\r", "# 'Spyder has differnet bla bla bla',\r", "# ['self.menuBar()'], None],\r", "#\r", "# ['The menu bar',\r", "# 'Spyder has differnet bla bla bla',\r", "# ['self.statusBar()'], None],\r", "#\r", "#\r", "# ['The toolbars!',\r", "# 'Spyder has differnet bla bla bla',\r", "# ['self.variableexplorer.dockwidget'], None],\r", "# ['The toolbars MO!',\r", "# 'Spyder has differnet bla bla bla',\r", "# ['self.extconsole.dockwidget'], None],\r", "# ['The whole window?!',\r", "# 'Spyder has differnet bla bla bla',\r", "# ['self'], None],\r", "# ['Lets try something!',\r", "# 'Spyder has differnet bla bla bla',\r", "# ['self.extconsole.dockwidget',\r", "# 'self.variableexplorer.dockwidget'], None]\r", "#\r", "# ]\r", "feat30", "=", "[", "{", "'title'", ":", "\"New features in Spyder 3.0\"", ",", "'content'", ":", "_", "(", "\"<b>Spyder</b> is an interactive development \"", "\"environment based on bla\"", ")", ",", "'image'", ":", "'spyder.png'", "}", ",", "{", "'title'", ":", "_", "(", "\"Welcome to Spyder introduction tour\"", ")", ",", "'content'", ":", "_", "(", "\"Spyder is an interactive development environment \"", "\"based on bla\"", ")", ",", "'widgets'", ":", "[", "'variableexplorer'", "]", "}", ",", "]", "tours", "=", "[", "{", "'name'", ":", "_", "(", "'Introduction tour'", ")", ",", "'tour'", ":", "intro", "}", ",", "{", "'name'", ":", "_", "(", "'New features in version 3.0'", ")", ",", "'tour'", ":", "feat30", "}", "]", "if", "index", "is", "None", ":", "return", "tours", "elif", "index", "==", "-", "1", ":", "return", "[", "test", "]", "else", ":", "return", "[", "tours", "[", "index", "]", "]" ]
This function generates a list of tours. The index argument is used to retrieve a particular tour. If None is passed, it will return the full list of tours. If instead -1 is given, this function will return a test tour To add more tours a new variable needs to be created to hold the list of dicts and the tours variable at the bottom of this function needs to be updated accordingly
[ "This", "function", "generates", "a", "list", "of", "tours", ".", "The", "index", "argument", "is", "used", "to", "retrieve", "a", "particular", "tour", ".", "If", "None", "is", "passed", "it", "will", "return", "the", "full", "list", "of", "tours", ".", "If", "instead", "-", "1", "is", "given", "this", "function", "will", "return", "a", "test", "tour", "To", "add", "more", "tours", "a", "new", "variable", "needs", "to", "be", "created", "to", "hold", "the", "list", "of", "dicts", "and", "the", "tours", "variable", "at", "the", "bottom", "of", "this", "function", "needs", "to", "be", "updated", "accordingly" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/tour.py#L82-L277
train
spyder-ide/spyder
spyder/app/tour.py
FadingCanvas.paintEvent
def paintEvent(self, event): """Override Qt method""" painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) # Decoration painter.fillPath(self.path_current, QBrush(self.color)) painter.strokePath(self.path_decoration, QPen(self.color_decoration, self.stroke_decoration))
python
def paintEvent(self, event): """Override Qt method""" painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) # Decoration painter.fillPath(self.path_current, QBrush(self.color)) painter.strokePath(self.path_decoration, QPen(self.color_decoration, self.stroke_decoration))
[ "def", "paintEvent", "(", "self", ",", "event", ")", ":", "painter", "=", "QPainter", "(", "self", ")", "painter", ".", "setRenderHint", "(", "QPainter", ".", "Antialiasing", ")", "# Decoration\r", "painter", ".", "fillPath", "(", "self", ".", "path_current", ",", "QBrush", "(", "self", ".", "color", ")", ")", "painter", ".", "strokePath", "(", "self", ".", "path_decoration", ",", "QPen", "(", "self", ".", "color_decoration", ",", "self", ".", "stroke_decoration", ")", ")" ]
Override Qt method
[ "Override", "Qt", "method" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/tour.py#L500-L507
train
spyder-ide/spyder
spyder/app/tour.py
FadingCanvas.reject
def reject(self): """Override Qt method""" if not self.is_fade_running(): key = Qt.Key_Escape self.key_pressed = key self.sig_key_pressed.emit()
python
def reject(self): """Override Qt method""" if not self.is_fade_running(): key = Qt.Key_Escape self.key_pressed = key self.sig_key_pressed.emit()
[ "def", "reject", "(", "self", ")", ":", "if", "not", "self", ".", "is_fade_running", "(", ")", ":", "key", "=", "Qt", ".", "Key_Escape", "self", ".", "key_pressed", "=", "key", "self", ".", "sig_key_pressed", ".", "emit", "(", ")" ]
Override Qt method
[ "Override", "Qt", "method" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/tour.py#L512-L517
train
spyder-ide/spyder
spyder/app/tour.py
FadingTipBox.mousePressEvent
def mousePressEvent(self, event): """override Qt method""" # Raise the main application window on click self.parent.raise_() self.raise_() if event.button() == Qt.RightButton: pass
python
def mousePressEvent(self, event): """override Qt method""" # Raise the main application window on click self.parent.raise_() self.raise_() if event.button() == Qt.RightButton: pass
[ "def", "mousePressEvent", "(", "self", ",", "event", ")", ":", "# Raise the main application window on click\r", "self", ".", "parent", ".", "raise_", "(", ")", "self", ".", "raise_", "(", ")", "if", "event", ".", "button", "(", ")", "==", "Qt", ".", "RightButton", ":", "pass" ]
override Qt method
[ "override", "Qt", "method" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/tour.py#L804-L811
train
spyder-ide/spyder
spyder/app/tour.py
AnimatedTour._set_data
def _set_data(self): """Set data that is displayed in each step of the tour.""" self.setting_data = True step, steps, frames = self.step_current, self.steps, self.frames current = '{0}/{1}'.format(step + 1, steps) frame = frames[step] combobox_frames = [u"{0}. {1}".format(i+1, f['title']) for i, f in enumerate(frames)] title, content, image = '', '', None widgets, dockwidgets, decoration = None, None, None run = None # Check if entry exists in dic and act accordingly if 'title' in frame: title = frame['title'] if 'content' in frame: content = frame['content'] if 'widgets' in frame: widget_names = frames[step]['widgets'] # Get the widgets based on their name widgets, dockwidgets = self._process_widgets(widget_names, self.spy_window) self.widgets = widgets self.dockwidgets = dockwidgets if 'decoration' in frame: widget_names = frames[step]['decoration'] deco, decoration = self._process_widgets(widget_names, self.spy_window) self.decoration = decoration if 'image' in frame: image = frames[step]['image'] if 'interact' in frame: self.canvas.set_interaction(frame['interact']) if frame['interact']: self._set_modal(False, [self.tips]) else: self._set_modal(True, [self.tips]) else: self.canvas.set_interaction(False) self._set_modal(True, [self.tips]) if 'run' in frame: # Asume that the frist widget is the console run = frame['run'] self.run = run self.tips.set_data(title, content, current, image, run, frames=combobox_frames, step=step) self._check_buttons() # Make canvas black when starting a new place of decoration self.canvas.update_widgets(dockwidgets) self.canvas.update_decoration(decoration) self.setting_data = False
python
def _set_data(self): """Set data that is displayed in each step of the tour.""" self.setting_data = True step, steps, frames = self.step_current, self.steps, self.frames current = '{0}/{1}'.format(step + 1, steps) frame = frames[step] combobox_frames = [u"{0}. {1}".format(i+1, f['title']) for i, f in enumerate(frames)] title, content, image = '', '', None widgets, dockwidgets, decoration = None, None, None run = None # Check if entry exists in dic and act accordingly if 'title' in frame: title = frame['title'] if 'content' in frame: content = frame['content'] if 'widgets' in frame: widget_names = frames[step]['widgets'] # Get the widgets based on their name widgets, dockwidgets = self._process_widgets(widget_names, self.spy_window) self.widgets = widgets self.dockwidgets = dockwidgets if 'decoration' in frame: widget_names = frames[step]['decoration'] deco, decoration = self._process_widgets(widget_names, self.spy_window) self.decoration = decoration if 'image' in frame: image = frames[step]['image'] if 'interact' in frame: self.canvas.set_interaction(frame['interact']) if frame['interact']: self._set_modal(False, [self.tips]) else: self._set_modal(True, [self.tips]) else: self.canvas.set_interaction(False) self._set_modal(True, [self.tips]) if 'run' in frame: # Asume that the frist widget is the console run = frame['run'] self.run = run self.tips.set_data(title, content, current, image, run, frames=combobox_frames, step=step) self._check_buttons() # Make canvas black when starting a new place of decoration self.canvas.update_widgets(dockwidgets) self.canvas.update_decoration(decoration) self.setting_data = False
[ "def", "_set_data", "(", "self", ")", ":", "self", ".", "setting_data", "=", "True", "step", ",", "steps", ",", "frames", "=", "self", ".", "step_current", ",", "self", ".", "steps", ",", "self", ".", "frames", "current", "=", "'{0}/{1}'", ".", "format", "(", "step", "+", "1", ",", "steps", ")", "frame", "=", "frames", "[", "step", "]", "combobox_frames", "=", "[", "u\"{0}. {1}\"", ".", "format", "(", "i", "+", "1", ",", "f", "[", "'title'", "]", ")", "for", "i", ",", "f", "in", "enumerate", "(", "frames", ")", "]", "title", ",", "content", ",", "image", "=", "''", ",", "''", ",", "None", "widgets", ",", "dockwidgets", ",", "decoration", "=", "None", ",", "None", ",", "None", "run", "=", "None", "# Check if entry exists in dic and act accordingly\r", "if", "'title'", "in", "frame", ":", "title", "=", "frame", "[", "'title'", "]", "if", "'content'", "in", "frame", ":", "content", "=", "frame", "[", "'content'", "]", "if", "'widgets'", "in", "frame", ":", "widget_names", "=", "frames", "[", "step", "]", "[", "'widgets'", "]", "# Get the widgets based on their name\r", "widgets", ",", "dockwidgets", "=", "self", ".", "_process_widgets", "(", "widget_names", ",", "self", ".", "spy_window", ")", "self", ".", "widgets", "=", "widgets", "self", ".", "dockwidgets", "=", "dockwidgets", "if", "'decoration'", "in", "frame", ":", "widget_names", "=", "frames", "[", "step", "]", "[", "'decoration'", "]", "deco", ",", "decoration", "=", "self", ".", "_process_widgets", "(", "widget_names", ",", "self", ".", "spy_window", ")", "self", ".", "decoration", "=", "decoration", "if", "'image'", "in", "frame", ":", "image", "=", "frames", "[", "step", "]", "[", "'image'", "]", "if", "'interact'", "in", "frame", ":", "self", ".", "canvas", ".", "set_interaction", "(", "frame", "[", "'interact'", "]", ")", "if", "frame", "[", "'interact'", "]", ":", "self", ".", "_set_modal", "(", "False", ",", "[", "self", ".", "tips", "]", ")", "else", ":", "self", ".", "_set_modal", "(", "True", ",", "[", "self", ".", "tips", "]", ")", "else", ":", "self", ".", "canvas", ".", "set_interaction", "(", "False", ")", "self", ".", "_set_modal", "(", "True", ",", "[", "self", ".", "tips", "]", ")", "if", "'run'", "in", "frame", ":", "# Asume that the frist widget is the console\r", "run", "=", "frame", "[", "'run'", "]", "self", ".", "run", "=", "run", "self", ".", "tips", ".", "set_data", "(", "title", ",", "content", ",", "current", ",", "image", ",", "run", ",", "frames", "=", "combobox_frames", ",", "step", "=", "step", ")", "self", ".", "_check_buttons", "(", ")", "# Make canvas black when starting a new place of decoration\r", "self", ".", "canvas", ".", "update_widgets", "(", "dockwidgets", ")", "self", ".", "canvas", ".", "update_decoration", "(", "decoration", ")", "self", ".", "setting_data", "=", "False" ]
Set data that is displayed in each step of the tour.
[ "Set", "data", "that", "is", "displayed", "in", "each", "step", "of", "the", "tour", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/tour.py#L1001-L1061
train
spyder-ide/spyder
spyder/app/tour.py
AnimatedTour.lost_focus
def lost_focus(self): """Confirm if the tour loses focus and hides the tips.""" if (self.is_running and not self.any_has_focus() and not self.setting_data and not self.hidden): self.hide_tips()
python
def lost_focus(self): """Confirm if the tour loses focus and hides the tips.""" if (self.is_running and not self.any_has_focus() and not self.setting_data and not self.hidden): self.hide_tips()
[ "def", "lost_focus", "(", "self", ")", ":", "if", "(", "self", ".", "is_running", "and", "not", "self", ".", "any_has_focus", "(", ")", "and", "not", "self", ".", "setting_data", "and", "not", "self", ".", "hidden", ")", ":", "self", ".", "hide_tips", "(", ")" ]
Confirm if the tour loses focus and hides the tips.
[ "Confirm", "if", "the", "tour", "loses", "focus", "and", "hides", "the", "tips", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/tour.py#L1239-L1243
train
spyder-ide/spyder
spyder/app/tour.py
AnimatedTour.gain_focus
def gain_focus(self): """Confirm if the tour regains focus and unhides the tips.""" if (self.is_running and self.any_has_focus() and not self.setting_data and self.hidden): self.unhide_tips()
python
def gain_focus(self): """Confirm if the tour regains focus and unhides the tips.""" if (self.is_running and self.any_has_focus() and not self.setting_data and self.hidden): self.unhide_tips()
[ "def", "gain_focus", "(", "self", ")", ":", "if", "(", "self", ".", "is_running", "and", "self", ".", "any_has_focus", "(", ")", "and", "not", "self", ".", "setting_data", "and", "self", ".", "hidden", ")", ":", "self", ".", "unhide_tips", "(", ")" ]
Confirm if the tour regains focus and unhides the tips.
[ "Confirm", "if", "the", "tour", "regains", "focus", "and", "unhides", "the", "tips", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/tour.py#L1245-L1249
train
spyder-ide/spyder
spyder/app/tour.py
AnimatedTour.any_has_focus
def any_has_focus(self): """Returns if tour or any of its components has focus.""" f = (self.hasFocus() or self.parent.hasFocus() or self.tips.hasFocus() or self.canvas.hasFocus()) return f
python
def any_has_focus(self): """Returns if tour or any of its components has focus.""" f = (self.hasFocus() or self.parent.hasFocus() or self.tips.hasFocus() or self.canvas.hasFocus()) return f
[ "def", "any_has_focus", "(", "self", ")", ":", "f", "=", "(", "self", ".", "hasFocus", "(", ")", "or", "self", ".", "parent", ".", "hasFocus", "(", ")", "or", "self", ".", "tips", ".", "hasFocus", "(", ")", "or", "self", ".", "canvas", ".", "hasFocus", "(", ")", ")", "return", "f" ]
Returns if tour or any of its components has focus.
[ "Returns", "if", "tour", "or", "any", "of", "its", "components", "has", "focus", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/tour.py#L1251-L1255
train
spyder-ide/spyder
spyder/plugins/ipythonconsole/widgets/figurebrowser.py
FigureBrowserWidget._handle_display_data
def _handle_display_data(self, msg): """ Reimplemented to handle communications between the figure explorer and the kernel. """ img = None data = msg['content']['data'] if 'image/svg+xml' in data: fmt = 'image/svg+xml' img = data['image/svg+xml'] elif 'image/png' in data: # PNG data is base64 encoded as it passes over the network # in a JSON structure so we decode it. fmt = 'image/png' img = decodestring(data['image/png'].encode('ascii')) elif 'image/jpeg' in data and self._jpg_supported: fmt = 'image/jpeg' img = decodestring(data['image/jpeg'].encode('ascii')) if img is not None: self.sig_new_inline_figure.emit(img, fmt) if (self.figurebrowser is not None and self.figurebrowser.mute_inline_plotting): if not self.sended_render_message: msg['content']['data']['text/plain'] = '' self._append_html( _('<br><hr>' '\nFigures now render in the Plots pane by default. ' 'To make them also appear inline in the Console, ' 'uncheck "Mute Inline Plotting" under the Plots ' 'pane options menu. \n' '<hr><br>'), before_prompt=True) self.sended_render_message = True else: msg['content']['data']['text/plain'] = '' del msg['content']['data'][fmt] return super(FigureBrowserWidget, self)._handle_display_data(msg)
python
def _handle_display_data(self, msg): """ Reimplemented to handle communications between the figure explorer and the kernel. """ img = None data = msg['content']['data'] if 'image/svg+xml' in data: fmt = 'image/svg+xml' img = data['image/svg+xml'] elif 'image/png' in data: # PNG data is base64 encoded as it passes over the network # in a JSON structure so we decode it. fmt = 'image/png' img = decodestring(data['image/png'].encode('ascii')) elif 'image/jpeg' in data and self._jpg_supported: fmt = 'image/jpeg' img = decodestring(data['image/jpeg'].encode('ascii')) if img is not None: self.sig_new_inline_figure.emit(img, fmt) if (self.figurebrowser is not None and self.figurebrowser.mute_inline_plotting): if not self.sended_render_message: msg['content']['data']['text/plain'] = '' self._append_html( _('<br><hr>' '\nFigures now render in the Plots pane by default. ' 'To make them also appear inline in the Console, ' 'uncheck "Mute Inline Plotting" under the Plots ' 'pane options menu. \n' '<hr><br>'), before_prompt=True) self.sended_render_message = True else: msg['content']['data']['text/plain'] = '' del msg['content']['data'][fmt] return super(FigureBrowserWidget, self)._handle_display_data(msg)
[ "def", "_handle_display_data", "(", "self", ",", "msg", ")", ":", "img", "=", "None", "data", "=", "msg", "[", "'content'", "]", "[", "'data'", "]", "if", "'image/svg+xml'", "in", "data", ":", "fmt", "=", "'image/svg+xml'", "img", "=", "data", "[", "'image/svg+xml'", "]", "elif", "'image/png'", "in", "data", ":", "# PNG data is base64 encoded as it passes over the network", "# in a JSON structure so we decode it.", "fmt", "=", "'image/png'", "img", "=", "decodestring", "(", "data", "[", "'image/png'", "]", ".", "encode", "(", "'ascii'", ")", ")", "elif", "'image/jpeg'", "in", "data", "and", "self", ".", "_jpg_supported", ":", "fmt", "=", "'image/jpeg'", "img", "=", "decodestring", "(", "data", "[", "'image/jpeg'", "]", ".", "encode", "(", "'ascii'", ")", ")", "if", "img", "is", "not", "None", ":", "self", ".", "sig_new_inline_figure", ".", "emit", "(", "img", ",", "fmt", ")", "if", "(", "self", ".", "figurebrowser", "is", "not", "None", "and", "self", ".", "figurebrowser", ".", "mute_inline_plotting", ")", ":", "if", "not", "self", ".", "sended_render_message", ":", "msg", "[", "'content'", "]", "[", "'data'", "]", "[", "'text/plain'", "]", "=", "''", "self", ".", "_append_html", "(", "_", "(", "'<br><hr>'", "'\\nFigures now render in the Plots pane by default. '", "'To make them also appear inline in the Console, '", "'uncheck \"Mute Inline Plotting\" under the Plots '", "'pane options menu. \\n'", "'<hr><br>'", ")", ",", "before_prompt", "=", "True", ")", "self", ".", "sended_render_message", "=", "True", "else", ":", "msg", "[", "'content'", "]", "[", "'data'", "]", "[", "'text/plain'", "]", "=", "''", "del", "msg", "[", "'content'", "]", "[", "'data'", "]", "[", "fmt", "]", "return", "super", "(", "FigureBrowserWidget", ",", "self", ")", ".", "_handle_display_data", "(", "msg", ")" ]
Reimplemented to handle communications between the figure explorer and the kernel.
[ "Reimplemented", "to", "handle", "communications", "between", "the", "figure", "explorer", "and", "the", "kernel", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/ipythonconsole/widgets/figurebrowser.py#L40-L76
train
spyder-ide/spyder
spyder/plugins/editor/widgets/codeeditor.py
get_file_language
def get_file_language(filename, text=None): """Get file language from filename""" ext = osp.splitext(filename)[1] if ext.startswith('.'): ext = ext[1:] # file extension with leading dot language = ext if not ext: if text is None: text, _enc = encoding.read(filename) for line in text.splitlines(): if not line.strip(): continue if line.startswith('#!'): shebang = line[2:] if 'python' in shebang: language = 'python' else: break return language
python
def get_file_language(filename, text=None): """Get file language from filename""" ext = osp.splitext(filename)[1] if ext.startswith('.'): ext = ext[1:] # file extension with leading dot language = ext if not ext: if text is None: text, _enc = encoding.read(filename) for line in text.splitlines(): if not line.strip(): continue if line.startswith('#!'): shebang = line[2:] if 'python' in shebang: language = 'python' else: break return language
[ "def", "get_file_language", "(", "filename", ",", "text", "=", "None", ")", ":", "ext", "=", "osp", ".", "splitext", "(", "filename", ")", "[", "1", "]", "if", "ext", ".", "startswith", "(", "'.'", ")", ":", "ext", "=", "ext", "[", "1", ":", "]", "# file extension with leading dot\r", "language", "=", "ext", "if", "not", "ext", ":", "if", "text", "is", "None", ":", "text", ",", "_enc", "=", "encoding", ".", "read", "(", "filename", ")", "for", "line", "in", "text", ".", "splitlines", "(", ")", ":", "if", "not", "line", ".", "strip", "(", ")", ":", "continue", "if", "line", ".", "startswith", "(", "'#!'", ")", ":", "shebang", "=", "line", "[", "2", ":", "]", "if", "'python'", "in", "shebang", ":", "language", "=", "'python'", "else", ":", "break", "return", "language" ]
Get file language from filename
[ "Get", "file", "language", "from", "filename" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/widgets/codeeditor.py#L175-L193
train
spyder-ide/spyder
spyder/plugins/editor/widgets/codeeditor.py
GoToLineDialog.text_has_changed
def text_has_changed(self, text): """Line edit's text has changed""" text = to_text_string(text) if text: self.lineno = int(text) else: self.lineno = None
python
def text_has_changed(self, text): """Line edit's text has changed""" text = to_text_string(text) if text: self.lineno = int(text) else: self.lineno = None
[ "def", "text_has_changed", "(", "self", ",", "text", ")", ":", "text", "=", "to_text_string", "(", "text", ")", "if", "text", ":", "self", ".", "lineno", "=", "int", "(", "text", ")", "else", ":", "self", ".", "lineno", "=", "None" ]
Line edit's text has changed
[ "Line", "edit", "s", "text", "has", "changed" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/widgets/codeeditor.py#L157-L163
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
save_figure_tofile
def save_figure_tofile(fig, fmt, fname): """Save fig to fname in the format specified by fmt.""" root, ext = osp.splitext(fname) if ext == '.png' and fmt == 'image/svg+xml': qimg = svg_to_image(fig) qimg.save(fname) else: if fmt == 'image/svg+xml' and is_unicode(fig): fig = fig.encode('utf-8') with open(fname, 'wb') as f: f.write(fig)
python
def save_figure_tofile(fig, fmt, fname): """Save fig to fname in the format specified by fmt.""" root, ext = osp.splitext(fname) if ext == '.png' and fmt == 'image/svg+xml': qimg = svg_to_image(fig) qimg.save(fname) else: if fmt == 'image/svg+xml' and is_unicode(fig): fig = fig.encode('utf-8') with open(fname, 'wb') as f: f.write(fig)
[ "def", "save_figure_tofile", "(", "fig", ",", "fmt", ",", "fname", ")", ":", "root", ",", "ext", "=", "osp", ".", "splitext", "(", "fname", ")", "if", "ext", "==", "'.png'", "and", "fmt", "==", "'image/svg+xml'", ":", "qimg", "=", "svg_to_image", "(", "fig", ")", "qimg", ".", "save", "(", "fname", ")", "else", ":", "if", "fmt", "==", "'image/svg+xml'", "and", "is_unicode", "(", "fig", ")", ":", "fig", "=", "fig", ".", "encode", "(", "'utf-8'", ")", "with", "open", "(", "fname", ",", "'wb'", ")", "as", "f", ":", "f", ".", "write", "(", "fig", ")" ]
Save fig to fname in the format specified by fmt.
[ "Save", "fig", "to", "fname", "in", "the", "format", "specified", "by", "fmt", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L38-L49
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
get_unique_figname
def get_unique_figname(dirname, root, ext): """ Append a number to "root" to form a filename that does not already exist in "dirname". """ i = 1 figname = root + '_%d' % i + ext while True: if osp.exists(osp.join(dirname, figname)): i += 1 figname = root + '_%d' % i + ext else: return osp.join(dirname, figname)
python
def get_unique_figname(dirname, root, ext): """ Append a number to "root" to form a filename that does not already exist in "dirname". """ i = 1 figname = root + '_%d' % i + ext while True: if osp.exists(osp.join(dirname, figname)): i += 1 figname = root + '_%d' % i + ext else: return osp.join(dirname, figname)
[ "def", "get_unique_figname", "(", "dirname", ",", "root", ",", "ext", ")", ":", "i", "=", "1", "figname", "=", "root", "+", "'_%d'", "%", "i", "+", "ext", "while", "True", ":", "if", "osp", ".", "exists", "(", "osp", ".", "join", "(", "dirname", ",", "figname", ")", ")", ":", "i", "+=", "1", "figname", "=", "root", "+", "'_%d'", "%", "i", "+", "ext", "else", ":", "return", "osp", ".", "join", "(", "dirname", ",", "figname", ")" ]
Append a number to "root" to form a filename that does not already exist in "dirname".
[ "Append", "a", "number", "to", "root", "to", "form", "a", "filename", "that", "does", "not", "already", "exist", "in", "dirname", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L52-L64
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
FigureBrowser.setup
def setup(self, mute_inline_plotting=None, show_plot_outline=None): """Setup the figure browser with provided settings.""" assert self.shellwidget is not None self.mute_inline_plotting = mute_inline_plotting self.show_plot_outline = show_plot_outline if self.figviewer is not None: self.mute_inline_action.setChecked(mute_inline_plotting) self.show_plot_outline_action.setChecked(show_plot_outline) return self.figviewer = FigureViewer(background_color=self.background_color) self.figviewer.setStyleSheet("FigureViewer{" "border: 1px solid lightgrey;" "border-top-width: 0px;" "border-bottom-width: 0px;" "border-left-width: 0px;" "}") self.thumbnails_sb = ThumbnailScrollBar( self.figviewer, background_color=self.background_color) # Option actions : self.setup_option_actions(mute_inline_plotting, show_plot_outline) # Create the layout : main_widget = QSplitter() main_widget.addWidget(self.figviewer) main_widget.addWidget(self.thumbnails_sb) main_widget.setFrameStyle(QScrollArea().frameStyle()) self.tools_layout = QHBoxLayout() toolbar = self.setup_toolbar() for widget in toolbar: self.tools_layout.addWidget(widget) self.tools_layout.addStretch() self.setup_options_button() layout = create_plugin_layout(self.tools_layout, main_widget) self.setLayout(layout)
python
def setup(self, mute_inline_plotting=None, show_plot_outline=None): """Setup the figure browser with provided settings.""" assert self.shellwidget is not None self.mute_inline_plotting = mute_inline_plotting self.show_plot_outline = show_plot_outline if self.figviewer is not None: self.mute_inline_action.setChecked(mute_inline_plotting) self.show_plot_outline_action.setChecked(show_plot_outline) return self.figviewer = FigureViewer(background_color=self.background_color) self.figviewer.setStyleSheet("FigureViewer{" "border: 1px solid lightgrey;" "border-top-width: 0px;" "border-bottom-width: 0px;" "border-left-width: 0px;" "}") self.thumbnails_sb = ThumbnailScrollBar( self.figviewer, background_color=self.background_color) # Option actions : self.setup_option_actions(mute_inline_plotting, show_plot_outline) # Create the layout : main_widget = QSplitter() main_widget.addWidget(self.figviewer) main_widget.addWidget(self.thumbnails_sb) main_widget.setFrameStyle(QScrollArea().frameStyle()) self.tools_layout = QHBoxLayout() toolbar = self.setup_toolbar() for widget in toolbar: self.tools_layout.addWidget(widget) self.tools_layout.addStretch() self.setup_options_button() layout = create_plugin_layout(self.tools_layout, main_widget) self.setLayout(layout)
[ "def", "setup", "(", "self", ",", "mute_inline_plotting", "=", "None", ",", "show_plot_outline", "=", "None", ")", ":", "assert", "self", ".", "shellwidget", "is", "not", "None", "self", ".", "mute_inline_plotting", "=", "mute_inline_plotting", "self", ".", "show_plot_outline", "=", "show_plot_outline", "if", "self", ".", "figviewer", "is", "not", "None", ":", "self", ".", "mute_inline_action", ".", "setChecked", "(", "mute_inline_plotting", ")", "self", ".", "show_plot_outline_action", ".", "setChecked", "(", "show_plot_outline", ")", "return", "self", ".", "figviewer", "=", "FigureViewer", "(", "background_color", "=", "self", ".", "background_color", ")", "self", ".", "figviewer", ".", "setStyleSheet", "(", "\"FigureViewer{\"", "\"border: 1px solid lightgrey;\"", "\"border-top-width: 0px;\"", "\"border-bottom-width: 0px;\"", "\"border-left-width: 0px;\"", "\"}\"", ")", "self", ".", "thumbnails_sb", "=", "ThumbnailScrollBar", "(", "self", ".", "figviewer", ",", "background_color", "=", "self", ".", "background_color", ")", "# Option actions :", "self", ".", "setup_option_actions", "(", "mute_inline_plotting", ",", "show_plot_outline", ")", "# Create the layout :", "main_widget", "=", "QSplitter", "(", ")", "main_widget", ".", "addWidget", "(", "self", ".", "figviewer", ")", "main_widget", ".", "addWidget", "(", "self", ".", "thumbnails_sb", ")", "main_widget", ".", "setFrameStyle", "(", "QScrollArea", "(", ")", ".", "frameStyle", "(", ")", ")", "self", ".", "tools_layout", "=", "QHBoxLayout", "(", ")", "toolbar", "=", "self", ".", "setup_toolbar", "(", ")", "for", "widget", "in", "toolbar", ":", "self", ".", "tools_layout", ".", "addWidget", "(", "widget", ")", "self", ".", "tools_layout", ".", "addStretch", "(", ")", "self", ".", "setup_options_button", "(", ")", "layout", "=", "create_plugin_layout", "(", "self", ".", "tools_layout", ",", "main_widget", ")", "self", ".", "setLayout", "(", "layout", ")" ]
Setup the figure browser with provided settings.
[ "Setup", "the", "figure", "browser", "with", "provided", "settings", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L97-L136
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
FigureBrowser.setup_toolbar
def setup_toolbar(self): """Setup the toolbar""" savefig_btn = create_toolbutton( self, icon=ima.icon('filesave'), tip=_("Save Image As..."), triggered=self.save_figure) saveall_btn = create_toolbutton( self, icon=ima.icon('save_all'), tip=_("Save All Images..."), triggered=self.save_all_figures) copyfig_btn = create_toolbutton( self, icon=ima.icon('editcopy'), tip=_("Copy plot to clipboard as image (%s)" % get_shortcut('plots', 'copy')), triggered=self.copy_figure) closefig_btn = create_toolbutton( self, icon=ima.icon('editclear'), tip=_("Remove image"), triggered=self.close_figure) closeall_btn = create_toolbutton( self, icon=ima.icon('filecloseall'), tip=_("Remove all images from the explorer"), triggered=self.close_all_figures) vsep1 = QFrame() vsep1.setFrameStyle(53) goback_btn = create_toolbutton( self, icon=ima.icon('ArrowBack'), tip=_("Previous Figure ({})".format( get_shortcut('plots', 'previous figure'))), triggered=self.go_previous_thumbnail) gonext_btn = create_toolbutton( self, icon=ima.icon('ArrowForward'), tip=_("Next Figure ({})".format( get_shortcut('plots', 'next figure'))), triggered=self.go_next_thumbnail) vsep2 = QFrame() vsep2.setFrameStyle(53) zoom_out_btn = create_toolbutton( self, icon=ima.icon('zoom_out'), tip=_("Zoom out (Ctrl + mouse-wheel-down)"), triggered=self.zoom_out) zoom_in_btn = create_toolbutton( self, icon=ima.icon('zoom_in'), tip=_("Zoom in (Ctrl + mouse-wheel-up)"), triggered=self.zoom_in) self.zoom_disp = QSpinBox() self.zoom_disp.setAlignment(Qt.AlignCenter) self.zoom_disp.setButtonSymbols(QSpinBox.NoButtons) self.zoom_disp.setReadOnly(True) self.zoom_disp.setSuffix(' %') self.zoom_disp.setRange(0, 9999) self.zoom_disp.setValue(100) self.figviewer.sig_zoom_changed.connect(self.zoom_disp.setValue) zoom_pan = QWidget() layout = QHBoxLayout(zoom_pan) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(zoom_out_btn) layout.addWidget(zoom_in_btn) layout.addWidget(self.zoom_disp) return [savefig_btn, saveall_btn, copyfig_btn, closefig_btn, closeall_btn, vsep1, goback_btn, gonext_btn, vsep2, zoom_pan]
python
def setup_toolbar(self): """Setup the toolbar""" savefig_btn = create_toolbutton( self, icon=ima.icon('filesave'), tip=_("Save Image As..."), triggered=self.save_figure) saveall_btn = create_toolbutton( self, icon=ima.icon('save_all'), tip=_("Save All Images..."), triggered=self.save_all_figures) copyfig_btn = create_toolbutton( self, icon=ima.icon('editcopy'), tip=_("Copy plot to clipboard as image (%s)" % get_shortcut('plots', 'copy')), triggered=self.copy_figure) closefig_btn = create_toolbutton( self, icon=ima.icon('editclear'), tip=_("Remove image"), triggered=self.close_figure) closeall_btn = create_toolbutton( self, icon=ima.icon('filecloseall'), tip=_("Remove all images from the explorer"), triggered=self.close_all_figures) vsep1 = QFrame() vsep1.setFrameStyle(53) goback_btn = create_toolbutton( self, icon=ima.icon('ArrowBack'), tip=_("Previous Figure ({})".format( get_shortcut('plots', 'previous figure'))), triggered=self.go_previous_thumbnail) gonext_btn = create_toolbutton( self, icon=ima.icon('ArrowForward'), tip=_("Next Figure ({})".format( get_shortcut('plots', 'next figure'))), triggered=self.go_next_thumbnail) vsep2 = QFrame() vsep2.setFrameStyle(53) zoom_out_btn = create_toolbutton( self, icon=ima.icon('zoom_out'), tip=_("Zoom out (Ctrl + mouse-wheel-down)"), triggered=self.zoom_out) zoom_in_btn = create_toolbutton( self, icon=ima.icon('zoom_in'), tip=_("Zoom in (Ctrl + mouse-wheel-up)"), triggered=self.zoom_in) self.zoom_disp = QSpinBox() self.zoom_disp.setAlignment(Qt.AlignCenter) self.zoom_disp.setButtonSymbols(QSpinBox.NoButtons) self.zoom_disp.setReadOnly(True) self.zoom_disp.setSuffix(' %') self.zoom_disp.setRange(0, 9999) self.zoom_disp.setValue(100) self.figviewer.sig_zoom_changed.connect(self.zoom_disp.setValue) zoom_pan = QWidget() layout = QHBoxLayout(zoom_pan) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(zoom_out_btn) layout.addWidget(zoom_in_btn) layout.addWidget(self.zoom_disp) return [savefig_btn, saveall_btn, copyfig_btn, closefig_btn, closeall_btn, vsep1, goback_btn, gonext_btn, vsep2, zoom_pan]
[ "def", "setup_toolbar", "(", "self", ")", ":", "savefig_btn", "=", "create_toolbutton", "(", "self", ",", "icon", "=", "ima", ".", "icon", "(", "'filesave'", ")", ",", "tip", "=", "_", "(", "\"Save Image As...\"", ")", ",", "triggered", "=", "self", ".", "save_figure", ")", "saveall_btn", "=", "create_toolbutton", "(", "self", ",", "icon", "=", "ima", ".", "icon", "(", "'save_all'", ")", ",", "tip", "=", "_", "(", "\"Save All Images...\"", ")", ",", "triggered", "=", "self", ".", "save_all_figures", ")", "copyfig_btn", "=", "create_toolbutton", "(", "self", ",", "icon", "=", "ima", ".", "icon", "(", "'editcopy'", ")", ",", "tip", "=", "_", "(", "\"Copy plot to clipboard as image (%s)\"", "%", "get_shortcut", "(", "'plots'", ",", "'copy'", ")", ")", ",", "triggered", "=", "self", ".", "copy_figure", ")", "closefig_btn", "=", "create_toolbutton", "(", "self", ",", "icon", "=", "ima", ".", "icon", "(", "'editclear'", ")", ",", "tip", "=", "_", "(", "\"Remove image\"", ")", ",", "triggered", "=", "self", ".", "close_figure", ")", "closeall_btn", "=", "create_toolbutton", "(", "self", ",", "icon", "=", "ima", ".", "icon", "(", "'filecloseall'", ")", ",", "tip", "=", "_", "(", "\"Remove all images from the explorer\"", ")", ",", "triggered", "=", "self", ".", "close_all_figures", ")", "vsep1", "=", "QFrame", "(", ")", "vsep1", ".", "setFrameStyle", "(", "53", ")", "goback_btn", "=", "create_toolbutton", "(", "self", ",", "icon", "=", "ima", ".", "icon", "(", "'ArrowBack'", ")", ",", "tip", "=", "_", "(", "\"Previous Figure ({})\"", ".", "format", "(", "get_shortcut", "(", "'plots'", ",", "'previous figure'", ")", ")", ")", ",", "triggered", "=", "self", ".", "go_previous_thumbnail", ")", "gonext_btn", "=", "create_toolbutton", "(", "self", ",", "icon", "=", "ima", ".", "icon", "(", "'ArrowForward'", ")", ",", "tip", "=", "_", "(", "\"Next Figure ({})\"", ".", "format", "(", "get_shortcut", "(", "'plots'", ",", "'next figure'", ")", ")", ")", ",", "triggered", "=", "self", ".", "go_next_thumbnail", ")", "vsep2", "=", "QFrame", "(", ")", "vsep2", ".", "setFrameStyle", "(", "53", ")", "zoom_out_btn", "=", "create_toolbutton", "(", "self", ",", "icon", "=", "ima", ".", "icon", "(", "'zoom_out'", ")", ",", "tip", "=", "_", "(", "\"Zoom out (Ctrl + mouse-wheel-down)\"", ")", ",", "triggered", "=", "self", ".", "zoom_out", ")", "zoom_in_btn", "=", "create_toolbutton", "(", "self", ",", "icon", "=", "ima", ".", "icon", "(", "'zoom_in'", ")", ",", "tip", "=", "_", "(", "\"Zoom in (Ctrl + mouse-wheel-up)\"", ")", ",", "triggered", "=", "self", ".", "zoom_in", ")", "self", ".", "zoom_disp", "=", "QSpinBox", "(", ")", "self", ".", "zoom_disp", ".", "setAlignment", "(", "Qt", ".", "AlignCenter", ")", "self", ".", "zoom_disp", ".", "setButtonSymbols", "(", "QSpinBox", ".", "NoButtons", ")", "self", ".", "zoom_disp", ".", "setReadOnly", "(", "True", ")", "self", ".", "zoom_disp", ".", "setSuffix", "(", "' %'", ")", "self", ".", "zoom_disp", ".", "setRange", "(", "0", ",", "9999", ")", "self", ".", "zoom_disp", ".", "setValue", "(", "100", ")", "self", ".", "figviewer", ".", "sig_zoom_changed", ".", "connect", "(", "self", ".", "zoom_disp", ".", "setValue", ")", "zoom_pan", "=", "QWidget", "(", ")", "layout", "=", "QHBoxLayout", "(", "zoom_pan", ")", "layout", ".", "setSpacing", "(", "0", ")", "layout", ".", "setContentsMargins", "(", "0", ",", "0", ",", "0", ",", "0", ")", "layout", ".", "addWidget", "(", "zoom_out_btn", ")", "layout", ".", "addWidget", "(", "zoom_in_btn", ")", "layout", ".", "addWidget", "(", "self", ".", "zoom_disp", ")", "return", "[", "savefig_btn", ",", "saveall_btn", ",", "copyfig_btn", ",", "closefig_btn", ",", "closeall_btn", ",", "vsep1", ",", "goback_btn", ",", "gonext_btn", ",", "vsep2", ",", "zoom_pan", "]" ]
Setup the toolbar
[ "Setup", "the", "toolbar" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L138-L212
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
FigureBrowser.setup_option_actions
def setup_option_actions(self, mute_inline_plotting, show_plot_outline): """Setup the actions to show in the cog menu.""" self.setup_in_progress = True self.mute_inline_action = create_action( self, _("Mute inline plotting"), tip=_("Mute inline plotting in the ipython console."), toggled=lambda state: self.option_changed('mute_inline_plotting', state) ) self.mute_inline_action.setChecked(mute_inline_plotting) self.show_plot_outline_action = create_action( self, _("Show plot outline"), tip=_("Show the plot outline."), toggled=self.show_fig_outline_in_viewer ) self.show_plot_outline_action.setChecked(show_plot_outline) self.actions = [self.mute_inline_action, self.show_plot_outline_action] self.setup_in_progress = False
python
def setup_option_actions(self, mute_inline_plotting, show_plot_outline): """Setup the actions to show in the cog menu.""" self.setup_in_progress = True self.mute_inline_action = create_action( self, _("Mute inline plotting"), tip=_("Mute inline plotting in the ipython console."), toggled=lambda state: self.option_changed('mute_inline_plotting', state) ) self.mute_inline_action.setChecked(mute_inline_plotting) self.show_plot_outline_action = create_action( self, _("Show plot outline"), tip=_("Show the plot outline."), toggled=self.show_fig_outline_in_viewer ) self.show_plot_outline_action.setChecked(show_plot_outline) self.actions = [self.mute_inline_action, self.show_plot_outline_action] self.setup_in_progress = False
[ "def", "setup_option_actions", "(", "self", ",", "mute_inline_plotting", ",", "show_plot_outline", ")", ":", "self", ".", "setup_in_progress", "=", "True", "self", ".", "mute_inline_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Mute inline plotting\"", ")", ",", "tip", "=", "_", "(", "\"Mute inline plotting in the ipython console.\"", ")", ",", "toggled", "=", "lambda", "state", ":", "self", ".", "option_changed", "(", "'mute_inline_plotting'", ",", "state", ")", ")", "self", ".", "mute_inline_action", ".", "setChecked", "(", "mute_inline_plotting", ")", "self", ".", "show_plot_outline_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Show plot outline\"", ")", ",", "tip", "=", "_", "(", "\"Show the plot outline.\"", ")", ",", "toggled", "=", "self", ".", "show_fig_outline_in_viewer", ")", "self", ".", "show_plot_outline_action", ".", "setChecked", "(", "show_plot_outline", ")", "self", ".", "actions", "=", "[", "self", ".", "mute_inline_action", ",", "self", ".", "show_plot_outline_action", "]", "self", ".", "setup_in_progress", "=", "False" ]
Setup the actions to show in the cog menu.
[ "Setup", "the", "actions", "to", "show", "in", "the", "cog", "menu", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L214-L233
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
FigureBrowser.create_shortcuts
def create_shortcuts(self): """Create shortcuts for this widget.""" # Configurable copyfig = config_shortcut(self.copy_figure, context='plots', name='copy', parent=self) prevfig = config_shortcut(self.go_previous_thumbnail, context='plots', name='previous figure', parent=self) nextfig = config_shortcut(self.go_next_thumbnail, context='plots', name='next figure', parent=self) return [copyfig, prevfig, nextfig]
python
def create_shortcuts(self): """Create shortcuts for this widget.""" # Configurable copyfig = config_shortcut(self.copy_figure, context='plots', name='copy', parent=self) prevfig = config_shortcut(self.go_previous_thumbnail, context='plots', name='previous figure', parent=self) nextfig = config_shortcut(self.go_next_thumbnail, context='plots', name='next figure', parent=self) return [copyfig, prevfig, nextfig]
[ "def", "create_shortcuts", "(", "self", ")", ":", "# Configurable", "copyfig", "=", "config_shortcut", "(", "self", ".", "copy_figure", ",", "context", "=", "'plots'", ",", "name", "=", "'copy'", ",", "parent", "=", "self", ")", "prevfig", "=", "config_shortcut", "(", "self", ".", "go_previous_thumbnail", ",", "context", "=", "'plots'", ",", "name", "=", "'previous figure'", ",", "parent", "=", "self", ")", "nextfig", "=", "config_shortcut", "(", "self", ".", "go_next_thumbnail", ",", "context", "=", "'plots'", ",", "name", "=", "'next figure'", ",", "parent", "=", "self", ")", "return", "[", "copyfig", ",", "prevfig", ",", "nextfig", "]" ]
Create shortcuts for this widget.
[ "Create", "shortcuts", "for", "this", "widget", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L255-L265
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
FigureBrowser.option_changed
def option_changed(self, option, value): """Handle when the value of an option has changed""" setattr(self, to_text_string(option), value) self.shellwidget.set_namespace_view_settings() if self.setup_in_progress is False: self.sig_option_changed.emit(option, value)
python
def option_changed(self, option, value): """Handle when the value of an option has changed""" setattr(self, to_text_string(option), value) self.shellwidget.set_namespace_view_settings() if self.setup_in_progress is False: self.sig_option_changed.emit(option, value)
[ "def", "option_changed", "(", "self", ",", "option", ",", "value", ")", ":", "setattr", "(", "self", ",", "to_text_string", "(", "option", ")", ",", "value", ")", "self", ".", "shellwidget", ".", "set_namespace_view_settings", "(", ")", "if", "self", ".", "setup_in_progress", "is", "False", ":", "self", ".", "sig_option_changed", ".", "emit", "(", "option", ",", "value", ")" ]
Handle when the value of an option has changed
[ "Handle", "when", "the", "value", "of", "an", "option", "has", "changed" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L277-L282
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
FigureBrowser.show_fig_outline_in_viewer
def show_fig_outline_in_viewer(self, state): """Draw a frame around the figure viewer if state is True.""" if state is True: self.figviewer.figcanvas.setStyleSheet( "FigureCanvas{border: 1px solid lightgrey;}") else: self.figviewer.figcanvas.setStyleSheet("FigureCanvas{}") self.option_changed('show_plot_outline', state)
python
def show_fig_outline_in_viewer(self, state): """Draw a frame around the figure viewer if state is True.""" if state is True: self.figviewer.figcanvas.setStyleSheet( "FigureCanvas{border: 1px solid lightgrey;}") else: self.figviewer.figcanvas.setStyleSheet("FigureCanvas{}") self.option_changed('show_plot_outline', state)
[ "def", "show_fig_outline_in_viewer", "(", "self", ",", "state", ")", ":", "if", "state", "is", "True", ":", "self", ".", "figviewer", ".", "figcanvas", ".", "setStyleSheet", "(", "\"FigureCanvas{border: 1px solid lightgrey;}\"", ")", "else", ":", "self", ".", "figviewer", ".", "figcanvas", ".", "setStyleSheet", "(", "\"FigureCanvas{}\"", ")", "self", ".", "option_changed", "(", "'show_plot_outline'", ",", "state", ")" ]
Draw a frame around the figure viewer if state is True.
[ "Draw", "a", "frame", "around", "the", "figure", "viewer", "if", "state", "is", "True", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L284-L291
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
FigureBrowser.set_shellwidget
def set_shellwidget(self, shellwidget): """Bind the shellwidget instance to the figure browser""" self.shellwidget = shellwidget shellwidget.set_figurebrowser(self) shellwidget.sig_new_inline_figure.connect(self._handle_new_figure)
python
def set_shellwidget(self, shellwidget): """Bind the shellwidget instance to the figure browser""" self.shellwidget = shellwidget shellwidget.set_figurebrowser(self) shellwidget.sig_new_inline_figure.connect(self._handle_new_figure)
[ "def", "set_shellwidget", "(", "self", ",", "shellwidget", ")", ":", "self", ".", "shellwidget", "=", "shellwidget", "shellwidget", ".", "set_figurebrowser", "(", "self", ")", "shellwidget", ".", "sig_new_inline_figure", ".", "connect", "(", "self", ".", "_handle_new_figure", ")" ]
Bind the shellwidget instance to the figure browser
[ "Bind", "the", "shellwidget", "instance", "to", "the", "figure", "browser" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L293-L297
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
FigureBrowser.copy_figure
def copy_figure(self): """Copy figure from figviewer to clipboard.""" if self.figviewer and self.figviewer.figcanvas.fig: self.figviewer.figcanvas.copy_figure()
python
def copy_figure(self): """Copy figure from figviewer to clipboard.""" if self.figviewer and self.figviewer.figcanvas.fig: self.figviewer.figcanvas.copy_figure()
[ "def", "copy_figure", "(", "self", ")", ":", "if", "self", ".", "figviewer", "and", "self", ".", "figviewer", ".", "figcanvas", ".", "fig", ":", "self", ".", "figviewer", ".", "figcanvas", ".", "copy_figure", "(", ")" ]
Copy figure from figviewer to clipboard.
[ "Copy", "figure", "from", "figviewer", "to", "clipboard", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L349-L352
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
FigureViewer.setup_figcanvas
def setup_figcanvas(self): """Setup the FigureCanvas.""" self.figcanvas = FigureCanvas(background_color=self.background_color) self.figcanvas.installEventFilter(self) self.setWidget(self.figcanvas)
python
def setup_figcanvas(self): """Setup the FigureCanvas.""" self.figcanvas = FigureCanvas(background_color=self.background_color) self.figcanvas.installEventFilter(self) self.setWidget(self.figcanvas)
[ "def", "setup_figcanvas", "(", "self", ")", ":", "self", ".", "figcanvas", "=", "FigureCanvas", "(", "background_color", "=", "self", ".", "background_color", ")", "self", ".", "figcanvas", ".", "installEventFilter", "(", "self", ")", "self", ".", "setWidget", "(", "self", ".", "figcanvas", ")" ]
Setup the FigureCanvas.
[ "Setup", "the", "FigureCanvas", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L382-L386
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
FigureViewer.load_figure
def load_figure(self, fig, fmt): """Set a new figure in the figure canvas.""" self.figcanvas.load_figure(fig, fmt) self.scale_image() self.figcanvas.repaint()
python
def load_figure(self, fig, fmt): """Set a new figure in the figure canvas.""" self.figcanvas.load_figure(fig, fmt) self.scale_image() self.figcanvas.repaint()
[ "def", "load_figure", "(", "self", ",", "fig", ",", "fmt", ")", ":", "self", ".", "figcanvas", ".", "load_figure", "(", "fig", ",", "fmt", ")", "self", ".", "scale_image", "(", ")", "self", ".", "figcanvas", ".", "repaint", "(", ")" ]
Set a new figure in the figure canvas.
[ "Set", "a", "new", "figure", "in", "the", "figure", "canvas", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L388-L392
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
FigureViewer.eventFilter
def eventFilter(self, widget, event): """A filter to control the zooming and panning of the figure canvas.""" # ---- Zooming if event.type() == QEvent.Wheel: modifiers = QApplication.keyboardModifiers() if modifiers == Qt.ControlModifier: if event.angleDelta().y() > 0: self.zoom_in() else: self.zoom_out() return True else: return False # ---- Panning # Set ClosedHandCursor: elif event.type() == QEvent.MouseButtonPress: if event.button() == Qt.LeftButton: QApplication.setOverrideCursor(Qt.ClosedHandCursor) self._ispanning = True self.xclick = event.globalX() self.yclick = event.globalY() # Reset Cursor: elif event.type() == QEvent.MouseButtonRelease: QApplication.restoreOverrideCursor() self._ispanning = False # Move ScrollBar: elif event.type() == QEvent.MouseMove: if self._ispanning: dx = self.xclick - event.globalX() self.xclick = event.globalX() dy = self.yclick - event.globalY() self.yclick = event.globalY() scrollBarH = self.horizontalScrollBar() scrollBarH.setValue(scrollBarH.value() + dx) scrollBarV = self.verticalScrollBar() scrollBarV.setValue(scrollBarV.value() + dy) return QWidget.eventFilter(self, widget, event)
python
def eventFilter(self, widget, event): """A filter to control the zooming and panning of the figure canvas.""" # ---- Zooming if event.type() == QEvent.Wheel: modifiers = QApplication.keyboardModifiers() if modifiers == Qt.ControlModifier: if event.angleDelta().y() > 0: self.zoom_in() else: self.zoom_out() return True else: return False # ---- Panning # Set ClosedHandCursor: elif event.type() == QEvent.MouseButtonPress: if event.button() == Qt.LeftButton: QApplication.setOverrideCursor(Qt.ClosedHandCursor) self._ispanning = True self.xclick = event.globalX() self.yclick = event.globalY() # Reset Cursor: elif event.type() == QEvent.MouseButtonRelease: QApplication.restoreOverrideCursor() self._ispanning = False # Move ScrollBar: elif event.type() == QEvent.MouseMove: if self._ispanning: dx = self.xclick - event.globalX() self.xclick = event.globalX() dy = self.yclick - event.globalY() self.yclick = event.globalY() scrollBarH = self.horizontalScrollBar() scrollBarH.setValue(scrollBarH.value() + dx) scrollBarV = self.verticalScrollBar() scrollBarV.setValue(scrollBarV.value() + dy) return QWidget.eventFilter(self, widget, event)
[ "def", "eventFilter", "(", "self", ",", "widget", ",", "event", ")", ":", "# ---- Zooming", "if", "event", ".", "type", "(", ")", "==", "QEvent", ".", "Wheel", ":", "modifiers", "=", "QApplication", ".", "keyboardModifiers", "(", ")", "if", "modifiers", "==", "Qt", ".", "ControlModifier", ":", "if", "event", ".", "angleDelta", "(", ")", ".", "y", "(", ")", ">", "0", ":", "self", ".", "zoom_in", "(", ")", "else", ":", "self", ".", "zoom_out", "(", ")", "return", "True", "else", ":", "return", "False", "# ---- Panning", "# Set ClosedHandCursor:", "elif", "event", ".", "type", "(", ")", "==", "QEvent", ".", "MouseButtonPress", ":", "if", "event", ".", "button", "(", ")", "==", "Qt", ".", "LeftButton", ":", "QApplication", ".", "setOverrideCursor", "(", "Qt", ".", "ClosedHandCursor", ")", "self", ".", "_ispanning", "=", "True", "self", ".", "xclick", "=", "event", ".", "globalX", "(", ")", "self", ".", "yclick", "=", "event", ".", "globalY", "(", ")", "# Reset Cursor:", "elif", "event", ".", "type", "(", ")", "==", "QEvent", ".", "MouseButtonRelease", ":", "QApplication", ".", "restoreOverrideCursor", "(", ")", "self", ".", "_ispanning", "=", "False", "# Move ScrollBar:", "elif", "event", ".", "type", "(", ")", "==", "QEvent", ".", "MouseMove", ":", "if", "self", ".", "_ispanning", ":", "dx", "=", "self", ".", "xclick", "-", "event", ".", "globalX", "(", ")", "self", ".", "xclick", "=", "event", ".", "globalX", "(", ")", "dy", "=", "self", ".", "yclick", "-", "event", ".", "globalY", "(", ")", "self", ".", "yclick", "=", "event", ".", "globalY", "(", ")", "scrollBarH", "=", "self", ".", "horizontalScrollBar", "(", ")", "scrollBarH", ".", "setValue", "(", "scrollBarH", ".", "value", "(", ")", "+", "dx", ")", "scrollBarV", "=", "self", ".", "verticalScrollBar", "(", ")", "scrollBarV", ".", "setValue", "(", "scrollBarV", ".", "value", "(", ")", "+", "dy", ")", "return", "QWidget", ".", "eventFilter", "(", "self", ",", "widget", ",", "event", ")" ]
A filter to control the zooming and panning of the figure canvas.
[ "A", "filter", "to", "control", "the", "zooming", "and", "panning", "of", "the", "figure", "canvas", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L394-L438
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
FigureViewer.zoom_in
def zoom_in(self): """Scale the image up by one scale step.""" if self._scalefactor <= self._sfmax: self._scalefactor += 1 self.scale_image() self._adjust_scrollbar(self._scalestep) self.sig_zoom_changed.emit(self.get_scaling())
python
def zoom_in(self): """Scale the image up by one scale step.""" if self._scalefactor <= self._sfmax: self._scalefactor += 1 self.scale_image() self._adjust_scrollbar(self._scalestep) self.sig_zoom_changed.emit(self.get_scaling())
[ "def", "zoom_in", "(", "self", ")", ":", "if", "self", ".", "_scalefactor", "<=", "self", ".", "_sfmax", ":", "self", ".", "_scalefactor", "+=", "1", "self", ".", "scale_image", "(", ")", "self", ".", "_adjust_scrollbar", "(", "self", ".", "_scalestep", ")", "self", ".", "sig_zoom_changed", ".", "emit", "(", "self", ".", "get_scaling", "(", ")", ")" ]
Scale the image up by one scale step.
[ "Scale", "the", "image", "up", "by", "one", "scale", "step", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L441-L447
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
FigureViewer.zoom_out
def zoom_out(self): """Scale the image down by one scale step.""" if self._scalefactor >= self._sfmin: self._scalefactor -= 1 self.scale_image() self._adjust_scrollbar(1/self._scalestep) self.sig_zoom_changed.emit(self.get_scaling())
python
def zoom_out(self): """Scale the image down by one scale step.""" if self._scalefactor >= self._sfmin: self._scalefactor -= 1 self.scale_image() self._adjust_scrollbar(1/self._scalestep) self.sig_zoom_changed.emit(self.get_scaling())
[ "def", "zoom_out", "(", "self", ")", ":", "if", "self", ".", "_scalefactor", ">=", "self", ".", "_sfmin", ":", "self", ".", "_scalefactor", "-=", "1", "self", ".", "scale_image", "(", ")", "self", ".", "_adjust_scrollbar", "(", "1", "/", "self", ".", "_scalestep", ")", "self", ".", "sig_zoom_changed", ".", "emit", "(", "self", ".", "get_scaling", "(", ")", ")" ]
Scale the image down by one scale step.
[ "Scale", "the", "image", "down", "by", "one", "scale", "step", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L449-L455
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
FigureViewer.scale_image
def scale_image(self): """Scale the image size.""" new_width = int(self.figcanvas.fwidth * self._scalestep ** self._scalefactor) new_height = int(self.figcanvas.fheight * self._scalestep ** self._scalefactor) self.figcanvas.setFixedSize(new_width, new_height)
python
def scale_image(self): """Scale the image size.""" new_width = int(self.figcanvas.fwidth * self._scalestep ** self._scalefactor) new_height = int(self.figcanvas.fheight * self._scalestep ** self._scalefactor) self.figcanvas.setFixedSize(new_width, new_height)
[ "def", "scale_image", "(", "self", ")", ":", "new_width", "=", "int", "(", "self", ".", "figcanvas", ".", "fwidth", "*", "self", ".", "_scalestep", "**", "self", ".", "_scalefactor", ")", "new_height", "=", "int", "(", "self", ".", "figcanvas", ".", "fheight", "*", "self", ".", "_scalestep", "**", "self", ".", "_scalefactor", ")", "self", ".", "figcanvas", ".", "setFixedSize", "(", "new_width", ",", "new_height", ")" ]
Scale the image size.
[ "Scale", "the", "image", "size", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L457-L463
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
FigureViewer._adjust_scrollbar
def _adjust_scrollbar(self, f): """ Adjust the scrollbar position to take into account the zooming of the figure. """ # Adjust horizontal scrollbar : hb = self.horizontalScrollBar() hb.setValue(int(f * hb.value() + ((f - 1) * hb.pageStep()/2))) # Adjust the vertical scrollbar : vb = self.verticalScrollBar() vb.setValue(int(f * vb.value() + ((f - 1) * vb.pageStep()/2)))
python
def _adjust_scrollbar(self, f): """ Adjust the scrollbar position to take into account the zooming of the figure. """ # Adjust horizontal scrollbar : hb = self.horizontalScrollBar() hb.setValue(int(f * hb.value() + ((f - 1) * hb.pageStep()/2))) # Adjust the vertical scrollbar : vb = self.verticalScrollBar() vb.setValue(int(f * vb.value() + ((f - 1) * vb.pageStep()/2)))
[ "def", "_adjust_scrollbar", "(", "self", ",", "f", ")", ":", "# Adjust horizontal scrollbar :", "hb", "=", "self", ".", "horizontalScrollBar", "(", ")", "hb", ".", "setValue", "(", "int", "(", "f", "*", "hb", ".", "value", "(", ")", "+", "(", "(", "f", "-", "1", ")", "*", "hb", ".", "pageStep", "(", ")", "/", "2", ")", ")", ")", "# Adjust the vertical scrollbar :", "vb", "=", "self", ".", "verticalScrollBar", "(", ")", "vb", ".", "setValue", "(", "int", "(", "f", "*", "vb", ".", "value", "(", ")", "+", "(", "(", "f", "-", "1", ")", "*", "vb", ".", "pageStep", "(", ")", "/", "2", ")", ")", ")" ]
Adjust the scrollbar position to take into account the zooming of the figure.
[ "Adjust", "the", "scrollbar", "position", "to", "take", "into", "account", "the", "zooming", "of", "the", "figure", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L474-L485
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
ThumbnailScrollBar.setup_gui
def setup_gui(self): """Setup the main layout of the widget.""" scrollarea = self.setup_scrollarea() up_btn, down_btn = self.setup_arrow_buttons() self.setFixedWidth(150) layout = QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.addWidget(up_btn) layout.addWidget(scrollarea) layout.addWidget(down_btn)
python
def setup_gui(self): """Setup the main layout of the widget.""" scrollarea = self.setup_scrollarea() up_btn, down_btn = self.setup_arrow_buttons() self.setFixedWidth(150) layout = QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.addWidget(up_btn) layout.addWidget(scrollarea) layout.addWidget(down_btn)
[ "def", "setup_gui", "(", "self", ")", ":", "scrollarea", "=", "self", ".", "setup_scrollarea", "(", ")", "up_btn", ",", "down_btn", "=", "self", ".", "setup_arrow_buttons", "(", ")", "self", ".", "setFixedWidth", "(", "150", ")", "layout", "=", "QVBoxLayout", "(", "self", ")", "layout", ".", "setContentsMargins", "(", "0", ",", "0", ",", "0", ",", "0", ")", "layout", ".", "setSpacing", "(", "0", ")", "layout", ".", "addWidget", "(", "up_btn", ")", "layout", ".", "addWidget", "(", "scrollarea", ")", "layout", ".", "addWidget", "(", "down_btn", ")" ]
Setup the main layout of the widget.
[ "Setup", "the", "main", "layout", "of", "the", "widget", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L504-L515
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
ThumbnailScrollBar.setup_scrollarea
def setup_scrollarea(self): """Setup the scrollarea that will contain the FigureThumbnails.""" self.view = QWidget() self.scene = QGridLayout(self.view) self.scene.setColumnStretch(0, 100) self.scene.setColumnStretch(2, 100) self.scrollarea = QScrollArea() self.scrollarea.setWidget(self.view) self.scrollarea.setWidgetResizable(True) self.scrollarea.setFrameStyle(0) self.scrollarea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.scrollarea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.scrollarea.setSizePolicy(QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred)) # Set the vertical scrollbar explicitely : # This is required to avoid a "RuntimeError: no access to protected # functions or signals for objects not created from Python" in Linux. self.scrollarea.setVerticalScrollBar(QScrollBar()) return self.scrollarea
python
def setup_scrollarea(self): """Setup the scrollarea that will contain the FigureThumbnails.""" self.view = QWidget() self.scene = QGridLayout(self.view) self.scene.setColumnStretch(0, 100) self.scene.setColumnStretch(2, 100) self.scrollarea = QScrollArea() self.scrollarea.setWidget(self.view) self.scrollarea.setWidgetResizable(True) self.scrollarea.setFrameStyle(0) self.scrollarea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.scrollarea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.scrollarea.setSizePolicy(QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred)) # Set the vertical scrollbar explicitely : # This is required to avoid a "RuntimeError: no access to protected # functions or signals for objects not created from Python" in Linux. self.scrollarea.setVerticalScrollBar(QScrollBar()) return self.scrollarea
[ "def", "setup_scrollarea", "(", "self", ")", ":", "self", ".", "view", "=", "QWidget", "(", ")", "self", ".", "scene", "=", "QGridLayout", "(", "self", ".", "view", ")", "self", ".", "scene", ".", "setColumnStretch", "(", "0", ",", "100", ")", "self", ".", "scene", ".", "setColumnStretch", "(", "2", ",", "100", ")", "self", ".", "scrollarea", "=", "QScrollArea", "(", ")", "self", ".", "scrollarea", ".", "setWidget", "(", "self", ".", "view", ")", "self", ".", "scrollarea", ".", "setWidgetResizable", "(", "True", ")", "self", ".", "scrollarea", ".", "setFrameStyle", "(", "0", ")", "self", ".", "scrollarea", ".", "setVerticalScrollBarPolicy", "(", "Qt", ".", "ScrollBarAlwaysOff", ")", "self", ".", "scrollarea", ".", "setHorizontalScrollBarPolicy", "(", "Qt", ".", "ScrollBarAlwaysOff", ")", "self", ".", "scrollarea", ".", "setSizePolicy", "(", "QSizePolicy", "(", "QSizePolicy", ".", "Ignored", ",", "QSizePolicy", ".", "Preferred", ")", ")", "# Set the vertical scrollbar explicitely :", "# This is required to avoid a \"RuntimeError: no access to protected", "# functions or signals for objects not created from Python\" in Linux.", "self", ".", "scrollarea", ".", "setVerticalScrollBar", "(", "QScrollBar", "(", ")", ")", "return", "self", ".", "scrollarea" ]
Setup the scrollarea that will contain the FigureThumbnails.
[ "Setup", "the", "scrollarea", "that", "will", "contain", "the", "FigureThumbnails", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L517-L539
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
ThumbnailScrollBar.setup_arrow_buttons
def setup_arrow_buttons(self): """ Setup the up and down arrow buttons that are placed at the top and bottom of the scrollarea. """ # Get the height of the up/down arrow of the default vertical # scrollbar : vsb = self.scrollarea.verticalScrollBar() style = vsb.style() opt = QStyleOptionSlider() vsb.initStyleOption(opt) vsb_up_arrow = style.subControlRect( QStyle.CC_ScrollBar, opt, QStyle.SC_ScrollBarAddLine, self) # Setup the up and down arrow button : up_btn = up_btn = QPushButton(icon=ima.icon('last_edit_location')) up_btn.setFlat(True) up_btn.setFixedHeight(vsb_up_arrow.size().height()) up_btn.clicked.connect(self.go_up) down_btn = QPushButton(icon=ima.icon('folding.arrow_down_on')) down_btn.setFlat(True) down_btn.setFixedHeight(vsb_up_arrow.size().height()) down_btn.clicked.connect(self.go_down) return up_btn, down_btn
python
def setup_arrow_buttons(self): """ Setup the up and down arrow buttons that are placed at the top and bottom of the scrollarea. """ # Get the height of the up/down arrow of the default vertical # scrollbar : vsb = self.scrollarea.verticalScrollBar() style = vsb.style() opt = QStyleOptionSlider() vsb.initStyleOption(opt) vsb_up_arrow = style.subControlRect( QStyle.CC_ScrollBar, opt, QStyle.SC_ScrollBarAddLine, self) # Setup the up and down arrow button : up_btn = up_btn = QPushButton(icon=ima.icon('last_edit_location')) up_btn.setFlat(True) up_btn.setFixedHeight(vsb_up_arrow.size().height()) up_btn.clicked.connect(self.go_up) down_btn = QPushButton(icon=ima.icon('folding.arrow_down_on')) down_btn.setFlat(True) down_btn.setFixedHeight(vsb_up_arrow.size().height()) down_btn.clicked.connect(self.go_down) return up_btn, down_btn
[ "def", "setup_arrow_buttons", "(", "self", ")", ":", "# Get the height of the up/down arrow of the default vertical", "# scrollbar :", "vsb", "=", "self", ".", "scrollarea", ".", "verticalScrollBar", "(", ")", "style", "=", "vsb", ".", "style", "(", ")", "opt", "=", "QStyleOptionSlider", "(", ")", "vsb", ".", "initStyleOption", "(", "opt", ")", "vsb_up_arrow", "=", "style", ".", "subControlRect", "(", "QStyle", ".", "CC_ScrollBar", ",", "opt", ",", "QStyle", ".", "SC_ScrollBarAddLine", ",", "self", ")", "# Setup the up and down arrow button :", "up_btn", "=", "up_btn", "=", "QPushButton", "(", "icon", "=", "ima", ".", "icon", "(", "'last_edit_location'", ")", ")", "up_btn", ".", "setFlat", "(", "True", ")", "up_btn", ".", "setFixedHeight", "(", "vsb_up_arrow", ".", "size", "(", ")", ".", "height", "(", ")", ")", "up_btn", ".", "clicked", ".", "connect", "(", "self", ".", "go_up", ")", "down_btn", "=", "QPushButton", "(", "icon", "=", "ima", ".", "icon", "(", "'folding.arrow_down_on'", ")", ")", "down_btn", ".", "setFlat", "(", "True", ")", "down_btn", ".", "setFixedHeight", "(", "vsb_up_arrow", ".", "size", "(", ")", ".", "height", "(", ")", ")", "down_btn", ".", "clicked", ".", "connect", "(", "self", ".", "go_down", ")", "return", "up_btn", ",", "down_btn" ]
Setup the up and down arrow buttons that are placed at the top and bottom of the scrollarea.
[ "Setup", "the", "up", "and", "down", "arrow", "buttons", "that", "are", "placed", "at", "the", "top", "and", "bottom", "of", "the", "scrollarea", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L541-L566
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
ThumbnailScrollBar.save_all_figures_as
def save_all_figures_as(self): """Save all the figures to a file.""" self.redirect_stdio.emit(False) dirname = getexistingdirectory(self, caption='Save all figures', basedir=getcwd_or_home()) self.redirect_stdio.emit(True) if dirname: return self.save_all_figures_todir(dirname)
python
def save_all_figures_as(self): """Save all the figures to a file.""" self.redirect_stdio.emit(False) dirname = getexistingdirectory(self, caption='Save all figures', basedir=getcwd_or_home()) self.redirect_stdio.emit(True) if dirname: return self.save_all_figures_todir(dirname)
[ "def", "save_all_figures_as", "(", "self", ")", ":", "self", ".", "redirect_stdio", ".", "emit", "(", "False", ")", "dirname", "=", "getexistingdirectory", "(", "self", ",", "caption", "=", "'Save all figures'", ",", "basedir", "=", "getcwd_or_home", "(", ")", ")", "self", ".", "redirect_stdio", ".", "emit", "(", "True", ")", "if", "dirname", ":", "return", "self", ".", "save_all_figures_todir", "(", "dirname", ")" ]
Save all the figures to a file.
[ "Save", "all", "the", "figures", "to", "a", "file", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L573-L580
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
ThumbnailScrollBar.save_all_figures_todir
def save_all_figures_todir(self, dirname): """Save all figure in dirname.""" fignames = [] for thumbnail in self._thumbnails: fig = thumbnail.canvas.fig fmt = thumbnail.canvas.fmt fext = {'image/png': '.png', 'image/jpeg': '.jpg', 'image/svg+xml': '.svg'}[fmt] figname = get_unique_figname(dirname, 'Figure', fext) save_figure_tofile(fig, fmt, figname) fignames.append(figname) return fignames
python
def save_all_figures_todir(self, dirname): """Save all figure in dirname.""" fignames = [] for thumbnail in self._thumbnails: fig = thumbnail.canvas.fig fmt = thumbnail.canvas.fmt fext = {'image/png': '.png', 'image/jpeg': '.jpg', 'image/svg+xml': '.svg'}[fmt] figname = get_unique_figname(dirname, 'Figure', fext) save_figure_tofile(fig, fmt, figname) fignames.append(figname) return fignames
[ "def", "save_all_figures_todir", "(", "self", ",", "dirname", ")", ":", "fignames", "=", "[", "]", "for", "thumbnail", "in", "self", ".", "_thumbnails", ":", "fig", "=", "thumbnail", ".", "canvas", ".", "fig", "fmt", "=", "thumbnail", ".", "canvas", ".", "fmt", "fext", "=", "{", "'image/png'", ":", "'.png'", ",", "'image/jpeg'", ":", "'.jpg'", ",", "'image/svg+xml'", ":", "'.svg'", "}", "[", "fmt", "]", "figname", "=", "get_unique_figname", "(", "dirname", ",", "'Figure'", ",", "fext", ")", "save_figure_tofile", "(", "fig", ",", "fmt", ",", "figname", ")", "fignames", ".", "append", "(", "figname", ")", "return", "fignames" ]
Save all figure in dirname.
[ "Save", "all", "figure", "in", "dirname", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L582-L595
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
ThumbnailScrollBar.save_current_figure_as
def save_current_figure_as(self): """Save the currently selected figure.""" if self.current_thumbnail is not None: self.save_figure_as(self.current_thumbnail.canvas.fig, self.current_thumbnail.canvas.fmt)
python
def save_current_figure_as(self): """Save the currently selected figure.""" if self.current_thumbnail is not None: self.save_figure_as(self.current_thumbnail.canvas.fig, self.current_thumbnail.canvas.fmt)
[ "def", "save_current_figure_as", "(", "self", ")", ":", "if", "self", ".", "current_thumbnail", "is", "not", "None", ":", "self", ".", "save_figure_as", "(", "self", ".", "current_thumbnail", ".", "canvas", ".", "fig", ",", "self", ".", "current_thumbnail", ".", "canvas", ".", "fmt", ")" ]
Save the currently selected figure.
[ "Save", "the", "currently", "selected", "figure", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L597-L601
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
ThumbnailScrollBar.save_figure_as
def save_figure_as(self, fig, fmt): """Save the figure to a file.""" fext, ffilt = { 'image/png': ('.png', 'PNG (*.png)'), 'image/jpeg': ('.jpg', 'JPEG (*.jpg;*.jpeg;*.jpe;*.jfif)'), 'image/svg+xml': ('.svg', 'SVG (*.svg);;PNG (*.png)')}[fmt] figname = get_unique_figname(getcwd_or_home(), 'Figure', fext) self.redirect_stdio.emit(False) fname, fext = getsavefilename( parent=self.parent(), caption='Save Figure', basedir=figname, filters=ffilt, selectedfilter='', options=None) self.redirect_stdio.emit(True) if fname: save_figure_tofile(fig, fmt, fname)
python
def save_figure_as(self, fig, fmt): """Save the figure to a file.""" fext, ffilt = { 'image/png': ('.png', 'PNG (*.png)'), 'image/jpeg': ('.jpg', 'JPEG (*.jpg;*.jpeg;*.jpe;*.jfif)'), 'image/svg+xml': ('.svg', 'SVG (*.svg);;PNG (*.png)')}[fmt] figname = get_unique_figname(getcwd_or_home(), 'Figure', fext) self.redirect_stdio.emit(False) fname, fext = getsavefilename( parent=self.parent(), caption='Save Figure', basedir=figname, filters=ffilt, selectedfilter='', options=None) self.redirect_stdio.emit(True) if fname: save_figure_tofile(fig, fmt, fname)
[ "def", "save_figure_as", "(", "self", ",", "fig", ",", "fmt", ")", ":", "fext", ",", "ffilt", "=", "{", "'image/png'", ":", "(", "'.png'", ",", "'PNG (*.png)'", ")", ",", "'image/jpeg'", ":", "(", "'.jpg'", ",", "'JPEG (*.jpg;*.jpeg;*.jpe;*.jfif)'", ")", ",", "'image/svg+xml'", ":", "(", "'.svg'", ",", "'SVG (*.svg);;PNG (*.png)'", ")", "}", "[", "fmt", "]", "figname", "=", "get_unique_figname", "(", "getcwd_or_home", "(", ")", ",", "'Figure'", ",", "fext", ")", "self", ".", "redirect_stdio", ".", "emit", "(", "False", ")", "fname", ",", "fext", "=", "getsavefilename", "(", "parent", "=", "self", ".", "parent", "(", ")", ",", "caption", "=", "'Save Figure'", ",", "basedir", "=", "figname", ",", "filters", "=", "ffilt", ",", "selectedfilter", "=", "''", ",", "options", "=", "None", ")", "self", ".", "redirect_stdio", ".", "emit", "(", "True", ")", "if", "fname", ":", "save_figure_tofile", "(", "fig", ",", "fmt", ",", "fname", ")" ]
Save the figure to a file.
[ "Save", "the", "figure", "to", "a", "file", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L603-L620
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
ThumbnailScrollBar.remove_all_thumbnails
def remove_all_thumbnails(self): """Remove all thumbnails.""" for thumbnail in self._thumbnails: self.layout().removeWidget(thumbnail) thumbnail.sig_canvas_clicked.disconnect() thumbnail.sig_remove_figure.disconnect() thumbnail.sig_save_figure.disconnect() thumbnail.deleteLater() self._thumbnails = [] self.current_thumbnail = None self.figure_viewer.figcanvas.clear_canvas()
python
def remove_all_thumbnails(self): """Remove all thumbnails.""" for thumbnail in self._thumbnails: self.layout().removeWidget(thumbnail) thumbnail.sig_canvas_clicked.disconnect() thumbnail.sig_remove_figure.disconnect() thumbnail.sig_save_figure.disconnect() thumbnail.deleteLater() self._thumbnails = [] self.current_thumbnail = None self.figure_viewer.figcanvas.clear_canvas()
[ "def", "remove_all_thumbnails", "(", "self", ")", ":", "for", "thumbnail", "in", "self", ".", "_thumbnails", ":", "self", ".", "layout", "(", ")", ".", "removeWidget", "(", "thumbnail", ")", "thumbnail", ".", "sig_canvas_clicked", ".", "disconnect", "(", ")", "thumbnail", ".", "sig_remove_figure", ".", "disconnect", "(", ")", "thumbnail", ".", "sig_save_figure", ".", "disconnect", "(", ")", "thumbnail", ".", "deleteLater", "(", ")", "self", ".", "_thumbnails", "=", "[", "]", "self", ".", "current_thumbnail", "=", "None", "self", ".", "figure_viewer", ".", "figcanvas", ".", "clear_canvas", "(", ")" ]
Remove all thumbnails.
[ "Remove", "all", "thumbnails", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L656-L666
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
ThumbnailScrollBar.remove_thumbnail
def remove_thumbnail(self, thumbnail): """Remove thumbnail.""" if thumbnail in self._thumbnails: index = self._thumbnails.index(thumbnail) self._thumbnails.remove(thumbnail) self.layout().removeWidget(thumbnail) thumbnail.deleteLater() thumbnail.sig_canvas_clicked.disconnect() thumbnail.sig_remove_figure.disconnect() thumbnail.sig_save_figure.disconnect() # Select a new thumbnail if any : if thumbnail == self.current_thumbnail: if len(self._thumbnails) > 0: self.set_current_index(min(index, len(self._thumbnails)-1)) else: self.current_thumbnail = None self.figure_viewer.figcanvas.clear_canvas()
python
def remove_thumbnail(self, thumbnail): """Remove thumbnail.""" if thumbnail in self._thumbnails: index = self._thumbnails.index(thumbnail) self._thumbnails.remove(thumbnail) self.layout().removeWidget(thumbnail) thumbnail.deleteLater() thumbnail.sig_canvas_clicked.disconnect() thumbnail.sig_remove_figure.disconnect() thumbnail.sig_save_figure.disconnect() # Select a new thumbnail if any : if thumbnail == self.current_thumbnail: if len(self._thumbnails) > 0: self.set_current_index(min(index, len(self._thumbnails)-1)) else: self.current_thumbnail = None self.figure_viewer.figcanvas.clear_canvas()
[ "def", "remove_thumbnail", "(", "self", ",", "thumbnail", ")", ":", "if", "thumbnail", "in", "self", ".", "_thumbnails", ":", "index", "=", "self", ".", "_thumbnails", ".", "index", "(", "thumbnail", ")", "self", ".", "_thumbnails", ".", "remove", "(", "thumbnail", ")", "self", ".", "layout", "(", ")", ".", "removeWidget", "(", "thumbnail", ")", "thumbnail", ".", "deleteLater", "(", ")", "thumbnail", ".", "sig_canvas_clicked", ".", "disconnect", "(", ")", "thumbnail", ".", "sig_remove_figure", ".", "disconnect", "(", ")", "thumbnail", ".", "sig_save_figure", ".", "disconnect", "(", ")", "# Select a new thumbnail if any :", "if", "thumbnail", "==", "self", ".", "current_thumbnail", ":", "if", "len", "(", "self", ".", "_thumbnails", ")", ">", "0", ":", "self", ".", "set_current_index", "(", "min", "(", "index", ",", "len", "(", "self", ".", "_thumbnails", ")", "-", "1", ")", ")", "else", ":", "self", ".", "current_thumbnail", "=", "None", "self", ".", "figure_viewer", ".", "figcanvas", ".", "clear_canvas", "(", ")" ]
Remove thumbnail.
[ "Remove", "thumbnail", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L668-L685
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
ThumbnailScrollBar.set_current_thumbnail
def set_current_thumbnail(self, thumbnail): """Set the currently selected thumbnail.""" self.current_thumbnail = thumbnail self.figure_viewer.load_figure( thumbnail.canvas.fig, thumbnail.canvas.fmt) for thumbnail in self._thumbnails: thumbnail.highlight_canvas(thumbnail == self.current_thumbnail)
python
def set_current_thumbnail(self, thumbnail): """Set the currently selected thumbnail.""" self.current_thumbnail = thumbnail self.figure_viewer.load_figure( thumbnail.canvas.fig, thumbnail.canvas.fmt) for thumbnail in self._thumbnails: thumbnail.highlight_canvas(thumbnail == self.current_thumbnail)
[ "def", "set_current_thumbnail", "(", "self", ",", "thumbnail", ")", ":", "self", ".", "current_thumbnail", "=", "thumbnail", "self", ".", "figure_viewer", ".", "load_figure", "(", "thumbnail", ".", "canvas", ".", "fig", ",", "thumbnail", ".", "canvas", ".", "fmt", ")", "for", "thumbnail", "in", "self", ".", "_thumbnails", ":", "thumbnail", ".", "highlight_canvas", "(", "thumbnail", "==", "self", ".", "current_thumbnail", ")" ]
Set the currently selected thumbnail.
[ "Set", "the", "currently", "selected", "thumbnail", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L698-L704
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
ThumbnailScrollBar.go_previous_thumbnail
def go_previous_thumbnail(self): """Select the thumbnail previous to the currently selected one.""" if self.current_thumbnail is not None: index = self._thumbnails.index(self.current_thumbnail) - 1 index = index if index >= 0 else len(self._thumbnails) - 1 self.set_current_index(index) self.scroll_to_item(index)
python
def go_previous_thumbnail(self): """Select the thumbnail previous to the currently selected one.""" if self.current_thumbnail is not None: index = self._thumbnails.index(self.current_thumbnail) - 1 index = index if index >= 0 else len(self._thumbnails) - 1 self.set_current_index(index) self.scroll_to_item(index)
[ "def", "go_previous_thumbnail", "(", "self", ")", ":", "if", "self", ".", "current_thumbnail", "is", "not", "None", ":", "index", "=", "self", ".", "_thumbnails", ".", "index", "(", "self", ".", "current_thumbnail", ")", "-", "1", "index", "=", "index", "if", "index", ">=", "0", "else", "len", "(", "self", ".", "_thumbnails", ")", "-", "1", "self", ".", "set_current_index", "(", "index", ")", "self", ".", "scroll_to_item", "(", "index", ")" ]
Select the thumbnail previous to the currently selected one.
[ "Select", "the", "thumbnail", "previous", "to", "the", "currently", "selected", "one", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L706-L712
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
ThumbnailScrollBar.go_next_thumbnail
def go_next_thumbnail(self): """Select thumbnail next to the currently selected one.""" if self.current_thumbnail is not None: index = self._thumbnails.index(self.current_thumbnail) + 1 index = 0 if index >= len(self._thumbnails) else index self.set_current_index(index) self.scroll_to_item(index)
python
def go_next_thumbnail(self): """Select thumbnail next to the currently selected one.""" if self.current_thumbnail is not None: index = self._thumbnails.index(self.current_thumbnail) + 1 index = 0 if index >= len(self._thumbnails) else index self.set_current_index(index) self.scroll_to_item(index)
[ "def", "go_next_thumbnail", "(", "self", ")", ":", "if", "self", ".", "current_thumbnail", "is", "not", "None", ":", "index", "=", "self", ".", "_thumbnails", ".", "index", "(", "self", ".", "current_thumbnail", ")", "+", "1", "index", "=", "0", "if", "index", ">=", "len", "(", "self", ".", "_thumbnails", ")", "else", "index", "self", ".", "set_current_index", "(", "index", ")", "self", ".", "scroll_to_item", "(", "index", ")" ]
Select thumbnail next to the currently selected one.
[ "Select", "thumbnail", "next", "to", "the", "currently", "selected", "one", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L714-L720
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
ThumbnailScrollBar.scroll_to_item
def scroll_to_item(self, index): """Scroll to the selected item of ThumbnailScrollBar.""" spacing_between_items = self.scene.verticalSpacing() height_view = self.scrollarea.viewport().height() height_item = self.scene.itemAt(index).sizeHint().height() height_view_excluding_item = max(0, height_view - height_item) height_of_top_items = spacing_between_items for i in range(index): item = self.scene.itemAt(i) height_of_top_items += item.sizeHint().height() height_of_top_items += spacing_between_items pos_scroll = height_of_top_items - height_view_excluding_item // 2 vsb = self.scrollarea.verticalScrollBar() vsb.setValue(pos_scroll)
python
def scroll_to_item(self, index): """Scroll to the selected item of ThumbnailScrollBar.""" spacing_between_items = self.scene.verticalSpacing() height_view = self.scrollarea.viewport().height() height_item = self.scene.itemAt(index).sizeHint().height() height_view_excluding_item = max(0, height_view - height_item) height_of_top_items = spacing_between_items for i in range(index): item = self.scene.itemAt(i) height_of_top_items += item.sizeHint().height() height_of_top_items += spacing_between_items pos_scroll = height_of_top_items - height_view_excluding_item // 2 vsb = self.scrollarea.verticalScrollBar() vsb.setValue(pos_scroll)
[ "def", "scroll_to_item", "(", "self", ",", "index", ")", ":", "spacing_between_items", "=", "self", ".", "scene", ".", "verticalSpacing", "(", ")", "height_view", "=", "self", ".", "scrollarea", ".", "viewport", "(", ")", ".", "height", "(", ")", "height_item", "=", "self", ".", "scene", ".", "itemAt", "(", "index", ")", ".", "sizeHint", "(", ")", ".", "height", "(", ")", "height_view_excluding_item", "=", "max", "(", "0", ",", "height_view", "-", "height_item", ")", "height_of_top_items", "=", "spacing_between_items", "for", "i", "in", "range", "(", "index", ")", ":", "item", "=", "self", ".", "scene", ".", "itemAt", "(", "i", ")", "height_of_top_items", "+=", "item", ".", "sizeHint", "(", ")", ".", "height", "(", ")", "height_of_top_items", "+=", "spacing_between_items", "pos_scroll", "=", "height_of_top_items", "-", "height_view_excluding_item", "//", "2", "vsb", "=", "self", ".", "scrollarea", ".", "verticalScrollBar", "(", ")", "vsb", ".", "setValue", "(", "pos_scroll", ")" ]
Scroll to the selected item of ThumbnailScrollBar.
[ "Scroll", "to", "the", "selected", "item", "of", "ThumbnailScrollBar", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L722-L738
train
spyder-ide/spyder
spyder/plugins/plots/widgets/figurebrowser.py
ThumbnailScrollBar.go_up
def go_up(self): """Scroll the scrollbar of the scrollarea up by a single step.""" vsb = self.scrollarea.verticalScrollBar() vsb.setValue(int(vsb.value() - vsb.singleStep()))
python
def go_up(self): """Scroll the scrollbar of the scrollarea up by a single step.""" vsb = self.scrollarea.verticalScrollBar() vsb.setValue(int(vsb.value() - vsb.singleStep()))
[ "def", "go_up", "(", "self", ")", ":", "vsb", "=", "self", ".", "scrollarea", ".", "verticalScrollBar", "(", ")", "vsb", ".", "setValue", "(", "int", "(", "vsb", ".", "value", "(", ")", "-", "vsb", ".", "singleStep", "(", ")", ")", ")" ]
Scroll the scrollbar of the scrollarea up by a single step.
[ "Scroll", "the", "scrollbar", "of", "the", "scrollarea", "up", "by", "a", "single", "step", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/plots/widgets/figurebrowser.py#L741-L744
train