text_prompt stringlengths 157 13.1k | code_prompt stringlengths 7 19.8k ⌀ |
|---|---|
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _handle_input_request(self, msg):
"""Save history and add a %plot magic.""" |
if self._hidden:
raise RuntimeError('Request for raw input during hidden execution.')
# Make sure that all output from the SUB channel has been processed
# before entering readline mode.
self.kernel_client.iopub_channel.flush()
def callback(line):
# Sav... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def global_max(col_vals, index):
"""Returns the global maximum and minimum.""" |
col_vals_without_None = [x for x in col_vals if x is not None]
max_col, min_col = zip(*col_vals_without_None)
return max(max_col), min(min_col) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def header(self, axis, x, level=0):
"""
Return the values of the labels for the header of columns or rows.
The value corresponds to the header of column or ... |
ax = self._axis(axis)
return ax.values[x] if not hasattr(ax, 'levels') \
else ax.values[x][level] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_bgcolor(self, index):
"""Background color depending on value.""" |
column = index.column()
if not self.bgcolor_enabled:
return
value = self.get_value(index.row(), column)
if self.max_min_col[column] is None or isna(value):
color = QColor(BACKGROUND_NONNUMBER_COLOR)
if is_text_string(value):
co... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_value(self, row, column):
"""Return the value of the DataFrame.""" |
# To increase the performance iat is used but that requires error
# handling, so fallback uses iloc
try:
value = self.df.iat[row, column]
except OutOfBoundsDatetime:
value = self.df.iloc[:, column].astype(str).iat[row]
except:
value = ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def load_more_data(self, value, rows=False, columns=False):
"""Load more rows and columns to display.""" |
try:
if rows and value == self.verticalScrollBar().maximum():
self.model().fetch_more(rows=rows)
self.sig_fetch_more_rows.emit()
if columns and value == self.horizontalScrollBar().maximum():
self.model().fetch_more(columns=columns)
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def sortByColumn(self, index):
"""Implement a column sort.""" |
if self.sort_old == [None]:
self.header_class.setSortIndicatorShown(True)
sort_order = self.header_class.sortIndicatorOrder()
self.sig_sort_by_column.emit()
if not self.model().sort(index, sort_order):
if len(self.sort_old) != 2:
self.heade... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def setup_menu(self):
"""Setup context menu.""" |
copy_action = create_action(self, _('Copy'),
shortcut=keybinding('Copy'),
icon=ima.icon('editcopy'),
triggered=self.copy,
context=Qt.WidgetShortcut)
func... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def change_type(self, func):
"""A function that changes types of cells.""" |
model = self.model()
index_list = self.selectedIndexes()
[model.setData(i, '', change_type=func) for i in index_list] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def rowCount(self, index=None):
"""Get number of rows in the header.""" |
if self.axis == 0:
return max(1, self._shape[0])
else:
if self.total_rows <= self.rows_loaded:
return self.total_rows
else:
return self.rows_loaded |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def sort(self, column, order=Qt.AscendingOrder):
"""Overriding sort method.""" |
ascending = order == Qt.AscendingOrder
self.model.sort(self.COLUMN_INDEX, order=ascending)
return True |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def headerData(self, section, orientation, role):
"""Get the information to put in the header.""" |
if role == Qt.TextAlignmentRole:
if orientation == Qt.Horizontal:
return Qt.AlignCenter | Qt.AlignBottom
else:
return Qt.AlignRight | Qt.AlignVCenter
if role != Qt.DisplayRole and role != Qt.ToolTipRole:
return None
if ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def data(self, index, role):
"""
Get the data for the header.
This is used when a header has levels.
""" |
if not index.isValid() or \
index.row() >= self._shape[0] or \
index.column() >= self._shape[1]:
return None
row, col = ((index.row(), index.column()) if self.axis == 0
else (index.column(), index.row()))
if role != Qt.DisplayRole:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def headerData(self, section, orientation, role):
"""
Get the text to put in the header of the levels of the indexes.
By default it returns 'Index i', where... |
if role == Qt.TextAlignmentRole:
if orientation == Qt.Horizontal:
return Qt.AlignCenter | Qt.AlignBottom
else:
return Qt.AlignRight | Qt.AlignVCenter
if role != Qt.DisplayRole and role != Qt.ToolTipRole:
return None
if ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def data(self, index, role):
"""Get the information of the levels.""" |
if not index.isValid():
return None
if role == Qt.FontRole:
return self._font
label = ''
if index.column() == self.model.header_shape[1] - 1:
label = str(self.model.name(0, index.row()))
elif index.row() == self.model.header_shape[0] -... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create_table_level(self):
"""Create the QTableView that will hold the level model.""" |
self.table_level = QTableView()
self.table_level.setEditTriggers(QTableWidget.NoEditTriggers)
self.table_level.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.table_level.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.table_level.setFrameStyle(QFrame.Plain)... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create_table_header(self):
"""Create the QTableView that will hold the header model.""" |
self.table_header = QTableView()
self.table_header.verticalHeader().hide()
self.table_header.setEditTriggers(QTableWidget.NoEditTriggers)
self.table_header.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.table_header.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create_table_index(self):
"""Create the QTableView that will hold the index model.""" |
self.table_index = QTableView()
self.table_index.horizontalHeader().hide()
self.table_index.setEditTriggers(QTableWidget.NoEditTriggers)
self.table_index.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.table_index.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create_data_table(self):
"""Create the QTableView that will hold the data model.""" |
self.dataTable = DataFrameView(self, self.dataModel,
self.table_header.horizontalHeader(),
self.hscroll, self.vscroll)
self.dataTable.verticalHeader().hide()
self.dataTable.horizontalHeader().hide()
self... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def sortByIndex(self, index):
"""Implement a Index sort.""" |
self.table_level.horizontalHeader().setSortIndicatorShown(True)
sort_order = self.table_level.horizontalHeader().sortIndicatorOrder()
self.table_index.model().sort(index, sort_order)
self._sort_update() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _column_resized(self, col, old_width, new_width):
"""Update the column width.""" |
self.dataTable.setColumnWidth(col, new_width)
self._update_layout() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _row_resized(self, row, old_height, new_height):
"""Update the row height.""" |
self.dataTable.setRowHeight(row, new_height)
self._update_layout() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _index_resized(self, col, old_width, new_width):
"""Resize the corresponding column of the index section selected.""" |
self.table_index.setColumnWidth(col, new_width)
self._update_layout() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _header_resized(self, row, old_height, new_height):
"""Resize the corresponding row of the header section selected.""" |
self.table_header.setRowHeight(row, new_height)
self._update_layout() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _reset_model(self, table, model):
"""Set the model in the given table.""" |
old_sel_model = table.selectionModel()
table.setModel(model)
if old_sel_model:
del old_sel_model |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def setCurrentIndex(self, y, x):
"""Set current selection.""" |
self.dataTable.selectionModel().setCurrentIndex(
self.dataTable.model().index(y, x),
QItemSelectionModel.ClearAndSelect) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _resizeColumnToContents(self, header, data, col, limit_ms):
"""Resize a column by its contents.""" |
hdr_width = self._sizeHintForColumn(header, col, limit_ms)
data_width = self._sizeHintForColumn(data, col, limit_ms)
if data_width > hdr_width:
width = min(self.max_width, data_width)
elif hdr_width > data_width * 2:
width = max(min(hdr_width, self.min_trun... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _resizeColumnsToContents(self, header, data, limit_ms):
"""Resize all the colummns to its contents.""" |
max_col = data.model().columnCount()
if limit_ms is None:
max_col_ms = None
else:
max_col_ms = limit_ms / max(1, max_col)
for col in range(max_col):
self._resizeColumnToContents(header, data, col, max_col_ms) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def eventFilter(self, obj, event):
"""Override eventFilter to catch resize event.""" |
if obj == self.dataTable and event.type() == QEvent.Resize:
self._resizeVisibleColumnsToContents()
return False |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _resizeCurrentColumnToContents(self, new_index, old_index):
"""Resize the current column to its contents.""" |
if new_index.column() not in self._autosized_cols:
# Ensure the requested column is fully into view after resizing
self._resizeVisibleColumnsToContents()
self.dataTable.scrollTo(new_index) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def resizeColumnsToContents(self):
"""Resize the columns to its contents.""" |
self._autosized_cols = set()
self._resizeColumnsToContents(self.table_level,
self.table_index, self._max_autosize_ms)
self._update_layout() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def change_format(self):
"""
Ask user for display format for floats and use it.
This function also checks whether the format is valid and emits
`sig_option... |
format, valid = QInputDialog.getText(self, _('Format'),
_("Float formatting"),
QLineEdit.Normal,
self.dataModel.get_format())
if valid:
format = str(f... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _update_header_size(self):
"""Update the column width of the header.""" |
column_count = self.table_header.model().columnCount()
for index in range(0, column_count):
if index < column_count:
column_width = self.dataTable.columnWidth(index)
self.table_header.setColumnWidth(index, column_width)
else:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def setup_options_button(self):
"""Add the cog menu button to the toolbar.""" |
if not self.options_button:
self.options_button = create_toolbutton(
self, text=_('Options'), icon=ima.icon('tooloptions'))
actions = self.actions + [MENU_SEPARATOR] + self.plugin_actions
self.options_menu = QMenu(self)
add_actions(self.op... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def option_changed(self, option, value):
"""Option has changed""" |
setattr(self, to_text_string(option), value)
self.shellwidget.set_namespace_view_settings()
self.refresh_table() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_view_settings(self):
"""Return dict editor view settings""" |
settings = {}
for name in REMOTE_SETTINGS:
settings[name] = getattr(self, name)
return settings |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def refresh_table(self):
"""Refresh variable table""" |
if self.is_visible and self.isVisible():
self.shellwidget.refresh_namespacebrowser()
try:
self.editor.resizeRowToContents()
except TypeError:
pass |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_data(self, data):
"""Set data.""" |
if data != self.editor.model.get_data():
self.editor.set_data(data)
self.editor.adjust_columns() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def import_data(self, filenames=None):
"""Import data from text file.""" |
title = _("Import data")
if filenames is None:
if self.filename is None:
basedir = getcwd_or_home()
else:
basedir = osp.dirname(self.filename)
filenames, _selfilter = getopenfilenames(self, title, basedir,
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def apply_changes(self):
"""Apply changes callback""" |
if self.is_modified:
self.save_to_conf()
if self.apply_callback is not None:
self.apply_callback()
# Since the language cannot be retrieved by CONF and the language
# is needed before loading CONF, this is an extra method needed to
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_page(self, index=None):
"""Return page widget""" |
if index is None:
widget = self.pages_widget.currentWidget()
else:
widget = self.pages_widget.widget(index)
return widget.widget() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def resizeEvent(self, event):
"""
Reimplement Qt method to be able to save the widget's size from the
main application
""" |
QDialog.resizeEvent(self, event)
self.size_change.emit(self.size()) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def is_valid(self):
"""Return True if all widget contents are valid""" |
for lineedit in self.lineedits:
if lineedit in self.validate_data and lineedit.isEnabled():
validator, invalid_msg = self.validate_data[lineedit]
text = to_text_string(lineedit.text())
if not validator(text):
QMessageBox.crit... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def save_to_conf(self):
"""Save settings to configuration file""" |
for checkbox, (option, _default) in list(self.checkboxes.items()):
self.set_option(option, checkbox.isChecked())
for radiobutton, (option, _default) in list(self.radiobuttons.items()):
self.set_option(option, radiobutton.isChecked())
for lineedit, (option, _default)... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create_fontgroup(self, option=None, text=None, title=None,
tip=None, fontfilters=None, without_group=False):
"""Option=None -> setting plugin font""" |
if title:
fontlabel = QLabel(title)
else:
fontlabel = QLabel(_("Font"))
fontbox = QFontComboBox()
if fontfilters is not None:
fontbox.setFontFilters(fontfilters)
sizelabel = QLabel(" "+_("Size"))
sizebox = QSpinBox()
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def prompt_restart_required(self):
"""Prompt the user with a request to restart.""" |
restart_opts = self.restart_options
changed_opts = self.changed_options
options = [restart_opts[o] for o in changed_opts if o in restart_opts]
if len(options) == 1:
msg_start = _("Spyder needs to restart to change the following "
"setting:")... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def update_status(self, value, value_set):
"""Update the status and set_status to update the icons to display.""" |
self._status = value
self._status_set = value_set
self.repaint()
self.update() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def restore_scrollbar_position(self):
"""Restoring scrollbar position after main window is visible""" |
scrollbar_pos = self.get_option('scrollbar_position', None)
if scrollbar_pos is not None:
self.explorer.treewidget.set_scrollbar_position(scrollbar_pos) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def remove_obsolete_items(self):
"""Removing obsolete items""" |
self.rdata = [(filename, data) for filename, data in self.rdata
if is_module_or_package(filename)] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def check_update_available(self):
"""Checks if there is an update available. It takes as parameters the current version of Spyder and a list of valid cleaned rel... |
# Don't perform any check for development versions
if 'dev' in self.version:
return (False, latest_release)
# Filter releases
if is_stable_version(self.version):
releases = [r for r in self.releases if is_stable_version(r)]
else:
releases = [... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def start(self):
"""Main method of the WorkerUpdates worker""" |
if is_anaconda():
self.url = 'https://repo.anaconda.com/pkgs/main'
if os.name == 'nt':
self.url += '/win-64/repodata.json'
elif sys.platform == 'darwin':
self.url += '/osx-64/repodata.json'
else:
self.url += '/linux... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create_shortcuts(self, parent):
"""Create shortcuts for this widget""" |
# Configurable
findnext = config_shortcut(self.find_next, context='_',
name='Find next', parent=parent)
findprev = config_shortcut(self.find_previous, context='_',
name='Find previous', parent=parent)
togglefind... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def toggle_highlighting(self, state):
"""Toggle the 'highlight all results' feature""" |
if self.editor is not None:
if state:
self.highlight_matches()
else:
self.clear_matches() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def show_replace(self):
"""Show replace widgets""" |
self.show(hide_replace=False)
for widget in self.replace_widgets:
widget.show() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def find_next(self):
"""Find next occurrence""" |
state = self.find(changed=False, forward=True, rehighlight=False,
multiline_replace_check=False)
self.editor.setFocus()
self.search_text.add_current_text()
return state |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def find_previous(self):
"""Find previous occurrence""" |
state = self.find(changed=False, forward=False, rehighlight=False,
multiline_replace_check=False)
self.editor.setFocus()
return state |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def highlight_matches(self):
"""Highlight found results""" |
if self.is_code_editor and self.highlight_button.isChecked():
text = self.search_text.currentText()
words = self.words_button.isChecked()
regexp = self.re_button.isChecked()
self.editor.highlight_found_results(text, words=words,
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def replace_find(self, focus_replace_text=False, replace_all=False):
"""Replace and find""" |
if (self.editor is not None):
replace_text = to_text_string(self.replace_text.currentText())
search_text = to_text_string(self.search_text.currentText())
re_pattern = None
# Check regexp before proceeding
if self.re_button.isChecked():
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def replace_find_selection(self, focus_replace_text=False):
"""Replace and find in the current selection""" |
if self.editor is not None:
replace_text = to_text_string(self.replace_text.currentText())
search_text = to_text_string(self.search_text.currentText())
case = self.case_button.isChecked()
words = self.words_button.isChecked()
re_flags = re.MULTI... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def change_number_matches(self, current_match=0, total_matches=0):
"""Change number of match and total matches.""" |
if current_match and total_matches:
matches_string = u"{} {} {}".format(current_match, _(u"of"),
total_matches)
self.number_matches_text.setText(matches_string)
elif total_matches:
matches_string = u"{} {}".format(... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_rich_text_font(self, font):
"""Set rich text mode font""" |
self.rich_text.set_font(font, fixed_font=self.get_plugin_font()) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_plain_text_font(self, font, color_scheme=None):
"""Set plain text mode font""" |
self.plain_text.set_font(font, color_scheme=color_scheme) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def switch_to_plain_text(self):
"""Switch to plain text mode""" |
self.rich_help = False
self.plain_text.show()
self.rich_text.hide()
self.plain_text_action.setChecked(True) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def switch_to_rich_text(self):
"""Switch to rich text mode""" |
self.rich_help = True
self.plain_text.hide()
self.rich_text.show()
self.rich_text_action.setChecked(True)
self.show_source_action.setChecked(False) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_plain_text(self, text, is_code):
"""Set plain text docs""" |
# text is coming from utils.dochelpers.getdoc
if type(text) is dict:
name = text['name']
if name:
rst_title = ''.join(['='*len(name), '\n', name, '\n',
'='*len(name), '\n\n'])
else:
rst_tit... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_rich_text_html(self, html_text, base_url):
"""Set rich text""" |
self.rich_text.set_html(html_text, base_url)
self.save_text([self.rich_text.set_html, html_text, base_url]) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def show_rich_text(self, text, collapse=False, img_path=''):
"""Show text in rich mode""" |
self.switch_to_plugin()
self.switch_to_rich_text()
context = generate_context(collapse=collapse, img_path=img_path,
css_path=self.css_path)
self.render_sphinx_doc(text, context) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def show_plain_text(self, text):
"""Show text in plain mode""" |
self.switch_to_plugin()
self.switch_to_plain_text()
self.set_plain_text(text, is_code=False) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def show_tutorial(self):
"""Show the Spyder tutorial in the Help plugin, opening it if needed""" |
self.switch_to_plugin()
tutorial_path = get_module_source_path('spyder.plugins.help.utils')
tutorial = osp.join(tutorial_path, 'tutorial.rst')
text = open(tutorial).read()
self.show_rich_text(text, collapse=True) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_object_text(self, text, force_refresh=False, ignore_unknown=False):
"""Set object analyzed by Help""" |
if (self.locked and not force_refresh):
return
self.switch_to_console_source()
add_to_combo = True
if text is None:
text = to_text_string(self.combo.currentText())
add_to_combo = False
found = self.show_help(text, ignore_unknown=ig... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_editor_doc(self, doc, force_refresh=False):
"""
Use the help plugin to show docstring dictionary computed
with introspection plugin from the Editor pl... |
if (self.locked and not force_refresh):
return
self.switch_to_editor_source()
self._last_editor_doc = doc
self.object_edit.setText(doc['obj_text'])
if self.rich_help:
self.render_sphinx_doc(doc)
else:
self.set_plain_text(doc... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def toggle_plain_text(self, checked):
"""Toggle plain text docstring""" |
if checked:
self.docstring = checked
self.switch_to_plain_text()
self.force_refresh()
self.set_option('rich_mode', not checked) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def toggle_show_source(self, checked):
"""Toggle show source code""" |
if checked:
self.switch_to_plain_text()
self.docstring = not checked
self.force_refresh()
self.set_option('rich_mode', not checked) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def toggle_rich_text(self, checked):
"""Toggle between sphinxified docstrings or plain ones""" |
if checked:
self.docstring = not checked
self.switch_to_rich_text()
self.set_option('rich_mode', checked) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def toggle_auto_import(self, checked):
"""Toggle automatic import feature""" |
self.combo.validate_current_text()
self.set_option('automatic_import', checked)
self.force_refresh() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _update_lock_icon(self):
"""Update locked state icon""" |
icon = ima.icon('lock') if self.locked else ima.icon('lock_open')
self.locked_button.setIcon(icon)
tip = _("Unlock") if self.locked else _("Lock")
self.locked_button.setToolTip(tip) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_shell(self):
"""
Return shell which is currently bound to Help,
or another running shell if it has been terminated
""" |
if (not hasattr(self.shell, 'get_doc') or
(hasattr(self.shell, 'is_running') and
not self.shell.is_running())):
self.shell = None
if self.main.ipyconsole is not None:
shell = self.main.ipyconsole.get_current_shellwidget()
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def render_sphinx_doc(self, doc, context=None, css_path=CSS_PATH):
"""Transform doc string dictionary to HTML and show it""" |
# Math rendering option could have changed
if self.main.editor is not None:
fname = self.main.editor.get_current_filename()
dname = osp.dirname(fname)
else:
dname = ''
self._sphinx_thread.render(doc, context, self.get_option('math'),
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _on_sphinx_thread_html_ready(self, html_text):
"""Set our sphinx documentation based on thread result""" |
self._sphinx_thread.wait()
self.set_rich_text_html(html_text, QUrl.fromLocalFile(self.css_path)) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _on_sphinx_thread_error_msg(self, error_msg):
""" Display error message on Sphinx rich text failure""" |
self._sphinx_thread.wait()
self.plain_text_action.setChecked(True)
sphinx_ver = programs.get_module_version('sphinx')
QMessageBox.critical(self,
_('Help'),
_("The following error occured when calling "
"<b>Sphinx %s</b... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def contains_cursor(self, cursor):
""" Checks if the textCursor is in the decoration. :param cursor: The text cursor to test :type cursor: QtGui.QTextCursor :ret... |
start = self.cursor.selectionStart()
end = self.cursor.selectionEnd()
if cursor.atBlockEnd():
end -= 1
return start <= cursor.position() <= end |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_as_underlined(self, color=Qt.blue):
""" Underlines the text. :param color: underline color. """ |
self.format.setUnderlineStyle(
QTextCharFormat.SingleUnderline)
self.format.setUnderlineColor(color) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_as_spell_check(self, color=Qt.blue):
""" Underlines text as a spellcheck error. :param color: Underline color :type color: QtGui.QColor """ |
self.format.setUnderlineStyle(
QTextCharFormat.SpellCheckUnderline)
self.format.setUnderlineColor(color) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_as_error(self, color=Qt.red):
""" Highlights text as a syntax error. :param color: Underline color :type color: QtGui.QColor """ |
self.format.setUnderlineStyle(
QTextCharFormat.WaveUnderline)
self.format.setUnderlineColor(color) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_as_warning(self, color=QColor("orange")):
""" Highlights text as a syntax warning. :param color: Underline color :type color: QtGui.QColor """ |
self.format.setUnderlineStyle(
QTextCharFormat.WaveUnderline)
self.format.setUnderlineColor(color) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def close_threads(self, parent):
"""Close threads associated to parent_id""" |
logger.debug("Call ThreadManager's 'close_threads'")
if parent is None:
# Closing all threads
self.pending_threads = []
threadlist = []
for threads in list(self.started_threads.values()):
threadlist += threads
else:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def add_thread(self, checker, end_callback, source_code, parent):
"""Add thread to queue""" |
parent_id = id(parent)
thread = AnalysisThread(self, checker, source_code)
self.end_callbacks[id(thread)] = end_callback
self.pending_threads.append((thread, parent_id))
logger.debug("Added thread %r to queue" % thread)
QTimer.singleShot(50, self.update_queue) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def text_changed(self):
"""Editor's text has changed""" |
self.default = False
self.editor.document().changed_since_autosave = True
self.text_changed_at.emit(self.filename,
self.editor.get_position('cursor')) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def bookmarks_changed(self):
"""Bookmarks list has changed.""" |
bookmarks = self.editor.get_bookmarks()
if self.editor.bookmarks != bookmarks:
self.editor.bookmarks = bookmarks
self.sig_save_bookmarks.emit(self.filename, repr(bookmarks)) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _update_id_list(self):
"""Update list of corresponpding ids and tabs.""" |
self.id_list = [id(self.editor.tabs.widget(_i))
for _i in range(self.editor.tabs.count())] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def refresh(self):
"""Remove editors that are not longer open.""" |
self._update_id_list()
for _id in self.history[:]:
if _id not in self.id_list:
self.history.remove(_id) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def remove(self, tab_index):
"""Remove the widget at the corresponding tab_index.""" |
_id = id(self.editor.tabs.widget(tab_index))
if _id in self.history:
self.history.remove(_id) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def remove_and_append(self, index):
"""Remove previous entrances of a tab, and add it as the latest.""" |
while index in self:
self.remove(index)
self.append(index) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def load_data(self):
"""Fill ListWidget with the tabs texts.
Add elements in inverse order of stack_history.
""" |
for index in reversed(self.stack_history):
text = self.tabs.tabText(index)
text = text.replace('&', '')
item = QListWidgetItem(ima.icon('TextFileIcon'), text)
self.addItem(item) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def item_selected(self, item=None):
"""Change to the selected document and hide this widget.""" |
if item is None:
item = self.currentItem()
# stack history is in inverse order
try:
index = self.stack_history[-(self.currentRow()+1)]
except IndexError:
pass
else:
self.editor.set_stack_index(index)
self.ed... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def select_row(self, steps):
"""Move selected row a number of steps.
Iterates in a cyclic behaviour.
""" |
row = (self.currentRow() + steps) % self.count()
self.setCurrentRow(row) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_dialog_position(self):
"""Positions the tab switcher in the top-center of the editor.""" |
left = self.editor.geometry().width()/2 - self.width()/2
top = self.editor.tabs.tabBar().geometry().height()
self.move(self.editor.mapToGlobal(QPoint(left, top))) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def keyReleaseEvent(self, event):
"""Reimplement Qt method.
Handle "most recent used" tab behavior,
When ctrl is released and tab_switcher is visible, tab w... |
if self.isVisible():
qsc = get_shortcut(context='Editor', name='Go to next file')
for key in qsc.split('+'):
key = key.lower()
if ((key == 'ctrl' and event.key() == Qt.Key_Control) or
(key == 'alt' and event.key() == Qt.Key_Alt)... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def keyPressEvent(self, event):
"""Reimplement Qt method to allow cyclic behavior.""" |
if event.key() == Qt.Key_Down:
self.select_row(1)
elif event.key() == Qt.Key_Up:
self.select_row(-1) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def focusOutEvent(self, event):
"""Reimplement Qt method to close the widget when loosing focus.""" |
event.ignore()
# Inspired from CompletionWidget.focusOutEvent() in file
# widgets/sourcecode/base.py line 212
if sys.platform == "darwin":
if event.reason() != Qt.ActiveWindowFocusReason:
self.close()
else:
self.close() |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.