def on_button_equ_clicked(self): # calculate begin... cal_str = self.line_edit.text() # get string from edit line cal_str = CalTools.str_filter(cal_str) # filter string prefix_stack = CalTools.get_calculator_stack(cal_str) # create a prefix stack # print some logs print "cal str:", cal_str print "prefix stack:" CalTools.print_calculator_stack(prefix_stack) # make prefix to suffix suffix_stack = CalTools.prefix_to_suffix(prefix_stack) if None == suffix_stack: self.line_edit.setText(self.error_str) print self.error_str return print "suffix stack:" CalTools.print_calculator_stack(suffix_stack) # calculate suffix result_str = CalTools.calculate_from_stack(suffix_stack) print "---calculator result---" print result_str if result_str == self.error_str: self.line_edit.setText(self.error_str) return else: self.line_edit.setText(result_str)
def test_stack(): my_stack = ExpStack.ExpStack() print my_stack.is_empty() my_stack.push("1") my_stack.push(2) my_stack.push(3.14) print my_stack.is_empty() print my_stack.get_data() print my_stack.size() CalTools.print_calculator_stack(my_stack)
def main(): if __name__ == "__main__": cal_str = CalTools.get_calculator_str() cal_str = CalTools.str_filter(cal_str) # filter string # main loop while "-1" != cal_str: prefix_stack = CalTools.get_calculator_stack(cal_str) print "cal str:", cal_str print "prefix stack:" CalTools.print_calculator_stack(prefix_stack) # make prefix to suffix suffix_stack = CalTools.prefix_to_suffix(prefix_stack) print "suffix stack:" CalTools.print_calculator_stack(suffix_stack) # calculate suffix print "---calculator result---" print CalTools.calculate_from_stack(suffix_stack) cal_str = CalTools.get_calculator_str() cal_str = CalTools.str_filter(cal_str) # filter string print "bye~" else: print __name__