def __init__(self, program: Program): super().__init__() AppGlobals.Instance().onChipOpened.connect(self.CheckForProgram) AppGlobals.Instance().onChipModified.connect(self.CheckForProgram) self.program = program self.modified = False self.codeEditor = CodeTextEditor() layout = QHBoxLayout() self.setLayout(layout) self._programNameField = QLineEdit(program.name) self._programNameField.textChanged.connect(self.UpdateProgramName) self._parameterEditor = ParameterEditor(program) self._parameterEditor.onParametersChanged.connect(self.ProgramEdited) programNameLabel = QLabel("Name:") sideLayout = QVBoxLayout() sideLayout.addWidget(programNameLabel) sideLayout.addWidget(self._programNameField) sideLayout.addWidget(self._parameterEditor) layout.addLayout(sideLayout, stretch=0) layout.addWidget(self.codeEditor, stretch=1) self.codeEditor.SetCode(self.program.script) self.codeEditor.codeChanged.connect(self.ProgramEdited)
def SaveChip(self, saveAs=False) -> bool: if saveAs or not AppGlobals.Chip().HasBeenSaved(): filename, filterType = QFileDialog.getSaveFileName( self, "Save Chip", filter="uChip Project File (*.ucc)") if filename: AppGlobals.Chip().SaveToFile(Path(filename)) AppGlobals.Instance().onChipSaved.emit() return True return False else: AppGlobals.Chip().SaveToFile(AppGlobals.Chip().path) AppGlobals.Instance().onChipSaved.emit() return True
def __init__(self): super().__init__() AppGlobals.Instance().onChipDataModified.connect(self.UpdateTitle) AppGlobals.Instance().onChipOpened.connect(self.UpdateTitle) AppGlobals.Instance().onChipSaved.connect(self.UpdateTitle) StylesheetLoader.RegisterWidget(self) self.chipEditor = ChipEditor() self.setCentralWidget(self.chipEditor) self.resize(self.screen().size() / 2) self.move(self.screen().size().width() / 2, 0) self.setWindowIcon(QIcon("Images/UCIcon.png")) self._rigViewer = RigViewer() self._editorWindow = ProgramEditorWindow() self._programList = ProgramList(self) self._programList.onProgramEditRequest.connect(self.EditProgram) self._runningProgramsList = RunningProgramsList() self._editorWindow.setVisible(False) menuBar = MenuBar() menuBar.new.connect(self.NewChip) menuBar.open.connect(self.OpenChip) menuBar.save.connect(self.SaveChip) menuBar.saveAs.connect(lambda: self.SaveChip(True)) menuBar.exit.connect(self.close) menuBar.showRigView.connect(self.ShowRigWidget) menuBar.showProgramList.connect(self.ShowProgramList) menuBar.zoomToFit.connect(self.chipEditor.viewer.Recenter) self.updateWorker = ProgramRunnerWorker(self) self.updateWorker.start() killTimer = QTimer(self) killTimer.timeout.connect(self.CheckForKill) killTimer.start(1000) self.setMenuBar(menuBar) self.ShowRigWidget() self.ShowProgramList() self.ShowProgramEditorWindow() self.ShowRunningProgramsList() self._editorWindow.close() AppGlobals.OpenChip(Chip())
def __init__(self, valve: Valve): super().__init__() AppGlobals.Instance().onChipModified.connect(self.CheckForValve) self._valve = valve self.valveToggleButton = QToolButton() self.valveNumberLabel = QLabel("Number") self.valveNumberDial = QSpinBox() self.valveNumberDial.setMinimum(0) self.valveNumberDial.setValue(self._valve.solenoidNumber) self.valveNumberDial.setMaximum(9999) self.valveNumberDial.valueChanged.connect(self.UpdateValve) self.valveNameLabel = QLabel("Name") self.valveNameField = QLineEdit(self._valve.name) self.valveNameField.textChanged.connect(self.UpdateValve) mainLayout = QVBoxLayout() mainLayout.addWidget(self.valveToggleButton, alignment=Qt.AlignCenter) layout = QGridLayout() layout.addWidget(self.valveNameLabel, 0, 0) layout.addWidget(self.valveNameField, 0, 1) layout.addWidget(self.valveNumberLabel, 1, 0) layout.addWidget(self.valveNumberDial, 1, 1) mainLayout.addLayout(layout) self.containerWidget.setLayout(mainLayout) self.valveToggleButton.clicked.connect(self.Toggle) self.Update() self.Move(QPointF())
def __init__(self, programInstance: ProgramInstance, uniqueRun): super().__init__() AppGlobals.Instance().onChipModified.connect(self.UpdateParameterItems) self.editingParameterVisibility = False self.programInstance = programInstance self.uniqueRun = uniqueRun self._programNameWidget = QLabel() layout = QVBoxLayout() self.setLayout(layout) self.runButton = QPushButton("Run") self.runButton.clicked.connect(self.RunProgram) self._stopButton = QPushButton("Stop") self._stopButton.clicked.connect(self.StopProgram) self.parameterItems: List[ProgramParameterItem] = [] self._parametersLayout = QVBoxLayout() layout.addWidget(self._programNameWidget) layout.addLayout(self._parametersLayout) layout.addWidget(self.runButton) layout.addWidget(self._stopButton) timer = QTimer(self) timer.timeout.connect(self.UpdateInstanceView) timer.start(30) self.UpdateInstanceView() self.UpdateParameterItems()
def Duplicate(self) -> 'ChipItem': newPreset = ProgramPreset(self._preset.instance.program) newPreset.instance = self._preset.instance.Clone() newPreset.position = QPointF(self._preset.position) newPreset.name = self._preset.name AppGlobals.Chip().programPresets.append(newPreset) AppGlobals.Instance().onChipModified.emit() return ProgramPresetItem(newPreset)
def Duplicate(self) -> 'ChipItem': newValve = Valve() newValve.position = QPointF(self._valve.position) newValve.name = self._valve.name newValve.solenoidNumber = AppGlobals.Chip().NextSolenoidNumber() AppGlobals.Chip().valves.append(newValve) AppGlobals.Instance().onChipModified.emit() return ValveChipItem(newValve)
def BrowseForImage(self): filename, filterType = QFileDialog.getOpenFileName( self, "Browse for Image", filter="Images (*.png *.bmp *.jpg *.jpeg *.tif *.tiff)") if filename: newImage = Image(Path(filename)) AppGlobals.Chip().images.append(newImage) AppGlobals.Instance().onChipModified.emit() self.viewer.CenterItem(self.viewer.AddItem( ImageChipItem(newImage)))
def NewProgram(self): newProgram = Program() AppGlobals.Chip().programs.append(newProgram) AppGlobals.Instance().onChipModified.emit() for item in [ self._programsList.item(row) for row in range(self._programsList.count()) ]: if item.program is newProgram: self._programsList.setCurrentItem(item) self.onProgramEditRequest.emit(newProgram) return
def __init__(self, dataType: DataType): super().__init__() self.dataType = dataType AppGlobals.Instance().onChipModified.connect(self.Repopulate) self.Repopulate() timer = QTimer(self) timer.timeout.connect(self.UpdateNames) timer.start(30)
def __init__(self, parent): super().__init__(parent) self._programsLabel = QLabel("Programs") self._programsList = QListWidget() self._programsList.itemClicked.connect(self.SelectProgram) self._programsList.itemDoubleClicked.connect(self.EditProgram) AppGlobals.Instance().onChipModified.connect(self.SyncInstances) self._instances: Dict[Program, ProgramInstance] = {} self._newButton = QPushButton("Create New Program") self._newButton.clicked.connect(self.NewProgram) layout = QVBoxLayout() layout.addWidget(self._programsLabel) layout.addWidget(self._programsList) layout.addWidget(self._newButton) self.setLayout(layout) AppGlobals.Instance().onChipOpened.connect(self.SyncInstances)
def SelectProgramPreset(self): if not AppGlobals.Chip().programs: return presetSelection, confirmed = QInputDialog.getItem( self, "Program Preset", "Program", [program.name for program in AppGlobals.Chip().programs], 0, False) if confirmed: selected = [ program for program in AppGlobals.Chip().programs if program.name == presetSelection ][0] newPreset = ProgramPreset(selected) AppGlobals.Chip().programPresets.append(newPreset) AppGlobals.Instance().onChipModified.emit() self.viewer.CenterItem( self.viewer.AddItem(ProgramPresetItem(newPreset)))
def __init__(self, preset: ProgramPreset): super().__init__() AppGlobals.Instance().onChipModified.connect(self.CheckForPreset) self._preset = preset self._presetNameField = QLineEdit(preset.name) self._presetNameField.textChanged.connect(self.UpdatePreset) self._presetNameLabel = QLabel() self._instanceWidget = ProgramInstanceWidget(preset.instance, True) layout = QVBoxLayout() layout.addWidget(self._presetNameField) layout.addWidget(self._presetNameLabel) layout.addWidget(self._instanceWidget) self.containerWidget.setLayout(layout) self.Update() self.CheckForPreset()
def __init__(self): super().__init__() self.viewer = ChipSceneViewer() actionsLayout = QHBoxLayout() self._actionsWidget = QWidget(self.viewer) self._actionsWidget.setLayout(actionsLayout) self._lockButton = QToolButton() self._lockButton.setText("Done") self._lockButton.clicked.connect(lambda: self.SetEditing(False)) self._editButton = QToolButton() self._editButton.setText("Edit") self._editButton.clicked.connect(lambda: self.SetEditing(True)) self._plusButton = QToolButton() self._plusButton.setText("+") self._plusButton.setPopupMode(QToolButton.InstantPopup) actionsLayout.addWidget(self._plusButton) actionsLayout.addWidget(self._lockButton) actionsLayout.addWidget(self._editButton) menu = QMenu(self._plusButton) menu.addAction("Valve").triggered.connect(self.AddValve) menu.addAction("Program Preset...").triggered.connect( self.SelectProgramPreset) menu.addAction("Image...").triggered.connect(self.BrowseForImage) self._plusButton.setMenu(menu) layout = QHBoxLayout() layout.addWidget(self.viewer) self.setLayout(layout) self._mode = Mode.VIEWING AppGlobals.Instance().onChipOpened.connect(self.LoadChip)
def UpdateParameterValue(self): lastValue = self._programInstance.parameterValues[self.parameter] if self.parameter.dataType is DataType.INTEGER: self._programInstance.parameterValues[ self.parameter] = self._valueField.value() elif self.parameter.dataType is DataType.FLOAT: self._programInstance.parameterValues[ self.parameter] = self._valueField.value() elif self.parameter.dataType is DataType.BOOLEAN: self._programInstance.parameterValues[ self.parameter] = self._valueField.currentData() elif self.parameter.dataType is DataType.STRING: self._programInstance.parameterValues[ self.parameter] = self._valueField.text() elif self.parameter.dataType is not DataType.OTHER: self._programInstance.parameterValues[ self.parameter] = self._valueField.currentData() self._programInstance.parameterVisibility[ self.parameter] = self.visibilityToggle.isChecked() if self._programInstance.parameterValues[self.parameter] != lastValue: AppGlobals.Instance().onChipModified.emit()
def RequestDelete(self): AppGlobals.Chip().valves.remove(self._valve) AppGlobals.Instance().onChipModified.emit()
def RequestDelete(self): super().RequestDelete() AppGlobals.Chip().programPresets.remove(self._preset) AppGlobals.Instance().onChipModified.emit()
def SaveProgram(self): self.program.script = self.codeEditor.Code() self.program.name = self._programNameField.text() self._parameterEditor.Save() self.modified = False AppGlobals.Instance().onChipModified.emit()
def DeleteProgram(self, program: Program): if QMessageBox.question( self, "Confirm Deletion", "Are you sure you want to delete " + program.name + "?") is QMessageBox.Yes: AppGlobals.Chip().programs.remove(program) AppGlobals.Instance().onChipModified.emit()
def Move(self, delta: QPointF): if delta != QPointF(): AppGlobals.Instance().onChipDataModified.emit() self._valve.position += delta self.GraphicsObject().setPos(self._valve.position)
def UpdateValve(self): self._valve.solenoidNumber = self.valveNumberDial.value() self._valve.name = self.valveNameField.text() AppGlobals.Instance().onChipDataModified.emit()
def AddValve(self): newValve = Valve() newValve.solenoidNumber = AppGlobals.Chip().NextSolenoidNumber() AppGlobals.Chip().valves.append(newValve) AppGlobals.Instance().onChipModified.emit() self.viewer.CenterItem(self.viewer.AddItem(ValveChipItem(newValve)))
def UpdatePreset(self): self._preset.name = self._presetNameField.text() AppGlobals.Instance().onChipDataModified.emit()