本文整理汇总了Python中qtpy.QtWidgets.QPushButton.setDefault方法的典型用法代码示例。如果您正苦于以下问题:Python QPushButton.setDefault方法的具体用法?Python QPushButton.setDefault怎么用?Python QPushButton.setDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QPushButton
的用法示例。
在下文中一共展示了QPushButton.setDefault方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: final_dialog
# 需要导入模块: from qtpy.QtWidgets import QPushButton [as 别名]
# 或者: from qtpy.QtWidgets.QPushButton import setDefault [as 别名]
def final_dialog(self, label):
"""
Final dialog that to show where the calculated collapsed cube was put.
:param label:
:return:
"""
final_dialog = QDialog()
# Create data component label and input box
widget_desc = QLabel('The collapsed cube was added as an overlay with label "{}". {}'.format(
label, self._extra_message))
widget_desc.setWordWrap(True)
widget_desc.setFixedWidth(350)
widget_desc.setAlignment((Qt.AlignLeft | Qt.AlignTop))
hb_desc = QHBoxLayout()
hb_desc.addWidget(widget_desc)
# Create Ok button
okButton = QPushButton("Ok")
okButton.clicked.connect(lambda: final_dialog.close())
okButton.setDefault(True)
hb_buttons = QHBoxLayout()
hb_buttons.addStretch(1)
hb_buttons.addWidget(okButton)
# Add description and buttons to popup box
vbl = QVBoxLayout()
vbl.addLayout(hb_desc)
vbl.addLayout(hb_buttons)
final_dialog.setLayout(vbl)
final_dialog.setMaximumWidth(400)
final_dialog.show()
示例2: ConvertFluxUnitGUI
# 需要导入模块: from qtpy.QtWidgets import QPushButton [as 别名]
# 或者: from qtpy.QtWidgets.QPushButton import setDefault [as 别名]
class ConvertFluxUnitGUI(QDialog):
"""
GUI for unit conversions
"""
def __init__(self, controller, parent=None, convert_data=False):
super(ConvertFluxUnitGUI, self).__init__(parent=parent)
self.setWindowFlags(self.windowFlags() | Qt.Tool)
self.title = "Unit Conversion"
self.setMinimumSize(400, 270)
self.convert_data = convert_data
self.cubeviz_layout = controller.cubeviz_layout
self._hub = self.cubeviz_layout.session.hub
self.controller = controller
self.data = controller.data
self.controller_components = controller._components
self.current_unit = None
self.current_layout = None
self._init_ui()
def _init_ui(self):
# LINE 1: Data component drop down
self.component_prompt = QLabel("Data Component:")
self.component_prompt.setWordWrap(True)
# Add the data component labels to the drop down, with the ComponentID
# set as the userData:
if self.parent is not None and hasattr(self.parent, 'data_components'):
self.label_data = [(str(cid), cid) for cid in self.parent.data_components]
else:
self.label_data = [(str(cid), cid) for cid in self.data.visible_components]
default_index = 0
self.component_combo = QComboBox()
self.component_combo.setFixedWidth(200)
update_combobox(self.component_combo, self.label_data, default_index=default_index)
self.component_combo.currentIndexChanged.connect(self.update_unit_layout)
# hbl is short for Horizontal Box Layout
hbl1 = QHBoxLayout()
hbl1.addWidget(self.component_prompt)
hbl1.addWidget(self.component_combo)
hbl1.addStretch(1)
# LINE 2: Unit conversion layout
# This layout is filled by CubeVizUnit
self.unit_layout = QHBoxLayout() # this is hbl2
# LINE 3: Message box
self.message_box = QLabel("")
hbl3 = QHBoxLayout()
hbl3.addWidget(self.message_box)
hbl3.addStretch(1)
# Line 4: Buttons
ok_text = "Convert Data" if self.convert_data else "Convert Displayed Units"
ok_function = self.convert_data_units if self.convert_data else self.convert_displayed_units
self.okButton = QPushButton(ok_text)
self.okButton.clicked.connect(ok_function)
self.okButton.setDefault(True)
self.cancelButton = QPushButton("Cancel")
self.cancelButton.clicked.connect(self.cancel)
hbl4 = QHBoxLayout()
hbl4.addStretch(1)
hbl4.addWidget(self.cancelButton)
hbl4.addWidget(self.okButton)
vbl = QVBoxLayout()
vbl.addLayout(hbl1)
vbl.addLayout(self.unit_layout)
vbl.addLayout(hbl3)
vbl.addLayout(hbl4)
self.setLayout(vbl)
self.vbl = vbl
self.update_unit_layout(default_index)
self.show()
def update_unit_layout(self, index):
"""
Call back for component selection drop down.
"""
component_id = self.component_combo.currentData()
# STEP1: Clean up widgets from last component
widgets = (self.unit_layout.itemAt(i) for i in range(self.unit_layout.count()))
for w in widgets:
if isinstance(w, QSpacerItem):
self.unit_layout.removeItem(w)
continue
elif isinstance(w, QWidgetItem):
w = w.widget()
if hasattr(w, "deleteLater"):
#.........这里部分代码省略.........
示例3: ImportWizard
# 需要导入模块: from qtpy.QtWidgets import QPushButton [as 别名]
# 或者: from qtpy.QtWidgets.QPushButton import setDefault [as 别名]
class ImportWizard(QDialog):
"""Text data import wizard"""
def __init__(self, parent, text,
title=None, icon=None, contents_title=None, varname=None):
QDialog.__init__(self, parent)
# Destroying the C++ object right after closing the dialog box,
# otherwise it may be garbage-collected in another QThread
# (e.g. the editor's analysis thread in Spyder), thus leading to
# a segmentation fault on UNIX or an application crash on Windows
self.setAttribute(Qt.WA_DeleteOnClose)
if title is None:
title = _("Import wizard")
self.setWindowTitle(title)
if icon is None:
self.setWindowIcon(ima.icon('fileimport'))
if contents_title is None:
contents_title = _("Raw text")
if varname is None:
varname = _("variable_name")
self.var_name, self.clip_data = None, None
# Setting GUI
self.tab_widget = QTabWidget(self)
self.text_widget = ContentsWidget(self, text)
self.table_widget = PreviewWidget(self)
self.tab_widget.addTab(self.text_widget, _("text"))
self.tab_widget.setTabText(0, contents_title)
self.tab_widget.addTab(self.table_widget, _("table"))
self.tab_widget.setTabText(1, _("Preview"))
self.tab_widget.setTabEnabled(1, False)
name_layout = QHBoxLayout()
name_label = QLabel(_("Variable Name"))
name_layout.addWidget(name_label)
self.name_edt = QLineEdit()
self.name_edt.setText(varname)
name_layout.addWidget(self.name_edt)
btns_layout = QHBoxLayout()
cancel_btn = QPushButton(_("Cancel"))
btns_layout.addWidget(cancel_btn)
cancel_btn.clicked.connect(self.reject)
h_spacer = QSpacerItem(40, 20,
QSizePolicy.Expanding, QSizePolicy.Minimum)
btns_layout.addItem(h_spacer)
self.back_btn = QPushButton(_("Previous"))
self.back_btn.setEnabled(False)
btns_layout.addWidget(self.back_btn)
self.back_btn.clicked.connect(ft_partial(self._set_step, step=-1))
self.fwd_btn = QPushButton(_("Next"))
btns_layout.addWidget(self.fwd_btn)
self.fwd_btn.clicked.connect(ft_partial(self._set_step, step=1))
self.done_btn = QPushButton(_("Done"))
self.done_btn.setEnabled(False)
btns_layout.addWidget(self.done_btn)
self.done_btn.clicked.connect(self.process)
self.text_widget.asDataChanged.connect(self.fwd_btn.setEnabled)
self.text_widget.asDataChanged.connect(self.done_btn.setDisabled)
layout = QVBoxLayout()
layout.addLayout(name_layout)
layout.addWidget(self.tab_widget)
layout.addLayout(btns_layout)
self.setLayout(layout)
def _focus_tab(self, tab_idx):
"""Change tab focus"""
for i in range(self.tab_widget.count()):
self.tab_widget.setTabEnabled(i, False)
self.tab_widget.setTabEnabled(tab_idx, True)
self.tab_widget.setCurrentIndex(tab_idx)
def _set_step(self, step):
"""Proceed to a given step"""
new_tab = self.tab_widget.currentIndex() + step
assert new_tab < self.tab_widget.count() and new_tab >= 0
if new_tab == self.tab_widget.count()-1:
try:
self.table_widget.open_data(self._get_plain_text(),
self.text_widget.get_col_sep(),
self.text_widget.get_row_sep(),
self.text_widget.trnsp_box.isChecked(),
self.text_widget.get_skiprows(),
self.text_widget.get_comments())
self.done_btn.setEnabled(True)
self.done_btn.setDefault(True)
self.fwd_btn.setEnabled(False)
self.back_btn.setEnabled(True)
except (SyntaxError, AssertionError) as error:
QMessageBox.critical(self, _("Import wizard"),
_("<b>Unable to proceed to next step</b>"
"<br><br>Please check your entries."
"<br><br>Error message:<br>%s") % str(error))
return
#.........这里部分代码省略.........
示例4: TextEditor
# 需要导入模块: from qtpy.QtWidgets import QPushButton [as 别名]
# 或者: from qtpy.QtWidgets.QPushButton import setDefault [as 别名]
class TextEditor(QDialog):
"""Array Editor Dialog"""
def __init__(self, text, title='', font=None, parent=None,
readonly=False, size=(400, 300)):
QDialog.__init__(self, parent)
# Destroying the C++ object right after closing the dialog box,
# otherwise it may be garbage-collected in another QThread
# (e.g. the editor's analysis thread in Spyder), thus leading to
# a segmentation fault on UNIX or an application crash on Windows
self.setAttribute(Qt.WA_DeleteOnClose)
self.text = None
self.btn_save_and_close = None
# Display text as unicode if it comes as bytes, so users see
# its right representation
if is_binary_string(text):
self.is_binary = True
text = to_text_string(text, 'utf8')
else:
self.is_binary = False
self.layout = QVBoxLayout()
self.setLayout(self.layout)
# Text edit
self.edit = QTextEdit(parent)
self.edit.setReadOnly(readonly)
self.edit.textChanged.connect(self.text_changed)
self.edit.setPlainText(text)
if font is None:
font = get_font()
self.edit.setFont(font)
self.layout.addWidget(self.edit)
# Buttons configuration
btn_layout = QHBoxLayout()
btn_layout.addStretch()
if not readonly:
self.btn_save_and_close = QPushButton(_('Save and Close'))
self.btn_save_and_close.setDisabled(True)
self.btn_save_and_close.clicked.connect(self.accept)
btn_layout.addWidget(self.btn_save_and_close)
self.btn_close = QPushButton(_('Close'))
self.btn_close.setAutoDefault(True)
self.btn_close.setDefault(True)
self.btn_close.clicked.connect(self.reject)
btn_layout.addWidget(self.btn_close)
self.layout.addLayout(btn_layout)
# Make the dialog act as a window
self.setWindowFlags(Qt.Window)
self.setWindowIcon(ima.icon('edit'))
self.setWindowTitle(_("Text editor") + \
"%s" % (" - "+str(title) if str(title) else ""))
self.resize(size[0], size[1])
@Slot()
def text_changed(self):
"""Text has changed"""
# Save text as bytes, if it was initially bytes
if self.is_binary:
self.text = to_binary_string(self.edit.toPlainText(), 'utf8')
else:
self.text = to_text_string(self.edit.toPlainText())
if self.btn_save_and_close:
self.btn_save_and_close.setEnabled(True)
self.btn_save_and_close.setAutoDefault(True)
self.btn_save_and_close.setDefault(True)
def get_value(self):
"""Return modified text"""
# It is import to avoid accessing Qt C++ object as it has probably
# already been destroyed, due to the Qt.WA_DeleteOnClose attribute
return self.text
def setup_and_check(self, value):
"""Verify if TextEditor is able to display strings passed to it."""
try:
to_text_string(value, 'utf8')
return True
except:
return False
示例5: MOSVizViewer
# 需要导入模块: from qtpy.QtWidgets import QPushButton [as 别名]
# 或者: from qtpy.QtWidgets.QPushButton import setDefault [as 别名]
#.........这里部分代码省略.........
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:
line_edit = QLineEdit(os.path.basename("Not Saving to File."),
self.central_widget.meta_form_widget)
line_edit.setReadOnly(True)
self.meta_form_layout.addRow("Save File", line_edit)
else:
line_edit = QLineEdit(os.path.basename(self.savepath),
self.central_widget.meta_form_widget)
line_edit.setReadOnly(True)
self.meta_form_layout.addRow("Save File", line_edit)
self.input_flag = QLineEdit(self.get_flag(),
self.central_widget.meta_form_widget)
self.input_flag.textChanged.connect(self._text_changed)
self.input_flag.setStyleSheet("background-color: rgba(255, 255, 255);")
self.meta_form_layout.addRow("Flag", self.input_flag)
self.input_comments = QPlainTextEdit(self.get_comment(),
self.central_widget.meta_form_widget)
self.input_comments.textChanged.connect(self._text_changed)
self.input_comments.setStyleSheet("background-color: rgba(255, 255, 255);")
self.meta_form_layout.addRow("Comments", self.input_comments)
self.input_save = QPushButton('Save',
self.central_widget.meta_form_widget)
self.input_save.clicked.connect(self.update_comments)
self.input_save.setDefault(True)
self.input_refresh = QPushButton('Reload',
self.central_widget.meta_form_widget)
self.input_refresh.clicked.connect(self.refresh_comments)
self.meta_form_layout.addRow(self.input_save, self.input_refresh)
if not self.isHidden() and self.image_viewer_hidden:
self.image_widget.setVisible(False)
def _load_spectrum2d_widget(self, spec2d_data, level2_data):
if not spec2d_data:
return
xp2d = np.arange(spec2d_data.shape[1])
yp2d = np.repeat(0, spec2d_data.shape[1])
spectrum2d_disp, spectrum2d_offset = spec2d_data.coords.pixel2world(xp2d, yp2d)
x_min = spectrum2d_disp.min()
x_max = spectrum2d_disp.max()
if self.slit_controller.has_slits and \
None not in self.slit_controller.y_bounds:
y_min, y_max = self.slit_controller.y_bounds
else:
y_min = -0.5
y_max = spec2d_data.shape[0] - 0.5
self.extent = [x_min, x_max, y_min, y_max]
示例6: ArrayEditor
# 需要导入模块: from qtpy.QtWidgets import QPushButton [as 别名]
# 或者: from qtpy.QtWidgets.QPushButton import setDefault [as 别名]
#.........这里部分代码省略.........
btn_layout.addWidget(label)
btn_layout.addWidget(ra_combo)
self.shape_label = QLabel()
btn_layout.addWidget(self.shape_label)
label = QLabel(_("Index:"))
btn_layout.addWidget(label)
btn_layout.addWidget(self.index_spin)
self.slicing_label = QLabel()
btn_layout.addWidget(self.slicing_label)
# set the widget to display when launched
self.current_dim_changed(self.last_dim)
else:
ra_combo = QComboBox(self)
ra_combo.currentIndexChanged.connect(self.stack.setCurrentIndex)
ra_combo.addItems(names)
btn_layout.addWidget(ra_combo)
if is_masked_array:
label = QLabel(_("<u>Warning</u>: changes are applied separately"))
label.setToolTip(_("For performance reasons, changes applied "\
"to masked array won't be reflected in "\
"array's data (and vice-versa)."))
btn_layout.addWidget(label)
btn_layout.addStretch()
if not readonly:
self.btn_save_and_close = QPushButton(_('Save and Close'))
self.btn_save_and_close.setDisabled(True)
self.btn_save_and_close.clicked.connect(self.accept)
btn_layout.addWidget(self.btn_save_and_close)
self.btn_close = QPushButton(_('Close'))
self.btn_close.setAutoDefault(True)
self.btn_close.setDefault(True)
self.btn_close.clicked.connect(self.reject)
btn_layout.addWidget(self.btn_close)
self.layout.addLayout(btn_layout, 2, 0)
self.setMinimumSize(400, 300)
# Make the dialog act as a window
self.setWindowFlags(Qt.Window)
return True
@Slot(QModelIndex, QModelIndex)
def save_and_close_enable(self, left_top, bottom_right):
"""Handle the data change event to enable the save and close button."""
if self.btn_save_and_close:
self.btn_save_and_close.setEnabled(True)
self.btn_save_and_close.setAutoDefault(True)
self.btn_save_and_close.setDefault(True)
def current_widget_changed(self, index):
self.arraywidget = self.stack.widget(index)
self.arraywidget.model.dataChanged.connect(self.save_and_close_enable)
def change_active_widget(self, index):
"""
This is implemented for handling negative values in index for
3d arrays, to give the same behavior as slicing
"""
string_index = [':']*3
string_index[self.last_dim] = '<font color=red>%i</font>'
self.slicing_label.setText((r"Slicing: [" + ", ".join(string_index) +
"]") % index)
示例7: ContourOptionsDialog
# 需要导入模块: from qtpy.QtWidgets import QPushButton [as 别名]
# 或者: from qtpy.QtWidgets.QPushButton import setDefault [as 别名]
#.........这里部分代码省略.........
# Line 5: Vmin
self.vmin_checkBox = QCheckBox("Set min:")
self.vmin_input = QLineEdit()
self.vmin_input.setFixedWidth(150)
self.vmin_input.setDisabled(not self.is_vmin)
vmin = ""
if self.is_vmin:
self.vmin_checkBox.setChecked(True)
vmin = str(self.contour_settings.vmin)
elif self.contour_settings.data_min is not None:
vmin = self.contour_settings.data_min
vmin = "{0:1.4f}".format(vmin)
self.vmin_input.setText(vmin)
self.vmin_default_text = vmin
self.vmin_checkBox.toggled.connect(self.toggle_vmin)
hbl5 = QHBoxLayout()
hbl5.addWidget(self.vmin_checkBox)
hbl5.addWidget(self.vmin_input)
# Line f:
self.previewButton = QPushButton("Preview")
self.previewButton.clicked.connect(self.preview)
self.defaultButton = QPushButton("Reset")
self.defaultButton.clicked.connect(self.default)
self.okButton = QPushButton("OK")
self.okButton.clicked.connect(self.finish)
self.okButton.setDefault(True)
self.cancelButton = QPushButton("Cancel")
self.cancelButton.clicked.connect(self.cancel)
hblf = QHBoxLayout()
hblf.addStretch(1)
hblf.addWidget(self.previewButton)
hblf.addWidget(self.defaultButton)
hblf.addWidget(self.cancelButton)
hblf.addWidget(self.okButton)
vbl = QVBoxLayout()
vbl.addLayout(hbl1)
vbl.addLayout(hbl2)
vbl.addLayout(hbl3)
vbl.addLayout(hbl4)
vbl.addLayout(hbl5)
vbl.addLayout(hblf)
self.setLayout(vbl)
self.show()
def update_data_vals(self, vmin="", vmax="", spacing="1"):
self.vmin_default_text = vmin
if not self.is_vmin:
self.vmin_input.setText(vmin)
self.vmax_default_text = vmax
if not self.is_vmax:
示例8: MomentMapsGUI
# 需要导入模块: from qtpy.QtWidgets import QPushButton [as 别名]
# 或者: from qtpy.QtWidgets.QPushButton import setDefault [as 别名]
class MomentMapsGUI(QDialog):
def __init__(self, data, data_collection, parent=None):
super(MomentMapsGUI, self).__init__(parent)
# Get the data_components (e.g., FLUX, DQ, ERROR etc)
# Using list comprehension to keep the order of the component_ids
self.data_components = [str(x).strip() for x in data.component_ids() if not x in data.coordinate_components]
self.data = data
self.data_collection = data_collection
self.parent = parent
self.label = ''
self.calculateButton = None
self.cancelButton = None
def display(self):
"""
Create the popup box with the calculation input area and buttons.
:return:
"""
self.setWindowFlags(self.windowFlags() | Qt.Tool)
self.setWindowTitle("Create Moment Map")
boldFont = QtGui.QFont()
boldFont.setBold(True)
# Create calculation label and input box
self.data_label = QLabel("Data:")
self.data_label.setFixedWidth(100)
self.data_label.setAlignment((Qt.AlignRight | Qt.AlignTop))
self.data_label.setFont(boldFont)
self.data_combobox = QComboBox()
self.data_combobox.addItems([str(x).strip() for x in self.data.component_ids() if not x in self.data.coordinate_components])
self.data_combobox.setMinimumWidth(200)
hbl1 = QHBoxLayout()
hbl1.addWidget(self.data_label)
hbl1.addWidget(self.data_combobox)
# Create calculation label and input box
self.order_label = QLabel("Order:")
self.order_label.setFixedWidth(100)
self.order_label.setAlignment((Qt.AlignRight | Qt.AlignTop))
self.order_label.setFont(boldFont)
self.order_combobox = QComboBox()
self.order_combobox.addItems(["1", "2", "3", "4", "5", "6", "7", "8"])
self.order_combobox.setMinimumWidth(200)
hbl2 = QHBoxLayout()
hbl2.addWidget(self.order_label)
hbl2.addWidget(self.order_combobox)
# Create Calculate and Cancel buttons
self.calculateButton = QPushButton("Calculate")
self.calculateButton.clicked.connect(self.calculate_callback)
self.calculateButton.setDefault(True)
self.cancelButton = QPushButton("Cancel")
self.cancelButton.clicked.connect(self.cancel_callback)
hbl5 = QHBoxLayout()
hbl5.addStretch(1)
hbl5.addWidget(self.cancelButton)
hbl5.addWidget(self.calculateButton)
# Add calculation and buttons to popup box
vbl = QVBoxLayout()
vbl.addLayout(hbl1)
vbl.addLayout(hbl2)
vbl.addLayout(hbl5)
self.setLayout(vbl)
self.setMaximumWidth(700)
self.show()
def do_calculation(self, order, data_name):
# Grab spectral-cube
import spectral_cube
cube = spectral_cube.SpectralCube(self.data[data_name], wcs=self.data.coords.wcs)
cube_moment = cube.moment(order=order, axis=0)
self.label = '{}-moment-{}'.format(data_name, order)
# Add new overlay/component to cubeviz. We add this both to the 2D
# container Data object and also as an overlay. In future we might be
# able to use the 2D container Data object for the overlays directly.
add_to_2d_container(self.parent, self.data, cube_moment.value, cube_moment.unit, self.label)
# Going to pass in just the value into the overlay as the units aren't
# currently used for the overlay area. BUT, this is probably not the
# best way to do this.
self.parent.add_overlay(cube_moment.value, self.label, display_now=False)
def calculate_callback(self):
#.........这里部分代码省略.........
示例9: ImageRotationDialog
# 需要导入模块: from qtpy.QtWidgets import QPushButton [as 别名]
# 或者: from qtpy.QtWidgets.QPushButton import setDefault [as 别名]
#.........这里部分代码省略.........
f = signal._plot.navigator_plot.update
else:
f = signal._plot.signal_plot.update
# TODO: TAG: Functionality check
if hasattr(signal, 'events') and hasattr(
signal.events, 'data_changed'):
if disconnect:
signal.events.data_changed.disconnect(f)
else:
signal.events.data_changed.connect(f, [])
self._connected_updates = not disconnect
def update(self):
angle = self.num_angle.value()
reshape = self.chk_reshape.isChecked()
if self.opt_new.isChecked():
if self.new_out is None:
out = None
else:
out = self.new_out.signal
elif self.opt_replace.isChecked():
out = self.signal.signal
else:
return # Indeterminate state, do nothing
s = self.plugin.rotate_signal(angle, self.signal.signal, record=False,
reshape=reshape, out=out, axes=self.axes)
if out is None:
s.metadata.General.title = self.signal.name + "[Rotated]"
s.plot()
self.connect_update_plot(s)
if (self.gbo_preview.isChecked() and self.opt_new.isChecked() and
self.new_out is None):
self.new_out = self.ui.lut_signalwrapper[s]
else:
s = out
if self.chk_grid.isChecked() is True:
pass # TODO: Draw grid
def create_controls(self):
"""
Create UI controls.
"""
vbox = QVBoxLayout()
form = QFormLayout()
self.num_angle = QDoubleSpinBox()
self.num_angle.setValue(0.0)
self.num_angle.setMinimum(-360)
self.num_angle.setMaximum(360)
form.addRow(tr("Angle:"), self.num_angle)
vbox.addLayout(form)
self.gbo_preview = QGroupBox(tr("Preview"))
self.gbo_preview.setCheckable(True)
self.gbo_preview.setChecked(False)
gbo_vbox = QVBoxLayout()
self.chk_grid = QCheckBox(tr("Grid"))
self.chk_grid.setChecked(False)
self.num_grid = QSpinBox()
self.num_grid.setValue(4)
self.num_grid.setMinimum(1)
self.num_grid.setEnabled(False)
self.chk_grid.toggled[bool].connect(self.num_grid.setEnabled)
gbo_vbox.addWidget(self.chk_grid)
gbo_vbox.addWidget(self.num_grid)
self.gbo_preview.setLayout(gbo_vbox)
vbox.addWidget(self.gbo_preview)
self.gbo_preview.toggled[bool].connect(self.set_preview)
self.gbo_output = QGroupBox(tr("Output"))
self.opt_new = QRadioButton(tr("New signal"))
self.opt_replace = QRadioButton(tr("In place"))
self.opt_new.setChecked(True)
gbo_vbox2 = QVBoxLayout()
gbo_vbox2.addWidget(self.opt_new)
gbo_vbox2.addWidget(self.opt_replace)
self.gbo_output.setLayout(gbo_vbox2)
vbox.addWidget(self.gbo_output)
self.chk_reshape = QCheckBox(tr("Resize to fit"))
self.chk_reshape.setChecked(False)
vbox.addWidget(self.chk_reshape)
self.btn_ok = QPushButton(tr("&OK"))
self.btn_ok.setDefault(True)
self.btn_ok.clicked.connect(self.accept)
self.btn_cancel = QPushButton(tr("&Cancel"))
self.btn_cancel.clicked.connect(self.reject)
hbox = QHBoxLayout()
hbox.addWidget(self.btn_ok)
hbox.addWidget(self.btn_cancel)
vbox.addLayout(hbox)
vbox.addStretch(1)
self.setLayout(vbox)
示例10: ProjectDialog
# 需要导入模块: from qtpy.QtWidgets import QPushButton [as 别名]
# 或者: from qtpy.QtWidgets.QPushButton import setDefault [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()
#.........这里部分代码省略.........
示例11: SlitSelectionUI
# 需要导入模块: from qtpy.QtWidgets import QPushButton [as 别名]
# 或者: from qtpy.QtWidgets.QPushButton import setDefault [as 别名]
class SlitSelectionUI(QDialog):
"""
Custom slit selection UI and editor.
Right now it only applies slits temporarly,
ie. if the current target is changed, slit settings
will be lost.
"""
def __init__(self, mosviz_viewer, parent=None):
super(SlitSelectionUI, self).__init__(parent=parent)
self.mosviz_viewer = mosviz_viewer
self._slit_dict = {}
self._mosviz_table_option_text = 'Slit from MOSViz Table'
self._init_ui()
def _init_ui(self):
self.slit_type_label = QLabel('Slit Type')
self.slit_type_combo = QComboBox()
self.slit_type_combo.currentIndexChanged.connect(self.update_info)
hbl1 = QHBoxLayout()
hbl1.addWidget(self.slit_type_label)
hbl1.addWidget(self.slit_type_combo)
self.slit_width_label = QLabel('Slit Width')
self.slit_width_input = QLineEdit()
self.slit_width_combo = QComboBox()
self.slit_width_units = QLabel('arcsec')
hbl2 = QHBoxLayout()
hbl2.addWidget(self.slit_width_label)
hbl2.addWidget(self.slit_width_input)
hbl2.addWidget(self.slit_width_combo)
hbl2.addWidget(self.slit_width_units)
self.slit_length_label = QLabel('Slit Length')
self.slit_length_input = QLineEdit()
self.slit_length_combo = QComboBox()
self.slit_length_units = QLabel('arcsec')
hbl3 = QHBoxLayout()
hbl3.addWidget(self.slit_length_label)
hbl3.addWidget(self.slit_length_input)
hbl3.addWidget(self.slit_length_combo)
hbl3.addWidget(self.slit_length_units)
self.okButton = QPushButton('Apply')
self.okButton.clicked.connect(self.apply)
self.okButton.setDefault(True)
self.cancelButton = QPushButton('Cancel')
self.cancelButton.clicked.connect(self.cancel)
hbl4 = QHBoxLayout()
hbl4.addWidget(self.cancelButton)
hbl4.addWidget(self.okButton)
vbl = QVBoxLayout()
vbl.addLayout(hbl1)
vbl.addLayout(hbl2)
vbl.addLayout(hbl3)
vbl.addLayout(hbl4)
self.setLayout(vbl)
self.vbl = vbl
self._load_selections()
self._populate_combo()
self.update_info(0)
self.show()
def _load_selections(self):
"""Load preconfigured slit shapes from yaml file"""
file_path = os.path.join(os.path.dirname(__file__), 'saved_slits.yaml')
with open(file_path) as f:
self.slit_dict = yaml.load(f)
def _populate_combo(self, default_index=0):
"""Populate combo box with slit types"""
name_list = [self._mosviz_table_option_text] + \
[self.slit_dict[s]['name'] for s in sorted(self.slit_dict)] + \
['Custom']
key_list = ['default'] + [s for s in sorted(self.slit_dict)] + ['custom']
combo_input = [(name, key) for name, key in zip(name_list, key_list)]
update_combobox(self.slit_type_combo, combo_input, default_index=default_index)
@property
def width(self):
if self.slit_width_combo.isVisible():
width = self.slit_width_combo.currentData()
else:
width = self.slit_width_input.text()
return u.Quantity(width)
@property
def length(self):
#.........这里部分代码省略.........
示例12: CondaPackagesWidget
# 需要导入模块: from qtpy.QtWidgets import QPushButton [as 别名]
# 或者: from qtpy.QtWidgets.QPushButton import setDefault [as 别名]
#.........这里部分代码省略.........
self.button_cancel = QPushButton('Cancel')
self.button_channels = QPushButton(_('Channels'))
self.button_ok = QPushButton(_('Ok'))
self.button_update = QPushButton(_('Update index...'))
self.button_apply = QPushButton(_('Apply'))
self.button_clear = QPushButton(_('Clear'))
self.button_options = QToolButton()
self.combobox_filter = DropdownPackageFilter(self)
self.frame_top = FramePackageTop()
self.frame_bottom = FramePackageTop()
self.progress_bar = ProgressBarPackage(self)
self.status_bar = LabelPackageStatus(self)
self.table = TableCondaPackages(self)
self.textbox_search = LineEditSearch(self)
self.widgets = [self.button_update, self.button_channels,
self.combobox_filter, self.textbox_search, self.table,
self.button_ok, self.button_apply, self.button_clear,
self.button_options]
self.table_first_row = FirstRowWidget(
widget_before=self.textbox_search)
self.table_last_row = LastRowWidget(
widgets_after=[self.button_apply, self.button_clear,
self.button_cancel, self.combobox_filter])
# Widget setup
self.button_options.setPopupMode(QToolButton.InstantPopup)
self.button_options.setIcon(icon_options)
self.button_options.setAutoRaise(True)
max_height = self.status_bar.fontMetrics().height()
max_width = self.textbox_search.fontMetrics().width('M'*23)
self.bbox.addButton(self.button_ok, QDialogButtonBox.ActionRole)
self.button_ok.setAutoDefault(True)
self.button_ok.setDefault(True)
self.button_ok.setMaximumSize(QSize(0, 0))
self.button_ok.setVisible(False)
self.combobox_filter.addItems([k for k in C.COMBOBOX_VALUES_ORDERED])
self.combobox_filter.setMinimumWidth(120)
self.progress_bar.setMaximumHeight(max_height*1.2)
self.progress_bar.setMaximumWidth(max_height*12)
self.progress_bar.setTextVisible(False)
self.progress_bar.setVisible(False)
self.setMinimumSize(QSize(480, 300))
self.setWindowTitle(_("Conda Package Manager"))
self.status_bar.setFixedHeight(max_height*1.5)
self.textbox_search.setMaximumWidth(max_width)
self.textbox_search.setPlaceholderText('Search Packages')
self.table_first_row.setMaximumHeight(0)
self.table_last_row.setMaximumHeight(0)
self.table_last_row.setVisible(False)
self.table_first_row.setVisible(False)
# Layout
top_layout = QHBoxLayout()
top_layout.addWidget(self.combobox_filter)
top_layout.addWidget(self.button_channels)
top_layout.addWidget(self.button_update)
top_layout.addWidget(self.textbox_search)
top_layout.addStretch()
top_layout.addWidget(self.button_options)
middle_layout = QVBoxLayout()
middle_layout.addWidget(self.table_first_row)
middle_layout.addWidget(self.table)
middle_layout.addWidget(self.table_last_row)
示例13: SelectSmoothing
# 需要导入模块: from qtpy.QtWidgets import QPushButton [as 别名]
# 或者: from qtpy.QtWidgets.QPushButton import setDefault [as 别名]
#.........这里部分代码省略.........
if self.parent is not None and hasattr(self.parent, 'data_components'):
labeldata = [(str(cid), cid) for cid in self.parent.data_components]
else:
labeldata = [(str(cid), cid) for cid in self.data.main_components()]
self.component_combo = QComboBox()
update_combobox(self.component_combo, labeldata)
self.component_combo.setMaximumWidth(150)
self.component_combo.setCurrentIndex(0)
if self.allow_preview:
self.component_combo.currentIndexChanged.connect(self.update_preview_button)
hbl4 = QHBoxLayout()
hbl4.addWidget(self.component_prompt)
hbl4.addWidget(self.component_combo)
# Line 5: Preview Message
message = "Info: Smoothing previews are displayed on " \
"CubeViz's left and single image viewers."
self.preview_message = QLabel(message)
self.preview_message.setWordWrap(True)
self.preview_message.hide()
hbl5 = QHBoxLayout()
hbl5.addWidget(self.preview_message)
# LINE 6: preview ok cancel buttons
self.previewButton = QPushButton("Preview Slice")
self.previewButton.clicked.connect(self.call_preview)
self.okButton = QPushButton("Smooth Cube")
self.okButton.clicked.connect(self.call_main)
self.okButton.setDefault(True)
self.cancelButton = QPushButton("Cancel")
self.cancelButton.clicked.connect(self.cancel)
hbl6 = QHBoxLayout()
hbl6.addStretch(1)
if self.allow_preview:
hbl6.addWidget(self.previewButton)
hbl6.addWidget(self.cancelButton)
hbl6.addWidget(self.okButton)
# Add Lines to Vertical Layout
# vbl is short for Vertical Box Layout
vbl = QVBoxLayout()
if self.allow_spectral_axes:
vbl.addLayout(hbl1)
vbl.addLayout(hbl2)
vbl.addLayout(hbl3)
vbl.addLayout(hbl4)
vbl.addLayout(hbl5)
vbl.addLayout(hbl6)
self.setLayout(vbl)
self.setMaximumWidth(330)
# Connect kernel combo box to event handler
self.combo.currentIndexChanged.connect(self.selection_changed)
self.selection_changed(0)
self.show()
def _load_options(self):