class VerticalMontageFromCSV(QDialog): def __init__(self, parent=None): #Constructor super(VerticalMontageFromCSV, self).__init__(parent) self.montage = Montages() self.error = Error(self) self.CSVLabel = QPushButton( 'Provide full path to CSV file for creating montages', self) QPushButtonStyleStr = 'QPushButton{ background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #eafaf1, stop: 1 #d5f5e3); } \ QPushButton:hover{ background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #b4e6ed, stop: 1 #a6e3ec); } \ QPushButton:pressed{ background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #b4e6ed, stop: 1 #60c1dc);}' self.CSVLabel.setStyleSheet(QPushButtonStyleStr) self.CSVLabel.setFixedWidth(310) self.CSVLabel.clicked.connect(self.showPathToCSV) self.orLabel1 = QLabel("or", self) self.orLabel1.setAlignment(QtCore.Qt.AlignCenter) self.browse1 = QPushButton("Browse", self) self.browse1.setStyleSheet(QPushButtonStyleStr) self.browse1.clicked.connect(self.getCSVPath) self.CSVPathName = QLabel("Path: ", self) self.imageLabel = QPushButton( 'Provide path to where images are located', self) self.imageLabel.setStyleSheet(QPushButtonStyleStr) self.imageLabel.setFixedWidth(310) self.imageLabel.clicked.connect(self.showPathToImage) self.orLabel2 = QLabel("or", self) self.orLabel2.setAlignment(QtCore.Qt.AlignCenter) self.browse2 = QPushButton("Browse", self) self.browse2.setStyleSheet(QPushButtonStyleStr) self.browse2.clicked.connect(self.getImagePath) self.imagePathName = QLabel("Path: ", self) self.saveLabel = QPushButton( 'Provide full path to valid directory to save montages', self) self.saveLabel.setStyleSheet(QPushButtonStyleStr) self.saveLabel.setFixedWidth(310) self.saveLabel.clicked.connect(self.showPathToSave) self.orLabel3 = QLabel("or", self) self.orLabel3.setAlignment(QtCore.Qt.AlignCenter) self.browse3 = QPushButton("Browse", self) self.browse3.setStyleSheet(QPushButtonStyleStr) self.browse3.clicked.connect(self.getOutputPath) self.savePath = QLabel("Path: ", self) self.spacer = QLabel("", self) self.apply = QPushButton("Apply", self) self.apply.setStyleSheet(QPushButtonStyleStr) self.apply.clicked.connect(self.createMontage) self.backToMenu = QPushButton("Back To Menu", self) self.backToMenu.setStyleSheet(QPushButtonStyleStr) self.backToMenu.clicked.connect(self.close) self.message = QLabel(self) self.layout1 = QVBoxLayout(self) layout2 = QHBoxLayout() layout3 = QHBoxLayout() layout4 = QHBoxLayout() layout5 = QHBoxLayout() layout2.addWidget(self.CSVLabel) layout2.addWidget(self.orLabel1) layout2.addWidget(self.browse1) self.layout1.addLayout(layout2) self.layout1.addWidget(self.CSVPathName) layout3.addWidget(self.imageLabel) layout3.addWidget(self.orLabel2) layout3.addWidget(self.browse2) self.layout1.addLayout(layout3) self.layout1.addWidget(self.imagePathName) layout4.addWidget(self.saveLabel) layout4.addWidget(self.orLabel3) layout4.addWidget(self.browse3) self.layout1.addLayout(layout4) self.layout1.addWidget(self.savePath) self.layout1.addWidget(self.spacer) layout5.addWidget(self.apply) layout5.addWidget(self.backToMenu) self.layout1.addLayout(layout5) self.layout1.addWidget(self.message) self.setGeometry(590, 475, 350, 150) self.setWindowTitle('Option 3') self.CSVPath = "" self.imagePath = "" self.outputPath = "" ## @function showPathToCSV # @brief Member function that gets path to CSV files from user-written path def showPathToCSV(self): text, ok = QInputDialog.getText(self, 'Input Path to CSV File', 'Enter path to valid CSV File:') if ok: if os.path.isfile(str(text)): self.CSVPathName.clear self.CSVPathName.setText("Path: " + str(text)) self.CSVPath = str(text) else: self.CSVPathName.clear self.CSVPathName.setText("Given file is not valid: " + str(text)) ## @function showPathToImage # @brief Member function that gets path to images from user-written path def showPathToImage(self): text, ok = QInputDialog.getText(self, 'Input Path to Images', 'Enter path to location of images:') if ok: if os.path.isdir(str(text)): self.imagePathName.clear self.imagePathName.setText("Path: " + str(text)) self.imagePath = str(text) else: self.imagePathName.clear self.imagePathName.setText("Given directory is not valid: " + str(text)) ## @function showPathToSave # @brief Member function that gets path to save montages from user-written path def showPathToSave(self): text, ok = QInputDialog.getText(self, 'Input Path to Save Montage', 'Enter path to directory:') if ok: if os.path.isdir(str(text)): self.savePath.clear self.savePath.setText("Path: " + str(text)) self.outputPath = str(text) else: self.savePath.clear self.savePath.setText("Given directory is not valid: " + str(text)) ## @function getCSVPath # @brief Member function that gets path to CSV files from user-chosen folder using browse def getCSVPath(self): text = QFileDialog.getOpenFileName(self, 'Select File', 'C:\\', "CSV files (*.csv)") self.CSVPathName.clear self.CSVPathName.setText("Path: " + str(text)) self.CSVPath = str(text) ## @function getImagePath # @brief Member function that gets path to images from user-chosen folder using browse def getImagePath(self): text = QFileDialog.getExistingDirectory(self, 'Select Folder', 'C:\\', QFileDialog.ShowDirsOnly) self.imagePathName.clear self.imagePathName.setText("Path: " + str(text)) self.imagePath = str(text) ## @function getOutputPath # @brief Member function that gets path to save montages from user-chosen folder using browse def getOutputPath(self): text = QFileDialog.getExistingDirectory(self, 'Select Folder', 'C:\\', QFileDialog.ShowDirsOnly) self.savePath.clear self.savePath.setText("Path: " + str(text)) self.outputPath = str(text) ## @function createMontage # @brief Member function that given valid directories creates the montage def createMontage(self): if self.CSVPath == "" or self.imagePath == "" or self.outputPath == "": self.error.exec_() else: self.montage.input_data(src_path=self.CSVPath, dest_path=self.outputPath, image_src_path=self.imagePath) self.montage.montages_from_csv_binned(ncols=0, nrows=1) self.message.setText("Montages created and saved.")