Exemple #1
0
    def __init__(self, *args, **kwargs):
        super(Calculator, self).__init__(*args, **kwargs)

        # Single-inheritence approach: http://goo.gl/WNiHc
        # Calculator class only inherits from QWidget
        # A specific member attribute self.ui contains all
        # widgets set up in the designer.
        self.ui = Ui_Calculator()
        self.ui.setupUi(self)

        # Create a validator for each QLineEdit that only
        # allows a user to enter floats: 123.123
        self.ui.inputA.setValidator(QtGui.QDoubleValidator())
        self.ui.inputB.setValidator(QtGui.QDoubleValidator())

        # instead of using the stock operator values set in the
        # ui file, lets set the box to match our class attribute
        self.ui.operatorBox.clear()
        self.ui.operatorBox.addItems(self.OPS.keys())

        self.ui.clearButton.clicked.connect(self.clear)

        # every time the text is edited in either input field,
        # calculate the result live
        self.ui.inputA.textEdited.connect(self.calc)
        self.ui.inputB.textEdited.connect(self.calc)

        # also when the operator box is changed
        self.ui.operatorBox.currentIndexChanged.connect(self.calc)
Exemple #2
0
	def __init__(self, *args, **kwargs):
		super(Calculator, self).__init__(*args, **kwargs)

		# Single-inheritence approach: http://goo.gl/WNiHc
		# Calculator class only inherits from QWidget
		# A specific member attribute self.ui contains all
		# widgets set up in the designer.		
		self.ui = Ui_Calculator()
		self.ui.setupUi(self)

		self.ui.calcButton = QtGui.QPushButton("Calculate")
		self.ui.horizontalLayout_2.addWidget(self.ui.calcButton)

		# Create a validator for each QLineEdit that only
		# allows a user to enter floats: 123.123
		self.ui.inputA.setValidator(QtGui.QDoubleValidator())
		self.ui.inputB.setValidator(QtGui.QDoubleValidator())

		# instead of using the stock operator values set in the
		# ui file, lets set the box to match our class attribute
		self.ui.operatorBox.clear()
		self.ui.operatorBox.addItems(self.OPS.keys())

		self.ui.clearButton.clicked.connect(self.clear)
		self.ui.calcButton.clicked.connect(self.calc)