def ask_login(parent=None): # type: (Any) -> AccountInfo """Ask login with a dialog. parent (QWidget, optional): Defaults to None. Parent widget. Returns: cgtwq.AccountInfo: Account logged in. """ _app = application() dialog = QDialog(parent) account_input = QLineEdit() password_input = QLineEdit() _setup_login_dialog(dialog, account_input, password_input) while True: dialog.exec_() if dialog.result() == QDialog.Rejected: raise ValueError("Rejected") account, password = account_input.text(), password_input.text() try: return cgtwq.login(account, password) except (ValueError, cgtwq.AccountNotFoundError, cgtwq.PasswordError) as ex: msg = text_type(ex) QMessageBox.critical(parent, "登录失败", msg)
def showSystemSettings(system): from brigks.gui.systemSettingsWidget import SystemSettingsWidget widget = SystemSettingsWidget(system) dialog = QDialog() layout = QVBoxLayout() layout.addWidget(widget) dialog.setLayout(layout) if not dialog.exec_(): return
def DDTree(): tree = TreeWidget() dialog = QDialog() layout = QVBoxLayout() layout.addWidget(tree) dialog.setLayout(layout) if not dialog.exec_(): return
def divcon(data): """Divide by a constant, taken from user input""" parent = QDialog() constant, ok = QInputDialog.getDouble(parent, "X/C", "Input constant:") if not ok: raise RuntimeError("User cancelled input") return data / constant
def subcon(data): """Subtract a constant, taken from user input""" parent = QDialog() constant, ok = QInputDialog.getDouble(parent, "X-C", "Input constant:") if not ok: raise RuntimeError("User cancelled input") return data - constant
def addcon(data): """Add a constant, taken from user input""" parent = QDialog() constant, ok = QInputDialog.getDouble(parent, "X+C", "Input constant:") if not ok: raise RuntimeError("User cancelled input") return data + constant
def mulcon(data): """Multiply by a constant, taken from user input""" parent = QDialog() constant, ok = QInputDialog.getDouble(parent, "X*C", "Input constant:") if not ok: raise RuntimeError("User cancelled input") return data * constant
def getUnitFactor(): parent = QDialog() title = "Change Units" label = "Enter conversion factor:" factor, ok = QInputDialog.getDouble(parent, title, label) if not ok: raise RuntimeError("User cancelled input") return factor
def inputname(): parent = QDialog() title = "Change Name" label = "Enter new name:" dialog = QInputDialog.getText(parent, title, label) if dialog[1]: name = dialog[0] return name
def timeOffset(data): result = XPadDataItem(data) parent = QDialog() offset, ok = QInputDialog.getDouble(parent, "Time Offset", "Input time offest:") if not ok: raise RuntimeError("User cancelled input") result.dim[data.order].data = np.add(result.dim[data.order].data, offset) result.name = f"Timoff({result.name}, {offset})" result.label = f"Timoff({result.label}, {offset})" return result
def powcon(data): """Exponentiate by a constant, taken from user input""" result = XPadDataItem(data) parent = QDialog() constant, ok = QInputDialog.getDouble(parent, "X^C", "Input constant:") if not ok: raise RuntimeError("User cancelled input") result.data = np.power(data.data, constant) result.name = f"({data.name})^{constant}" result.label = f"({data.label})^{constant}" result.units = f"({data.units})^{constant}" return result
def _show_bones_hierarchy(self, file_path): dlg = QDialog(parent=dcc.get_main_window() or None) dlg.setWindowTitle('Select Skeleton Node') lyt = layouts.VerticalLayout(spacing=0, margins=(0, 0, 0, 0)) dlg.setLayout(lyt) bone_hierarchy_widget = BoneHierarchyWidget(file_path, parent=dlg) current_bone = self.text() or '' bone_hierarchy_widget.set_bone(current_bone) lyt.addWidget(bone_hierarchy_widget) dlg.exec_() selected_node = bone_hierarchy_widget.selected_node if not selected_node: return self.setText(selected_node)
def changeunits(data): result = XPadDataItem(data) parent = QDialog() title = "Change Units" label = "Enter new units:" new_unit, ok = QInputDialog.getText(parent, title, label) if not ok: raise RuntimeError("User cancelled input") unit_factor = getUnitFactor() if unit_factor and new_unit: result.data = np.multiply(data.data, unit_factor) result.units = new_unit return result
def __init__(self, name, report, parent=None): QDialog.__init__(self, parent) icon = self.style().standardIcon(QStyle.SP_MessageBoxCritical) self.setWindowTitle('Error reporting') self.setWindowIcon(icon) try: font = QFontDatabase().systemFont(QFontDatabase.FixedFont) except AttributeError as e: font = QFont() font.setStyleHint(QFont.TypeWriter) self.text = QPlainTextEdit() self.text.setFont(font) self.text.setReadOnly(True) self.text.setLineWrapMode(QPlainTextEdit.NoWrap) self.text.setPlainText(report) TracebackHighlighter(self.text.document()) icon_label = QLabel() icon_label.setPixmap(icon.pixmap(ICON_SIZE, ICON_SIZE)) label = QLabel("{} error !".format(name)) label.setFont(QFont('default', pointSize=14)) button_copy = QPushButton('Copy to clipboard') button_copy.clicked.connect(self._copy) layout = QGridLayout(self) layout.addWidget(icon_label, 0, 0) layout.addWidget(label, 0, 1) layout.addWidget(self.text, 1, 0, 1, 2) layout.addWidget(button_copy, 2, 0, 1, 2) layout.setColumnStretch(1, 100) self.setModal(True) self.resize(600, 400)
def addAttributeSlot(self): """ Adds a new attribute (column) to the table """ dialog = QDialog(self) dialog.setModal(True) dialog.setWindowTitle('Add Attribute') layout = QVBoxLayout() dialog.setLayout(layout) form = QFormLayout() nameBox = QLineEdit() typeCombo = QComboBox() for attrType in _attrTypes: typeName = partio.TypeName(attrType) typeCombo.addItem(typeName) typeCombo.setCurrentIndex(partio.FLOAT) countBox = QLineEdit() countBox.setValidator(QIntValidator()) countBox.setText('1') fixedCheckbox = QCheckBox() valueBox = QLineEdit() valueBox.setText('0') form.addRow('Name:', nameBox) form.addRow('Type:', typeCombo) form.addRow('Count:', countBox) form.addRow('Fixed:', fixedCheckbox) form.addRow('Default Value:', valueBox) layout.addLayout(form) buttons = QHBoxLayout() layout.addLayout(buttons) add = QPushButton('Add') add.clicked.connect(dialog.accept) buttons.addWidget(add) cancel = QPushButton('Cancel') cancel.clicked.connect(dialog.reject) buttons.addWidget(cancel) if not dialog.exec_(): return name = str(nameBox.text()) if not name: print 'Please supply a name for the new attribute' # TODO: prompt return attrType = typeCombo.currentIndex() count = int(countBox.text()) fixed = fixedCheckbox.isChecked() values = list(str(valueBox.text()).strip().split()) for i in range(count): if i < len(values): value = values[i] else: value = values[-1] if attrType == partio.INT or attrType == partio.INDEXEDSTR: values[i] = int(value) elif attrType == partio.FLOAT or attrType == partio.VECTOR: values[i] = float(value) # pylint:disable=R0204 else: values[i] = 0.0 # pylint:disable=R0204 value = tuple(values) self.data.addAttribute(name, attrType, count, fixed, value)
def _on_open_rig_control_selector(self): from tpRigToolkit.tools.controlrig.core import client, tool, toolset dlg = QDialog(parent=self) dlg.setWindowTitle('Select Control') dlg.setWindowIcon(resources.icon('circle')) lyt = layouts.VerticalLayout(spacing=0, margins=(0, 0, 0, 0)) lyt.setSpacing(0) lyt.setContentsMargins(0, 0, 0, 0) dlg.setLayout(lyt) if hasattr(self._rig_object, 'full_path'): current_project = self._rig_object else: current_project = self._rig_object.get_project() project_path = current_project.full_path # TODO: The project itself should return this path controls_path = os.path.join(project_path, 'controls.json') self._control_rig_client = client.ControlRigClient.create( tool.ControlRigTool.ID) control_selector = toolset.ControlRigToolset( as_selector=True, controls_path=controls_path, control_data=self._control_data, selector_parent=dlg) control_selector.initialize(self._control_rig_client) lyt.addWidget(control_selector) dlg.resize(600, 700) dlg.exec_() control_data = control_selector.control_data or dict() if not control_data and self._control_data: return if control_data: control_data.pop('control_name', None) # control_data.pop('control_data', None) self.controlSelected.emit(control_data)
def echo(self, data_dict, reply_dict): reply_dict['result'] = data_dict['text'] reply_dict['success'] = True def set_title(self, data_dict, reply_dict): self._window.setWindowTitle(data_dict['title']) reply_dict['result'] = True reply_dict['success'] = True def sleep(self, data_dict, reply_dict): for i in range(6): logger.info('Sleeping {}'.format(i)) time.sleep(1) reply_dict['result'] = True reply_dict['success'] = True if __name__ == '__main__': from Qt.QtWidgets import QApplication, QDialog, QPlainTextEdit app = QApplication(sys.argv) window = QDialog() window.setWindowTitle('Example Base') window.setFixedSize(240, 150) QPlainTextEdit(window) server = ExampleServer(window) window.show() app.exec_()
def addAttributeSlot(self): """ Adds a new attribute (column) to the table """ dialog = QDialog(self) dialog.setModal(True) dialog.setWindowTitle('Add Attribute') layout = QVBoxLayout() dialog.setLayout(layout) form = QFormLayout() nameBox = QLineEdit() typeCombo = QComboBox() for attrType in _attrTypes: typeName = partio.TypeName(attrType) typeCombo.addItem(typeName) typeCombo.setCurrentIndex(partio.FLOAT) countBox = QLineEdit() countBox.setValidator(QIntValidator()) countBox.setText('1') fixedCheckbox = QCheckBox() valueBox = QLineEdit() valueBox.setText('0') form.addRow('Name:', nameBox) form.addRow('Type:', typeCombo) form.addRow('Count:', countBox) form.addRow('Fixed:', fixedCheckbox) form.addRow('Default Value:', valueBox) layout.addLayout(form) buttons = QHBoxLayout() layout.addLayout(buttons) add = QPushButton('Add') add.clicked.connect(dialog.accept) buttons.addWidget(add) cancel = QPushButton('Cancel') cancel.clicked.connect(dialog.reject) buttons.addWidget(cancel) if not dialog.exec_(): return name = str(nameBox.text()) if not name: print('Please supply a name for the new attribute') # TODO: prompt return attrType = typeCombo.currentIndex() count = int(countBox.text()) fixed = fixedCheckbox.isChecked() values = list(str(valueBox.text()).strip().split()) for i in range(count): if i < len(values): value = values[i] else: value = values[-1] if attrType == partio.INT or attrType == partio.INDEXEDSTR: values[i] = int(value) elif attrType == partio.FLOAT or attrType == partio.VECTOR: values[i] = float(value) # pylint:disable=R0204 else: values[i] = 0.0 # pylint:disable=R0204 value = tuple(values) self.data.addAttribute(name, attrType, count, fixed, value)