예제 #1
0
    def __init__(self, p, top):
        super().__init__(p)
        self.top = top
        self.choose_color = config['color']
        self.setProperty('class', 'set')
        layer = qt.QVBoxLayout()

        self.server_cfg = qt.QFrame(self)
        layer_1 = CommonHBox()
        layer_1.addWidget(qt.QLabel('服务器', self.server_cfg))
        self.server_input = qt.QLineEdit(config['server'], self.server_cfg)
        layer_1.addWidget(self.server_input)
        self.server_cfg.setLayout(layer_1)

        self.color_cfg = qt.QFrame(self)
        layer_2 = CommonHBox()
        layer_2.addWidget(qt.QLabel('主题', self.server_cfg))
        self.white = qt.QPushButton(self.color_cfg)
        self.white.clicked.connect(self.set_white)
        self.white.setProperty('class', 'white')
        self.dracula = qt.QPushButton(self.color_cfg)
        self.dracula.clicked.connect(self.set_dracula)
        self.dracula.setProperty('class', 'dracula')
        layer_2.addWidget(self.white)
        layer_2.addWidget(self.dracula)
        self.color_cfg.setLayout(layer_2)

        self.save_btn = CommonBtn('保存', self)
        self.save_btn.clicked.connect(self.save)
        layer.addWidget(self.server_cfg)
        layer.addWidget(self.color_cfg)
        layer.addWidget(self.save_btn)
        self.setLayout(layer)
예제 #2
0
    def __init__(self, parent, top, g_id, cover, nick):
        super().__init__(parent)
        self.top = top
        self.setProperty('class', 'the-room')
        self.setFixedSize(140, 150)
        self.g_id = g_id

        layer = CommonVBox()
        h_layer = CommonHBox()

        id_label = qt.QLabel(str(g_id), self)
        id_label.setAlignment(qt.Qt.AlignCenter)
        id_label.setProperty('class', 'id')
        cover_img = qt.QLabel(self)
        cover_img.setProperty('class', 'cover')
        cover_img.setFixedSize(66, 60)
        cover_img.setScaledContents(True)
        cover_img.setPixmap(qt.QPixmap(f'./static/avatar/{cover}.png'))
        join_btn = CommonBtn('加入', self)
        join_btn.clicked.connect(self.join_room)

        h_layer.addWidget(cover_img)
        nick_ = qt.QLabel(nick, self)
        nick_.setProperty('class', 'nick')
        nick_.setWordWrap(True)
        h_layer.addWidget(nick_)

        layer.addWidget(id_label, 0)
        layer.addLayout(h_layer, 2)
        layer.addWidget(join_btn, 0)
        self.setLayout(layer)
예제 #3
0
    def __init__(self, parent, top):
        super().__init__(parent)
        self.top = top
        self.setProperty('class', 'user-info')
        layer = CommonHBox()

        self.left_frm = qt.QFrame(self)
        self.left_frm.setProperty('class', 'left')
        left_layer = qt.QVBoxLayout()
        self.avatar = Avatar(self.left_frm, top)
        left_layer.addWidget(self.avatar)
        self.left_frm.setLayout(left_layer)

        self.right_frm = qt.QFrame(self)
        self.right_frm.setProperty('class', 'right')
        right_layer = qt.QVBoxLayout()
        self.nick = SuperInput(self.left_frm, ico=0xe007)
        self.act = SuperInput(self.right_frm, ico=0xe006)
        self.act.input.setEnabled(False)
        self.pwd = SuperInput(self.right_frm, ico=0xe008)
        right_layer.addWidget(self.nick)
        right_layer.addWidget(self.act)
        right_layer.addWidget(self.pwd)
        self.right_frm.setLayout(right_layer)

        layer.addWidget(self.left_frm)
        layer.addWidget(self.right_frm)
        self.setLayout(layer)
예제 #4
0
    def __init__(self, player, top):
        super().__init__(parent=player)
        self.setProperty("class", "login")
        self.top = top
        self.dialog = None
        self.req_id = 0

        layer = CommonVBox()

        toggle_layer = CommonHBox()
        self.toggle_frm = ToggleLogin(self, top)
        toggle_layer.addWidget(self.toggle_frm)
        layer.addLayout(toggle_layer)

        mid_frame = qt.QFrame(self)
        input_layer = qt.QVBoxLayout()
        self.nick_ipt = SuperInput(self, placeholder="昵称", ico=0xe007)
        self.nick_ipt.hide()
        self.act_ipt = SuperInput(self, placeholder="账号", ico=0xe006)
        self.pwd_ipt = SuperInput(self, placeholder="密码", ico=0xe008)
        input_layer.addWidget(self.nick_ipt)
        input_layer.addWidget(self.act_ipt)
        input_layer.addWidget(self.pwd_ipt)
        mid_frame.setLayout(input_layer)
        layer.addWidget(mid_frame, 1)

        self.submit = IcoButton(self.top, parent=self, text="登录", ico=0xe001)
        self.submit.clicked.connect(self.click_submit)
        layer.addWidget(self.submit, alignment=qt.Qt.AlignHCenter)

        self.setLayout(layer)

        self.submit_signal.connect(self.result)
        self.dialog_click.connect(self.dialog_btn_click)
예제 #5
0
    def __init__(self, parent, top):
        super().__init__(parent)
        self.top = top
        self.setProperty("class", "act-info")
        layer = qt.QVBoxLayout()

        self.user_info = UserInfo(self, top)
        self.game_num = qt.QLabel(self)
        self.win_num = qt.QLabel(self)
        btn_frm = qt.QFrame(self)
        btn_layer = CommonHBox()
        self.save_btn = IcoButton(self.top, btn_frm, '保存', ico=0xe010)
        self.save_btn.clicked.connect(self.do_save)
        self.exit_btn = IcoButton(self.top, btn_frm, '退出', ico=0xe009)
        self.exit_btn.clicked.connect(self.do_exit)
        btn_layer.addWidget(self.save_btn)
        btn_layer.addWidget(self.exit_btn)
        btn_frm.setLayout(btn_layer)

        layer.addWidget(self.user_info, 3)
        layer.addWidget(self.game_num, 2)
        layer.addWidget(self.win_num, 1)
        layer.addWidget(btn_frm)
        self.setLayout(layer)
        self.save_signal.connect(self.save_result)
예제 #6
0
    def __init__(self, top):
        super().__init__(parent=top)
        self.setObjectName("home")
        layer = CommonHBox()

        self.player_frm = Player(top, self)
        self.room_frm = RoomFrame(top, self)

        layer.addWidget(self.player_frm)
        layer.addWidget(self.room_frm)
        self.setLayout(layer)
예제 #7
0
    def __init__(self, parent, top):
        super().__init__(parent)
        self.setProperty('class', 'body')
        self.top = top
        self.put_event = Event()
        self.put_pos = []

        layer = CommonHBox()
        self.chessboard = ChessBoard(self, top)
        layer.addWidget(self.chessboard, qt.Qt.AlignCenter)
        self.setLayout(layer)
        self.setMouseTracking(True)
예제 #8
0
    def __init__(self, parent, top):
        super().__init__(parent=parent)
        self.top = top
        self.setProperty('class', 'toggle')
        layer = CommonHBox()

        self.login_btn = qt.QPushButton('登录', self)
        self.login_btn.clicked.connect(lambda: self.click(self.login_btn))
        self.login_btn.setProperty('class', 'active')
        self.register_btn = qt.QPushButton('注册', self)
        self.register_btn.setProperty('class', 'reg')
        self.register_btn.clicked.connect(
            lambda: self.click(self.register_btn))

        layer.addWidget(self.login_btn)
        layer.addWidget(self.register_btn)
        self.setLayout(layer)
예제 #9
0
    def __init__(self, parent, top):
        super().__init__(parent=parent)
        self.top = top
        self.setFixedHeight(46)
        self.setProperty('class', 'head')

        self.back_btn = IcoButton(top, self, ico=0xe011)
        self.back_btn.setProperty('what', 'back')
        self.back_btn.clicked.connect(self.back_home)
        self.refresh_btn = IcoButton(top, self, text='刷新', ico=0xe012)
        self.refresh_btn.setProperty('what', 'refresh')
        self.refresh_btn.clicked.connect(self.refresh)

        layer = CommonHBox()
        layer.addWidget(self.back_btn)
        layer.addStretch(2)
        layer.addWidget(self.refresh_btn)
        self.setLayout(layer)
예제 #10
0
    def __init__(self, parent, top):
        super().__init__(parent)
        self.top = top
        self.setProperty('class', 'set-about')
        self.set_dialog = SetDialog(self, top)
        self.about_dialog = AboutDialog(self, top)

        layer = CommonHBox()
        self.set_btn = CommonBtn(chr(0xe002), self)
        self.set_btn.clicked.connect(self.set_dialog.exec)
        self.about_btn = CommonBtn(chr(0xe003), self)
        self.about_btn.clicked.connect(self.about_dialog.exec)

        layer.addStretch(0)
        layer.addWidget(self.set_btn, alignment=qt.Qt.AlignRight)
        layer.addWidget(self.about_btn, alignment=qt.Qt.AlignRight)
        self.setLayout(layer)

        self.set_qss.connect(self.do_set_qss)
        self.set_qss.emit()
예제 #11
0
    def __init__(self, parent, top):
        super().__init__(parent)
        self.top = top
        self.setProperty('class', 'head')
        self.dialog = HeadDialog(self, top)
        self.setFixedHeight(50)
        layer = CommonHBox()

        self.back_btn = IcoButton(self.top, self, ico=0xe011)
        self.back_btn.clicked.connect(self.back_home)
        btn_layer = CommonHBox()
        self.create_btn = IcoButton(self.top, self, text='创建房间', ico=0xe013)
        self.create_btn.clicked.connect(self.create_)
        self.create_btn.setFixedWidth(140)
        self.join_btn = IcoButton(self.top, self, text='加入房间', ico=0xe004)
        self.join_btn.clicked.connect(self.join_)
        self.join_btn.setFixedWidth(140)
        self.exit_btn = IcoButton(self.top, self, text='退出游戏', ico=0xe009)
        self.exit_btn.clicked.connect(self.exit_)
        self.exit_btn.setFixedWidth(140)
        self.exit_btn.hide()

        layer.addWidget(self.back_btn, 0)
        btn_layer.addWidget(self.create_btn, alignment=qt.Qt.AlignHCenter)
        btn_layer.addWidget(self.join_btn, alignment=qt.Qt.AlignHCenter)
        btn_layer.addWidget(self.exit_btn, alignment=qt.Qt.AlignHCenter)
        layer.addLayout(btn_layer, 1)
        self.setLayout(layer)
예제 #12
0
    def __init__(self, parent, top):
        super().__init__(parent)
        self.top = top
        self.preserve = {}
        self.setProperty('class', 'player')
        self.setFixedWidth(240)
        layer = CommonHBox()

        self.base_info = qt.QFrame(self)
        self.base_info.setProperty('class', 'base')
        base_info_layer = CommonVBox()
        self.avatar = AvatarLabel(self.base_info, (66, 66), 8)
        self.avatar.setProperty('class', 'avatar')
        base_info_layer.addWidget(self.avatar)
        self.base_info.setLayout(base_info_layer)

        self.game_info = qt.QFrame(self)
        self.game_info.setProperty('class', 'game')
        game_info_layer = CommonVBox()
        self.nick = qt.QLabel(self.base_info)
        self.nick.setProperty('class', 'nick')
        self.nick.setWordWrap(True)
        self.game_num = qt.QLabel(self.game_info)
        self.game_num.setProperty('class', 'game_num')
        self.win_num = qt.QLabel(self.game_info)
        self.win_num.setProperty('class', 'win_num')
        game_info_layer.addWidget(self.nick)
        game_info_layer.addWidget(self.game_num)
        game_info_layer.addWidget(self.win_num)
        self.game_info.setLayout(game_info_layer)

        layer.addWidget(self.base_info)
        layer.addWidget(self.game_info)
        self.setLayout(layer)

        self.update_info(False)
예제 #13
0
    def __init__(self, parent, top):
        super().__init__(parent)
        self.setProperty('class', 'footer')
        self.setFixedHeight(100)
        self.top = top
        layer = CommonHBox()

        self.p1 = PlayerInfo(self, top)
        self.middle_frm = qt.QFrame(self)
        self.p2 = PlayerInfo(self, top)

        layer.addWidget(self.p1)
        layer.addWidget(self.middle_frm)
        layer.addWidget(self.p2)
        self.setLayout(layer)

        self.turn_signal.connect(self.turn_to)
예제 #14
0
class TurnPage(qt.QFrame):
    list_signal = qt.pyqtSignal(dict, int)
    dialog_signal = qt.pyqtSignal(str)

    def __init__(self, parent, top):
        super().__init__(parent)
        self.top = top
        self.setFixedHeight(50)
        self.setProperty('class', 'turn-page')

        self.dialog = None
        self.is_req = False
        self.init_page_ = False
        self.btn_lis = []

        self.layer = CommonHBox()
        self.setLayout(self.layer)

        self.dialog_signal.connect(self.dialog_click)
        self.list_signal.connect(self.list_result)

    # 重置页码信息
    def init_page(self, page_count):
        while self.layer.count():
            self.layer.itemAt(0).widget().setParent(None)
        self.btn_lis.clear()
        for i in range(1, page_count + 1):
            btn = CommonBtn(str(i), self)
            btn.setFixedSize(46, 36)
            btn.clicked.connect(self.click_page_btn)
            if i == 1:
                btn.setProperty('class', 'active')
            self.btn_lis.append(btn)
            self.layer.addWidget(btn)
        self.top.set_qss.emit()

    # 点击翻页按钮
    def click_page_btn(self):
        self.turn_page(int(self.sender().text()))

    # 翻页操作
    def turn_page(self, p, init_page=False):
        self.init_page_ = init_page
        self.dialog = PopDialog(self.top,
                                self.dialog_signal,
                                captain='查询中',
                                text='正在请求服务器',
                                btn_list=['取消'])
        thread = AsyncRequest(self.top,
                              url='/room_list',
                              data={
                                  'page': p - 1,
                                  'count': Item_Num_One_Page
                              },
                              signal=self.list_signal,
                              req_id=p)
        thread.start()
        self.is_req = True
        self.dialog.exec()

    def list_result(self, dic, req_id):
        if self.is_req:
            if dic['state'] == 'suc':
                info = dic['data']
                count = info['count']
                page_num = ceil(count / Item_Num_One_Page)
                # 修改btn样式
                for i in self.btn_lis:
                    if i.text() == str(req_id):
                        i.setProperty('class', 'active')
                    else:
                        i.setProperty('class', '')
                self.top.set_qss.emit()
                # 修改info_label和列表
                self.parent().body.refresh(info['lis'])
                if self.init_page_:
                    self.init_page(page_num)
                self.dialog.close()
            else:
                self.dialog.set_text('错误:' + dic['data'])
                self.dialog.set_btn('取消', '关闭')

    def dialog_click(self, s):
        self.is_req = False
        self.dialog.close()