def OnGenerate(self,e): try: editlength_f=int(self.editlength.GetValue()) except ValueError: self.parent.parent.errorPopup("length should be an integer number\n greater than 0!","ERROR!") return -1 if editlength_f<=0: self.parent.parent.errorPopup("length should be an integer number\n greater than 0!","ERROR!") return -1 perc=[] test=0.0 for index in xrange(0,self.lc.GetItemCount(),1): percentage=float(self.lc.GetItem(index,1).GetText()) test+=percentage perc.append([self.lc.GetItem(index,0).GetText(),percentage]) if test!=100.0: self.parent.parent.errorPopup("Sum of percentages equal to %s (100 is expected)!\nTreating given values as ratios..."%test,"WARNING!") for i in xrange(0,len(perc),1): perc[i][1]/=float(test) perc[i][1]*=100.0 #self.parent.parent.errorPopup("Sum of percentages is equal to %s! 100 is expected!"%test,"ERROR!") #return -1 try: chain=A.make_chain(editlength_f, perc) except: print "ERROR: something unexpected happened during chain generation, how weird..." return -1 self.editchain.SetValue(chain)
def OnGenerate(self, e): try: editlength_f = int(self.editlength.GetValue()) except ValueError: self.parent.parent.errorPopup( "length should be an integer number\n greater than 0!", "ERROR!") return -1 if editlength_f <= 0: self.parent.parent.errorPopup( "length should be an integer number\n greater than 0!", "ERROR!") return -1 perc = [] test = 0.0 for index in range(0, self.lc.GetItemCount(), 1): percentage = float(self.lc.GetItem(index, 1).GetText()) test += percentage perc.append([self.lc.GetItem(index, 0).GetText(), percentage]) if test != 100.0: self.parent.parent.errorPopup( "Sum of percentages equal to %s (100 is expected)!\nTreating given values as ratios..." % test, "WARNING!") for i in range(0, len(perc), 1): perc[i][1] /= float(test) perc[i][1] *= 100.0 #self.parent.parent.errorPopup("Sum of percentages is equal to %s! 100 is expected!"%test,"ERROR!") #return -1 try: chain = A.make_chain(editlength_f, perc) except: print( "ERROR: something unexpected happened during chain generation, how weird..." ) return -1 self.editchain.SetValue(chain)