本文整理汇总了Python中qtpy.QtWidgets.QComboBox.setCurrentIndex方法的典型用法代码示例。如果您正苦于以下问题:Python QComboBox.setCurrentIndex方法的具体用法?Python QComboBox.setCurrentIndex怎么用?Python QComboBox.setCurrentIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QComboBox
的用法示例。
在下文中一共展示了QComboBox.setCurrentIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_controls
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import setCurrentIndex [as 别名]
def create_controls(self):
self.setWindowTitle(tr(self.plugin.name))
vbox = QVBoxLayout()
form = QFormLayout()
for Name, (enabled, url) in self.packages.items():
name = Name.lower()
cbo = QComboBox()
if enabled:
branches = get_branches(name, url)
for n, b in branches.items():
cbo.addItem(n, b)
if not check_git_repo(name):
cbo.insertItem(0, "<Select to change>", None)
cbo.setCurrentIndex(0)
self._prev_indices[cbo] = 0
cbo.currentIndexChanged.connect(
partial(self._cbo_changed, cbo))
else:
cbo.setEditText("<git repository>")
cbo.setToolTip(tr(
"This is installed in a git repository but we're set to "
"not use git."))
cbo.setEnabled(enabled)
form.addRow(Name + ':', cbo)
vbox.addLayout(form)
vbox.addWidget(QLabel(tr(
"You should restart the application if you make any changes!")))
btns = QDialogButtonBox(QDialogButtonBox.Ok, Qt.Horizontal, self)
btns.accepted.connect(self.accept)
vbox.addWidget(btns)
self.setLayout(vbox)
示例2: _AcquisitionRasterWidget
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import setCurrentIndex [as 别名]
class _AcquisitionRasterWidget(_AcquisitionWidget):
def _init_ui(self):
# Widgets
self._cb_raster_mode = QComboBox()
self._cb_raster_mode.addItems([None] + list(_RASTER_MODES))
# Layouts
layout = _AcquisitionWidget._init_ui(self)
layout.addRow('Raster mode', self._cb_raster_mode)
# Singals
self._cb_raster_mode.currentIndexChanged.connect(self.edited)
return layout
def parameter(self, parameter=None):
parameter = _AcquisitionWidget.parameter(self, parameter)
parameter.raster_mode = self._cb_raster_mode.currentText()
return parameter
def setParameter(self, condition):
_AcquisitionWidget.setParameter(self, condition)
self._cb_raster_mode.setCurrentIndex(self._cb_raster_mode.findText(condition.raster_mode))
def setReadOnly(self, state):
_AcquisitionWidget.setReadOnly(self, state)
self._cb_raster_mode.setEnabled(not state)
def isReadOnly(self):
return _AcquisitionWidget.isReadOnly(self) and \
not self._cb_raster_mode.isEnabled()
示例3: populate_unit_layout
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import setCurrentIndex [as 别名]
def populate_unit_layout(self, unit_layout, gui=None):
"""
Populate horizontal layout (living on conversion gui)
with appropriate widgets.
Layouts:
[QComboBox]
:param unit_layout: (QHBoxLayout) Horizontal layout
:param gui: conversion gui
:return: updated unit_layout
"""
unit_str = self._unit.to_string()
options = self._unit.find_equivalent_units(include_prefix_units=True)
options = [i.to_string() for i in options]
options.sort(key=lambda x: x.upper())
if unit_str not in options:
options.append(unit_str)
index = options.index(unit_str)
combo = QComboBox()
# combo.setFixedWidth(200)
combo.addItems(options)
combo.setCurrentIndex(index)
combo.currentIndexChanged.connect(self._update_message)
self.options_combo = combo
unit_layout.addWidget(combo)
self._update_message()
return unit_layout
示例4: _CompositionWidget
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import setCurrentIndex [as 别名]
class _CompositionWidget(_ConditionWidget):
def _init_ui(self):
# Widgets
self._cb_unit = QComboBox()
self._cb_unit.addItems(list(_COMPOSITION_UNITS))
# Layouts
layout = _ConditionWidget._init_ui(self)
layout.addRow('<i>Unit</i>', self._cb_unit)
# Signals
self._cb_unit.currentIndexChanged.connect(self.edited)
return layout
def parameter(self, parameter=None):
parameter = _ConditionWidget.parameter(self, parameter)
parameter.unit = self._cb_unit.currentText()
return parameter
def setParameter(self, condition):
_ConditionWidget.setParameter(self, condition)
self._cb_unit.setCurrentIndex(self._cb_unit.findText(condition.unit))
def setReadOnly(self, state):
_ConditionWidget.setReadOnly(self, state)
self._cb_unit.setEnabled(not state)
def isReadOnly(self):
return _ConditionWidget.isReadOnly(self) and \
not self._cb_unit.isEnabled()
示例5: RunConfigDialog
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import setCurrentIndex [as 别名]
class RunConfigDialog(BaseRunConfigDialog):
"""Run configuration dialog box: multiple file version"""
def __init__(self, parent=None):
BaseRunConfigDialog.__init__(self, parent)
self.file_to_run = None
self.combo = None
self.stack = None
def run_btn_clicked(self):
"""Run button was just clicked"""
self.file_to_run = to_text_string(self.combo.currentText())
def setup(self, fname):
"""Setup Run Configuration dialog with filename *fname*"""
combo_label = QLabel(_("Select a run configuration:"))
self.combo = QComboBox()
self.combo.setMaxVisibleItems(20)
self.combo.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLength)
self.combo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.stack = QStackedWidget()
configurations = _get_run_configurations()
for index, (filename, options) in enumerate(configurations):
if fname == filename:
break
else:
# There is no run configuration for script *fname*:
# creating a temporary configuration that will be kept only if
# dialog changes are accepted by the user
configurations.insert(0, (fname, RunConfiguration(fname).get()))
index = 0
for filename, options in configurations:
widget = RunConfigOptions(self)
widget.set(options)
self.combo.addItem(filename)
self.stack.addWidget(widget)
self.combo.currentIndexChanged.connect(self.stack.setCurrentIndex)
self.combo.setCurrentIndex(index)
self.add_widgets(combo_label, self.combo, 10, self.stack)
self.add_button_box(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
self.setWindowTitle(_("Run configuration per file"))
def accept(self):
"""Reimplement Qt method"""
configurations = []
for index in range(self.stack.count()):
filename = to_text_string(self.combo.itemText(index))
runconfigoptions = self.stack.widget(index)
if index == self.stack.currentIndex() and\
not runconfigoptions.is_valid():
return
options = runconfigoptions.get()
configurations.append( (filename, options) )
_set_run_configurations(configurations)
QDialog.accept(self)
示例6: DetectorSpectrometerWidget
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import setCurrentIndex [as 别名]
class DetectorSpectrometerWidget(_DetectorWidget):
def __init__(self, parent=None):
_DetectorWidget.__init__(self, DetectorSpectrometer, parent)
def _init_ui(self):
# Widgets
self._txt_channel_count = NumericalAttributeLineEdit(self.CLASS.channel_count)
self._txt_channel_count.setFormat('{0:d}')
self._wdg_calibration = CalibrationWidget()
self._cb_collection_mode = QComboBox()
self._cb_collection_mode.addItems([None] + list(_COLLECTION_MODES))
# Layout
layout = _DetectorWidget._init_ui(self)
layout.insertRow(0, '<i>Channel count</i>', self._txt_channel_count)
layout.insertRow(1, '<i>Calibration</i>', self._wdg_calibration)
layout.addRow('Collection mode', self._cb_collection_mode)
# Signals
self._txt_channel_count.textEdited.connect(self.edited)
self._wdg_calibration.edited.connect(self.edited)
self._cb_collection_mode.currentIndexChanged.connect(self.edited)
return layout
def _create_parameter(self):
return self.CLASS(1, CalibrationConstant('Quantity', 'm', 0.0))
def parameter(self, parameter=None):
parameter = _DetectorWidget.parameter(self, parameter)
parameter.channel_count = self._txt_channel_count.text()
parameter.calibration = self._wdg_calibration.calibration()
parameter.collection_mode = self._cb_collection_mode.currentText()
return parameter
def setParameter(self, condition):
_DetectorWidget.setParameter(self, condition)
self._txt_channel_count.setText(condition.channel_count)
self._wdg_calibration.setCalibration(condition.calibration)
self._cb_collection_mode.setCurrentIndex(self._cb_collection_mode.findText(condition.collection_mode))
def setReadOnly(self, state):
_DetectorWidget.setReadOnly(self, state)
self._txt_channel_count.setReadOnly(state)
self._wdg_calibration.setReadOnly(state)
self._cb_collection_mode.setEnabled(not state)
def isReadOnly(self):
return _DetectorWidget.isReadOnly(self) and \
self._txt_channel_count.isReadOnly() and \
self._wdg_calibration.isReadOnly() and \
not self._cb_collection_mode.isEnabled()
def hasAcceptableInput(self):
return _DetectorWidget.hasAcceptableInput(self) and \
self._txt_channel_count.hasAcceptableInput() and \
self._wdg_calibration.hasAcceptableInput()
示例7: IntensityIDWidget
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import setCurrentIndex [as 别名]
class IntensityIDWidget(_ConditionWidget):
def __init__(self, parent=None):
_ConditionWidget.__init__(self, IntensityID, parent)
def _init_ui(self):
print("TEST HUHU")
# Controls
self._cb_type = QComboBox()
self._cb_type.addItems([None] + list(_INTENSITY_TYPES))
self._cb_measure = QComboBox()
self._cb_measure.addItems([None] + list(_INTENSITY_MEASURES))
# Layouts
layout = _ConditionWidget._init_ui(self)
layout.addRow("<i>Type</i>", self._cb_type)
layout.addRow("<i>Measure</i>", self._cb_measure)
# Signals
self._cb_type.currentIndexChanged.connect(self.edited)
self._cb_measure.currentIndexChanged.connect(self.edited)
return layout
def _create_parameter(self):
return self.CLASS(None, None)
def parameter(self, parameter=None):
parameter = _ConditionWidget.parameter(self, parameter)
parameter.type = self._cb_type
parameter.measure = self._cb_measure
return parameter
def setParameter(self, condition):
_ConditionWidget.setParameter(self, condition)
self._cb_type.setCurrentIndex(self._cb_type.findText(condition.type))
self._cb_measure.setCurrentIndex(self._cb_measure.findText(condition.measure))
def setReadOnly(self, state):
_ConditionWidget.setReadOnly(self, state)
self._cb_type.setEnabled(not state)
self._cb_measure.setEnabled(not state)
def isReadOnly(self):
return _ConditionWidget.isReadOnly(self) and \
not self._cb_type.isEnabled() and \
not self._cb_measure.isEnabled()
def hasAcceptableInput(self):
return _ConditionWidget.hasAcceptableInput(self)
示例8: BackgroundIDWidget
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import setCurrentIndex [as 别名]
class BackgroundIDWidget(_ConditionWidget):
def __init__(self, parent=None):
_ConditionWidget.__init__(self, BackgroundID, parent)
def _init_ui(self):
# Controls
self._cb_interpolation = QComboBox()
self._cb_interpolation.addItems([None] + list(_BACKGROUND_INTERPOLATIONS))
# Layouts
layout = _ConditionWidget._init_ui(self)
layout.addRow("<i>Interpolation</i>", self._cb_interpolation)
# Signals
self._cb_interpolation.currentIndexChanged.connect(self.edited)
return layout
def _create_parameter(self):
return self.CLASS(None)
def parameter(self, parameter=None):
parameter = _ConditionWidget.parameter(self, parameter)
parameter.interpolation = self._cb_interpolation
return parameter
def setParameter(self, condition):
_ConditionWidget.setParameter(self, condition)
self._cb_interpolation.setCurrentIndex(self._cb_interpolation.findText(condition.interpolation))
def setReadOnly(self, state):
_ConditionWidget.setReadOnly(self, state)
self._cb_interpolation.setEnabled(not state)
def isReadOnly(self):
return _ConditionWidget.isReadOnly(self) and \
not self._cb_interpolation.isEnabled()
def hasAcceptableInput(self):
return _ConditionWidget.hasAcceptableInput(self)
示例9: FontLayout
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import setCurrentIndex [as 别名]
class FontLayout(QGridLayout):
"""Font selection"""
def __init__(self, value, parent=None):
QGridLayout.__init__(self)
font = tuple_to_qfont(value)
assert font is not None
# Font family
self.family = QFontComboBox(parent)
self.family.setCurrentFont(font)
self.addWidget(self.family, 0, 0, 1, -1)
# Font size
self.size = QComboBox(parent)
self.size.setEditable(True)
sizelist = list(range(6, 12)) + list(range(12, 30, 2)) + [36, 48, 72]
size = font.pointSize()
if size not in sizelist:
sizelist.append(size)
sizelist.sort()
self.size.addItems([str(s) for s in sizelist])
self.size.setCurrentIndex(sizelist.index(size))
self.addWidget(self.size, 1, 0)
# Italic or not
self.italic = QCheckBox(_("Italic"), parent)
self.italic.setChecked(font.italic())
self.addWidget(self.italic, 1, 1)
# Bold or not
self.bold = QCheckBox(_("Bold"), parent)
self.bold.setChecked(font.bold())
self.addWidget(self.bold, 1, 2)
def get_font(self):
font = self.family.currentFont()
font.setItalic(self.italic.isChecked())
font.setBold(self.bold.isChecked())
font.setPointSize(int(self.size.currentText()))
return qfont_to_tuple(font)
示例10: Help
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import setCurrentIndex [as 别名]
#.........这里部分代码省略.........
self.set_plain_text_font(font, color_scheme=color_scheme)
self.set_rich_text_font(rich_font)
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.extconsole.apply_plugin_settings(options=[connect_n])
if self.main.ipyconsole is not None:
self.main.ipyconsole.apply_plugin_settings(options=[connect_n])
#------ Public API (related to Help's source) -------------------------
def source_is_console(self):
"""Return True if source is Console"""
return self.source_combo.currentIndex() == 0
def switch_to_editor_source(self):
self.source_combo.setCurrentIndex(1)
def switch_to_console_source(self):
self.source_combo.setCurrentIndex(0)
def source_changed(self, index=None):
if self.source_is_console():
# Console
self.combo.show()
self.object_edit.hide()
self.show_source_action.setEnabled(True)
self.auto_import_action.setEnabled(True)
else:
# Editor
self.combo.hide()
self.object_edit.show()
self.show_source_action.setDisabled(True)
self.auto_import_action.setDisabled(True)
self.restore_text()
def save_text(self, callback):
if self.source_is_console():
self._last_console_cb = callback
else:
self._last_editor_cb = callback
def restore_text(self):
if self.source_is_console():
cb = self._last_console_cb
else:
cb = self._last_editor_cb
if cb is None:
if self.is_plain_text_mode():
示例11: PyDMLogDisplay
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import setCurrentIndex [as 别名]
class PyDMLogDisplay(QWidget, LogLevels):
"""
Standard display for Log Output
This widget handles instantating a ``GuiHandler`` and displaying log
messages to a ``QPlainTextEdit``. The level of the log can be changed from
inside the widget itself, allowing users to select from any of the
``.levels`` specified by the widget.
Parameters
----------
parent : QObject, optional
logname : str
Name of log to display in widget
level : logging.Level
Initial level of log display
"""
Q_ENUMS(LogLevels)
LogLevels = LogLevels
terminator = '\n'
default_format = '%(asctime)s %(message)s'
default_level = logging.INFO
def __init__(self, parent=None, logname=None, level=logging.NOTSET):
QWidget.__init__(self, parent=parent)
# Create Widgets
self.label = QLabel('Minimum displayed log level: ', parent=self)
self.combo = QComboBox(parent=self)
self.text = QPlainTextEdit(parent=self)
self.text.setReadOnly(True)
self.clear_btn = QPushButton("Clear", parent=self)
# Create layout
layout = QVBoxLayout()
level_control = QHBoxLayout()
level_control.addWidget(self.label)
level_control.addWidget(self.combo)
layout.addLayout(level_control)
layout.addWidget(self.text)
layout.addWidget(self.clear_btn)
self.setLayout(layout)
# Allow QCombobox to control log level
for log_level, value in LogLevels.as_dict().items():
self.combo.addItem(log_level, value)
self.combo.currentIndexChanged[str].connect(self.setLevel)
# Allow QPushButton to clear log text
self.clear_btn.clicked.connect(self.clear)
# Create a handler with the default format
self.handler = GuiHandler(level=level, parent=self)
self.logFormat = self.default_format
self.handler.message.connect(self.write)
# Create logger. Either as a root or given logname
self.log = None
self.level = None
self.logName = logname or ''
self.logLevel = level
self.destroyed.connect(functools.partial(logger_destroyed, self.log))
def sizeHint(self):
return QSize(400, 300)
@Property(LogLevels)
def logLevel(self):
return self.level
@logLevel.setter
def logLevel(self, level):
if level != self.level:
self.level = level
idx = self.combo.findData(level)
self.combo.setCurrentIndex(idx)
@Property(str)
def logName(self):
"""Name of associated log"""
return self.log.name
@logName.setter
def logName(self, name):
# Disconnect prior log from handler
if self.log:
self.log.removeHandler(self.handler)
# Reattach handler to new handler
self.log = logging.getLogger(name)
# Ensure that the log matches level of handler
# only if the handler level is less than the log.
if self.log.level < self.handler.level:
self.log.setLevel(self.handler.level)
# Attach preconfigured handler
self.log.addHandler(self.handler)
@Property(str)
def logFormat(self):
"""Format for log messages"""
return self.handler.formatter._fmt
@logFormat.setter
def logFormat(self, fmt):
#.........这里部分代码省略.........
示例12: CSVSettingsDialog
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import setCurrentIndex [as 别名]
class CSVSettingsDialog(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.settings = QSettings()
# decimal
self.decimalLabel = QLabel(self.tr("decimal:"))
self.decimalComboBox = QComboBox()
self.decimalLabel.setBuddy(self.decimalComboBox)
self.decimalComboBox.addItems([",", "."])
# separator
self.separatorLabel = QLabel(self.tr("separator:"))
self.separatorComboBox = QComboBox()
self.separatorLabel.setBuddy(self.separatorComboBox)
self.separatorComboBox.addItem("Semicolon ';'", ';')
self.separatorComboBox.addItem("Comma ','", ',')
self.separatorComboBox.addItem("Tabulator '\\t'", '\t')
self.separatorComboBox.addItem("Whitespace ' '", ' ')
# buttons
self.buttons = QDialogButtonBox(
QDialogButtonBox.Ok | QDialogButtonBox.Cancel
)
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
# layout
layout = QGridLayout()
layout.addWidget(self.decimalLabel, 0, 0)
layout.addWidget(self.decimalComboBox, 0, 1)
layout.addWidget(self.separatorLabel, 1, 0)
layout.addWidget(self.separatorComboBox, 1, 1)
layout.addWidget(self.buttons, 2, 0, 1, 2)
self.setLayout(layout)
# settings
self.decimalComboBox.setCurrentIndex(
self.decimalComboBox.findText(
self.settings.value(DECIMAL_SETTING, ","))
)
self.separatorComboBox.setCurrentIndex(
self.separatorComboBox.findData(
self.settings.value(SEPARATOR_SETTING, ";"))
)
self.setWindowTitle(self.tr("record settings"))
def accept(self):
self.settings.setValue(DECIMAL_SETTING, self.decimal)
self.settings.setValue(SEPARATOR_SETTING, self.separator)
super().accept()
# decimal property
@property
def decimal(self):
return self.decimalComboBox.currentText()
# seperator property
@property
def separator(self):
return self.separatorComboBox.itemData(
self.separatorComboBox.currentIndex())
示例13: LSPServerEditor
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import setCurrentIndex [as 别名]
class LSPServerEditor(QDialog):
DEFAULT_HOST = '127.0.0.1'
DEFAULT_PORT = 2084
DEFAULT_CMD = ''
DEFAULT_ARGS = ''
DEFAULT_CONFIGURATION = '{}'
DEFAULT_EXTERNAL = False
HOST_REGEX = re.compile(r'^\w+([.]\w+)*$')
NON_EMPTY_REGEX = re.compile(r'^\S+$')
JSON_VALID = _('JSON valid')
JSON_INVALID = _('JSON invalid')
def __init__(self, parent, language=None, cmd='', host='127.0.0.1',
port=2084, args='', external=False, configurations={},
**kwargs):
super(LSPServerEditor, self).__init__(parent)
self.parent = parent
self.external = external
bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.button_ok = bbox.button(QDialogButtonBox.Ok)
self.button_cancel = bbox.button(QDialogButtonBox.Cancel)
self.button_ok.setEnabled(False)
description = _('To create a new configuration, '
'you need to select a programming '
'language, along with a executable '
'name for the server to execute '
'(If the instance is local), '
'and the host and port. Finally, '
'you need to provide the '
'arguments that the server accepts. '
'The placeholders <tt>%(host)s</tt> and '
'<tt>%(port)s</tt> refer to the host '
'and the port, respectively.')
server_settings_description = QLabel(description)
server_settings_description.setWordWrap(True)
lang_label = QLabel(_('Language:'))
self.lang_cb = QComboBox(self)
self.lang_cb.setToolTip(_('Programming language provided '
'by the LSP server'))
self.lang_cb.addItem(_('Select a language'))
self.lang_cb.addItems(LSP_LANGUAGES)
if language is not None:
idx = LSP_LANGUAGES.index(language)
self.lang_cb.setCurrentIndex(idx + 1)
self.button_ok.setEnabled(True)
host_label = QLabel(_('Host:'))
self.host_input = QLineEdit(self)
self.host_input.setToolTip(_('Name of the host that will provide '
'access to the server'))
self.host_input.setText(host)
self.host_input.textChanged.connect(lambda x: self.validate())
port_label = QLabel(_('Port:'))
self.port_spinner = QSpinBox(self)
self.port_spinner.setToolTip(_('TCP port number of the server'))
self.port_spinner.setMinimum(1)
self.port_spinner.setMaximum(60000)
self.port_spinner.setValue(port)
cmd_label = QLabel(_('Command to execute:'))
self.cmd_input = QLineEdit(self)
self.cmd_input.setToolTip(_('Command used to start the '
'LSP server locally'))
self.cmd_input.setText(cmd)
if not external:
self.cmd_input.textChanged.connect(lambda x: self.validate())
args_label = QLabel(_('Server arguments:'))
self.args_input = QLineEdit(self)
self.args_input.setToolTip(_('Additional arguments required to '
'start the server'))
self.args_input.setText(args)
conf_label = QLabel(_('LSP Server Configurations:'))
self.conf_input = CodeEditor(None)
self.conf_input.textChanged.connect(self.validate)
color_scheme = CONF.get('appearance', 'selected')
self.conf_input.setup_editor(
language='JSON',
color_scheme=color_scheme,
wrap=False,
edge_line=True,
highlight_current_line=True,
highlight_current_cell=True,
occurrence_highlighting=True,
auto_unindent=True,
font=get_font(),
filename='config.json')
self.conf_input.setToolTip(_('Additional LSP server configurations '
'set at runtime. JSON required'))
conf_text = '{}'
try:
conf_text = json.dumps(configurations, indent=4, sort_keys=True)
except Exception:
pass
#.........这里部分代码省略.........
示例14: ProjectDialog
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import setCurrentIndex [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()
#.........这里部分代码省略.........
示例15: LineListsWindow
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import setCurrentIndex [as 别名]
#.........这里部分代码省略.........
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()
wrange = self._build_waverange_dialog(self.wave_range, line_list)
self.wave_range = wrange
def _lineList_selection_change(self, index):
# ignore first element in drop down. It contains
# the "Select line list" message.
if index > 0 and hasattr(self.hub, 'plot_widget') and self.hub.plot_widget.spectral_axis_unit:
line_list = linelist.get_from_cache(index - 1)
try:
self._get_waverange_from_dialog(line_list)
if self.wave_range[0] and self.wave_range[1]:
self._build_view(line_list, 0, waverange=self.wave_range)
self.line_list_selector.setCurrentIndex(0)
except UnitConversionError as err:
error_dialog = QErrorMessage()
error_dialog.showMessage('Units conversion not possible.')
error_dialog.exec_()
def _build_waverange_dialog(self, wave_range, line_list):
dialog = QDialog()
loadUi(os.path.join(os.path.dirname(__file__), "ui", "linelists_waverange.ui"), dialog)
# convert from line list native units to whatever units
# are currently being displayed in the spectral axis.
linelist_units = wave_range[0].unit
spectral_axis_unit = self.hub.plot_widget.spectral_axis_unit
w0 = wave_range[0].to(spectral_axis_unit, equivalencies=u.spectral())
w1 = wave_range[1].to(spectral_axis_unit, equivalencies=u.spectral())
# populate labels with correct physical quantity name
dispersion_unit = u.Unit(spectral_axis_unit or "")
if dispersion_unit.physical_type == 'length':
dialog.minwave_label.setText("Minimum wavelength")
dialog.maxwave_label.setText("Maximum wavelength")
elif dispersion_unit.physical_type == 'frequency':
dialog.minwave_label.setText("Minimum frequency")
dialog.maxwave_label.setText("Maximum frequency")
elif dispersion_unit.physical_type == 'energy':
dialog.minwave_label.setText("Minimum energy")
dialog.maxwave_label.setText("Maximum energy")
else:
dialog.minwave_label.setText("Minimum disp. var.")