def buttonClicked(self): if self.display.text() == 'Error!': self.display.setText('') button = self.sender() key = button.text() if key == '=': try: result = str(eval(self.display.text())) except: result = 'Error!' self.display.setText(result) elif key == 'C': self.display.clear() elif key in constantList: arr = ['3.141592', '3E+8', '340', '1.5E+8'] self.display.setText(self.display.text() + str(arr[constantList.index(key)])) elif key in functionList: n = self.display.text() arr = ['factorial', 'decToBin', 'binToDec', 'decToRoman'] for i in range(0, 4): if key == functionList[i]: value = getattr(calcFunctions, arr[i])(n) self.display.setText(str(value)) else: self.display.setText(self.display.text() + key)
def buttonClicked(self): if self.display.text() == 'Error!': self.display.setText('') button = self.sender() key = button.text() if key == '=': try: result = str(eval(self.display.text())) except: result = 'Error!' self.display.setText(result) elif key == 'C': self.display.clear() elif key in constantList: i = constantList.index(key) # 만약 (3pi)를 누르면 (3*pi)값이 나오도록 변경 value = self.display.text() + '*' + constantDic[i][1] result = str(eval(value)) self.display.setText(result) elif key in functionList: i = functionList.index(key) n = self.display.text() value = functionMap[i][1](n) self.display.setText(str(value)) else: self.display.setText(self.display.text() + key)
def buttonClicked(self): if self.display.text() == 'Error!': self.display.setText('') button = self.sender() key = button.text() if key == '=': try: result = str(eval(self.display.text())) except: result = 'Error!' self.display.setText(result) elif key == 'C': self.display.clear() elif key in functionList: i = functionList.index(key) temp = keypad2.function[i][1](self.display.text()) self.display.setText(temp) elif key in constantList: i = constantList.index(key) temp = self.display.text() + keypad2.constant[i][1] self.display.setText(temp) else: self.display.setText(self.display.text() + key)
def buttonClicked(self): if self.display.text() == 'Error!': self.display.setText('') button = self.sender() key = button.text() if key == '=': try: result = str(eval(self.display.text())) except: result = 'Error!' self.display.setText(result) elif key == 'C': self.display.clear() elif key in constantList: n = self.display.text() value = constants.constantMap[constantList.index(key)][1](n) self.display.setText(str(value)) elif key in functionList: n = self.display.text() value = functions.functionMap[functionList.index(key)][1](n) self.display.setText(str(value)) else: self.display.setText(self.display.text() + key)
def buttonClicked(self): if self.display.text() == 'Error!': self.display.setText('') button = self.sender() key = button.text() if key == numPadList[11]: try: result = str(eval(self.display.text())) except: result = 'Error!' self.display.setText(result) elif key == operatorList[6]: self.display.clear() elif [True for x in constantList if key == x]: # eval 함수를 숫자로 계산 할 수 없는 경우 에러처리 try : btTcon = constantList.index(key) text_list = ['3.141592', '3E+8', '340', '1.5E+8'] self.display.setText(self.display.text() + text_list[btTcon]) except : self.display.setText("eval Error") elif [True for x in functionList if key == x]: # eval을 숫자로 계산할 수 없는 경우 에러처리 try : result_text = self.display.text() btTfun = functionList.index(key) func_list = [romkey.factorial, romkey.decToBin, romkey.binToDec, romkey.decToRoman, romkey.romanToDec] func = func_list[btTfun] value = func(result_text) self.display.setText(str(value)) except : self.display.setText("eval Error") else: self.display.setText(self.display.text() + key)
def buttonClicked(self): if self.display.text() == 'Error!': self.display.setText('') button = self.sender() key = button.text() if key == '=': try: result = str(eval(self.display.text())) except: result = 'Error!' self.display.setText(result) elif key == 'C': self.display.clear() elif key in constantList: keyIndex = constantList.index(key) self.display.setText(self.display.text() + constantResult[keyIndex]) elif key in functionList: n = eval(self.display.text()) functionResult = [ calcFunctions.factorial(n), calcFunctions.decToBin(n), calcFunctions.binToDec(n), calcFunctions.decToRoman(n) ] keyIndex = functionList.index(key) value = functionResult[keyIndex] self.display.setText(str(value)) else: self.display.setText(self.display.text() + key)
def buttonClicked(self): self.flagCheck() button = self.sender() key = button.text() if key == "=": try: result = str(eval(self.display.text())) except: result = "Error!" self.display.setText(result) self.flag = "error" else: self.display.setText(result) elif key == "C": self.display.clear() self.flag = "" elif key in constantList: if self.flag != "number" and self.flag != "constant": idx = constantList.index(key) self.display.setText(self.display.text() + constantValueList[idx]) self.flag = "constant" elif key == functionList[0]: if self.display.text() != "": n = eval(self.display.text()) if isinstance(n, int): if 0 <= int(n) <= 17: value = factorial(int(n)) self.flag = "number" else: value = 'Error!' self.flag = "error" else: value = 'Error!' self.flag = "error" else: value = 'Error!' self.flag = "error" self.display.setText(str(value)) elif key == functionList[1]: if self.display.text() != "": n = str(eval(self.display.text())) value = calcFunctions.decToBin(n) if len(value) > 15: value = "Too long" self.flag = "error" else: self.flag = "bin" else: value = 'Error!' self.flag = "error" self.display.setText(str(value)) elif key == functionList[2]: if self.display.text() != "": n = str(eval(self.display.text())) value = calcFunctions.binToDec(n) if value == "Error!": self.flag = "error" else: self.flag = "number" else: value = 'Error!' self.flag = "error" self.display.setText(str(value)) elif key == functionList[3]: n = self.display.text() value = calcFunctions.decToRoman(n) self.display.setText(str(value)) elif key in operatorList: if self.flag == "bin": pass elif key == "(" or key == ")": self.display.setText(self.display.text() + key) elif self.flag != "operator": self.display.setText(self.display.text() + key) self.flag = "operator" else: self.flagCheck() if self.flag != "constant" and self.flag != "bin": if self.display.text() == "0": if key == "0": pass elif key == ".": self.display.setText(self.display.text() + key) else: self.display.setText(key) elif key == ".": if "." in self.display.text(): pass elif self.display.text() == "": pass else: self.display.setText(self.display.text() + key) else: self.display.setText(self.display.text() + key) self.flag = "number" print(self.flag)
def buttonClicked(self): # if self.display.text() == 'Error!': # self.display.setText('') button = self.sender() key = button.text() text = self.display.text() if len(text) >= 1: last = text[len(text) - 1] #func = [factorial, decToBin, binToDec, decToRoman] if text[0:6] == 'Error!': self.display.setText(text[6:]) print(self.display.text()) elif key == '=': try: result = str(eval(self.display.text())) except: result = 'Error!' self.display.setText(result) elif key == 'C': self.display.clear() elif key == 'U': self.display.setText(text[:len(text) - 1]) elif key in operatorList: # Operator should not be stacked if len(text) == 0 and key == '-': self.display.setText(text + key) elif key == '(': self.display.setText(text + key) elif key == ')': openCount = 0 closeCount = 0 for alp in text: if alp == '(': openCount += 1 elif alp == ')': closeCount += 1 if openCount > closeCount: self.display.setText(text + key) elif len(text) >= 1 and (last == '(' or last == ')'): self.display.setText(text + key) elif len(text) >= 1 and (last not in operatorList): self.display.setText(text + key) #### CONSTANT OPERATOR #### elif key in constantList: if len(text) >= 1 and text[len(text) - 1] in operatorList: index = constantList.index(key) self.display.setText(text + constantValue[index]) #### FUNCTION OPERATOR #### elif key in functionList: #index = functionList.index(key) result = functionMap[functionList.index(key)][1](text) if result == 'Error!': self.display.setText(str(result) + text) else: self.display.setText(str(result)) else: self.display.setText(self.display.text() + key)