本文整理汇总了Python中qtpy.QtWidgets.QComboBox.model方法的典型用法代码示例。如果您正苦于以下问题:Python QComboBox.model方法的具体用法?Python QComboBox.model怎么用?Python QComboBox.model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QComboBox
的用法示例。
在下文中一共展示了QComboBox.model方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ConfigDialog
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import model [as 别名]
class ConfigDialog(QDialog):
"""
Dialog window for specifying test configuration.
The window contains a combobox with all the frameworks, a line edit box for
specifying the working directory, a button to use a file browser for
selecting the directory, and OK and Cancel buttons. Initially, no framework
is selected and the OK button is disabled. Selecting a framework enables
the OK button.
"""
def __init__(self, frameworks, config, parent=None):
"""
Construct a dialog window.
Parameters
----------
frameworks : dict of (str, type)
Names of all supported frameworks with their associated class
(assumed to be a subclass of RunnerBase)
config : Config
Initial configuration
parent : QWidget
"""
super(ConfigDialog, self).__init__(parent)
self.setWindowTitle(_('Configure tests'))
layout = QVBoxLayout(self)
framework_layout = QHBoxLayout()
framework_label = QLabel(_('Test framework'))
framework_layout.addWidget(framework_label)
self.framework_combobox = QComboBox(self)
for ix, (name, runner) in enumerate(sorted(frameworks.items())):
installed = runner.is_installed()
if installed:
label = name
else:
label = '{} ({})'.format(name, _('not available'))
self.framework_combobox.addItem(label)
self.framework_combobox.model().item(ix).setEnabled(installed)
framework_layout.addWidget(self.framework_combobox)
layout.addLayout(framework_layout)
layout.addSpacing(10)
wdir_label = QLabel(_('Directory from which to run tests'))
layout.addWidget(wdir_label)
wdir_layout = QHBoxLayout()
self.wdir_lineedit = QLineEdit(self)
wdir_layout.addWidget(self.wdir_lineedit)
self.wdir_button = QPushButton(ima.icon('DirOpenIcon'), '', self)
self.wdir_button.setToolTip(_("Select directory"))
self.wdir_button.clicked.connect(lambda: self.select_directory())
wdir_layout.addWidget(self.wdir_button)
layout.addLayout(wdir_layout)
layout.addSpacing(20)
self.buttons = QDialogButtonBox(QDialogButtonBox.Ok |
QDialogButtonBox.Cancel)
layout.addWidget(self.buttons)
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
self.ok_button = self.buttons.button(QDialogButtonBox.Ok)
self.ok_button.setEnabled(False)
self.framework_combobox.currentIndexChanged.connect(
self.framework_changed)
self.framework_combobox.setCurrentIndex(-1)
if config.framework:
index = self.framework_combobox.findText(config.framework)
if index != -1:
self.framework_combobox.setCurrentIndex(index)
self.wdir_lineedit.setText(config.wdir)
@Slot(int)
def framework_changed(self, index):
"""Called when selected framework changes."""
if index != -1:
self.ok_button.setEnabled(True)
def select_directory(self):
"""Display dialog for user to select working directory."""
basedir = to_text_string(self.wdir_lineedit.text())
if not osp.isdir(basedir):
basedir = getcwd()
title = _("Select directory")
directory = getexistingdirectory(self, title, basedir)
if directory:
self.wdir_lineedit.setText(directory)
def get_config(self):
"""
Return the test configuration specified by the user.
Returns
-------
#.........这里部分代码省略.........
示例2: LineListsWindow
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import model [as 别名]
class LineListsWindow(QWidget):
"""
The actual line lists widget.
Parameters
----------
hub : :class:`~specviz.core.Hub`
The Hub object for the plugin.
Signals
-------
erase_linelabels : Signal
Fired when a line list is removed by user action.
dismiss_linelists_window : Signal
Fired when the entire widget is dismissed. This happens only
when the corresponding plot widget is dismissed by user action.
"""
erase_linelabels = Signal(pg.PlotWidget)
dismiss_linelists_window = Signal()
def __init__(self, hub, *args, **kwargs):
super().__init__(*args, **kwargs)
self.hub = hub
self.wave_range = (None, None)
loadUi(os.path.join(os.path.dirname(__file__), "ui", "linelists_window.ui"), self)
# QtDesigner can't add a combo box to a tool bar...
self.line_list_selector = QComboBox()
self.line_list_selector.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self.line_list_selector.setMinimumWidth(230)
self.line_list_selector.setToolTip("Select line list from internal library")
self.main_toolbar.addWidget(self.line_list_selector)
# QtDesigner creates tabbed widgets with 2 tabs, and doesn't allow
# removing then in the designer itself. Remove in here then.
while self.tab_widget.count() > 0:
self.tab_widget.removeTab(0)
# Local references for often used objects.
self.plot_window = self.hub.plot_window
# Request that line lists be read from wherever are they sources.
if not hasattr(self, 'linelists'):
self._request_linelists()
# Populate line list selector with internal line lists
model = self.line_list_selector.model()
item = QStandardItem("Select line list")
font = QFont("Monospace")
font.setStyleHint(QFont.TypeWriter)
font.setPointSize(12)
item.setFont(font)
model.appendRow(item)
for description in linelist.descriptions():
item = QStandardItem(str(description))
item.setFont(font)
model.appendRow(item)
self.line_labels_plotter = LineLabelsPlotter(self)
# Connect controls to appropriate signals.
self.draw_button.clicked.connect(
lambda:self.line_labels_plotter._plot_linelists(
table_views=self._get_table_views(),
panes=self._get_panes(),
units=self.hub.plot_widget.spectral_axis_unit,
caller=self.line_labels_plotter))
self.erase_button.clicked.connect(lambda:self.erase_linelabels.emit(self.plot_window.plot_widget))
self.dismiss_button.clicked.connect(self.dismiss_linelists_window.emit)
self.actionOpen.triggered.connect(lambda:self._open_linelist_file(file_name=None))
self.actionExport.triggered.connect(lambda:self._export_to_file(file_name=None))
self.line_list_selector.currentIndexChanged.connect(self._lineList_selection_change)
self.tab_widget.tabCloseRequested.connect(self._on_tab_close)
self.hub.plot_window.window_removed.connect(self.dismiss_linelists_window.emit)
def dismiss(self):
"""
The Dismiss button just clears the plug-in
window from whatever line lists it's holding.
"""
v = self.tab_widget.count()
for index in range(v-1,-1,-1):
self.tab_widget.removeTab(index)
def _get_waverange_from_dialog(self, line_list):
# there is a widget-wide wavelength range so as to preserve
# the user definition from call to call. At the initial
# call, the wave range is initialized with whatever range
# is being displayed in the spectrum plot window.
if self.wave_range[0] == None or self.wave_range[1] == None:
self.wave_range = self._find_wavelength_range()
#.........这里部分代码省略.........