<commit_before>import os, sys
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtGui import QStandardItem, QStandardItemModel, QIcon
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QSizePolicy, QVBoxLayout, QFormLayout, QStackedLayout, QWidget, QComboBox, QTabWidget
from FluidPropertyWidget import *
import peacock
from peacock.Input.ExecutableInfo import ExecutableInfo


class FluidPropertyInterrogatorPlugin(QtWidgets.QWidget):
    """
    Fluid property interrogator GUI
    """

    SINGLE_PHASE = 1
    TWO_PHASE = 2
    TWO_PHASE_NCG = 3

    def __init__(self, **kwargs):
        super(FluidPropertyInterrogatorPlugin, self).__init__(**kwargs)

        self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)

        self.layoutMain = QVBoxLayout(self)

        self.ctlFPType = QComboBox(self)
        self.layoutMain.addWidget(self.ctlFPType)

        self.layoutFPParams = QStackedLayout()
        self.ctlSinglePhaseWidget = self.setupSinglePhaseUI(self.layoutFPParams)
        self.ctlTwoPhaseWidget = self.setupTwoPhaseUI(self.layoutFPParams)
        self.layoutFPParams.addWidget(self.ctlSinglePhaseWidget)
        self.layoutFPParams.addWidget(self.ctlTwoPhaseWidget)
        self.layoutMain.addLayout(self.layoutFPParams)

        self.ctlFPType.currentIndexChanged.connect(self.onFluidPropertyChanged)

    def setupSinglePhaseUI(self, layout):
        widget = QTabWidget(self)
        widget.addTab(FluidPropertyWidget1PhasePT(self), "p, T")
        widget.addTab(FluidPropertyWidget1PhaseRhoE(self), "rho, e")
        widget.addTab(FluidPropertyWidget1PhaseRhoP(self), "rho, p")
        return widget

    def setupTwoPhaseUI(self, layout):
        widget = QTabWidget(self)
        widget.addTab(FluidPropertyWidget2PhaseP(self), "p")
        widget.addTab(FluidPropertyWidget2PhaseT(self), "T")
        return widget

    def fillFluidProperties(self):
        """
        Fill the combo box with single phase fluid property classes
        """

        fp_classes = [
            {
                'name': 'Single phase',
                'classes': [],
                'data': self.SINGLE_PHASE
            },
            {
                'name': 'Two phase',
                'classes': [],
                'data': self.TWO_PHASE
            }
        ]

        json_fps = self.exe_info.json_data.json_data["blocks"]["FluidProperties"]['star']['subblock_types']

        for class_name, vals in json_fps.items():
            params = vals['parameters']
            if 'fp_type' in params:
                fp_type = params['fp_type']['default']
                if fp_type == 'single-phase-fp':
                    fp_classes[0]['classes'].append(class_name)
                elif fp_type == 'two-phase-fp':
                    fp_classes[1]['classes'].append(class_name)

        for fpc in fp_classes:
            fpc['classes'].sort()

        sep_indices = []
        model = QStandardItemModel()
        for fpc in fp_classes:
            parent = QStandardItem(fpc['name'])
            parent.setEnabled(False)
            model.appendRow(parent)
            for c in fpc['classes']:
                item = QStandardItem(c)
                item.setData(fpc['data'])
                model.appendRow(item)
            sep_indices.append(model.rowCount())

        self.ctlFPType.setModel(model)
        for idx in sep_indices[:-1]:
            self.ctlFPType.insertSeparator(idx)

    def onFluidPropertyChanged(self, index):
        fp_type = self.ctlFPType.model().item(index).data()
        if fp_type == self.SINGLE_PHASE:
            self.layoutFPParams.setCurrentWidget(self.ctlSinglePhaseWidget)
            self.ctlSinglePhaseWidget.currentWidget().updateWidgets()
        elif fp_type == self.TWO_PHASE:
            self.layoutFPParams.setCurrentWidget(self.ctlTwoPhaseWidget)
            self.ctlTwoPhaseWidget.currentWidget().updateWidgets()
        else:
            raise SystemExit("Unknown fp_type")

    def fluidPropertyInputFileBlock(self):
        str = ""
        str += "[./fp]\n"
        str += "type = {}\n".format(self.ctlFPType.currentText())
        str += "[../]\n"
        return str

    def setExecutablePath(self, exe_path):
        self.exe_path = exe_path
        self.exe_info = ExecutableInfo()
        self.exe_info.setPath(self.exe_path)
        self.fillFluidProperties()

        for tab in range(self.ctlSinglePhaseWidget.count()):
            self.ctlSinglePhaseWidget.widget(tab).setExecutablePath(exe_path)
        for tab in range(self.ctlTwoPhaseWidget.count()):
            self.ctlTwoPhaseWidget.widget(tab).setExecutablePath(exe_path)

def main(size=None):
    """
    Run the FluidPropertyInterrogatorPlugin alone
    """
    from peacock.utils import ExeFinder

    widget = FluidPropertyInterrogatorPlugin()
    exe_path = ExeFinder.getExecutablePath(None, start_dir = os.getcwd())
    if exe_path:
        widget.setExecutablePath(exe_path)
        widget.layoutMain.setContentsMargins(15, 15, 15, 15)
        widget.show()
        widget.setWindowTitle("Fluid Property Interrogator")
        return widget
    else:
        raise SystemExit("No executable found")

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    widget = main(size=[400,100])
    sys.exit(app.exec_())
<commit_msg>FluidProperties -> Modules/FluidProperties in THM python<commit_after>import os, sys
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtGui import QStandardItem, QStandardItemModel, QIcon
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QSizePolicy, QVBoxLayout, QFormLayout, QStackedLayout, QWidget, QComboBox, QTabWidget
from FluidPropertyWidget import *
import peacock
from peacock.Input.ExecutableInfo import ExecutableInfo


class FluidPropertyInterrogatorPlugin(QtWidgets.QWidget):
    """
    Fluid property interrogator GUI
    """

    SINGLE_PHASE = 1
    TWO_PHASE = 2
    TWO_PHASE_NCG = 3

    def __init__(self, **kwargs):
        super(FluidPropertyInterrogatorPlugin, self).__init__(**kwargs)

        self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)

        self.layoutMain = QVBoxLayout(self)

        self.ctlFPType = QComboBox(self)
        self.layoutMain.addWidget(self.ctlFPType)

        self.layoutFPParams = QStackedLayout()
        self.ctlSinglePhaseWidget = self.setupSinglePhaseUI(self.layoutFPParams)
        self.ctlTwoPhaseWidget = self.setupTwoPhaseUI(self.layoutFPParams)
        self.layoutFPParams.addWidget(self.ctlSinglePhaseWidget)
        self.layoutFPParams.addWidget(self.ctlTwoPhaseWidget)
        self.layoutMain.addLayout(self.layoutFPParams)

        self.ctlFPType.currentIndexChanged.connect(self.onFluidPropertyChanged)

    def setupSinglePhaseUI(self, layout):
        widget = QTabWidget(self)
        widget.addTab(FluidPropertyWidget1PhasePT(self), "p, T")
        widget.addTab(FluidPropertyWidget1PhaseRhoE(self), "rho, e")
        widget.addTab(FluidPropertyWidget1PhaseRhoP(self), "rho, p")
        return widget

    def setupTwoPhaseUI(self, layout):
        widget = QTabWidget(self)
        widget.addTab(FluidPropertyWidget2PhaseP(self), "p")
        widget.addTab(FluidPropertyWidget2PhaseT(self), "T")
        return widget

    def fillFluidProperties(self):
        """
        Fill the combo box with single phase fluid property classes
        """

        fp_classes = [
            {
                'name': 'Single phase',
                'classes': [],
                'data': self.SINGLE_PHASE
            },
            {
                'name': 'Two phase',
                'classes': [],
                'data': self.TWO_PHASE
            }
        ]

        json_fps = self.exe_info.json_data.json_data["blocks"]['Modules']['subblocks']['FluidProperties']['star']['subblock_types']

        for class_name, vals in json_fps.items():
            params = vals['parameters']
            if 'fp_type' in params:
                fp_type = params['fp_type']['default']
                if fp_type == 'single-phase-fp':
                    fp_classes[0]['classes'].append(class_name)
                elif fp_type == 'two-phase-fp':
                    fp_classes[1]['classes'].append(class_name)

        for fpc in fp_classes:
            fpc['classes'].sort()

        sep_indices = []
        model = QStandardItemModel()
        for fpc in fp_classes:
            parent = QStandardItem(fpc['name'])
            parent.setEnabled(False)
            model.appendRow(parent)
            for c in fpc['classes']:
                item = QStandardItem(c)
                item.setData(fpc['data'])
                model.appendRow(item)
            sep_indices.append(model.rowCount())

        self.ctlFPType.setModel(model)
        for idx in sep_indices[:-1]:
            self.ctlFPType.insertSeparator(idx)

    def onFluidPropertyChanged(self, index):
        fp_type = self.ctlFPType.model().item(index).data()
        if fp_type == self.SINGLE_PHASE:
            self.layoutFPParams.setCurrentWidget(self.ctlSinglePhaseWidget)
            self.ctlSinglePhaseWidget.currentWidget().updateWidgets()
        elif fp_type == self.TWO_PHASE:
            self.layoutFPParams.setCurrentWidget(self.ctlTwoPhaseWidget)
            self.ctlTwoPhaseWidget.currentWidget().updateWidgets()
        else:
            raise SystemExit("Unknown fp_type")

    def fluidPropertyInputFileBlock(self):
        str = ""
        str += "[./fp]\n"
        str += "type = {}\n".format(self.ctlFPType.currentText())
        str += "[../]\n"
        return str

    def setExecutablePath(self, exe_path):
        self.exe_path = exe_path
        self.exe_info = ExecutableInfo()
        self.exe_info.setPath(self.exe_path)
        self.fillFluidProperties()

        for tab in range(self.ctlSinglePhaseWidget.count()):
            self.ctlSinglePhaseWidget.widget(tab).setExecutablePath(exe_path)
        for tab in range(self.ctlTwoPhaseWidget.count()):
            self.ctlTwoPhaseWidget.widget(tab).setExecutablePath(exe_path)

def main(size=None):
    """
    Run the FluidPropertyInterrogatorPlugin alone
    """
    from peacock.utils import ExeFinder

    widget = FluidPropertyInterrogatorPlugin()
    exe_path = ExeFinder.getExecutablePath(None, start_dir = os.getcwd())
    if exe_path:
        widget.setExecutablePath(exe_path)
        widget.layoutMain.setContentsMargins(15, 15, 15, 15)
        widget.show()
        widget.setWindowTitle("Fluid Property Interrogator")
        return widget
    else:
        raise SystemExit("No executable found")

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    widget = main(size=[400,100])
    sys.exit(app.exec_())

{'fraction_non_alphanumeric': 0.10506127794929367, 'fraction_numerical': 0.005426139021423894, 'mean_word_length': 2.609047940580689, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2274642', 'n_tokens_mistral': 3253, 'n_tokens_neox': 3137, 'n_words': 544}