repo
stringlengths
7
55
path
stringlengths
4
223
func_name
stringlengths
1
134
original_string
stringlengths
75
104k
language
stringclasses
1 value
code
stringlengths
75
104k
code_tokens
listlengths
19
28.4k
docstring
stringlengths
1
46.9k
docstring_tokens
listlengths
1
1.97k
sha
stringlengths
40
40
url
stringlengths
87
315
partition
stringclasses
1 value
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor.create_table_level
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) self.table_level.horizontalHeader().sectionResized.connect( self._index_resized) self.table_level.verticalHeader().sectionResized.connect( self._header_resized) self.table_level.setItemDelegate(QItemDelegate()) self.layout.addWidget(self.table_level, 0, 0) self.table_level.setContentsMargins(0, 0, 0, 0) self.table_level.horizontalHeader().sectionClicked.connect( self.sortByIndex)
python
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) self.table_level.horizontalHeader().sectionResized.connect( self._index_resized) self.table_level.verticalHeader().sectionResized.connect( self._header_resized) self.table_level.setItemDelegate(QItemDelegate()) self.layout.addWidget(self.table_level, 0, 0) self.table_level.setContentsMargins(0, 0, 0, 0) self.table_level.horizontalHeader().sectionClicked.connect( self.sortByIndex)
[ "def", "create_table_level", "(", "self", ")", ":", "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", ")", "self", ".", "table_level", ".", "horizontalHeader", "(", ")", ".", "sectionResized", ".", "connect", "(", "self", ".", "_index_resized", ")", "self", ".", "table_level", ".", "verticalHeader", "(", ")", ".", "sectionResized", ".", "connect", "(", "self", ".", "_header_resized", ")", "self", ".", "table_level", ".", "setItemDelegate", "(", "QItemDelegate", "(", ")", ")", "self", ".", "layout", ".", "addWidget", "(", "self", ".", "table_level", ",", "0", ",", "0", ")", "self", ".", "table_level", ".", "setContentsMargins", "(", "0", ",", "0", ",", "0", ",", "0", ")", "self", ".", "table_level", ".", "horizontalHeader", "(", ")", ".", "sectionClicked", ".", "connect", "(", "self", ".", "sortByIndex", ")" ]
Create the QTableView that will hold the level model.
[ "Create", "the", "QTableView", "that", "will", "hold", "the", "level", "model", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L956-L971
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor.create_table_header
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) self.table_header.setHorizontalScrollMode(QTableView.ScrollPerPixel) self.table_header.setHorizontalScrollBar(self.hscroll) self.table_header.setFrameStyle(QFrame.Plain) self.table_header.horizontalHeader().sectionResized.connect( self._column_resized) self.table_header.setItemDelegate(QItemDelegate()) self.layout.addWidget(self.table_header, 0, 1)
python
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) self.table_header.setHorizontalScrollMode(QTableView.ScrollPerPixel) self.table_header.setHorizontalScrollBar(self.hscroll) self.table_header.setFrameStyle(QFrame.Plain) self.table_header.horizontalHeader().sectionResized.connect( self._column_resized) self.table_header.setItemDelegate(QItemDelegate()) self.layout.addWidget(self.table_header, 0, 1)
[ "def", "create_table_header", "(", "self", ")", ":", "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", ")", "self", ".", "table_header", ".", "setHorizontalScrollMode", "(", "QTableView", ".", "ScrollPerPixel", ")", "self", ".", "table_header", ".", "setHorizontalScrollBar", "(", "self", ".", "hscroll", ")", "self", ".", "table_header", ".", "setFrameStyle", "(", "QFrame", ".", "Plain", ")", "self", ".", "table_header", ".", "horizontalHeader", "(", ")", ".", "sectionResized", ".", "connect", "(", "self", ".", "_column_resized", ")", "self", ".", "table_header", ".", "setItemDelegate", "(", "QItemDelegate", "(", ")", ")", "self", ".", "layout", ".", "addWidget", "(", "self", ".", "table_header", ",", "0", ",", "1", ")" ]
Create the QTableView that will hold the header model.
[ "Create", "the", "QTableView", "that", "will", "hold", "the", "header", "model", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L973-L986
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor.create_table_index
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) self.table_index.setVerticalScrollMode(QTableView.ScrollPerPixel) self.table_index.setVerticalScrollBar(self.vscroll) self.table_index.setFrameStyle(QFrame.Plain) self.table_index.verticalHeader().sectionResized.connect( self._row_resized) self.table_index.setItemDelegate(QItemDelegate()) self.layout.addWidget(self.table_index, 1, 0) self.table_index.setContentsMargins(0, 0, 0, 0)
python
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) self.table_index.setVerticalScrollMode(QTableView.ScrollPerPixel) self.table_index.setVerticalScrollBar(self.vscroll) self.table_index.setFrameStyle(QFrame.Plain) self.table_index.verticalHeader().sectionResized.connect( self._row_resized) self.table_index.setItemDelegate(QItemDelegate()) self.layout.addWidget(self.table_index, 1, 0) self.table_index.setContentsMargins(0, 0, 0, 0)
[ "def", "create_table_index", "(", "self", ")", ":", "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", ")", "self", ".", "table_index", ".", "setVerticalScrollMode", "(", "QTableView", ".", "ScrollPerPixel", ")", "self", ".", "table_index", ".", "setVerticalScrollBar", "(", "self", ".", "vscroll", ")", "self", ".", "table_index", ".", "setFrameStyle", "(", "QFrame", ".", "Plain", ")", "self", ".", "table_index", ".", "verticalHeader", "(", ")", ".", "sectionResized", ".", "connect", "(", "self", ".", "_row_resized", ")", "self", ".", "table_index", ".", "setItemDelegate", "(", "QItemDelegate", "(", ")", ")", "self", ".", "layout", ".", "addWidget", "(", "self", ".", "table_index", ",", "1", ",", "0", ")", "self", ".", "table_index", ".", "setContentsMargins", "(", "0", ",", "0", ",", "0", ",", "0", ")" ]
Create the QTableView that will hold the index model.
[ "Create", "the", "QTableView", "that", "will", "hold", "the", "index", "model", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L988-L1002
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor.create_data_table
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.dataTable.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.dataTable.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.dataTable.setHorizontalScrollMode(QTableView.ScrollPerPixel) self.dataTable.setVerticalScrollMode(QTableView.ScrollPerPixel) self.dataTable.setFrameStyle(QFrame.Plain) self.dataTable.setItemDelegate(QItemDelegate()) self.layout.addWidget(self.dataTable, 1, 1) self.setFocusProxy(self.dataTable) self.dataTable.sig_sort_by_column.connect(self._sort_update) self.dataTable.sig_fetch_more_columns.connect(self._fetch_more_columns) self.dataTable.sig_fetch_more_rows.connect(self._fetch_more_rows)
python
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.dataTable.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.dataTable.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.dataTable.setHorizontalScrollMode(QTableView.ScrollPerPixel) self.dataTable.setVerticalScrollMode(QTableView.ScrollPerPixel) self.dataTable.setFrameStyle(QFrame.Plain) self.dataTable.setItemDelegate(QItemDelegate()) self.layout.addWidget(self.dataTable, 1, 1) self.setFocusProxy(self.dataTable) self.dataTable.sig_sort_by_column.connect(self._sort_update) self.dataTable.sig_fetch_more_columns.connect(self._fetch_more_columns) self.dataTable.sig_fetch_more_rows.connect(self._fetch_more_rows)
[ "def", "create_data_table", "(", "self", ")", ":", "self", ".", "dataTable", "=", "DataFrameView", "(", "self", ",", "self", ".", "dataModel", ",", "self", ".", "table_header", ".", "horizontalHeader", "(", ")", ",", "self", ".", "hscroll", ",", "self", ".", "vscroll", ")", "self", ".", "dataTable", ".", "verticalHeader", "(", ")", ".", "hide", "(", ")", "self", ".", "dataTable", ".", "horizontalHeader", "(", ")", ".", "hide", "(", ")", "self", ".", "dataTable", ".", "setHorizontalScrollBarPolicy", "(", "Qt", ".", "ScrollBarAlwaysOff", ")", "self", ".", "dataTable", ".", "setVerticalScrollBarPolicy", "(", "Qt", ".", "ScrollBarAlwaysOff", ")", "self", ".", "dataTable", ".", "setHorizontalScrollMode", "(", "QTableView", ".", "ScrollPerPixel", ")", "self", ".", "dataTable", ".", "setVerticalScrollMode", "(", "QTableView", ".", "ScrollPerPixel", ")", "self", ".", "dataTable", ".", "setFrameStyle", "(", "QFrame", ".", "Plain", ")", "self", ".", "dataTable", ".", "setItemDelegate", "(", "QItemDelegate", "(", ")", ")", "self", ".", "layout", ".", "addWidget", "(", "self", ".", "dataTable", ",", "1", ",", "1", ")", "self", ".", "setFocusProxy", "(", "self", ".", "dataTable", ")", "self", ".", "dataTable", ".", "sig_sort_by_column", ".", "connect", "(", "self", ".", "_sort_update", ")", "self", ".", "dataTable", ".", "sig_fetch_more_columns", ".", "connect", "(", "self", ".", "_fetch_more_columns", ")", "self", ".", "dataTable", ".", "sig_fetch_more_rows", ".", "connect", "(", "self", ".", "_fetch_more_rows", ")" ]
Create the QTableView that will hold the data model.
[ "Create", "the", "QTableView", "that", "will", "hold", "the", "data", "model", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L1004-L1021
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor.sortByIndex
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()
python
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()
[ "def", "sortByIndex", "(", "self", ",", "index", ")", ":", "self", ".", "table_level", ".", "horizontalHeader", "(", ")", ".", "setSortIndicatorShown", "(", "True", ")", "sort_order", "=", "self", ".", "table_level", ".", "horizontalHeader", "(", ")", ".", "sortIndicatorOrder", "(", ")", "self", ".", "table_index", ".", "model", "(", ")", ".", "sort", "(", "index", ",", "sort_order", ")", "self", ".", "_sort_update", "(", ")" ]
Implement a Index sort.
[ "Implement", "a", "Index", "sort", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L1023-L1028
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor._column_resized
def _column_resized(self, col, old_width, new_width): """Update the column width.""" self.dataTable.setColumnWidth(col, new_width) self._update_layout()
python
def _column_resized(self, col, old_width, new_width): """Update the column width.""" self.dataTable.setColumnWidth(col, new_width) self._update_layout()
[ "def", "_column_resized", "(", "self", ",", "col", ",", "old_width", ",", "new_width", ")", ":", "self", ".", "dataTable", ".", "setColumnWidth", "(", "col", ",", "new_width", ")", "self", ".", "_update_layout", "(", ")" ]
Update the column width.
[ "Update", "the", "column", "width", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L1034-L1037
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor._row_resized
def _row_resized(self, row, old_height, new_height): """Update the row height.""" self.dataTable.setRowHeight(row, new_height) self._update_layout()
python
def _row_resized(self, row, old_height, new_height): """Update the row height.""" self.dataTable.setRowHeight(row, new_height) self._update_layout()
[ "def", "_row_resized", "(", "self", ",", "row", ",", "old_height", ",", "new_height", ")", ":", "self", ".", "dataTable", ".", "setRowHeight", "(", "row", ",", "new_height", ")", "self", ".", "_update_layout", "(", ")" ]
Update the row height.
[ "Update", "the", "row", "height", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L1039-L1042
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor._index_resized
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()
python
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()
[ "def", "_index_resized", "(", "self", ",", "col", ",", "old_width", ",", "new_width", ")", ":", "self", ".", "table_index", ".", "setColumnWidth", "(", "col", ",", "new_width", ")", "self", ".", "_update_layout", "(", ")" ]
Resize the corresponding column of the index section selected.
[ "Resize", "the", "corresponding", "column", "of", "the", "index", "section", "selected", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L1044-L1047
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor._header_resized
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()
python
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()
[ "def", "_header_resized", "(", "self", ",", "row", ",", "old_height", ",", "new_height", ")", ":", "self", ".", "table_header", ".", "setRowHeight", "(", "row", ",", "new_height", ")", "self", ".", "_update_layout", "(", ")" ]
Resize the corresponding row of the header section selected.
[ "Resize", "the", "corresponding", "row", "of", "the", "header", "section", "selected", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L1049-L1052
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor._reset_model
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
python
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
[ "def", "_reset_model", "(", "self", ",", "table", ",", "model", ")", ":", "old_sel_model", "=", "table", ".", "selectionModel", "(", ")", "table", ".", "setModel", "(", "model", ")", "if", "old_sel_model", ":", "del", "old_sel_model" ]
Set the model in the given table.
[ "Set", "the", "model", "in", "the", "given", "table", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L1087-L1092
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor.setModel
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( self._resizeCurrentColumnToContents) # Asociate the models (level, vertical index and horizontal header) # with its corresponding view. self._reset_model(self.table_level, DataFrameLevelModel(model, self.palette(), self.font())) self._reset_model(self.table_header, DataFrameHeaderModel( model, 0, self.palette())) self._reset_model(self.table_index, DataFrameHeaderModel( model, 1, self.palette())) # Needs to be called after setting all table models if relayout: self._update_layout()
python
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( self._resizeCurrentColumnToContents) # Asociate the models (level, vertical index and horizontal header) # with its corresponding view. self._reset_model(self.table_level, DataFrameLevelModel(model, self.palette(), self.font())) self._reset_model(self.table_header, DataFrameHeaderModel( model, 0, self.palette())) self._reset_model(self.table_index, DataFrameHeaderModel( model, 1, self.palette())) # Needs to be called after setting all table models if relayout: self._update_layout()
[ "def", "setModel", "(", "self", ",", "model", ",", "relayout", "=", "True", ")", ":", "self", ".", "_model", "=", "model", "sel_model", "=", "self", ".", "dataTable", ".", "selectionModel", "(", ")", "sel_model", ".", "currentColumnChanged", ".", "connect", "(", "self", ".", "_resizeCurrentColumnToContents", ")", "# Asociate the models (level, vertical index and horizontal header)\r", "# with its corresponding view.\r", "self", ".", "_reset_model", "(", "self", ".", "table_level", ",", "DataFrameLevelModel", "(", "model", ",", "self", ".", "palette", "(", ")", ",", "self", ".", "font", "(", ")", ")", ")", "self", ".", "_reset_model", "(", "self", ".", "table_header", ",", "DataFrameHeaderModel", "(", "model", ",", "0", ",", "self", ".", "palette", "(", ")", ")", ")", "self", ".", "_reset_model", "(", "self", ".", "table_index", ",", "DataFrameHeaderModel", "(", "model", ",", "1", ",", "self", ".", "palette", "(", ")", ")", ")", "# Needs to be called after setting all table models\r", "if", "relayout", ":", "self", ".", "_update_layout", "(", ")" ]
Set the model for the data, header/index and level views.
[ "Set", "the", "model", "for", "the", "data", "header", "/", "index", "and", "level", "views", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L1098-L1121
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor.setCurrentIndex
def setCurrentIndex(self, y, x): """Set current selection.""" self.dataTable.selectionModel().setCurrentIndex( self.dataTable.model().index(y, x), QItemSelectionModel.ClearAndSelect)
python
def setCurrentIndex(self, y, x): """Set current selection.""" self.dataTable.selectionModel().setCurrentIndex( self.dataTable.model().index(y, x), QItemSelectionModel.ClearAndSelect)
[ "def", "setCurrentIndex", "(", "self", ",", "y", ",", "x", ")", ":", "self", ".", "dataTable", ".", "selectionModel", "(", ")", ".", "setCurrentIndex", "(", "self", ".", "dataTable", ".", "model", "(", ")", ".", "index", "(", "y", ",", "x", ")", ",", "QItemSelectionModel", ".", "ClearAndSelect", ")" ]
Set current selection.
[ "Set", "current", "selection", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L1123-L1127
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor._resizeColumnToContents
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_trunc), min(self.max_width, data_width)) else: width = max(min(self.max_width, hdr_width), self.min_trunc) header.setColumnWidth(col, width)
python
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_trunc), min(self.max_width, data_width)) else: width = max(min(self.max_width, hdr_width), self.min_trunc) header.setColumnWidth(col, width)
[ "def", "_resizeColumnToContents", "(", "self", ",", "header", ",", "data", ",", "col", ",", "limit_ms", ")", ":", "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_trunc", ")", ",", "min", "(", "self", ".", "max_width", ",", "data_width", ")", ")", "else", ":", "width", "=", "max", "(", "min", "(", "self", ".", "max_width", ",", "hdr_width", ")", ",", "self", ".", "min_trunc", ")", "header", ".", "setColumnWidth", "(", "col", ",", "width", ")" ]
Resize a column by its contents.
[ "Resize", "a", "column", "by", "its", "contents", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L1146-L1157
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor._resizeColumnsToContents
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)
python
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)
[ "def", "_resizeColumnsToContents", "(", "self", ",", "header", ",", "data", ",", "limit_ms", ")", ":", "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", ")" ]
Resize all the colummns to its contents.
[ "Resize", "all", "the", "colummns", "to", "its", "contents", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L1159-L1167
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor.eventFilter
def eventFilter(self, obj, event): """Override eventFilter to catch resize event.""" if obj == self.dataTable and event.type() == QEvent.Resize: self._resizeVisibleColumnsToContents() return False
python
def eventFilter(self, obj, event): """Override eventFilter to catch resize event.""" if obj == self.dataTable and event.type() == QEvent.Resize: self._resizeVisibleColumnsToContents() return False
[ "def", "eventFilter", "(", "self", ",", "obj", ",", "event", ")", ":", "if", "obj", "==", "self", ".", "dataTable", "and", "event", ".", "type", "(", ")", "==", "QEvent", ".", "Resize", ":", "self", ".", "_resizeVisibleColumnsToContents", "(", ")", "return", "False" ]
Override eventFilter to catch resize event.
[ "Override", "eventFilter", "to", "catch", "resize", "event", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L1169-L1173
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor._resizeCurrentColumnToContents
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)
python
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)
[ "def", "_resizeCurrentColumnToContents", "(", "self", ",", "new_index", ",", "old_index", ")", ":", "if", "new_index", ".", "column", "(", ")", "not", "in", "self", ".", "_autosized_cols", ":", "# Ensure the requested column is fully into view after resizing\r", "self", ".", "_resizeVisibleColumnsToContents", "(", ")", "self", ".", "dataTable", ".", "scrollTo", "(", "new_index", ")" ]
Resize the current column to its contents.
[ "Resize", "the", "current", "column", "to", "its", "contents", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L1202-L1207
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor.resizeColumnsToContents
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()
python
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()
[ "def", "resizeColumnsToContents", "(", "self", ")", ":", "self", ".", "_autosized_cols", "=", "set", "(", ")", "self", ".", "_resizeColumnsToContents", "(", "self", ".", "table_level", ",", "self", ".", "table_index", ",", "self", ".", "_max_autosize_ms", ")", "self", ".", "_update_layout", "(", ")" ]
Resize the columns to its contents.
[ "Resize", "the", "columns", "to", "its", "contents", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L1209-L1214
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor.change_bgcolor_enable
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 state > 0)
python
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 state > 0)
[ "def", "change_bgcolor_enable", "(", "self", ",", "state", ")", ":", "self", ".", "dataModel", ".", "bgcolor", "(", "state", ")", "self", ".", "bgcolor_global", ".", "setEnabled", "(", "not", "self", ".", "is_series", "and", "state", ">", "0", ")" ]
This is implementet so column min/max is only active when bgcolor is
[ "This", "is", "implementet", "so", "column", "min", "/", "max", "is", "only", "active", "when", "bgcolor", "is" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L1216-L1221
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor.change_format
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_changed`. """ format, valid = QInputDialog.getText(self, _('Format'), _("Float formatting"), QLineEdit.Normal, self.dataModel.get_format()) if valid: format = str(format) try: format % 1.1 except: msg = _("Format ({}) is incorrect").format(format) QMessageBox.critical(self, _("Error"), msg) return if not format.startswith('%'): msg = _("Format ({}) should start with '%'").format(format) QMessageBox.critical(self, _("Error"), msg) return self.dataModel.set_format(format) self.sig_option_changed.emit('dataframe_format', format)
python
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_changed`. """ format, valid = QInputDialog.getText(self, _('Format'), _("Float formatting"), QLineEdit.Normal, self.dataModel.get_format()) if valid: format = str(format) try: format % 1.1 except: msg = _("Format ({}) is incorrect").format(format) QMessageBox.critical(self, _("Error"), msg) return if not format.startswith('%'): msg = _("Format ({}) should start with '%'").format(format) QMessageBox.critical(self, _("Error"), msg) return self.dataModel.set_format(format) self.sig_option_changed.emit('dataframe_format', format)
[ "def", "change_format", "(", "self", ")", ":", "format", ",", "valid", "=", "QInputDialog", ".", "getText", "(", "self", ",", "_", "(", "'Format'", ")", ",", "_", "(", "\"Float formatting\"", ")", ",", "QLineEdit", ".", "Normal", ",", "self", ".", "dataModel", ".", "get_format", "(", ")", ")", "if", "valid", ":", "format", "=", "str", "(", "format", ")", "try", ":", "format", "%", "1.1", "except", ":", "msg", "=", "_", "(", "\"Format ({}) is incorrect\"", ")", ".", "format", "(", "format", ")", "QMessageBox", ".", "critical", "(", "self", ",", "_", "(", "\"Error\"", ")", ",", "msg", ")", "return", "if", "not", "format", ".", "startswith", "(", "'%'", ")", ":", "msg", "=", "_", "(", "\"Format ({}) should start with '%'\"", ")", ".", "format", "(", "format", ")", "QMessageBox", ".", "critical", "(", "self", ",", "_", "(", "\"Error\"", ")", ",", "msg", ")", "return", "self", ".", "dataModel", ".", "set_format", "(", "format", ")", "self", ".", "sig_option_changed", ".", "emit", "(", "'dataframe_format'", ",", "format", ")" ]
Ask user for display format for floats and use it. This function also checks whether the format is valid and emits `sig_option_changed`.
[ "Ask", "user", "for", "display", "format", "for", "floats", "and", "use", "it", ".", "This", "function", "also", "checks", "whether", "the", "format", "is", "valid", "and", "emits", "sig_option_changed", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L1223-L1247
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor.get_value
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.get_data() if self.is_series: return df.iloc[:, 0] else: return df
python
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.get_data() if self.is_series: return df.iloc[:, 0] else: return df
[ "def", "get_value", "(", "self", ")", ":", "# It is import to avoid accessing Qt C++ object as it has probably\r", "# already been destroyed, due to the Qt.WA_DeleteOnClose attribute\r", "df", "=", "self", ".", "dataModel", ".", "get_data", "(", ")", "if", "self", ".", "is_series", ":", "return", "df", ".", "iloc", "[", ":", ",", "0", "]", "else", ":", "return", "df" ]
Return modified Dataframe -- this is *not* a copy
[ "Return", "modified", "Dataframe", "--", "this", "is", "*", "not", "*", "a", "copy" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L1249-L1257
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/dataframeeditor.py
DataFrameEditor._update_header_size
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: break
python
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: break
[ "def", "_update_header_size", "(", "self", ")", ":", "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", ":", "break" ]
Update the column width of the header.
[ "Update", "the", "column", "width", "of", "the", "header", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L1259-L1267
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/namespacebrowser.py
NamespaceBrowser.setup
def setup(self, check_all=None, exclude_private=None, exclude_uppercase=None, exclude_capitalized=None, exclude_unsupported=None, excluded_names=None, minmax=None, dataframe_format=None): """ Setup the namespace browser with provided settings. Args: dataframe_format (string): default floating-point format for DataFrame editor """ assert self.shellwidget is not None self.check_all = check_all self.exclude_private = exclude_private self.exclude_uppercase = exclude_uppercase self.exclude_capitalized = exclude_capitalized self.exclude_unsupported = exclude_unsupported self.excluded_names = excluded_names self.minmax = minmax self.dataframe_format = dataframe_format if self.editor is not None: self.editor.setup_menu(minmax) self.editor.set_dataframe_format(dataframe_format) self.exclude_private_action.setChecked(exclude_private) self.exclude_uppercase_action.setChecked(exclude_uppercase) self.exclude_capitalized_action.setChecked(exclude_capitalized) self.exclude_unsupported_action.setChecked(exclude_unsupported) self.refresh_table() return self.editor = RemoteCollectionsEditorTableView( self, data=None, minmax=minmax, shellwidget=self.shellwidget, dataframe_format=dataframe_format) self.editor.sig_option_changed.connect(self.sig_option_changed.emit) self.editor.sig_files_dropped.connect(self.import_data) self.editor.sig_free_memory.connect(self.sig_free_memory.emit) self.setup_option_actions(exclude_private, exclude_uppercase, exclude_capitalized, exclude_unsupported) # Setup toolbar layout. 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() # Setup layout. layout = create_plugin_layout(self.tools_layout, self.editor) self.setLayout(layout) self.sig_option_changed.connect(self.option_changed)
python
def setup(self, check_all=None, exclude_private=None, exclude_uppercase=None, exclude_capitalized=None, exclude_unsupported=None, excluded_names=None, minmax=None, dataframe_format=None): """ Setup the namespace browser with provided settings. Args: dataframe_format (string): default floating-point format for DataFrame editor """ assert self.shellwidget is not None self.check_all = check_all self.exclude_private = exclude_private self.exclude_uppercase = exclude_uppercase self.exclude_capitalized = exclude_capitalized self.exclude_unsupported = exclude_unsupported self.excluded_names = excluded_names self.minmax = minmax self.dataframe_format = dataframe_format if self.editor is not None: self.editor.setup_menu(minmax) self.editor.set_dataframe_format(dataframe_format) self.exclude_private_action.setChecked(exclude_private) self.exclude_uppercase_action.setChecked(exclude_uppercase) self.exclude_capitalized_action.setChecked(exclude_capitalized) self.exclude_unsupported_action.setChecked(exclude_unsupported) self.refresh_table() return self.editor = RemoteCollectionsEditorTableView( self, data=None, minmax=minmax, shellwidget=self.shellwidget, dataframe_format=dataframe_format) self.editor.sig_option_changed.connect(self.sig_option_changed.emit) self.editor.sig_files_dropped.connect(self.import_data) self.editor.sig_free_memory.connect(self.sig_free_memory.emit) self.setup_option_actions(exclude_private, exclude_uppercase, exclude_capitalized, exclude_unsupported) # Setup toolbar layout. 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() # Setup layout. layout = create_plugin_layout(self.tools_layout, self.editor) self.setLayout(layout) self.sig_option_changed.connect(self.option_changed)
[ "def", "setup", "(", "self", ",", "check_all", "=", "None", ",", "exclude_private", "=", "None", ",", "exclude_uppercase", "=", "None", ",", "exclude_capitalized", "=", "None", ",", "exclude_unsupported", "=", "None", ",", "excluded_names", "=", "None", ",", "minmax", "=", "None", ",", "dataframe_format", "=", "None", ")", ":", "assert", "self", ".", "shellwidget", "is", "not", "None", "self", ".", "check_all", "=", "check_all", "self", ".", "exclude_private", "=", "exclude_private", "self", ".", "exclude_uppercase", "=", "exclude_uppercase", "self", ".", "exclude_capitalized", "=", "exclude_capitalized", "self", ".", "exclude_unsupported", "=", "exclude_unsupported", "self", ".", "excluded_names", "=", "excluded_names", "self", ".", "minmax", "=", "minmax", "self", ".", "dataframe_format", "=", "dataframe_format", "if", "self", ".", "editor", "is", "not", "None", ":", "self", ".", "editor", ".", "setup_menu", "(", "minmax", ")", "self", ".", "editor", ".", "set_dataframe_format", "(", "dataframe_format", ")", "self", ".", "exclude_private_action", ".", "setChecked", "(", "exclude_private", ")", "self", ".", "exclude_uppercase_action", ".", "setChecked", "(", "exclude_uppercase", ")", "self", ".", "exclude_capitalized_action", ".", "setChecked", "(", "exclude_capitalized", ")", "self", ".", "exclude_unsupported_action", ".", "setChecked", "(", "exclude_unsupported", ")", "self", ".", "refresh_table", "(", ")", "return", "self", ".", "editor", "=", "RemoteCollectionsEditorTableView", "(", "self", ",", "data", "=", "None", ",", "minmax", "=", "minmax", ",", "shellwidget", "=", "self", ".", "shellwidget", ",", "dataframe_format", "=", "dataframe_format", ")", "self", ".", "editor", ".", "sig_option_changed", ".", "connect", "(", "self", ".", "sig_option_changed", ".", "emit", ")", "self", ".", "editor", ".", "sig_files_dropped", ".", "connect", "(", "self", ".", "import_data", ")", "self", ".", "editor", ".", "sig_free_memory", ".", "connect", "(", "self", ".", "sig_free_memory", ".", "emit", ")", "self", ".", "setup_option_actions", "(", "exclude_private", ",", "exclude_uppercase", ",", "exclude_capitalized", ",", "exclude_unsupported", ")", "# Setup toolbar layout.\r", "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", "(", ")", "# Setup layout.\r", "layout", "=", "create_plugin_layout", "(", "self", ".", "tools_layout", ",", "self", ".", "editor", ")", "self", ".", "setLayout", "(", "layout", ")", "self", ".", "sig_option_changed", ".", "connect", "(", "self", ".", "option_changed", ")" ]
Setup the namespace browser with provided settings. Args: dataframe_format (string): default floating-point format for DataFrame editor
[ "Setup", "the", "namespace", "browser", "with", "provided", "settings", ".", "Args", ":", "dataframe_format", "(", "string", ")", ":", "default", "floating", "-", "point", "format", "for", "DataFrame", "editor" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/namespacebrowser.py#L82-L142
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/namespacebrowser.py
NamespaceBrowser.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 = create_toolbutton(self, text=_("Save data"), icon=ima.icon('filesave'), triggered=lambda: self.save_data(self.filename)) self.save_button.setEnabled(False) save_as_button = create_toolbutton(self, text=_("Save data as..."), icon=ima.icon('filesaveas'), triggered=self.save_data) reset_namespace_button = create_toolbutton( self, text=_("Remove all variables"), icon=ima.icon('editdelete'), triggered=self.reset_namespace) return [load_button, self.save_button, save_as_button, reset_namespace_button]
python
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 = create_toolbutton(self, text=_("Save data"), icon=ima.icon('filesave'), triggered=lambda: self.save_data(self.filename)) self.save_button.setEnabled(False) save_as_button = create_toolbutton(self, text=_("Save data as..."), icon=ima.icon('filesaveas'), triggered=self.save_data) reset_namespace_button = create_toolbutton( self, text=_("Remove all variables"), icon=ima.icon('editdelete'), triggered=self.reset_namespace) return [load_button, self.save_button, save_as_button, reset_namespace_button]
[ "def", "setup_toolbar", "(", "self", ")", ":", "load_button", "=", "create_toolbutton", "(", "self", ",", "text", "=", "_", "(", "'Import data'", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'fileimport'", ")", ",", "triggered", "=", "lambda", ":", "self", ".", "import_data", "(", ")", ")", "self", ".", "save_button", "=", "create_toolbutton", "(", "self", ",", "text", "=", "_", "(", "\"Save data\"", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'filesave'", ")", ",", "triggered", "=", "lambda", ":", "self", ".", "save_data", "(", "self", ".", "filename", ")", ")", "self", ".", "save_button", ".", "setEnabled", "(", "False", ")", "save_as_button", "=", "create_toolbutton", "(", "self", ",", "text", "=", "_", "(", "\"Save data as...\"", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'filesaveas'", ")", ",", "triggered", "=", "self", ".", "save_data", ")", "reset_namespace_button", "=", "create_toolbutton", "(", "self", ",", "text", "=", "_", "(", "\"Remove all variables\"", ")", ",", "icon", "=", "ima", ".", "icon", "(", "'editdelete'", ")", ",", "triggered", "=", "self", ".", "reset_namespace", ")", "return", "[", "load_button", ",", "self", ".", "save_button", ",", "save_as_button", ",", "reset_namespace_button", "]" ]
Setup toolbar
[ "Setup", "toolbar" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/namespacebrowser.py#L153-L171
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/namespacebrowser.py
NamespaceBrowser.setup_option_actions
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 = create_action(self, _("Exclude private references"), tip=_("Exclude references which name starts" " with an underscore"), toggled=lambda state: self.sig_option_changed.emit('exclude_private', state)) self.exclude_private_action.setChecked(exclude_private) self.exclude_uppercase_action = create_action(self, _("Exclude all-uppercase references"), tip=_("Exclude references which name is uppercase"), toggled=lambda state: self.sig_option_changed.emit('exclude_uppercase', state)) self.exclude_uppercase_action.setChecked(exclude_uppercase) self.exclude_capitalized_action = create_action(self, _("Exclude capitalized references"), tip=_("Exclude references which name starts with an " "uppercase character"), toggled=lambda state: self.sig_option_changed.emit('exclude_capitalized', state)) self.exclude_capitalized_action.setChecked(exclude_capitalized) self.exclude_unsupported_action = create_action(self, _("Exclude unsupported data types"), tip=_("Exclude references to unsupported data types" " (i.e. which won't be handled/saved correctly)"), toggled=lambda state: self.sig_option_changed.emit('exclude_unsupported', state)) self.exclude_unsupported_action.setChecked(exclude_unsupported) self.actions = [ self.exclude_private_action, self.exclude_uppercase_action, self.exclude_capitalized_action, self.exclude_unsupported_action] if is_module_installed('numpy'): self.actions.extend([MENU_SEPARATOR, self.editor.minmax_action]) self.setup_in_progress = False
python
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 = create_action(self, _("Exclude private references"), tip=_("Exclude references which name starts" " with an underscore"), toggled=lambda state: self.sig_option_changed.emit('exclude_private', state)) self.exclude_private_action.setChecked(exclude_private) self.exclude_uppercase_action = create_action(self, _("Exclude all-uppercase references"), tip=_("Exclude references which name is uppercase"), toggled=lambda state: self.sig_option_changed.emit('exclude_uppercase', state)) self.exclude_uppercase_action.setChecked(exclude_uppercase) self.exclude_capitalized_action = create_action(self, _("Exclude capitalized references"), tip=_("Exclude references which name starts with an " "uppercase character"), toggled=lambda state: self.sig_option_changed.emit('exclude_capitalized', state)) self.exclude_capitalized_action.setChecked(exclude_capitalized) self.exclude_unsupported_action = create_action(self, _("Exclude unsupported data types"), tip=_("Exclude references to unsupported data types" " (i.e. which won't be handled/saved correctly)"), toggled=lambda state: self.sig_option_changed.emit('exclude_unsupported', state)) self.exclude_unsupported_action.setChecked(exclude_unsupported) self.actions = [ self.exclude_private_action, self.exclude_uppercase_action, self.exclude_capitalized_action, self.exclude_unsupported_action] if is_module_installed('numpy'): self.actions.extend([MENU_SEPARATOR, self.editor.minmax_action]) self.setup_in_progress = False
[ "def", "setup_option_actions", "(", "self", ",", "exclude_private", ",", "exclude_uppercase", ",", "exclude_capitalized", ",", "exclude_unsupported", ")", ":", "self", ".", "setup_in_progress", "=", "True", "self", ".", "exclude_private_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Exclude private references\"", ")", ",", "tip", "=", "_", "(", "\"Exclude references which name starts\"", "\" with an underscore\"", ")", ",", "toggled", "=", "lambda", "state", ":", "self", ".", "sig_option_changed", ".", "emit", "(", "'exclude_private'", ",", "state", ")", ")", "self", ".", "exclude_private_action", ".", "setChecked", "(", "exclude_private", ")", "self", ".", "exclude_uppercase_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Exclude all-uppercase references\"", ")", ",", "tip", "=", "_", "(", "\"Exclude references which name is uppercase\"", ")", ",", "toggled", "=", "lambda", "state", ":", "self", ".", "sig_option_changed", ".", "emit", "(", "'exclude_uppercase'", ",", "state", ")", ")", "self", ".", "exclude_uppercase_action", ".", "setChecked", "(", "exclude_uppercase", ")", "self", ".", "exclude_capitalized_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Exclude capitalized references\"", ")", ",", "tip", "=", "_", "(", "\"Exclude references which name starts with an \"", "\"uppercase character\"", ")", ",", "toggled", "=", "lambda", "state", ":", "self", ".", "sig_option_changed", ".", "emit", "(", "'exclude_capitalized'", ",", "state", ")", ")", "self", ".", "exclude_capitalized_action", ".", "setChecked", "(", "exclude_capitalized", ")", "self", ".", "exclude_unsupported_action", "=", "create_action", "(", "self", ",", "_", "(", "\"Exclude unsupported data types\"", ")", ",", "tip", "=", "_", "(", "\"Exclude references to unsupported data types\"", "\" (i.e. which won't be handled/saved correctly)\"", ")", ",", "toggled", "=", "lambda", "state", ":", "self", ".", "sig_option_changed", ".", "emit", "(", "'exclude_unsupported'", ",", "state", ")", ")", "self", ".", "exclude_unsupported_action", ".", "setChecked", "(", "exclude_unsupported", ")", "self", ".", "actions", "=", "[", "self", ".", "exclude_private_action", ",", "self", ".", "exclude_uppercase_action", ",", "self", ".", "exclude_capitalized_action", ",", "self", ".", "exclude_unsupported_action", "]", "if", "is_module_installed", "(", "'numpy'", ")", ":", "self", ".", "actions", ".", "extend", "(", "[", "MENU_SEPARATOR", ",", "self", ".", "editor", ".", "minmax_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/variableexplorer/widgets/namespacebrowser.py#L173-L215
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/namespacebrowser.py
NamespaceBrowser.setup_options_button
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.options_menu, actions) self.options_button.setMenu(self.options_menu) if self.tools_layout.itemAt(self.tools_layout.count() - 1) is None: self.tools_layout.insertWidget( self.tools_layout.count() - 1, self.options_button) else: self.tools_layout.addWidget(self.options_button)
python
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.options_menu, actions) self.options_button.setMenu(self.options_menu) if self.tools_layout.itemAt(self.tools_layout.count() - 1) is None: self.tools_layout.insertWidget( self.tools_layout.count() - 1, self.options_button) else: self.tools_layout.addWidget(self.options_button)
[ "def", "setup_options_button", "(", "self", ")", ":", "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", ".", "options_menu", ",", "actions", ")", "self", ".", "options_button", ".", "setMenu", "(", "self", ".", "options_menu", ")", "if", "self", ".", "tools_layout", ".", "itemAt", "(", "self", ".", "tools_layout", ".", "count", "(", ")", "-", "1", ")", "is", "None", ":", "self", ".", "tools_layout", ".", "insertWidget", "(", "self", ".", "tools_layout", ".", "count", "(", ")", "-", "1", ",", "self", ".", "options_button", ")", "else", ":", "self", ".", "tools_layout", ".", "addWidget", "(", "self", ".", "options_button", ")" ]
Add the cog menu button to the toolbar.
[ "Add", "the", "cog", "menu", "button", "to", "the", "toolbar", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/namespacebrowser.py#L217-L232
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/namespacebrowser.py
NamespaceBrowser.option_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()
python
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()
[ "def", "option_changed", "(", "self", ",", "option", ",", "value", ")", ":", "setattr", "(", "self", ",", "to_text_string", "(", "option", ")", ",", "value", ")", "self", ".", "shellwidget", ".", "set_namespace_view_settings", "(", ")", "self", ".", "refresh_table", "(", ")" ]
Option has changed
[ "Option", "has", "changed" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/namespacebrowser.py#L234-L238
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/namespacebrowser.py
NamespaceBrowser.get_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
python
def get_view_settings(self): """Return dict editor view settings""" settings = {} for name in REMOTE_SETTINGS: settings[name] = getattr(self, name) return settings
[ "def", "get_view_settings", "(", "self", ")", ":", "settings", "=", "{", "}", "for", "name", "in", "REMOTE_SETTINGS", ":", "settings", "[", "name", "]", "=", "getattr", "(", "self", ",", "name", ")", "return", "settings" ]
Return dict editor view settings
[ "Return", "dict", "editor", "view", "settings" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/namespacebrowser.py#L240-L245
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/namespacebrowser.py
NamespaceBrowser.refresh_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
python
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
[ "def", "refresh_table", "(", "self", ")", ":", "if", "self", ".", "is_visible", "and", "self", ".", "isVisible", "(", ")", ":", "self", ".", "shellwidget", ".", "refresh_namespacebrowser", "(", ")", "try", ":", "self", ".", "editor", ".", "resizeRowToContents", "(", ")", "except", "TypeError", ":", "pass" ]
Refresh variable table
[ "Refresh", "variable", "table" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/namespacebrowser.py#L247-L254
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/namespacebrowser.py
NamespaceBrowser.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()
python
def set_data(self, data): """Set data.""" if data != self.editor.model.get_data(): self.editor.set_data(data) self.editor.adjust_columns()
[ "def", "set_data", "(", "self", ",", "data", ")", ":", "if", "data", "!=", "self", ".", "editor", ".", "model", ".", "get_data", "(", ")", ":", "self", ".", "editor", ".", "set_data", "(", "data", ")", "self", ".", "editor", ".", "adjust_columns", "(", ")" ]
Set data.
[ "Set", "data", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/namespacebrowser.py#L266-L270
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/namespacebrowser.py
NamespaceBrowser.import_data
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, iofunctions.load_filters) if not filenames: return elif is_text_string(filenames): filenames = [filenames] for filename in filenames: self.filename = to_text_string(filename) ext = osp.splitext(self.filename)[1].lower() if ext not in iofunctions.load_funcs: buttons = QMessageBox.Yes | QMessageBox.Cancel answer = QMessageBox.question(self, title, _("<b>Unsupported file extension '%s'</b><br><br>" "Would you like to import it anyway " "(by selecting a known file format)?" ) % ext, buttons) if answer == QMessageBox.Cancel: return formats = list(iofunctions.load_extensions.keys()) item, ok = QInputDialog.getItem(self, title, _('Open file as:'), formats, 0, False) if ok: ext = iofunctions.load_extensions[to_text_string(item)] else: return load_func = iofunctions.load_funcs[ext] # 'import_wizard' (self.setup_io) if is_text_string(load_func): # Import data with import wizard error_message = None try: text, _encoding = encoding.read(self.filename) base_name = osp.basename(self.filename) editor = ImportWizard(self, text, title=base_name, varname=fix_reference_name(base_name)) if editor.exec_(): var_name, clip_data = editor.get_data() self.editor.new_value(var_name, clip_data) except Exception as error: error_message = str(error) else: QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents() error_message = self.shellwidget.load_data(self.filename, ext) self.shellwidget._kernel_reply = None QApplication.restoreOverrideCursor() QApplication.processEvents() if error_message is not None: QMessageBox.critical(self, title, _("<b>Unable to load '%s'</b>" "<br><br>Error message:<br>%s" ) % (self.filename, error_message)) self.refresh_table()
python
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, iofunctions.load_filters) if not filenames: return elif is_text_string(filenames): filenames = [filenames] for filename in filenames: self.filename = to_text_string(filename) ext = osp.splitext(self.filename)[1].lower() if ext not in iofunctions.load_funcs: buttons = QMessageBox.Yes | QMessageBox.Cancel answer = QMessageBox.question(self, title, _("<b>Unsupported file extension '%s'</b><br><br>" "Would you like to import it anyway " "(by selecting a known file format)?" ) % ext, buttons) if answer == QMessageBox.Cancel: return formats = list(iofunctions.load_extensions.keys()) item, ok = QInputDialog.getItem(self, title, _('Open file as:'), formats, 0, False) if ok: ext = iofunctions.load_extensions[to_text_string(item)] else: return load_func = iofunctions.load_funcs[ext] # 'import_wizard' (self.setup_io) if is_text_string(load_func): # Import data with import wizard error_message = None try: text, _encoding = encoding.read(self.filename) base_name = osp.basename(self.filename) editor = ImportWizard(self, text, title=base_name, varname=fix_reference_name(base_name)) if editor.exec_(): var_name, clip_data = editor.get_data() self.editor.new_value(var_name, clip_data) except Exception as error: error_message = str(error) else: QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents() error_message = self.shellwidget.load_data(self.filename, ext) self.shellwidget._kernel_reply = None QApplication.restoreOverrideCursor() QApplication.processEvents() if error_message is not None: QMessageBox.critical(self, title, _("<b>Unable to load '%s'</b>" "<br><br>Error message:<br>%s" ) % (self.filename, error_message)) self.refresh_table()
[ "def", "import_data", "(", "self", ",", "filenames", "=", "None", ")", ":", "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", ",", "iofunctions", ".", "load_filters", ")", "if", "not", "filenames", ":", "return", "elif", "is_text_string", "(", "filenames", ")", ":", "filenames", "=", "[", "filenames", "]", "for", "filename", "in", "filenames", ":", "self", ".", "filename", "=", "to_text_string", "(", "filename", ")", "ext", "=", "osp", ".", "splitext", "(", "self", ".", "filename", ")", "[", "1", "]", ".", "lower", "(", ")", "if", "ext", "not", "in", "iofunctions", ".", "load_funcs", ":", "buttons", "=", "QMessageBox", ".", "Yes", "|", "QMessageBox", ".", "Cancel", "answer", "=", "QMessageBox", ".", "question", "(", "self", ",", "title", ",", "_", "(", "\"<b>Unsupported file extension '%s'</b><br><br>\"", "\"Would you like to import it anyway \"", "\"(by selecting a known file format)?\"", ")", "%", "ext", ",", "buttons", ")", "if", "answer", "==", "QMessageBox", ".", "Cancel", ":", "return", "formats", "=", "list", "(", "iofunctions", ".", "load_extensions", ".", "keys", "(", ")", ")", "item", ",", "ok", "=", "QInputDialog", ".", "getItem", "(", "self", ",", "title", ",", "_", "(", "'Open file as:'", ")", ",", "formats", ",", "0", ",", "False", ")", "if", "ok", ":", "ext", "=", "iofunctions", ".", "load_extensions", "[", "to_text_string", "(", "item", ")", "]", "else", ":", "return", "load_func", "=", "iofunctions", ".", "load_funcs", "[", "ext", "]", "# 'import_wizard' (self.setup_io)\r", "if", "is_text_string", "(", "load_func", ")", ":", "# Import data with import wizard\r", "error_message", "=", "None", "try", ":", "text", ",", "_encoding", "=", "encoding", ".", "read", "(", "self", ".", "filename", ")", "base_name", "=", "osp", ".", "basename", "(", "self", ".", "filename", ")", "editor", "=", "ImportWizard", "(", "self", ",", "text", ",", "title", "=", "base_name", ",", "varname", "=", "fix_reference_name", "(", "base_name", ")", ")", "if", "editor", ".", "exec_", "(", ")", ":", "var_name", ",", "clip_data", "=", "editor", ".", "get_data", "(", ")", "self", ".", "editor", ".", "new_value", "(", "var_name", ",", "clip_data", ")", "except", "Exception", "as", "error", ":", "error_message", "=", "str", "(", "error", ")", "else", ":", "QApplication", ".", "setOverrideCursor", "(", "QCursor", "(", "Qt", ".", "WaitCursor", ")", ")", "QApplication", ".", "processEvents", "(", ")", "error_message", "=", "self", ".", "shellwidget", ".", "load_data", "(", "self", ".", "filename", ",", "ext", ")", "self", ".", "shellwidget", ".", "_kernel_reply", "=", "None", "QApplication", ".", "restoreOverrideCursor", "(", ")", "QApplication", ".", "processEvents", "(", ")", "if", "error_message", "is", "not", "None", ":", "QMessageBox", ".", "critical", "(", "self", ",", "title", ",", "_", "(", "\"<b>Unable to load '%s'</b>\"", "\"<br><br>Error message:<br>%s\"", ")", "%", "(", "self", ".", "filename", ",", "error_message", ")", ")", "self", ".", "refresh_table", "(", ")" ]
Import data from text file.
[ "Import", "data", "from", "text", "file", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/namespacebrowser.py#L278-L344
train
spyder-ide/spyder
spyder/plugins/variableexplorer/widgets/namespacebrowser.py
NamespaceBrowser.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"), filename, iofunctions.save_filters) if filename: self.filename = filename else: return False QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents() error_message = self.shellwidget.save_namespace(self.filename) self.shellwidget._kernel_reply = None QApplication.restoreOverrideCursor() QApplication.processEvents() if error_message is not None: if 'Some objects could not be saved:' in error_message: save_data_message = ( _('<b>Some objects could not be saved:</b>') + '<br><br><code>{obj_list}</code>'.format( obj_list=error_message.split(': ')[1])) else: save_data_message = _( '<b>Unable to save current workspace</b>' '<br><br>Error message:<br>') + error_message QMessageBox.critical(self, _("Save data"), save_data_message) self.save_button.setEnabled(self.filename is not None)
python
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"), filename, iofunctions.save_filters) if filename: self.filename = filename else: return False QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents() error_message = self.shellwidget.save_namespace(self.filename) self.shellwidget._kernel_reply = None QApplication.restoreOverrideCursor() QApplication.processEvents() if error_message is not None: if 'Some objects could not be saved:' in error_message: save_data_message = ( _('<b>Some objects could not be saved:</b>') + '<br><br><code>{obj_list}</code>'.format( obj_list=error_message.split(': ')[1])) else: save_data_message = _( '<b>Unable to save current workspace</b>' '<br><br>Error message:<br>') + error_message QMessageBox.critical(self, _("Save data"), save_data_message) self.save_button.setEnabled(self.filename is not None)
[ "def", "save_data", "(", "self", ",", "filename", "=", "None", ")", ":", "if", "filename", "is", "None", ":", "filename", "=", "self", ".", "filename", "if", "filename", "is", "None", ":", "filename", "=", "getcwd_or_home", "(", ")", "filename", ",", "_selfilter", "=", "getsavefilename", "(", "self", ",", "_", "(", "\"Save data\"", ")", ",", "filename", ",", "iofunctions", ".", "save_filters", ")", "if", "filename", ":", "self", ".", "filename", "=", "filename", "else", ":", "return", "False", "QApplication", ".", "setOverrideCursor", "(", "QCursor", "(", "Qt", ".", "WaitCursor", ")", ")", "QApplication", ".", "processEvents", "(", ")", "error_message", "=", "self", ".", "shellwidget", ".", "save_namespace", "(", "self", ".", "filename", ")", "self", ".", "shellwidget", ".", "_kernel_reply", "=", "None", "QApplication", ".", "restoreOverrideCursor", "(", ")", "QApplication", ".", "processEvents", "(", ")", "if", "error_message", "is", "not", "None", ":", "if", "'Some objects could not be saved:'", "in", "error_message", ":", "save_data_message", "=", "(", "_", "(", "'<b>Some objects could not be saved:</b>'", ")", "+", "'<br><br><code>{obj_list}</code>'", ".", "format", "(", "obj_list", "=", "error_message", ".", "split", "(", "': '", ")", "[", "1", "]", ")", ")", "else", ":", "save_data_message", "=", "_", "(", "'<b>Unable to save current workspace</b>'", "'<br><br>Error message:<br>'", ")", "+", "error_message", "QMessageBox", ".", "critical", "(", "self", ",", "_", "(", "\"Save data\"", ")", ",", "save_data_message", ")", "self", ".", "save_button", ".", "setEnabled", "(", "self", ".", "filename", "is", "not", "None", ")" ]
Save data
[ "Save", "data" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/variableexplorer/widgets/namespacebrowser.py#L353-L385
train
spyder-ide/spyder
spyder/preferences/configdialog.py
ConfigPage.apply_changes
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 # ensure that when changes are applied, they are copied to a # specific file storing the language value. This only applies to # the main section config. if self.CONF_SECTION == u'main': self._save_lang() for restart_option in self.restart_options: if restart_option in self.changed_options: self.prompt_restart_required() break # Ensure a single popup is displayed self.set_modified(False)
python
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 # ensure that when changes are applied, they are copied to a # specific file storing the language value. This only applies to # the main section config. if self.CONF_SECTION == u'main': self._save_lang() for restart_option in self.restart_options: if restart_option in self.changed_options: self.prompt_restart_required() break # Ensure a single popup is displayed self.set_modified(False)
[ "def", "apply_changes", "(", "self", ")", ":", "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\r", "# is needed before loading CONF, this is an extra method needed to\r", "# ensure that when changes are applied, they are copied to a\r", "# specific file storing the language value. This only applies to\r", "# the main section config.\r", "if", "self", ".", "CONF_SECTION", "==", "u'main'", ":", "self", ".", "_save_lang", "(", ")", "for", "restart_option", "in", "self", ".", "restart_options", ":", "if", "restart_option", "in", "self", ".", "changed_options", ":", "self", ".", "prompt_restart_required", "(", ")", "break", "# Ensure a single popup is displayed\r", "self", ".", "set_modified", "(", "False", ")" ]
Apply changes callback
[ "Apply", "changes", "callback" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/configdialog.py#L92-L111
train
spyder-ide/spyder
spyder/preferences/configdialog.py
ConfigDialog.get_page
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()
python
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()
[ "def", "get_page", "(", "self", ",", "index", "=", "None", ")", ":", "if", "index", "is", "None", ":", "widget", "=", "self", ".", "pages_widget", ".", "currentWidget", "(", ")", "else", ":", "widget", "=", "self", ".", "pages_widget", ".", "widget", "(", "index", ")", "return", "widget", ".", "widget", "(", ")" ]
Return page widget
[ "Return", "page", "widget" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/configdialog.py#L197-L203
train
spyder-ide/spyder
spyder/preferences/configdialog.py
ConfigDialog.accept
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)
python
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)
[ "def", "accept", "(", "self", ")", ":", "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
[ "Reimplement", "Qt", "method" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/configdialog.py#L206-L213
train
spyder-ide/spyder
spyder/preferences/configdialog.py
ConfigDialog.resizeEvent
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())
python
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())
[ "def", "resizeEvent", "(", "self", ",", "event", ")", ":", "QDialog", ".", "resizeEvent", "(", "self", ",", "event", ")", "self", ".", "size_change", ".", "emit", "(", "self", ".", "size", "(", ")", ")" ]
Reimplement Qt method to be able to save the widget's size from the main application
[ "Reimplement", "Qt", "method", "to", "be", "able", "to", "save", "the", "widget", "s", "size", "from", "the", "main", "application" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/configdialog.py#L251-L257
train
spyder-ide/spyder
spyder/preferences/configdialog.py
SpyderConfigPage.is_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] text = to_text_string(lineedit.text()) if not validator(text): QMessageBox.critical(self, self.get_name(), "%s:<br><b>%s</b>" % (invalid_msg, text), QMessageBox.Ok) return False return True
python
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.critical(self, self.get_name(), "%s:<br><b>%s</b>" % (invalid_msg, text), QMessageBox.Ok) return False return True
[ "def", "is_valid", "(", "self", ")", ":", "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", ".", "critical", "(", "self", ",", "self", ".", "get_name", "(", ")", ",", "\"%s:<br><b>%s</b>\"", "%", "(", "invalid_msg", ",", "text", ")", ",", "QMessageBox", ".", "Ok", ")", "return", "False", "return", "True" ]
Return True if all widget contents are valid
[ "Return", "True", "if", "all", "widget", "contents", "are", "valid" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/configdialog.py#L295-L306
train
spyder-ide/spyder
spyder/preferences/configdialog.py
SpyderConfigPage.load_from_conf
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 and PyQt if not API == 'pyside': checkbox.clicked.connect(lambda _foo, opt=option: self.has_been_modified(opt)) else: checkbox.clicked.connect(lambda opt=option: self.has_been_modified(opt)) for radiobutton, (option, default) in list(self.radiobuttons.items()): radiobutton.setChecked(self.get_option(option, default)) radiobutton.toggled.connect(lambda _foo, opt=option: self.has_been_modified(opt)) if radiobutton.restart_required: self.restart_options[option] = radiobutton.label_text for lineedit, (option, default) in list(self.lineedits.items()): lineedit.setText(self.get_option(option, default)) lineedit.textChanged.connect(lambda _foo, opt=option: self.has_been_modified(opt)) if lineedit.restart_required: self.restart_options[option] = lineedit.label_text for textedit, (option, default) in list(self.textedits.items()): textedit.setPlainText(self.get_option(option, default)) textedit.textChanged.connect(lambda opt=option: self.has_been_modified(opt)) if textedit.restart_required: self.restart_options[option] = textedit.label_text for spinbox, (option, default) in list(self.spinboxes.items()): spinbox.setValue(self.get_option(option, default)) spinbox.valueChanged.connect(lambda _foo, opt=option: self.has_been_modified(opt)) for combobox, (option, default) in list(self.comboboxes.items()): value = self.get_option(option, default) for index in range(combobox.count()): data = from_qvariant(combobox.itemData(index), to_text_string) # For PyQt API v2, it is necessary to convert `data` to # unicode in case the original type was not a string, like an # integer for example (see qtpy.compat.from_qvariant): if to_text_string(data) == to_text_string(value): break else: if combobox.count() == 0: index = None if index: combobox.setCurrentIndex(index) combobox.currentIndexChanged.connect(lambda _foo, opt=option: self.has_been_modified(opt)) if combobox.restart_required: self.restart_options[option] = combobox.label_text for (fontbox, sizebox), option in list(self.fontboxes.items()): font = self.get_font(option) fontbox.setCurrentFont(font) sizebox.setValue(font.pointSize()) if option is None: property = 'plugin_font' else: property = option fontbox.currentIndexChanged.connect(lambda _foo, opt=property: self.has_been_modified(opt)) sizebox.valueChanged.connect(lambda _foo, opt=property: self.has_been_modified(opt)) for clayout, (option, default) in list(self.coloredits.items()): property = to_qvariant(option) edit = clayout.lineedit btn = clayout.colorbtn edit.setText(self.get_option(option, default)) # QAbstractButton works differently for PySide and PyQt if not API == 'pyside': btn.clicked.connect(lambda _foo, opt=option: self.has_been_modified(opt)) else: btn.clicked.connect(lambda opt=option: self.has_been_modified(opt)) edit.textChanged.connect(lambda _foo, opt=option: self.has_been_modified(opt)) for (clayout, cb_bold, cb_italic ), (option, default) in list(self.scedits.items()): edit = clayout.lineedit btn = clayout.colorbtn color, bold, italic = self.get_option(option, default) edit.setText(color) cb_bold.setChecked(bold) cb_italic.setChecked(italic) edit.textChanged.connect(lambda _foo, opt=option: self.has_been_modified(opt)) # QAbstractButton works differently for PySide and PyQt if not API == 'pyside': btn.clicked.connect(lambda _foo, opt=option: self.has_been_modified(opt)) cb_bold.clicked.connect(lambda _foo, opt=option: self.has_been_modified(opt)) cb_italic.clicked.connect(lambda _foo, opt=option: self.has_been_modified(opt)) else: btn.clicked.connect(lambda opt=option: self.has_been_modified(opt)) cb_bold.clicked.connect(lambda opt=option: self.has_been_modified(opt)) cb_italic.clicked.connect(lambda opt=option: self.has_been_modified(opt))
python
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 and PyQt if not API == 'pyside': checkbox.clicked.connect(lambda _foo, opt=option: self.has_been_modified(opt)) else: checkbox.clicked.connect(lambda opt=option: self.has_been_modified(opt)) for radiobutton, (option, default) in list(self.radiobuttons.items()): radiobutton.setChecked(self.get_option(option, default)) radiobutton.toggled.connect(lambda _foo, opt=option: self.has_been_modified(opt)) if radiobutton.restart_required: self.restart_options[option] = radiobutton.label_text for lineedit, (option, default) in list(self.lineedits.items()): lineedit.setText(self.get_option(option, default)) lineedit.textChanged.connect(lambda _foo, opt=option: self.has_been_modified(opt)) if lineedit.restart_required: self.restart_options[option] = lineedit.label_text for textedit, (option, default) in list(self.textedits.items()): textedit.setPlainText(self.get_option(option, default)) textedit.textChanged.connect(lambda opt=option: self.has_been_modified(opt)) if textedit.restart_required: self.restart_options[option] = textedit.label_text for spinbox, (option, default) in list(self.spinboxes.items()): spinbox.setValue(self.get_option(option, default)) spinbox.valueChanged.connect(lambda _foo, opt=option: self.has_been_modified(opt)) for combobox, (option, default) in list(self.comboboxes.items()): value = self.get_option(option, default) for index in range(combobox.count()): data = from_qvariant(combobox.itemData(index), to_text_string) # For PyQt API v2, it is necessary to convert `data` to # unicode in case the original type was not a string, like an # integer for example (see qtpy.compat.from_qvariant): if to_text_string(data) == to_text_string(value): break else: if combobox.count() == 0: index = None if index: combobox.setCurrentIndex(index) combobox.currentIndexChanged.connect(lambda _foo, opt=option: self.has_been_modified(opt)) if combobox.restart_required: self.restart_options[option] = combobox.label_text for (fontbox, sizebox), option in list(self.fontboxes.items()): font = self.get_font(option) fontbox.setCurrentFont(font) sizebox.setValue(font.pointSize()) if option is None: property = 'plugin_font' else: property = option fontbox.currentIndexChanged.connect(lambda _foo, opt=property: self.has_been_modified(opt)) sizebox.valueChanged.connect(lambda _foo, opt=property: self.has_been_modified(opt)) for clayout, (option, default) in list(self.coloredits.items()): property = to_qvariant(option) edit = clayout.lineedit btn = clayout.colorbtn edit.setText(self.get_option(option, default)) # QAbstractButton works differently for PySide and PyQt if not API == 'pyside': btn.clicked.connect(lambda _foo, opt=option: self.has_been_modified(opt)) else: btn.clicked.connect(lambda opt=option: self.has_been_modified(opt)) edit.textChanged.connect(lambda _foo, opt=option: self.has_been_modified(opt)) for (clayout, cb_bold, cb_italic ), (option, default) in list(self.scedits.items()): edit = clayout.lineedit btn = clayout.colorbtn color, bold, italic = self.get_option(option, default) edit.setText(color) cb_bold.setChecked(bold) cb_italic.setChecked(italic) edit.textChanged.connect(lambda _foo, opt=option: self.has_been_modified(opt)) # QAbstractButton works differently for PySide and PyQt if not API == 'pyside': btn.clicked.connect(lambda _foo, opt=option: self.has_been_modified(opt)) cb_bold.clicked.connect(lambda _foo, opt=option: self.has_been_modified(opt)) cb_italic.clicked.connect(lambda _foo, opt=option: self.has_been_modified(opt)) else: btn.clicked.connect(lambda opt=option: self.has_been_modified(opt)) cb_bold.clicked.connect(lambda opt=option: self.has_been_modified(opt)) cb_italic.clicked.connect(lambda opt=option: self.has_been_modified(opt))
[ "def", "load_from_conf", "(", "self", ")", ":", "for", "checkbox", ",", "(", "option", ",", "default", ")", "in", "list", "(", "self", ".", "checkboxes", ".", "items", "(", ")", ")", ":", "checkbox", ".", "setChecked", "(", "self", ".", "get_option", "(", "option", ",", "default", ")", ")", "# QAbstractButton works differently for PySide and PyQt\r", "if", "not", "API", "==", "'pyside'", ":", "checkbox", ".", "clicked", ".", "connect", "(", "lambda", "_foo", ",", "opt", "=", "option", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")", "else", ":", "checkbox", ".", "clicked", ".", "connect", "(", "lambda", "opt", "=", "option", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")", "for", "radiobutton", ",", "(", "option", ",", "default", ")", "in", "list", "(", "self", ".", "radiobuttons", ".", "items", "(", ")", ")", ":", "radiobutton", ".", "setChecked", "(", "self", ".", "get_option", "(", "option", ",", "default", ")", ")", "radiobutton", ".", "toggled", ".", "connect", "(", "lambda", "_foo", ",", "opt", "=", "option", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")", "if", "radiobutton", ".", "restart_required", ":", "self", ".", "restart_options", "[", "option", "]", "=", "radiobutton", ".", "label_text", "for", "lineedit", ",", "(", "option", ",", "default", ")", "in", "list", "(", "self", ".", "lineedits", ".", "items", "(", ")", ")", ":", "lineedit", ".", "setText", "(", "self", ".", "get_option", "(", "option", ",", "default", ")", ")", "lineedit", ".", "textChanged", ".", "connect", "(", "lambda", "_foo", ",", "opt", "=", "option", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")", "if", "lineedit", ".", "restart_required", ":", "self", ".", "restart_options", "[", "option", "]", "=", "lineedit", ".", "label_text", "for", "textedit", ",", "(", "option", ",", "default", ")", "in", "list", "(", "self", ".", "textedits", ".", "items", "(", ")", ")", ":", "textedit", ".", "setPlainText", "(", "self", ".", "get_option", "(", "option", ",", "default", ")", ")", "textedit", ".", "textChanged", ".", "connect", "(", "lambda", "opt", "=", "option", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")", "if", "textedit", ".", "restart_required", ":", "self", ".", "restart_options", "[", "option", "]", "=", "textedit", ".", "label_text", "for", "spinbox", ",", "(", "option", ",", "default", ")", "in", "list", "(", "self", ".", "spinboxes", ".", "items", "(", ")", ")", ":", "spinbox", ".", "setValue", "(", "self", ".", "get_option", "(", "option", ",", "default", ")", ")", "spinbox", ".", "valueChanged", ".", "connect", "(", "lambda", "_foo", ",", "opt", "=", "option", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")", "for", "combobox", ",", "(", "option", ",", "default", ")", "in", "list", "(", "self", ".", "comboboxes", ".", "items", "(", ")", ")", ":", "value", "=", "self", ".", "get_option", "(", "option", ",", "default", ")", "for", "index", "in", "range", "(", "combobox", ".", "count", "(", ")", ")", ":", "data", "=", "from_qvariant", "(", "combobox", ".", "itemData", "(", "index", ")", ",", "to_text_string", ")", "# For PyQt API v2, it is necessary to convert `data` to\r", "# unicode in case the original type was not a string, like an\r", "# integer for example (see qtpy.compat.from_qvariant):\r", "if", "to_text_string", "(", "data", ")", "==", "to_text_string", "(", "value", ")", ":", "break", "else", ":", "if", "combobox", ".", "count", "(", ")", "==", "0", ":", "index", "=", "None", "if", "index", ":", "combobox", ".", "setCurrentIndex", "(", "index", ")", "combobox", ".", "currentIndexChanged", ".", "connect", "(", "lambda", "_foo", ",", "opt", "=", "option", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")", "if", "combobox", ".", "restart_required", ":", "self", ".", "restart_options", "[", "option", "]", "=", "combobox", ".", "label_text", "for", "(", "fontbox", ",", "sizebox", ")", ",", "option", "in", "list", "(", "self", ".", "fontboxes", ".", "items", "(", ")", ")", ":", "font", "=", "self", ".", "get_font", "(", "option", ")", "fontbox", ".", "setCurrentFont", "(", "font", ")", "sizebox", ".", "setValue", "(", "font", ".", "pointSize", "(", ")", ")", "if", "option", "is", "None", ":", "property", "=", "'plugin_font'", "else", ":", "property", "=", "option", "fontbox", ".", "currentIndexChanged", ".", "connect", "(", "lambda", "_foo", ",", "opt", "=", "property", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")", "sizebox", ".", "valueChanged", ".", "connect", "(", "lambda", "_foo", ",", "opt", "=", "property", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")", "for", "clayout", ",", "(", "option", ",", "default", ")", "in", "list", "(", "self", ".", "coloredits", ".", "items", "(", ")", ")", ":", "property", "=", "to_qvariant", "(", "option", ")", "edit", "=", "clayout", ".", "lineedit", "btn", "=", "clayout", ".", "colorbtn", "edit", ".", "setText", "(", "self", ".", "get_option", "(", "option", ",", "default", ")", ")", "# QAbstractButton works differently for PySide and PyQt\r", "if", "not", "API", "==", "'pyside'", ":", "btn", ".", "clicked", ".", "connect", "(", "lambda", "_foo", ",", "opt", "=", "option", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")", "else", ":", "btn", ".", "clicked", ".", "connect", "(", "lambda", "opt", "=", "option", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")", "edit", ".", "textChanged", ".", "connect", "(", "lambda", "_foo", ",", "opt", "=", "option", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")", "for", "(", "clayout", ",", "cb_bold", ",", "cb_italic", ")", ",", "(", "option", ",", "default", ")", "in", "list", "(", "self", ".", "scedits", ".", "items", "(", ")", ")", ":", "edit", "=", "clayout", ".", "lineedit", "btn", "=", "clayout", ".", "colorbtn", "color", ",", "bold", ",", "italic", "=", "self", ".", "get_option", "(", "option", ",", "default", ")", "edit", ".", "setText", "(", "color", ")", "cb_bold", ".", "setChecked", "(", "bold", ")", "cb_italic", ".", "setChecked", "(", "italic", ")", "edit", ".", "textChanged", ".", "connect", "(", "lambda", "_foo", ",", "opt", "=", "option", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")", "# QAbstractButton works differently for PySide and PyQt\r", "if", "not", "API", "==", "'pyside'", ":", "btn", ".", "clicked", ".", "connect", "(", "lambda", "_foo", ",", "opt", "=", "option", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")", "cb_bold", ".", "clicked", ".", "connect", "(", "lambda", "_foo", ",", "opt", "=", "option", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")", "cb_italic", ".", "clicked", ".", "connect", "(", "lambda", "_foo", ",", "opt", "=", "option", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")", "else", ":", "btn", ".", "clicked", ".", "connect", "(", "lambda", "opt", "=", "option", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")", "cb_bold", ".", "clicked", ".", "connect", "(", "lambda", "opt", "=", "option", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")", "cb_italic", ".", "clicked", ".", "connect", "(", "lambda", "opt", "=", "option", ":", "self", ".", "has_been_modified", "(", "opt", ")", ")" ]
Load settings from configuration file
[ "Load", "settings", "from", "configuration", "file" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/configdialog.py#L308-L410
train
spyder-ide/spyder
spyder/preferences/configdialog.py
SpyderConfigPage.save_to_conf
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) in list(self.lineedits.items()): self.set_option(option, to_text_string(lineedit.text())) for textedit, (option, _default) in list(self.textedits.items()): self.set_option(option, to_text_string(textedit.toPlainText())) for spinbox, (option, _default) in list(self.spinboxes.items()): self.set_option(option, spinbox.value()) for combobox, (option, _default) in list(self.comboboxes.items()): data = combobox.itemData(combobox.currentIndex()) self.set_option(option, from_qvariant(data, to_text_string)) for (fontbox, sizebox), option in list(self.fontboxes.items()): font = fontbox.currentFont() font.setPointSize(sizebox.value()) self.set_font(font, option) for clayout, (option, _default) in list(self.coloredits.items()): self.set_option(option, to_text_string(clayout.lineedit.text())) for (clayout, cb_bold, cb_italic), (option, _default) in list(self.scedits.items()): color = to_text_string(clayout.lineedit.text()) bold = cb_bold.isChecked() italic = cb_italic.isChecked() self.set_option(option, (color, bold, italic))
python
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) in list(self.lineedits.items()): self.set_option(option, to_text_string(lineedit.text())) for textedit, (option, _default) in list(self.textedits.items()): self.set_option(option, to_text_string(textedit.toPlainText())) for spinbox, (option, _default) in list(self.spinboxes.items()): self.set_option(option, spinbox.value()) for combobox, (option, _default) in list(self.comboboxes.items()): data = combobox.itemData(combobox.currentIndex()) self.set_option(option, from_qvariant(data, to_text_string)) for (fontbox, sizebox), option in list(self.fontboxes.items()): font = fontbox.currentFont() font.setPointSize(sizebox.value()) self.set_font(font, option) for clayout, (option, _default) in list(self.coloredits.items()): self.set_option(option, to_text_string(clayout.lineedit.text())) for (clayout, cb_bold, cb_italic), (option, _default) in list(self.scedits.items()): color = to_text_string(clayout.lineedit.text()) bold = cb_bold.isChecked() italic = cb_italic.isChecked() self.set_option(option, (color, bold, italic))
[ "def", "save_to_conf", "(", "self", ")", ":", "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", ")", "in", "list", "(", "self", ".", "lineedits", ".", "items", "(", ")", ")", ":", "self", ".", "set_option", "(", "option", ",", "to_text_string", "(", "lineedit", ".", "text", "(", ")", ")", ")", "for", "textedit", ",", "(", "option", ",", "_default", ")", "in", "list", "(", "self", ".", "textedits", ".", "items", "(", ")", ")", ":", "self", ".", "set_option", "(", "option", ",", "to_text_string", "(", "textedit", ".", "toPlainText", "(", ")", ")", ")", "for", "spinbox", ",", "(", "option", ",", "_default", ")", "in", "list", "(", "self", ".", "spinboxes", ".", "items", "(", ")", ")", ":", "self", ".", "set_option", "(", "option", ",", "spinbox", ".", "value", "(", ")", ")", "for", "combobox", ",", "(", "option", ",", "_default", ")", "in", "list", "(", "self", ".", "comboboxes", ".", "items", "(", ")", ")", ":", "data", "=", "combobox", ".", "itemData", "(", "combobox", ".", "currentIndex", "(", ")", ")", "self", ".", "set_option", "(", "option", ",", "from_qvariant", "(", "data", ",", "to_text_string", ")", ")", "for", "(", "fontbox", ",", "sizebox", ")", ",", "option", "in", "list", "(", "self", ".", "fontboxes", ".", "items", "(", ")", ")", ":", "font", "=", "fontbox", ".", "currentFont", "(", ")", "font", ".", "setPointSize", "(", "sizebox", ".", "value", "(", ")", ")", "self", ".", "set_font", "(", "font", ",", "option", ")", "for", "clayout", ",", "(", "option", ",", "_default", ")", "in", "list", "(", "self", ".", "coloredits", ".", "items", "(", ")", ")", ":", "self", ".", "set_option", "(", "option", ",", "to_text_string", "(", "clayout", ".", "lineedit", ".", "text", "(", ")", ")", ")", "for", "(", "clayout", ",", "cb_bold", ",", "cb_italic", ")", ",", "(", "option", ",", "_default", ")", "in", "list", "(", "self", ".", "scedits", ".", "items", "(", ")", ")", ":", "color", "=", "to_text_string", "(", "clayout", ".", "lineedit", ".", "text", "(", ")", ")", "bold", "=", "cb_bold", ".", "isChecked", "(", ")", "italic", "=", "cb_italic", ".", "isChecked", "(", ")", "self", ".", "set_option", "(", "option", ",", "(", "color", ",", "bold", ",", "italic", ")", ")" ]
Save settings to configuration file
[ "Save", "settings", "to", "configuration", "file" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/configdialog.py#L412-L437
train
spyder-ide/spyder
spyder/preferences/configdialog.py
SpyderConfigPage.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) if directory: edit.setText(directory)
python
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) if directory: edit.setText(directory)
[ "def", "select_directory", "(", "self", ",", "edit", ")", ":", "basedir", "=", "to_text_string", "(", "edit", ".", "text", "(", ")", ")", "if", "not", "osp", ".", "isdir", "(", "basedir", ")", ":", "basedir", "=", "getcwd_or_home", "(", ")", "title", "=", "_", "(", "\"Select directory\"", ")", "directory", "=", "getexistingdirectory", "(", "self", ",", "title", ",", "basedir", ")", "if", "directory", ":", "edit", ".", "setText", "(", "directory", ")" ]
Select directory
[ "Select", "directory" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/configdialog.py#L555-L563
train
spyder-ide/spyder
spyder/preferences/configdialog.py
SpyderConfigPage.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 file") filename, _selfilter = getopenfilename(self, title, basedir, filters) if filename: edit.setText(filename)
python
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 file") filename, _selfilter = getopenfilename(self, title, basedir, filters) if filename: edit.setText(filename)
[ "def", "select_file", "(", "self", ",", "edit", ",", "filters", "=", "None", ")", ":", "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 file\"", ")", "filename", ",", "_selfilter", "=", "getopenfilename", "(", "self", ",", "title", ",", "basedir", ",", "filters", ")", "if", "filename", ":", "edit", ".", "setText", "(", "filename", ")" ]
Select File
[ "Select", "File" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/configdialog.py#L585-L595
train
spyder-ide/spyder
spyder/preferences/configdialog.py
SpyderConfigPage.create_combobox
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) for name, key in choices: if not (name is None and key is None): combobox.addItem(name, to_qvariant(key)) # Insert separators count = 0 for index, item in enumerate(choices): name, key = item if name is None and key is None: combobox.insertSeparator(index + count) count += 1 self.comboboxes[combobox] = (option, default) layout = QHBoxLayout() layout.addWidget(label) layout.addWidget(combobox) layout.addStretch(1) layout.setContentsMargins(0, 0, 0, 0) widget = QWidget(self) widget.label = label widget.combobox = combobox widget.setLayout(layout) combobox.restart_required = restart combobox.label_text = text return widget
python
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) for name, key in choices: if not (name is None and key is None): combobox.addItem(name, to_qvariant(key)) # Insert separators count = 0 for index, item in enumerate(choices): name, key = item if name is None and key is None: combobox.insertSeparator(index + count) count += 1 self.comboboxes[combobox] = (option, default) layout = QHBoxLayout() layout.addWidget(label) layout.addWidget(combobox) layout.addStretch(1) layout.setContentsMargins(0, 0, 0, 0) widget = QWidget(self) widget.label = label widget.combobox = combobox widget.setLayout(layout) combobox.restart_required = restart combobox.label_text = text return widget
[ "def", "create_combobox", "(", "self", ",", "text", ",", "choices", ",", "option", ",", "default", "=", "NoDefault", ",", "tip", "=", "None", ",", "restart", "=", "False", ")", ":", "label", "=", "QLabel", "(", "text", ")", "combobox", "=", "QComboBox", "(", ")", "if", "tip", "is", "not", "None", ":", "combobox", ".", "setToolTip", "(", "tip", ")", "for", "name", ",", "key", "in", "choices", ":", "if", "not", "(", "name", "is", "None", "and", "key", "is", "None", ")", ":", "combobox", ".", "addItem", "(", "name", ",", "to_qvariant", "(", "key", ")", ")", "# Insert separators\r", "count", "=", "0", "for", "index", ",", "item", "in", "enumerate", "(", "choices", ")", ":", "name", ",", "key", "=", "item", "if", "name", "is", "None", "and", "key", "is", "None", ":", "combobox", ".", "insertSeparator", "(", "index", "+", "count", ")", "count", "+=", "1", "self", ".", "comboboxes", "[", "combobox", "]", "=", "(", "option", ",", "default", ")", "layout", "=", "QHBoxLayout", "(", ")", "layout", ".", "addWidget", "(", "label", ")", "layout", ".", "addWidget", "(", "combobox", ")", "layout", ".", "addStretch", "(", "1", ")", "layout", ".", "setContentsMargins", "(", "0", ",", "0", ",", "0", ",", "0", ")", "widget", "=", "QWidget", "(", "self", ")", "widget", ".", "label", "=", "label", "widget", ".", "combobox", "=", "combobox", "widget", ".", "setLayout", "(", "layout", ")", "combobox", ".", "restart_required", "=", "restart", "combobox", ".", "label_text", "=", "text", "return", "widget" ]
choices: couples (name, key)
[ "choices", ":", "couples", "(", "name", "key", ")" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/configdialog.py#L683-L712
train
spyder-ide/spyder
spyder/preferences/configdialog.py
SpyderConfigPage.create_file_combobox
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, key)""" combobox = FileComboBox(self, adjust_to_contents=adjust_to_contents, default_line_edit=default_line_edit) combobox.restart_required = restart combobox.label_text = text edit = combobox.lineEdit() edit.label_text = text edit.restart_required = restart self.lineedits[edit] = (option, default) if tip is not None: combobox.setToolTip(tip) combobox.addItems(choices) msg = _('Invalid file path') self.validate_data[edit] = (osp.isfile, msg) browse_btn = QPushButton(ima.icon('FileIcon'), '', self) browse_btn.setToolTip(_("Select file")) browse_btn.clicked.connect(lambda: self.select_file(edit, filters)) layout = QGridLayout() layout.addWidget(combobox, 0, 0, 0, 9) layout.addWidget(browse_btn, 0, 10) layout.setContentsMargins(0, 0, 0, 0) widget = QWidget(self) widget.combobox = combobox widget.browse_btn = browse_btn widget.setLayout(layout) return widget
python
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, key)""" combobox = FileComboBox(self, adjust_to_contents=adjust_to_contents, default_line_edit=default_line_edit) combobox.restart_required = restart combobox.label_text = text edit = combobox.lineEdit() edit.label_text = text edit.restart_required = restart self.lineedits[edit] = (option, default) if tip is not None: combobox.setToolTip(tip) combobox.addItems(choices) msg = _('Invalid file path') self.validate_data[edit] = (osp.isfile, msg) browse_btn = QPushButton(ima.icon('FileIcon'), '', self) browse_btn.setToolTip(_("Select file")) browse_btn.clicked.connect(lambda: self.select_file(edit, filters)) layout = QGridLayout() layout.addWidget(combobox, 0, 0, 0, 9) layout.addWidget(browse_btn, 0, 10) layout.setContentsMargins(0, 0, 0, 0) widget = QWidget(self) widget.combobox = combobox widget.browse_btn = browse_btn widget.setLayout(layout) return widget
[ "def", "create_file_combobox", "(", "self", ",", "text", ",", "choices", ",", "option", ",", "default", "=", "NoDefault", ",", "tip", "=", "None", ",", "restart", "=", "False", ",", "filters", "=", "None", ",", "adjust_to_contents", "=", "False", ",", "default_line_edit", "=", "False", ")", ":", "combobox", "=", "FileComboBox", "(", "self", ",", "adjust_to_contents", "=", "adjust_to_contents", ",", "default_line_edit", "=", "default_line_edit", ")", "combobox", ".", "restart_required", "=", "restart", "combobox", ".", "label_text", "=", "text", "edit", "=", "combobox", ".", "lineEdit", "(", ")", "edit", ".", "label_text", "=", "text", "edit", ".", "restart_required", "=", "restart", "self", ".", "lineedits", "[", "edit", "]", "=", "(", "option", ",", "default", ")", "if", "tip", "is", "not", "None", ":", "combobox", ".", "setToolTip", "(", "tip", ")", "combobox", ".", "addItems", "(", "choices", ")", "msg", "=", "_", "(", "'Invalid file path'", ")", "self", ".", "validate_data", "[", "edit", "]", "=", "(", "osp", ".", "isfile", ",", "msg", ")", "browse_btn", "=", "QPushButton", "(", "ima", ".", "icon", "(", "'FileIcon'", ")", ",", "''", ",", "self", ")", "browse_btn", ".", "setToolTip", "(", "_", "(", "\"Select file\"", ")", ")", "browse_btn", ".", "clicked", ".", "connect", "(", "lambda", ":", "self", ".", "select_file", "(", "edit", ",", "filters", ")", ")", "layout", "=", "QGridLayout", "(", ")", "layout", ".", "addWidget", "(", "combobox", ",", "0", ",", "0", ",", "0", ",", "9", ")", "layout", ".", "addWidget", "(", "browse_btn", ",", "0", ",", "10", ")", "layout", ".", "setContentsMargins", "(", "0", ",", "0", ",", "0", ",", "0", ")", "widget", "=", "QWidget", "(", "self", ")", "widget", ".", "combobox", "=", "combobox", "widget", ".", "browse_btn", "=", "browse_btn", "widget", ".", "setLayout", "(", "layout", ")", "return", "widget" ]
choices: couples (name, key)
[ "choices", ":", "couples", "(", "name", "key", ")" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/configdialog.py#L714-L747
train
spyder-ide/spyder
spyder/preferences/configdialog.py
SpyderConfigPage.create_fontgroup
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() sizebox.setRange(7, 100) self.fontboxes[(fontbox, sizebox)] = option layout = QHBoxLayout() for subwidget in (fontlabel, fontbox, sizelabel, sizebox): layout.addWidget(subwidget) layout.addStretch(1) widget = QWidget(self) widget.fontlabel = fontlabel widget.sizelabel = sizelabel widget.fontbox = fontbox widget.sizebox = sizebox widget.setLayout(layout) if not without_group: if text is None: text = _("Font style") group = QGroupBox(text) group.setLayout(layout) if tip is not None: group.setToolTip(tip) return group else: return widget
python
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() sizebox.setRange(7, 100) self.fontboxes[(fontbox, sizebox)] = option layout = QHBoxLayout() for subwidget in (fontlabel, fontbox, sizelabel, sizebox): layout.addWidget(subwidget) layout.addStretch(1) widget = QWidget(self) widget.fontlabel = fontlabel widget.sizelabel = sizelabel widget.fontbox = fontbox widget.sizebox = sizebox widget.setLayout(layout) if not without_group: if text is None: text = _("Font style") group = QGroupBox(text) group.setLayout(layout) if tip is not None: group.setToolTip(tip) return group else: return widget
[ "def", "create_fontgroup", "(", "self", ",", "option", "=", "None", ",", "text", "=", "None", ",", "title", "=", "None", ",", "tip", "=", "None", ",", "fontfilters", "=", "None", ",", "without_group", "=", "False", ")", ":", "if", "title", ":", "fontlabel", "=", "QLabel", "(", "title", ")", "else", ":", "fontlabel", "=", "QLabel", "(", "_", "(", "\"Font\"", ")", ")", "fontbox", "=", "QFontComboBox", "(", ")", "if", "fontfilters", "is", "not", "None", ":", "fontbox", ".", "setFontFilters", "(", "fontfilters", ")", "sizelabel", "=", "QLabel", "(", "\" \"", "+", "_", "(", "\"Size\"", ")", ")", "sizebox", "=", "QSpinBox", "(", ")", "sizebox", ".", "setRange", "(", "7", ",", "100", ")", "self", ".", "fontboxes", "[", "(", "fontbox", ",", "sizebox", ")", "]", "=", "option", "layout", "=", "QHBoxLayout", "(", ")", "for", "subwidget", "in", "(", "fontlabel", ",", "fontbox", ",", "sizelabel", ",", "sizebox", ")", ":", "layout", ".", "addWidget", "(", "subwidget", ")", "layout", ".", "addStretch", "(", "1", ")", "widget", "=", "QWidget", "(", "self", ")", "widget", ".", "fontlabel", "=", "fontlabel", "widget", ".", "sizelabel", "=", "sizelabel", "widget", ".", "fontbox", "=", "fontbox", "widget", ".", "sizebox", "=", "sizebox", "widget", ".", "setLayout", "(", "layout", ")", "if", "not", "without_group", ":", "if", "text", "is", "None", ":", "text", "=", "_", "(", "\"Font style\"", ")", "group", "=", "QGroupBox", "(", "text", ")", "group", ".", "setLayout", "(", "layout", ")", "if", "tip", "is", "not", "None", ":", "group", ".", "setToolTip", "(", "tip", ")", "return", "group", "else", ":", "return", "widget" ]
Option=None -> setting plugin font
[ "Option", "=", "None", "-", ">", "setting", "plugin", "font" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/configdialog.py#L749-L791
train
spyder-ide/spyder
spyder/preferences/configdialog.py
SpyderConfigPage.create_tab
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) layout.addStretch(1) widget.setLayout(layout) return widget
python
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) layout.addStretch(1) widget.setLayout(layout) return widget
[ "def", "create_tab", "(", "self", ",", "*", "widgets", ")", ":", "widget", "=", "QWidget", "(", ")", "layout", "=", "QVBoxLayout", "(", ")", "for", "widg", "in", "widgets", ":", "layout", ".", "addWidget", "(", "widg", ")", "layout", ".", "addStretch", "(", "1", ")", "widget", ".", "setLayout", "(", "layout", ")", "return", "widget" ]
Create simple tab widget page: widgets added in a vertical layout
[ "Create", "simple", "tab", "widget", "page", ":", "widgets", "added", "in", "a", "vertical", "layout" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/configdialog.py#L799-L807
train
spyder-ide/spyder
spyder/preferences/configdialog.py
GeneralConfigPage.prompt_restart_required
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:") else: msg_start = _("Spyder needs to restart to change the following " "settings:") msg_end = _("Do you wish to restart now?") msg_options = u"" for option in options: msg_options += u"<li>{0}</li>".format(option) msg_title = _("Information") msg = u"{0}<ul>{1}</ul><br>{2}".format(msg_start, msg_options, msg_end) answer = QMessageBox.information(self, msg_title, msg, QMessageBox.Yes | QMessageBox.No) if answer == QMessageBox.Yes: self.restart()
python
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:") else: msg_start = _("Spyder needs to restart to change the following " "settings:") msg_end = _("Do you wish to restart now?") msg_options = u"" for option in options: msg_options += u"<li>{0}</li>".format(option) msg_title = _("Information") msg = u"{0}<ul>{1}</ul><br>{2}".format(msg_start, msg_options, msg_end) answer = QMessageBox.information(self, msg_title, msg, QMessageBox.Yes | QMessageBox.No) if answer == QMessageBox.Yes: self.restart()
[ "def", "prompt_restart_required", "(", "self", ")", ":", "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:\"", ")", "else", ":", "msg_start", "=", "_", "(", "\"Spyder needs to restart to change the following \"", "\"settings:\"", ")", "msg_end", "=", "_", "(", "\"Do you wish to restart now?\"", ")", "msg_options", "=", "u\"\"", "for", "option", "in", "options", ":", "msg_options", "+=", "u\"<li>{0}</li>\"", ".", "format", "(", "option", ")", "msg_title", "=", "_", "(", "\"Information\"", ")", "msg", "=", "u\"{0}<ul>{1}</ul><br>{2}\"", ".", "format", "(", "msg_start", ",", "msg_options", ",", "msg_end", ")", "answer", "=", "QMessageBox", ".", "information", "(", "self", ",", "msg_title", ",", "msg", ",", "QMessageBox", ".", "Yes", "|", "QMessageBox", ".", "No", ")", "if", "answer", "==", "QMessageBox", ".", "Yes", ":", "self", ".", "restart", "(", ")" ]
Prompt the user with a request to restart.
[ "Prompt", "the", "user", "with", "a", "request", "to", "restart", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/preferences/configdialog.py#L834-L857
train
spyder-ide/spyder
spyder/widgets/helperwidgets.py
IconLineEdit._refresh
def _refresh(self): """After an application style change, the paintEvent updates the custom defined stylesheet. """ padding = self.height() css_base = """QLineEdit {{ border: none; padding-right: {padding}px; }} """ css_oxygen = """QLineEdit {{background: transparent; border: none; padding-right: {padding}px; }} """ if self._application_style == 'oxygen': css_template = css_oxygen else: css_template = css_base css = css_template.format(padding=padding) self.setStyleSheet(css) self.update()
python
def _refresh(self): """After an application style change, the paintEvent updates the custom defined stylesheet. """ padding = self.height() css_base = """QLineEdit {{ border: none; padding-right: {padding}px; }} """ css_oxygen = """QLineEdit {{background: transparent; border: none; padding-right: {padding}px; }} """ if self._application_style == 'oxygen': css_template = css_oxygen else: css_template = css_base css = css_template.format(padding=padding) self.setStyleSheet(css) self.update()
[ "def", "_refresh", "(", "self", ")", ":", "padding", "=", "self", ".", "height", "(", ")", "css_base", "=", "\"\"\"QLineEdit {{\n border: none;\n padding-right: {padding}px;\n }}\n \"\"\"", "css_oxygen", "=", "\"\"\"QLineEdit {{background: transparent;\n border: none;\n padding-right: {padding}px;\n }}\n \"\"\"", "if", "self", ".", "_application_style", "==", "'oxygen'", ":", "css_template", "=", "css_oxygen", "else", ":", "css_template", "=", "css_base", "css", "=", "css_template", ".", "format", "(", "padding", "=", "padding", ")", "self", ".", "setStyleSheet", "(", "css", ")", "self", ".", "update", "(", ")" ]
After an application style change, the paintEvent updates the custom defined stylesheet.
[ "After", "an", "application", "style", "change", "the", "paintEvent", "updates", "the", "custom", "defined", "stylesheet", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/helperwidgets.py#L212-L234
train
spyder-ide/spyder
spyder/widgets/helperwidgets.py
IconLineEdit.update_status
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()
python
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()
[ "def", "update_status", "(", "self", ",", "value", ",", "value_set", ")", ":", "self", ".", "_status", "=", "value", "self", ".", "_status_set", "=", "value_set", "self", ".", "repaint", "(", ")", "self", ".", "update", "(", ")" ]
Update the status and set_status to update the icons to display.
[ "Update", "the", "status", "and", "set_status", "to", "update", "the", "icons", "to", "display", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/helperwidgets.py#L248-L253
train
spyder-ide/spyder
spyder/widgets/helperwidgets.py
IconLineEdit.paintEvent
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.geometry() space = int((rect.height())/6) h = rect.height() - space w = rect.width() - h if self._icon_visible: if self._status and self._status_set: pixmap = self._set_icon.pixmap(h, h) elif self._status: pixmap = self._valid_icon.pixmap(h, h) else: pixmap = self._invalid_icon.pixmap(h, h) painter.drawPixmap(w, space, pixmap) application_style = QApplication.style().objectName() if self._application_style != application_style: self._application_style = application_style self._refresh() # Small hack to gurantee correct padding on Spyder start if self._paint_count < 5: self._paint_count += 1 self._refresh()
python
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.geometry() space = int((rect.height())/6) h = rect.height() - space w = rect.width() - h if self._icon_visible: if self._status and self._status_set: pixmap = self._set_icon.pixmap(h, h) elif self._status: pixmap = self._valid_icon.pixmap(h, h) else: pixmap = self._invalid_icon.pixmap(h, h) painter.drawPixmap(w, space, pixmap) application_style = QApplication.style().objectName() if self._application_style != application_style: self._application_style = application_style self._refresh() # Small hack to gurantee correct padding on Spyder start if self._paint_count < 5: self._paint_count += 1 self._refresh()
[ "def", "paintEvent", "(", "self", ",", "event", ")", ":", "super", "(", "IconLineEdit", ",", "self", ")", ".", "paintEvent", "(", "event", ")", "painter", "=", "QPainter", "(", "self", ")", "rect", "=", "self", ".", "geometry", "(", ")", "space", "=", "int", "(", "(", "rect", ".", "height", "(", ")", ")", "/", "6", ")", "h", "=", "rect", ".", "height", "(", ")", "-", "space", "w", "=", "rect", ".", "width", "(", ")", "-", "h", "if", "self", ".", "_icon_visible", ":", "if", "self", ".", "_status", "and", "self", ".", "_status_set", ":", "pixmap", "=", "self", ".", "_set_icon", ".", "pixmap", "(", "h", ",", "h", ")", "elif", "self", ".", "_status", ":", "pixmap", "=", "self", ".", "_valid_icon", ".", "pixmap", "(", "h", ",", "h", ")", "else", ":", "pixmap", "=", "self", ".", "_invalid_icon", ".", "pixmap", "(", "h", ",", "h", ")", "painter", ".", "drawPixmap", "(", "w", ",", "space", ",", "pixmap", ")", "application_style", "=", "QApplication", ".", "style", "(", ")", ".", "objectName", "(", ")", "if", "self", ".", "_application_style", "!=", "application_style", ":", "self", ".", "_application_style", "=", "application_style", "self", ".", "_refresh", "(", ")", "# Small hack to gurantee correct padding on Spyder start", "if", "self", ".", "_paint_count", "<", "5", ":", "self", ".", "_paint_count", "+=", "1", "self", ".", "_refresh", "(", ")" ]
Qt Override. Include a validation icon to the left of the line edit.
[ "Qt", "Override", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/helperwidgets.py#L255-L286
train
spyder-ide/spyder
spyder/plugins/outlineexplorer/plugin.py
OutlineExplorer.register_plugin
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)
python
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)
[ "def", "register_plugin", "(", "self", ")", ":", "self", ".", "main", ".", "restore_scrollbar_position", ".", "connect", "(", "self", ".", "restore_scrollbar_position", ")", "self", ".", "main", ".", "add_dockwidget", "(", "self", ")" ]
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/outlineexplorer/plugin.py#L79-L83
train
spyder-ide/spyder
spyder/plugins/outlineexplorer/plugin.py
OutlineExplorer.visibility_changed
def visibility_changed(self, enable): """DockWidget visibility has changed""" super(SpyderPluginWidget, self).visibility_changed(enable) if enable: self.explorer.is_visible.emit()
python
def visibility_changed(self, enable): """DockWidget visibility has changed""" super(SpyderPluginWidget, self).visibility_changed(enable) if enable: self.explorer.is_visible.emit()
[ "def", "visibility_changed", "(", "self", ",", "enable", ")", ":", "super", "(", "SpyderPluginWidget", ",", "self", ")", ".", "visibility_changed", "(", "enable", ")", "if", "enable", ":", "self", ".", "explorer", ".", "is_visible", ".", "emit", "(", ")" ]
DockWidget visibility has changed
[ "DockWidget", "visibility", "has", "changed" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/outlineexplorer/plugin.py#L95-L99
train
spyder-ide/spyder
spyder/plugins/outlineexplorer/plugin.py
OutlineExplorer.restore_scrollbar_position
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)
python
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)
[ "def", "restore_scrollbar_position", "(", "self", ")", ":", "scrollbar_pos", "=", "self", ".", "get_option", "(", "'scrollbar_position'", ",", "None", ")", "if", "scrollbar_pos", "is", "not", "None", ":", "self", ".", "explorer", ".", "treewidget", ".", "set_scrollbar_position", "(", "scrollbar_pos", ")" ]
Restoring scrollbar position after main window is visible
[ "Restoring", "scrollbar", "position", "after", "main", "window", "is", "visible" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/outlineexplorer/plugin.py#L102-L106
train
spyder-ide/spyder
spyder/plugins/outlineexplorer/plugin.py
OutlineExplorer.save_config
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.treewidget.get_expanded_state()) self.set_option('scrollbar_position', self.explorer.treewidget.get_scrollbar_position())
python
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.treewidget.get_expanded_state()) self.set_option('scrollbar_position', self.explorer.treewidget.get_scrollbar_position())
[ "def", "save_config", "(", "self", ")", ":", "for", "option", ",", "value", "in", "list", "(", "self", ".", "explorer", ".", "get_options", "(", ")", ".", "items", "(", ")", ")", ":", "self", ".", "set_option", "(", "option", ",", "value", ")", "self", ".", "set_option", "(", "'expanded_state'", ",", "self", ".", "explorer", ".", "treewidget", ".", "get_expanded_state", "(", ")", ")", "self", ".", "set_option", "(", "'scrollbar_position'", ",", "self", ".", "explorer", ".", "treewidget", ".", "get_scrollbar_position", "(", ")", ")" ]
Save configuration: tree widget state
[ "Save", "configuration", ":", "tree", "widget", "state" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/outlineexplorer/plugin.py#L108-L115
train
spyder-ide/spyder
spyder/plugins/outlineexplorer/plugin.py
OutlineExplorer.load_config
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 converted to a # string by 'userconfig': if is_text_string(expanded_state): expanded_state = None if expanded_state is not None: self.explorer.treewidget.set_expanded_state(expanded_state)
python
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 converted to a # string by 'userconfig': if is_text_string(expanded_state): expanded_state = None if expanded_state is not None: self.explorer.treewidget.set_expanded_state(expanded_state)
[ "def", "load_config", "(", "self", ")", ":", "expanded_state", "=", "self", ".", "get_option", "(", "'expanded_state'", ",", "None", ")", "# Sometimes the expanded state option may be truncated in .ini file\r", "# (for an unknown reason), in this case it would be converted to a\r", "# string by 'userconfig':\r", "if", "is_text_string", "(", "expanded_state", ")", ":", "expanded_state", "=", "None", "if", "expanded_state", "is", "not", "None", ":", "self", ".", "explorer", ".", "treewidget", ".", "set_expanded_state", "(", "expanded_state", ")" ]
Load configuration: tree widget state
[ "Load", "configuration", ":", "tree", "widget", "state" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/outlineexplorer/plugin.py#L117-L126
train
spyder-ide/spyder
spyder/plugins/pylint/widgets/pylintgui.py
ResultsTree.activated
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, '')
python
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, '')
[ "def", "activated", "(", "self", ",", "item", ")", ":", "data", "=", "self", ".", "data", ".", "get", "(", "id", "(", "item", ")", ")", "if", "data", "is", "not", "None", ":", "fname", ",", "lineno", "=", "data", "self", ".", "sig_edit_goto", ".", "emit", "(", "fname", ",", "lineno", ",", "''", ")" ]
Double-click event
[ "Double", "-", "click", "event" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/pylint/widgets/pylintgui.py#L67-L72
train
spyder-ide/spyder
spyder/plugins/pylint/widgets/pylintgui.py
PylintWidget.remove_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)]
python
def remove_obsolete_items(self): """Removing obsolete items""" self.rdata = [(filename, data) for filename, data in self.rdata if is_module_or_package(filename)]
[ "def", "remove_obsolete_items", "(", "self", ")", ":", "self", ".", "rdata", "=", "[", "(", "filename", ",", "data", ")", "for", "filename", ",", "data", "in", "self", ".", "rdata", "if", "is_module_or_package", "(", "filename", ")", "]" ]
Removing obsolete items
[ "Removing", "obsolete", "items" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/pylint/widgets/pylintgui.py#L257-L260
train
spyder-ide/spyder
spyder/workers/updates.py
WorkerUpdates.check_update_available
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 releases in chronological order. Example: ['2.3.2', '2.3.3' ...] or with github ['2.3.4', '2.3.3' ...] """ # 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 = [r for r in self.releases if not is_stable_version(r) or r in self.version] latest_release = releases[-1] return (check_version(self.version, latest_release, '<'), latest_release)
python
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 releases in chronological order. Example: ['2.3.2', '2.3.3' ...] or with github ['2.3.4', '2.3.3' ...] """ # 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 = [r for r in self.releases if not is_stable_version(r) or r in self.version] latest_release = releases[-1] return (check_version(self.version, latest_release, '<'), latest_release)
[ "def", "check_update_available", "(", "self", ")", ":", "# 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", "=", "[", "r", "for", "r", "in", "self", ".", "releases", "if", "not", "is_stable_version", "(", "r", ")", "or", "r", "in", "self", ".", "version", "]", "latest_release", "=", "releases", "[", "-", "1", "]", "return", "(", "check_version", "(", "self", ".", "version", ",", "latest_release", ",", "'<'", ")", ",", "latest_release", ")" ]
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' ...]
[ "Checks", "if", "there", "is", "an", "update", "available", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/workers/updates.py#L54-L75
train
spyder-ide/spyder
spyder/workers/updates.py
WorkerUpdates.start
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-64/repodata.json' else: self.url = ('https://api.github.com/repos/' 'spyder-ide/spyder/releases') self.update_available = False self.latest_release = __version__ error_msg = None try: if hasattr(ssl, '_create_unverified_context'): # Fix for issue # 2685 [Works only with Python >=2.7.9] # More info: https://www.python.org/dev/peps/pep-0476/#opting-out context = ssl._create_unverified_context() page = urlopen(self.url, context=context) else: page = urlopen(self.url) try: data = page.read() # Needed step for python3 compatibility if not is_text_string(data): data = data.decode() data = json.loads(data) if is_anaconda(): if self.releases is None: self.releases = [] for item in data['packages']: if ('spyder' in item and not re.search(r'spyder-[a-zA-Z]', item)): self.releases.append(item.split('-')[1]) result = self.check_update_available() else: if self.releases is None: self.releases = [item['tag_name'].replace('v', '') for item in data] self.releases = list(reversed(self.releases)) result = self.check_update_available() self.update_available, self.latest_release = result except Exception: error_msg = _('Unable to retrieve information.') except HTTPError: error_msg = _('Unable to retrieve information.') except URLError: error_msg = _('Unable to connect to the internet. <br><br>Make ' 'sure the connection is working properly.') except Exception: error_msg = _('Unable to check for updates.') # Don't show dialog when starting up spyder and an error occur if not (self.startup and error_msg is not None): self.error = error_msg self.sig_ready.emit()
python
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-64/repodata.json' else: self.url = ('https://api.github.com/repos/' 'spyder-ide/spyder/releases') self.update_available = False self.latest_release = __version__ error_msg = None try: if hasattr(ssl, '_create_unverified_context'): # Fix for issue # 2685 [Works only with Python >=2.7.9] # More info: https://www.python.org/dev/peps/pep-0476/#opting-out context = ssl._create_unverified_context() page = urlopen(self.url, context=context) else: page = urlopen(self.url) try: data = page.read() # Needed step for python3 compatibility if not is_text_string(data): data = data.decode() data = json.loads(data) if is_anaconda(): if self.releases is None: self.releases = [] for item in data['packages']: if ('spyder' in item and not re.search(r'spyder-[a-zA-Z]', item)): self.releases.append(item.split('-')[1]) result = self.check_update_available() else: if self.releases is None: self.releases = [item['tag_name'].replace('v', '') for item in data] self.releases = list(reversed(self.releases)) result = self.check_update_available() self.update_available, self.latest_release = result except Exception: error_msg = _('Unable to retrieve information.') except HTTPError: error_msg = _('Unable to retrieve information.') except URLError: error_msg = _('Unable to connect to the internet. <br><br>Make ' 'sure the connection is working properly.') except Exception: error_msg = _('Unable to check for updates.') # Don't show dialog when starting up spyder and an error occur if not (self.startup and error_msg is not None): self.error = error_msg self.sig_ready.emit()
[ "def", "start", "(", "self", ")", ":", "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-64/repodata.json'", "else", ":", "self", ".", "url", "=", "(", "'https://api.github.com/repos/'", "'spyder-ide/spyder/releases'", ")", "self", ".", "update_available", "=", "False", "self", ".", "latest_release", "=", "__version__", "error_msg", "=", "None", "try", ":", "if", "hasattr", "(", "ssl", ",", "'_create_unverified_context'", ")", ":", "# Fix for issue # 2685 [Works only with Python >=2.7.9]", "# More info: https://www.python.org/dev/peps/pep-0476/#opting-out", "context", "=", "ssl", ".", "_create_unverified_context", "(", ")", "page", "=", "urlopen", "(", "self", ".", "url", ",", "context", "=", "context", ")", "else", ":", "page", "=", "urlopen", "(", "self", ".", "url", ")", "try", ":", "data", "=", "page", ".", "read", "(", ")", "# Needed step for python3 compatibility", "if", "not", "is_text_string", "(", "data", ")", ":", "data", "=", "data", ".", "decode", "(", ")", "data", "=", "json", ".", "loads", "(", "data", ")", "if", "is_anaconda", "(", ")", ":", "if", "self", ".", "releases", "is", "None", ":", "self", ".", "releases", "=", "[", "]", "for", "item", "in", "data", "[", "'packages'", "]", ":", "if", "(", "'spyder'", "in", "item", "and", "not", "re", ".", "search", "(", "r'spyder-[a-zA-Z]'", ",", "item", ")", ")", ":", "self", ".", "releases", ".", "append", "(", "item", ".", "split", "(", "'-'", ")", "[", "1", "]", ")", "result", "=", "self", ".", "check_update_available", "(", ")", "else", ":", "if", "self", ".", "releases", "is", "None", ":", "self", ".", "releases", "=", "[", "item", "[", "'tag_name'", "]", ".", "replace", "(", "'v'", ",", "''", ")", "for", "item", "in", "data", "]", "self", ".", "releases", "=", "list", "(", "reversed", "(", "self", ".", "releases", ")", ")", "result", "=", "self", ".", "check_update_available", "(", ")", "self", ".", "update_available", ",", "self", ".", "latest_release", "=", "result", "except", "Exception", ":", "error_msg", "=", "_", "(", "'Unable to retrieve information.'", ")", "except", "HTTPError", ":", "error_msg", "=", "_", "(", "'Unable to retrieve information.'", ")", "except", "URLError", ":", "error_msg", "=", "_", "(", "'Unable to connect to the internet. <br><br>Make '", "'sure the connection is working properly.'", ")", "except", "Exception", ":", "error_msg", "=", "_", "(", "'Unable to check for updates.'", ")", "# Don't show dialog when starting up spyder and an error occur", "if", "not", "(", "self", ".", "startup", "and", "error_msg", "is", "not", "None", ")", ":", "self", ".", "error", "=", "error_msg", "self", ".", "sig_ready", ".", "emit", "(", ")" ]
Main method of the WorkerUpdates worker
[ "Main", "method", "of", "the", "WorkerUpdates", "worker" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/workers/updates.py#L77-L140
train
spyder-ide/spyder
spyder/widgets/findreplace.py
FindReplace.eventFilter
def eventFilter(self, widget, event): """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. """ if event.type() == QEvent.KeyPress: key = event.key() shift = event.modifiers() & Qt.ShiftModifier if key == Qt.Key_Return: if shift: self.return_shift_pressed.emit() else: self.return_pressed.emit() if key == Qt.Key_Tab: if self.search_text.hasFocus(): self.replace_text.set_current_text( self.search_text.currentText()) self.focusNextChild() return super(FindReplace, self).eventFilter(widget, event)
python
def eventFilter(self, widget, event): """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. """ if event.type() == QEvent.KeyPress: key = event.key() shift = event.modifiers() & Qt.ShiftModifier if key == Qt.Key_Return: if shift: self.return_shift_pressed.emit() else: self.return_pressed.emit() if key == Qt.Key_Tab: if self.search_text.hasFocus(): self.replace_text.set_current_text( self.search_text.currentText()) self.focusNextChild() return super(FindReplace, self).eventFilter(widget, event)
[ "def", "eventFilter", "(", "self", ",", "widget", ",", "event", ")", ":", "if", "event", ".", "type", "(", ")", "==", "QEvent", ".", "KeyPress", ":", "key", "=", "event", ".", "key", "(", ")", "shift", "=", "event", ".", "modifiers", "(", ")", "&", "Qt", ".", "ShiftModifier", "if", "key", "==", "Qt", ".", "Key_Return", ":", "if", "shift", ":", "self", ".", "return_shift_pressed", ".", "emit", "(", ")", "else", ":", "self", ".", "return_pressed", ".", "emit", "(", ")", "if", "key", "==", "Qt", ".", "Key_Tab", ":", "if", "self", ".", "search_text", ".", "hasFocus", "(", ")", ":", "self", ".", "replace_text", ".", "set_current_text", "(", "self", ".", "search_text", ".", "currentText", "(", ")", ")", "self", ".", "focusNextChild", "(", ")", "return", "super", "(", "FindReplace", ",", "self", ")", ".", "eventFilter", "(", "widget", ",", "event", ")" ]
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.
[ "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", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/findreplace.py#L182-L205
train
spyder-ide/spyder
spyder/widgets/findreplace.py
FindReplace.create_shortcuts
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 = config_shortcut(self.show, context='_', name='Find text', parent=parent) togglereplace = config_shortcut(self.show_replace, context='_', name='Replace text', parent=parent) hide = config_shortcut(self.hide, context='_', name='hide find and replace', parent=self) return [findnext, findprev, togglefind, togglereplace, hide]
python
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 = config_shortcut(self.show, context='_', name='Find text', parent=parent) togglereplace = config_shortcut(self.show_replace, context='_', name='Replace text', parent=parent) hide = config_shortcut(self.hide, context='_', name='hide find and replace', parent=self) return [findnext, findprev, togglefind, togglereplace, hide]
[ "def", "create_shortcuts", "(", "self", ",", "parent", ")", ":", "# Configurable\r", "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", "=", "config_shortcut", "(", "self", ".", "show", ",", "context", "=", "'_'", ",", "name", "=", "'Find text'", ",", "parent", "=", "parent", ")", "togglereplace", "=", "config_shortcut", "(", "self", ".", "show_replace", ",", "context", "=", "'_'", ",", "name", "=", "'Replace text'", ",", "parent", "=", "parent", ")", "hide", "=", "config_shortcut", "(", "self", ".", "hide", ",", "context", "=", "'_'", ",", "name", "=", "'hide find and replace'", ",", "parent", "=", "self", ")", "return", "[", "findnext", ",", "findprev", ",", "togglefind", ",", "togglereplace", ",", "hide", "]" ]
Create shortcuts for this widget
[ "Create", "shortcuts", "for", "this", "widget" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/findreplace.py#L207-L222
train
spyder-ide/spyder
spyder/widgets/findreplace.py
FindReplace.toggle_highlighting
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()
python
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()
[ "def", "toggle_highlighting", "(", "self", ",", "state", ")", ":", "if", "self", ".", "editor", "is", "not", "None", ":", "if", "state", ":", "self", ".", "highlight_matches", "(", ")", "else", ":", "self", ".", "clear_matches", "(", ")" ]
Toggle the 'highlight all results' feature
[ "Toggle", "the", "highlight", "all", "results", "feature" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/findreplace.py#L251-L257
train
spyder-ide/spyder
spyder/widgets/findreplace.py
FindReplace.show
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].isVisible(): self.hide_replace() text = self.editor.get_selected_text() # When selecting several lines, and replace box is activated the # text won't be replaced for the selection if hide_replace or len(text.splitlines())<=1: highlighted = True # If no text is highlighted for search, use whatever word is # under the cursor if not text: highlighted = False try: cursor = self.editor.textCursor() cursor.select(QTextCursor.WordUnderCursor) text = to_text_string(cursor.selectedText()) except AttributeError: # We can't do this for all widgets, e.g. WebView's pass # Now that text value is sorted out, use it for the search if text and not self.search_text.currentText() or highlighted: self.search_text.setEditText(text) self.search_text.lineEdit().selectAll() self.refresh() else: self.search_text.lineEdit().selectAll() self.search_text.setFocus()
python
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].isVisible(): self.hide_replace() text = self.editor.get_selected_text() # When selecting several lines, and replace box is activated the # text won't be replaced for the selection if hide_replace or len(text.splitlines())<=1: highlighted = True # If no text is highlighted for search, use whatever word is # under the cursor if not text: highlighted = False try: cursor = self.editor.textCursor() cursor.select(QTextCursor.WordUnderCursor) text = to_text_string(cursor.selectedText()) except AttributeError: # We can't do this for all widgets, e.g. WebView's pass # Now that text value is sorted out, use it for the search if text and not self.search_text.currentText() or highlighted: self.search_text.setEditText(text) self.search_text.lineEdit().selectAll() self.refresh() else: self.search_text.lineEdit().selectAll() self.search_text.setFocus()
[ "def", "show", "(", "self", ",", "hide_replace", "=", "True", ")", ":", "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", "]", ".", "isVisible", "(", ")", ":", "self", ".", "hide_replace", "(", ")", "text", "=", "self", ".", "editor", ".", "get_selected_text", "(", ")", "# When selecting several lines, and replace box is activated the\r", "# text won't be replaced for the selection\r", "if", "hide_replace", "or", "len", "(", "text", ".", "splitlines", "(", ")", ")", "<=", "1", ":", "highlighted", "=", "True", "# If no text is highlighted for search, use whatever word is\r", "# under the cursor\r", "if", "not", "text", ":", "highlighted", "=", "False", "try", ":", "cursor", "=", "self", ".", "editor", ".", "textCursor", "(", ")", "cursor", ".", "select", "(", "QTextCursor", ".", "WordUnderCursor", ")", "text", "=", "to_text_string", "(", "cursor", ".", "selectedText", "(", ")", ")", "except", "AttributeError", ":", "# We can't do this for all widgets, e.g. WebView's\r", "pass", "# Now that text value is sorted out, use it for the search\r", "if", "text", "and", "not", "self", ".", "search_text", ".", "currentText", "(", ")", "or", "highlighted", ":", "self", ".", "search_text", ".", "setEditText", "(", "text", ")", "self", ".", "search_text", ".", "lineEdit", "(", ")", ".", "selectAll", "(", ")", "self", ".", "refresh", "(", ")", "else", ":", "self", ".", "search_text", ".", "lineEdit", "(", ")", ".", "selectAll", "(", ")", "self", ".", "search_text", ".", "setFocus", "(", ")" ]
Overrides Qt Method
[ "Overrides", "Qt", "Method" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/findreplace.py#L259-L292
train
spyder-ide/spyder
spyder/widgets/findreplace.py
FindReplace.hide
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_matches()
python
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_matches()
[ "def", "hide", "(", "self", ")", ":", "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_matches", "(", ")" ]
Overrides Qt Method
[ "Overrides", "Qt", "Method" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/findreplace.py#L295-L303
train
spyder-ide/spyder
spyder/widgets/findreplace.py
FindReplace.show_replace
def show_replace(self): """Show replace widgets""" self.show(hide_replace=False) for widget in self.replace_widgets: widget.show()
python
def show_replace(self): """Show replace widgets""" self.show(hide_replace=False) for widget in self.replace_widgets: widget.show()
[ "def", "show_replace", "(", "self", ")", ":", "self", ".", "show", "(", "hide_replace", "=", "False", ")", "for", "widget", "in", "self", ".", "replace_widgets", ":", "widget", ".", "show", "(", ")" ]
Show replace widgets
[ "Show", "replace", "widgets" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/findreplace.py#L305-L309
train
spyder-ide/spyder
spyder/widgets/findreplace.py
FindReplace.refresh
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 state: self.find()
python
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 state: self.find()
[ "def", "refresh", "(", "self", ")", ":", "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", "state", ":", "self", ".", "find", "(", ")" ]
Refresh widget
[ "Refresh", "widget" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/findreplace.py#L316-L326
train
spyder-ide/spyder
spyder/widgets/findreplace.py
FindReplace.set_editor
def set_editor(self, editor, refresh=True): """ Set associated editor/web page: codeeditor.base.TextEditBaseWidget browser.WebView """ self.editor = editor # Note: This is necessary to test widgets/editor.py # in Qt builds that don't have web widgets try: from qtpy.QtWebEngineWidgets import QWebEngineView except ImportError: QWebEngineView = type(None) self.words_button.setVisible(not isinstance(editor, QWebEngineView)) self.re_button.setVisible(not isinstance(editor, QWebEngineView)) from spyder.plugins.editor.widgets.codeeditor import CodeEditor self.is_code_editor = isinstance(editor, CodeEditor) self.highlight_button.setVisible(self.is_code_editor) if refresh: self.refresh() if self.isHidden() and editor is not None: self.clear_matches()
python
def set_editor(self, editor, refresh=True): """ Set associated editor/web page: codeeditor.base.TextEditBaseWidget browser.WebView """ self.editor = editor # Note: This is necessary to test widgets/editor.py # in Qt builds that don't have web widgets try: from qtpy.QtWebEngineWidgets import QWebEngineView except ImportError: QWebEngineView = type(None) self.words_button.setVisible(not isinstance(editor, QWebEngineView)) self.re_button.setVisible(not isinstance(editor, QWebEngineView)) from spyder.plugins.editor.widgets.codeeditor import CodeEditor self.is_code_editor = isinstance(editor, CodeEditor) self.highlight_button.setVisible(self.is_code_editor) if refresh: self.refresh() if self.isHidden() and editor is not None: self.clear_matches()
[ "def", "set_editor", "(", "self", ",", "editor", ",", "refresh", "=", "True", ")", ":", "self", ".", "editor", "=", "editor", "# Note: This is necessary to test widgets/editor.py\r", "# in Qt builds that don't have web widgets\r", "try", ":", "from", "qtpy", ".", "QtWebEngineWidgets", "import", "QWebEngineView", "except", "ImportError", ":", "QWebEngineView", "=", "type", "(", "None", ")", "self", ".", "words_button", ".", "setVisible", "(", "not", "isinstance", "(", "editor", ",", "QWebEngineView", ")", ")", "self", ".", "re_button", ".", "setVisible", "(", "not", "isinstance", "(", "editor", ",", "QWebEngineView", ")", ")", "from", "spyder", ".", "plugins", ".", "editor", ".", "widgets", ".", "codeeditor", "import", "CodeEditor", "self", ".", "is_code_editor", "=", "isinstance", "(", "editor", ",", "CodeEditor", ")", "self", ".", "highlight_button", ".", "setVisible", "(", "self", ".", "is_code_editor", ")", "if", "refresh", ":", "self", ".", "refresh", "(", ")", "if", "self", ".", "isHidden", "(", ")", "and", "editor", "is", "not", "None", ":", "self", ".", "clear_matches", "(", ")" ]
Set associated editor/web page: codeeditor.base.TextEditBaseWidget browser.WebView
[ "Set", "associated", "editor", "/", "web", "page", ":", "codeeditor", ".", "base", ".", "TextEditBaseWidget", "browser", ".", "WebView" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/findreplace.py#L328-L349
train
spyder-ide/spyder
spyder/widgets/findreplace.py
FindReplace.find_next
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
python
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
[ "def", "find_next", "(", "self", ")", ":", "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 next occurrence
[ "Find", "next", "occurrence" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/findreplace.py#L352-L358
train
spyder-ide/spyder
spyder/widgets/findreplace.py
FindReplace.find_previous
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
python
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
[ "def", "find_previous", "(", "self", ")", ":", "state", "=", "self", ".", "find", "(", "changed", "=", "False", ",", "forward", "=", "False", ",", "rehighlight", "=", "False", ",", "multiline_replace_check", "=", "False", ")", "self", ".", "editor", ".", "setFocus", "(", ")", "return", "state" ]
Find previous occurrence
[ "Find", "previous", "occurrence" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/findreplace.py#L361-L366
train
spyder-ide/spyder
spyder/widgets/findreplace.py
FindReplace.text_has_been_edited
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)""" self.find(changed=True, forward=True, start_highlight_timer=True)
python
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)""" self.find(changed=True, forward=True, start_highlight_timer=True)
[ "def", "text_has_been_edited", "(", "self", ",", "text", ")", ":", "self", ".", "find", "(", "changed", "=", "True", ",", "forward", "=", "True", ",", "start_highlight_timer", "=", "True", ")" ]
Find text has been edited (this slot won't be triggered when setting the search pattern combo box text programmatically)
[ "Find", "text", "has", "been", "edited", "(", "this", "slot", "won", "t", "be", "triggered", "when", "setting", "the", "search", "pattern", "combo", "box", "text", "programmatically", ")" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/findreplace.py#L368-L371
train
spyder-ide/spyder
spyder/widgets/findreplace.py
FindReplace.highlight_matches
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, regexp=regexp)
python
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, regexp=regexp)
[ "def", "highlight_matches", "(", "self", ")", ":", "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", ",", "regexp", "=", "regexp", ")" ]
Highlight found results
[ "Highlight", "found", "results" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/findreplace.py#L373-L380
train
spyder-ide/spyder
spyder/widgets/findreplace.py
FindReplace.find
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 deactivated to prevent changing the selection. Otherwise # we show matching items. if multiline_replace_check and self.replace_widgets[0].isVisible() and \ len(to_text_string(self.editor.get_selected_text()).splitlines())>1: return None text = self.search_text.currentText() if len(text) == 0: self.search_text.lineEdit().setStyleSheet("") if not self.is_code_editor: # Clears the selection for WebEngine self.editor.find_text('') self.change_number_matches() return None else: case = self.case_button.isChecked() words = self.words_button.isChecked() regexp = self.re_button.isChecked() found = self.editor.find_text(text, changed, forward, case=case, words=words, regexp=regexp) stylesheet = self.STYLE[found] tooltip = self.TOOLTIP[found] if not found and regexp: error_msg = regexp_error_msg(text) if error_msg: # special styling for regexp errors stylesheet = self.STYLE['regexp_error'] tooltip = self.TOOLTIP['regexp_error'] + ': ' + error_msg self.search_text.lineEdit().setStyleSheet(stylesheet) self.search_text.setToolTip(tooltip) if self.is_code_editor and found: block = self.editor.textCursor().block() TextHelper(self.editor).unfold_if_colapsed(block) if rehighlight or not self.editor.found_results: self.highlight_timer.stop() if start_highlight_timer: self.highlight_timer.start() else: self.highlight_matches() else: self.clear_matches() number_matches = self.editor.get_number_matches(text, case=case, regexp=regexp) if hasattr(self.editor, 'get_match_number'): match_number = self.editor.get_match_number(text, case=case, regexp=regexp) else: match_number = 0 self.change_number_matches(current_match=match_number, total_matches=number_matches) return found
python
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 deactivated to prevent changing the selection. Otherwise # we show matching items. if multiline_replace_check and self.replace_widgets[0].isVisible() and \ len(to_text_string(self.editor.get_selected_text()).splitlines())>1: return None text = self.search_text.currentText() if len(text) == 0: self.search_text.lineEdit().setStyleSheet("") if not self.is_code_editor: # Clears the selection for WebEngine self.editor.find_text('') self.change_number_matches() return None else: case = self.case_button.isChecked() words = self.words_button.isChecked() regexp = self.re_button.isChecked() found = self.editor.find_text(text, changed, forward, case=case, words=words, regexp=regexp) stylesheet = self.STYLE[found] tooltip = self.TOOLTIP[found] if not found and regexp: error_msg = regexp_error_msg(text) if error_msg: # special styling for regexp errors stylesheet = self.STYLE['regexp_error'] tooltip = self.TOOLTIP['regexp_error'] + ': ' + error_msg self.search_text.lineEdit().setStyleSheet(stylesheet) self.search_text.setToolTip(tooltip) if self.is_code_editor and found: block = self.editor.textCursor().block() TextHelper(self.editor).unfold_if_colapsed(block) if rehighlight or not self.editor.found_results: self.highlight_timer.stop() if start_highlight_timer: self.highlight_timer.start() else: self.highlight_matches() else: self.clear_matches() number_matches = self.editor.get_number_matches(text, case=case, regexp=regexp) if hasattr(self.editor, 'get_match_number'): match_number = self.editor.get_match_number(text, case=case, regexp=regexp) else: match_number = 0 self.change_number_matches(current_match=match_number, total_matches=number_matches) return found
[ "def", "find", "(", "self", ",", "changed", "=", "True", ",", "forward", "=", "True", ",", "rehighlight", "=", "True", ",", "start_highlight_timer", "=", "False", ",", "multiline_replace_check", "=", "True", ")", ":", "# When several lines are selected in the editor and replace box is activated, \r", "# dynamic search is deactivated to prevent changing the selection. Otherwise\r", "# we show matching items.\r", "if", "multiline_replace_check", "and", "self", ".", "replace_widgets", "[", "0", "]", ".", "isVisible", "(", ")", "and", "len", "(", "to_text_string", "(", "self", ".", "editor", ".", "get_selected_text", "(", ")", ")", ".", "splitlines", "(", ")", ")", ">", "1", ":", "return", "None", "text", "=", "self", ".", "search_text", ".", "currentText", "(", ")", "if", "len", "(", "text", ")", "==", "0", ":", "self", ".", "search_text", ".", "lineEdit", "(", ")", ".", "setStyleSheet", "(", "\"\"", ")", "if", "not", "self", ".", "is_code_editor", ":", "# Clears the selection for WebEngine\r", "self", ".", "editor", ".", "find_text", "(", "''", ")", "self", ".", "change_number_matches", "(", ")", "return", "None", "else", ":", "case", "=", "self", ".", "case_button", ".", "isChecked", "(", ")", "words", "=", "self", ".", "words_button", ".", "isChecked", "(", ")", "regexp", "=", "self", ".", "re_button", ".", "isChecked", "(", ")", "found", "=", "self", ".", "editor", ".", "find_text", "(", "text", ",", "changed", ",", "forward", ",", "case", "=", "case", ",", "words", "=", "words", ",", "regexp", "=", "regexp", ")", "stylesheet", "=", "self", ".", "STYLE", "[", "found", "]", "tooltip", "=", "self", ".", "TOOLTIP", "[", "found", "]", "if", "not", "found", "and", "regexp", ":", "error_msg", "=", "regexp_error_msg", "(", "text", ")", "if", "error_msg", ":", "# special styling for regexp errors\r", "stylesheet", "=", "self", ".", "STYLE", "[", "'regexp_error'", "]", "tooltip", "=", "self", ".", "TOOLTIP", "[", "'regexp_error'", "]", "+", "': '", "+", "error_msg", "self", ".", "search_text", ".", "lineEdit", "(", ")", ".", "setStyleSheet", "(", "stylesheet", ")", "self", ".", "search_text", ".", "setToolTip", "(", "tooltip", ")", "if", "self", ".", "is_code_editor", "and", "found", ":", "block", "=", "self", ".", "editor", ".", "textCursor", "(", ")", ".", "block", "(", ")", "TextHelper", "(", "self", ".", "editor", ")", ".", "unfold_if_colapsed", "(", "block", ")", "if", "rehighlight", "or", "not", "self", ".", "editor", ".", "found_results", ":", "self", ".", "highlight_timer", ".", "stop", "(", ")", "if", "start_highlight_timer", ":", "self", ".", "highlight_timer", ".", "start", "(", ")", "else", ":", "self", ".", "highlight_matches", "(", ")", "else", ":", "self", ".", "clear_matches", "(", ")", "number_matches", "=", "self", ".", "editor", ".", "get_number_matches", "(", "text", ",", "case", "=", "case", ",", "regexp", "=", "regexp", ")", "if", "hasattr", "(", "self", ".", "editor", ",", "'get_match_number'", ")", ":", "match_number", "=", "self", ".", "editor", ".", "get_match_number", "(", "text", ",", "case", "=", "case", ",", "regexp", "=", "regexp", ")", "else", ":", "match_number", "=", "0", "self", ".", "change_number_matches", "(", "current_match", "=", "match_number", ",", "total_matches", "=", "number_matches", ")", "return", "found" ]
Call the find function
[ "Call", "the", "find", "function" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/findreplace.py#L387-L443
train
spyder-ide/spyder
spyder/widgets/findreplace.py
FindReplace.replace_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()) re_pattern = None # Check regexp before proceeding if self.re_button.isChecked(): try: re_pattern = re.compile(search_text) # Check if replace_text can be substituted in re_pattern # Fixes issue #7177 re_pattern.sub(replace_text, '') except re.error: # Do nothing with an invalid regexp return case = self.case_button.isChecked() first = True cursor = None while True: if first: # First found seltxt = to_text_string(self.editor.get_selected_text()) cmptxt1 = search_text if case else search_text.lower() cmptxt2 = seltxt if case else seltxt.lower() if re_pattern is None: has_selected = self.editor.has_selected_text() if has_selected and cmptxt1 == cmptxt2: # Text was already found, do nothing pass else: if not self.find(changed=False, forward=True, rehighlight=False): break else: if len(re_pattern.findall(cmptxt2)) > 0: pass else: if not self.find(changed=False, forward=True, rehighlight=False): break first = False wrapped = False position = self.editor.get_position('cursor') position0 = position cursor = self.editor.textCursor() cursor.beginEditBlock() else: position1 = self.editor.get_position('cursor') if is_position_inf(position1, position0 + len(replace_text) - len(search_text) + 1): # Identify wrapping even when the replace string # includes part of the search string wrapped = True if wrapped: if position1 == position or \ is_position_sup(position1, position): # Avoid infinite loop: replace string includes # part of the search string break if position1 == position0: # Avoid infinite loop: single found occurrence break position0 = position1 if re_pattern is None: cursor.removeSelectedText() cursor.insertText(replace_text) else: seltxt = to_text_string(cursor.selectedText()) cursor.removeSelectedText() cursor.insertText(re_pattern.sub(replace_text, seltxt)) if self.find_next(): found_cursor = self.editor.textCursor() cursor.setPosition(found_cursor.selectionStart(), QTextCursor.MoveAnchor) cursor.setPosition(found_cursor.selectionEnd(), QTextCursor.KeepAnchor) else: break if not replace_all: break if cursor is not None: cursor.endEditBlock() if focus_replace_text: self.replace_text.setFocus()
python
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(): try: re_pattern = re.compile(search_text) # Check if replace_text can be substituted in re_pattern # Fixes issue #7177 re_pattern.sub(replace_text, '') except re.error: # Do nothing with an invalid regexp return case = self.case_button.isChecked() first = True cursor = None while True: if first: # First found seltxt = to_text_string(self.editor.get_selected_text()) cmptxt1 = search_text if case else search_text.lower() cmptxt2 = seltxt if case else seltxt.lower() if re_pattern is None: has_selected = self.editor.has_selected_text() if has_selected and cmptxt1 == cmptxt2: # Text was already found, do nothing pass else: if not self.find(changed=False, forward=True, rehighlight=False): break else: if len(re_pattern.findall(cmptxt2)) > 0: pass else: if not self.find(changed=False, forward=True, rehighlight=False): break first = False wrapped = False position = self.editor.get_position('cursor') position0 = position cursor = self.editor.textCursor() cursor.beginEditBlock() else: position1 = self.editor.get_position('cursor') if is_position_inf(position1, position0 + len(replace_text) - len(search_text) + 1): # Identify wrapping even when the replace string # includes part of the search string wrapped = True if wrapped: if position1 == position or \ is_position_sup(position1, position): # Avoid infinite loop: replace string includes # part of the search string break if position1 == position0: # Avoid infinite loop: single found occurrence break position0 = position1 if re_pattern is None: cursor.removeSelectedText() cursor.insertText(replace_text) else: seltxt = to_text_string(cursor.selectedText()) cursor.removeSelectedText() cursor.insertText(re_pattern.sub(replace_text, seltxt)) if self.find_next(): found_cursor = self.editor.textCursor() cursor.setPosition(found_cursor.selectionStart(), QTextCursor.MoveAnchor) cursor.setPosition(found_cursor.selectionEnd(), QTextCursor.KeepAnchor) else: break if not replace_all: break if cursor is not None: cursor.endEditBlock() if focus_replace_text: self.replace_text.setFocus()
[ "def", "replace_find", "(", "self", ",", "focus_replace_text", "=", "False", ",", "replace_all", "=", "False", ")", ":", "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\r", "if", "self", ".", "re_button", ".", "isChecked", "(", ")", ":", "try", ":", "re_pattern", "=", "re", ".", "compile", "(", "search_text", ")", "# Check if replace_text can be substituted in re_pattern\r", "# Fixes issue #7177\r", "re_pattern", ".", "sub", "(", "replace_text", ",", "''", ")", "except", "re", ".", "error", ":", "# Do nothing with an invalid regexp\r", "return", "case", "=", "self", ".", "case_button", ".", "isChecked", "(", ")", "first", "=", "True", "cursor", "=", "None", "while", "True", ":", "if", "first", ":", "# First found\r", "seltxt", "=", "to_text_string", "(", "self", ".", "editor", ".", "get_selected_text", "(", ")", ")", "cmptxt1", "=", "search_text", "if", "case", "else", "search_text", ".", "lower", "(", ")", "cmptxt2", "=", "seltxt", "if", "case", "else", "seltxt", ".", "lower", "(", ")", "if", "re_pattern", "is", "None", ":", "has_selected", "=", "self", ".", "editor", ".", "has_selected_text", "(", ")", "if", "has_selected", "and", "cmptxt1", "==", "cmptxt2", ":", "# Text was already found, do nothing\r", "pass", "else", ":", "if", "not", "self", ".", "find", "(", "changed", "=", "False", ",", "forward", "=", "True", ",", "rehighlight", "=", "False", ")", ":", "break", "else", ":", "if", "len", "(", "re_pattern", ".", "findall", "(", "cmptxt2", ")", ")", ">", "0", ":", "pass", "else", ":", "if", "not", "self", ".", "find", "(", "changed", "=", "False", ",", "forward", "=", "True", ",", "rehighlight", "=", "False", ")", ":", "break", "first", "=", "False", "wrapped", "=", "False", "position", "=", "self", ".", "editor", ".", "get_position", "(", "'cursor'", ")", "position0", "=", "position", "cursor", "=", "self", ".", "editor", ".", "textCursor", "(", ")", "cursor", ".", "beginEditBlock", "(", ")", "else", ":", "position1", "=", "self", ".", "editor", ".", "get_position", "(", "'cursor'", ")", "if", "is_position_inf", "(", "position1", ",", "position0", "+", "len", "(", "replace_text", ")", "-", "len", "(", "search_text", ")", "+", "1", ")", ":", "# Identify wrapping even when the replace string\r", "# includes part of the search string\r", "wrapped", "=", "True", "if", "wrapped", ":", "if", "position1", "==", "position", "or", "is_position_sup", "(", "position1", ",", "position", ")", ":", "# Avoid infinite loop: replace string includes\r", "# part of the search string\r", "break", "if", "position1", "==", "position0", ":", "# Avoid infinite loop: single found occurrence\r", "break", "position0", "=", "position1", "if", "re_pattern", "is", "None", ":", "cursor", ".", "removeSelectedText", "(", ")", "cursor", ".", "insertText", "(", "replace_text", ")", "else", ":", "seltxt", "=", "to_text_string", "(", "cursor", ".", "selectedText", "(", ")", ")", "cursor", ".", "removeSelectedText", "(", ")", "cursor", ".", "insertText", "(", "re_pattern", ".", "sub", "(", "replace_text", ",", "seltxt", ")", ")", "if", "self", ".", "find_next", "(", ")", ":", "found_cursor", "=", "self", ".", "editor", ".", "textCursor", "(", ")", "cursor", ".", "setPosition", "(", "found_cursor", ".", "selectionStart", "(", ")", ",", "QTextCursor", ".", "MoveAnchor", ")", "cursor", ".", "setPosition", "(", "found_cursor", ".", "selectionEnd", "(", ")", ",", "QTextCursor", ".", "KeepAnchor", ")", "else", ":", "break", "if", "not", "replace_all", ":", "break", "if", "cursor", "is", "not", "None", ":", "cursor", ".", "endEditBlock", "(", ")", "if", "focus_replace_text", ":", "self", ".", "replace_text", ".", "setFocus", "(", ")" ]
Replace and find
[ "Replace", "and", "find" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/findreplace.py#L446-L533
train
spyder-ide/spyder
spyder/widgets/findreplace.py
FindReplace.replace_find_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.search_text.currentText()) case = self.case_button.isChecked() words = self.words_button.isChecked() re_flags = re.MULTILINE if case else re.IGNORECASE|re.MULTILINE re_pattern = None if self.re_button.isChecked(): pattern = search_text else: pattern = re.escape(search_text) replace_text = re.escape(replace_text) if words: # match whole words only pattern = r'\b{pattern}\b'.format(pattern=pattern) # Check regexp before proceeding try: re_pattern = re.compile(pattern, flags=re_flags) # Check if replace_text can be substituted in re_pattern # Fixes issue #7177 re_pattern.sub(replace_text, '') except re.error as e: # Do nothing with an invalid regexp return selected_text = to_text_string(self.editor.get_selected_text()) replacement = re_pattern.sub(replace_text, selected_text) if replacement != selected_text: cursor = self.editor.textCursor() cursor.beginEditBlock() cursor.removeSelectedText() if not self.re_button.isChecked(): replacement = re.sub(r'\\(?![nrtf])(.)', r'\1', replacement) cursor.insertText(replacement) cursor.endEditBlock() if focus_replace_text: self.replace_text.setFocus() else: self.editor.setFocus()
python
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.MULTILINE if case else re.IGNORECASE|re.MULTILINE re_pattern = None if self.re_button.isChecked(): pattern = search_text else: pattern = re.escape(search_text) replace_text = re.escape(replace_text) if words: # match whole words only pattern = r'\b{pattern}\b'.format(pattern=pattern) # Check regexp before proceeding try: re_pattern = re.compile(pattern, flags=re_flags) # Check if replace_text can be substituted in re_pattern # Fixes issue #7177 re_pattern.sub(replace_text, '') except re.error as e: # Do nothing with an invalid regexp return selected_text = to_text_string(self.editor.get_selected_text()) replacement = re_pattern.sub(replace_text, selected_text) if replacement != selected_text: cursor = self.editor.textCursor() cursor.beginEditBlock() cursor.removeSelectedText() if not self.re_button.isChecked(): replacement = re.sub(r'\\(?![nrtf])(.)', r'\1', replacement) cursor.insertText(replacement) cursor.endEditBlock() if focus_replace_text: self.replace_text.setFocus() else: self.editor.setFocus()
[ "def", "replace_find_selection", "(", "self", ",", "focus_replace_text", "=", "False", ")", ":", "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", ".", "MULTILINE", "if", "case", "else", "re", ".", "IGNORECASE", "|", "re", ".", "MULTILINE", "re_pattern", "=", "None", "if", "self", ".", "re_button", ".", "isChecked", "(", ")", ":", "pattern", "=", "search_text", "else", ":", "pattern", "=", "re", ".", "escape", "(", "search_text", ")", "replace_text", "=", "re", ".", "escape", "(", "replace_text", ")", "if", "words", ":", "# match whole words only\r", "pattern", "=", "r'\\b{pattern}\\b'", ".", "format", "(", "pattern", "=", "pattern", ")", "# Check regexp before proceeding\r", "try", ":", "re_pattern", "=", "re", ".", "compile", "(", "pattern", ",", "flags", "=", "re_flags", ")", "# Check if replace_text can be substituted in re_pattern\r", "# Fixes issue #7177\r", "re_pattern", ".", "sub", "(", "replace_text", ",", "''", ")", "except", "re", ".", "error", "as", "e", ":", "# Do nothing with an invalid regexp\r", "return", "selected_text", "=", "to_text_string", "(", "self", ".", "editor", ".", "get_selected_text", "(", ")", ")", "replacement", "=", "re_pattern", ".", "sub", "(", "replace_text", ",", "selected_text", ")", "if", "replacement", "!=", "selected_text", ":", "cursor", "=", "self", ".", "editor", ".", "textCursor", "(", ")", "cursor", ".", "beginEditBlock", "(", ")", "cursor", ".", "removeSelectedText", "(", ")", "if", "not", "self", ".", "re_button", ".", "isChecked", "(", ")", ":", "replacement", "=", "re", ".", "sub", "(", "r'\\\\(?![nrtf])(.)'", ",", "r'\\1'", ",", "replacement", ")", "cursor", ".", "insertText", "(", "replacement", ")", "cursor", ".", "endEditBlock", "(", ")", "if", "focus_replace_text", ":", "self", ".", "replace_text", ".", "setFocus", "(", ")", "else", ":", "self", ".", "editor", ".", "setFocus", "(", ")" ]
Replace and find in the current selection
[ "Replace", "and", "find", "in", "the", "current", "selection" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/findreplace.py#L542-L583
train
spyder-ide/spyder
spyder/widgets/findreplace.py
FindReplace.change_number_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"), total_matches) self.number_matches_text.setText(matches_string) elif total_matches: matches_string = u"{} {}".format(total_matches, _(u"matches")) self.number_matches_text.setText(matches_string) else: self.number_matches_text.setText(_(u"no matches"))
python
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(total_matches, _(u"matches")) self.number_matches_text.setText(matches_string) else: self.number_matches_text.setText(_(u"no matches"))
[ "def", "change_number_matches", "(", "self", ",", "current_match", "=", "0", ",", "total_matches", "=", "0", ")", ":", "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", "(", "total_matches", ",", "_", "(", "u\"matches\"", ")", ")", "self", ".", "number_matches_text", ".", "setText", "(", "matches_string", ")", "else", ":", "self", ".", "number_matches_text", ".", "setText", "(", "_", "(", "u\"no matches\"", ")", ")" ]
Change number of match and total matches.
[ "Change", "number", "of", "match", "and", "total", "matches", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/findreplace.py#L585-L595
train
spyder-ide/spyder
spyder/utils/introspection/rope_patch.py
apply
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 raise ImportError("rope %s can't be patched" % rope.VERSION) # [1] Patching project.Project for compatibility with py2exe/cx_Freeze # distributions from spyder.config.base import is_py2exe_or_cx_Freeze if is_py2exe_or_cx_Freeze(): from rope.base import project class PatchedProject(project.Project): def _default_config(self): # py2exe/cx_Freeze distribution from spyder.config.base import get_module_source_path fname = get_module_source_path('spyder', 'default_config.py') return open(fname, 'rb').read() project.Project = PatchedProject # Patching pycore.PyCore... from rope.base import pycore class PatchedPyCore(pycore.PyCore): # [2] ...so that forced builtin modules (i.e. modules that were # declared as 'extension_modules' in rope preferences) will be indeed # recognized as builtins by rope, as expected # # This patch is included in rope 0.9.4+ but applying it anyway is ok def get_module(self, name, folder=None): """Returns a `PyObject` if the module was found.""" # check if this is a builtin module pymod = self._builtin_module(name) if pymod is not None: return pymod module = self.find_module(name, folder) if module is None: raise pycore.ModuleNotFoundError( 'Module %s not found' % name) return self.resource_to_pyobject(module) # [3] ...to avoid considering folders without __init__.py as Python # packages def _find_module_in_folder(self, folder, modname): module = folder packages = modname.split('.') for pkg in packages[:-1]: if module.is_folder() and module.has_child(pkg): module = module.get_child(pkg) else: return None if module.is_folder(): if module.has_child(packages[-1]) and \ module.get_child(packages[-1]).is_folder() and \ module.get_child(packages[-1]).has_child('__init__.py'): return module.get_child(packages[-1]) elif module.has_child(packages[-1] + '.py') and \ not module.get_child(packages[-1] + '.py').is_folder(): return module.get_child(packages[-1] + '.py') pycore.PyCore = PatchedPyCore # [2] Patching BuiltinName for the go to definition feature to simply work # with forced builtins from rope.base import builtins, libutils, pyobjects import inspect import os.path as osp class PatchedBuiltinName(builtins.BuiltinName): def _pycore(self): p = self.pyobject while p.parent is not None: p = p.parent if isinstance(p, builtins.BuiltinModule) and p.pycore is not None: return p.pycore def get_definition_location(self): if not inspect.isbuiltin(self.pyobject): _lines, lineno = inspect.getsourcelines(self.pyobject.builtin) path = inspect.getfile(self.pyobject.builtin) if path.endswith('pyc') and osp.isfile(path[:-1]): path = path[:-1] pycore = self._pycore() if pycore and pycore.project: resource = libutils.path_to_resource(pycore.project, path) module = pyobjects.PyModule(pycore, None, resource) return (module, lineno) return (None, None) builtins.BuiltinName = PatchedBuiltinName # [4] Patching several PyDocExtractor methods: # 1. get_doc: # To force rope to return the docstring of any object which has one, even # if it's not an instance of AbstractFunction, AbstractClass, or # AbstractModule. # Also, to use utils.dochelpers.getdoc to get docs from forced builtins. # # 2. _get_class_docstring and _get_single_function_docstring: # To not let rope add a 2 spaces indentation to every docstring, which was # breaking our rich text mode. The only value that we are modifying is the # 'indents' keyword of those methods, from 2 to 0. # # 3. get_calltip # To easily get calltips of forced builtins from rope.contrib import codeassist from spyder_kernels.utils.dochelpers import getdoc from rope.base import exceptions class PatchedPyDocExtractor(codeassist.PyDocExtractor): def get_builtin_doc(self, pyobject): buitin = pyobject.builtin return getdoc(buitin) def get_doc(self, pyobject): if hasattr(pyobject, 'builtin'): doc = self.get_builtin_doc(pyobject) return doc elif isinstance(pyobject, builtins.BuiltinModule): docstring = pyobject.get_doc() if docstring is not None: docstring = self._trim_docstring(docstring) else: docstring = '' # TODO: Add a module_name key, so that the name could appear # on the OI text filed but not be used by sphinx to render # the page doc = {'name': '', 'argspec': '', 'note': '', 'docstring': docstring } return doc elif isinstance(pyobject, pyobjects.AbstractFunction): return self._get_function_docstring(pyobject) elif isinstance(pyobject, pyobjects.AbstractClass): return self._get_class_docstring(pyobject) elif isinstance(pyobject, pyobjects.AbstractModule): return self._trim_docstring(pyobject.get_doc()) elif pyobject.get_doc() is not None: # Spyder patch return self._trim_docstring(pyobject.get_doc()) return None def get_calltip(self, pyobject, ignore_unknown=False, remove_self=False): if hasattr(pyobject, 'builtin'): doc = self.get_builtin_doc(pyobject) return doc['name'] + doc['argspec'] try: if isinstance(pyobject, pyobjects.AbstractClass): pyobject = pyobject['__init__'].get_object() if not isinstance(pyobject, pyobjects.AbstractFunction): pyobject = pyobject['__call__'].get_object() except exceptions.AttributeNotFoundError: return None if ignore_unknown and not isinstance(pyobject, pyobjects.PyFunction): return if isinstance(pyobject, pyobjects.AbstractFunction): result = self._get_function_signature(pyobject, add_module=True) if remove_self and self._is_method(pyobject): return result.replace('(self)', '()').replace('(self, ', '(') return result def _get_class_docstring(self, pyclass): contents = self._trim_docstring(pyclass.get_doc(), indents=0) supers = [super.get_name() for super in pyclass.get_superclasses()] doc = 'class %s(%s):\n\n' % (pyclass.get_name(), ', '.join(supers)) + contents if '__init__' in pyclass: init = pyclass['__init__'].get_object() if isinstance(init, pyobjects.AbstractFunction): doc += '\n\n' + self._get_single_function_docstring(init) return doc def _get_single_function_docstring(self, pyfunction): docs = pyfunction.get_doc() docs = self._trim_docstring(docs, indents=0) return docs codeassist.PyDocExtractor = PatchedPyDocExtractor # [5] Get the right matplotlib docstrings for Help try: import matplotlib as mpl mpl.rcParams['docstring.hardcopy'] = True except: pass
python
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 raise ImportError("rope %s can't be patched" % rope.VERSION) # [1] Patching project.Project for compatibility with py2exe/cx_Freeze # distributions from spyder.config.base import is_py2exe_or_cx_Freeze if is_py2exe_or_cx_Freeze(): from rope.base import project class PatchedProject(project.Project): def _default_config(self): # py2exe/cx_Freeze distribution from spyder.config.base import get_module_source_path fname = get_module_source_path('spyder', 'default_config.py') return open(fname, 'rb').read() project.Project = PatchedProject # Patching pycore.PyCore... from rope.base import pycore class PatchedPyCore(pycore.PyCore): # [2] ...so that forced builtin modules (i.e. modules that were # declared as 'extension_modules' in rope preferences) will be indeed # recognized as builtins by rope, as expected # # This patch is included in rope 0.9.4+ but applying it anyway is ok def get_module(self, name, folder=None): """Returns a `PyObject` if the module was found.""" # check if this is a builtin module pymod = self._builtin_module(name) if pymod is not None: return pymod module = self.find_module(name, folder) if module is None: raise pycore.ModuleNotFoundError( 'Module %s not found' % name) return self.resource_to_pyobject(module) # [3] ...to avoid considering folders without __init__.py as Python # packages def _find_module_in_folder(self, folder, modname): module = folder packages = modname.split('.') for pkg in packages[:-1]: if module.is_folder() and module.has_child(pkg): module = module.get_child(pkg) else: return None if module.is_folder(): if module.has_child(packages[-1]) and \ module.get_child(packages[-1]).is_folder() and \ module.get_child(packages[-1]).has_child('__init__.py'): return module.get_child(packages[-1]) elif module.has_child(packages[-1] + '.py') and \ not module.get_child(packages[-1] + '.py').is_folder(): return module.get_child(packages[-1] + '.py') pycore.PyCore = PatchedPyCore # [2] Patching BuiltinName for the go to definition feature to simply work # with forced builtins from rope.base import builtins, libutils, pyobjects import inspect import os.path as osp class PatchedBuiltinName(builtins.BuiltinName): def _pycore(self): p = self.pyobject while p.parent is not None: p = p.parent if isinstance(p, builtins.BuiltinModule) and p.pycore is not None: return p.pycore def get_definition_location(self): if not inspect.isbuiltin(self.pyobject): _lines, lineno = inspect.getsourcelines(self.pyobject.builtin) path = inspect.getfile(self.pyobject.builtin) if path.endswith('pyc') and osp.isfile(path[:-1]): path = path[:-1] pycore = self._pycore() if pycore and pycore.project: resource = libutils.path_to_resource(pycore.project, path) module = pyobjects.PyModule(pycore, None, resource) return (module, lineno) return (None, None) builtins.BuiltinName = PatchedBuiltinName # [4] Patching several PyDocExtractor methods: # 1. get_doc: # To force rope to return the docstring of any object which has one, even # if it's not an instance of AbstractFunction, AbstractClass, or # AbstractModule. # Also, to use utils.dochelpers.getdoc to get docs from forced builtins. # # 2. _get_class_docstring and _get_single_function_docstring: # To not let rope add a 2 spaces indentation to every docstring, which was # breaking our rich text mode. The only value that we are modifying is the # 'indents' keyword of those methods, from 2 to 0. # # 3. get_calltip # To easily get calltips of forced builtins from rope.contrib import codeassist from spyder_kernels.utils.dochelpers import getdoc from rope.base import exceptions class PatchedPyDocExtractor(codeassist.PyDocExtractor): def get_builtin_doc(self, pyobject): buitin = pyobject.builtin return getdoc(buitin) def get_doc(self, pyobject): if hasattr(pyobject, 'builtin'): doc = self.get_builtin_doc(pyobject) return doc elif isinstance(pyobject, builtins.BuiltinModule): docstring = pyobject.get_doc() if docstring is not None: docstring = self._trim_docstring(docstring) else: docstring = '' # TODO: Add a module_name key, so that the name could appear # on the OI text filed but not be used by sphinx to render # the page doc = {'name': '', 'argspec': '', 'note': '', 'docstring': docstring } return doc elif isinstance(pyobject, pyobjects.AbstractFunction): return self._get_function_docstring(pyobject) elif isinstance(pyobject, pyobjects.AbstractClass): return self._get_class_docstring(pyobject) elif isinstance(pyobject, pyobjects.AbstractModule): return self._trim_docstring(pyobject.get_doc()) elif pyobject.get_doc() is not None: # Spyder patch return self._trim_docstring(pyobject.get_doc()) return None def get_calltip(self, pyobject, ignore_unknown=False, remove_self=False): if hasattr(pyobject, 'builtin'): doc = self.get_builtin_doc(pyobject) return doc['name'] + doc['argspec'] try: if isinstance(pyobject, pyobjects.AbstractClass): pyobject = pyobject['__init__'].get_object() if not isinstance(pyobject, pyobjects.AbstractFunction): pyobject = pyobject['__call__'].get_object() except exceptions.AttributeNotFoundError: return None if ignore_unknown and not isinstance(pyobject, pyobjects.PyFunction): return if isinstance(pyobject, pyobjects.AbstractFunction): result = self._get_function_signature(pyobject, add_module=True) if remove_self and self._is_method(pyobject): return result.replace('(self)', '()').replace('(self, ', '(') return result def _get_class_docstring(self, pyclass): contents = self._trim_docstring(pyclass.get_doc(), indents=0) supers = [super.get_name() for super in pyclass.get_superclasses()] doc = 'class %s(%s):\n\n' % (pyclass.get_name(), ', '.join(supers)) + contents if '__init__' in pyclass: init = pyclass['__init__'].get_object() if isinstance(init, pyobjects.AbstractFunction): doc += '\n\n' + self._get_single_function_docstring(init) return doc def _get_single_function_docstring(self, pyfunction): docs = pyfunction.get_doc() docs = self._trim_docstring(docs, indents=0) return docs codeassist.PyDocExtractor = PatchedPyDocExtractor # [5] Get the right matplotlib docstrings for Help try: import matplotlib as mpl mpl.rcParams['docstring.hardcopy'] = True except: pass
[ "def", "apply", "(", ")", ":", "from", "spyder", ".", "utils", ".", "programs", "import", "is_module_installed", "if", "is_module_installed", "(", "'rope'", ",", "'<0.9.4'", ")", ":", "import", "rope", "raise", "ImportError", "(", "\"rope %s can't be patched\"", "%", "rope", ".", "VERSION", ")", "# [1] Patching project.Project for compatibility with py2exe/cx_Freeze\r", "# distributions\r", "from", "spyder", ".", "config", ".", "base", "import", "is_py2exe_or_cx_Freeze", "if", "is_py2exe_or_cx_Freeze", "(", ")", ":", "from", "rope", ".", "base", "import", "project", "class", "PatchedProject", "(", "project", ".", "Project", ")", ":", "def", "_default_config", "(", "self", ")", ":", "# py2exe/cx_Freeze distribution\r", "from", "spyder", ".", "config", ".", "base", "import", "get_module_source_path", "fname", "=", "get_module_source_path", "(", "'spyder'", ",", "'default_config.py'", ")", "return", "open", "(", "fname", ",", "'rb'", ")", ".", "read", "(", ")", "project", ".", "Project", "=", "PatchedProject", "# Patching pycore.PyCore...\r", "from", "rope", ".", "base", "import", "pycore", "class", "PatchedPyCore", "(", "pycore", ".", "PyCore", ")", ":", "# [2] ...so that forced builtin modules (i.e. modules that were \r", "# declared as 'extension_modules' in rope preferences) will be indeed\r", "# recognized as builtins by rope, as expected\r", "# \r", "# This patch is included in rope 0.9.4+ but applying it anyway is ok\r", "def", "get_module", "(", "self", ",", "name", ",", "folder", "=", "None", ")", ":", "\"\"\"Returns a `PyObject` if the module was found.\"\"\"", "# check if this is a builtin module\r", "pymod", "=", "self", ".", "_builtin_module", "(", "name", ")", "if", "pymod", "is", "not", "None", ":", "return", "pymod", "module", "=", "self", ".", "find_module", "(", "name", ",", "folder", ")", "if", "module", "is", "None", ":", "raise", "pycore", ".", "ModuleNotFoundError", "(", "'Module %s not found'", "%", "name", ")", "return", "self", ".", "resource_to_pyobject", "(", "module", ")", "# [3] ...to avoid considering folders without __init__.py as Python\r", "# packages\r", "def", "_find_module_in_folder", "(", "self", ",", "folder", ",", "modname", ")", ":", "module", "=", "folder", "packages", "=", "modname", ".", "split", "(", "'.'", ")", "for", "pkg", "in", "packages", "[", ":", "-", "1", "]", ":", "if", "module", ".", "is_folder", "(", ")", "and", "module", ".", "has_child", "(", "pkg", ")", ":", "module", "=", "module", ".", "get_child", "(", "pkg", ")", "else", ":", "return", "None", "if", "module", ".", "is_folder", "(", ")", ":", "if", "module", ".", "has_child", "(", "packages", "[", "-", "1", "]", ")", "and", "module", ".", "get_child", "(", "packages", "[", "-", "1", "]", ")", ".", "is_folder", "(", ")", "and", "module", ".", "get_child", "(", "packages", "[", "-", "1", "]", ")", ".", "has_child", "(", "'__init__.py'", ")", ":", "return", "module", ".", "get_child", "(", "packages", "[", "-", "1", "]", ")", "elif", "module", ".", "has_child", "(", "packages", "[", "-", "1", "]", "+", "'.py'", ")", "and", "not", "module", ".", "get_child", "(", "packages", "[", "-", "1", "]", "+", "'.py'", ")", ".", "is_folder", "(", ")", ":", "return", "module", ".", "get_child", "(", "packages", "[", "-", "1", "]", "+", "'.py'", ")", "pycore", ".", "PyCore", "=", "PatchedPyCore", "# [2] Patching BuiltinName for the go to definition feature to simply work \r", "# with forced builtins\r", "from", "rope", ".", "base", "import", "builtins", ",", "libutils", ",", "pyobjects", "import", "inspect", "import", "os", ".", "path", "as", "osp", "class", "PatchedBuiltinName", "(", "builtins", ".", "BuiltinName", ")", ":", "def", "_pycore", "(", "self", ")", ":", "p", "=", "self", ".", "pyobject", "while", "p", ".", "parent", "is", "not", "None", ":", "p", "=", "p", ".", "parent", "if", "isinstance", "(", "p", ",", "builtins", ".", "BuiltinModule", ")", "and", "p", ".", "pycore", "is", "not", "None", ":", "return", "p", ".", "pycore", "def", "get_definition_location", "(", "self", ")", ":", "if", "not", "inspect", ".", "isbuiltin", "(", "self", ".", "pyobject", ")", ":", "_lines", ",", "lineno", "=", "inspect", ".", "getsourcelines", "(", "self", ".", "pyobject", ".", "builtin", ")", "path", "=", "inspect", ".", "getfile", "(", "self", ".", "pyobject", ".", "builtin", ")", "if", "path", ".", "endswith", "(", "'pyc'", ")", "and", "osp", ".", "isfile", "(", "path", "[", ":", "-", "1", "]", ")", ":", "path", "=", "path", "[", ":", "-", "1", "]", "pycore", "=", "self", ".", "_pycore", "(", ")", "if", "pycore", "and", "pycore", ".", "project", ":", "resource", "=", "libutils", ".", "path_to_resource", "(", "pycore", ".", "project", ",", "path", ")", "module", "=", "pyobjects", ".", "PyModule", "(", "pycore", ",", "None", ",", "resource", ")", "return", "(", "module", ",", "lineno", ")", "return", "(", "None", ",", "None", ")", "builtins", ".", "BuiltinName", "=", "PatchedBuiltinName", "# [4] Patching several PyDocExtractor methods:\r", "# 1. get_doc:\r", "# To force rope to return the docstring of any object which has one, even\r", "# if it's not an instance of AbstractFunction, AbstractClass, or\r", "# AbstractModule.\r", "# Also, to use utils.dochelpers.getdoc to get docs from forced builtins.\r", "#\r", "# 2. _get_class_docstring and _get_single_function_docstring:\r", "# To not let rope add a 2 spaces indentation to every docstring, which was\r", "# breaking our rich text mode. The only value that we are modifying is the\r", "# 'indents' keyword of those methods, from 2 to 0.\r", "#\r", "# 3. get_calltip\r", "# To easily get calltips of forced builtins\r", "from", "rope", ".", "contrib", "import", "codeassist", "from", "spyder_kernels", ".", "utils", ".", "dochelpers", "import", "getdoc", "from", "rope", ".", "base", "import", "exceptions", "class", "PatchedPyDocExtractor", "(", "codeassist", ".", "PyDocExtractor", ")", ":", "def", "get_builtin_doc", "(", "self", ",", "pyobject", ")", ":", "buitin", "=", "pyobject", ".", "builtin", "return", "getdoc", "(", "buitin", ")", "def", "get_doc", "(", "self", ",", "pyobject", ")", ":", "if", "hasattr", "(", "pyobject", ",", "'builtin'", ")", ":", "doc", "=", "self", ".", "get_builtin_doc", "(", "pyobject", ")", "return", "doc", "elif", "isinstance", "(", "pyobject", ",", "builtins", ".", "BuiltinModule", ")", ":", "docstring", "=", "pyobject", ".", "get_doc", "(", ")", "if", "docstring", "is", "not", "None", ":", "docstring", "=", "self", ".", "_trim_docstring", "(", "docstring", ")", "else", ":", "docstring", "=", "''", "# TODO: Add a module_name key, so that the name could appear\r", "# on the OI text filed but not be used by sphinx to render\r", "# the page\r", "doc", "=", "{", "'name'", ":", "''", ",", "'argspec'", ":", "''", ",", "'note'", ":", "''", ",", "'docstring'", ":", "docstring", "}", "return", "doc", "elif", "isinstance", "(", "pyobject", ",", "pyobjects", ".", "AbstractFunction", ")", ":", "return", "self", ".", "_get_function_docstring", "(", "pyobject", ")", "elif", "isinstance", "(", "pyobject", ",", "pyobjects", ".", "AbstractClass", ")", ":", "return", "self", ".", "_get_class_docstring", "(", "pyobject", ")", "elif", "isinstance", "(", "pyobject", ",", "pyobjects", ".", "AbstractModule", ")", ":", "return", "self", ".", "_trim_docstring", "(", "pyobject", ".", "get_doc", "(", ")", ")", "elif", "pyobject", ".", "get_doc", "(", ")", "is", "not", "None", ":", "# Spyder patch\r", "return", "self", ".", "_trim_docstring", "(", "pyobject", ".", "get_doc", "(", ")", ")", "return", "None", "def", "get_calltip", "(", "self", ",", "pyobject", ",", "ignore_unknown", "=", "False", ",", "remove_self", "=", "False", ")", ":", "if", "hasattr", "(", "pyobject", ",", "'builtin'", ")", ":", "doc", "=", "self", ".", "get_builtin_doc", "(", "pyobject", ")", "return", "doc", "[", "'name'", "]", "+", "doc", "[", "'argspec'", "]", "try", ":", "if", "isinstance", "(", "pyobject", ",", "pyobjects", ".", "AbstractClass", ")", ":", "pyobject", "=", "pyobject", "[", "'__init__'", "]", ".", "get_object", "(", ")", "if", "not", "isinstance", "(", "pyobject", ",", "pyobjects", ".", "AbstractFunction", ")", ":", "pyobject", "=", "pyobject", "[", "'__call__'", "]", ".", "get_object", "(", ")", "except", "exceptions", ".", "AttributeNotFoundError", ":", "return", "None", "if", "ignore_unknown", "and", "not", "isinstance", "(", "pyobject", ",", "pyobjects", ".", "PyFunction", ")", ":", "return", "if", "isinstance", "(", "pyobject", ",", "pyobjects", ".", "AbstractFunction", ")", ":", "result", "=", "self", ".", "_get_function_signature", "(", "pyobject", ",", "add_module", "=", "True", ")", "if", "remove_self", "and", "self", ".", "_is_method", "(", "pyobject", ")", ":", "return", "result", ".", "replace", "(", "'(self)'", ",", "'()'", ")", ".", "replace", "(", "'(self, '", ",", "'('", ")", "return", "result", "def", "_get_class_docstring", "(", "self", ",", "pyclass", ")", ":", "contents", "=", "self", ".", "_trim_docstring", "(", "pyclass", ".", "get_doc", "(", ")", ",", "indents", "=", "0", ")", "supers", "=", "[", "super", ".", "get_name", "(", ")", "for", "super", "in", "pyclass", ".", "get_superclasses", "(", ")", "]", "doc", "=", "'class %s(%s):\\n\\n'", "%", "(", "pyclass", ".", "get_name", "(", ")", ",", "', '", ".", "join", "(", "supers", ")", ")", "+", "contents", "if", "'__init__'", "in", "pyclass", ":", "init", "=", "pyclass", "[", "'__init__'", "]", ".", "get_object", "(", ")", "if", "isinstance", "(", "init", ",", "pyobjects", ".", "AbstractFunction", ")", ":", "doc", "+=", "'\\n\\n'", "+", "self", ".", "_get_single_function_docstring", "(", "init", ")", "return", "doc", "def", "_get_single_function_docstring", "(", "self", ",", "pyfunction", ")", ":", "docs", "=", "pyfunction", ".", "get_doc", "(", ")", "docs", "=", "self", ".", "_trim_docstring", "(", "docs", ",", "indents", "=", "0", ")", "return", "docs", "codeassist", ".", "PyDocExtractor", "=", "PatchedPyDocExtractor", "# [5] Get the right matplotlib docstrings for Help\r", "try", ":", "import", "matplotlib", "as", "mpl", "mpl", ".", "rcParams", "[", "'docstring.hardcopy'", "]", "=", "True", "except", ":", "pass" ]
Monkey patching rope See [1], [2], [3], [4] and [5] in module docstring.
[ "Monkey", "patching", "rope", "See", "[", "1", "]", "[", "2", "]", "[", "3", "]", "[", "4", "]", "and", "[", "5", "]", "in", "module", "docstring", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/introspection/rope_patch.py#L30-L211
train
spyder-ide/spyder
spyder/plugins/editor/panels/indentationguides.py
IndentationGuide.paintEvent
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() for _, line_number, block in self.editor.visible_blocks: indentation = TextBlockHelper.get_fold_lvl(block) ref_lvl = indentation block = block.next() last_line = block.blockNumber() lvl = TextBlockHelper.get_fold_lvl(block) if ref_lvl == lvl: # for zone set programmatically such as imports # in pyqode.python ref_lvl -= 1 while (block.isValid() and TextBlockHelper.get_fold_lvl(block) > ref_lvl): last_line = block.blockNumber() block = block.next() end_of_sub_fold = block if last_line: block = block.document().findBlockByNumber(last_line) while ((block.blockNumber()) and (block.text().strip() == '' or block.text().strip().startswith('#'))): block = block.previous() last_line = block.blockNumber() block = self.editor.document().findBlockByNumber(line_number) top = int(self.editor.blockBoundingGeometry(block).translated( self.editor.contentOffset()).top()) bottom = top + int(self.editor.blockBoundingRect(block).height()) indentation = TextBlockHelper.get_fold_lvl(block) for i in range(1, indentation): if (line_number > last_line and TextBlockHelper.get_fold_lvl(end_of_sub_fold) <= i): continue else: x = self.editor.fontMetrics().width(i * self.i_width * '9') + offset painter.drawLine(x, top, x, bottom)
python
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() for _, line_number, block in self.editor.visible_blocks: indentation = TextBlockHelper.get_fold_lvl(block) ref_lvl = indentation block = block.next() last_line = block.blockNumber() lvl = TextBlockHelper.get_fold_lvl(block) if ref_lvl == lvl: # for zone set programmatically such as imports # in pyqode.python ref_lvl -= 1 while (block.isValid() and TextBlockHelper.get_fold_lvl(block) > ref_lvl): last_line = block.blockNumber() block = block.next() end_of_sub_fold = block if last_line: block = block.document().findBlockByNumber(last_line) while ((block.blockNumber()) and (block.text().strip() == '' or block.text().strip().startswith('#'))): block = block.previous() last_line = block.blockNumber() block = self.editor.document().findBlockByNumber(line_number) top = int(self.editor.blockBoundingGeometry(block).translated( self.editor.contentOffset()).top()) bottom = top + int(self.editor.blockBoundingRect(block).height()) indentation = TextBlockHelper.get_fold_lvl(block) for i in range(1, indentation): if (line_number > last_line and TextBlockHelper.get_fold_lvl(end_of_sub_fold) <= i): continue else: x = self.editor.fontMetrics().width(i * self.i_width * '9') + offset painter.drawLine(x, top, x, bottom)
[ "def", "paintEvent", "(", "self", ",", "event", ")", ":", "painter", "=", "QPainter", "(", "self", ")", "color", "=", "QColor", "(", "self", ".", "color", ")", "color", ".", "setAlphaF", "(", ".5", ")", "painter", ".", "setPen", "(", "color", ")", "offset", "=", "self", ".", "editor", ".", "document", "(", ")", ".", "documentMargin", "(", ")", "+", "self", ".", "editor", ".", "contentOffset", "(", ")", ".", "x", "(", ")", "for", "_", ",", "line_number", ",", "block", "in", "self", ".", "editor", ".", "visible_blocks", ":", "indentation", "=", "TextBlockHelper", ".", "get_fold_lvl", "(", "block", ")", "ref_lvl", "=", "indentation", "block", "=", "block", ".", "next", "(", ")", "last_line", "=", "block", ".", "blockNumber", "(", ")", "lvl", "=", "TextBlockHelper", ".", "get_fold_lvl", "(", "block", ")", "if", "ref_lvl", "==", "lvl", ":", "# for zone set programmatically such as imports", "# in pyqode.python", "ref_lvl", "-=", "1", "while", "(", "block", ".", "isValid", "(", ")", "and", "TextBlockHelper", ".", "get_fold_lvl", "(", "block", ")", ">", "ref_lvl", ")", ":", "last_line", "=", "block", ".", "blockNumber", "(", ")", "block", "=", "block", ".", "next", "(", ")", "end_of_sub_fold", "=", "block", "if", "last_line", ":", "block", "=", "block", ".", "document", "(", ")", ".", "findBlockByNumber", "(", "last_line", ")", "while", "(", "(", "block", ".", "blockNumber", "(", ")", ")", "and", "(", "block", ".", "text", "(", ")", ".", "strip", "(", ")", "==", "''", "or", "block", ".", "text", "(", ")", ".", "strip", "(", ")", ".", "startswith", "(", "'#'", ")", ")", ")", ":", "block", "=", "block", ".", "previous", "(", ")", "last_line", "=", "block", ".", "blockNumber", "(", ")", "block", "=", "self", ".", "editor", ".", "document", "(", ")", ".", "findBlockByNumber", "(", "line_number", ")", "top", "=", "int", "(", "self", ".", "editor", ".", "blockBoundingGeometry", "(", "block", ")", ".", "translated", "(", "self", ".", "editor", ".", "contentOffset", "(", ")", ")", ".", "top", "(", ")", ")", "bottom", "=", "top", "+", "int", "(", "self", ".", "editor", ".", "blockBoundingRect", "(", "block", ")", ".", "height", "(", ")", ")", "indentation", "=", "TextBlockHelper", ".", "get_fold_lvl", "(", "block", ")", "for", "i", "in", "range", "(", "1", ",", "indentation", ")", ":", "if", "(", "line_number", ">", "last_line", "and", "TextBlockHelper", ".", "get_fold_lvl", "(", "end_of_sub_fold", ")", "<=", "i", ")", ":", "continue", "else", ":", "x", "=", "self", ".", "editor", ".", "fontMetrics", "(", ")", ".", "width", "(", "i", "*", "self", ".", "i_width", "*", "'9'", ")", "+", "offset", "painter", ".", "drawLine", "(", "x", ",", "top", ",", "x", ",", "bottom", ")" ]
Override Qt method.
[ "Override", "Qt", "method", "." ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/panels/indentationguides.py#L32-L80
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.get_plugin_actions
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]
python
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]
[ "def", "get_plugin_actions", "(", "self", ")", ":", "return", "[", "self", ".", "rich_text_action", ",", "self", ".", "plain_text_action", ",", "self", ".", "show_source_action", ",", "MENU_SEPARATOR", ",", "self", ".", "auto_import_action", "]" ]
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/help/plugin.py#L212-L216
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.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) self.main.console.set_help(self) self.internal_shell = self.main.console.shell self.console = self.main.console
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) self.main.console.set_help(self) self.internal_shell = self.main.console.shell self.console = self.main.console
[ "def", "register_plugin", "(", "self", ")", ":", "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", ".", "console", ".", "shell", "self", ".", "console", "=", "self", ".", "main", ".", "console" ]
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/help/plugin.py#L218-L225
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.refresh_plugin
def refresh_plugin(self): """Refresh widget""" if self._starting_up: self._starting_up = False self.switch_to_rich_text() self.show_intro_message()
python
def refresh_plugin(self): """Refresh widget""" if self._starting_up: self._starting_up = False self.switch_to_rich_text() self.show_intro_message()
[ "def", "refresh_plugin", "(", "self", ")", ":", "if", "self", ".", "_starting_up", ":", "self", ".", "_starting_up", "=", "False", "self", ".", "switch_to_rich_text", "(", ")", "self", ".", "show_intro_message", "(", ")" ]
Refresh widget
[ "Refresh", "widget" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L231-L236
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.update_font
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) self.set_rich_text_font(rich_font)
python
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) self.set_rich_text_font(rich_font)
[ "def", "update_font", "(", "self", ")", ":", "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", ")", "self", ".", "set_rich_text_font", "(", "rich_font", ")" ]
Update font from Preferences
[ "Update", "font", "from", "Preferences" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L238-L245
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.apply_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 = self.get_option(wrap_n) self.wrap_action.setChecked(wrap_o) math_n = 'math' math_o = self.get_option(math_n) if color_scheme_n in options: self.set_plain_text_color_scheme(color_scheme_o) if wrap_n in options: self.toggle_wrap_mode(wrap_o) if math_n in options: self.toggle_math_mode(math_o) # To make auto-connection changes take place instantly self.main.editor.apply_plugin_settings(options=[connect_n]) self.main.ipyconsole.apply_plugin_settings(options=[connect_n])
python
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 = self.get_option(wrap_n) self.wrap_action.setChecked(wrap_o) math_n = 'math' math_o = self.get_option(math_n) if color_scheme_n in options: self.set_plain_text_color_scheme(color_scheme_o) if wrap_n in options: self.toggle_wrap_mode(wrap_o) if math_n in options: self.toggle_math_mode(math_o) # To make auto-connection changes take place instantly self.main.editor.apply_plugin_settings(options=[connect_n]) self.main.ipyconsole.apply_plugin_settings(options=[connect_n])
[ "def", "apply_plugin_settings", "(", "self", ",", "options", ")", ":", "color_scheme_n", "=", "'color_scheme_name'", "color_scheme_o", "=", "self", ".", "get_color_scheme", "(", ")", "connect_n", "=", "'connect_to_oi'", "wrap_n", "=", "'wrap'", "wrap_o", "=", "self", ".", "get_option", "(", "wrap_n", ")", "self", ".", "wrap_action", ".", "setChecked", "(", "wrap_o", ")", "math_n", "=", "'math'", "math_o", "=", "self", ".", "get_option", "(", "math_n", ")", "if", "color_scheme_n", "in", "options", ":", "self", ".", "set_plain_text_color_scheme", "(", "color_scheme_o", ")", "if", "wrap_n", "in", "options", ":", "self", ".", "toggle_wrap_mode", "(", "wrap_o", ")", "if", "math_n", "in", "options", ":", "self", ".", "toggle_math_mode", "(", "math_o", ")", "# To make auto-connection changes take place instantly\r", "self", ".", "main", ".", "editor", ".", "apply_plugin_settings", "(", "options", "=", "[", "connect_n", "]", ")", "self", ".", "main", ".", "ipyconsole", ".", "apply_plugin_settings", "(", "options", "=", "[", "connect_n", "]", ")" ]
Apply configuration file's plugin settings
[ "Apply", "configuration", "file", "s", "plugin", "settings" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L247-L267
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.set_rich_text_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())
python
def set_rich_text_font(self, font): """Set rich text mode font""" self.rich_text.set_font(font, fixed_font=self.get_plugin_font())
[ "def", "set_rich_text_font", "(", "self", ",", "font", ")", ":", "self", ".", "rich_text", ".", "set_font", "(", "font", ",", "fixed_font", "=", "self", ".", "get_plugin_font", "(", ")", ")" ]
Set rich text mode font
[ "Set", "rich", "text", "mode", "font" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L328-L330
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.set_plain_text_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)
python
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)
[ "def", "set_plain_text_font", "(", "self", ",", "font", ",", "color_scheme", "=", "None", ")", ":", "self", ".", "plain_text", ".", "set_font", "(", "font", ",", "color_scheme", "=", "color_scheme", ")" ]
Set plain text mode font
[ "Set", "plain", "text", "mode", "font" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L332-L334
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.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)
python
def toggle_wrap_mode(self, checked): """Toggle wrap mode""" self.plain_text.editor.toggle_wrap_mode(checked) self.set_option('wrap', checked)
[ "def", "toggle_wrap_mode", "(", "self", ",", "checked", ")", ":", "self", ".", "plain_text", ".", "editor", ".", "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/help/plugin.py#L341-L344
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.switch_to_plain_text
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)
python
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)
[ "def", "switch_to_plain_text", "(", "self", ")", ":", "self", ".", "rich_help", "=", "False", "self", ".", "plain_text", ".", "show", "(", ")", "self", ".", "rich_text", ".", "hide", "(", ")", "self", ".", "plain_text_action", ".", "setChecked", "(", "True", ")" ]
Switch to plain text mode
[ "Switch", "to", "plain", "text", "mode" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L358-L363
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.switch_to_rich_text
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)
python
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)
[ "def", "switch_to_rich_text", "(", "self", ")", ":", "self", ".", "rich_help", "=", "True", "self", ".", "plain_text", ".", "hide", "(", ")", "self", ".", "rich_text", ".", "show", "(", ")", "self", ".", "rich_text_action", ".", "setChecked", "(", "True", ")", "self", ".", "show_source_action", ".", "setChecked", "(", "False", ")" ]
Switch to rich text mode
[ "Switch", "to", "rich", "text", "mode" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L365-L371
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.set_plain_text
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_title = '' if text['argspec']: definition = ''.join(['Definition: ', name, text['argspec'], '\n']) else: definition = '' if text['note']: note = ''.join(['Type: ', text['note'], '\n\n----\n\n']) else: note = '' full_text = ''.join([rst_title, definition, note, text['docstring']]) else: full_text = text self.plain_text.set_text(full_text, is_code) self.save_text([self.plain_text.set_text, full_text, is_code])
python
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_title = '' if text['argspec']: definition = ''.join(['Definition: ', name, text['argspec'], '\n']) else: definition = '' if text['note']: note = ''.join(['Type: ', text['note'], '\n\n----\n\n']) else: note = '' full_text = ''.join([rst_title, definition, note, text['docstring']]) else: full_text = text self.plain_text.set_text(full_text, is_code) self.save_text([self.plain_text.set_text, full_text, is_code])
[ "def", "set_plain_text", "(", "self", ",", "text", ",", "is_code", ")", ":", "# text is coming from utils.dochelpers.getdoc\r", "if", "type", "(", "text", ")", "is", "dict", ":", "name", "=", "text", "[", "'name'", "]", "if", "name", ":", "rst_title", "=", "''", ".", "join", "(", "[", "'='", "*", "len", "(", "name", ")", ",", "'\\n'", ",", "name", ",", "'\\n'", ",", "'='", "*", "len", "(", "name", ")", ",", "'\\n\\n'", "]", ")", "else", ":", "rst_title", "=", "''", "if", "text", "[", "'argspec'", "]", ":", "definition", "=", "''", ".", "join", "(", "[", "'Definition: '", ",", "name", ",", "text", "[", "'argspec'", "]", ",", "'\\n'", "]", ")", "else", ":", "definition", "=", "''", "if", "text", "[", "'note'", "]", ":", "note", "=", "''", ".", "join", "(", "[", "'Type: '", ",", "text", "[", "'note'", "]", ",", "'\\n\\n----\\n\\n'", "]", ")", "else", ":", "note", "=", "''", "full_text", "=", "''", ".", "join", "(", "[", "rst_title", ",", "definition", ",", "note", ",", "text", "[", "'docstring'", "]", "]", ")", "else", ":", "full_text", "=", "text", "self", ".", "plain_text", ".", "set_text", "(", "full_text", ",", "is_code", ")", "self", ".", "save_text", "(", "[", "self", ".", "plain_text", ".", "set_text", ",", "full_text", ",", "is_code", "]", ")" ]
Set plain text docs
[ "Set", "plain", "text", "docs" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L373-L402
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.set_rich_text_html
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])
python
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])
[ "def", "set_rich_text_html", "(", "self", ",", "html_text", ",", "base_url", ")", ":", "self", ".", "rich_text", ".", "set_html", "(", "html_text", ",", "base_url", ")", "self", ".", "save_text", "(", "[", "self", ".", "rich_text", ".", "set_html", ",", "html_text", ",", "base_url", "]", ")" ]
Set rich text
[ "Set", "rich", "text" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L404-L407
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.show_rich_text
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)
python
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)
[ "def", "show_rich_text", "(", "self", ",", "text", ",", "collapse", "=", "False", ",", "img_path", "=", "''", ")", ":", "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", ")" ]
Show text in rich mode
[ "Show", "text", "in", "rich", "mode" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L440-L446
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.show_plain_text
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)
python
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)
[ "def", "show_plain_text", "(", "self", ",", "text", ")", ":", "self", ".", "switch_to_plugin", "(", ")", "self", ".", "switch_to_plain_text", "(", ")", "self", ".", "set_plain_text", "(", "text", ",", "is_code", "=", "False", ")" ]
Show text in plain mode
[ "Show", "text", "in", "plain", "mode" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L448-L452
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.show_tutorial
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)
python
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)
[ "def", "show_tutorial", "(", "self", ")", ":", "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", ")" ]
Show the Spyder tutorial in the Help plugin, opening it if needed
[ "Show", "the", "Spyder", "tutorial", "in", "the", "Help", "plugin", "opening", "it", "if", "needed" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L455-L461
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.set_object_text
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=ignore_unknown) if ignore_unknown and not found: return if add_to_combo: self.combo.add_text(text) if found: self.save_history() if self.dockwidget is not None: self.dockwidget.blockSignals(True) self.__eventually_raise_help(text, force=force_refresh) if self.dockwidget is not None: self.dockwidget.blockSignals(False)
python
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=ignore_unknown) if ignore_unknown and not found: return if add_to_combo: self.combo.add_text(text) if found: self.save_history() if self.dockwidget is not None: self.dockwidget.blockSignals(True) self.__eventually_raise_help(text, force=force_refresh) if self.dockwidget is not None: self.dockwidget.blockSignals(False)
[ "def", "set_object_text", "(", "self", ",", "text", ",", "force_refresh", "=", "False", ",", "ignore_unknown", "=", "False", ")", ":", "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", "=", "ignore_unknown", ")", "if", "ignore_unknown", "and", "not", "found", ":", "return", "if", "add_to_combo", ":", "self", ".", "combo", ".", "add_text", "(", "text", ")", "if", "found", ":", "self", ".", "save_history", "(", ")", "if", "self", ".", "dockwidget", "is", "not", "None", ":", "self", ".", "dockwidget", ".", "blockSignals", "(", "True", ")", "self", ".", "__eventually_raise_help", "(", "text", ",", "force", "=", "force_refresh", ")", "if", "self", ".", "dockwidget", "is", "not", "None", ":", "self", ".", "dockwidget", ".", "blockSignals", "(", "False", ")" ]
Set object analyzed by Help
[ "Set", "object", "analyzed", "by", "Help" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L483-L507
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.set_editor_doc
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 """ 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, is_code=False) if self.dockwidget is not None: self.dockwidget.blockSignals(True) self.__eventually_raise_help(doc['docstring'], force=force_refresh) if self.dockwidget is not None: self.dockwidget.blockSignals(False)
python
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 """ 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, is_code=False) if self.dockwidget is not None: self.dockwidget.blockSignals(True) self.__eventually_raise_help(doc['docstring'], force=force_refresh) if self.dockwidget is not None: self.dockwidget.blockSignals(False)
[ "def", "set_editor_doc", "(", "self", ",", "doc", ",", "force_refresh", "=", "False", ")", ":", "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", ",", "is_code", "=", "False", ")", "if", "self", ".", "dockwidget", "is", "not", "None", ":", "self", ".", "dockwidget", ".", "blockSignals", "(", "True", ")", "self", ".", "__eventually_raise_help", "(", "doc", "[", "'docstring'", "]", ",", "force", "=", "force_refresh", ")", "if", "self", ".", "dockwidget", "is", "not", "None", ":", "self", ".", "dockwidget", ".", "blockSignals", "(", "False", ")" ]
Use the help plugin to show docstring dictionary computed with introspection plugin from the Editor plugin
[ "Use", "the", "help", "plugin", "to", "show", "docstring", "dictionary", "computed", "with", "introspection", "plugin", "from", "the", "Editor", "plugin" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L509-L529
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.load_history
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()] else: history = [] return history
python
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()] else: history = [] return history
[ "def", "load_history", "(", "self", ",", "obj", "=", "None", ")", ":", "if", "osp", ".", "isfile", "(", "self", ".", "LOG_PATH", ")", ":", "history", "=", "[", "line", ".", "replace", "(", "'\\n'", ",", "''", ")", "for", "line", "in", "open", "(", "self", ".", "LOG_PATH", ",", "'r'", ")", ".", "readlines", "(", ")", "]", "else", ":", "history", "=", "[", "]", "return", "history" ]
Load history from a text file in user home directory
[ "Load", "history", "from", "a", "text", "file", "in", "user", "home", "directory" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L545-L552
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.save_history
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)) for index in range(self.combo.count())] search_history = '\n'.join(search_history) open(self.LOG_PATH, 'w').write(search_history) except (UnicodeEncodeError, UnicodeDecodeError, EnvironmentError): pass
python
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)) for index in range(self.combo.count())] search_history = '\n'.join(search_history) open(self.LOG_PATH, 'w').write(search_history) except (UnicodeEncodeError, UnicodeDecodeError, EnvironmentError): pass
[ "def", "save_history", "(", "self", ")", ":", "# Don't fail when saving search history to disk\r", "# See issues 8878 and 6864\r", "try", ":", "search_history", "=", "[", "to_text_string", "(", "self", ".", "combo", ".", "itemText", "(", "index", ")", ")", "for", "index", "in", "range", "(", "self", ".", "combo", ".", "count", "(", ")", ")", "]", "search_history", "=", "'\\n'", ".", "join", "(", "search_history", ")", "open", "(", "self", ".", "LOG_PATH", ",", "'w'", ")", ".", "write", "(", "search_history", ")", "except", "(", "UnicodeEncodeError", ",", "UnicodeDecodeError", ",", "EnvironmentError", ")", ":", "pass" ]
Save history to a text file in user home directory
[ "Save", "history", "to", "a", "text", "file", "in", "user", "home", "directory" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L554-L564
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.toggle_plain_text
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)
python
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)
[ "def", "toggle_plain_text", "(", "self", ",", "checked", ")", ":", "if", "checked", ":", "self", ".", "docstring", "=", "checked", "self", ".", "switch_to_plain_text", "(", ")", "self", ".", "force_refresh", "(", ")", "self", ".", "set_option", "(", "'rich_mode'", ",", "not", "checked", ")" ]
Toggle plain text docstring
[ "Toggle", "plain", "text", "docstring" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L567-L573
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.toggle_show_source
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)
python
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)
[ "def", "toggle_show_source", "(", "self", ",", "checked", ")", ":", "if", "checked", ":", "self", ".", "switch_to_plain_text", "(", ")", "self", ".", "docstring", "=", "not", "checked", "self", ".", "force_refresh", "(", ")", "self", ".", "set_option", "(", "'rich_mode'", ",", "not", "checked", ")" ]
Toggle show source code
[ "Toggle", "show", "source", "code" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L576-L582
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.toggle_rich_text
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)
python
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)
[ "def", "toggle_rich_text", "(", "self", ",", "checked", ")", ":", "if", "checked", ":", "self", ".", "docstring", "=", "not", "checked", "self", ".", "switch_to_rich_text", "(", ")", "self", ".", "set_option", "(", "'rich_mode'", ",", "checked", ")" ]
Toggle between sphinxified docstrings or plain ones
[ "Toggle", "between", "sphinxified", "docstrings", "or", "plain", "ones" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L585-L590
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.toggle_auto_import
def toggle_auto_import(self, checked): """Toggle automatic import feature""" self.combo.validate_current_text() self.set_option('automatic_import', checked) self.force_refresh()
python
def toggle_auto_import(self, checked): """Toggle automatic import feature""" self.combo.validate_current_text() self.set_option('automatic_import', checked) self.force_refresh()
[ "def", "toggle_auto_import", "(", "self", ",", "checked", ")", ":", "self", ".", "combo", ".", "validate_current_text", "(", ")", "self", ".", "set_option", "(", "'automatic_import'", ",", "checked", ")", "self", ".", "force_refresh", "(", ")" ]
Toggle automatic import feature
[ "Toggle", "automatic", "import", "feature" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L593-L597
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help._update_lock_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)
python
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)
[ "def", "_update_lock_icon", "(", "self", ")", ":", "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", ")" ]
Update locked state icon
[ "Update", "locked", "state", "icon" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L608-L613
train
spyder-ide/spyder
spyder/plugins/help/plugin.py
Help.get_shell
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() if shell is not None and shell.kernel_client is not None: self.shell = shell if self.shell is None: self.shell = self.internal_shell return self.shell
python
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() if shell is not None and shell.kernel_client is not None: self.shell = shell if self.shell is None: self.shell = self.internal_shell return self.shell
[ "def", "get_shell", "(", "self", ")", ":", "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", "(", ")", "if", "shell", "is", "not", "None", "and", "shell", ".", "kernel_client", "is", "not", "None", ":", "self", ".", "shell", "=", "shell", "if", "self", ".", "shell", "is", "None", ":", "self", ".", "shell", "=", "self", ".", "internal_shell", "return", "self", ".", "shell" ]
Return shell which is currently bound to Help, or another running shell if it has been terminated
[ "Return", "shell", "which", "is", "currently", "bound", "to", "Help", "or", "another", "running", "shell", "if", "it", "has", "been", "terminated" ]
f76836ce1b924bcc4efd3f74f2960d26a4e528e0
https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/help/plugin.py#L619-L634
train