Example #1
0
 def __init__(self, parent=None):
     super(Main, self).__init__(parent)
     self.desktop = QApplication.desktop()
     self.screenRect = self.desktop.screenGeometry()
     self.h = self.screenRect.height()
     self.w = self.screenRect.width()
     self.xr = self.w / 930
     self.yr = self.h / 640
     self.zr = min(self.xr, self.yr)
     self.resize(self.w, self.h)
     palette = QPalette()
     palette.setBrush(
         QPalette.Background,
         QBrush(QPixmap("./resource/image/back.jpg").scaled(self.size())))
     self.setPalette(palette)
Example #2
0
 def set_color(self):
     r, g, b = gprefs['cover_grid_color']
     pal = QPalette()
     col = QColor(r, g, b)
     pal.setColor(pal.Base, col)
     tex = gprefs['cover_grid_texture']
     if tex:
         from calibre.gui2.preferences.texture_chooser import texture_path
         path = texture_path(tex)
         if path:
             pm = QPixmap(path)
             if not pm.isNull():
                 val = pm.scaled(1, 1).toImage().pixel(0, 0)
                 r, g, b = qRed(val), qGreen(val), qBlue(val)
                 pal.setBrush(pal.Base, QBrush(pm))
     dark = (r + g + b)/3.0 < 128
     pal.setColor(pal.Text, QColor(Qt.white if dark else Qt.black))
     self.setPalette(pal)
     self.delegate.highlight_color = pal.color(pal.Text)
Example #3
0
 def set_color(self):
     r, g, b = gprefs['cover_grid_color']
     pal = QPalette()
     col = QColor(r, g, b)
     pal.setColor(pal.Base, col)
     tex = gprefs['cover_grid_texture']
     if tex:
         from calibre.gui2.preferences.texture_chooser import texture_path
         path = texture_path(tex)
         if path:
             pm = QPixmap(path)
             if not pm.isNull():
                 val = pm.scaled(1, 1).toImage().pixel(0, 0)
                 r, g, b = qRed(val), qGreen(val), qBlue(val)
                 pal.setBrush(pal.Base, QBrush(pm))
     dark = (r + g + b) / 3.0 < 128
     pal.setColor(pal.Text, QColor(Qt.white if dark else Qt.black))
     self.setPalette(pal)
     self.delegate.highlight_color = pal.color(pal.Text)
Example #4
0
    def init_ui(self):
        width = 800
        height = 580

        self.setFixedSize(width, height)

        # 设置棋盘背景
        oBackGroundImage = QImage("reversi_images/board.png")
        sBackGroundImage = oBackGroundImage.scaled(QSize(
            width, height))  # resize Image to widgets size
        palette = QPalette()
        palette.setBrush(QPalette.Window, QBrush(sBackGroundImage))
        self.setPalette(palette)

        # 初始化棋盘元素
        self.label_count_down = QLabel('', self)
        self.label_count_down.setStyleSheet(
            f"color: orange; font-size: 30px; font-weight: bold; font-family: Microsoft YaHei"
        )
        self.label_count_down.setGeometry(350, 0, 500, 60)

        self.label_turn = QLabel('蓝方回合', self)
        self.label_turn.setStyleSheet(
            f"color: blue; font-size: 24px; font-weight: bold; font-family: Microsoft YaHei"
        )
        self.label_turn.setGeometry(320, 60, 500, 40)

        self.label_blue_name = QLabel('蓝方-AI托管', self)
        self.label_blue_name.setStyleSheet(
            f"color: gray; font-size: 18px; font-weight: bold; font-family: Microsoft YaHei"
        )
        self.label_blue_name.setGeometry(150, 40, 180, 20)

        self.label_blue_score = QLabel('2', self)
        self.label_blue_score.setStyleSheet(
            f"color: yellow; font-size: 24px; font-weight: bold; font-family: Microsoft YaHei"
        )
        self.label_blue_score.setGeometry(180, 60, 120, 30)

        self.label_red_name = QLabel('大师南瓜球', self)
        self.label_red_name.setStyleSheet(
            f"color: gray; font-size: 18px; font-weight: bold; font-family: Microsoft YaHei"
        )
        self.label_red_name.setGeometry(520, 40, 180, 20)

        self.label_red_score = QLabel('2', self)
        self.label_red_score.setStyleSheet(
            f"color: yellow; font-size: 24px; font-weight: bold; font-family: Microsoft YaHei"
        )
        self.label_red_score.setGeometry(570, 60, 120, 30)

        self.btn_manunal_bye = QPushButton('手动轮空', self)
        self.btn_manunal_bye.setStyleSheet(
            f"color: #cf8160; font-size: 18px; font-weight: bold; font-family: Microsoft YaHei; background-color: #89090a"
        )
        self.btn_manunal_bye.setGeometry(685, 460, 80, 30)
        self.btn_manunal_bye.clicked.connect(self.manunal_bye)

        self.btn_restart = QPushButton('重新开始', self)
        self.btn_restart.setStyleSheet(
            f"color: #cf8160; font-size: 18px; font-weight: bold; font-family: Microsoft YaHei; background-color: #89090a"
        )
        self.btn_restart.setGeometry(685, 505, 80, 30)
        self.btn_restart.clicked.connect(self.restart)

        # 180 120
        # 445 -> 480 (row 1 -> 8 top )
        mid_top_x, mid_top_y = 400, 120
        self.btn_list_board = []

        self.qicon_blue = QIcon(QPixmap("reversi_images/blue.png"))
        self.qicon_red = QIcon(QPixmap("reversi_images/red.png"))
        self.qicon_empty = QIcon()
        self.qicon_next_step = QIcon(QPixmap("reversi_images/next_step.png"))
        self.qicon_invalid = QIcon(QPixmap("reversi_images/invalid.png"))
        self.qicon_current_blue = QIcon(
            QPixmap("reversi_images/current_blue.png"))
        self.qicon_current_red = QIcon(
            QPixmap("reversi_images/current_red.png"))

        for row_index in range_from_one(board_size):
            label_row = []

            row_width = 445 + int((480 - 445) / 7 * (row_index - 1))

            for col_index in range_from_one(board_size):
                cell = self.board[row_index][col_index]
                x, y = mid_top_x - row_width // 2 + row_width // 8 * (
                    col_index - 1), mid_top_y + 47 * (row_index - 1)

                btn = QPushButton(self)
                btn.setIconSize(QSize(60, 50))
                btn.setGeometry(x, y, row_width // 8, 50)

                btn.setStyleSheet(
                    "QPushButton { background-color: transparent; border: 0px }"
                )

                def cb(ri, ci):
                    def _cb():
                        logger.debug(f"clicked row={ri}, col={ci}")

                        # 初始化无效格子
                        if self.invalid_cell_count < invalid_cell_count:
                            if self.board[ri][ci] != cell_empty:
                                logger.info("该格子不为空,不能设置为无效格子")
                                return

                            self.board[ri][ci] = cell_invalid
                            self.invalid_cell_count = self.invalid_cell_count + 1
                            logger.info(f"设置第{self.invalid_cell_count}个无效位置")
                            self.paint()

                            if self.invalid_cell_count == invalid_cell_count:
                                # 记录点击次数,到达五个按钮时进入正式游戏模式(尝试ai点击)并隐藏提示按钮
                                self.ai_try_put_cell()
                            return

                        if self.current_step_cell(
                        ) in self.ai_cells and not self.ai_moving:
                            logger.info("当前回合由机器人托管,将无视该点击")
                            return
                        self.ai_moving = False

                        # 判断是否可行
                        if self.is_game_over():
                            self.game_over()
                            return

                        if not self.has_any_valid_cell():
                            logger.info("本轮无任何可行落子,将轮空")
                            self.next_turn()
                            self.loop_index += 1
                            if not self.has_any_valid_cell():
                                logger.info("双方均不可再落子,游戏结束")
                                self.game_over()
                                return

                        # 记录下当前方
                        current_step_cell = self.current_step_cell()

                        # 落子
                        is_valid = self.put_cell(ri, ci) is not None
                        if is_valid:
                            self.loop_index += 1

                        # 计算落子后当前方局面分
                        current_score = self.evaluate(current_step_cell)
                        if current_score >= 0:
                            cr = "bold_red"
                        else:
                            cr = "bold_green"
                        logger.info(
                            color(cr) +
                            f"落子后当前{self.cell_name_without_color(current_step_cell)}局面分为{current_score}"
                        )

                        # 重绘界面
                        self.paint()

                        # 若轮到机器人
                        self.ai_try_put_cell()

                    return _cb

                btn.clicked.connect(cb(row_index, col_index))

                label_row.append(btn)

            self.btn_list_board.append(label_row)

        self.paint()

        self.show()
Example #5
0
class DBSample(QMainWindow):
    def __init__(self):
        super().__init__()
        uic.loadUi('UI1.ui', self)
        self.setWindowTitle('Sql Reader')
        self.connection = sqlite3.connect("Res\\logs.db")
        self.pushButton.clicked.connect(self.select_data)
        self.horizontalSlider.valueChanged[int].connect(self.changeValue)
        self.comboBox.addItems(["White", "Dark", "Yarik's Orientation"])
        self.comboBox.activated[str].connect(self.themes)
        self.themes('White')
        self.textEdit.setPlainText("SELECT * FROM Action")
        self.error = 0

    def select_data(self):
        query = self.textEdit.toPlainText()
        if 'order by' not in str(query).lower():
            query += ' order by "data time" desc'
        try:
            self.error = 0
            res = self.connection.cursor().execute(query).fetchall()
        except:
            self.error = 1
            self.label_3.setText('Sql request Error')

        self.tableWidget.setColumnCount(3)
        self.tableWidget.setHorizontalHeaderLabels(
            ['Action', 'Message', 'Data Time'])
        self.tableWidget.setColumnWidth(0, 150)
        self.tableWidget.setColumnWidth(1, 473)
        if self.error != 1:
            self.tableWidget.setColumnWidth(2, 110)
        else:
            self.tableWidget.setColumnWidth(2, 149)
        self.tableWidget.setRowCount(0)
        try:
            self.error = 0
            for i, row in enumerate(res):
                self.tableWidget.setRowCount(self.tableWidget.rowCount() + 1)
                for j, elem in enumerate(row):
                    self.tableWidget.setItem(i, j, QTableWidgetItem(str(elem)))
            self.error = 0
        except:
            self.error = 1
            self.label_3.setText('Sql request Error')

    def themes(self, text):
        if text == "Yarik's Orientation":
            self.label.setStyleSheet("color: rgb(0, 0, 0);")
            self.label_2.setStyleSheet("color: rgb(0, 0, 0);")
            self.label_3.setStyleSheet("color: rgb(0, 0, 0);")
            self.label_5.setStyleSheet("color: rgb(0, 0, 0);")
            self.pushButton.setStyleSheet(
                "background-image: url('Res/Timber.jpg');border-radius: 10px;")
            self.textEdit.setStyleSheet("background-image: url(Res/input.jpg)")
            self.Image = QImage("Res\\Azure Pop.jpg")
            self.Image = self.Image.scaled(QSize(800, 600))
            self.palette = QPalette()
            self.palette.setBrush(10, QBrush(self.Image))
            self.setPalette(self.palette)
            self.tableWidget.setStyleSheet(
                'background-image: url(Res/table.jpg)')
            stylesheet = """
                    QTableWidget {background-image: url(Res/table.jpg)}
                    QTableWidget QHeaderView::section:horizontal:first {background-image: url(Res/table0.jpg); border: none; border-style: none;}
                    QTableWidget QHeaderView::section:horizontal:middle {background-image: url(Res/table1.jpg); border: none; border-style: none;}
                    QTableWidget QHeaderView::section:horizontal:last {background-image: url(Res/table2.jpg); border: none; border-style: none;}
                    QTableWidget QHeaderView::section:vertical {background-image: url(Res/table.jpg); border: none; border-style: none;}
                    QTableWidget QTableCornerButton::section {background-image: url(Res/table.jpg);  border: 0px}
                    """

            self.tableWidget.setStyleSheet(stylesheet)

        elif text == "Dark":
            self.label.setStyleSheet("color: rgb(235, 235, 235);")
            self.label_2.setStyleSheet("color: rgb(235, 235, 235);")
            self.label_3.setStyleSheet("color: rgb(235, 235, 235);")
            self.label_5.setStyleSheet("color: rgb(235, 235, 235);")
            self.pushButton.setStyleSheet(
                "background-color: white;border-radius: 10px;")
            self.textEdit.setStyleSheet(
                "color: rgb(235, 235, 235); background-color: rgb(50, 50, 50)")
            self.palette = QPalette()
            self.palette.setBrush(10, QBrush(QColor(27, 27, 27)))
            self.setPalette(self.palette)
            stylesheet = """
                                QTableWidget {color: rgb(235, 235, 235); background-color: rgb(50, 50, 50)}
                                QTableWidget QHeaderView::section {background-color: rgb(50, 50, 50); border: none; border-style: none;}
                                QTableWidget QHeaderView {color: rgb(235, 235, 235);background-color: rgb(50, 50, 50); border: none; border-style: none;}
                                QTableWidget QTableCornerButton::section {background-color: rgb(50, 50, 50);  border: 0px}
                                """
            self.tableWidget.setStyleSheet(stylesheet)

        elif text == "White":
            self.label.setStyleSheet("color: rgb(0, 0, 0);")
            self.label_2.setStyleSheet("color: rgb(0, 0, 0);")
            self.label_3.setStyleSheet("color: rgb(0, 0, 0);")
            self.label_5.setStyleSheet("color: rgb(0, 0, 0);")
            self.pushButton.setStyleSheet(
                "background-color: rgb(255, 255, 255);border-radius: 10px;")
            self.textEdit.setStyleSheet("background-color: rgb(255, 255, 255)")
            self.palette = QPalette()
            self.palette.setBrush(10, QBrush(QColor(240, 240, 240)))
            self.setPalette(self.palette)
            stylesheet = """
                            QTableWidget {background-color: rgb(255, 255, 255)}
                            QTableWidget QHeaderView::section {background-color: rgb(255, 255, 255); border: none; border-style: none;}
                            QTableWidget QHeaderView {background-color: rgb(255, 255, 255); border: none; border-style: none;}
                            QTableWidget QTableCornerButton::section {background-color: rgb(255, 255, 255);  border: 0px}
                            """
            self.tableWidget.setStyleSheet(stylesheet)

    def changeValue(self, value):
        self.setWindowOpacity(value / 100)

    def closeEvent(self, event):
        self.connection.close()
Example #6
0
    def set_misc(self):
        self.retranslateUi(MainWindow)
        self.pushButton.clicked.connect(self.new_forecast)
        self.pushButton.setShortcut("Return")
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        oImage = QImage("icons\\background.png")
        sImage = oImage.scaled(QSize(749, 733))
        palette = QPalette()
        palette.setBrush(10, QBrush(oImage))
        MainWindow.setPalette(palette)

        color = QColor(255, 0, 0, 0)
        palette = QPalette()
        palette.setBrush(10, QBrush(color))
        self.hForecastSA1.setPalette(palette)
        self.hForecastSA2.setPalette(palette)

        self.scrollArea_1.setVerticalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.scrollArea_1.setFrameShape(QtGui.QFrame.NoFrame)
        self.scrollArea_2.setVerticalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.scrollArea_2.setFrameShape(QtGui.QFrame.NoFrame)

        sAreaStyleSheet = """
            
            QScrollArea{
                background-color:transparent;
                }
                
            """

        sBarStyleSheet = """
        
            QScrollBar:horizontal{
                background-color:transparent;
                }
        
        """

        lineEditStyleSheet = """
        
            *{
                background-color: rgba(0, 0, 0, 50);
                color: white;
            }
        
        """

        pushButtonStyleSheet = """
        
            *{
                background-color: rgba(0, 0, 0, 50);
                color: white;
            }
        
        """

        self.scrollArea_1.setStyleSheet(sAreaStyleSheet)
        self.scrollArea_1.horizontalScrollBar().setStyleSheet(sBarStyleSheet)
        self.scrollArea_2.setStyleSheet(sAreaStyleSheet)
        self.scrollArea_2.horizontalScrollBar().setStyleSheet(sBarStyleSheet)

        self.lineEdit.setStyleSheet(lineEditStyleSheet)
        self.pushButton.setStyleSheet(pushButtonStyleSheet)