text stringlengths 81 112k |
|---|
Create the QTableView that will hold the level model.
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... |
Create the QTableView that will hold the header model.
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... |
Create the QTableView that will hold the index model.
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)
... |
Create the QTableView that will hold the data model.
def create_data_table(self):
"""Create the QTableView that will hold the data model."""
self.dataTable = DataFrameView(self, self.dataModel,
self.table_header.horizontalHeader(),
... |
Implement a Index sort.
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._s... |
Update the column width.
def _column_resized(self, col, old_width, new_width):
"""Update the column width."""
self.dataTable.setColumnWidth(col, new_width)
self._update_layout() |
Update the row height.
def _row_resized(self, row, old_height, new_height):
"""Update the row height."""
self.dataTable.setRowHeight(row, new_height)
self._update_layout() |
Resize the corresponding column of the index section selected.
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() |
Resize the corresponding row of the header section selected.
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() |
Set the model in the given table.
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 |
Set the model for the data, header/index and level views.
def setModel(self, model, relayout=True):
"""Set the model for the data, header/index and level views."""
self._model = model
sel_model = self.dataTable.selectionModel()
sel_model.currentColumnChanged.connect(
... |
Set current selection.
def setCurrentIndex(self, y, x):
"""Set current selection."""
self.dataTable.selectionModel().setCurrentIndex(
self.dataTable.model().index(y, x),
QItemSelectionModel.ClearAndSelect) |
Resize a column by its contents.
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:
... |
Resize all the colummns to its contents.
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... |
Override eventFilter to catch resize event.
def eventFilter(self, obj, event):
"""Override eventFilter to catch resize event."""
if obj == self.dataTable and event.type() == QEvent.Resize:
self._resizeVisibleColumnsToContents()
return False |
Resize the current column to its contents.
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... |
Resize the columns to its contents.
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_... |
This is implementet so column min/max is only active when bgcolor is
def change_bgcolor_enable(self, state):
"""
This is implementet so column min/max is only active when bgcolor is
"""
self.dataModel.bgcolor(state)
self.bgcolor_global.setEnabled(not self.is_series and stat... |
Ask user for display format for floats and use it.
This function also checks whether the format is valid and emits
`sig_option_changed`.
def change_format(self):
"""
Ask user for display format for floats and use it.
This function also checks whether the format is valid... |
Return modified Dataframe -- this is *not* a copy
def get_value(self):
"""Return modified Dataframe -- this is *not* a copy"""
# It is import to avoid accessing Qt C++ object as it has probably
# already been destroyed, due to the Qt.WA_DeleteOnClose attribute
df = self.dataModel.ge... |
Update the column width of the header.
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.... |
Setup the namespace browser with provided settings.
Args:
dataframe_format (string): default floating-point format for
DataFrame editor
def setup(self, check_all=None, exclude_private=None,
exclude_uppercase=None, exclude_capitalized=None,
exclude... |
Setup toolbar
def setup_toolbar(self):
"""Setup toolbar"""
load_button = create_toolbutton(self, text=_('Import data'),
icon=ima.icon('fileimport'),
triggered=lambda: self.import_data())
self.save_button = crea... |
Setup the actions to show in the cog menu.
def setup_option_actions(self, exclude_private, exclude_uppercase,
exclude_capitalized, exclude_unsupported):
"""Setup the actions to show in the cog menu."""
self.setup_in_progress = True
self.exclude_private_action ... |
Add the cog menu button to the toolbar.
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... |
Option has changed
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() |
Return dict editor view settings
def get_view_settings(self):
"""Return dict editor view settings"""
settings = {}
for name in REMOTE_SETTINGS:
settings[name] = getattr(self, name)
return settings |
Refresh variable table
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 |
Set data.
def set_data(self, data):
"""Set data."""
if data != self.editor.model.get_data():
self.editor.set_data(data)
self.editor.adjust_columns() |
Import data from text file.
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(sel... |
Save data
def save_data(self, filename=None):
"""Save data"""
if filename is None:
filename = self.filename
if filename is None:
filename = getcwd_or_home()
filename, _selfilter = getsavefilename(self, _("Save data"),
... |
Apply changes callback
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
... |
Return page widget
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() |
Reimplement Qt method
def accept(self):
"""Reimplement Qt method"""
for index in range(self.pages_widget.count()):
configpage = self.get_page(index)
if not configpage.is_valid():
return
configpage.apply_changes()
QDialog.accept(self) |
Reimplement Qt method to be able to save the widget's size from the
main application
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_chang... |
Return True if all widget contents are valid
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]
... |
Load settings from configuration file
def load_from_conf(self):
"""Load settings from configuration file"""
for checkbox, (option, default) in list(self.checkboxes.items()):
checkbox.setChecked(self.get_option(option, default))
# QAbstractButton works differently for PySide ... |
Save settings to configuration file
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.it... |
Select directory
def select_directory(self, edit):
"""Select directory"""
basedir = to_text_string(edit.text())
if not osp.isdir(basedir):
basedir = getcwd_or_home()
title = _("Select directory")
directory = getexistingdirectory(self, title, basedir)
i... |
Select File
def select_file(self, edit, filters=None):
"""Select File"""
basedir = osp.dirname(to_text_string(edit.text()))
if not osp.isdir(basedir):
basedir = getcwd_or_home()
if filters is None:
filters = _("All files (*)")
title = _("Select fil... |
choices: couples (name, key)
def create_combobox(self, text, choices, option, default=NoDefault,
tip=None, restart=False):
"""choices: couples (name, key)"""
label = QLabel(text)
combobox = QComboBox()
if tip is not None:
combobox.setToolTip(tip... |
choices: couples (name, key)
def create_file_combobox(self, text, choices, option, default=NoDefault,
tip=None, restart=False, filters=None,
adjust_to_contents=False,
default_line_edit=False):
"""choices: couples (name, ... |
Option=None -> setting plugin font
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:
fontlab... |
Create simple tab widget page: widgets added in a vertical layout
def create_tab(self, *widgets):
"""Create simple tab widget page: widgets added in a vertical layout"""
widget = QWidget()
layout = QVBoxLayout()
for widg in widgets:
layout.addWidget(widg)
layou... |
Prompt the user with a request to restart.
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... |
After an application style change, the paintEvent updates the
custom defined stylesheet.
def _refresh(self):
"""After an application style change, the paintEvent updates the
custom defined stylesheet.
"""
padding = self.height()
css_base = """QLineEdit {{
... |
Update the status and set_status to update the icons to display.
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() |
Qt Override.
Include a validation icon to the left of the line edit.
def paintEvent(self, event):
"""Qt Override.
Include a validation icon to the left of the line edit.
"""
super(IconLineEdit, self).paintEvent(event)
painter = QPainter(self)
rect = self.geome... |
Register plugin in Spyder's main window
def register_plugin(self):
"""Register plugin in Spyder's main window"""
self.main.restore_scrollbar_position.connect(
self.restore_scrollbar_position)
self.main.add_dockwidget(self) |
DockWidget visibility has changed
def visibility_changed(self, enable):
"""DockWidget visibility has changed"""
super(SpyderPluginWidget, self).visibility_changed(enable)
if enable:
self.explorer.is_visible.emit() |
Restoring scrollbar position after main window is visible
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_... |
Save configuration: tree widget state
def save_config(self):
"""Save configuration: tree widget state"""
for option, value in list(self.explorer.get_options().items()):
self.set_option(option, value)
self.set_option('expanded_state',
self.explorer.treewi... |
Load configuration: tree widget state
def load_config(self):
"""Load configuration: tree widget state"""
expanded_state = self.get_option('expanded_state', None)
# Sometimes the expanded state option may be truncated in .ini file
# (for an unknown reason), in this case it would be c... |
Double-click event
def activated(self, item):
"""Double-click event"""
data = self.data.get(id(item))
if data is not None:
fname, lineno = data
self.sig_edit_goto.emit(fname, lineno, '') |
Removing obsolete items
def remove_obsolete_items(self):
"""Removing obsolete items"""
self.rdata = [(filename, data) for filename, data in self.rdata
if is_module_or_package(filename)] |
Checks if there is an update available.
It takes as parameters the current version of Spyder and a list of
valid cleaned releases in chronological order.
Example: ['2.3.2', '2.3.3' ...] or with github ['2.3.4', '2.3.3' ...]
def check_update_available(self):
"""Checks if there is an upd... |
Main method of the WorkerUpdates worker
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 == 'dar... |
Event filter for search_text widget.
Emits signals when presing Enter and Shift+Enter.
This signals are used for search forward and backward.
Also, a crude hack to get tab working in the Find/Replace boxes.
def eventFilter(self, widget, event):
"""Event filter for search_text widg... |
Create shortcuts for this widget
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.fin... |
Toggle the 'highlight all results' feature
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() |
Overrides Qt Method
def show(self, hide_replace=True):
"""Overrides Qt Method"""
QWidget.show(self)
self.visibility_changed.emit(True)
self.change_number_matches()
if self.editor is not None:
if hide_replace:
if self.replace_widgets[0].isVisibl... |
Overrides Qt Method
def hide(self):
"""Overrides Qt Method"""
for widget in self.replace_widgets:
widget.hide()
QWidget.hide(self)
self.visibility_changed.emit(False)
if self.editor is not None:
self.editor.setFocus()
self.clear_matche... |
Show replace widgets
def show_replace(self):
"""Show replace widgets"""
self.show(hide_replace=False)
for widget in self.replace_widgets:
widget.show() |
Refresh widget
def refresh(self):
"""Refresh widget"""
if self.isHidden():
if self.editor is not None:
self.clear_matches()
return
state = self.editor is not None
for widget in self.widgets:
widget.setEnabled(state)
if... |
Set associated editor/web page:
codeeditor.base.TextEditBaseWidget
browser.WebView
def set_editor(self, editor, refresh=True):
"""
Set associated editor/web page:
codeeditor.base.TextEditBaseWidget
browser.WebView
"""
self.editor =... |
Find next occurrence
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 |
Find previous occurrence
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 |
Find text has been edited (this slot won't be triggered when
setting the search pattern combo box text programmatically)
def text_has_been_edited(self, text):
"""Find text has been edited (this slot won't be triggered when
setting the search pattern combo box text programmatically)"""
... |
Highlight found results
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()
... |
Call the find function
def find(self, changed=True, forward=True,
rehighlight=True, start_highlight_timer=False, multiline_replace_check=True):
"""Call the find function"""
# When several lines are selected in the editor and replace box is activated,
# dynamic search is deacti... |
Replace and find
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())
... |
Replace and find in the current selection
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.... |
Change number of match and total matches.
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"),
... |
Monkey patching rope
See [1], [2], [3], [4] and [5] in module docstring.
def apply():
"""Monkey patching rope
See [1], [2], [3], [4] and [5] in module docstring."""
from spyder.utils.programs import is_module_installed
if is_module_installed('rope', '<0.9.4'):
import rope
... |
Override Qt method.
def paintEvent(self, event):
"""Override Qt method."""
painter = QPainter(self)
color = QColor(self.color)
color.setAlphaF(.5)
painter.setPen(color)
offset = self.editor.document().documentMargin() + \
self.editor.contentOffset().x()
... |
Return a list of actions related to plugin
def get_plugin_actions(self):
"""Return a list of actions related to plugin"""
return [self.rich_text_action, self.plain_text_action,
self.show_source_action, MENU_SEPARATOR,
self.auto_import_action] |
Register plugin in Spyder's main window
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)
self.main.console.set_help(self)
self.internal_shell = self.main.cons... |
Refresh widget
def refresh_plugin(self):
"""Refresh widget"""
if self._starting_up:
self._starting_up = False
self.switch_to_rich_text()
self.show_intro_message() |
Update font from Preferences
def update_font(self):
"""Update font from Preferences"""
color_scheme = self.get_color_scheme()
font = self.get_plugin_font()
rich_font = self.get_plugin_font(rich_text=True)
self.set_plain_text_font(font, color_scheme=color_scheme)
... |
Apply configuration file's plugin settings
def apply_plugin_settings(self, options):
"""Apply configuration file's plugin settings"""
color_scheme_n = 'color_scheme_name'
color_scheme_o = self.get_color_scheme()
connect_n = 'connect_to_oi'
wrap_n = 'wrap'
wrap_o = ... |
Set rich text mode font
def set_rich_text_font(self, font):
"""Set rich text mode font"""
self.rich_text.set_font(font, fixed_font=self.get_plugin_font()) |
Set plain text mode font
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) |
Toggle wrap mode
def toggle_wrap_mode(self, checked):
"""Toggle wrap mode"""
self.plain_text.editor.toggle_wrap_mode(checked)
self.set_option('wrap', checked) |
Switch to plain text mode
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) |
Switch to rich text mode
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) |
Set plain text docs
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',
... |
Set rich text
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]) |
Show text in rich mode
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_... |
Show text in plain mode
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) |
Show the Spyder tutorial in the Help plugin, opening it if needed
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... |
Set object analyzed by Help
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:
... |
Use the help plugin to show docstring dictionary computed
with introspection plugin from the Editor plugin
def set_editor_doc(self, doc, force_refresh=False):
"""
Use the help plugin to show docstring dictionary computed
with introspection plugin from the Editor plugin
"""
... |
Load history from a text file in user home directory
def load_history(self, obj=None):
"""Load history from a text file in user home directory"""
if osp.isfile(self.LOG_PATH):
history = [line.replace('\n', '')
for line in open(self.LOG_PATH, 'r').readlines()]
... |
Save history to a text file in user home directory
def save_history(self):
"""Save history to a text file in user home directory"""
# Don't fail when saving search history to disk
# See issues 8878 and 6864
try:
search_history = [to_text_string(self.combo.itemText(index... |
Toggle plain text docstring
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) |
Toggle show source code
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) |
Toggle between sphinxified docstrings or plain ones
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) |
Toggle automatic import feature
def toggle_auto_import(self, checked):
"""Toggle automatic import feature"""
self.combo.validate_current_text()
self.set_option('automatic_import', checked)
self.force_refresh() |
Update locked state icon
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) |
Return shell which is currently bound to Help,
or another running shell if it has been terminated
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') o... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.