Pyside GPIO弹出窗口Beaglebone Black

时间:2016-11-07 07:14:00

标签: pyside beagleboneblack adafruit

因此,当Beagleboard上的GPIO引脚设置为高电平时,我试图弹出警告窗口。在我的Adafruit中,我使用BBIO库轻松地在控制台中运行代码。但是,当使用应用于pyside库的相同逻辑时,程序会忽略" if"子句并自动运行弹出窗口。即使使用简单的弹出窗口,程序也会忽略if语句。任何帮助或想法都表示赞赏。

    #console code
    import Adafruit_BBIO.GPIO as GPIO
    from time import sleep #handy sleep command
    GPIO.setup("P8_16", GPIO.IN)

    while True:
        if GPIO.input("P8_16"):
            print ("Battery Low on the Down low!!")
            sleep (1.25)
        else:
            pass

    #popup code
    import sys
    from PySide.QtCore import *
    from PySide.QtGui import *
    import time
    import Adafruit_BBIO.GPIO as GPIO
    from time import sleep #handy sleep command

    GPIO.setup("P8_16", GPIO.IN) #set GPIO port

    while True:
        if GPIO.input("P8_16"):
            #sleep(1)
            def window():
                app = QApplication(sys.argv)
                w = QWidget()
                b = QPushButton(w)
                b.setText("Battery is Low!")

                b.move(100,100)
                b.clicked.connect(showdialog)
                w.setWindowTitle("Battery Alert")
                w.show()
                sys.exit(app.exec_())

            def showdialog():
                msg = QMessageBox()
                msg.setIcon(QMessageBox.Warning)

                msg.setText("Please recharge the Tracker battery")
                msg.setInformativeText("To exit simply close the windows")
                msg.setWindowTitle("Battery Low")
                msg.setDetailedText("Please recharge the Tracker unit")
                msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
                msg.buttonClicked.connect(msgbtn)

                retval = msg.exec_()
                print "value of pressed message box button:", retval

            def msgbtn(i):
                print "Button pressed is:",i.text()

            if __name__ == '__main__': 
                window()

        else:
            pass
            sleep(1)

0 个答案:

没有答案