本文整理汇总了Python中qtpy.QtWidgets.QLineEdit.setReadOnly方法的典型用法代码示例。如果您正苦于以下问题:Python QLineEdit.setReadOnly方法的具体用法?Python QLineEdit.setReadOnly怎么用?Python QLineEdit.setReadOnly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QLineEdit
的用法示例。
在下文中一共展示了QLineEdit.setReadOnly方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RegionOfInterestWidget
# 需要导入模块: from qtpy.QtWidgets import QLineEdit [as 别名]
# 或者: from qtpy.QtWidgets.QLineEdit import setReadOnly [as 别名]
class RegionOfInterestWidget(_ConditionWidget):
def __init__(self, parent=None):
_ConditionWidget.__init__(self, RegionOfInterest, parent)
def _init_ui(self):
# Widgets
validator = QIntValidator()
validator.setBottom(0)
self._txt_start_channel = QLineEdit()
self._txt_start_channel.setValidator(validator)
self._txt_start_channel.setAccessibleName('Start channel')
self._txt_end_channel = QLineEdit()
self._txt_end_channel.setValidator(validator)
self._txt_end_channel.setAccessibleName("End channel")
# Layouts
layout = _ConditionWidget._init_ui(self)
layout.addRow('<i>Start channel</i>', self._txt_start_channel)
layout.addRow('<i>End channel</i>', self._txt_end_channel)
# Signals
self._txt_start_channel.textEdited.connect(self.edited)
self._txt_end_channel.textEdited.connect(self.edited)
return layout
def _create_parameter(self):
return self.CLASS(0, 1)
def parameter(self, parameter=None):
parameter = _ConditionWidget.parameter(self, parameter)
parameter.channels = (int(self._txt_start_channel.text()),
int(self._txt_end_channel.text()))
return parameter
def setParameter(self, condition):
_ConditionWidget.setParameter(self, condition)
self._txt_start_channel.setText(str(condition.start_channel))
self._txt_end_channel.setText(str(condition.end_channel))
def setReadOnly(self, state):
_ConditionWidget.setReadOnly(self, state)
self._txt_start_channel.setReadOnly(state)
self._txt_end_channel.setReadOnly(state)
def isReadOnly(self):
return _ConditionWidget.isReadOnly(self) and \
self._txt_start_channel.isReadOnly() and \
self._txt_end_channel.isReadOnly()
def hasAcceptableInput(self):
return _ConditionWidget.hasAcceptableInput(self) and \
self._txt_start_channel.hasAcceptableInput() and \
self._txt_end_channel.hasAcceptableInput()
示例2: Help
# 需要导入模块: from qtpy.QtWidgets import QLineEdit [as 别名]
# 或者: from qtpy.QtWidgets.QLineEdit import setReadOnly [as 别名]
class Help(SpyderPluginWidget):
"""
Docstrings viewer widget
"""
CONF_SECTION = 'help'
CONFIGWIDGET_CLASS = HelpConfigPage
LOG_PATH = get_conf_path(CONF_SECTION)
FONT_SIZE_DELTA = DEFAULT_SMALL_DELTA
# Signals
focus_changed = Signal()
def __init__(self, parent):
if PYQT5:
SpyderPluginWidget.__init__(self, parent, main = parent)
else:
SpyderPluginWidget.__init__(self, parent)
self.internal_shell = None
# Initialize plugin
self.initialize_plugin()
self.no_doc_string = _("No further documentation available")
self._last_console_cb = None
self._last_editor_cb = None
self.plain_text = PlainText(self)
self.rich_text = RichText(self)
color_scheme = self.get_color_scheme()
self.set_plain_text_font(self.get_plugin_font(), color_scheme)
self.plain_text.editor.toggle_wrap_mode(self.get_option('wrap'))
# Add entries to read-only editor context-menu
self.wrap_action = create_action(self, _("Wrap lines"),
toggled=self.toggle_wrap_mode)
self.wrap_action.setChecked(self.get_option('wrap'))
self.plain_text.editor.readonly_menu.addSeparator()
add_actions(self.plain_text.editor.readonly_menu, (self.wrap_action,))
self.set_rich_text_font(self.get_plugin_font('rich_text'))
self.shell = None
self.external_console = None
# locked = disable link with Console
self.locked = False
self._last_texts = [None, None]
self._last_editor_doc = None
# Object name
layout_edit = QHBoxLayout()
layout_edit.setContentsMargins(0, 0, 0, 0)
txt = _("Source")
if sys.platform == 'darwin':
source_label = QLabel(" " + txt)
else:
source_label = QLabel(txt)
layout_edit.addWidget(source_label)
self.source_combo = QComboBox(self)
self.source_combo.addItems([_("Console"), _("Editor")])
self.source_combo.currentIndexChanged.connect(self.source_changed)
if (not programs.is_module_installed('rope') and
not programs.is_module_installed('jedi', '>=0.8.1')):
self.source_combo.hide()
source_label.hide()
layout_edit.addWidget(self.source_combo)
layout_edit.addSpacing(10)
layout_edit.addWidget(QLabel(_("Object")))
self.combo = ObjectComboBox(self)
layout_edit.addWidget(self.combo)
self.object_edit = QLineEdit(self)
self.object_edit.setReadOnly(True)
layout_edit.addWidget(self.object_edit)
self.combo.setMaxCount(self.get_option('max_history_entries'))
self.combo.addItems( self.load_history() )
self.combo.setItemText(0, '')
self.combo.valid.connect(lambda valid: self.force_refresh())
# Plain text docstring option
self.docstring = True
self.rich_help = self.get_option('rich_mode', True)
self.plain_text_action = create_action(self, _("Plain Text"),
toggled=self.toggle_plain_text)
# Source code option
self.show_source_action = create_action(self, _("Show Source"),
toggled=self.toggle_show_source)
# Rich text option
self.rich_text_action = create_action(self, _("Rich Text"),
toggled=self.toggle_rich_text)
# Add the help actions to an exclusive QActionGroup
help_actions = QActionGroup(self)
help_actions.setExclusive(True)
help_actions.addAction(self.plain_text_action)
#.........这里部分代码省略.........
示例3: PlotNameWidget
# 需要导入模块: from qtpy.QtWidgets import QLineEdit [as 别名]
# 或者: from qtpy.QtWidgets.QLineEdit import setReadOnly [as 别名]
class PlotNameWidget(QWidget):
"""A widget to display the plot name, and edit and close buttons
This widget is added to the table widget to support the renaming
and close buttons, as well as the direct renaming functionality.
"""
def __init__(self, presenter, plot_number, parent=None):
super(PlotNameWidget, self).__init__(parent)
self.presenter = presenter
self.plot_number = plot_number
self.mutex = QMutex()
self.line_edit = QLineEdit(self.presenter.get_plot_name_from_number(plot_number))
self.line_edit.setReadOnly(True)
self.line_edit.setFrame(False)
self.line_edit.setStyleSheet("* { background-color: rgba(0, 0, 0, 0); }")
self.line_edit.setAttribute(Qt.WA_TransparentForMouseEvents, True)
self.line_edit.editingFinished.connect(self.rename_plot)
shown_icon = get_icon('mdi.eye')
self.hide_button = QPushButton(shown_icon, "")
self.hide_button.setToolTip('Hide')
self.hide_button.setFlat(True)
self.hide_button.setMaximumWidth(self.hide_button.iconSize().width() * 5 / 3)
self.hide_button.clicked.connect(self.toggle_visibility)
rename_icon = get_icon('mdi.square-edit-outline')
self.rename_button = QPushButton(rename_icon, "")
self.rename_button.setToolTip('Rename')
self.rename_button.setFlat(True)
self.rename_button.setMaximumWidth(self.rename_button.iconSize().width() * 5 / 3)
self.rename_button.setCheckable(True)
self.rename_button.toggled.connect(self.rename_button_toggled)
close_icon = get_icon('mdi.close')
self.close_button = QPushButton(close_icon, "")
self.close_button.setToolTip('Delete')
self.close_button.setFlat(True)
self.close_button.setMaximumWidth(self.close_button.iconSize().width() * 5 / 3)
self.close_button.clicked.connect(lambda: self.close_pressed(self.plot_number))
self.layout = QHBoxLayout()
# Get rid of the top and bottom margins - the button provides
# some natural margin anyway. Get rid of right margin and
# reduce spacing to get buttons closer together.
self.layout.setContentsMargins(5, 0, 0, 0)
self.layout.setSpacing(0)
self.layout.addWidget(self.line_edit)
self.layout.addWidget(self.hide_button)
self.layout.addWidget(self.rename_button)
self.layout.addWidget(self.close_button)
self.layout.sizeHint()
self.setLayout(self.layout)
def set_plot_name(self, new_name):
"""
Sets the internally stored and displayed plot name
:param new_name: The name to set
"""
self.line_edit.setText(new_name)
def close_pressed(self, plot_number):
"""
Close the plot with the given name
:param plot_number: The unique number in GlobalFigureManager
"""
self.presenter.close_single_plot(plot_number)
def rename_button_toggled(self, checked):
"""
If the rename button is pressed from being unchecked then
make the line edit item editable
:param checked: True if the rename toggle is now pressed
"""
if checked:
self.toggle_plot_name_editable(True, toggle_rename_button=False)
def toggle_plot_name_editable(self, editable, toggle_rename_button=True):
"""
Set the line edit item to be editable or not editable. If
editable move the cursor focus to the editable name and
highlight it all.
:param editable: If true make the plot name editable, else
make it read only
:param toggle_rename_button: If true also toggle the rename
button state
"""
self.line_edit.setReadOnly(not editable)
self.line_edit.setAttribute(Qt.WA_TransparentForMouseEvents, not editable)
# This is a sneaky way to avoid the issue of two calls to
# this toggle method, by effectively disabling the button
# press in edit mode.
self.rename_button.setAttribute(Qt.WA_TransparentForMouseEvents, editable)
#.........这里部分代码省略.........
示例4: render_data
# 需要导入模块: from qtpy.QtWidgets import QLineEdit [as 别名]
# 或者: from qtpy.QtWidgets.QLineEdit import setReadOnly [as 别名]
def render_data(self, row, spec1d_data=None, spec2d_data=None,
image_data=None, level2_data=None):
"""
Render the updated data sets in the individual plot widgets within the
MOSViz viewer.
"""
self._check_unsaved_comments()
self.image_viewer_hidden = image_data is None
if spec1d_data is not None:
# TODO: This should not be needed. Must explore why the core model
# is out of sync with the proxy model.
self.spectrum1d_widget.plot_widget.clear_plots()
# Clear the specviz model of any rendered plot items
self._specviz_viewer.model.clear()
# Create a new Spectrum1D object from the flux data attribute of
# the incoming data
spec = glue_data_to_spectrum1d(spec1d_data, 'Flux')
# Create a DataItem from the Spectrum1D object, which adds the data
# to the internel specviz model
data_item = self._specviz_viewer.model.add_data(spec, 'Spectrum1D')
# Get the PlotDataItem rendered via the plot's proxy model and
# ensure that it is visible in the plot
plot_data_item = self.spectrum1d_widget.proxy_model.item_from_id(data_item.identifier)
plot_data_item.visible = True
plot_data_item.color = "#000000"
# Explicitly let the plot widget know that data items have changed
self.spectrum1d_widget.plot_widget.on_item_changed(data_item)
if not self.image_viewer_hidden:
if not self.image_widget.isVisible():
self.image_widget.setVisible(True)
wcs = image_data.coords.wcs
self.cutout_wcs = wcs
array = image_data.get_component(image_data.id['Flux']).data
# Add the slit patch to the plot
self.slit_controller.clear_slits()
if "slit_width" in self.catalog.meta["special_columns"] and \
"slit_length" in self.catalog.meta["special_columns"] and \
wcs is not None:
self.add_slit(row)
self.image_widget.draw_slit()
else:
self.image_widget.reset_limits()
self.image_widget.set_image(array, wcs=wcs, interpolation='none', origin='lower')
self.image_widget.axes.set_xlabel("Spatial X")
self.image_widget.axes.set_ylabel("Spatial Y")
if self.slit_controller.has_slits:
self.image_widget.set_slit_limits()
self.image_widget._redraw()
else:
self.cutout_wcs = None
# Plot the 2D spectrum data last because by then we can make sure that
# we set up the extent of the image appropriately if the cutout and the
# 1D spectrum are present so that the axes can be locked.
# We are repurposing the spectrum 2d widget to handle the display of both
# the level 3 and level 2 spectra.
if spec2d_data is not None or level2_data is not None:
self._load_spectrum2d_widget(spec2d_data, level2_data)
else:
self.spectrum2d_widget.no_data()
# Clear the meta information widget
# NOTE: this process is inefficient
for i in range(self.meta_form_layout.count()):
wid = self.meta_form_layout.itemAt(i).widget()
label = self.meta_form_layout.labelForField(wid)
if label is not None:
label.deleteLater()
wid.deleteLater()
# Repopulate the form layout
# NOTE: this process is inefficient
for col in row.colnames:
if col.lower() not in ["comments", "flag"]:
line_edit = QLineEdit(str(row[col]),
self.central_widget.meta_form_widget)
line_edit.setReadOnly(True)
self.meta_form_layout.addRow(col, line_edit)
# Set up comment and flag input/display boxes
if self.comments:
if self.savepath is not None:
if self.savepath == -1:
#.........这里部分代码省略.........
示例5: ProjectDialog
# 需要导入模块: from qtpy.QtWidgets import QLineEdit [as 别名]
# 或者: from qtpy.QtWidgets.QLineEdit import setReadOnly [as 别名]
class ProjectDialog(QDialog):
"""Project creation dialog."""
# path, type, packages
sig_project_creation_requested = Signal(object, object, object)
def __init__(self, parent):
"""Project creation dialog."""
super(ProjectDialog, self).__init__(parent=parent)
# Variables
current_python_version = '.'.join([to_text_string(sys.version_info[0]),
to_text_string(sys.version_info[1])])
python_versions = ['2.7', '3.4', '3.5']
if current_python_version not in python_versions:
python_versions.append(current_python_version)
python_versions = sorted(python_versions)
self.project_name = None
self.location = get_home_dir()
# Widgets
self.groupbox = QGroupBox()
self.radio_new_dir = QRadioButton(_("New directory"))
self.radio_from_dir = QRadioButton(_("Existing directory"))
self.label_project_name = QLabel(_('Project name'))
self.label_location = QLabel(_('Location'))
self.label_project_type = QLabel(_('Project type'))
self.label_python_version = QLabel(_('Python version'))
self.text_project_name = QLineEdit()
self.text_location = QLineEdit(get_home_dir())
self.combo_project_type = QComboBox()
self.combo_python_version = QComboBox()
self.button_select_location = QToolButton()
self.button_cancel = QPushButton(_('Cancel'))
self.button_create = QPushButton(_('Create'))
self.bbox = QDialogButtonBox(Qt.Horizontal)
self.bbox.addButton(self.button_cancel, QDialogButtonBox.ActionRole)
self.bbox.addButton(self.button_create, QDialogButtonBox.ActionRole)
# Widget setup
self.combo_python_version.addItems(python_versions)
self.radio_new_dir.setChecked(True)
self.text_location.setEnabled(True)
self.text_location.setReadOnly(True)
self.button_select_location.setIcon(get_std_icon('DirOpenIcon'))
self.button_cancel.setDefault(True)
self.button_cancel.setAutoDefault(True)
self.button_create.setEnabled(False)
self.combo_project_type.addItems(self._get_project_types())
self.combo_python_version.setCurrentIndex(
python_versions.index(current_python_version))
self.setWindowTitle(_('Create new project'))
self.setFixedWidth(500)
self.label_python_version.setVisible(False)
self.combo_python_version.setVisible(False)
# Layouts
layout_top = QHBoxLayout()
layout_top.addWidget(self.radio_new_dir)
layout_top.addWidget(self.radio_from_dir)
layout_top.addStretch(1)
self.groupbox.setLayout(layout_top)
layout_grid = QGridLayout()
layout_grid.addWidget(self.label_project_name, 0, 0)
layout_grid.addWidget(self.text_project_name, 0, 1, 1, 2)
layout_grid.addWidget(self.label_location, 1, 0)
layout_grid.addWidget(self.text_location, 1, 1)
layout_grid.addWidget(self.button_select_location, 1, 2)
layout_grid.addWidget(self.label_project_type, 2, 0)
layout_grid.addWidget(self.combo_project_type, 2, 1, 1, 2)
layout_grid.addWidget(self.label_python_version, 3, 0)
layout_grid.addWidget(self.combo_python_version, 3, 1, 1, 2)
layout = QVBoxLayout()
layout.addWidget(self.groupbox)
layout.addSpacing(10)
layout.addLayout(layout_grid)
layout.addStretch()
layout.addSpacing(20)
layout.addWidget(self.bbox)
self.setLayout(layout)
# Signals and slots
self.button_select_location.clicked.connect(self.select_location)
self.button_create.clicked.connect(self.create_project)
self.button_cancel.clicked.connect(self.close)
self.radio_from_dir.clicked.connect(self.update_location)
self.radio_new_dir.clicked.connect(self.update_location)
self.text_project_name.textChanged.connect(self.update_location)
def _get_project_types(self):
"""Get all available project types."""
project_types = get_available_project_types()
#.........这里部分代码省略.........