summaryrefslogtreecommitdiff
path: root/dockWidget.py
blob: d94c23c0766aa8c1d6f28a5a37102a1f4086e05e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.uic import loadUiType
import pandas as pd
from functools import partial
from component_selector import *
from collections import defaultdict
ui_dialog,_ = loadUiType('dockWidget.ui')


class dockWidget(QDockWidget,ui_dialog):
    
    def __init__(self,name,comptype,obj,parent=None):
        QDockWidget.__init__(self,parent)
        self.setupUi(self)
        self.setWindowTitle(obj.name)
        self.name=name
        self.obj=obj
        self.type = comptype
        self.inputdict = {}
        self.x_pclist = []
        self.modes()
        self.pushButton_2.clicked.connect(self.modeSelection)
        #self.inputparamslist()
        print(self.inputdict)
        self.pushButton.clicked.connect(self.param)
        self.dict = {}

    def modes(self):
        modesList = self.obj.modesList
        if(modesList):
            for j in modesList:
                self.comboBox.addItem(str(j))
            self.modeSelection()
        else:
            self.inputdict= {}
            self.inputdict = self.obj.paramgetter()
            self.inputparamslist()

    def modeSelection(self):
        self.inputdict= {}
        for i in reversed(range(self.formLayout.count())):
            self.formLayout.itemAt(i).widget().setParent(None)  
        self.inputdict = self.obj.paramgetter(self.comboBox.currentText())
        self.inputparamslist()

    def inputparamslist(self):
        try:
            print(self.inputdict)
            for c,i in enumerate(self.inputdict):
                if(i=="thermoPackage"):
                    print("thermo1")
                    combo = QComboBox()
                    self.lines = [line.rstrip('\n') for line in open('thermopackage.txt')]
                    print("thermo2")
                    for j in self.lines:
                        combo.addItem(str(j))
                    self.formLayout.addRow(QLabel(i+":"),combo )                    
                    self.inputdict[i] = combo   
                    print("thermo")
                elif(i=="condType"):
                    combo = QComboBox()
                    self.lines = ["Total","Partial"]
                    for j in self.lines:
                        combo.addItem(str(j))
                    self.formLayout.addRow(QLabel("Condensor Type :"+":"),combo)
                    self.inputdict[i] = combo
                elif(i=="x_pc"):
                    noc = len(compound_selected)
                    print(noc)
                    self.x_pclist.clear()
                    for j in range(noc):
                        l = QLineEdit()    
                        self.inputdict[i] = "x_pc"                                                  
                        self.formLayout.addRow(QLabel(str(compound_selected[j])+":"),l )
                        self.x_pclist.append(l)
                else:
                    print("elseloop")
                    l = QLineEdit()                                                      
                    self.formLayout.addRow(QLabel(i+":"),l )
                    self.inputdict[i] = l
            
        except Exception as e:
            print(e)

    def Show_Error(self):
        QMessageBox.about(self, 'Important', "Please fill all fields with data")

    def param(self):
        try:
            self.dict={}
            for i in self.inputdict:
                if(i=="thermoPackage"):
                    if (self.inputdict[i].currentText()):
                        self.dict[i] = self.inputdict[i].currentText()
                    else:
                        self.Show_Error()
                        break
                elif(i=="condType"):
                    if (self.inputdict[i].currentText()):
                        self.dict[i] = self.inputdict[i].currentText()
                    else:
                        self.Show_Error()
                        break
                elif(i =="x_pc"):
                    l=[]
                    mf = []
                    total_moles = 0
                    for mol_frac in self.x_pclist:
                        if (mol_frac.text()):
                            l.append(mol_frac.text())
                            total_moles += float(l[-1])
                        else:
                            self.Show_Error()
                            break
                    for c in range(len(compound_selected)):
                        mf.append(str(float(l[c])/total_moles))
                        self.x_pclist[c].setText(mf[-1])
                        # self.formLayout.addRow(QLabel(str(compound_selected[c])+" Mole Fraction: "+str(float(l[c])/total_moles)))
                    self.dict[i] = ",".join(mf)
                    # self.update()
                else:
                    if (self.inputdict[i].text()):
                        self.dict[i] = self.inputdict[i].text()
                    else:
                        print(self.inputdict[i].text())
                        self.Show_Error()
                        break
            self.obj.paramsetter(self.dict)
            print(self.dict)
            self.hide()
            
        except Exception as e:
            print(e)