class AddVariableWindow(QObject): add_variable = Signal(Variable) def __init__(self, ui_file, compartment_list, parent=None): super(AddVariableWindow, self).__init__(parent) ui_file = QFile(ui_file) ui_file.open(QFile.ReadOnly) self.window = QUiLoader().load(ui_file) add_button = self.window.findChild(QPushButton, 'AddButton') add_button.clicked.connect(self.on_add_clicked) self.compartment_list = compartment_list self.origin_combobox = self.window.findChild(QComboBox, 'OriginComboBox') self.destination_combobox = self.window.findChild( QComboBox, 'DestinationComboBox') for compartment in compartment_list: self.origin_combobox.addItem(compartment.name) self.destination_combobox.addItem(compartment.name) self.origin_combobox.addItem('Birth') self.destination_combobox.addItem('Death') self.window.setWindowIcon(QIcon(os.path.join( 'ui_files', 'icon.png'))) # Set the window icon self.window.show() def on_add_clicked(self): equationLE = self.window.findChild(QLineEdit, 'EquationLE') descriptionLE = self.window.findChild(QLineEdit, 'DescriptionLE') try: origin = self.compartment_list[self.origin_combobox.currentIndex()] except IndexError: origin = None try: end = self.compartment_list[ self.destination_combobox.currentIndex()] except IndexError: end = None if origin == end and origin is None: # Both are None QMessageBox.critical(self.window, "Error", "Origin and End cannot be Birth and Death") return elif origin == end: # Both are the same but not None QMessageBox.critical(self.window, "Error", "Origin and End cannot be the same") return new_variable = Variable(equation=parse_latex(str( equationLE.text())).simplify(), origin=origin, end=end, description=str(descriptionLE.text())) self.add_variable.emit(new_variable) self.window.destroy()
def show_create_project_dialog(self) -> None: """Dialog to create new project.""" file = os.path.join(os.environ['BCISTREAM_ROOT'], 'framework', 'qtgui', 'new_project.ui') project = QUiLoader().load(file, self.parent_frame) project.buttonBox.button(QDialogButtonBox.Ok).clicked.connect( lambda evt: self.create_project( project.lineEdit_project_name.text(), project.radioButton_visualization.isChecked(), project.radioButton_stimulus_delivery.isChecked(), project.radioButton_data_analysis.isChecked())) project.buttonBox.button( QDialogButtonBox.Ok).clicked.connect(lambda evt: project.destroy()) project.buttonBox.button(QDialogButtonBox.Cancel).clicked.connect( lambda evt: project.destroy()) project.lineEdit_project_name.textChanged.connect( lambda str_: project.buttonBox.button(QDialogButtonBox.Ok). setDisabled(os.path.isdir(os.path.join(self.projects_dir, str_)))) center = QDesktopWidget().availableGeometry().center() geometry = project.frameGeometry() geometry.moveCenter(center) project.move(geometry.topLeft()) project.show()
class AddCompartment(QObject): add_compartment = Signal(Compartment) def __init__(self, ui_file, parent=None): super(AddCompartment, self).__init__(parent) ui_file = QFile(ui_file) ui_file.open(QFile.ReadOnly) self.window = QUiLoader().load(ui_file) add_button = self.window.findChild(QPushButton, 'AddButton') add_button.clicked.connect(self.on_add_clicked) self.nameLE = self.window.findChild(QLineEdit, 'NameLE') self.symbolLE = self.window.findChild(QLineEdit, 'SymbolLE') self.initLE = self.window.findChild(QLineEdit, 'InitLE') self.infectionStateCheckBox = self.window.findChild( QCheckBox, 'InfectionStateCheckBox') # Add Constraints self.initLE.setValidator(QDoubleValidator()) self.nameLE.setMaxLength(32) self.symbolLE.setMaxLength(32) self.initLE.setMaxLength(16) self.window.setWindowIcon(QIcon(os.path.join( 'ui_files', 'icon.png'))) # Set the window icon self.window.show() def on_add_clicked(self): new_compartment = Compartment( name=str(self.nameLE.text()), symbol=sym.symbols(str(self.symbolLE.text())), value=float(self.initLE.text()), infection_state=True if self.infectionStateCheckBox.isChecked() else False) self.add_compartment.emit(new_compartment) self.window.destroy()