Created
July 28, 2022 07:56
-
-
Save nhatminhbui/acc644e741686ad538cee849996b6e32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, time | |
from PyQt5 import QtCore, QtGui, QtWidgets | |
from PyQt5.QtWidgets import QApplication, QMainWindow | |
from PyQt5.QtCore import QRunnable, QThreadPool | |
from gui import Ui_MainWindow | |
from firebase import Firebase | |
class MainWindow(QMainWindow): | |
def __init__(self, led, humi, temp): | |
super().__init__() | |
self.uic = Ui_MainWindow() | |
self.uic.setupUi(self) | |
self.database = Firebase() | |
self.status_change() | |
self.uic.btn_led.clicked.connect(self.func_onOff) | |
self.uic.btn_update.clicked.connect(self.func_update) | |
self.led, self.humi, self.temp = led, humi, temp | |
def func_onOff(self): | |
print("temp:", self.temp) | |
if (self.temp == '0'): | |
self.uic.btn_led.setText("On") | |
self.database.update_led("1") | |
else: | |
self.uic.btn_led.setText("Off") | |
self.database.update_led("0") | |
#database.update_led("1") | |
def status_change(self): | |
if (self.led == '1'): | |
self.uic.btn_led.setText("On") | |
elif (self.led == '0'): | |
self.uic.btn_led.setText("Off") | |
self.uic.lbl_humidityValue.setText(humi) | |
self.uic.lbl_temperatureValue.setText(temp) | |
def func_update(self): | |
text = self.uic.lineEdit_noti.text() | |
print(text) | |
self.database.update_noti(text) | |
class Runnable(QRunnable): | |
def __init__(self): | |
super().__init__() | |
self.led, self.humi, self.temp = None, None, None | |
def run(self): | |
self.database = Firebase() | |
while (True): | |
self.led = self.database.get_led_value() | |
self.humi = str(self.database.get_humi_value()) + " %" | |
self.temp = str(self.database.get_temp_value()) + " *C" | |
time.sleep(0.5) | |
def get_led_humi_temp(): | |
return self.led, self.humi, self.temp | |
if __name__ == "__main__": | |
pool = QThreadPool.globalInstance() | |
runnable = Runnable() | |
pool.start(runnable) # run | |
app = QApplication(sys.argv) | |
main_win = MainWindow(runnable.get_led_humi_temp()) | |
main_win.show() | |
sys.exit(app.exec()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment