QPushButton, to disable all other push buttons unless pressed again

I have 4 push buttons (open outer, close outer, open inner, close inner) which control 2 doors (via 2 relays), an inner and an outer door. Only one door can be open at a time, I have got this much of the code sorted, now the issue is when I close the outer door I would like it to disable all the other push buttons except for the "open" outer door button. Is this possible? I will paste the relevant section of my code below:

 #@QtCore.pyqtSlot()
    def OuterDoorOpen(self):
        if Door2_Channel == 0:
            return GPIO.output(self.Door1,GPIO.HIGH)
        else:
            return "Please Close Inner Door"

    #@QtCore.pyqtSlot()
    def OuterDoorClose(self):
        if Door2_Channel == 1:
            return
                GPIO.output(self.Door2,GPIO.LOW), self.pushButton_2.setEnabled(False),
self.pushButton_3.setEnabled(False),
self.pushButton_4.setEnabled(False)


    #@QtCore.pyqtSlot()
    def InnerDoorOpen(self):
        if Door1_Channel == 0:
            return GPIO.output(self.Door2,GPIO.HIGH)
        else:
            return "Please Close Outer Door"

    #@QtCore.pyqtSlot()
    def InnerDoorClose (self):
        if Door1_Channel == 1:
            return GPIO.output(self.Door2,GPIO.LOW)

I have designed the GUI using QtDesigner and Im using pyqt5 on python 3.7. I am controlling the relays using a raspberry pi. Whenever I run this code and hit the pushbutton close it causes the programme to crash.

Thanks

2 answers

  • answered 2018-09-24 09:20 Chaitanya Bangera

    Sorry if the suggestion sounds silly, but what if you add a Try except block within the OuterDoorClose block, and debug your code? It might help you understand which line of code is causing the program to crash and why. Eg:

    self.timer = QtCore.QTimer()
    self.timer.timeout.connect(self.enable_buttons)
    
    #@QtCore.pyqtSlot()
    def OuterDoorClose(self):
        try:
            if Door2_Channel == 1:
                self.pushButton_2.setEnabled(False)
                self.pushButton_3.setEnabled(False)
                self.pushButton_4.setEnabled(False)
                self.timer.start(30000)
                return GPIO.output(self.Door2,GPIO.LOW)
        except Exception as e:
            #Your exception code
    
    
    
    def self.enable_buttons(self):
        self.pushButton_2.setEnabled(True)
        self.pushButton_3.setEnabled(True)
        self.pushButton_4.setEnabled(True)
    

  • answered 2018-09-24 11:27 Almaas Shah

    i managed to get this to work by using partials and setting the SetEnabled to False. Here is the relevant section of the code.

    def OuterDoorClose(self):
        if GPIO.input(Outer)==0: #Outer Door Open
            self.ui.pushButton_3.setEnabled(False)
            self.ui.pushButton_4.setEnabled(False)
            QtCore.QTimer.singleShot(10000,partial(self.ui.pushButton_3.setEnabled,True))
            return GPIO.output(Outer,GPIO.HIGH)