class UiGameFrame(QFrame): def __init__(self, parent): super(UiGameFrame, self).__init__(parent) self.setupUi() def setupUi(self): # 游戏界面 self.setGeometry(QRect(10, 10, 671, 711)) # self.setStyleSheet("background-image: url(./img/bg.bmp);") self.setFrameShape(QFrame.Box) self.setFrameShadow(QFrame.Sunken) self.setLineWidth(2) self.setObjectName("uiGameFrame") # 房间信息 self.game_info = QLabel(self) self.game_info.setGeometry(QRect(20, 5, 631, 40)) self.game_info.setObjectName("gameInfo") self.game_info.setScaledContents(True) self.game_info.setStyleSheet( 'font-size:20px;font-weight:bold;') self.game_info.setAlignment(Qt.AlignCenter | Qt.AlignTop) # 游戏画面 self.game_frame = QFrame(self) self.game_frame.setGeometry(QRect(80, 145, 504, 504)) # self.game_frame.setStyleSheet("background-image: url(./img/game.bmp);") self.game_frame.setFrameShape(QFrame.Box) self.game_frame.setFrameShadow(QFrame.Plain) self.game_frame.setObjectName("gameFrame") # 对战 self.vs_frame = QFrame(self) self.vs_frame.setGeometry(QRect(50, 55, 270, 80)) self.vs_frame.setFrameShape(QFrame.StyledPanel) self.vs_frame.setFrameShadow(QFrame.Raised) self.vs_frame.setObjectName("vsFrame") # self.vs_frame.setStyleSheet("border:1px solid;") self.vs_user_image = QLabel(self.vs_frame) self.vs_user_image.setGeometry(QRect(5, 5, 70, 70)) self.vs_user_image.setObjectName("vsUserImage") self.vs_user_image.setScaledContents(True) self.vs_user_info = QLabel(self.vs_frame) self.vs_user_info.setGeometry(QRect(80, 5, 120, 70)) self.vs_user_info.setObjectName("vsUserInfo") self.lcdNumber_l = QLCDNumber(self.vs_frame) self.lcdNumber_l.setGeometry(QRect(205, 5, 60, 70)) self.lcdNumber_l.setLineWidth(0) self.lcdNumber_l.setDigitCount(2) self.lcdNumber_l.setSegmentStyle(QLCDNumber.Flat) self.lcdNumber_l.setProperty("intValue", 20) self.lcdNumber_l.setObjectName("lcdNumber_2") self.vs_frame_r = QFrame(self) self.vs_frame_r.setGeometry(QRect(350, 55, 270, 80)) self.vs_frame_r.setFrameShape(QFrame.StyledPanel) self.vs_frame_r.setFrameShadow(QFrame.Raised) self.vs_frame_r.setObjectName("vsFrameR") # self.vs_frame_r.setStyleSheet("border:1px solid;") self.lcdNumber_r = QLCDNumber(self.vs_frame_r) self.lcdNumber_r.setGeometry(QRect(5, 5, 60, 70)) self.lcdNumber_r.setLineWidth(0) self.lcdNumber_r.setDigitCount(2) self.lcdNumber_r.setSegmentStyle(QLCDNumber.Flat) self.lcdNumber_r.setProperty("intValue", 20) self.lcdNumber_r.setObjectName("lcdNumber_3") self.vs_user_image_r = QLabel(self.vs_frame_r) self.vs_user_image_r.setGeometry(QRect(70, 5, 70, 70)) self.vs_user_image_r.setObjectName("vsUserImageR") self.vs_user_image_r.setScaledContents(True) self.vs_user_info_r = QLabel(self.vs_frame_r) self.vs_user_info_r.setGeometry(QRect(145, 5, 120, 70)) self.vs_user_info_r.setObjectName("vsUserInfoR") # 按钮区域 self.cmd_frame = QFrame(self) self.cmd_frame.setGeometry(QRect(55, 655, 560, 47)) self.cmd_frame.setFrameShape(QFrame.StyledPanel) self.cmd_frame.setFrameShadow(QFrame.Raised) self.cmd_frame.setObjectName("cmdFrame") # 开始按钮 self.gameStartBtn = QPushButton(self.cmd_frame) self.gameStartBtn.setGeometry(QRect(10, 10, 100, 27)) self.gameStartBtn.setObjectName("gameStartBtn") # 悔棋按钮 self.gameUndoBtn = QPushButton(self.cmd_frame) self.gameUndoBtn.setGeometry(QRect(120, 10, 100, 27)) self.gameUndoBtn.setObjectName("gameUndoBtn") # 认输按钮 self.gameGiveupBtn = QPushButton(self.cmd_frame) self.gameGiveupBtn.setGeometry(QRect(230, 10, 100, 27)) self.gameGiveupBtn.setObjectName("gameGiveupBtn") # 返回大厅 self.gameReHallBtn = QPushButton(self.cmd_frame) self.gameReHallBtn.setGeometry(QRect(340, 10, 100, 27)) self.gameReHallBtn.setObjectName("gameReHallBtn") # 设置 self.gameSetBtn = QPushButton(self.cmd_frame) self.gameSetBtn.setGeometry(QRect(450, 10, 100, 27)) self.gameSetBtn.setObjectName("gameSetBtn") self.retranslateUi() QMetaObject.connectSlotsByName(self) def retranslateUi(self): _translate = QCoreApplication.translate self.gameStartBtn.setText(_translate("MainWindow", "开始游戏")) self.gameUndoBtn.setText(_translate("MainWindow", "悔棋")) self.gameGiveupBtn.setText(_translate("MainWindow", "认输")) self.gameReHallBtn.setText(_translate("MainWindow", "返回大厅")) self.gameSetBtn.setText(_translate("MainWindow", "设置"))
class MyWidget(QMainWindow): def __init__(self): super().__init__() self.setupUi(self) self.btn_1.clicked.connect(self.one) self.btn_2.clicked.connect(self.two) self.btn_3.clicked.connect(self.three) self.btn_4.clicked.connect(self.four) self.btn_5.clicked.connect(self.five) self.btn_6.clicked.connect(self.six) self.btn_7.clicked.connect(self.seven) self.btn_8.clicked.connect(self.eight) self.btn_9.clicked.connect(self.nine) self.btn_0.clicked.connect(self.zero) self.btn_00.clicked.connect(self.zerozero) self.btn_floating.clicked.connect(self.floating) self.btn_m_plus.clicked.connect(self.m_plus) self.btn_m_minus.clicked.connect(self.m_minus) self.btn_mr.clicked.connect(self.mr) self.btn_mc.clicked.connect(self.mc) self.btn_sin.clicked.connect(self.sin) self.btn_cos.clicked.connect(self.cos) self.btn_tg.clicked.connect(self.tg) self.btn_ctg.clicked.connect(self.ctg) self.btn_plus.clicked.connect(self.plus) self.btn_minus.clicked.connect(self.minus) self.btn_ymn.clicked.connect(self.ymn) self.btn_step.clicked.connect(self.step) self.btn_delen.clicked.connect(self.delen) self.btn_pr.clicked.connect(self.pr) self.btn_delet.clicked.connect(self.delet) self.btn_ac.clicked.connect(self.ac) self.btn_result.clicked.connect(self.result) def one(self): global operator, operation if operation: operator.append('1') operation = False else: operator[-1] += '1' self.window.display(operator[-1]) self.sprav.setText(''.join(operator)) def two(self): global operator, operation if operation: operator.append('2') operation = False else: operator[-1] += '2' self.window.display(operator[-1]) self.sprav.setText(''.join(operator)) def three(self): global operator, operation if operation: operator.append('3') operation = False else: operator[-1] += '3' self.window.display(operator[-1]) self.sprav.setText(''.join(operator)) def four(self): global operator, operation if operation: operator.append('4') operation = False else: operator[-1] += '4' self.window.display(operator[-1]) self.sprav.setText(''.join(operator)) def five(self): global operator, operation if operation: operator.append('5') operation = False else: operator[-1] += '5' self.window.display(operator[-1]) self.sprav.setText(''.join(operator)) def six(self): global operator, operation if operation: operator.append('6') operation = False else: operator[-1] += '6' self.window.display(operator[-1]) self.sprav.setText(''.join(operator)) def seven(self): global operator, operation if operation: operator.append('7') operation = False else: operator[-1] += '7' self.window.display(operator[-1]) self.sprav.setText(''.join(operator)) def eight(self): global operator, operation if operation: operator.append('8') operation = False else: operator[-1] += '8' self.window.display(operator[-1]) self.sprav.setText(''.join(operator)) def nine(self): global operator, operation if operation: operator.append('9') operation = False else: operator[-1] += '9' self.window.display(operator[-1]) self.sprav.setText(''.join(operator)) def zero(self): global operator, operation if operation: operator.append('0') operation = False else: operator[-1] += '0' self.window.display(operator[-1]) self.sprav.setText(''.join(operator)) def zerozero(self): global operator, operation if operation: operator.append('00') operation = False else: operator[-1] += '00' self.window.display(operator[-1]) self.sprav.setText(''.join(operator)) def floating(self): global operator, operation if operation: operator.append('.') operation = False else: operator[-1] += '.' self.window.display(operator[-1]) self.sprav.setText(''.join(operator)) def m_plus(self): global memory, operator if operator[-1].isdigit(): memory = float(memory) + float(operator[-1]) self.m.setText("M+") def m_minus(self): global memory, operator if operator[-1].isdigit(): memory = float(memory) - float(operator[-1]) self.m.setText("M-") def mr(self): global operator, memory if memory != 0: operator.append('mr') self.window.display(memory) self.sprav.setText(''.join(operator)) def mc(self): global memory memory = 0 self.m.setText("") def sin(self): global operator, operation operation = True operator.append('sin') self.sprav.setText(''.join(operator)) def cos(self): global operator, operation operation = True operator.append('cos') self.sprav.setText(''.join(operator)) def tg(self): global operator, operation operation = True operator.append('tg') self.sprav.setText(''.join(operator)) def ctg(self): global operator, operation operation = True operator.append('ctg') self.sprav.setText(''.join(operator)) def plus(self): global operator, operation operation = True operator.append('+') self.sprav.setText(''.join(operator)) def minus(self): global operator, operation operation = True operator.append('-') self.sprav.setText(''.join(operator)) def ymn(self): global operator, operation operation = True operator.append('*') self.sprav.setText(''.join(operator)) def step(self): global operator, operation operation = True operator.append('^') self.sprav.setText(''.join(operator)) def delen(self): global operator, operation operation = True operator.append('/') self.sprav.setText(''.join(operator)) def pr(self): global operator, operation operation = True operator.append('%') self.sprav.setText(''.join(operator)) def delet(self): global operator, operation if len(operator) != 0: last = operator[-1] if last == 'sin' or last == 'cos' or last == 'tg' or last == 'ctg' or last == 'mr': del operator[-1] else: operator[-1] = operator[-1][:-1:] if operator[-1] == '': del operator[-1] if len(operator) != 0: self.window.display(operator[-1]) else: operator = [''] self.window.display(0) self.sprav.setText(''.join(operator)) def ac(self): global operator, operation, k k += 1 if k == 7: self.resize(912, 689) operator = [] operation = True self.window.display(0) self.sprav.setText(''.join(operator)) def result(self): global operator, memory, operation try: while 'mr' in operator: index = operator.index('mr') operator[index] = memory while 'sin' in operator: index = operator.index('sin') rad = math.radians(float(operator[index + 1])) sin = math.sin(rad) del operator[index + 1] operator[index] = str(sin) while 'cos' in operator: index = operator.index('cos') rad = math.radians(float(operator[index + 1])) cos = math.cos(rad) del operator[index + 1] operator[index] = str(cos) while 'tg' in operator: index = operator.index('tg') rad = math.radians(float(operator[index + 1])) tg = math.tan(rad) del operator[index + 1] operator[index] = str(tg) while 'ctg' in operator: index = operator.index('ctg') rad = math.radians(float(operator[index + 1])) ctg = 1 / math.tan(rad) del operator[index + 1] operator[index] = str(ctg) while '^' in operator: index = operator.index('^') count = float(operator[index - 1]) ** float(operator[index + 1]) del operator[index + 1] operator[index] = str(float(round(count, 15))) del operator[index - 1] while ('*' in operator) or ("/" in operator) or ("%" in operator): if '*' in operator: index_1 = operator.index('*') else: index_1 = 1000 if '/' in operator: index_2 = operator.index('/') else: index_2 = 1000 if '%' in operator: index_3 = operator.index('%') else: index_3 = 1000 spisok = [index_1, index_2, index_3] if min(spisok) == index_2: count = float(operator[index_2 - 1]) / float(operator[index_2 + 1]) del operator[index_2 + 1] operator[index_2] = str(count) del operator[index_2 - 1] elif min(spisok) == index_1: count = float(operator[index_1 - 1]) * float(operator[index_1 + 1]) del operator[index_1 + 1] operator[index_1] = str(float(round(count, 15))) del operator[index_1 - 1] elif min(spisok) == index_3: count = float(operator[index_3 - 1]) % float(operator[index_3 + 1]) del operator[index_3 + 1] operator[index_3] = str(float(round(count, 15))) del operator[index_3 - 1] while ('+' in operator) or ("-" in operator): if '+' in operator: index_1 = operator.index('+') else: index_1 = 1000 if '-' in operator: index_2 = operator.index('-') else: index_2 = 1000 if (index_1 > index_2) and (index_2 != -1): count = float(operator[index_2 - 1]) - float(operator[index_2 + 1]) del operator[index_2 + 1] operator[index_2] = str(count) del operator[index_2 - 1] elif (index_1 < index_2) and (index_1 != -1): count = float(operator[index_1 - 1]) + float(operator[index_1 + 1]) del operator[index_1 + 1] operator[index_1] = str(count) del operator[index_1 - 1] self.sprav.setText(''.join(operator)) self.window.display(operator[0]) except Exception: self.window.display('Error') def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") #MainWindow.resize(912, 689) MainWindow.resize(490, 440) font = QFont() font.setFamily("MS Gothic") MainWindow.setFont(font) MainWindow.setStyleSheet("background-color: rgb(0, 0, 0);") self.centralwidget = QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.window = QLCDNumber(self.centralwidget) self.window.setGeometry(QRect(10, 10, 461, 60)) self.window.setStyleSheet("background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:2, fx:0.5, fy:0.5, stop:1 rgba(249, 187, 0, 255));") self.window.setDigitCount(20) self.window.setObjectName("window") self.btn_ac = QPushButton(self.centralwidget) self.btn_ac.setGeometry(QRect(410, 320, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(20) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_ac.setFont(font) self.btn_ac.setStyleSheet("font: 75 20pt \"Segoe Script\";color: rgb(255, 0, 0);\n" "background-color: rgb(29, 29, 29);") self.btn_ac.setIconSize(QSize(16, 16)) self.btn_ac.setObjectName("btn_ac") self.btn_mr = QPushButton(self.centralwidget) self.btn_mr.setGeometry(QRect(170, 80, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(15) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_mr.setFont(font) self.btn_mr.setStyleSheet("background-color: rgb(29, 29, 29);color: rgb(0, 239, 239);font: 75 15pt \"Segoe Script\";") self.btn_mr.setIconSize(QSize(16, 16)) self.btn_mr.setObjectName("btn_mr") self.btn_mc = QPushButton(self.centralwidget) self.btn_mc.setGeometry(QRect(250, 80, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(15) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_mc.setFont(font) self.btn_mc.setStyleSheet("background-color: rgb(29, 29, 29);color: rgb(0, 239, 239);font: 75 15pt \"Segoe Script\";") self.btn_mc.setIconSize(QSize(16, 16)) self.btn_mc.setObjectName("btn_mc") self.btn_m_plus = QPushButton(self.centralwidget) self.btn_m_plus.setEnabled(True) self.btn_m_plus.setGeometry(QRect(10, 80, 61, 50)) self.btn_m_plus.setMaximumSize(QSize(61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(15) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_m_plus.setFont(font) self.btn_m_plus.setCursor(QCursor(Qt.ArrowCursor)) self.btn_m_plus.setMouseTracking(True) self.btn_m_plus.setStyleSheet("background-color: rgb(29, 29, 29);color: rgb(0, 239, 239);font: 75 15pt \"Segoe Script\";") self.btn_m_plus.setIconSize(QSize(16, 16)) self.btn_m_plus.setCheckable(False) self.btn_m_plus.setChecked(False) self.btn_m_plus.setObjectName("btn_m_plus") self.btn_m_minus = QPushButton(self.centralwidget) self.btn_m_minus.setGeometry(QRect(90, 80, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(15) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_m_minus.setFont(font) self.btn_m_minus.setStyleSheet("background-color: rgb(29, 29, 29);color: rgb(0, 239, 239);font: 75 15pt \"Segoe Script\";") self.btn_m_minus.setIconSize(QSize(16, 16)) self.btn_m_minus.setObjectName("btn_m_minus") self.btn_cos = QPushButton(self.centralwidget) self.btn_cos.setGeometry(QRect(410, 80, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(20) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_cos.setFont(font) self.btn_cos.setStyleSheet("background-color: rgb(29, 29, 29);color: rgb(255, 169, 254);font: 75 20pt \"Segoe Script\";") self.btn_cos.setIconSize(QSize(16, 16)) self.btn_cos.setObjectName("btn_cos") self.btn_sin = QPushButton(self.centralwidget) self.btn_sin.setGeometry(QRect(330, 80, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(20) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_sin.setFont(font) self.btn_sin.setStyleSheet("background-color: rgb(29, 29, 29);color: rgb(255, 169, 254);font: 75 20pt \"Segoe Script\";") self.btn_sin.setIconSize(QSize(16, 16)) self.btn_sin.setObjectName("btn_sin") self.btn_tg = QPushButton(self.centralwidget) self.btn_tg.setGeometry(QRect(330, 140, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(20) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_tg.setFont(font) self.btn_tg.setStyleSheet("background-color: rgb(29, 29, 29);color: rgb(255, 169, 254);font: 75 20pt \"Segoe Script\";") self.btn_tg.setIconSize(QSize(16, 16)) self.btn_tg.setObjectName("btn_tg") self.btn_minus = QPushButton(self.centralwidget) self.btn_minus.setGeometry(QRect(250, 200, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(30) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_minus.setFont(font) self.btn_minus.setStyleSheet("background-color: rgb(29, 29, 29);font: 75 30pt \"Segoe Script\";color: rgb(27, 147, 0);") self.btn_minus.setIconSize(QSize(16, 16)) self.btn_minus.setObjectName("btn_minus") self.btn_plus = QPushButton(self.centralwidget) self.btn_plus.setGeometry(QRect(250, 140, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(30) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_plus.setFont(font) self.btn_plus.setStyleSheet("background-color: rgb(29, 29, 29);font: 75 30pt \"Segoe Script\";color: rgb(27, 147, 0);") self.btn_plus.setIconSize(QSize(16, 16)) self.btn_plus.setObjectName("btn_plus") self.btn_ymn = QPushButton(self.centralwidget) self.btn_ymn.setGeometry(QRect(250, 260, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(30) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_ymn.setFont(font) self.btn_ymn.setStyleSheet("background-color: rgb(29, 29, 29);font: 75 30pt \"Segoe Script\";color: rgb(27, 147, 0);") self.btn_ymn.setIconSize(QSize(16, 16)) self.btn_ymn.setObjectName("btn_ymn") self.btn_result = QPushButton(self.centralwidget) self.btn_result.setGeometry(QRect(330, 320, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(40) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_result.setFont(font) self.btn_result.setStyleSheet("background-color: rgb(29, 29, 29);font: 75 40pt \"Segoe Script\";color: rgb(255, 140, 0);") self.btn_result.setIconSize(QSize(16, 16)) self.btn_result.setObjectName("btn_result") self.btn_step = QPushButton(self.centralwidget) self.btn_step.setGeometry(QRect(330, 200, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(30) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_step.setFont(font) self.btn_step.setStyleSheet("background-color: rgb(29, 29, 29);font: 75 30pt \"Segoe Script\";color: rgb(27, 147, 0);") self.btn_step.setIconSize(QSize(16, 16)) self.btn_step.setObjectName("btn_step") self.btn_1 = QPushButton(self.centralwidget) self.btn_1.setGeometry(QRect(10, 140, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(30) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_1.setFont(font) self.btn_1.setMouseTracking(False) self.btn_1.setStyleSheet("background-color: rgb(29, 29, 29);color: rgb(0, 85, 255);font: 75 30pt \"Segoe Script\";") self.btn_1.setIconSize(QSize(16, 16)) self.btn_1.setCheckable(False) self.btn_1.setChecked(False) self.btn_1.setObjectName("btn_1") self.btn_2 = QPushButton(self.centralwidget) self.btn_2.setGeometry(QRect(90, 140, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(30) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_2.setFont(font) self.btn_2.setStyleSheet("background-color: rgb(29, 29, 29);color: rgb(0, 85, 255);font: 75 30pt \"Segoe Script\";") self.btn_2.setIconSize(QSize(16, 16)) self.btn_2.setObjectName("btn_2") self.btn_3 = QPushButton(self.centralwidget) self.btn_3.setGeometry(QRect(170, 140, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(30) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_3.setFont(font) self.btn_3.setStyleSheet("background-color: rgb(29, 29, 29);color: rgb(0, 85, 255);font: 75 30pt \"Segoe Script\";") self.btn_3.setIconSize(QSize(16, 16)) self.btn_3.setObjectName("btn_3") self.btn_4 = QPushButton(self.centralwidget) self.btn_4.setGeometry(QRect(10, 200, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(30) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_4.setFont(font) self.btn_4.setStyleSheet("background-color: rgb(29, 29, 29);color: rgb(0, 85, 255);font: 75 30pt \"Segoe Script\";") self.btn_4.setIconSize(QSize(16, 16)) self.btn_4.setObjectName("btn_4") self.btn_5 = QPushButton(self.centralwidget) self.btn_5.setGeometry(QRect(90, 200, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(30) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_5.setFont(font) self.btn_5.setStyleSheet("background-color: rgb(29, 29, 29);color: rgb(0, 85, 255);font: 75 30pt \"Segoe Script\";") self.btn_5.setIconSize(QSize(16, 16)) self.btn_5.setObjectName("btn_5") self.btn_6 = QPushButton(self.centralwidget) self.btn_6.setGeometry(QRect(170, 200, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(30) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_6.setFont(font) self.btn_6.setStyleSheet("background-color: rgb(29, 29, 29);font: 75 30pt \"Segoe Script\";color: rgb(0, 85, 255);") self.btn_6.setIconSize(QSize(16, 16)) self.btn_6.setObjectName("btn_6") self.btn_7 = QPushButton(self.centralwidget) self.btn_7.setGeometry(QRect(10, 260, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(30) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_7.setFont(font) self.btn_7.setStyleSheet("background-color: rgb(29, 29, 29);font: 75 30pt \"Segoe Script\";color: rgb(0, 85, 255);") self.btn_7.setIconSize(QSize(16, 16)) self.btn_7.setObjectName("btn_7") self.btn_8 = QPushButton(self.centralwidget) self.btn_8.setGeometry(QRect(90, 260, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(30) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_8.setFont(font) self.btn_8.setStyleSheet("background-color: rgb(29, 29, 29);font: 75 30pt \"Segoe Script\";color: rgb(0, 85, 255);") self.btn_8.setIconSize(QSize(16, 16)) self.btn_8.setObjectName("btn_8") self.btn_9 = QPushButton(self.centralwidget) self.btn_9.setGeometry(QRect(170, 260, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(30) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_9.setFont(font) self.btn_9.setStyleSheet("background-color: rgb(29, 29, 29);font: 75 30pt \"Segoe Script\";color: rgb(0, 85, 255);") self.btn_9.setIconSize(QSize(16, 16)) self.btn_9.setObjectName("btn_9") self.btn_0 = QPushButton(self.centralwidget) self.btn_0.setGeometry(QRect(10, 320, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(30) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_0.setFont(font) self.btn_0.setStyleSheet("background-color: rgb(29, 29, 29);font: 75 30pt \"Segoe Script\";color: rgb(0, 85, 255);") self.btn_0.setIconSize(QSize(16, 16)) self.btn_0.setObjectName("btn_0") self.btn_ctg = QPushButton(self.centralwidget) self.btn_ctg.setGeometry(QRect(410, 140, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(20) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_ctg.setFont(font) self.btn_ctg.setStyleSheet("background-color: rgb(29, 29, 29);color: rgb(255, 169, 254);font: 75 20pt \"Segoe Script\";") self.btn_ctg.setIconSize(QSize(16, 16)) self.btn_ctg.setObjectName("btn_ctg") self.btn_delen = QPushButton(self.centralwidget) self.btn_delen.setGeometry(QRect(330, 260, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(30) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_delen.setFont(font) self.btn_delen.setStyleSheet("background-color: rgb(29, 29, 29);font: 75 30pt \"Segoe Script\";color: rgb(27, 147, 0);") self.btn_delen.setIconSize(QSize(16, 16)) self.btn_delen.setObjectName("btn_delen") self.Sprav = QLabel(self.centralwidget) self.Sprav.setGeometry(QRect(500, 10, 401, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(20) self.Sprav.setFont(font) self.Sprav.setStyleSheet("color: rgb(255, 255, 255);\n" "color: rgb(255, 255, 0);") self.Sprav.setObjectName("Sprav") self.Text_sprav = QTextBrowser(self.centralwidget) self.Text_sprav.setGeometry(QRect(490, 69, 411, 351)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(12) font.setBold(False) font.setItalic(False) font.setWeight(50) self.Text_sprav.setFont(font) self.Text_sprav.setStyleSheet("color: rgb(255, 255, 0);\n" "font: 12pt \"Segoe Script\";") self.Text_sprav.setObjectName("Text_sprav") self.textEdit = QTextEdit(self.centralwidget) self.textEdit.setGeometry(QRect(10, 480, 391, 160)) font = QFont() font.setPointSize(14) self.textEdit.setFont(font) self.textEdit.setStyleSheet("color: rgb(255, 170, 0);") self.textEdit.setObjectName("textEdit") self.Sprav_2 = QLabel(self.centralwidget) self.Sprav_2.setGeometry(QRect(10, 430, 391, 41)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(20) self.Sprav_2.setFont(font) self.Sprav_2.setStyleSheet("color: rgb(255, 255, 255);\n" "color: rgb(255, 255, 0);") self.Sprav_2.setObjectName("Sprav_2") self.Text_sprav_2 = QTextBrowser(self.centralwidget) self.Text_sprav_2.setGeometry(QRect(410, 480, 491, 161)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(12) font.setBold(False) font.setItalic(False) font.setWeight(50) self.Text_sprav_2.setFont(font) self.Text_sprav_2.setStyleSheet("color: rgb(255, 255, 0);\n" "font: 12pt \"Segoe Script\";") self.Text_sprav_2.setObjectName("Text_sprav_2") self.m = QLabel(self.centralwidget) self.m.setGeometry(QRect(13, 13, 20, 10)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(9) self.m.setFont(font) self.m.setStyleSheet("background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:2, fx:0.5, fy:0.5, stop:1 rgba(249, 187, 0, 255));") self.m.setText("") self.m.setObjectName("m") self.btn_floating = QPushButton(self.centralwidget) self.btn_floating.setGeometry(QRect(250, 320, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(40) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_floating.setFont(font) self.btn_floating.setStyleSheet("background-color: rgb(29, 29, 29);font: 75 40pt \"Segoe Script\";\n" "color: rgb(20, 24, 255);") self.btn_floating.setIconSize(QSize(16, 16)) self.btn_floating.setObjectName("btn_floating") self.btn_00 = QPushButton(self.centralwidget) self.btn_00.setGeometry(QRect(90, 320, 141, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(30) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_00.setFont(font) self.btn_00.setStyleSheet("background-color: rgb(29, 29, 29);color: rgb(0, 85, 255);font: 75 30pt \"Segoe Script\";") self.btn_00.setIconSize(QSize(16, 16)) self.btn_00.setObjectName("btn_00") self.btn_delet = QPushButton(self.centralwidget) self.btn_delet.setGeometry(QRect(410, 260, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(20) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_delet.setFont(font) self.btn_delet.setStyleSheet("background-color: rgb(29, 29, 29);color: rgb(255, 0, 0);font: 75 20pt \"Segoe Script\";") self.btn_delet.setIconSize(QSize(16, 16)) self.btn_delet.setObjectName("btn_delet") self.btn_pr = QPushButton(self.centralwidget) self.btn_pr.setGeometry(QRect(410, 200, 61, 50)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(30) font.setBold(False) font.setItalic(False) font.setWeight(9) self.btn_pr.setFont(font) self.btn_pr.setStyleSheet("background-color: rgb(29, 29, 29);color: rgb(27, 147, 0);font: 75 30pt \"Segoe Script\";") self.btn_pr.setIconSize(QSize(16, 16)) self.btn_pr.setObjectName("btn_pr") self.sprav = QLabel(self.centralwidget) self.sprav.setGeometry(QRect(40, 380, 441, 41)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(15) self.sprav.setFont(font) self.sprav.setStyleSheet("color: rgb(255, 255, 255);") self.sprav.setText("") self.sprav.setObjectName("sprav") self.Sprav_4 = QLabel(self.centralwidget) self.Sprav_4.setGeometry(QRect(410, 430, 491, 41)) font = QFont() font.setFamily("Segoe Script") font.setPointSize(20) self.Sprav_4.setFont(font) self.Sprav_4.setStyleSheet("color: rgb(255, 255, 255);\n" "color: rgb(255, 255, 0);") self.Sprav_4.setObjectName("Sprav_4") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QMenuBar(MainWindow) self.menubar.setGeometry(QRect(0, 0, 912, 21)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.btn_ac.setText(_translate("MainWindow", "AC")) self.btn_mr.setText(_translate("MainWindow", "MR")) self.btn_mc.setText(_translate("MainWindow", "MC")) self.btn_m_plus.setText(_translate("MainWindow", "M+")) self.btn_m_minus.setText(_translate("MainWindow", "M-")) self.btn_cos.setText(_translate("MainWindow", "cos")) self.btn_sin.setText(_translate("MainWindow", "sin")) self.btn_tg.setText(_translate("MainWindow", "tg")) self.btn_minus.setText(_translate("MainWindow", "-")) self.btn_plus.setText(_translate("MainWindow", "+")) self.btn_ymn.setText(_translate("MainWindow", "x")) self.btn_result.setText(_translate("MainWindow", "=")) self.btn_step.setText(_translate("MainWindow", "^")) self.btn_1.setText(_translate("MainWindow", "1")) self.btn_2.setText(_translate("MainWindow", "2")) self.btn_3.setText(_translate("MainWindow", "3")) self.btn_4.setText(_translate("MainWindow", "4")) self.btn_5.setText(_translate("MainWindow", "5")) self.btn_6.setText(_translate("MainWindow", "6")) self.btn_7.setText(_translate("MainWindow", "7")) self.btn_8.setText(_translate("MainWindow", "8")) self.btn_9.setText(_translate("MainWindow", "9")) self.btn_0.setText(_translate("MainWindow", "0")) self.btn_ctg.setText(_translate("MainWindow", "ctg")) self.btn_delen.setText(_translate("MainWindow", "/")) self.Sprav.setText(_translate("MainWindow", " Справочник")) self.Text_sprav.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Segoe Script\'; font-size:12pt; font-weight:400; font-style:normal;\">\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:36px; margin-right:36px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'Lato-Regular,Arial,sans-serif\'; color:#0febff;\">[M+] – прибавление числа в память</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:36px; margin-right:36px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'Lato-Regular,Arial,sans-serif\'; color:#0febff;\">[M-] – вычитание числа из памяти</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:36px; margin-right:36px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'Lato-Regular,Arial,sans-serif\'; color:#0febff;\">[^] – возведение в выбранную степень</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:36px; margin-right:36px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'Lato-Regular,Arial,sans-serif\'; color:#0febff;\">[+][-][x][</span><span style=\" font-family:\'Symbol\'; color:#0febff;\">¸</span><span style=\" font-family:\'Lato-Regular,Arial,sans-serif\'; color:#0febff;\">] – арифметические операции</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:36px; margin-right:36px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'Lato-Regular,Arial,sans-serif\'; color:#0febff;\">[MR] – вывести содержимое памяти на дисплей</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:36px; margin-right:36px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'Lato-Regular,Arial,sans-serif\'; color:#0febff;\">[MC] – очистить содержимое памяти</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:36px; margin-right:36px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'Lato-Regular,Arial,sans-serif\'; color:#0febff;\">[AC] – общий сброс</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:36px; margin-right:36px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'Lato-Regular,Arial,sans-serif\'; color:#0febff;\">[sin][cos][tg][ctg] – формулы произведения тригонометрических функций, при работе с этими функциями сначала записывается sin, cos, tg, ctg потом число(Например sin 45)</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:36px; margin-right:36px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; color:#0febff;\">[Del]</span><span style=\" font-family:\'Lato-Regular,Arial,sans-serif\'; color:#0febff;\"> – удаляет последнюю введенную цифру или знак действия</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:36px; margin-right:36px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; color:#0febff;\">[%]</span><span style=\" font-family:\'Lato-Regular,Arial,sans-serif\'; color:#0febff;\"> – вычисляет остаток от деления</span><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:8pt; color:#0febff;\"><br /></span><span style=\" font-family:\'MS Shell Dlg 2\'; color:#0febff;\">[.]</span><span style=\" font-family:\'Lato-Regular,Arial,sans-serif\'; color:#0febff;\"> – используется для записи дробной части</span></p></body></html>")) self.Sprav_2.setText(_translate("MainWindow", " Для заметок")) self.Text_sprav_2.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Segoe Script\'; font-size:12pt; font-weight:400; font-style:normal;\">\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:10pt; color:#00ff7f;\"> </span><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:10pt; color:#11ff00;\"> - Если указанный порядок действий невозможно вычислить</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:10pt; color:#11ff00;\"> - Если мы накасячили</span></p>\n" "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:\'MS Shell Dlg 2\'; font-size:10pt; color:#11ff00;\"><br /></p>\n" "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:\'MS Shell Dlg 2\'; font-size:10pt; color:#11ff00;\"><br /></p>\n" "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:\'MS Shell Dlg 2\'; font-size:10pt; color:#11ff00;\"><br /></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:10pt; color:#11ff00;\"> По всем вопросам обращайтесь https://vk.com/vasily.shishkin</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:10pt; color:#11ff00;\"> https://vk.com/andrey.krivosheev</span></p></body></html>")) self.btn_floating.setText(_translate("MainWindow", ".")) self.btn_00.setText(_translate("MainWindow", "00")) self.btn_delet.setText(_translate("MainWindow", "Del")) self.btn_pr.setText(_translate("MainWindow", "%")) self.Sprav_4.setText(_translate("MainWindow", " Почему появляется ошибка?"))
class PomodoroTimer(QWidget): def __init__(self): # Create default constructor super().__init__() self.initializeUI() def initializeUI(self): """Initialize the window and display its contents to the screen.""" self.setMinimumSize(500, 400) self.setWindowTitle("1.1 - Pomodoro Timer") self.setWindowIcon(QIcon("images/tomato.png")) self.pomodoro_limit = POMODORO_TIME self.short_break_limit = SHORT_BREAK_TIME self.long_break_limit = LONG_BREAK_TIME self.setupTabsAndWidgets() # Variables related to the current tabs and widgets displayed in the GUI’s window self.current_tab_selected = 0 self.current_start_button = self.pomodoro_start_button self.current_stop_button = self.pomodoro_stop_button self.current_reset_button = self.pomodoro_reset_button self.current_time_limit = self.pomodoro_limit self.current_lcd = self.pomodoro_lcd # Variables related to user's current task self.task_is_set = False self.number_of_tasks = 0 self.task_complete_counter = 0 # Create timer object self.timer = QTimer(self) self.timer.timeout.connect(self.updateTimer) self.show() def setupTabsAndWidgets(self): """Set up the tab bar for the different pomodoro stages: pomodoro, short break, long break.""" # Create the tab bar and the QWidgets (containers) for each tab self.tab_bar = QTabWidget(self) self.pomodoro_tab = QWidget() self.pomodoro_tab.setObjectName("Pomodoro") self.short_break_tab = QWidget() self.short_break_tab.setObjectName("ShortBreak") self.long_break_tab = QWidget() self.long_break_tab.setObjectName("LongBreak") self.tab_bar.addTab(self.pomodoro_tab, "Pomodoro") self.tab_bar.addTab(self.short_break_tab, "Short Break") self.tab_bar.addTab(self.long_break_tab, "Long Break") self.tab_bar.currentChanged.connect(self.tabsSwitched) # Call the functions that contain the widgets for each tab self.pomodoroTab() self.shortBreakTab() self.longBreakTab() # Create the line edit and button widgets and layout for Pomodoro Taskbar self.enter_task_lineedit = QLineEdit() self.enter_task_lineedit.setClearButtonEnabled(True) self.enter_task_lineedit.setPlaceholderText("Enter Your Current Task") confirm_task_button = QPushButton(QIcon("images/plus.png"), None) confirm_task_button.setObjectName("ConfirmButton") confirm_task_button.clicked.connect(self.addTaskToTaskbar) task_entry_h_box = QHBoxLayout() task_entry_h_box.addWidget(self.enter_task_lineedit) task_entry_h_box.addWidget(confirm_task_button) self.tasks_v_box = QVBoxLayout() task_v_box = QVBoxLayout() task_v_box.addLayout(task_entry_h_box) task_v_box.addLayout(self.tasks_v_box) # Container for taskbar task_bar_gb = QGroupBox("Tasks") task_bar_gb.setLayout(task_v_box) # Create and set layout for the main window main_v_box = QVBoxLayout() main_v_box.addWidget(self.tab_bar) main_v_box.addWidget(task_bar_gb) self.setLayout(main_v_box) def pomodoroTab(self): """Set up the Pomodoro tab, widgets and layout.""" # Convert starting time to display on timer start_time = self.calculateDisplayTime(self.pomodoro_limit) self.pomodoro_lcd = QLCDNumber() self.pomodoro_lcd.setObjectName("PomodoroLCD") self.pomodoro_lcd.setSegmentStyle(QLCDNumber.Filled) self.pomodoro_lcd.display(start_time) self.pomodoro_start_button = QPushButton("Start") self.pomodoro_start_button.clicked.connect(self.startCountDown) self.pomodoro_stop_button = QPushButton("Stop") self.pomodoro_stop_button.clicked.connect(self.stopCountDown) self.pomodoro_reset_button = QPushButton("Reset") self.pomodoro_reset_button.clicked.connect(self.resetCountDown) button_h_box = QHBoxLayout() # Horizontal layout for buttons button_h_box.addWidget(self.pomodoro_start_button) button_h_box.addWidget(self.pomodoro_stop_button) button_h_box.addWidget(self.pomodoro_reset_button) # Create and set layout for the pomodoro tab v_box = QVBoxLayout() v_box.addWidget(self.pomodoro_lcd) v_box.addLayout(button_h_box) self.pomodoro_tab.setLayout(v_box) def shortBreakTab(self): """Set up the short break tab, widgets and layout.""" # Convert starting time to display on timer start_time = self.calculateDisplayTime(self.short_break_limit) self.short_break_lcd = QLCDNumber() self.short_break_lcd.setObjectName("ShortLCD") self.short_break_lcd.setSegmentStyle(QLCDNumber.Filled) self.short_break_lcd.display(start_time) self.short_start_button = QPushButton("Start") self.short_start_button.clicked.connect(self.startCountDown) self.short_stop_button = QPushButton("Stop") self.short_stop_button.clicked.connect(self.stopCountDown) self.short_reset_button = QPushButton("Reset") self.short_reset_button.clicked.connect(self.resetCountDown) button_h_box = QHBoxLayout() # Horizontal layout for buttons button_h_box.addWidget(self.short_start_button) button_h_box.addWidget(self.short_stop_button) button_h_box.addWidget(self.short_reset_button) # Create and set layout for the short break tab v_box = QVBoxLayout() v_box.addWidget(self.short_break_lcd) v_box.addLayout(button_h_box) self.short_break_tab.setLayout(v_box) def longBreakTab(self): """Set up the long break tab, widgets and layout.""" # Convert starting time to display on timer start_time = self.calculateDisplayTime(self.long_break_limit) self.long_break_lcd = QLCDNumber() self.long_break_lcd.setObjectName("LongLCD") self.long_break_lcd.setSegmentStyle(QLCDNumber.Filled) self.long_break_lcd.display(start_time) self.long_start_button = QPushButton("Start") self.long_start_button.clicked.connect(self.startCountDown) self.long_stop_button = QPushButton("Stop") self.long_stop_button.clicked.connect(self.stopCountDown) self.long_reset_button = QPushButton("Reset") self.long_reset_button.clicked.connect(self.resetCountDown) button_h_box = QHBoxLayout() # Horizontal layout for buttons button_h_box.addWidget(self.long_start_button) button_h_box.addWidget(self.long_stop_button) button_h_box.addWidget(self.long_reset_button) # Create and set layout for the long break tab v_box = QVBoxLayout() v_box.addWidget(self.long_break_lcd) v_box.addLayout(button_h_box) self.long_break_tab.setLayout(v_box) def startCountDown(self): """Starts the timer. If the current tab's time is 00:00, reset the time if user pushes the start button.""" self.current_start_button.setEnabled(False) # Used to reset counter_label if user has already has completed four pomodoro cycles if self.task_is_set == True and self.task_complete_counter == 0: self.counter_label.setText("{}/4".format( self.task_complete_counter)) remaining_time = self.calculateDisplayTime(self.current_time_limit) if remaining_time == "00:00": self.resetCountDown() self.timer.start(1000) else: self.timer.start(1000) def stopCountDown(self): """If the timer is already running, then stop the timer.""" if self.timer.isActive() != False: self.timer.stop() self.current_start_button.setEnabled(True) def resetCountDown(self): """Resets the time for the current tab when the reset button is selected.""" self.stopCountDown() # Stop countdown if timer is running # Reset time for currently selected tab if self.current_tab_selected == 0: # Pomodoro tab self.pomodoro_limit = POMODORO_TIME self.current_time_limit = self.pomodoro_limit reset_time = self.calculateDisplayTime(self.current_time_limit) elif self.current_tab_selected == 1: # Short break tab self.short_break_limit = SHORT_BREAK_TIME self.current_time_limit = self.short_break_limit reset_time = self.calculateDisplayTime(self.current_time_limit) elif self.current_tab_selected == 2: # Long break tab self.long_break_limit = LONG_BREAK_TIME self.current_time_limit = self.long_break_limit reset_time = self.calculateDisplayTime(self.current_time_limit) self.current_lcd.display(reset_time) def updateTimer(self): """Updates the timer and the current QLCDNumber widget. Also, update the task counter if a task is set.""" remaining_time = self.calculateDisplayTime(self.current_time_limit) if remaining_time == "00:00": self.stopCountDown() self.current_lcd.display(remaining_time) if self.current_tab_selected == 0 and self.task_is_set == True: self.task_complete_counter += 1 if self.task_complete_counter == 4: self.counter_label.setText( "Time for a long break. {}/4".format( self.task_complete_counter)) self.task_complete_counter = 0 elif self.task_complete_counter < 4: self.counter_label.setText("{}/4".format( self.task_complete_counter)) else: # Update the current timer by decreasing the current running time by one second self.current_time_limit -= 1000 self.current_lcd.display(remaining_time) def tabsSwitched(self, index): """Depending upon which tab the user is currently looking at, the information for that tab needs to be updated. This function updates the different variables that keep track of the timer, buttons, lcds and other widgets, and updates them accordingly.""" self.current_tab_selected = index self.stopCountDown() # Reset variables, time and widgets depending upon which tab is the current_tab_selected if self.current_tab_selected == 0: # Pomodoro tab self.current_start_button = self.pomodoro_start_button self.current_stop_button = self.pomodoro_stop_button self.current_reset_button = self.pomodoro_reset_button self.pomodoro_limit = POMODORO_TIME self.current_time_limit = self.pomodoro_limit reset_time = self.calculateDisplayTime(self.current_time_limit) self.current_lcd = self.pomodoro_lcd self.current_lcd.display(reset_time) elif self.current_tab_selected == 1: # Short break tab self.current_start_button = self.short_start_button self.current_stop_button = self.short_stop_button self.current_reset_button = self.short_reset_button self.short_break_limit = SHORT_BREAK_TIME self.current_time_limit = self.short_break_limit reset_time = self.calculateDisplayTime(self.current_time_limit) self.current_lcd = self.short_break_lcd self.current_lcd.display(reset_time) elif self.current_tab_selected == 2: # Long break tab self.current_start_button = self.long_start_button self.current_stop_button = self.long_stop_button self.current_reset_button = self.long_reset_button self.long_break_limit = LONG_BREAK_TIME self.current_time_limit = self.long_break_limit reset_time = self.calculateDisplayTime(self.current_time_limit) self.current_lcd = self.long_break_lcd self.current_lcd.display(reset_time) def addTaskToTaskbar(self): """When the user clicks plus button, the widgets for the new task will be added to the task bar. Only one task is allowed to be entered at a time.""" text = self.enter_task_lineedit.text() self.enter_task_lineedit.clear() # Change number_of_tasks if you want to add more tasks to the task bar if text != "" and self.number_of_tasks != 1: self.enter_task_lineedit.setReadOnly(True) self.task_is_set = True self.new_task = QLabel(text) self.counter_label = QLabel("{}/4".format( self.task_complete_counter)) self.counter_label.setAlignment(Qt.AlignRight) self.cancel_task_button = QPushButton(QIcon("images/minus.png"), None) self.cancel_task_button.setMaximumWidth(24) self.cancel_task_button.clicked.connect(self.clearCurrentTask) self.new_task_h_box = QHBoxLayout() self.new_task_h_box.addWidget(self.new_task) self.new_task_h_box.addWidget(self.counter_label) self.new_task_h_box.addWidget(self.cancel_task_button) self.tasks_v_box.addLayout(self.new_task_h_box) self.number_of_tasks += 1 def clearCurrentTask(self): """Delete the current task, and reset variables and widgets related to tasks.""" # Remove items from parent widget by setting the argument value in # setParent() to None self.new_task.setParent(None) self.counter_label.setParent(None) self.cancel_task_button.setParent(None) self.number_of_tasks -= 1 self.task_is_set = False self.task_complete_counter = 0 self.enter_task_lineedit.setReadOnly(False) def convertTotalTime(self, time_in_milli): """Convert time to milliseconds.""" minutes = (time_in_milli / (1000 * 60)) % 60 seconds = (time_in_milli / 1000) % 60 return int(minutes), int(seconds) def calculateDisplayTime(self, time): """Calculate the time that should be displayed in the QLCDNumber widget.""" minutes, seconds = self.convertTotalTime(time) amount_of_time = "{:02d}:{:02d}".format(minutes, seconds) return amount_of_time
class ControlWindow(QWidget): #Initialize the class (actually creating a initUI method and calling that, or just put all that code in here) def __init__(self): super().__init__() self.initUI() def initUI(self): #Primary screen - Control Window Screen (laptop) - Screen0 will always be primary screen (only screen on RPi) self.sizeScreen0 = QDesktopWidget().screenGeometry( 0) #use this function to get the screen geometry print(' Screen 0 size : ' + str(self.sizeScreen0.height()) + 'x' + str(self.sizeScreen0.width())) #Print out the screen size for debugging issues, will display in terminal self.setGeometry( 0, 0, self.sizeScreen0.width(), self.sizeScreen0.height()) #set window screen dimensions self.setWindowTitle( 'Control Panel') #name window screen (displayed at top of window) #Create a button - same format for any button you want to make self.Zero_button = QPushButton( self) #declare the button instance from the QPushbutton class # set the button position and size .setgeometry(Qrect(X position, Y position, button width, button height)) position is from upper left of button # The button position and dimensions are relative to the screen size. You can type in absolute numbers instead if you want and are sure of screensize self.Zero_button.setGeometry( QRect(self.sizeScreen0.width() * 0.015, self.sizeScreen0.height() * 0.02, self.sizeScreen0.width() * 0.165, self.sizeScreen0.height() * 0.12)) self.Zero_button.setObjectName("Zero_button") #name the button self.Zero_button.setStyleSheet( "font: bold 14px; background-color: rgb(5,176,36);") self.Weight_button = QPushButton(self) self.Weight_button.setGeometry( QRect(self.sizeScreen0.width() * 0.2, self.sizeScreen0.height() * 0.02, self.sizeScreen0.width() * 0.165, self.sizeScreen0.height() * 0.12)) self.Weight_button.setObjectName("Weight_button") self.Weight_button.setStyleSheet( "font: bold 14px; background-color: rgb(5,176,36);") self.Estop_button = QPushButton(self) self.Estop_button.setGeometry( QRect(self.sizeScreen0.width() * 0.74, self.sizeScreen0.height() * 0.02, self.sizeScreen0.width() * 0.2, self.sizeScreen0.height() * 0.12)) self.Estop_button.setObjectName("Estop_button") self.Estop_button.setStyleSheet( "font: bold 14px; background-color: red;") #Create another button (same process as before) self.Close_button = QPushButton(self) self.Close_button.setGeometry( QRect(self.sizeScreen0.width() * 0.95, self.sizeScreen0.height() * 0.01, self.sizeScreen0.width() * 0.04, self.sizeScreen0.height() * 0.06)) self.Close_button.setObjectName("X_button") self.Close_button.setStyleSheet( "font: bold 18px; background-color: rgb(5,176,36);") self.Top_label = QLabel(self) self.Top_label.setGeometry( QRect(self.sizeScreen0.width() * 0.1, self.sizeScreen0.height() * 0.125, self.sizeScreen0.width() * 0.3, self.sizeScreen0.height() * 0.3)) self.Top_label.setStyleSheet("font: bold 20px;") self.Middle_label = QLabel(self) self.Middle_label.setGeometry( QRect(self.sizeScreen0.width() * 0.1, self.sizeScreen0.height() * 0.325, self.sizeScreen0.width() * 0.3, self.sizeScreen0.height() * 0.3)) self.Middle_label.setStyleSheet("font: bold 20px;") self.Bottom_label = QLabel(self) self.Bottom_label.setGeometry( QRect(self.sizeScreen0.width() * 0.1, self.sizeScreen0.height() * 0.525, self.sizeScreen0.width() * 0.3, self.sizeScreen0.height() * 0.3)) self.Bottom_label.setStyleSheet("font: bold 20px;") self.Progress_label = QLabel(self) self.Progress_label.setGeometry( QRect(self.sizeScreen0.width() * 0.1, self.sizeScreen0.height() * 0.65, self.sizeScreen0.width() * 0.3, self.sizeScreen0.height() * 0.3)) self.Progress_label.setStyleSheet("font: bold 15px;") self.Weight_label = QLabel(self) self.Weight_label.setGeometry( QRect(self.sizeScreen0.width() * 0.355, self.sizeScreen0.height() * 0.05, self.sizeScreen0.width() * 0.3, self.sizeScreen0.height() * 0.3)) self.Weight_label.setStyleSheet("font: bold 15px;") self.Moisture_label = QLabel(self) self.Moisture_label.setGeometry( QRect(self.sizeScreen0.width() * 0.6125, self.sizeScreen0.height() * 0.125, self.sizeScreen0.width() * 0.2, self.sizeScreen0.height() * 0.15)) self.Moisture_label.setStyleSheet("font: bold 15px;") self.TopTemp_label = QLabel(self) self.TopTemp_label.setGeometry( QRect(self.sizeScreen0.width() * 0.4, self.sizeScreen0.height() * 0.03, self.sizeScreen0.width() * 0.22, self.sizeScreen0.height() * 0.05)) self.TopTemp_label.setStyleSheet("font: bold 15px;") self.BottomTemp_label = QLabel(self) self.BottomTemp_label.setGeometry( QRect(self.sizeScreen0.width() * 0.4, self.sizeScreen0.height() * 0.105, self.sizeScreen0.width() * 0.22, self.sizeScreen0.height() * 0.05)) self.BottomTemp_label.setStyleSheet("font: bold 15px;") #Create an LCD display widget to show numbers self.LCDdisplay = QLCDNumber( self) #Create the instance from the QLCDNumber class #Set the position and dimensions just like was done for the buttons self.LCDdisplay.setGeometry( QRect(self.sizeScreen0.width() * 0.935, self.sizeScreen0.height() * 0.8, self.sizeScreen0.width() * 0.05, self.sizeScreen0.height() * 0.1)) self.LCDdisplay.setObjectName("Counter") #Name it self.LCDdisplay.setStyleSheet("background-color:white;") self.TopTempdisplay = QLCDNumber(self) self.TopTempdisplay.setGeometry( QRect(self.sizeScreen0.width() * 0.62, self.sizeScreen0.height() * 0.025, self.sizeScreen0.width() * 0.1, self.sizeScreen0.height() * 0.06)) self.TopTempdisplay.setObjectName("Top Temperature") self.TopTempdisplay.setStyleSheet("background-color:white;") self.BottomTempdisplay = QLCDNumber(self) self.BottomTempdisplay.setGeometry( QRect(self.sizeScreen0.width() * 0.62, self.sizeScreen0.height() * 0.1, self.sizeScreen0.width() * 0.1, self.sizeScreen0.height() * 0.06)) self.BottomTempdisplay.setObjectName("Bottom Temperature") self.BottomTempdisplay.setStyleSheet("background-color:white;") self.TopWeightdisplay = QLCDNumber(self) self.TopWeightdisplay.setGeometry( QRect(self.sizeScreen0.width() * 0.3, self.sizeScreen0.height() * 0.22, self.sizeScreen0.width() * 0.2, self.sizeScreen0.height() * 0.12)) self.TopWeightdisplay.setObjectName("Top Weight") self.TopWeightdisplay.setStyleSheet("background-color:white;") self.TopMoisturedisplay = QLCDNumber(self) self.TopMoisturedisplay.setGeometry( QRect(self.sizeScreen0.width() * 0.6, self.sizeScreen0.height() * 0.22, self.sizeScreen0.width() * 0.2, self.sizeScreen0.height() * 0.12)) self.TopMoisturedisplay.setObjectName("Top Moisture") self.TopMoisturedisplay.setStyleSheet("background-color:white;") self.MiddleWeightdisplay = QLCDNumber(self) self.MiddleWeightdisplay.setGeometry( QRect(self.sizeScreen0.width() * 0.3, self.sizeScreen0.height() * 0.42, self.sizeScreen0.width() * 0.2, self.sizeScreen0.height() * 0.12)) self.MiddleWeightdisplay.setObjectName("Middle Weight") self.MiddleWeightdisplay.setStyleSheet("background-color:white;") self.MiddleMoisturedisplay = QLCDNumber(self) self.MiddleMoisturedisplay.setGeometry( QRect(self.sizeScreen0.width() * 0.6, self.sizeScreen0.height() * 0.42, self.sizeScreen0.width() * 0.2, self.sizeScreen0.height() * 0.12)) self.MiddleMoisturedisplay.setObjectName("Middle Moisture") self.MiddleMoisturedisplay.setStyleSheet("background-color:white;") self.BottomWeightdisplay = QLCDNumber(self) self.BottomWeightdisplay.setGeometry( QRect(self.sizeScreen0.width() * 0.3, self.sizeScreen0.height() * 0.62, self.sizeScreen0.width() * 0.2, self.sizeScreen0.height() * 0.12)) self.BottomWeightdisplay.setObjectName("Bottom Weight") self.BottomWeightdisplay.setStyleSheet("background-color:white;") self.BottomMoisturedisplay = QLCDNumber(self) self.BottomMoisturedisplay.setGeometry( QRect(self.sizeScreen0.width() * 0.6, self.sizeScreen0.height() * 0.62, self.sizeScreen0.width() * 0.2, self.sizeScreen0.height() * 0.12)) self.BottomMoisturedisplay.setObjectName("Bottom Moisture") self.BottomMoisturedisplay.setStyleSheet("background-color:white;") self.Progress_bar = QProgressBar(self) self.Progress_bar.setGeometry( QRect(self.sizeScreen0.width() * 0.1, self.sizeScreen0.height() * 0.83, self.sizeScreen0.width() * 0.7, self.sizeScreen0.height() * 0.04)) self.Progress_bar.setRange(0, 100) #loop = 60 #self.Progress_bar.setValue(loop) self.Progress_bar.setStyleSheet( "font: bold 15px; text-align: center; border: 1px solid grey;") #Not exactly sure what this does, but it is needed to put a name label on the buttons _translate = QCoreApplication.translate #Name the Close Button label self.Close_button.setText(_translate("ControlWindow", "X")) #Name the calibrate button label self.Zero_button.setText(_translate("ControlWindow", "Zero All Scales")) self.Weight_button.setText( _translate("ControlWindow", "Set Initial Weights")) self.Estop_button.setText( _translate("ControlWindow", "Emergency Shutoff")) self.Top_label.setText(_translate("ControlWindow", "Top Shelf:")) self.Middle_label.setText(_translate("ControlWindow", "Middle Shelf:")) self.Bottom_label.setText(_translate("ControlWindow", "Bottom Shelf:")) self.Progress_label.setText( _translate("ControlWindow", "Drying Progress:")) self.Weight_label.setText(_translate("ControlWindow", "Weight (lbs):")) self.Moisture_label.setText( _translate("ControlWindow", "Moisture Percent (%):")) self.TopTemp_label.setText( _translate("ControlWindow", "Top Temperature (F):")) self.BottomTemp_label.setText( _translate("ControlWindow", "Bottom Temperature (F):")) #This sets the Close button's action when you click on it, in this case it will run the method "CloseUp" which is below self.Close_button.clicked.connect(self.CloseUp) #Show the screen, not sure it is really needed though self.show #Like before, not exactly sure what it is doing, but needed to create and show the button naming labels def retranslateUi(self, TestDisplay): _translate = QCoreApplication.translate TestDisplay.setWindowTitle(_translate("MainGroWin", "MainWindow")) self.Disconnect_button.setText(_translate("MainGroWin", "Disconnect")) #The function that will close the window and program when you click on the "Close" button def CloseUp( self ): #create method inside the ControlWindow Class (belongs to the ControlWindow class) # print('Closed') #Used for debugging in terminal # Maximize the window, you can use the windowstate function to minimize, maximize and manipulate the window self.setWindowState(Qt.WindowMaximized) # Close up the window and shut it down self.close() #Function to update the LED value inside the counting display def updateLED(self, LEDnum): #update the LED value self.LEDvalue = LEDnum #rename the variable for clarity self.LCDdisplay.display( self.LEDvalue ) #use the display method of the LCDdisplay inhereited class to update the LED def updateProgressBar(self, ProgressNum): self.ProgressValue = ProgressNum self.Progress_bar.setValue(self.ProgressValue) def updateTopTemp(self, TopTemp): self.TopTempValue = TopTemp self.TopTempdisplay.display(self.TopTempValue)
class ControlWindow(QWidget): #Initialize the class (actually creating a initUI method and calling that, or just put all that code in here) def __init__(self): super().__init__() self.initUI() def initUI(self): #Primary screen - Control Window Screen (laptop) - Screen0 will always be primary screen (only screen on RPi) self.sizeScreen0 = QDesktopWidget().screenGeometry(0) #use this function to get the screen geometry print(' Screen 0 size : ' + str(self.sizeScreen0.height()) + 'x' + str(self.sizeScreen0.width())) #Print out the screen size for debugging issues, will display in terminal self.setGeometry(0, 0, self.sizeScreen0.width(), self.sizeScreen0.height()) #set window screen dimensions self.setWindowTitle('Control Panel') #name window screen (displayed at top of window) #Create a button - same format for any button you want to make self.Zero_button = QPushButton(self) #declare the button instance from the QPushbutton class # set the button position and size .setgeometry(Qrect(X position, Y position, button width, button height)) position is from upper left of button # The button position and dimensions are relative to the screen size. You can type in absolute numbers instead if you want and are sure of screensize self.Zero_button.setGeometry(QRect(self.sizeScreen0.width() * 0.015, self.sizeScreen0.height() * 0.02, self.sizeScreen0.width() * 0.165, self.sizeScreen0.height() * 0.12)) self.Zero_button.setObjectName("Zero_button") #name the button self.Zero_button.setStyleSheet("font: bold 14px; background-color: rgb(5,176,36);") self.Weight_button = QPushButton(self) self.Weight_button.setGeometry(QRect(self.sizeScreen0.width() * 0.2, self.sizeScreen0.height() * 0.02, self.sizeScreen0.width() * 0.165, self.sizeScreen0.height() * 0.12)) self.Weight_button.setObjectName("Weight_button") self.Weight_button.setStyleSheet("font: bold 14px; background-color: rgb(5,176,36);") self.Estop_button = QPushButton(self) self.Estop_button.setGeometry(QRect(self.sizeScreen0.width() * 0.74, self.sizeScreen0.height() * 0.02, self.sizeScreen0.width() * 0.2, self.sizeScreen0.height() * 0.12)) self.Estop_button.setObjectName("Estop_button") self.Estop_button.setStyleSheet("font: bold 14px; background-color: red;") self.Start_button = QPushButton(self) self.Start_button.setGeometry(QRect(self.sizeScreen0.width() * 0.825, self.sizeScreen0.height() * 0.61, self.sizeScreen0.width() * 0.15, self.sizeScreen0.height() * 0.15)) self.Start_button.setObjectName("Start_button") self.Start_button.setStyleSheet("font: bold 14px; background-color: rgb(5,176,36);") #Create another button (same process as before) self.Close_button = QPushButton(self) self.Close_button.setGeometry(QRect(self.sizeScreen0.width() * 0.95, self.sizeScreen0.height() * 0.01, self.sizeScreen0.width() * 0.04, self.sizeScreen0.height() * 0.06)) self.Close_button.setObjectName("X_button") self.Close_button.setStyleSheet("font: bold 18px; background-color: rgb(5,176,36);") #Creates GUI user inputs self.InitialSampleWeight = QLineEdit(self) self.InitialSampleWeight.setGeometry(QRect(self.sizeScreen0.width() * 0.2, self.sizeScreen0.height() * 0.8, self.sizeScreen0.width() * 0.09, self.sizeScreen0.height() * 0.1)) self.InitialSampleWeight.setStyleSheet("font: bold 20px;") self.InitialSampleWeight.setMaxLength(5) self.DryMatterWeight = QLineEdit(self) self.DryMatterWeight.setGeometry(QRect(self.sizeScreen0.width() * 0.5, self.sizeScreen0.height() * 0.8, self.sizeScreen0.width() * 0.09, self.sizeScreen0.height() * 0.1)) self.DryMatterWeight.setStyleSheet("font: bold 20px;") self.DryMatterWeight.setMaxLength(5) self.TargetWeightPercent = QLineEdit(self) self.TargetWeightPercent.setGeometry(QRect(self.sizeScreen0.width() * 0.8, self.sizeScreen0.height() * 0.8, self.sizeScreen0.width() * 0.09, self.sizeScreen0.height() * 0.1)) self.TargetWeightPercent.setStyleSheet("font: bold 20px;") self.TargetWeightPercent.setMaxLength(5) self.EStopTemp = QLineEdit(self) self.EStopTemp.setGeometry(QRect(self.sizeScreen0.width() * 0.86, self.sizeScreen0.height() * 0.3, self.sizeScreen0.width() * 0.09, self.sizeScreen0.height() * 0.1)) self.EStopTemp.setStyleSheet("font: bold 20px;") self.EStopTemp.setMaxLength(5) self.EStopTemp_label = QLabel(self) self.EStopTemp_label.setGeometry(QRect(self.sizeScreen0.width() * 0.815, self.sizeScreen0.height() * 0.20, self.sizeScreen0.width() * 0.3, self.sizeScreen0.height() * 0.1)) self.EStopTemp_label.setStyleSheet("font: bold 15px;") self.SampleWeight_label = QLabel(self) self.SampleWeight_label.setGeometry(QRect(self.sizeScreen0.width() * 0.05, self.sizeScreen0.height() * 0.8, self.sizeScreen0.width() * 0.15, self.sizeScreen0.height() * 0.1)) self.SampleWeight_label.setStyleSheet("font: bold 15px;") self.DryMatter_label = QLabel(self) self.DryMatter_label.setGeometry(QRect(self.sizeScreen0.width() * 0.37, self.sizeScreen0.height() * 0.8, self.sizeScreen0.width() * 0.13, self.sizeScreen0.height() * 0.1)) self.DryMatter_label.setStyleSheet("font: bold 15px;") self.TargetPercent_label = QLabel(self) self.TargetPercent_label.setGeometry(QRect(self.sizeScreen0.width() * 0.63, self.sizeScreen0.height() * 0.8, self.sizeScreen0.width() * 0.165, self.sizeScreen0.height() * 0.1)) self.TargetPercent_label.setStyleSheet("font: bold 15px;") self.Top_label = QLabel(self) self.Top_label.setGeometry(QRect(self.sizeScreen0.width() * 0.1, self.sizeScreen0.height() * 0.125, self.sizeScreen0.width() * 0.3, self.sizeScreen0.height() * 0.3)) self.Top_label.setStyleSheet("font: bold 20px;") self.Middle_label = QLabel(self) self.Middle_label.setGeometry(QRect(self.sizeScreen0.width() * 0.1, self.sizeScreen0.height() * 0.325, self.sizeScreen0.width() * 0.3, self.sizeScreen0.height() * 0.3)) self.Middle_label.setStyleSheet("font: bold 20px;") self.Bottom_label = QLabel(self) self.Bottom_label.setGeometry(QRect(self.sizeScreen0.width() * 0.1, self.sizeScreen0.height() * 0.525, self.sizeScreen0.width() * 0.3, self.sizeScreen0.height() * 0.3)) self.Bottom_label.setStyleSheet("font: bold 20px;") # self.Progress_label = QLabel(self) # self.Progress_label.setGeometry(QRect(self.sizeScreen0.width() * 0.1, self.sizeScreen0.height() * 0.65, self.sizeScreen0.width() * 0.3, self.sizeScreen0.height() * 0.3)) # self.Progress_label.setStyleSheet("font: bold 15px;") self.Weight_label = QLabel(self) self.Weight_label.setGeometry(QRect(self.sizeScreen0.width() * 0.34, self.sizeScreen0.height() * 0.05, self.sizeScreen0.width() * 0.3, self.sizeScreen0.height() * 0.3)) self.Weight_label.setStyleSheet("font: bold 15px;") self.Moisture_label = QLabel(self) self.Moisture_label.setGeometry(QRect(self.sizeScreen0.width() * 0.59, self.sizeScreen0.height() * 0.125, self.sizeScreen0.width() * 0.23, self.sizeScreen0.height() * 0.15)) self.Moisture_label.setStyleSheet("font: bold 15px;") self.TopTemp_label = QLabel(self) self.TopTemp_label.setGeometry(QRect(self.sizeScreen0.width() * 0.41, self.sizeScreen0.height() * 0.03, self.sizeScreen0.width() * 0.22, self.sizeScreen0.height() * 0.05)) self.TopTemp_label.setStyleSheet("font: bold 15px;") self.BottomTemp_label = QLabel(self) self.BottomTemp_label.setGeometry(QRect(self.sizeScreen0.width() * 0.41, self.sizeScreen0.height() * 0.105, self.sizeScreen0.width() * 0.25, self.sizeScreen0.height() * 0.05)) self.BottomTemp_label.setStyleSheet("font: bold 15px;") #Create an LCD display widget to show numbers self.LCDdisplay = QLCDNumber(self) #Create the instance from the QLCDNumber class #Set the position and dimensions just like was done for the buttons self.LCDdisplay.setGeometry(QRect(self.sizeScreen0.width() * 0.935, self.sizeScreen0.height() * 0.8, self.sizeScreen0.width() * 0.06, self.sizeScreen0.height() * 0.12)) self.LCDdisplay.setObjectName("Counter") #Name it self.LCDdisplay.setStyleSheet("background-color:white;") self.TopTempdisplay = QLCDNumber(self) self.TopTempdisplay.setGeometry(QRect(self.sizeScreen0.width() * 0.62, self.sizeScreen0.height() * 0.025, self.sizeScreen0.width() * 0.1, self.sizeScreen0.height() * 0.06)) self.TopTempdisplay.setObjectName("Top Temperature") self.TopTempdisplay.setStyleSheet("background-color:white;") self.BottomTempdisplay = QLCDNumber(self) self.BottomTempdisplay.setGeometry(QRect(self.sizeScreen0.width() * 0.62, self.sizeScreen0.height() * 0.1, self.sizeScreen0.width() * 0.1, self.sizeScreen0.height() * 0.06)) self.BottomTempdisplay.setObjectName("Bottom Temperature") self.BottomTempdisplay.setStyleSheet("background-color:white;") self.TopWeightdisplay = QLCDNumber(self) self.TopWeightdisplay.setGeometry(QRect(self.sizeScreen0.width() * 0.3, self.sizeScreen0.height() * 0.22, self.sizeScreen0.width() * 0.2, self.sizeScreen0.height() * 0.12)) self.TopWeightdisplay.setObjectName("Top Weight") self.TopWeightdisplay.setStyleSheet("background-color:white;") self.TopMoisturedisplay = QLCDNumber(self) self.TopMoisturedisplay.setGeometry(QRect(self.sizeScreen0.width() * 0.6, self.sizeScreen0.height() * 0.22, self.sizeScreen0.width() * 0.2, self.sizeScreen0.height() * 0.12)) self.TopMoisturedisplay.setObjectName("Top Moisture") self.TopMoisturedisplay.setStyleSheet("background-color:white;") self.MiddleWeightdisplay = QLCDNumber(self) self.MiddleWeightdisplay.setGeometry(QRect(self.sizeScreen0.width() * 0.3, self.sizeScreen0.height() * 0.42, self.sizeScreen0.width() * 0.2, self.sizeScreen0.height() * 0.12)) self.MiddleWeightdisplay.setObjectName("Middle Weight") self.MiddleWeightdisplay.setStyleSheet("background-color:white;") self.MiddleMoisturedisplay = QLCDNumber(self) self.MiddleMoisturedisplay.setGeometry(QRect(self.sizeScreen0.width() * 0.6, self.sizeScreen0.height() * 0.42, self.sizeScreen0.width() * 0.2, self.sizeScreen0.height() * 0.12)) self.MiddleMoisturedisplay.setObjectName("Middle Moisture") self.MiddleMoisturedisplay.setStyleSheet("background-color:white;") self.BottomWeightdisplay = QLCDNumber(self) self.BottomWeightdisplay.setGeometry(QRect(self.sizeScreen0.width() * 0.3, self.sizeScreen0.height() * 0.62, self.sizeScreen0.width() * 0.2, self.sizeScreen0.height() * 0.12)) self.BottomWeightdisplay.setObjectName("Bottom Weight") self.BottomWeightdisplay.setStyleSheet("background-color:white;") self.BottomMoisturedisplay = QLCDNumber(self) self.BottomMoisturedisplay.setGeometry(QRect(self.sizeScreen0.width() * 0.6, self.sizeScreen0.height() * 0.62, self.sizeScreen0.width() * 0.2, self.sizeScreen0.height() * 0.12)) self.BottomMoisturedisplay.setObjectName("Bottom Moisture") self.BottomMoisturedisplay.setStyleSheet("background-color:white;") # self.Progress_bar = QProgressBar(self) # self.Progress_bar.setGeometry(QRect(self.sizeScreen0.width() * 0.1, self.sizeScreen0.height() * 0.83, self.sizeScreen0.width() * 0.7, self.sizeScreen0.height() * 0.04)) # self.Progress_bar.setRange(0,100) # #loop = 60 # #self.Progress_bar.setValue(loop) # self.Progress_bar.setStyleSheet("font: bold 15px; text-align: center; border: 1px solid grey;") #Not exactly sure what this does, but it is needed to put a name label on the buttons _translate = QCoreApplication.translate #Name the Close Button label self.Close_button.setText(_translate("ControlWindow", "X")) #Name the calibrate button label self.Zero_button.setText(_translate("ControlWindow", "Zero All Scales")) self.Weight_button.setText(_translate("ControlWindow", "Set Initial"+ "\n" +"Weights")) self.Estop_button.setText(_translate("ControlWindow", "Emergency" + "\n" + "Shutoff")) self.Start_button.setText(_translate("ControlWindow", "Start/Resume")) self.Top_label.setText(_translate("ControlWindow", "Top Shelf:")) self.Middle_label.setText(_translate("ControlWindow", "Middle Shelf:")) self.Bottom_label.setText(_translate("ControlWindow", "Bottom Shelf:")) #self.Progress_label.setText(_translate("ControlWindow", "Drying Progress:")) self.Weight_label.setText(_translate("ControlWindow", "Weight (lbs):")) self.Moisture_label.setText(_translate("ControlWindow", "Moisture Percent (%):")) self.TopTemp_label.setText(_translate("ControlWindow", "Temperature 1 (F):")) self.BottomTemp_label.setText(_translate("ControlWindow", "Temperature 2 (F):")) self.SampleWeight_label.setText(_translate("ControlWindow", "Initial Sample"+ "\n" +" Weight (g):")) self.DryMatter_label.setText(_translate("ControlWindow", "Dry Matter"+ "\n" +"Weight (g):")) self.TargetPercent_label.setText(_translate("ControlWindow", "Target Moisture"+ "\n" +" Percent (%):")) self.EStopTemp_label.setText(_translate("ControlWindow", " E-Stop"+ "\n" +"Temperature (F):")) #This sets the Close button's action when you click on it, in this case it will run the method "CloseUp" which is below self.Close_button.clicked.connect(self.CloseUp) #self.Close_button.clicked.connect(GPIOcleanup) #This activates E-stop when E-stop is pressed self.Estop_button.clicked.connect(Eshutoff) #This activates method "startup" when Start/Resume button is pressed self.Start_button.clicked.connect(startup) #Saves input values when start button pressed self.Start_button.clicked.connect(self.getInitialSampleWeight) self.Start_button.clicked.connect(self.getDryMatterWeight) self.Start_button.clicked.connect(self.getTargetWeightPercent) self.Start_button.clicked.connect(self.getEStopTemp) #This activates zeroing of the scales when "Zero" butotn is clicked self.Zero_button.clicked.connect(self.ZeroAllScales) #Records initial values when clicked self.Weight_button.clicked.connect(self.SetInitialWeights) #Show the screen, not sure it is really needed though self.show #Like before, not exactly sure what it is doing, but needed to create and show the button naming labels def retranslateUi(self, TestDisplay): _translate = QCoreApplication.translate TestDisplay.setWindowTitle(_translate("MainGroWin", "MainWindow")) self.Disconnect_button.setText(_translate("MainGroWin", "Disconnect")) #The function that will close the window and program when you click on the "Close" button def CloseUp(self): #create method inside the ControlWindow Class (belongs to the ControlWindow class) # print('Closed') #Used for debugging in terminal # Maximize the window, you can use the windowstate function to minimize, maximize and manipulate the window self.setWindowState(Qt.WindowMaximized) # Close up the window and shut it down self.close() GPIO.cleanup() Eshutoff() def ZeroAllScales(self): #setting offset of scales to current value so that scales are zeroed #REWRITE to create a list that updates every time button is pressed, so that offset is cumulative global zeroTop global zeroMid global zeroBot global listTop global listMid global listBot listTop.append(weightTop) listMid.append(weightMid) listBot.append(weightBot) zeroTop = sum(listTop) zeroMid = sum(listMid) zeroBot = sum(listBot) def SetInitialWeights(self): #saving current weights as "initial weights" when button is pressed global initialWeightTop global initialWeightMid global initialWeightBot initialWeightTop = weightTop initialWeightMid = weightMid initialWeightBot = weightBot #Function to update the LED value inside the counting display def updateLED(self, LEDnum): #update the LED value self.LEDvalue = LEDnum #rename the variable for clarity self.LCDdisplay.display(self.LEDvalue) #use the display method of the LCDdisplay inhereited class to update the LED # def updateProgressBar (self, ProgressNum): # self.ProgressValue = ProgressNum # self.Progress_bar.setValue(self.ProgressValue) def updateTopTemp(self, TopTemp): #method for updating temperature display self.TopTempValue = TopTemp self.TopTempdisplay.display(self.TopTempValue) def updateBotTemp(self, BotTemp): #method for updating temperature display self.BotTempValue = BotTemp self.BottomTempdisplay.display(self.BotTempValue) def updateTopWeight(self, TopWeight): #method for updating weight display self.TopWeightValue = TopWeight self.TopWeightdisplay.display(self.TopWeightValue) def updateMiddleWeight(self, MiddleWeight): #method for updating weight display self.MiddleWeightValue = MiddleWeight self.MiddleWeightdisplay.display(self.MiddleWeightValue) def updateBottomWeight(self, BottomWeight): #method for updating weight display self.BottomWeightValue = BottomWeight self.BottomWeightdisplay.display(self.BottomWeightValue) def updateTopMoistureDisplay(self, TopMoisture): #method for updating moisture display self.TopMoistureValue = TopMoisture self.TopMoisturedisplay.display(self.TopMoistureValue) def updateMiddleMoistureDisplay(self, MiddleMoisture): #method for updating moisture display self.MiddleMoistureValue = MiddleMoisture self.MiddleMoisturedisplay.display(self.MiddleMoistureValue) def updateBottomMoistureDisplay(self, BottomMoisture): #method for updating moisture display self.BottomMoistureValue = BottomMoisture self.BottomMoisturedisplay.display(self.BottomMoistureValue) def getInitialSampleWeight(self): #method for saving the values input in the boxes - made an attempt to convert to int or float as appropriate global initialSampleWeightTemp global initialSampleWeight if self.InitialSampleWeight.text() != "": initialSampleWeightTemp = self.InitialSampleWeight.text() try: initialSampleWeight = float(initialSampleWeightTemp) except: initialSampleWeight = int(initialSampleWeightTemp) def getEStopTemp(self): global EStopTemp global EStopTempTemp if self.EStopTemp.text() != "": EStopTempTemp = self.EStopTemp.text() try: EStopTemp = float(EStopTempTemp) except: EStopTemp = int(EStopTempTemp) def getDryMatterWeight(self): #method for saving the values input in the boxes - made an attempt to convert to int or float as appropriate global dryMatterTemp global dryMatter if self.DryMatterWeight.text() != "": dryMatterTemp = self.DryMatterWeight.text() try: dryMatter = float(dryMatterTemp) except: dryMatter = int(dryMatterTemp) def getTargetWeightPercent(self): #method for saving the values input in the boxes - made an attempt to convert to int or float as appropriate global targetPercentTemp global targetPercent if self.TargetWeightPercent.text() != "": targetPercentTemp = self.TargetWeightPercent.text() try: targetPercent = float(targetPercentTemp) except: targetPercent = int(targetPercentTemp)
class timer(QMainWindow): def __init__(self): super(timer, self).__init__() self.initial_variables() #zd self.init_ui() self.show() def init_ui(self): self.time = QTimer(self) self.time.setInterval(1000) self.time.timeout.connect(self.refresh) self.time.timeout.connect(self.skip_day) #zd self.time_start_up = QTime(0, 0, 0) #正计时的开始时间 self.time_start_fall = QTime(23, 59, 59) #倒计时结束时分秒 self.time_start_data = QDate.currentDate() #倒计时结束年月日 self.time_system = QTimer(self) self.time_system.setInterval(1000) self.time_system.timeout.connect(self.refresh_system) self.time_system.start() self.hour = 0 #暂停前已经记录的时分秒 self.minute = 0 self.second = 0 self.interval = 0 self.time.start() self.init_window() self.init_lcd() self.init_Button() self.init_bar() self.init_label() def init_window(self): self.resize(900, 600) self.setWindowTitle('觅时') self.setWindowIcon(QIcon('./images/others/icon.png')) self.image_file = "./images/background/timg.png" mixer.init() self.sound = mixer.music.load( "./sound/Berliner Philharmoniker.mp3") #默认背景音乐 mixer.music.play(-1, 0.0) def init_bar(self): self.statusBar() menubar = self.menuBar() menubar.setNativeMenuBar(False) background_menu = menubar.addMenu('背景图片') sound_menu = menubar.addMenu('背景音乐') model_menu = menubar.addMenu('窗口模式') self.open_picture_action = QAction('本地图片', self) background_menu.addAction(self.open_picture_action) self.open_picture_action.triggered.connect(self.open_picture) self.open_music_action = QAction('本地音乐', self) self.stop_music_action = QAction('音乐暂停', self) self.continue_music_action = QAction('音乐继续', self) self.start_music_action = QAction('从头播放', self) sound_menu.addAction(self.open_music_action) sound_menu.addAction(self.stop_music_action) sound_menu.addAction(self.continue_music_action) sound_menu.addAction(self.start_music_action) self.open_music_action.triggered.connect(self.open_music) self.stop_music_action.triggered.connect(self.stop_music) self.continue_music_action.triggered.connect(self.continue_music) self.start_music_action.triggered.connect(self.start_music) self.float_action = QAction('悬浮窗', self) self.normal_action = QAction('正常窗口', self) model_menu.addAction(self.float_action) model_menu.addAction(self.normal_action) self.float_action.triggered.connect(self.float) self.normal_action.triggered.connect(self.normal) def open_picture(self): #选择本地图片 self.image_file, _ = QFileDialog.getOpenFileName( self, 'Open file', './images/background', 'Image files (*.jpg *.gif *.png *.jpeg)') self.setAutoFillBackground(True) if path.exists(self.image_file) == False: return palette = QPalette() palette.setBrush( QPalette.Background, QBrush( QPixmap(self.image_file).scaled(self.size(), Qt.IgnoreAspectRatio, Qt.SmoothTransformation))) self.setPalette(palette) def open_music(self): #选择本地音乐 self.music_file, _ = QFileDialog.getOpenFileName( self, 'Open file', './sound', 'Image files (*.mp3 *.wan *.midi)') if path.exists(self.music_file) == False: return mixer.init() self.sound = mixer.music.load(self.music_file) mixer.music.play(-1, 0.0) def stop_music(self): #音乐暂停 mixer.music.pause() def continue_music(self): #音乐继续 mixer.music.unpause() def start_music(self): #音乐从头开始 mixer.music.play() def init_lcd(self): #正计时LCD self.lcd1 = QLCDNumber(self) self.lcd1.setStyleSheet("background: transparent;font-size:50000px") self.lcd1.setObjectName("lcd1") self.lcd1.setDigitCount(12) self.lcd1.setMode(QLCDNumber.Dec) self.lcd1.setSegmentStyle(QLCDNumber.Flat) self.lcd1.setVisible(True) #倒计时LCD self.lcd2 = QLCDNumber(self) self.lcd2.setStyleSheet("background: transparent;font-size:50000px") self.lcd2.setObjectName("lcd2") self.lcd2.setDigitCount(12) self.lcd2.setMode(QLCDNumber.Dec) self.lcd2.setSegmentStyle(QLCDNumber.Flat) self.lcd2.setVisible(False) #系统时间LCD self.lcd3 = QLCDNumber(self) self.lcd3.setStyleSheet( "background: transparent;font-size:50000px;color:rgb(255,255,255)") self.lcd3.setObjectName("lcd3") self.lcd3.setDigitCount(12) self.lcd3.setMode(QLCDNumber.Dec) self.lcd3.setSegmentStyle(QLCDNumber.Flat) def init_label(self): #显示标签 self.label = QLabel("", self) self.label.setVisible(True) self.label.setFixedWidth(500) self.label.setFixedHeight(100) self.setStyleSheet( "QLabel{font-size:30px;font-weight:normal;font-family:Arial;}") self.label.setGeometry(QRect(300, 100, 20, 11)) def float(self): #进入悬浮窗 self.hide() self.resize(550, 60) # self.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint) self.lcd3.setVisible(False) self.splider.setVisible(False) self.label.setVisible(False) #self.setWindowFlags(Qt.WindowMaximizeButtonHint) self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint) self.setAutoFillBackground(True) palette = QPalette() palette.setBrush( QPalette.Background, QBrush( QPixmap(self.image_file).scaled(self.size(), Qt.IgnoreAspectRatio, Qt.SmoothTransformation))) self.setPalette(palette) self.show() self.showNormal() def normal(self): #退出悬浮窗 self.hide() self.resize(900, 500) screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 3) self.setWindowFlags(Qt.Widget) self.lcd3.setVisible(True) self.splider.setVisible(True) self.label.setVisible(True) self.show() def resizeEvent(self, *args, **kwargs): width = self.width() height = self.height() self.lcd1.setGeometry( QRect((width - 300) / 2, (height - 111) / 2, 300, 111)) self.lcd2.setGeometry( QRect((width - 300) / 2, (height - 111) / 2, 300, 111)) self.lcd3.setGeometry(QRect(width - 200, height - 100, 200, 111)) self.label.setGeometry(QRect((width - 75) / 2, height / 2, 300, 111)) self.setAutoFillBackground(True) palette = QPalette() palette.setBrush( QPalette.Background, QBrush( QPixmap(self.image_file).scaled(self.size(), Qt.IgnoreAspectRatio, Qt.SmoothTransformation))) self.setPalette(palette) def init_Button(self): #开始结束按钮 self.state_start_end = 0 self.pushButton = QPushButton() self.pushButton.setStyleSheet("background:transparent;") self.pushButton.setText("") icon = QIcon() icon.addPixmap(QPixmap(":/start/start.png")) self.pushButton.setIcon(icon) self.pushButton.setIconSize(QSize(30, 30)) self.pushButton.setCheckable(True) self.pushButton.setFlat(True) self.pushButton.setObjectName("开始/结束") self.pushButton.clicked.connect(self.start_end) #暂停继续按钮 self.state_continue_stop = 0 self.pushButton_2 = QPushButton() self.pushButton_2.setStyleSheet("background:transparent;") self.pushButton_2.setText("") icon1 = QIcon() icon1.addPixmap(QPixmap(":/on/stop.png")) self.pushButton_2.setIcon(icon1) self.pushButton_2.setIconSize(QSize(30, 30)) self.pushButton_2.setCheckable(True) self.pushButton_2.setFlat(True) self.pushButton_2.setObjectName("pushButton_2") self.pushButton_2.clicked.connect(self.continue_stop) #数据分析按钮 self.toolButton = QToolButton() self.toolButton.setLayoutDirection(Qt.LeftToRight) self.toolButton.setStyleSheet("background:transparent;") icon2 = QIcon() icon2.addPixmap(QPixmap(":/analytics/analytics.png"), QIcon.Normal, QIcon.Off) self.toolButton.setIcon(icon2) self.toolButton.setIconSize(QSize(30, 30)) self.toolButton.setAutoRaise(True) self.toolButton.setObjectName("toolButton") self.toolButton.clicked.connect(self.analyze) #声音播放静音按钮 self.sound_state = 0 self.pushButton_4 = QPushButton() self.pushButton_4.setStyleSheet("background:transparent;") self.pushButton_4.setText("") icon3 = QIcon() icon3.addPixmap(QPixmap(":/sound/sound.png"), QIcon.Normal, QIcon.Off) icon3.addPixmap(QPixmap(":/sound_off/Sound_off.png"), QIcon.Normal, QIcon.On) self.pushButton_4.setIcon(icon3) self.pushButton_4.setIconSize(QSize(30, 30)) self.pushButton_4.setCheckable(True) self.pushButton_4.setFlat(True) self.pushButton_4.setObjectName("pushButton_4") self.pushButton_4.clicked.connect(self.sound_renew) #self.pushButton_4.rclicked.connect(self.sound_renew()) #声音大小调节按钮 self.splider = QSlider(Qt.Horizontal) self.splider.valueChanged.connect(self.valChange) self.splider.setMinimum(0) self.splider.setMaximum(100) self.splider.setSingleStep(1) self.splider.setTickInterval(1) self.splider.setValue(100) #布局 hbox = QHBoxLayout() vbox = QVBoxLayout() hbox.addWidget(self.pushButton) hbox.addWidget(self.pushButton_2) hbox.addWidget(self.toolButton) hbox.addWidget(self.pushButton_4) hbox.addWidget(self.splider) hbox.addStretch(1) vbox.addStretch(1) vbox.addLayout(hbox) main_frame = QWidget() main_frame.setLayout(vbox) self.setCentralWidget(main_frame) def refresh(self): #正计时 self.startDate_up = QDateTime( QDate.currentDate(), self.time_start_up).toMSecsSinceEpoch() #显示正计时 self.endDate_up = QDateTime.currentMSecsSinceEpoch() interval_up = self.endDate_up - self.startDate_up + self.interval if interval_up > 0: hour = interval_up // (60 * 60 * 1000) min = (interval_up - hour * 60 * 60 * 1000) // (60 * 1000) sec = (interval_up - hour * 60 * 60 * 1000 - min * 60 * 1000) // 1000 intervals = '0' * (2 - len(str(hour))) + str( hour) + ':' + '0' * (2 - len(str(min))) + str( min) + ':' + '0' * (2 - len(str(sec))) + str(sec) self.lcd1.display(intervals) #倒计时 self.startDate_fall = QDateTime.currentMSecsSinceEpoch() #显示倒计时 self.endDate_fall = QDateTime( self.time_start_data, self.time_start_fall).toMSecsSinceEpoch() interval_fall = self.endDate_fall - self.startDate_fall - self.interval if interval_fall > 0: hour = interval_fall // (60 * 60 * 1000) min = (interval_fall - hour * 60 * 60 * 1000) // (60 * 1000) sec = (interval_fall - hour * 60 * 60 * 1000 - min * 60 * 1000) // 1000 intervals = '0' * (2 - len(str(hour))) + str( hour) + ':' + '0' * (2 - len(str(min))) + str( min) + ':' + '0' * (2 - len(str(sec))) + str(sec) self.lcd2.display(intervals) if hour == 0 and min == 0 and sec == 0: mixer.init() self.sound = mixer.music.load( "./sound/My Soul,Your Beats!.mp3") mixer.music.play(-1, 0.0) def refresh_system(self): hour = QTime.currentTime().hour() #显示系统时间 min = QTime.currentTime().minute() sec = QTime.currentTime().second() intervals = '0' * (2 - len(str(hour))) + str( hour) + ':' + '0' * (2 - len(str(min))) + str( min) + ':' + '0' * (2 - len(str(sec))) + str(sec) self.lcd3.display(intervals) def sound_renew(self): #背景音乐状态按钮 #if self.pushButton_4 == Qt.LeftButton: if self.sound_state == 0: self.sound_state = 1 mixer.music.set_volume(0.0) self.splider.setValue(0) self.splider.setEnabled(False) else: self.sound_state = 0 mixer.music.set_volume(1.0) self.splider.setValue(100) self.splider.setEnabled(True) def valChange(self): #设置音量为滑动条音量 mixer.music.set_volume(self.splider.value() / 100) def start_end(self): time_1 = QTimer(self) time_1.setInterval(1) time_1.timeout.connect(self.state_refresh) time_1.start() if self.state_start_end % 2 == 0: #任务开始 self.state_continue_stop = 1 self.statis = statistic() self.interval = 0 self.time.start() if self.state_start_end % 2 == 1: #任务结束 self.check = "无" text, ok = QInputDialog.getText(self, '任务备注', '任务备注') if ok: now_end = QDate.currentDate() print(now_end.toString(Qt.DefaultLocaleLongDate)) #结束时的年月日 time_end = QTime.currentTime() print(time_end.toString(Qt.DefaultLocaleLongDate)) #结束时的时分秒 self.new_check = QLabel(text) self.check = self.new_check.text() print('任务备注=%s' % self.check) #title self.set_end(time_end.toString(Qt.DefaultLocaleLongDate), self.check) #zd icon = QIcon() icon.addPixmap(QPixmap(":/start/start.png")) self.pushButton.setIcon(icon) icon1 = QIcon() icon1.addPixmap(QPixmap(":/on/stop.png")) self.pushButton_2.setIcon(icon1) if self.statis.time_button == 1: mixer.music.stop() mixer.music.load("./sound/Berliner Philharmoniker.mp3") mixer.music.play(-1, 0.0) self.time.stop() else: #没有确认退出 self.state_start_end += 1 self.state_start_end += 1 def state_refresh(self): if self.statis.state == 1: self.statis.state = 0 #print(self.statis.label_return)#标签 start = QDate.currentDate() #print(start.toString(Qt.DefaultLocaleLongDate))#开始的年月日 time_start = QTime.currentTime() print(time_start.toString(Qt.DefaultLocaleLongDate)) #开始的时分秒 self.set_begin( start.toString(Qt.DefaultLocaleLongDate), #zd time_start.toString(Qt.DefaultLocaleLongDate), self.statis.label_return) icon = QIcon() icon.addPixmap(QPixmap(":/over/over.png")) self.pushButton.setIcon(icon) icon1 = QIcon() icon1.addPixmap(QPixmap(":/stop/on.png")) self.pushButton_2.setIcon(icon1) self.label.setText(self.statis.label_return) if self.statis.time_button == 0: self.time_start_up = time_start self.lcd1.setVisible(True) self.lcd2.setVisible(False) else: hour = int(time_start.hour()) + int( self.statis.hour_time_return) minute = int(time_start.minute()) + int( self.statis.minute_time_return) second = int(time_start.second()) + int( self.statis.second_time_return) msec = int(self.statis.hour_time_return) * 3600 * 1000 + int( self.statis.minute_time_return) * 60 * 1000 + int( self.statis.second_time_return) * 1000 self.time_start_data = start if second >= 60: minute += 1 if minute >= 60: hour += 1 if hour >= 24: self.time_start_data = start.addDays(1) self.time_start_up = time_start self.time_start_fall = time_start.addMSecs(msec) self.lcd1.setVisible(False) self.lcd2.setVisible(True) if self.statis.state == 2: self.statis.state = 0 self.state_start_end += 1 def continue_stop(self): #暂停继续 self.state_continue_stop += 1 if self.state_start_end % 2 == 1 and self.state_continue_stop % 2 == 1: self.statis.state = 1 self.state_refresh() icon1 = QIcon() icon1.addPixmap(QPixmap(":/stop/on.png")) self.pushButton_2.setIcon(icon1) self.time.start() if self.state_start_end % 2 == 1 and self.state_continue_stop % 2 == 0: self.check = "无" text, ok = QInputDialog.getText(self, '任务备注', '任务备注') if ok: now_end = QDate.currentDate() print(now_end.toString(Qt.DefaultLocaleLongDate)) #结束时的年月日 time_end = QTime.currentTime() print(time_end.toString(Qt.DefaultLocaleLongDate)) #结束时的时分秒 self.new_check = QLabel(text) self.check = self.new_check.text() print('任务备注=%s' % self.check) #title self.set_end(time_end.toString(Qt.DefaultLocaleLongDate), self.check) #zd self.set_begin(now_end.toString(Qt.DefaultLocaleLongDate), time_end.toString(Qt.DefaultLocaleLongDate), '') icon1 = QIcon() icon1.addPixmap(QPixmap(":/on/stop.png")) self.pushButton_2.setIcon(icon1) self.interval += self.time_start_up.msecsTo(time_end) if self.interval < 0: self.interval += 86400 * 1000 self.time.stop() else: self.state_continue_stop += 1 #每次开始会调用 def set_begin(self, year, begin_time, tags): # zd # 年的格式转化 self.task_is_on = True def year_transform(year): new_year = '' for i in year: if i >= '0' and i <= '9': new_year = new_year + i else: new_year = new_year + '/' return new_year[:-1] self.year = year_transform(year) self.begin_time = begin_time if tags: self.tags = tags #结束或者暂停会调用 用于写入数据库 def set_end(self, end_time, title): #zd self.task_is_on = False # 判断是否大于1分钟,是则返回true否则false def cmp_1min(time1, time2): # print('begin compare') #print(time1+' '+time2) t1 = time1.split(':') t1 = [int(x) for x in t1] t2 = time2.split(':') t2 = [int(x) for x in t2] # print('interval is {}'.format(60*( 60*(t2[0]-t1[0])+(t2[1]-t1[1]) )+(t2[2]-t1[2]))) return 60 * (60 * (t2[0] - t1[0]) + (t2[1] - t1[1])) + (t2[2] - t1[2]) >= 60 if not cmp_1min(self.begin_time, end_time): print('小于1分钟,不予计入') QMessageBox.warning(self, '提示', '小于1分钟,不予计入', QMessageBox.Yes) return obj = { 'title': title, 'phase': (self.year, self.begin_time, end_time), 'tags': self.tags } if not obj['title']: obj['title'] = '(无)' print(obj) with open('./data/tasks', 'a') as f: f.write(dumps(obj) + '\n') with open('./data/date_list', 'r') as f: date_list = [x.strip() for x in f.readlines()] if self.year in date_list: return with open('./data/date_list', 'a') as f: f.write(self.year + '\n') print('加入新日期') #调用数据分析窗口 def analyze(self): self.anayze_window_opened = True self.anayze_window = analysis() def closeEvent(self, QCloseEvent): res = QMessageBox.question(self, '消息', '是否关闭这个窗口?', QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if res == QMessageBox.Yes: if self.anayze_window_opened: self.anayze_window.close() if self.task_is_on: self.set_end( QTime.currentTime().toString(Qt.DefaultLocaleLongDate), '(无任务名)') QCloseEvent.accept() else: QCloseEvent.ignore() def initial_variables(self): #zd self.anayze_window_opened = False self.task_is_on = False self.year = '' self.tt = 0 def skip_day(self): if not self.task_is_on: return # 年的格式转化 def year_transform(year): new_year = '' for i in year: if i >= '0' and i <= '9': new_year = new_year + i else: new_year = new_year + '/' return new_year[:-1] #last_time = QTime.currentTime().toString(Qt.DefaultLocaleLongDate) last_date = QDate.currentDate().toString(Qt.DefaultLocaleLongDate) if self.year != year_transform(last_date): print('天数不同!!!') self.set_end('23:59:59', '(无)') self.set_begin(last_date, '00:00:00', self.tags) def test(self): self.tt += 1 print('悬浮窗第{}次'.format(self.tt))
class life(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): '''initiates application UI''' self.tboard = Board(self) self.tboard.resize(720, 720) self.tboard.move(10, 10) # 开始按钮 self.beginbutton = QPushButton(self) self.beginbutton.setGeometry(QRect(790, 70, 131, 51)) self.beginbutton.setObjectName("beginbutton") self.beginbutton.clicked.connect(self.tboard.beginbuttonClicked) # 停止按钮 self.stopbutton = QPushButton(self) self.stopbutton.setGeometry(QRect(790, 150, 131, 51)) self.stopbutton.setObjectName("stopbutton") self.stopbutton.clicked.connect(self.tboard.stopbuttonClicked) self.groupBox = QGroupBox(self) self.groupBox.setGeometry(QRect(750, 270, 211, 391)) self.groupBox.setObjectName("groupBox") # 窗口边长输入 self.Nchanger = QLineEdit(self.groupBox) self.Nchanger.setGeometry(QRect(100, 80, 51, 21)) self.Nchanger.setObjectName("Nchanger") self.Nchanger.setText("50") self.Nchanger.editingFinished.connect(self.editingFinished) # 密度滑动条lcd显示 self.densitylcd = QLCDNumber(self.groupBox) self.densitylcd.setGeometry(QRect(130, 140, 64, 23)) self.densitylcd.setObjectName("densitylcd") self.densitylcd.setDigitCount(3) self.densitylcd.setSegmentStyle(QLCDNumber.Flat) # 速度滑动条lcd显示 self.speedlcd = QLCDNumber(self.groupBox) self.speedlcd.setGeometry(QRect(130, 230, 64, 23)) self.speedlcd.setObjectName("speedlcd") self.speedlcd.setDigitCount(3) self.speedlcd.setSegmentStyle(QLCDNumber.Flat) # 密度滑动条 self.horizontalSlider = QSlider(self.groupBox) self.horizontalSlider.setGeometry(QRect(30, 170, 160, 22)) self.horizontalSlider.setOrientation(Qt.Horizontal) self.horizontalSlider.setObjectName("horizontalSlider") self.horizontalSlider.setMaximum(100) self.horizontalSlider.setMinimum(0) self.horizontalSlider.setValue(30) self.densitylcd.display(30) self.horizontalSlider.valueChanged.connect(self.densityvalueChanged) # 速度滑动条 self.speedchanger = QSlider(self.groupBox) self.speedchanger.setGeometry(QRect(30, 260, 160, 22)) self.speedchanger.setOrientation(Qt.Horizontal) self.speedchanger.setObjectName("speedchanger") self.speedchanger.setMaximum(600) self.speedchanger.setMinimum(15) self.speedchanger.setValue(200) self.speedlcd.display(415) self.speedchanger.valueChanged.connect(self.speedvalueChanged) # 控件名称定义 self.label_2 = QLabel(self.groupBox) self.label_2.setGeometry(QRect(30, 80, 81, 21)) self.label_2.setObjectName("label_2") self.label_3 = QLabel(self.groupBox) self.label_3.setGeometry(QRect(30, 140, 131, 21)) self.label_3.setObjectName("label_3") self.label_4 = QLabel(self.groupBox) self.label_4.setGeometry(QRect(30, 230, 121, 21)) self.label_4.setObjectName("label_4") _translate = QCoreApplication.translate self.beginbutton.setText(_translate("MainWindow", "开始")) self.stopbutton.setText(_translate("MainWindow", "停止")) self.groupBox.setTitle(_translate("MainWindow", " 参数设置")) self.label_2.setText(_translate("MainWindow", "图窗边长:")) self.label_3.setText(_translate("MainWindow", "初始细胞密度:")) self.label_4.setText(_translate("MainWindow", "演化速度:")) self.resize(980, 740) self.setFixedSize(980, 740) self.center() self.setWindowTitle('game of life') self.show() # 将窗口置于屏幕中央 def center(self): screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2) # 密度滑动条移动时调用函数 def densityvalueChanged(self): self.tboard.density = self.horizontalSlider.value() / 100 self.densitylcd.display(self.horizontalSlider.value()) # 速度滑动条移动时调用函数 def speedvalueChanged(self): self.tboard.Speed = self.speedchanger.value() self.speedlcd.display(600 - self.speedchanger.value() + 15) # 窗口边长变化时调用函数 def editingFinished(self): self.tboard.N = int(self.Nchanger.text())
class Ui_Form(object): def __init__(self): self._button_group = QButtonGroup() self.COLOR = { 'Красный': 'red.jpg', 'Синий': 'dark_blue.jpg', 'Зелёный': 'green.jpg', 'Фиолетовый': 'purple.jpg', 'Чёрный': 'black.jpg', 'Розовый': 'pink.jpg', 'Оранжевый': 'orange.jpg', 'Коричневый': 'brovn.jpg', 'Голубой': 'blue.jpg', 'Жёлтый': 'yellow.jpg' } self.widget_main = QTabWidget(Form) self.widget_game = QWidget() self.widget_top10 = QWidget() self.play_button = QPushButton(self.widget_game) self.choose_color_2 = QComboBox(self.widget_game) self.choose_color_1 = QComboBox(self.widget_game) self.name_team_2 = QLineEdit(self.widget_game) self.name_team_1 = QLineEdit(self.widget_game) self.button_south = QPushButton(self.widget_game) self.button_west = QPushButton(self.widget_game) self.button_noth = QPushButton(self.widget_game) self.button_east = QPushButton(self.widget_game) self.game_over_sec = QLCDNumber(self.widget_game) self.info_tab = QPlainTextEdit(self.widget_game) self.top_tab = QPlainTextEdit(self.widget_top10) self.matrix = list() self.time_game = 300 self.kol_move = 0 self.x, self.y = 6, 6 self.con = sqlite3.connect("football.db") self.cur = self.con.cursor() def setupUi(self, Form): Form.setObjectName("Form") Form.resize(640, 480) self.widget_main.setGeometry(QtCore.QRect(0, 0, 641, 481)) self.widget_main.setMouseTracking(False) self.widget_main.setTabletTracking(False) self.widget_main.setAcceptDrops(False) self.widget_main.setAutoFillBackground(False) self.widget_main.setTabPosition(QtWidgets.QTabWidget.South) self.widget_main.setTabShape(QtWidgets.QTabWidget.Rounded) self.widget_main.setTabsClosable(False) self.widget_main.setMovable(False) self.widget_main.setTabBarAutoHide(False) self.widget_main.setObjectName("widget_main") self.widget_game.setObjectName("widget_game") self.info_tab.setGeometry(QtCore.QRect(470, 50, 160, 90)) self.info_tab.setEnabled(False) self.top_tab.setGeometry(QtCore.QRect(120, 50, 400, 360)) self.top_tab.setEnabled(False) self.game_over_sec.setGeometry(QtCore.QRect(520, 160, 110, 60)) self.game_over_sec.setObjectName("game_over_sec") self.button_east.setGeometry(QtCore.QRect(580, 320, 40, 30)) self.button_east.setObjectName("button_east") self.button_noth.setGeometry(QtCore.QRect(540, 290, 40, 30)) self.button_noth.setObjectName("button_noth") self.button_west.setGeometry(QtCore.QRect(500, 320, 40, 30)) self.button_west.setObjectName("button_west") self.button_south.setGeometry(QtCore.QRect(540, 350, 40, 30)) self.button_south.setMinimumSize(QtCore.QSize(41, 31)) self.button_south.setObjectName("button_south") self.name_team_1.setGeometry(QtCore.QRect(0, 0, 110, 30)) self.name_team_1.setObjectName("name_team_1") self.name_team_2.setGeometry(QtCore.QRect(240, 0, 110, 30)) self.name_team_2.setObjectName("name_team_2") self.choose_color_1.setGeometry(QtCore.QRect(120, 0, 110, 30)) self.choose_color_1.setObjectName("choose_color_1") self.choose_color_1.addItem("") self.choose_color_1.addItem("") self.choose_color_1.addItem("") self.choose_color_1.addItem("") self.choose_color_1.addItem("") self.choose_color_2.setGeometry(QtCore.QRect(360, 0, 110, 30)) self.choose_color_2.setObjectName("choose_color_2") self.choose_color_2.addItem("") self.choose_color_2.addItem("") self.choose_color_2.addItem("") self.choose_color_2.addItem("") self.choose_color_2.addItem("") self.play_button.setGeometry(QtCore.QRect(500, 0, 110, 40)) self.play_button.setText("ИГРАТЬ") self.play_button.setIconSize(QtCore.QSize(16, 16)) self.play_button.setShortcut("") self.play_button.setObjectName("play_button") self.play_button.clicked.connect(self._play_button_clicked) self.widget_main.addTab(self.widget_game, "") self.widget_top10.setObjectName("widget_top10") self.widget_main.addTab(self.widget_top10, "") for i in range(13): self.matrix.append(list()) for j in range(13): btn = QPushButton('', self.widget_game) btn.setGeometry((i + 2) * 30, j * 30 + 50, 30, 30) btn.setStyleSheet('QPushButton {background-color: white}') self.matrix[-1].append(btn) self._update_tad_top() self.retranslateUi(Form) self.widget_main.setCurrentIndex(1) QtCore.QMetaObject.connectSlotsByName(Form) def retranslateUi(self, Form): _translate = QtCore.QCoreApplication.translate Form.setWindowTitle(_translate("Form", "Form")) self.button_east.setText("˃") self.button_noth.setText("˄") self.button_west.setText("˂") self.button_south.setText("˅") self._button_group.addButton(self.button_south) self._button_group.addButton(self.button_east) self._button_group.addButton(self.button_noth) self._button_group.addButton(self.button_west) self._button_group.buttonClicked.connect(self._button_move) self.choose_color_1.setItemText(0, _translate("Form", "Синий")) self.choose_color_1.setItemText(1, _translate("Form", "Оранжевый")) self.choose_color_1.setItemText(2, _translate("Form", "Зелёный")) self.choose_color_1.setItemText(3, _translate("Form", "Фиолетовый")) self.choose_color_1.setItemText(4, _translate("Form", "Чёрный")) self.choose_color_2.setItemText(0, _translate("Form", "Красный")) self.choose_color_2.setItemText(1, _translate("Form", "Розовый")) self.choose_color_2.setItemText(2, _translate("Form", "Коричневый")) self.choose_color_2.setItemText(3, _translate("Form", "Голубой")) self.choose_color_2.setItemText(4, _translate("Form", "Жёлтый")) self.widget_main.setTabText(self.widget_main.indexOf(self.widget_game), _translate("Form", "Игра")) self.widget_main.setTabText( self.widget_main.indexOf(self.widget_top10), _translate("Form", "Топ команд")) def _play_button_clicked(self): if self.name_team_1.text() == self.name_team_2.text() == '': self.all_teams = ('Зенит', 'Локомотив', self.choose_color_1.currentText(), self.choose_color_2.currentText(), 0) else: self.all_teams = (self.name_team_1.text(), self.name_team_2.text(), self.choose_color_1.currentText(), self.choose_color_2.currentText(), 0) self.cur.execute( """INSERT INTO players(name_team1,name_team2,color_team1,color_team2, time_win) VALUES(?, ?, ?, ?, ?);""", self.all_teams) self.con.commit() self.color1, self.color2 = self.COLOR[self._return_znach(key=('color_team1',))[0]],\ self.COLOR[self._return_znach(key=('color_team2',))[0]] for i in range(13): for j in range(13): if 5 <= i <= 7 and j == 0: self.matrix[i][j].setIcon(QIcon(self.color1)) self.matrix[i][j].setIconSize(QSize(20, 20)) self.matrix[i][j].setText('-') elif 5 <= i <= 7 and j == 12: self.matrix[i][j].setIcon(QIcon(self.color2)) self.matrix[i][j].setIconSize(QSize(20, 20)) self.matrix[i][j].setText('-') else: self.matrix[i][j].setText('') self.matrix[i][j].setIcon(QIcon()) self.matrix[6][6].setIcon(QIcon('football_ball.jpg')) self.matrix[6][6].setIconSize(QSize(25, 25)) self._teams = [ self._return_znach(key=("name_team1", ))[0], self._return_znach(key=("name_team2", ))[0] ] first_move = random.randint(0, 1) self._teams_cycle = cycle( [self._teams[first_move], self._teams[abs(first_move - 1)]]) self.time_game = 300 self.game_over_sec.display(self.time_game) self.player_now = next(self._teams_cycle) self.info_tab.setPlaceholderText(f'Ход команды\n{self.player_now}') QTimer.singleShot(1000, self._update) self.button_south.setEnabled(True) self.button_west.setEnabled(True) self.button_noth.setEnabled(True) self.button_east.setEnabled(True) self.x, self.y, self.kol_move = 6, 6, 0 def _update(self): try: k = -1 self.time_game -= 1 k /= self.time_game self.game_over_sec.display(self.time_game) QTimer.singleShot(1000, self._update) except ZeroDivisionError: self.game_over_sec.display(0) name_win = self._return_znach(key=("win_team", ))[0] if name_win == 'Ничья': self.info_tab.setPlaceholderText(f'Игра окончена!\n{name_win}') return self.info_tab.setPlaceholderText( f'Игра окончена!\n' f'Победила команда {self._return_znach(key=("win_team",))[0]}') def _return_znach(self, key=('name', )): result = self.cur.execute(f"""SELECT {key[0]} FROM players WHERE number_of_play=(SELECT MAX(number_of_play) FROM players)""").fetchone() return result def _button_move(self, button): text = button.text() if text == "˃": self._move_right() elif text == "˂": self._move_left() elif text == "˄": self._move_up() elif text == "˅": self._move_down() if self.matrix[self.x][self.y].text() == '-': if self.y == 12: self.cur.execute( """UPDATE players SET win_team = (SELECT name_team1 FROM players WHERE number_of_play=(SELECT MAX(number_of_play) FROM players)) WHERE number_of_play=(SELECT MAX(number_of_play) FROM players)""" ) self.cur.execute( f"""UPDATE players SET time_win = ? WHERE number_of_play=(SELECT MAX(number_of_play) FROM players);""", (self.time_game, )) self.con.commit() self.time_game = 1 self.button_south.setEnabled(False) self.button_west.setEnabled(False) self.button_noth.setEnabled(False) self.button_east.setEnabled(False) self._update_tad_top() return else: self.cur.execute( """UPDATE players SET win_team = (SELECT name_team2 FROM players WHERE number_of_play=(SELECT MAX(number_of_play) FROM players)) WHERE number_of_play=(SELECT MAX(number_of_play) FROM players)""" ) self.cur.execute( f"""UPDATE players SET time_win = ? WHERE number_of_play=(SELECT MAX(number_of_play) FROM players);""", (self.time_game, )) self.time_game = 1 self.con.commit() self.button_south.setEnabled(False) self.button_west.setEnabled(False) self.button_noth.setEnabled(False) self.button_east.setEnabled(False) self._update_tad_top() return if self.kol_move == 3: self.player_now = next(self._teams_cycle) self.info_tab.setPlaceholderText(f'Ход команды\n{self.player_now}') self.kol_move = 0 def _move_right(self): if self.x + 1 < 13: if self.matrix[self.x + 1][self.y].text() != "." and self.matrix[ self.x][self.y].text() != '-': if self.player_now == self._teams[0]: self.matrix[self.x][self.y].setIcon(QIcon(self.color1)) self.matrix[self.x][self.y].setIconSize(QSize(20, 20)) self.matrix[self.x][self.y].setText('.') self.x += 1 self.matrix[self.x][self.y].setIcon( QIcon('football_ball.jpg')) self.matrix[self.x][self.y].setIconSize(QSize(25, 25)) self.kol_move += 1 elif self.player_now == self._teams[1]: self.matrix[self.x][self.y].setIcon(QIcon(self.color2)) self.matrix[self.x][self.y].setIconSize(QSize(20, 20)) self.matrix[self.x][self.y].setText('.') self.x += 1 self.matrix[self.x][self.y].setIcon( QIcon('football_ball.jpg')) self.matrix[self.x][self.y].setIconSize(QSize(25, 25)) self.kol_move += 1 if (self.matrix[self.x][self.y].text() == "." and self.matrix[self.x - 1][self.y].text() == "." and self.matrix[self.x][self.y + 1].text() == "." and self.matrix[self.x][self.y - 1].text() == "."): self._strake() def _move_left(self): if self.x - 1 > -1: if self.matrix[self.x - 1][self.y].text() != "." and self.matrix[ self.x][self.y].text() != '-': if self.player_now == self._teams[0]: self.matrix[self.x][self.y].setIcon(QIcon(self.color1)) self.matrix[self.x][self.y].setIconSize(QSize(20, 20)) self.matrix[self.x][self.y].setText('.') self.x -= 1 self.matrix[self.x][self.y].setIcon( QIcon('football_ball.jpg')) self.matrix[self.x][self.y].setIconSize(QSize(25, 25)) self.kol_move += 1 if self.player_now == self._teams[1]: self.matrix[self.x][self.y].setIcon(QIcon(self.color2)) self.matrix[self.x][self.y].setIconSize(QSize(20, 20)) self.matrix[self.x][self.y].setText('.') self.x -= 1 self.matrix[self.x][self.y].setIcon( QIcon('football_ball.jpg')) self.matrix[self.x][self.y].setIconSize(QSize(25, 25)) self.kol_move += 1 if (self.matrix[self.x + 1][self.y].text() == "." and self.matrix[self.x - 1][self.y].text() == "." and self.matrix[self.x][self.y + 1].text() == "." and self.matrix[self.x][self.y - 1].text() == "."): self._strake() def _move_down(self): if self.y + 1 < 13: if self.matrix[self.x][self.y + 1].text() != "." and self.matrix[ self.x][self.y].text() != '-': if self.player_now == self._teams[0]: self.matrix[self.x][self.y].setIcon(QIcon(self.color1)) self.matrix[self.x][self.y].setIconSize(QSize(20, 20)) self.matrix[self.x][self.y].setText('.') self.y += 1 self.matrix[self.x][self.y].setIcon( QIcon('football_ball.jpg')) self.matrix[self.x][self.y].setIconSize(QSize(25, 25)) self.kol_move += 1 elif self.player_now == self._teams[1]: self.matrix[self.x][self.y].setIcon(QIcon(self.color2)) self.matrix[self.x][self.y].setIconSize(QSize(20, 20)) self.matrix[self.x][self.y].setText('.') self.y += 1 self.matrix[self.x][self.y].setIcon( QIcon('football_ball.jpg')) self.matrix[self.x][self.y].setIconSize(QSize(25, 25)) self.kol_move += 1 if (self.matrix[self.x + 1][self.y].text() == "." and self.matrix[self.x - 1][self.y].text() == "." and self.matrix[self.x][self.y + 1].text() == "." and self.matrix[self.x][self.y - 1].text() == "."): self._strake() def _move_up(self): if self.y - 1 > -1: if self.matrix[self.x][self.y - 1].text() != "." and self.matrix[ self.x][self.y].text() != '-': if self.player_now == self._teams[0]: self.matrix[self.x][self.y].setIcon(QIcon(self.color1)) self.matrix[self.x][self.y].setIconSize(QSize(20, 20)) self.matrix[self.x][self.y].setText('.') self.y -= 1 self.matrix[self.x][self.y].setIcon( QIcon('football_ball.jpg')) self.matrix[self.x][self.y].setIconSize(QSize(25, 25)) self.kol_move += 1 elif self.player_now == self._teams[1]: self.matrix[self.x][self.y].setIcon(QIcon(self.color2)) self.matrix[self.x][self.y].setIconSize(QSize(20, 20)) self.matrix[self.x][self.y].setText('.') self.y -= 1 self.matrix[self.x][self.y].setIcon( QIcon('football_ball.jpg')) self.matrix[self.x][self.y].setIconSize(QSize(25, 25)) self.kol_move += 1 if (self.matrix[self.x + 1][self.y].text() == "." and self.matrix[self.x - 1][self.y].text() == "." and self.matrix[self.x][self.y + 1].text() == "." and self.matrix[self.x][self.y - 1].text() == "."): self._strake() def _strake(self): i, k = 0, 3 if self.player_now == self._teams[0]: self.info_tab.setPlaceholderText( f'Штрафной\nКоманды {self._teams[0]}') while i < k: if self.y + 1 < 13: if self.matrix[self.x][self.y - 1].text( ) != "." and self.matrix[self.x][self.y].text() != '-': self.matrix[self.x][self.y].setIcon(QIcon(self.color1)) self.matrix[self.x][self.y].setIconSize(QSize(20, 20)) self.matrix[self.x][self.y].setText('.') self.y += 1 self.matrix[self.x][self.y].setIcon( QIcon('football_ball.jpg')) self.matrix[self.x][self.y].setIconSize(QSize(25, 25)) i += 1 elif self.matrix[self.x][self.y].text() == '-': self.cur.execute( """UPDATE players SET win_team = (SELECT name_team1 FROM players WHERE number_of_play=(SELECT MAX(number_of_play) FROM players)) WHERE number_of_play=(SELECT MAX(number_of_play) FROM players)""" ) self.cur.execute( f"""UPDATE players SET time_win = ? WHERE number_of_play=(SELECT MAX(number_of_play) FROM players);""", (self.time_game - 300, )) self.con.commit() self.time_game = 1 self.info_tab.setPlaceholderText( f'Игра окончена!\nПобедила команда {self._teams[0]}' ) self.button_south.setEnabled(False) self.button_west.setEnabled(False) self.button_noth.setEnabled(False) self.button_east.setEnabled(False) self._update_tad_top() return elif self.matrix[self.x][self.y + 1].text() == '.': self.matrix[self.x][self.y].setIcon(QIcon(self.color1)) self.matrix[self.x][self.y].setIconSize(QSize(20, 20)) self.matrix[self.x][self.y].setText('.') self.y += 1 self.matrix[self.x][self.y].setIcon( QIcon('football_ball.jpg')) self.matrix[self.x][self.y].setIconSize(QSize(25, 25)) i += 1 k += 1 elif self.player_now == self._teams[1]: self.info_tab.setPlaceholderText( f'Штрафной\nКоманды {self._teams[1]}') while i < k: if self.y - 1 > -1: if self.matrix[self.x + 1][self.y].text( ) != "." and self.matrix[self.x][self.y].text() != "-": self.matrix[self.x][self.y].setIcon(QIcon(self.color2)) self.matrix[self.x][self.y].setIconSize(QSize(20, 20)) self.matrix[self.x][self.y].setText('.') self.y -= 1 self.matrix[self.x][self.y].setIcon( QIcon('football_ball.jpg')) self.matrix[self.x][self.y].setIconSize(QSize(25, 25)) i += 1 elif self.matrix[self.x][self.y].text() == '-': self.cur.execute( """UPDATE players SET win_team = (SELECT name_team2 FROM players WHERE number_of_play=(SELECT MAX(number_of_play) FROM players)) WHERE number_of_play=(SELECT MAX(number_of_play) FROM players)""" ) self.cur.execute( f"""UPDATE players SET time_win = ? WHERE number_of_play=(SELECT MAX(number_of_play) FROM players);""", (self.time_game, )) self.con.commit() self.time_game = 1 self.info_tab.setPlaceholderText( f'Игра окончена!\nПобедила команда {self._teams[0]}' ) self.button_south.setEnabled(False) self.button_west.setEnabled(False) self.button_noth.setEnabled(False) self.button_east.setEnabled(False) self._update_tad_top() return elif self.matrix[self.x][self.y - 1].text() == '.': self.matrix[self.x][self.y].setIcon(QIcon(self.color1)) self.matrix[self.x][self.y].setIconSize(QSize(20, 20)) self.matrix[self.x][self.y].setText('.') self.y -= 1 self.matrix[self.x][self.y].setIcon( QIcon('football_ball.jpg')) self.matrix[self.x][self.y].setIconSize(QSize(25, 25)) i += 1 k += 1 def _update_tad_top(self): result = self.cur.execute("""SELECT time_win FROM players""").fetchall() result.sort(reverse=True) with open('text_for_top.txt', mode='w') as out_file: if len(result) > 20: for i in range(10): total = self.cur.execute( "SELECT win_team FROM players WHERE time_win=?;", result[i]).fetchone() print('', i + 1, total[0], abs(result[i][0] - 300), file=out_file, sep='\t') else: for i in range(len(result)): total = self.cur.execute( "SELECT win_team FROM players WHERE time_win=?;", result[i]).fetchone() print('', i + 1, total[0], abs(result[i][0] - 300), file=out_file, sep='\t') with open('text_for_top.txt', mode='r') as file: self.top_tab.setPlainText(file.read()) self.con.commit()
class Example(QMainWindow): def __init__(self): super(Example, self).__init__() self.tmr = QTimer() self.tmr.timeout.connect(self.on_timer) self.alarm_class = Alarm(0, 0) self.status = False self.h_m_list = [None, None] self.color_frame = (0, 0, 0) self.old_pos = None self.text = ['00', '00'] self.initUI() def initUI(self): # Генерация окна self.setWindowTitle('Clock') self.setGeometry(100, 100, 260, 160) self.setWindowFlags(Qt.FramelessWindowHint) self.setObjectName('MainWidget') self.setStyleSheet("#MainWidget {background-color: #272727;}") # Кнопка закрытие окна self.btn_close = QPushButton(self, clicked=self.close) self.btn_close.setIcon(QtGui.QIcon(QtGui.QPixmap('pngs/cross.png'))) self.btn_close.setFlat(True) self.btn_close.resize(17, 17) self.btn_close.move(242, 1) self.btn_close.show() # Кнопка возрата в general self.btn_gn = QPushButton(self, clicked=self.general) self.btn_gn.setIcon(QtGui.QIcon(QtGui.QPixmap('pngs/back.png'))) self.btn_gn.setFlat(True) self.btn_gn.resize(20, 20) self.btn_gn.move(1, 1) self.btn_gn.show() # Кнопка входа в settings self.btn_st = QPushButton(self, clicked=self.settings) self.btn_st.setIcon(QtGui.QIcon(QtGui.QPixmap("pngs/gear.png"))) self.btn_st.setFlat(True) self.btn_st.resize(15, 15) self.btn_st.move(3, 3) self.btn_st.show() # Кнопка будильника self.alarmB = QPushButton(self, clicked=self.alarm_st) self.alarmB.setIcon(QtGui.QIcon(QtGui.QPixmap("pngs/alarmN.png"))) self.alarmB.setFlat(True) self.alarmB.resize(25, 25) self.alarmB.move(204, 39) self.alarmB.show() # Кнопка включения будильника self.alVKL = QPushButton('Включить', self, clicked=self.alarm_status) self.alVKL.resize(65, 20) self.alVKL.setObjectName('a') self.alVKL.setStyleSheet( "#a {background-color: white; border-radius: 2px;}") self.alVKL.move(98, 110) # Синхронизация системного времени self.sinT = QPushButton('Синхронизация\nсистемного\nвремени', self, clicked=set_server_time) self.sinT.resize(90, 50) self.sinT.move(120, 28) # Дисплей для будильника self.lcdA = QLCDNumber(self) self.lcdA.resize(150, 75) self.lcdA.move(55, 30) self.lcdA.setSegmentStyle(QLCDNumber.Flat) self.lcdA.setObjectName("LCDA") self.lcdA.setStyleSheet( "#LCDA {background-image: url(pngs/фон.png); border: 2px solid #4c4c4c;}" ) self.lcdA.display(':'.join(self.text)) # Слайдер выбора часа self.sldH = QSlider(Qt.Vertical, self) self.sldH.setMaximum(23) self.sldH.move(46, 30) self.sldH.resize(9, 75) self.sldH.valueChanged.connect(self.slider) # Слайдер выбора минут self.sldM = QSlider(Qt.Vertical, self) self.sldM.setMaximum(59) self.sldM.move(206, 30) self.sldM.resize(9, 75) self.sldM.valueChanged.connect(self.slider2) # Дисплей часов self.lcd = QLCDNumber(self) self.lcd.resize(150, 75) self.lcd.setSegmentStyle(QLCDNumber.Flat) self.lcd.move(55, 40) self.lcd.display(make_time_for_lcd()) self.lcd.setObjectName("LCD") self.lcd.setStyleSheet( "#LCD {background-image: url(pngs/фон.png); border: 2px solid #4c4c4c;}" ) # Комбобокс для стилизации self.combo = QComboBox(self) self.combo.setStyleSheet('border-radius: 3px, 3px, 2px, 1px;') self.combo.resize(75, 20) self.combo.addItems([ "Stylization", "Color", "Olds", "Matrix", "Sofa", "Low Poly", "Anime", "Pony", "Савок" ]) self.combo.activated[str].connect(self.onActivated) self.combo.move(30, 30) # Кнопка отключения будильника self.gm = QPushButton('ОТКЛЮЧИТЬ\nБУДИЛЬНИК', self, clicked=self.play_stop) self.gm.setObjectName('x') self.gm.setStyleSheet("#x {background-color: rgb(0, 255, 0);}") self.gm.resize(90, 50) self.gm.move(85, 55) self.general() # Сцена часов def general(self): try: self.btn_st.show() self.btn_gn.hide() self.combo.hide() self.alarmB.show() self.lcd.show() self.sldH.hide() self.sldM.hide() self.lcdA.hide() self.alVKL.hide() self.sinT.hide() self.gm.hide() except AttributeError: pass # Сцена настроек def settings(self): self.btn_gn.show() self.btn_st.hide() self.combo.show() self.alarmB.hide() self.lcd.hide() self.sldH.hide() self.sldM.hide() self.lcdA.hide() self.alVKL.hide() self.sinT.show() self.gm.hide() def alarm_st(self): self.btn_gn.show() self.btn_st.hide() self.alarmB.hide() self.lcd.hide() self.sldH.show() self.sldM.show() self.sldH.setValue(get_local_time()['hours']) self.sldM.setValue(get_local_time()['minutes']) self.lcdA.show() self.alVKL.show() self.sinT.hide() def good_morning(self): self.gm.show() self.btn_gn.hide() self.btn_st.hide() self.alarmB.hide() self.lcd.hide() self.sldH.hide() self.sldM.hide() self.lcdA.hide() self.alVKL.hide() self.sinT.hide() def play_stop(self): self.alarm_class.stop_sound() self.alarm_status() self.general() # Изменение фона окна def palette(self): color = QColorDialog.getColor() if color.isValid(): self.setStyleSheet("#MainWidget {background-color: %s;}" % color.name()) self.paintEvent(self, clr=self.hex_to_rgb(color.name())) # рисование окна def paintEvent(self, event: QtGui.QPaintEvent, clr=(0, 0, 0)): painter = QtGui.QPainter(self) painter.setPen( QtGui.QPen( QtGui.QColor(int(fabs(clr[0] - 75)), int(fabs(clr[1] - 75)), int(fabs(clr[2] - 75))), 2)) painter.drawRect(self.rect()) # нужна для перемещёния окна def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.old_pos = event.pos() # вызывается всякий раз, когда мышь перемещается def mouseMoveEvent(self, event): if not self.old_pos: return delta = event.pos() - self.old_pos self.move(self.pos() + delta) # перевод их hex в rgb def hex_to_rgb(self, value): value = value.lstrip('#') lv = len(value) return tuple( int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3)) def onActivated(self, val): backgrounds = { 'Stylization': '#272727', 'Olds': 'pngs/olds.png', 'Matrix': 'pngs/matrix.png', 'Sofa': 'pngs/диван.jpg', 'Low Poly': 'pngs/bg.png', "Anime": 'pngs/anime.jpg', "Pony": 'pngs/pony.jpg', "Савок": 'pngs/фоник.png' } if val == 'Color': self.palette() elif val == 'Stylization': self.setStyleSheet("#MainWidget {background-color: #272727;}") elif val != 'Color': self.setStyleSheet("#MainWidget {background-image: url(%s);}" % backgrounds[val]) self.paintEvent(self) def slider(self, n): self.h_m_list[0] = n if len(str(n)) == 1: n = '0' + str(n) self.text[0] = str(n) self.lcdA.display(':'.join(self.text)) def slider2(self, n): self.h_m_list[1] = n if len(str(n)) == 1: n = '0' + str(n) self.text[1] = str(n) self.lcdA.display(':'.join(self.text)) def on_timer(self): """ timer handler """ self.lcd.display(make_time_for_lcd()) if self.status: t = get_local_time() if t['hours'] == self.h_m_list[0] and t[ 'minutes'] == self.h_m_list[1]: self.alarm_class.start_sound() self.good_morning() def alarm_status(self): if not self.status: self.status = True self.alarmB.setIcon(QtGui.QIcon(QtGui.QPixmap("pngs/alarmA.png"))) self.alVKL.setText('Выключить') self.alarm_class.set(self.h_m_list[0], self.h_m_list[1]) elif self.status: self.status = False self.alarmB.setIcon(QtGui.QIcon(QtGui.QPixmap("pngs/alarmN.png"))) self.alVKL.setText('Включить') self.alarm_class.tracked = self.status
class OperationalPlanning(QWidget): signal_gameover = Signal.get_signal().signal_gameover def __init__(self): super(OperationalPlanning, self).__init__() self.setObjectName('OperationalPlanning') self.setStyleSheet(GetQssFile.readQss('../resource/qss/operationalPlanning.qss')) self.log = logging.getLogger('StarCraftII') # test fix algorithm self.algorithm = None self.algorithmThread = None # font font = QFont() font.setWeight(50) font.setPixelSize(15) # set widget of layout self.frame = QFrame(self) self.frame.setGeometry(QDesktopWidget().screenGeometry()) self.main_layout = QHBoxLayout(self) self.main_layout.setSpacing(20) self.setLayout(self.main_layout) # start action self.start = QPushButton() self.start.setObjectName('start') self.startLabel = QLabel('start') self.startLabel.setFont(font) self.start_layout = QVBoxLayout() self.start_layout.addWidget(self.start, alignment=Qt.AlignCenter) self.start_layout.addWidget(self.startLabel, alignment=Qt.AlignCenter) self.main_layout.addLayout(self.start_layout) # pause action # self.pause = QPushButton() # self.pause.setObjectName('pause') # self.pauseLabel = QLabel('pause') # self.pauseLabel.setFont(font) # self.pause_layout = QVBoxLayout() # self.pause_layout.addWidget(self.pause, alignment=Qt.AlignCenter) # self.pause_layout.addWidget(self.pauseLabel, alignment=Qt.AlignCenter) # self.main_layout.addLayout(self.pause_layout) # stop action self.stop = QPushButton() self.stop.setObjectName('stop') self.stopLabel = QLabel('stop') self.stopLabel.setFont(font) self.stop_layout = QVBoxLayout() self.stop_layout.addWidget(self.stop, alignment=Qt.AlignCenter) self.stop_layout.addWidget(self.stopLabel, alignment=Qt.AlignCenter) self.main_layout.addLayout(self.stop_layout) # switch policy action self.switch = QPushButton() self.switch.setObjectName('switch') self.switchLabel = QLabel('switch policy') self.switchLabel.setFont(font) self.switch_layout = QVBoxLayout() self.switch_layout.addWidget(self.switch, alignment=Qt.AlignCenter) self.switch_layout.addWidget(self.switchLabel, alignment=Qt.AlignCenter) self.main_layout.addLayout(self.switch_layout) # simulation time self.lcd = QLCDNumber() self.lcd.setObjectName('lcd') self.lcd.setDigitCount(10) self.lcd.setMode(QLCDNumber.Dec) self.lcd.setSegmentStyle(QLCDNumber.Flat) self.lcd.setFrameStyle(QFrame.Panel | QFrame.Raised) self.lcd.display(time.strftime("%X", time.localtime())) self.lcdLabel = QLabel('simulation time') self.lcdLabel.setFont(font) self.lcd_layout = QVBoxLayout() self.lcd_layout.addWidget(self.lcd, alignment=Qt.AlignBottom) self.lcd_layout.addWidget(self.lcdLabel, alignment=Qt.AlignBottom) self.main_layout.addLayout(self.lcd_layout) # define time self.qtime = QTimer() self.qtime.timeout.connect(self.refresh) # define global variable global interval interval = 0 global start_or_pause start_or_pause = False global stop stop = True # map description self.map = QPushButton() self.map.setObjectName('map') self.mapLabel = QLabel('map description') self.mapLabel.setFont(font) self.map_layout = QVBoxLayout() self.map_layout.addWidget(self.map, alignment=Qt.AlignCenter) self.map_layout.addWidget(self.mapLabel, alignment=Qt.AlignCenter) self.main_layout.addLayout(self.map_layout) # add stretch self.main_layout.addStretch(1) # popup window self.dialog = None # initialization self.initUI() def refresh(self): timeworker = TimeWorker(self.lcd, OperationalPlanning.interval) OperationalPlanning.interval += 1 timeworker.run() def initUI(self): # connect the slot function self.start.clicked.connect(self.buttonEvent) # self.pause.clicked.connect(self.buttonEvent) self.stop.clicked.connect(self.buttonEvent) self.switch.clicked.connect(self.buttonEvent) self.map.clicked.connect(self.buttonEvent) self.signal_gameover.connect(self.stopEvent) def buttonEvent(self): sender = self.sender() if sender == self.start: self.startEvent() # elif sender == self.pause: # self.pauseEvent() elif sender == self.stop: self.stopEvent() elif sender == self.switch: self.switchEvent() elif sender == self.map: self.mapEvent() # start simulation def startEvent(self): message = 'start the simulation' self.log.info(message) Signal.get_signal().emit_signal_str(message) # fix rl algorithm globalInformation.set_value(strings.IS_STOP, False) OperationalPlanning.interval = 0 OperationalPlanning.start_or_pause = True OperationalPlanning.stop = False self.qtime.start(1000) def playWithHuman(): subprocess.Popen(strings.PLAY_WITH_HUMAN) def playWithMachine(): """ map_name = '3m' difficulty = '3' param_set = {} param_set['gamma'] = 0.99 param_set['td_lambda'] = 0.8 param_set['learning_rate'] = 0.0005 param_set['alpha'] = 0.99 param_set['eps'] = 1e-05 param_set['epsilon_start'] = 1 param_set['epsilon_end'] = 0.01 param_set['time_length'] = 100000 param_set['grad_norm_clip'] = 10 param_set['before_learn'] = 50 param_set['batch_size'] = 16 param_set['target_update_interval'] = 400 # # # iql set # param_set['algorithm'] = 'iql_CT' # path = '../model/' + map_name + '_iql_CT_3/' # COMA set param_set['algorithm'] = 'COMA' path = '../model/' + map_name + '_COMA_3/' param_set['map_name'] = map_name param_set['difficulty'] = difficulty param_set['path'] = path param_set['load_model'] = True param_set['test'] = True # self.algorithm = MARL() # self.algorithmThread = threading.Thread( # target=self.algorithm.algorithm(param_set), # name='StarCraft2Thread') """ # self.algorithm = AlgorithmAgent() # self.algorithm.start() self.algorithm = MasterAgent() self.algorithm.start() if globalInformation.get_value('pattern') == strings.HUMAN_VS_MACHINE: playWithHuman() elif globalInformation.get_value('pattern') == strings.MACHINE_VS_MACHINE: playWithMachine() # Signal.get_signal().emit_signal_none() # pause simulation def pauseEvent(self): message = 'pause the simulation' self.log.info(message) Signal.get_signal().emit_signal_str(message) if OperationalPlanning.stop: return if OperationalPlanning.start_or_pause: self.qtime.stop() OperationalPlanning.start_or_pause = False else: self.qtime.start(1000) OperationalPlanning.start_or_pause = True # stop simulation def stopEvent(self): message = 'stop the simulation' self.log.info(message) Signal.get_signal().emit_signal_str(message) self.qtime.stop() OperationalPlanning.start_or_pause = False OperationalPlanning.stop = True globalInformation.set_value(strings.IS_STOP, True) # a description of current map def mapEvent(self): message = 'open the map description' self.log.info(message) Signal.get_signal().emit_signal_str(message) self.window = FramelessWindow('map description') self.dialog = QDialog() mapDialog = MapDescriptionDialog() mapDialog.setupUi(self.dialog) self.dialog.setModal(True) self.window.setWidget(self.dialog) self.initFrameLessWindow( QSize(700, 600), 'Operational Planning', QIcon('../resource/drawable/logo.png') ) self.window.show() # self.dialog.show() # switch policy of a dialog # there is a description of each algorithm def switchEvent(self): message = 'switch policy' self.log.info(message) Signal.get_signal().emit_signal_str(message) self.window = FramelessWindow('switch policy') self.dialog = QDialog() # tab item name list_str = [ strings.ALGORITHM_COMA, strings.ALGORITHM_COMMNET_COMA, strings.ALGORITHM_QMIX, strings.ALGORITHM_QTRAN_ALT, strings.ALGORITHM_QTRAN_BASE, strings.ALGORITHM_VDN ] # item content list_item = [ strings.CLASS_ALGORITHM_COMA, strings.CLASS_ALGORITHM_COMMNET_COMA, strings.CLASS_ALGORITHM_QMIX, strings.CLASS_ALGORITHM_QTRAN_ALT, strings.CLASS_ALGORITHM_QTRAN_BASE, strings.CLASS_ALGORITHM_VDN ] # title name self.listDialog = ListDialog(list_str, list_item, strings.OPERATIONAL_PLANNING_TITLE, strings.TYPE_POLICY) self.listDialog.setupUi(self.dialog, self.window) self.window.setWidget(self.dialog) self.initFrameLessWindow( QSize(700, 600), 'Operational Planning', QIcon('../resource/drawable/logo.png') ) self.window.show() # self.dialog.setModal(True) # self.dialog.show() def initFrameLessWindow(self, size, title, icon): self.window.resize(size) self.window.setWindowTitle(title) self.window.setWindowIcon(icon)
class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName(_fromUtf8("MainWindow")) MainWindow.resize(1400, 900) self.centralwidget = QWidget(MainWindow) self.centralwidget.setObjectName(_fromUtf8("centralwidget")) self.centralwidget.resize(1400, 900) ''' Structure of this GUI centralWidget (1400 x 900) verticalLayout horizontalLayoutTop webcam_box1 (700 x 500) webcam_box2 (700 x 500) horizontalLayoutBottom controlBox (300 x 300) timer_LCD (200 x 100) (could be (200 x 300) pulseOxBox (450 x 300) ''' BigFont = QFont("Helvetica [Cronyx]", 12, QFont.Bold) # vertical layout allows to add widget vertically self.verticalLayout = QVBoxLayout() self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.horizontalLayoutTop = QHBoxLayout() self.horizontalLayoutTop.setObjectName( _fromUtf8("horizontalLayoutTop")) self.webcam_box1 = QGroupBox(self.centralwidget) self.webcam_box1.setTitle(_fromUtf8("Camera Feed 1")) self.webcam_box1.setObjectName(_fromUtf8("webcam_box_1")) #self.webcam_box1.setGeometry(QtCore.QRect(0, 0, 700, 500)) #self.webcam_box2.setGeometry(QtCore.QRect(700, 0, 700, 500)) self.webcam1 = QLabel(self.webcam_box1) self.webcam1.setGeometry(QtCore.QRect(30, 30, 641, 481)) # Default image size self.webcam1.setText(_fromUtf8("Camera Feed 1")) self.webcam1.setObjectName(_fromUtf8("webcam_1")) self.webcam1_hBox = QHBoxLayout() # Camera Control #self.cameraControlWidget = QWidget(self.centralwidget) self.cameraControlWidget = [] self.cameraControlWidget.append(PtGreyCameraControl(0)) self.cameraControlWidget.append(PtGreyCameraControl(1)) #self.CameraControlGrid = QGridLayout() # self.CameraControlForm =QFormLayout() # self.FPS_value.setFixedWidth(5) # self.CameraControlForm.addRow(self.exposure_title, self.exposure_value) # self.CameraControlForm.addRow(self.gain_title,self.gain_value) # self.CameraControlForm.addRow(self.FPS_title,self.FPS_value) #self.cameraControlWidget.setLayout(self.CameraControlGrid) self.webcam1_hBox.addWidget(self.webcam1, 3) self.webcam1_hBox.addWidget(self.cameraControlWidget[0], 1) self.webcam_box1.setLayout(self.webcam1_hBox) # Webcam -2 // May be webcam or the second point grey self.webcam_box2 = QGroupBox(self.centralwidget) self.webcam_box2.setTitle(_fromUtf8("Camera Feed 2")) self.webcam_box2.setObjectName(_fromUtf8("webcam_box_2")) self.webcam2 = QLabel(self.webcam_box2) self.webcam2.setGeometry(QtCore.QRect(30, 30, 641, 481)) # Default image size self.webcam2.setText(_fromUtf8("Camera Feed 2")) self.webcam2.setObjectName(_fromUtf8("webcam_2")) self.webcam2_vBox = QHBoxLayout() self.webcamControlWidget = QWidget(self.centralwidget) self.webcam2_hBoxBottom = QVBoxLayout() self.push_inc_webcam_gain = QPushButton() self.push_inc_webcam_gain.setObjectName( _fromUtf8("increase_webcam_gain")) self.push_inc_webcam_gain.setFont(BigFont) self.push_dec_webcam_gain = QPushButton() self.push_dec_webcam_gain.setObjectName( _fromUtf8("decrease_webcam_gain")) self.push_dec_webcam_gain.setFont(BigFont) self.push_inc_webcam_exp = QPushButton() self.push_inc_webcam_exp.setObjectName( _fromUtf8("increase_webcam_exposure")) self.push_inc_webcam_exp.setFont(BigFont) self.push_dec_webcam_exp = QPushButton() self.push_dec_webcam_exp.setObjectName( _fromUtf8("decrease_webcam_exposure")) self.push_dec_webcam_exp.setFont(BigFont) self.webcam2_hBoxBottom.addWidget(self.push_inc_webcam_exp) self.webcam2_hBoxBottom.addWidget(self.push_dec_webcam_exp) self.webcam2_hBoxBottom.addWidget(self.push_inc_webcam_gain) self.webcam2_hBoxBottom.addWidget(self.push_dec_webcam_gain) self.webcamControlWidget.setLayout(self.webcam2_hBoxBottom) self.webcam2_vBox.addWidget(self.webcam2, 3) #FIXME: Need to implement both webcam and point grey here self.webcam2_vBox.addWidget(self.cameraControlWidget[1], 1) self.webcam_box2.setLayout(self.webcam2_vBox) self.OTEventBlock = OTEventBlock() if CONFIG.PROFILE == 0: #Operating room profile self.horizontalLayoutTop.addWidget(self.webcam_box1, 2) self.cameraControlWidget[0].Binning_value.setEnabled(False) self.cameraControlWidget[0].offsetX_value.setEnabled(False) self.cameraControlWidget[0].offsetY_value.setEnabled(False) self.cameraControlWidget[0].width_value.setEnabled(False) self.cameraControlWidget[0].height_value.setEnabled(False) self.horizontalLayoutTop.addWidget(self.OTEventBlock, 1) else: self.horizontalLayoutTop.addWidget(self.webcam_box1, 1) self.horizontalLayoutTop.addWidget(self.webcam_box2, 1) #self.horizontalLayoutTop.addWidget(self.perfusion_box) self.horizontalLayoutBottom = QHBoxLayout() self.horizontalLayoutBottom.setObjectName( _fromUtf8("horizontalLayoutBottom")) # Application controls self.control_box = QGroupBox(self.centralwidget) self.control_box.setTitle(_fromUtf8("Controls")) self.control_box.setObjectName(_fromUtf8("control_box")) self.control_box.setGeometry(QtCore.QRect(0, 0, 300, 300)) self.control_vBox = QVBoxLayout() self.control_hBoxTop = QHBoxLayout() self.push_setup = QPushButton() # self.push_setup.setGeometry(QtCore.QRect(80, 20, 81, 23)) self.push_setup.setObjectName(_fromUtf8("push_setup")) self.push_setup.setFont(BigFont) self.push_start = QPushButton() # self.push_start.setGeometry(QtCore.QRect(190, 20, 81, 23)) self.push_start.setObjectName(_fromUtf8("push_start")) self.push_start.setFont(BigFont) self.push_stop = QPushButton() # self.push_stop.setGeometry(QtCore.QRect(300, 20, 81, 23)) self.push_stop.setObjectName(_fromUtf8("push_stop")) self.push_stop.setFont(BigFont) self.push_process = QPushButton() # self.push_process.setGeometry(QtCore.QRect(80, 50, 81, 23)) self.push_process.setObjectName(_fromUtf8("push_process")) self.push_process.setFont(BigFont) self.control_hBoxTop.addWidget(self.push_start) self.control_hBoxTop.addWidget(self.push_stop) self.control_hBoxTop.addWidget(self.push_setup) self.plain_instruction = QPlainTextEdit(self.control_box) self.plain_instruction.setGeometry(QtCore.QRect(0, 100, 400, 300)) self.plain_instruction.setObjectName(_fromUtf8("plain_instruction")) self.plain_instruction.setCenterOnScroll(True) self.plain_instruction.setReadOnly(True) self.control_vBox.addLayout(self.control_hBoxTop) self.control_vBox.addWidget(self.plain_instruction) self.control_box.setLayout(self.control_vBox) ''' self.push_setup = QPushButton(self.control_box) self.push_setup.setGeometry(QtCore.QRect(80, 20, 81, 23)) self.push_setup.setObjectName(_fromUtf8("push_setup")) self.push_start = QPushButton(self.control_box) self.push_start.setGeometry(QtCore.QRect(190, 20, 81, 23)) self.push_start.setObjectName(_fromUtf8("push_start")) self.push_stop = QPushButton(self.control_box) self.push_stop.setGeometry(QtCore.QRect(300, 20, 81, 23)) self.push_stop.setObjectName(_fromUtf8("push_stop")) self.push_process = QPushButton(self.control_box) self.push_process.setGeometry(QtCore.QRect(80, 50, 81, 23)) self.push_process.setObjectName(_fromUtf8("push_process")) self.plain_instruction = QPlainTextEdit(self.control_box) self.plain_instruction.setGeometry(QtCore.QRect(0, 100, 400, 300)) self.plain_instruction.setObjectName(_fromUtf8("plain_instruction")) self.plain_instruction.setCenterOnScroll(True) self.plain_instruction.setReadOnly(True) ''' # Pulse Oximeter output self.pulseOx_box = QGroupBox(self.centralwidget) self.pulseOx_box.setTitle(_fromUtf8("Pulse oximeter recordings")) self.pulseOx_box.setObjectName(_fromUtf8("pulseox_Output")) #self.pulseOx_box.setGeometry(0, 0, 450, 300) self.pulseOxLayout = QVBoxLayout() # PULSE oximeter self.pulseOx = DisplayForm() self.pulseOx2 = DisplayForm() #self.pulseOx.setGeometry(8,8,450,150) #self.pulseOx1.setGeometry(8,8,450,150) self.pulseOxLayout.addWidget(self.pulseOx) if CONFIG.PROFILE: self.pulseOxLayout.addWidget(self.pulseOx2) self.pulseOx_box.setLayout(self.pulseOxLayout) # Timer self.timer_lcd = QLCDNumber(self.centralwidget) self.timer_lcd.setObjectName(_fromUtf8("pulseox_Output")) self.timer_lcd.setGeometry(10, 10, 200, 100) self.horizontalLayoutBottom.addWidget(self.control_box, 2) self.horizontalLayoutBottom.addWidget(self.timer_lcd, 1) self.horizontalLayoutBottom.addWidget(self.pulseOx_box, 2) self.verticalLayout.addLayout(self.horizontalLayoutTop, 3) self.verticalLayout.addLayout(self.horizontalLayoutBottom, 2) self.centralwidget.setLayout(self.verticalLayout) MainWindow.setCentralWidget(self.centralwidget) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) #self.config_form = ConfigForm() #self.toolbar = Toolbar() # Group controls ''' self.label_2 = QLabel(self.control_box) self.label_2.setGeometry(QtCore.QRect(30, 20, 71, 16)) self.label_2.setObjectName(_fromUtf8("label_2")) self.push_check = QPushButton(self.control_box) self.push_check.setGeometry(QtCore.QRect(80, 40, 81, 23)) self.push_check.setObjectName(_fromUtf8("push_check")) self.push_close = QPushButton(self.control_box) self.push_close.setGeometry(QtCore.QRect(190, 40, 81, 23)) self.push_close.setObjectName(_fromUtf8("push_close")) self.push_browse = QPushButton(self.control_box) self.push_browse.setGeometry(QtCore.QRect(80, 120,81,23)) self.push_browse.setObjectName(_fromUtf8('push_browse')) self.label = QLabel(self.control_box) self.label.setGeometry(QtCore.QRect(30, 150, 91, 16)) self.label.setObjectName(_fromUtf8("label")) self.plain_instruction = QPlainTextEdit(self.control_box) self.plain_instruction.setGeometry(QtCore.QRect(30, 180, 300, 300)) self.plain_instruction.setObjectName(_fromUtf8("plain_instruction")) self.plain_instruction.setCenterOnScroll(True) self.plain_instruction.setReadOnly(True) #self.plain_instruction.setMaximumBlockCount(20) # Group_Frame self.horizontalLayoutBottom = QHBoxLayout() self.horizontalLayoutBottom.setObjectName(_fromUtf8("horizontalLayoutBottom")) # Group_Output self.Group_Output = QGroupBox(self.centralwidget) self.Group_Output.setTitle(_fromUtf8("distancePPG Output")) self.Group_Output.setObjectName(_fromUtf8("Group_Output")) self.label_3 = QLabel(self.Group_Output) self.label_3.setGeometry(QtCore.QRect(20, 20, 130, 15)) self.label_3.setObjectName(_fromUtf8("label_3")) self.line_HR = QLCDNumber(self.Group_Output) self.line_HR.setGeometry(QtCore.QRect(20, 40, 100, 100)) self.line_HR.setObjectName(_fromUtf8("line_HR")) self.label_4 = QLabel(self.Group_Output) self.label_4.setGeometry(QtCore.QRect(20, 140, 130, 15)) self.label_4.setObjectName(_fromUtf8("label_4")) self.SQDisplay = QLCDNumber(self.Group_Output) self.SQDisplay.setGeometry(QtCore.QRect(20, 160, 100, 100)) self.SQDisplay.setObjectName(_fromUtf8("SQDisplay")) self.label_6= QLabel(self.Group_Output) self.label_6.setGeometry(QtCore.QRect(20, 260, 130, 15)) self.label_6.setObjectName(_fromUtf8("label_6")) self.motion = QLCDNumber(self.Group_Output) self.motion.setGeometry(QtCore.QRect(20, 280, 100, 100)) self.motion.setObjectName(_fromUtf8("motion")) #self.frame_HRV = matplotlibWidget(self.Group_Output) #self.frame_HRV.setGeometry(QtCore.QRect(20, 90, 191, 141)) #self.frame_HRV.setObjectName(_fromUtf8("frame_HRV")) #self.label_4 = QLabel(self.Group_Output) #self.label_4.setGeometry(QtCore.QRect(20, 70, 54, 12)) #self.label_4.setObjectName(_fromUtf8("label_4")) self.label_5 = QLabel(self.Group_Output) self.label_5.setGeometry(QtCore.QRect(230, 10, 200, 12)) self.label_5.setObjectName(_fromUtf8("label_5")) self.cameraPPG = CameraForm(self.Group_Output) self.cameraPPG.setGeometry(QtCore.QRect(230, 22, 500, 400)) self.cameraPPG.setObjectName(_fromUtf8("camera_PPG")) #self.verticalLayout_2.addWidget(self.Group_Output) #self.verticalLayout_4.addLayout(self.verticalLayout_2) self.verticalLayout.addLayout(self.horizontalLayoutTop) self.verticalLayout.addLayout(self.horizontalLayoutBottom) self.centralwidget.setLayout(self.verticalLayout) MainWindow.setCentralWidget(self.centralwidget) #menubar self.menubar = QtGui.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 696, 18)) self.menubar.setObjectName(_fromUtf8("menubar")) self.menuSave = QtGui.QMenu(self.menubar) self.menuSave.setObjectName(_fromUtf8("menuSave")) MainWindow.setMenuBar(self.menubar) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName(_fromUtf8("statusbar")) MainWindow.setStatusBar(self.statusbar) self.actionCurrent_Dir = QtGui.QAction(MainWindow) self.actionCurrent_Dir.setObjectName(_fromUtf8("actionCurrent_Dir")) self.actionChange_Dir = QtGui.QAction(MainWindow) self.actionChange_Dir.setObjectName(_fromUtf8("actionChange_Dir")) self.menubar.addAction(self.menuSave.menuAction()) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) ''' def retranslateUi(self, MainWindow): MainWindow.setWindowTitle( _translate("MainWindow", "PerfusionCam Demo", None)) self.push_start.setText(_translate("MainWindow", "Start", None)) self.push_stop.setText(_translate("MainWindow", "Stop", None)) self.push_setup.setText(_translate("MainWindow", "Setup", None)) self.push_process.setText(_translate("MainWindow", "Process", None)) self.push_inc_webcam_gain.setText( _translate("MainWindow", "Inc. Gain", None)) self.push_dec_webcam_gain.setText( _translate("MainWindow", "Dec. Gain", None)) self.push_inc_webcam_exp.setText( _translate("MainWindow", "Inc. Exposure", None)) self.push_dec_webcam_exp.setText( _translate("MainWindow", "Dec. Exposure", None)) self.cameraControlWidget[0].push_cameraSetup.setText( _translate("MainWindow", "Update Settings", None)) self.cameraControlWidget[1].push_cameraSetup.setText( _translate("MainWindow", "Update Settings", None)) #self.label.setText(_translate("MainWindow", "Status:", None)) #self.label_2.setText(_translate("MainWindow", "Controls:", None)) #self.push_check.setText(_translate("MainWindow", "Check ", None)) #self.push_close.setText(_translate("MainWindow", "Close", None)) #self.push_browse.setText(_translate("MainWindow", "Select Folder", None)) #self.label_3.setText(_translate("MainWindow", "BR (Br PM)", None)) #self.label_4.setText(_translate("MainWindow", "Signal Quality:", None)) #self.label_5.setText(_translate("MainWindow", "Camera PPG Waveform:", None)) #self.label_6.setText(_translate("MainWindow", "LF/HF (using PRV):", None)) #self.menuSave.setTitle(_translate("MainWindow", "File", None)) #self.actionCurrent_Dir.setText(_translate("MainWindow", "Current Dir", None)) #self.actionChange_Dir.setText(_translate("MainWindow", "Change Dir", None))
class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(784, 600) self.centralwidget = QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.Time = QLCDNumber(self.centralwidget) self.Time.setGeometry(QRect(260, 80, 271, 121)) self.Time.setFrameShape(QFrame.Box) self.Time.setFrameShadow(QFrame.Sunken) self.Time.setLineWidth(1) self.Time.setMidLineWidth(0) self.Time.setSmallDecimalPoint(False) self.Time.setDigitCount(8) self.Time.setObjectName("lcdNumber") self.label = QLabel(self.centralwidget) self.label.setGeometry(QRect(220, 0, 341, 61)) font = QFont() font.setBold(False) font.setWeight(50) self.label.setFont(font) self.label.setFocusPolicy(Qt.NoFocus) self.label.setFrameShape(QFrame.NoFrame) self.label.setTextFormat(Qt.AutoText) self.label.setScaledContents(False) self.label.setAlignment(Qt.AlignCenter) self.label.setIndent(-1) self.label.setObjectName("label") self.line = QFrame(self.centralwidget) self.line.setGeometry(QRect(0, 40, 831, 31)) self.line.setFrameShape(QFrame.HLine) self.line.setFrameShadow(QFrame.Sunken) self.line.setObjectName("line") self.line_2 = QFrame(self.centralwidget) self.line_2.setGeometry(QRect(0, 220, 801, 31)) self.line_2.setFrameShape(QFrame.HLine) self.line_2.setFrameShadow(QFrame.Sunken) self.line_2.setObjectName("line_2") self.Melody = QPushButton(self.centralwidget) self.Melody.setGeometry(QRect(-270, 240, 1091, 61)) self.Melody.setObjectName("pushButton") self.Pause = QPushButton(self.centralwidget) self.Pause.setGeometry(QRect(520, 370, 81, 81)) self.Pause.setDefault(True) self.Pause.setFlat(False) self.Pause.setObjectName("pushButton_2") self.Stop = QPushButton(self.centralwidget) self.Stop.setGeometry(QRect(190, 370, 81, 81)) self.Stop.setDefault(True) self.Stop.setObjectName("pushButton_3") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QMenuBar(MainWindow) self.menubar.setGeometry(QRect(0, 0, 784, 21)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.label.setText(_translate("MainWindow", "Таймер")) self.Melody.setText(_translate("MainWindow", "Рингтон")) self.Pause.setText(_translate("MainWindow", "Пауза")) self.Stop.setText(_translate("MainWindow", "Отмена"))