<commit_before>#!/usr/local/bin/python
"""
ImageDataResizer

:Authors:
	<NAME>
"""
import sys
from PySide.QtGui import QApplication
from PySide.QtGui import QMainWindow
from PySide.QtGui import QWidget
from PySide.QtGui import QLineEdit
from PySide.QtGui import QPushButton
from PySide.QtGui import QLabel
from PySide.QtGui import QGridLayout
from PySide.QtGui import QDoubleValidator
from PySide.QtGui import QFileDialog
from PySide.QtCore import Qt
from PySide.QtCore import Slot

from ui.MainWindow import MainWindow
from ui.parameters.RenderInfoWidget import RenderInfoWidget
from core.data.DataReader import DataReader
from core.data.DataResizer import DataResizer
from core.data.DataWriter import DataWriter

# Define settings parameters
APPNAME = "Image Data Resampler"
ORGNAME = "Delft"
ORGDOMAIN = "student.tudelft.nl"


class ImageDataResizer(MainWindow):
	def __init__(self, args):
		super(ImageDataResizer, self).__init__(args)

		self.fileName = None
		# Initialize the user interface
		self.initUI()

	def initUI(self):
		self.createElements()
		self.statusBar = self.statusBar()
		self.statusBar.setSizeGripEnabled(False)

		# Set some window/application properties
		self.setUnifiedTitleAndToolBarOnMac(True)
		self.setWindowTitle(APPNAME)
		self.setWindowState(Qt.WindowActive)

	def createElements(self):
		self.mainWindow = QMainWindow()
		self.inputLabel = QLabel("")
		self.datasetInfo = RenderInfoWidget()
		self.inputButton = QPushButton("Load file")
		self.factorLine = QLineEdit()
		self.factorLine.setValidator(QDoubleValidator())
		self.outputButton = QPushButton("Export file")

		self.inputButton.clicked.connect(self.setInputFile)
		self.outputButton.clicked.connect(self.exportToFile)

		layout = QGridLayout()
		layout.setAlignment(Qt.AlignTop)
		layout.addWidget(QLabel("Input file"), 0, 0)
		layout.addWidget(self.inputButton, 0, 1)
		layout.addWidget(self.datasetInfo, 1, 1, 1, 2)
		layout.addWidget(QLabel("Scale factor"), 2, 0)
		layout.addWidget(self.factorLine, 2, 1)
		layout.addWidget(self.outputButton, 3, 1)

		self.centralWidget = QWidget()
		self.centralWidget.setLayout(layout)
		self.setCentralWidget(self.centralWidget)

	@Slot()
	def setInputFile(self):
		dataReader = DataReader()
		extensions = dataReader.GetSupportedExtensionsAsString()
		fileName, other = QFileDialog.getOpenFileName(self, "Open data set", "", "Images ("+extensions+")", options=QFileDialog.Directory)
		if len(fileName) > 0:
			self.fileName = fileName
			self.datasetInfo.setFile(self.fileName)

	@Slot()
	def exportToFile(self):
		if not self.fileName:
			self.statusBar.showMessage("Please set an input file.")
			return

		if len(self.factorLine.text()) == 0:
			self.statusBar.showMessage("Please set a scale factor.")
			return

		if float(self.factorLine.text()) > 1.0:
			self.statusBar.showMessage("Cannot enlarge datasets.")
			return

		if float(self.factorLine.text()) < 0.0:
			self.statusBar.showMessage("You funny")

		self.statusBar.clearMessage()

		dataWriter = DataWriter()
		extensions = dataWriter.GetSupportedExtensionsAsString()
		exportFileName, other = QFileDialog.getSaveFileName(self, "Export resampled data", "", "Images ("+extensions+")")
		if len(exportFileName) > 0:
			self.statusBar.setVisible(True)

			factor = float(self.factorLine.text())

			self.statusBar.showMessage("Reading...")
			dataReader = DataReader()
			imageData = dataReader.GetImageData(self.fileName)

			self.statusBar.showMessage("Resizing...")
			dataResizer = DataResizer()
			resizedData = dataResizer.ResizeData(imageData, factor)

			self.statusBar.showMessage("Writing...")
			dataWriter.WriteToFile(resizedData, exportFileName, DataReader.TypeMHA)

			self.statusBar.showMessage("Done.")


def main():
	app = QApplication(sys.argv)<commit_msg>Better user feedback from data modifier.<commit_after>#!/usr/local/bin/python
"""
ImageDataResizer

:Authors:
	<NAME>
"""
import sys
from PySide.QtGui import QApplication
from PySide.QtGui import QMainWindow
from PySide.QtGui import QWidget
from PySide.QtGui import QLineEdit
from PySide.QtGui import QPushButton
from PySide.QtGui import QLabel
from PySide.QtGui import QGridLayout
from PySide.QtGui import QDoubleValidator
from PySide.QtGui import QFileDialog
from PySide.QtCore import Qt
from PySide.QtCore import Slot

from ui.MainWindow import MainWindow
from ui.parameters.RenderInfoWidget import RenderInfoWidget
from core.data.DataReader import DataReader
from core.data.DataResizer import DataResizer
from core.data.DataWriter import DataWriter

# Define settings parameters
APPNAME = "Image Data Resampler"
ORGNAME = "Delft"
ORGDOMAIN = "student.tudelft.nl"


class ImageDataResizer(MainWindow):
	def __init__(self, args):
		super(ImageDataResizer, self).__init__(args)

		self.fileName = None
		# Initialize the user interface
		self.initUI()

	def initUI(self):
		self.createElements()
		self.statusBar = self.statusBar()
		self.statusBar.setSizeGripEnabled(False)

		# Set some window/application properties
		self.setUnifiedTitleAndToolBarOnMac(True)
		self.setWindowTitle(APPNAME)
		self.setWindowState(Qt.WindowActive)

	def createElements(self):
		self.mainWindow = QMainWindow()
		self.inputLabel = QLabel("")
		self.datasetInfo = RenderInfoWidget()
		self.inputButton = QPushButton("Load file")
		self.factorLine = QLineEdit()
		self.factorLine.setValidator(QDoubleValidator())
		self.outputButton = QPushButton("Export file")

		self.inputButton.clicked.connect(self.setInputFile)
		self.outputButton.clicked.connect(self.exportToFile)

		layout = QGridLayout()
		layout.setAlignment(Qt.AlignTop)
		layout.addWidget(QLabel("Input file"), 0, 0)
		layout.addWidget(self.inputButton, 0, 1)
		layout.addWidget(self.datasetInfo, 1, 1, 1, 2)
		layout.addWidget(QLabel("Scale factor"), 2, 0)
		layout.addWidget(self.factorLine, 2, 1)
		layout.addWidget(self.outputButton, 3, 1)

		self.centralWidget = QWidget()
		self.centralWidget.setLayout(layout)
		self.setCentralWidget(self.centralWidget)

	@Slot()
	def setInputFile(self):
		dataReader = DataReader()
		extensions = dataReader.GetSupportedExtensionsAsString()
		fileName, other = QFileDialog.getOpenFileName(self, "Open data set", "", "Images ("+extensions+")", options=QFileDialog.Directory)
		if len(fileName) > 0:
			self.fileName = fileName
			self.datasetInfo.setFile(self.fileName)

	@Slot()
	def exportToFile(self):
		if not self.fileName:
			self.statusBar.showMessage("Please set an input file.")
			return

		if len(self.factorLine.text()) == 0:
			self.statusBar.showMessage("Please set a scale factor.")
			return

		if float(self.factorLine.text()) > 1.0:
			self.statusBar.showMessage("Cannot enlarge datasets.")
			return

		if float(self.factorLine.text()) < 0.0:
			self.statusBar.showMessage("You trying to be funny?")

		self.statusBar.clearMessage()

		dataWriter = DataWriter()
		extensions = dataWriter.GetSupportedExtensionsAsString()
		exportFileName, other = QFileDialog.getSaveFileName(self, "Export resampled data", "", "Images ("+extensions+")")
		if len(exportFileName) > 0:
			self.statusBar.setVisible(True)

			factor = float(self.factorLine.text())

			self.statusBar.showMessage("Reading...")
			dataReader = DataReader()
			imageData = dataReader.GetImageData(self.fileName)

			self.statusBar.showMessage("Resizing...")
			dataResizer = DataResizer()
			resizedData = dataResizer.ResizeData(imageData, factor)

			self.statusBar.showMessage("Writing...")
			dataWriter.WriteToFile(resizedData, exportFileName, DataReader.TypeMHA)

			self.statusBar.showMessage("Done.")


def main():
	app = QApplication(sys.argv)
{'fraction_non_alphanumeric': 0.11323238973008558, 'fraction_numerical': 0.005529953917050691, 'mean_word_length': 5.267326732673268, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7080260', 'n_tokens_mistral': 2632, 'n_tokens_neox': 2382, 'n_words': 507}