示例#1
0
 def __init__(self):
     QtGui.QMainWindow.__init__(self)
     
     # This is always the same
     self.ui=Ui_Concentration()
     self.ui.setupUi(self)
示例#2
0
class Main(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        
        # This is always the same
        self.ui=Ui_Concentration()
        self.ui.setupUi(self)
    
    def changed_number(self):
        try:
            c1_unit = self.ui.c1_unit.text()
            c1_val = self.convertFrom(c1_unit, self.ui.c1_value.text())
            c2_unit = self.ui.c2_unit.text()
            c2_val = self.convertFrom(c2_unit, self.ui.c2_value.text())
            V1_unit = self.ui.V1_unit.text()
            V1_val = self.convertFrom(V1_unit, self.ui.V1_value.text())
            V2_unit = self.ui.V2_unit.text()
            V2_val = self.convertFrom(V2_unit, self.ui.V2_value.text())
        except Exception as e:
            print e
            return
        ret = None
        try:
            if self.ui.butt_c1.isChecked():
                ret = self.convertTo(c1_unit, V2_val*c2_val/V1_val)
                valued = self.ui.c1_value
            elif self.ui.butt_c2.isChecked():
                ret = self.convertTo(c2_unit, V1_val*c1_val/V2_val)
                valued = self.ui.c2_value
            elif self.ui.butt_v1.isChecked():
                ret = self.convertTo(V1_unit, V2_val*c2_val/c1_val)
                valued = self.ui.V1_value
            elif self.ui.butt_v2.isChecked():
                ret = self.convertTo(V2_unit, V1_val*c1_val/c2_val)
                valued = self.ui.V2_value
        except ZeroDivisionError:
            return
        if ret == None:
            ret =""
        ret = str(ret)
        valued.setText(QtCore.QString(str(ret)))
    
    def Dissolve(self):
        print("running Dissolve")
        try:
            AmountUnit = self.ui.Dis_AmountUnit.text()
            AmountValue = self.convertFrom(AmountUnit, self.ui.Dis_AmountValue.text())
            print "Amount, %s, %s" % (str(AmountValue), self.ui.Dis_AmountValue.text())
            ConcUnit = self.ui.Dis_ConcUnit.text()
            ConcValue = self.convertFrom(ConcUnit, self.ui.Dis_ConcValue.text())
            print "Conc, %s, %s" % (str(ConcValue), str(self.ui.Dis_ConcValue.text()))
            VolumeUnit = self.ui.Dis_VolumeUnit.text()
            VolumeValue = self.convertFrom(VolumeUnit, self.ui.Dis_VolumeValue.text())
            print "Volume, %s, %s" % (str(VolumeValue), str(self.ui.Dis_VolumeValue.text()))
        except Exception as e:
            print e
            return
        ret = None
        try:
            if self.ui.Dis_Amount_Select.isChecked():
                print
                print "Conc", ConcValue
                print "Volume", VolumeValue
                print "Amount nonconv", ConcValue*VolumeValue
                print "Amount conv", self.convertTo(AmountUnit, ConcValue*VolumeValue)
                ret = self.convertTo(AmountUnit, ConcValue*VolumeValue)
                valued = self.ui.Dis_AmountValue
            elif self.ui.Dis_Conc_Select.isChecked():
                ret = self.convertTo(ConcUnit, AmountValue/VolumeValue)
                valued = self.ui.Dis_ConcValue
            elif self.ui.Dis_Volume_Select.isChecked():
                ret = self.convertTo(VolumeUnit, AmountValue/ConcValue)
                valued = self.ui.Dis_VolumeValue
        except ZeroDivisionError:
            return
        if ret == None:
            ret =""
        ret = str(ret)
        valued.setText(QtCore.QString(str(ret)))


    def convertTo(self, unit, in_value):
        """Convert the value from SI-units, into its prefixed value"""
        value = in_value
        if unit == "M" or unit.toUpper() == "L":
            return value
        elif unit == "mM":
            return value*1000
        elif unit == "uM" or unit == "µM":
            return value*(1000**2)
        elif unit == "nM":
            return value*(1000**3)
        elif unit == "pM":
            return value*(1000**4)
        elif unit == "mol":
            return value
        elif unit == "mmol":
            return value*1000
        elif unit == "µmol" or unit == "umol":
            return value*(1000**2)
        elif unit == "nmol" or unit == "nmol":
            return value*(1000**3)
        elif unit == "pmol" or unit == "pmol":
            return value*(1000**4)
        elif unit.toUpper() == "ML":
            return value*1000
        elif unit == "µL" or unit.toUpper() == "UL":
            return value*(1000**2)
        elif unit == "mg":
            return value*1000
        elif unit == "µg" or unit == "ug":
            return value*(1000**2)
        else:
            return None

    def convertFrom(self, unit, in_value):
        value = in_value.toFloat()[0]
        print value
        print unit
        if unit == "M" or unit.toUpper() == "L":
            return value
        elif unit == "mM":
            return value/1000
        elif unit == "uM" or unit == "µM":
            return value/(1000**2)
        elif unit == "nM":
            return value/(1000**3)
        elif unit == "pM":
            return value/(1000**4)
        elif unit =="mol":
            return value
        elif unit == "mmol":
            return value/1000
        elif unit == "µmol" or unit == "umol":
            return value/(1000**2)
        elif unit == "nmol" or unit == "nmol":
            return value/(1000**3)
        elif unit == "pmol" or unit == "pmol":
            return value/(1000**4)
        elif unit.toUpper() == "ML":
            return value/1000
        elif unit == "µL" or unit.toUpper() == "UL":
            return value/(1000**2)
        else:
            return None