class DataProcessingDialog(QDialog): ''' Signals ''' newDataAdded = Signal(str, str, str) dataChanged = Signal(str, str, str) def __init__(self, dataManager, parent=None, inputList=None): self.operations = { 'Filtering': [FilterGroup, 'Filter settings', -1], 'Average': [AverageGroup, 'Window settings', -1], 'Energy': [EnergyGroup, 'Window settings', -1], 'Power': [PowerGroup, 'Window settings', -1], 'Peak-To-Peak': [Peak2PeakGroup, 'Window settings', -1], 'Variance': [VarianceGroup, 'Window settings', -1], 'Entropy': [EntropyGroup, 'Window settings', -1], 'Skewness': [SkewnessGroup, 'Window settings', -1], 'Thresholding': [ThresholdGroup, 'Settings', -1], 'Detrend': [DetrendGroup, 'Settings', -1], 'STFT': [STFTGroup, 'Spectrum settings', -1], 'CWT': [CWTGroup, 'CWT settings', -1] } QDialog.__init__(self, parent) self.dataManager = dataManager self.setWindowTitle('Data Processing') self.inputList = inputList #Setup Layouts self.mainLayout = QGridLayout(self) self.setupInLayout() self.setupProcessLayout() self.setupOutLayout() self.setupBtnBoxLayout() ''' Input Layout ''' def setupInLayout(self): inGroup = QGroupBox('Input to process') inLayout = QFormLayout(inGroup) self.inTree = DataSelector(self.dataManager, inputList=self.inputList) self.operChooser = QComboBox() [self.operChooser.addItem(i) for i in self.operations] self.operChooser.currentTextChanged.connect(self.setOperation) inLayout.addRow(QLabel('Select Input')) inLayout.addRow(self.inTree) inLayout.addRow(QLabel('Operation'), self.operChooser) self.mainLayout.addWidget(inGroup, 0, 0) def setOperation(self): print('Set Operation') index = self.operations[self.operChooser.currentText()][2] self.processLayout.setCurrentIndex(index) ''' Signal Processing Settings Layout ''' def setupProcessLayout(self): processGroup = QGroupBox('Processing settings') self.processLayout = QStackedLayout() self.mainLayout.addLayout(self.processLayout, 1, 0) # Setup Processing Sublayouts for op in self.operations: index = self.createGroup(self.operations[op][0], op, self.operations[op][1]) self.operations[op][2] = index ''' Create Groups ''' def createGroup(self, GroupClass, name, title): newGroup = GroupClass(title, fs=self.dataManager.getFs()) newGroup.progress.connect(self.updateProgress) index = self.processLayout.addWidget(newGroup) return index ''' Output Layout ''' def setupOutLayout(self): outGroup = QGroupBox('Output') outLayout = QFormLayout(outGroup) self.outNameEdit = QLineEdit() inAsOutCheck = QCheckBox('Replace input') inAsOutCheck.toggled.connect(self.setInputAsOutput) outLayout.addWidget(inAsOutCheck) outLayout.addRow('Output name', self.outNameEdit) self.mainLayout.addWidget(outGroup, 2, 0) def setInputAsOutput(self, isOn): if isOn: inStruct = self.inTree.getSelectedStruct() wName = list(inStruct.keys())[0] gName = list(inStruct[wName].keys())[0] self.outNameEdit.setText(gName) self.outNameEdit.setDisabled(True) else: self.outNameEdit.setEnabled(True) ''' Button Box Layout ''' def setupBtnBoxLayout(self): bottomLayout = QHBoxLayout() self.progBar = QProgressBar() self.progBar.setVisible(False) bottomLayout.addWidget(self.progBar) buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Close) buttonBox.accepted.connect(self.okBtnBox) buttonBox.rejected.connect(self.close) bottomLayout.addWidget(buttonBox) self.mainLayout.addLayout(bottomLayout, 3, 0) def okBtnBox(self): inStruct = self.inTree.getSelectedStruct() data = self.dataManager.getData(inStruct, inv=True) wName = list(data.keys())[0] gName = list(data[wName].keys())[0] outName = self.outNameEdit.text() if outName in self.dataManager[wName].getColumnNames(): msgBox = QMessageBox() msgBox.setText('Signal already exists') msgBox.setInformativeText("Do you want to replace it?") msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) msgBox.setDefaultButton(QMessageBox.Ok) ret = msgBox.exec() if ret == QMessageBox.Ok: self.dataManager.removeSignal(wName, outName) print('removed') else: return self.progBar.setVisible(True) outData = self.processLayout.currentWidget().process( data[wName][gName]) self.dataManager.appendSignal(wName, outName, inStruct[wName][gName], outData) self.newDataAdded.emit(wName, gName, self.outNameEdit.text()) def updateProgress(self, prog): self.progBar.setValue(prog)
class MetalGUI(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) self.parent = parent self.supported_setups = ['TOP-DOWN'] self.stacked_layout = QStackedLayout() self.__setup_widget = None self.__metal_main_widget = None self.__init_main_widget__() self.stacked_layout.setCurrentIndex(0) self.setLayout(self.stacked_layout) def minimumSizeHint(self): return self.stacked_layout.currentWidget().minimumSizeHint() def sizeHint(self): return self.stacked_layout.currentWidget().sizeHint() def __load_settings__(self): base_path = Path(__file__).parent settings_path = str( (base_path / '../resources/PRINTER_SETTINGS.json').resolve()) settings_file = QFile(settings_path) if settings_file.open(QIODevice.ReadOnly | QIODevice.Text): file_data = QJsonDocument.fromJson( settings_file.readAll()).object() if "metal_printer_settings" in file_data: printer_setup = str( file_data["metal_printer_settings"]["printer_setup"]) if printer_setup == self.supported_setups[0]: self.__select_setup__(0) else: return False return True settings_file.close() return False def __init_configuration_selection_widget__(self): self.__setup_widget = QWidget(self) setup_layout = QHBoxLayout() for idx in range(len(self.supported_setups)): button = QPushButton(self.supported_setups[idx], self.__setup_widget) button.setFixedSize(200, 200) button.clicked.connect(self.__select_setup__) setup_layout.addWidget(button) self.__setup_widget.setLayout(setup_layout) self.stacked_layout.addWidget(self.__setup_widget) def __select_setup__(self, idx): self.selected_setup = self.supported_setups[idx] self.__init_main_widget__() self.stacked_layout.setCurrentIndex(1) self.parent.move( self.desktops.screen(0).rect().center() - self.__metal_main_widget.rect().center()) def __init_main_widget__(self): self.__metal_main_widget = QTabWidget(self) self.__metal_main_widget.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) self.__gcode_sender_widget = GCodeSenderGUI( parent=self.__metal_main_widget) self.__slicer_widget = MetalSlicerGUI(parent=self.__metal_main_widget) self.__slicer_widget.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) self.__metal_main_widget.addTab(self.__gcode_sender_widget, 'GCode Sender') self.__metal_main_widget.addTab(self.__slicer_widget, 'Slicer') self.stacked_layout.addWidget(self.__metal_main_widget) self.desktops = QDesktopWidget() @Slot() def closeEvent(self, event: QCloseEvent): if self.__setup_widget: self.__setup_widget.close() if self.__metal_main_widget: self.__slicer_widget.close() self.__metal_main_widget.close() event.accept() def get_settings_window(self, parent=None): printer_settings = QGroupBox("Metal Printer Settings:", parent) gcodesender_settings = self.__gcode_sender_widget.get_settings_window( printer_settings) settings_layout = QVBoxLayout(printer_settings) settings_layout.addWidget(gcodesender_settings) return printer_settings
class DLPGUI(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) self.parent = parent self.supported_setups = ['BOTTOM-UP', 'TOP-DOWN'] self.supported_projectors = ['VisitechLRSWQ', 'VisitechLRS4KA'] self.supported_motors = ['ClearpathSDSK', 'ClearpathSCSK', 'Nanostage'] self.selected_setup = self.supported_setups[0] self.selected_projector = self.supported_projectors[0] self.selected_motor = self.supported_motors[0] self.stacked_layout = QStackedLayout() self.__setup_widget = None self.__dlp_main_widget = None if not self.__load_settings__(): self.__init_configuration_selection_widget__() self.__init_projector_selection_widget__() self.__init_motor_selection_widget__() self.stacked_layout.setCurrentIndex(0) self.setLayout(self.stacked_layout) def minimumSizeHint(self): return self.stacked_layout.currentWidget().minimumSizeHint() def sizeHint(self): return self.stacked_layout.currentWidget().sizeHint() def __load_settings__(self): base_path = Path(__file__).parent settings_path = str( (base_path / '../resources/PRINTER_SETTINGS.json').resolve()) settings_file = QFile(settings_path) if settings_file.open(QIODevice.ReadOnly | QIODevice.Text): file_data = QJsonDocument.fromJson( settings_file.readAll()).object() if "dlp_settings" in file_data: printer_setup = str(file_data["dlp_settings"]["printer_setup"]) if printer_setup == self.supported_setups[0]: self.__select_setup__(0) elif printer_setup == self.supported_setups[1]: self.__select_setup__(1) else: return False projector_setup = str( file_data["dlp_settings"]["projector_setup"]) if projector_setup == self.supported_projectors[0]: self.__select_projector__(None, 0) elif projector_setup == self.supported_projectors[1]: self.__select_projector__(None, 1) else: return False motor_setup = str(file_data["dlp_settings"]["motor_setup"]) if motor_setup == self.supported_motors[0]: self.__select_motor__(None, 0) elif motor_setup == self.supported_motors[1]: self.__select_motor__(None, 1) elif motor_setup == self.supported_motors[2]: self.__select_motor__(None, 2) else: return False return True settings_file.close() return False def __init_configuration_selection_widget__(self): self.__setup_widget = QWidget(self) setup_layout = QHBoxLayout() for idx in range(len(self.supported_setups)): button = QPushButton(self.supported_setups[idx], self.__setup_widget) button.setFixedSize(200, 200) button.clicked.connect(self.__select_setup__) setup_layout.addWidget(button) self.__setup_widget.setLayout(setup_layout) self.stacked_layout.addWidget(self.__setup_widget) # self.stacked_layout.setCurrentIndex(0) def __init_projector_selection_widget__(self): self.__projector_setup_widget = QWidget(self) projector_setup_layout = QHBoxLayout() for idx in range(len(self.supported_projectors)): button = QPushButton(self.supported_projectors[idx], self.__setup_widget) button.setFixedSize(200, 200) button.clicked.connect( lambda state=None, x=idx: self.__select_projector__(state, x)) projector_setup_layout.addWidget(button) self.__projector_setup_widget.setLayout(projector_setup_layout) self.stacked_layout.addWidget(self.__projector_setup_widget) def __init_motor_selection_widget__(self): self.__motor_setup_widget = QWidget(self) motor_setup_layout = QHBoxLayout() for idx in range(len(self.supported_motors)): button = QPushButton(self.supported_motors[idx], self.__setup_widget) button.setFixedSize(200, 200) button.clicked.connect( lambda state=None, x=idx: self.__select_motor__(state, x)) motor_setup_layout.addWidget(button) self.__motor_setup_widget.setLayout(motor_setup_layout) self.stacked_layout.addWidget(self.__motor_setup_widget) def __select_setup__(self, idx): self.selected_setup = self.supported_setups[idx] self.stacked_layout.setCurrentIndex(1) def __select_projector__(self, button_state, projector_id): self.selected_projector = self.supported_projectors[projector_id] self.stacked_layout.setCurrentIndex(2) def __select_motor__(self, button_state, motor_id): self.selected_motor = self.supported_motors[motor_id] self.__init_main_widget__() self.stacked_layout.setCurrentIndex(3) # self.parent.move(self.desktops.screen(0).rect().center() - self.__dlp_main_widget.rect().center()) def __init_main_widget__(self): self.__dlp_main_widget = QTabWidget(self) self.__dlp_main_widget.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) self.dlp_controller = DLPMainController(self.selected_setup, self.selected_projector, self.selected_motor) self.__printer_widget = DLPPrinterGUI( dlp_controller=self.dlp_controller, parent=self.__dlp_main_widget) self.__slicer_widget = DLPSlicerGUI(dlp_controller=self.dlp_controller, parent=self.__dlp_main_widget) self.__settings_widget = DLPSettingsGUI( dlp_controller=self.dlp_controller, parent=self.__dlp_main_widget) self.__printer_widget.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) self.__slicer_widget.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) self.__settings_widget.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) self.__dlp_main_widget.addTab(self.__printer_widget, 'DLP') self.__dlp_main_widget.addTab(self.__slicer_widget, 'Slicer') self.__dlp_main_widget.addTab(self.__settings_widget, 'Advanced Settings') self.stacked_layout.addWidget(self.__dlp_main_widget) self.dlp_controller.save_default_parameters() # self.__dlp_main_widget.move() # self.desktops = QDesktopWidget() # self.parent.move(self.desktops.screen(0).rect().center() - self.__dlp_main_widget.rect().center()) # self.__dlp_main_widget.move(QGuiApplication.desktop().screen().rect().center() - self.rect().center()) def reset_main_widget(self): self.dlp_controller.close_projector() self.__init_main_widget__() self.stacked_layout.setCurrentIndex(3) # self.parent.move(self.desktops.screen(0).rect().center() - self.__dlp_main_widget.rect().center()) @Slot() def closeEvent(self, event: QCloseEvent): if self.__setup_widget: self.__setup_widget.close() if self.__dlp_main_widget: self.__printer_widget.close() self.__slicer_widget.close() self.__settings_widget.close() self.__dlp_main_widget.close() event.accept() def get_settings_window(self, parent=None): printer_settings = QGroupBox("DLP Printer Settings:", parent) dlp_setup_label = QLabel("DLP Setup:", printer_settings) self.dlp_setup_combo = QComboBox(printer_settings) self.dlp_setup_combo.addItems(self.supported_setups) self.dlp_setup_combo.setCurrentIndex( self.supported_setups.index(self.selected_setup)) dlp_projector_label = QLabel("DLP Projector:", printer_settings) self.dlp_projector_combo = QComboBox(printer_settings) self.dlp_projector_combo.addItems(self.supported_projectors) self.dlp_projector_combo.setCurrentIndex( self.supported_projectors.index(self.selected_projector)) dlp_motor_label = QLabel("DLP Motor:", printer_settings) self.dlp_motor_combo = QComboBox(printer_settings) self.dlp_motor_combo.addItems(self.supported_motors) self.dlp_motor_combo.setCurrentIndex( self.supported_motors.index(self.selected_motor)) apply_button = QPushButton("Apply Changes", printer_settings) apply_button.clicked.connect(self.__apply_settings) printer_settings_layout = QGridLayout(printer_settings) printer_settings_layout.addWidget(dlp_setup_label, 1, 0) printer_settings_layout.addWidget(self.dlp_setup_combo, 1, 1) printer_settings_layout.addWidget(dlp_projector_label, 2, 0) printer_settings_layout.addWidget(self.dlp_projector_combo, 2, 1) printer_settings_layout.addWidget(dlp_motor_label, 3, 0) printer_settings_layout.addWidget(self.dlp_motor_combo, 3, 1) printer_settings_layout.addWidget(apply_button, 4, 1) return printer_settings @Slot() def __apply_settings(self): self.selected_setup = self.supported_setups[ self.dlp_setup_combo.currentIndex()] if self.supported_motors[self.dlp_motor_combo.currentIndex( )] is not self.selected_motor: self.selected_motor = self.supported_motors[ self.dlp_motor_combo.currentIndex()] self.dlp_controller.change_motor(self.selected_setup, self.selected_motor) if self.supported_projectors[self.dlp_projector_combo.currentIndex( )] is not self.selected_projector: self.selected_projector = self.supported_projectors[ self.dlp_projector_combo.currentIndex()] self.dlp_controller.change_projector(self.selected_projector) self.dlp_controller.save_default_parameters()