Exemplo n.º 1
0
	def __init__(self):
		self.montage = Montages()
		self.choices = {
		"1": self.montage_dir,
		"2": self.montage_from_csv,
		"3": self.img_scatter,
		"4": self.image_hist_from_csv,
		"5": self.quit
		}
Exemplo n.º 2
0
	def __init__(self):
		self.montage = Montages()
		self.choices = {
		"1": self.montage_dir,
		"2": self.montage_from_csv,
		"3": self.vertical_montage_from_csv,
		"4": self.image_hist_from_csv,
		"5": self.quit
		}
Exemplo n.º 3
0
 def initUI(self):
     # create a class object
     self.setStyleSheet('QPushButton {font-family: cursive, sans-serif; font-weight: 300; font-size: 14px; color: #CD853F; }') 
     self.montage = Montages()
     # create buttons
     createPath = QPushButton(self)
     createPath.setText("Choose the directory of your photos")
     createPath.clicked.connect(self.cPath)
     savePath = QPushButton(self)
     savePath.setText("Choose the directory to save your plot")
     savePath.clicked.connect(self.sPath)
     create = QPushButton(self)
     create.setText("Create plot")
     create.clicked.connect(self.createPlot)
     # set layout
     sbox = QGridLayout(self)
     sbox.addWidget(createPath, 1, 0)
     sbox.addWidget(savePath, 2, 0)
     sbox.addWidget(create, 3, 1)
     self.setLayout(sbox)
     # set background as transparent
     palette	= QPalette()
     palette.setBrush(QPalette.Background,QBrush(QPixmap()))
     self.setPalette(palette)
Exemplo n.º 4
0
class Menu:
	'''Display menu and respond to choices when run.'''
	def __init__(self):
		self.montage = Montages()
		self.histogram = Histograms()
		self.choices = {
		"1": self.montage_dir,
		"2": self.montage_from_csv,
		"3": self.vertical_montage_from_csv,
		"4": self.image_hist_from_csv,
		"5": self.image_hist_panda,
		"6": self.quit
		}

	def display_menu(self):
		print("""
PyMontage Menu

1. Create montages from recursively from given directory and sub-directories
2. Create montages from provided CSV files (split by categories or bins)
3. Create vertical montage from provided CSV file
4. Create image histogram from provided CSV file
5. Create image histogram using panda
6. Quit 
""")

	def run(self):
		'''Display the menu and responsd to choices'''
		while True:
			self.display_menu()
			choice = input("Enter an option: ")
			action = self.choices.get(str(choice))
			if action:
				action()
			else:
				print("{0} is not a valid choice".format(choice))

	def enter_dir(self, message = "Provide valid directory"):
		while True:
			provided_dir = raw_input(message)
			if os.path.isdir(provided_dir): break
			else: print("Not a valid directory")

		return provided_dir

	def montage_dir(self):
		input_dir = self.enter_dir("Provide full path to directory to create montages: ")
		output_dir = self.enter_dir("Provide full path to valid direcotry to save montages: ")
		self.montage.input_data(src_path = input_dir, dest_path = output_dir)
		print("Creating montages...")
		self.montage.montages_from_directory()
		print("Saving montages complete.")

	def enter_csv(self, message = "provide path to valid csv"):
		while True:
			provided_csv = raw_input(message)
			if os.path.isfile(provided_csv): break
			else: print("Not a valid file")

		return provided_csv

	def montage_from_csv(self):
		input_csv = self.enter_csv("Provide full path to csv file for creating montages: ")
		image_path = self.enter_dir("Provide path to where images are located: ")
		output_dir = self.enter_dir("Provide full path to valid direcotry to save montages: ")
		self.montage.input_data(src_path = input_csv, dest_path = output_dir, image_src_path = image_path)
		print("Creating montages...")
		self.montage.montage_from_csv_binned()

	def vertical_montage_from_csv(self):
		input_csv = self.enter_csv("Provide full path to csv file for creating montages: ")
		image_path = self.enter_dir("Provide path to where images are located: ")
		output_dir = self.enter_dir("Provide full path to valid direcotry to save montages: ")
		self.montage.input_data(src_path = input_csv, dest_path = output_dir, image_src_path = image_path)
		print("Creating montages...")
		self.montage.montage_from_csv_binned(ncols = 0, nrows = 1)		

		#Adding helper functions
	#X var in an input array to be binned, essentially the column in the csv file you want
	def enter_xvar(self, message = "choose your x variable"):
		providedx_var = raw_input(message)
		return providedx_var

	def enter_sortvar(self, message = "choose your sort variable"):
		providedsortvar = raw_input(message)
		return providedsortvar

	def enter_numbins(self, message = "choose the number of bins"):
		providednumbins = raw_input(message)
		return providednumbins
	
	def enter_thumbsize(self, message = "choose the thumbnail size"):
		providedthumbsize = raw_input(message)
		return providedthumbsize

	def image_hist_from_csv(self):
		#changed to lower case csv not CSV
		input_csv = self.enter_csv("Provide full path to csv file for creating image histogram: ")
		output_dir = self.enter_dir("Provide full path to valid directory to  save image histogram: ")
		#accesses the histogram object it previously used instantiated and calls input_data method
		self.histogram.input_data(src_path = input_csv, dest_path = output_dir)
		print("Creating image histogram...")
		#than it calls the create_image_hist method. changed from self.create_image_hist() to self.montage.create_image_hist()
		self.histogram.create_image_hist()

	#method that calls Damon's Code in Panda
	def image_hist_panda(self):
		#gets all the necessary information from the user
		input_csv = self.enter_csv("Provide full path to csv file for creating image histogram: ")
		output_dir = self.enter_dir("Provide full path to valid directory to  save image histogram: ")
		xvar = self.enter_xvar("Provide X Variable to bin for creating image histogram: ")
		sortvar = self.enter_sortvar("Provide the sort variable for sorting image histogram: ")
		numbins = self.enter_numbins("Provide the number of bins for creating image histogram: ")
		thumbsize = self.enter_thumbsize("Provide the thumbnail size for creating image histogram")
		self.histogram.input_data2(infile = input_csv, outfile = output_dir, x_var = xvar, sort_var = sortvar, num_bins = numbins, thumb_size = thumbsize)
		print("Creating image histogram...")
		#calls the correct histogram method
		self.histogram.create_image_hist_panda()


	def quit(self):
		print("Good bye!")
		sys.exit(0)
Exemplo n.º 5
0
class Menu:
	'''Display menu and respond to choices when run.'''
	def __init__(self):
		self.montage = Montages()
		self.choices = {
		"1": self.montage_dir,
		"2": self.montage_from_csv,
		"3": self.img_scatter,
		"4": self.image_hist_from_csv,
		"5": self.quit
		}

	def display_menu(self):
		print("""
PyMontage Menu
1. Create montages from recursively from given directory and sub-directories
2. Create montages from provided CSV files (split by categories or bins)
3. Create image scatter plote from provided CSV file
4. Create image histogram from provided CSV file
5. Quit 
""")

	def run(self):
		'''Display the menu and responsd to choices'''
		while True:
			self.display_menu()
			choice = input("Enter an option: ")
			action = self.choices.get(str(choice))
			if action:
				action()
			else:
				print("{0} is not a valid choice".format(choice))

	def enter_dir(self, message = "Provide valid directory"):
		while True:
			provided_dir = raw_input(message)
			if os.path.isdir(provided_dir): break
			else: print("Not a valid directory")

		return provided_dir

	def montage_dir(self):
		input_dir = self.enter_dir("Provide full path to directory to create montages: ")
		output_dir = self.enter_dir("Provide full path to valid direcotry to save montages: ")
		self.montage.input_data(src_path = input_dir, dest_path = output_dir)
		print("Creating montages...")
		created_montages = self.montage.montages_from_directory()
		for i, created_montage in enumerate(created_montages):
			created_montage.save(output_dir + "/montage-" + str(i) + ".jpg")
		print("Saving montages complete.")

	def enter_csv(self, message = "provide path to valid csv"):
		while True:
			provided_csv = raw_input(message)
			if os.path.isfile(provided_csv): break
			else: print("Not a valid file")

		return provided_csv

	def montage_from_csv(self):
		input_csv = self.enter_csv("Provide full path to csv file for creating montages: ")
		output_dir = self.enter_dir("Provide full path to valid direcotry to save montages: ")
		print("Creating montages...")
		df = pd.read_csv(input_csv)
		created_montages = self.montage.binned_montage(df)
		for created_montage, bin_name in created_montages:
			created_montage.save(output_dir + "/montage-" + str(bin_name) + ".png")
		print("Saving montages complete.")


	def img_scatter(self):
		input_csv = self.enter_csv("Provide full path to csv file for creating image scatter plot: ")
		output_dir = self.enter_dir("Provide full path and name to valid direcotry to save image scatter plot: ")
		print("Creating image scatter plot...")
		df = pd.read_csv(input_csv)
		created_img_scatter = self.montage.scatter(df)
		created_img_scatter.save(output_dir+"img-scatter.png")

	def image_hist_from_csv(self):
		input_CSV = self.enter_csv("Provide full path to csv file for creating image histogram: ")
		output_dir = self.enter_dir("Provide full path and fielname to  save image histogram: ")
		self.montage.input_data(src_path = input_CSV, dest_path = output_dir)
		print("Creating image histogram...")
		created_img_hist = self.montage.create_image_hist()
        	created_img_hist.save(output_dir+"hist.png")


	def quit(self):
		print("Good bye!")
		sys.exit(0)
Exemplo n.º 6
0
class Menu:
	'''Display menu and respond to choices when run.'''
	def __init__(self):
		self.montage = Montages()
		self.choices = {
		"1": self.montage_dir,
		"2": self.montage_from_csv,
		"3": self.vertical_montage_from_csv,
		"4": self.image_hist_from_csv,
		"5": self.quit
		}

	def display_menu(self):
		print("""
PyMontage Menu

1. Create montages from recursively from given directory and sub-directories
2. Create montages from provided CSV files (split by categories or bins)
3. Create vetical montge from provided CSV file
4. Create image histogram from provided CSV file
5. Quit 
""")

	def run(self):
		'''Display the menu and responsd to choices'''
		while True:
			self.display_menu()
			choice = input("Enter an option: ")
			action = self.choices.get(str(choice))
			if action:
				action()
			else:
				print("{0} is not a valid choice".format(choice))

	def enter_dir(self, message = "Provide valid directory"):
		while True:
			provided_dir = raw_input(message)
			if os.path.isdir(provided_dir): break
			else: print("Not a valid directory")

		return provided_dir

	def montage_dir(self):
		input_dir = self.enter_dir("Provide full path to directory to create montages: ")
		output_dir = self.enter_dir("Provide full path to valid direcotry to save montages: ")
		self.montage.input_data(src_path = input_dir, dest_path = output_dir)
		print("Creating montages...")
		self.montage.montages_from_directory()
		print("Saving montages complete.")

	def enter_csv(self, message = "provide path to valid csv"):
		while True:
			provided_csv = raw_input(message)
			if os.path.isfile(provided_csv): break
			else: print("Not a valid file")

		return provided_csv

	def montage_from_csv(self):
		input_csv = self.enter_csv("Provide full path to csv file for creating montages: ")
		image_path = self.enter_dir("Provide path to where images are located: ")
		output_dir = self.enter_dir("Provide full path to valid direcotry to save montages: ")
		self.montage.input_data(src_path = input_csv, dest_path = output_dir, image_src_path = image_path)
		print("Creating montages...")
		self.montage.montage_from_csv_binned()

	def vertical_montage_from_csv(self):
		input_csv = self.enter_csv("Provide full path to csv file for creating montages: ")
		image_path = self.enter_dir("Provide path to where images are located: ")
		output_dir = self.enter_dir("Provide full path to valid direcotry to save montages: ")
		self.montage.input_data(src_path = input_csv, dest_path = output_dir, image_src_path = image_path)
		print("Creating montages...")
		self.montage.montage_from_csv_binned(ncols = 0, nrows = 1)		

	def image_hist_from_csv(self):
		input_CSV = self.enter_csv("Provide full path to csv file for creating image histogram: ")
		output_dir = self.enter_dir("Provide full path and fielname to  save image histogram: ")
		self.montage.input_data(src_path = input_CSV, dest_path = output_dir)
		print("Creating image histogram...")
		self.montage.create_image_hist()


	def quit(self):
		print("Good bye!")
		sys.exit(0)
Exemplo n.º 7
0
class SubWidget(QWidget):
    """@class SubWidget
    @brief Another Window of the Interface
     
    This class is the other window of the interface. Users can choose the folder
    where their photos are stored, and the folder where they want to save their plots.
    After choosing these folders, users can create plots by simply clicking Create Plot.
    Users can return to the main window by clicking the close button on the upper left 
    corner of the window.
    """   
    # self-defined signal
    closed = pyqtSignal()
    
    def __init__(self, choice, parent = None):
        """The constructor."""
        super(SubWidget, self).__init__(parent)
        # assign the local variable option with the value of choice
        self.option = choice
        self.initUI()
        
    def initUI(self):
        # create a class object
        self.setStyleSheet('QPushButton {font-family: cursive, sans-serif; font-weight: 300; font-size: 14px; color: #CD853F; }') 
        self.montage = Montages()
        # create buttons
        createPath = QPushButton(self)
        createPath.setText("Choose the directory of your photos")
        createPath.clicked.connect(self.cPath)
        savePath = QPushButton(self)
        savePath.setText("Choose the directory to save your plot")
        savePath.clicked.connect(self.sPath)
        create = QPushButton(self)
        create.setText("Create plot")
        create.clicked.connect(self.createPlot)
        # set layout
        sbox = QGridLayout(self)
        sbox.addWidget(createPath, 1, 0)
        sbox.addWidget(savePath, 2, 0)
        sbox.addWidget(create, 3, 1)
        self.setLayout(sbox)
        # set background as transparent
        palette	= QPalette()
        palette.setBrush(QPalette.Background,QBrush(QPixmap()))
        self.setPalette(palette)
        
    def closeEvent(self, event):
        """Define signal closed"""
        self.closed.emit()
        event.accept()
        
    def cPath(self):
        """Save the path of the directory where pictures are stored"""
        self.srcPath = str(QFileDialog.getExistingDirectory(self, "Select Directory"))
        
    def sPath(self):
        """Save the path of the directory where the montage should be stored"""
        self.destPath = str(QFileDialog.getExistingDirectory(self, "Select Directory"))
        
    def createPlot(self):
        """Check user's choice and create the plot"""
        if self.option == 1:
           self.montage.input_data(src_path = self.srcPath, dest_path = self.destPath)
           self.montage.montages_from_directory()
Exemplo n.º 8
0
class Menu:
    '''Display menu and respond to choices when run.'''
    def __init__(self):
        self.montage = Montages()
        self.choices = {
            "1": self.montage_dir,
            "2": self.montage_from_csv,
            "3": self.vertical_montage_from_csv,
            "4": self.image_hist_from_csv,
            "5": self.quit
        }

    def display_menu(self):
        print("""
PyMontage Menu

1. Create montages from recursively from given directory and sub-directories
2. Create montages from provided CSV files (split by categories or bins)
3. Create vetical montge from provided CSV file
4. Create image histogram from provided CSV file
5. Quit 
""")

    def run(self):
        '''Display the menu and responsd to choices'''
        while True:
            self.display_menu()
            choice = input("Enter an option: ")
            action = self.choices.get(str(choice))
            if action:
                action()
            else:
                print("{0} is not a valid choice".format(choice))

    def enter_dir(self, message="Provide valid directory"):
        while True:
            provided_dir = raw_input(message)
            if os.path.isdir(provided_dir): break
            else: print("Not a valid directory")

        return provided_dir

    def montage_dir(self):
        input_dir = self.enter_dir(
            "Provide full path to directory to create montages: ")
        output_dir = self.enter_dir(
            "Provide full path to valid direcotry to save montages: ")
        self.montage.input_data(src_path=input_dir, dest_path=output_dir)
        print("Creating montages...")
        self.montage.montages_from_directory()
        print("Saving montages complete.")

    def enter_csv(self, message="provide path to valid csv"):
        while True:
            provided_csv = raw_input(message)
            if os.path.isfile(provided_csv): break
            else: print("Not a valid file")

        return provided_csv

    def montage_from_csv(self):
        input_csv = self.enter_csv(
            "Provide full path to csv file for creating montages: ")
        image_path = self.enter_dir(
            "Provide path to where images are located: ")
        output_dir = self.enter_dir(
            "Provide full path to valid direcotry to save montages: ")
        self.montage.input_data(src_path=input_csv,
                                dest_path=output_dir,
                                image_src_path=image_path)
        print("Creating montages...")
        self.montage.montage_from_csv_binned()

    def vertical_montage_from_csv(self):
        input_csv = self.enter_csv(
            "Provide full path to csv file for creating montages: ")
        image_path = self.enter_dir(
            "Provide path to where images are located: ")
        output_dir = self.enter_dir(
            "Provide full path to valid direcotry to save montages: ")
        self.montage.input_data(src_path=input_csv,
                                dest_path=output_dir,
                                image_src_path=image_path)
        print("Creating montages...")
        self.montage.montage_from_csv_binned(ncols=0, nrows=1)

    def image_hist_from_csv(self):
        input_CSV = self.enter_csv(
            "Provide full path to csv file for creating image histogram: ")
        output_dir = self.enter_dir(
            "Provide full path and fielname to  save image histogram: ")
        self.montage.input_data(src_path=input_CSV, dest_path=output_dir)
        print("Creating image histogram...")
        self.montage.create_image_hist()

    def quit(self):
        print("Good bye!")
        sys.exit(0)
Exemplo n.º 9
0
    def __init__(self, parent=None):  #Constructor
        super(ImageHistFromCSV, self).__init__(parent)
        self.montage = Montages()
        self.error = Error(self)
        self.createLabel = QPushButton(
            'Provide full path to csv file for creating image histogram', 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.createLabel.setStyleSheet(QPushButtonStyleStr)
        self.createLabel.setFixedWidth(350)
        self.createLabel.clicked.connect(self.showPathToCreate)
        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.createPath = QLabel("Path: ", self)
        self.saveLabel = QPushButton(
            'Provide full path and filename to save image histogram', self)
        self.saveLabel.setStyleSheet(QPushButtonStyleStr)
        self.saveLabel.setFixedWidth(350)
        self.saveLabel.clicked.connect(self.showPathToSave)
        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.getOutputPath)
        self.savePath = QLabel("Path: ", self)
        self.spacer = QLabel("", self)
        self.apply = QPushButton("Apply", self)
        self.apply.setStyleSheet(QPushButtonStyleStr)
        self.apply.setFixedWidth(200)
        self.apply.clicked.connect(self.createHist)
        self.backToMenu = QPushButton("Back To Menu", self)
        self.backToMenu.setStyleSheet(QPushButtonStyleStr)
        self.backToMenu.setFixedWidth(200)
        self.backToMenu.clicked.connect(self.close)
        self.message = QLabel(self)
        self.layout1 = QVBoxLayout(self)
        layout2 = QHBoxLayout()
        layout3 = QHBoxLayout()
        layout4 = QHBoxLayout()

        layout2.addWidget(self.createLabel)
        layout2.addWidget(self.orLabel1)
        layout2.addWidget(self.browse1)
        self.layout1.addLayout(layout2)
        self.layout1.addWidget(self.createPath)
        layout3.addWidget(self.saveLabel)
        layout3.addWidget(self.orLabel2)
        layout3.addWidget(self.browse2)
        self.layout1.addLayout(layout3)
        self.layout1.addWidget(self.savePath)
        self.layout1.addWidget(self.spacer)
        layout4.addWidget(self.apply)
        layout4.addWidget(self.backToMenu)
        self.layout1.addLayout(layout4)
        self.layout1.addWidget(self.message)

        self.setGeometry(590, 475, 350, 150)
        self.setWindowTitle('Option 4')

        self.inputPath = ""
        self.outputPath = ""
Exemplo n.º 10
0
class ImageHistFromCSV(QDialog):
    def __init__(self, parent=None):  #Constructor
        super(ImageHistFromCSV, self).__init__(parent)
        self.montage = Montages()
        self.error = Error(self)
        self.createLabel = QPushButton(
            'Provide full path to csv file for creating image histogram', 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.createLabel.setStyleSheet(QPushButtonStyleStr)
        self.createLabel.setFixedWidth(350)
        self.createLabel.clicked.connect(self.showPathToCreate)
        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.createPath = QLabel("Path: ", self)
        self.saveLabel = QPushButton(
            'Provide full path and filename to save image histogram', self)
        self.saveLabel.setStyleSheet(QPushButtonStyleStr)
        self.saveLabel.setFixedWidth(350)
        self.saveLabel.clicked.connect(self.showPathToSave)
        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.getOutputPath)
        self.savePath = QLabel("Path: ", self)
        self.spacer = QLabel("", self)
        self.apply = QPushButton("Apply", self)
        self.apply.setStyleSheet(QPushButtonStyleStr)
        self.apply.setFixedWidth(200)
        self.apply.clicked.connect(self.createHist)
        self.backToMenu = QPushButton("Back To Menu", self)
        self.backToMenu.setStyleSheet(QPushButtonStyleStr)
        self.backToMenu.setFixedWidth(200)
        self.backToMenu.clicked.connect(self.close)
        self.message = QLabel(self)
        self.layout1 = QVBoxLayout(self)
        layout2 = QHBoxLayout()
        layout3 = QHBoxLayout()
        layout4 = QHBoxLayout()

        layout2.addWidget(self.createLabel)
        layout2.addWidget(self.orLabel1)
        layout2.addWidget(self.browse1)
        self.layout1.addLayout(layout2)
        self.layout1.addWidget(self.createPath)
        layout3.addWidget(self.saveLabel)
        layout3.addWidget(self.orLabel2)
        layout3.addWidget(self.browse2)
        self.layout1.addLayout(layout3)
        self.layout1.addWidget(self.savePath)
        self.layout1.addWidget(self.spacer)
        layout4.addWidget(self.apply)
        layout4.addWidget(self.backToMenu)
        self.layout1.addLayout(layout4)
        self.layout1.addWidget(self.message)

        self.setGeometry(590, 475, 350, 150)
        self.setWindowTitle('Option 4')

        self.inputPath = ""
        self.outputPath = ""

    ## @function showPathToCreate
    #  @brief Member function that gets input path to create montage from user-written path
    def showPathToCreate(self):
        text, ok = QInputDialog.getText(
            self, 'Input Path to Create Image Histogram',
            'Enter path to directory:')
        if ok:
            if os.path.isdir(str(text)):
                self.createPath.clear
                self.createPath.setText("Path: " + str(text))
                self.inputPath = str(text)
            else:
                self.createPath.clear
                self.createPath.setText("Given directory is not valid: " +
                                        str(text))

    ## @function showPathToSave
    #  @brief Member function that gets path to save montage from user-written path
    def showPathToSave(self):
        text, ok = QInputDialog.getText(self,
                                        'Input Path to Save Image Histogram',
                                        '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.getExistingDirectory(self, 'Select Folder', 'C:\\',
                                                QFileDialog.ShowDirsOnly)
        self.createPath.clear
        self.createPath.setText("Path: " + str(text))
        self.inputPath = 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)

    def createHist(self):
        if self.inputPath == "" or self.outputPath == "":
            self.error.exec_()
        else:
            self.montage.input_data(src_path=self.inputPath,
                                    dest_path=self.outputPath)
            self.montage.create_image_hist()
            self.message.setText("Image histogram created and saved.")
Exemplo n.º 11
0
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.")