def main(): """ Start the application :return: """ app = QApplication(sys.argv) form = mainWindow() form.show() sys.exit(app.exec_())
def main(): app = QApplication(sys.argv) form = mainWindow() form.show() sys.exit(app.exec_())
import sys from PyQt5.QtWidgets import * from mainwindow import mainWindow if __name__ == '__main__': app = QApplication(sys.argv) win = mainWindow() win.show() sys.exit(app.exec_())
class masterServer: # mainWin is a class attribute. This line of code is executed when the class masterServer is imported. mainWin = mainWindow() @classmethod def updateLcd_ColVal(cls, data): # Class method, change the value of main_window.lcdNumber in the class attribute mainWin, that is, # change the display value and background color of lcdNumber in the graphical interface. # The first element of the data list is the source of the data. dataFrom = data[0] # for example "1.slave_RPi_2" index = int(dataFrom[0]) # for example "1" from string "1.slave_RPi_2" global lcd_backCol for i in range(1, 14): # Dynamically named graphical interface lcdNumber attributes, each slave_RPi corresponds to 13 lcdNumber attributes, # a total of 104, greatly optimized code aesthetics through string dynamic naming. lcdNumber_name = eval("cls.mainWin.main_window.lcdNumber_" + str(i + 13 * (index - 1))) # Starting from data[2] is sensor data # The availability of data means that the Raspberry Pi is already in the network connection, # as long as it is determined whether the sensor is connected or the data acquisition is normal. # That is to judge whether the background color of the original lcdNumber is brown or green. # If the obtained data value is -1, it means that The corresponding sensor is disconnected or the value is not acquired properly.. if data[i + 1] == -1: # If the background color of the original lcdNumber is not green, It means to reset the corresponding lcdNumber, # set the background color to brown, and set the displayed value to 0. if lcd_backCol[index - 1][i - 1] != 'brown': lcdNumber_name.setStyleSheet( "background: brown;" ) # Change the color of a single lcdNumber to brown. sleep(0.0075) # Leave time required for operation lcdNumber_name.display(0) # set the displayed value to 0. sleep(0.0075) lcd_backCol[index - 1][i - 1] = 'brown' # If the obtained data value is -1, Then it is necessary to determine whether the original lcdNumber displays a value, # that is, whether the original background color is green. else: # If the original display is not green, you will not only need to update the display value but also update the background color. if lcd_backCol[index - 1][i - 1] != 'green': lcdNumber_name.setStyleSheet( "background: green;" ) # Change the color of a single lcdNumber to green. sleep(0.0075) lcdNumber_name.display(data[i + 1]) sleep(0.0075) lcd_backCol[index - 1][i - 1] = 'green' else: # Otherwise just update the value. lcdNumber_name.display(data[i + 1]) sleep(0.03) @classmethod def resetLCD_ColVal(cls, slaveNum): # Change the background color and displayed value of the lcdNumber corresponding to the Raspberry Pi # and all its clients that are suddenly disconnected. global lcd_backCol for index in range(slaveNum, 9): for i in range(1, 14): lcdNumber_name = eval("cls.mainWin.main_window.lcdNumber_" + str(i + 13 * (index - 1))) if lcd_backCol[index - 1][i - 1] != 'gray': lcd_backCol[index - 1][i - 1] = 'gray' lcdNumber_name.setStyleSheet( "background: gray;" ) # Change the color of a single lcdNumber to gray sleep(0.0075) lcdNumber_name.display(0) # set the displayed value to 0. sleep(0.0075)
def main(): mainwin = mainwindow.mainWindow("ui/ui.glade") Gtk.main()