Ejemplo n.º 1
0
 def click_submit(self):
     nick, act, pwd = self.nick_ipt.text(), self.act_ipt.text(
     ), self.pwd_ipt.text()
     if check_legal(act) and check_legal(pwd) and (
             # 登录
         (self.is_login() and (not nick or check_legal(nick))) or
             # 注册
         (not self.is_login() and check_legal(nick))):
         self.dialog = PopDialog(self.top,
                                 text='正在请求服务器',
                                 btn_list=['取消'],
                                 click_signal=self.dialog_click,
                                 captain='登录中')
         self.dialog.finished.connect(self.cancel_req)
         self.req_id += 1
         AsyncRequest(self.top,
                      url='/login',
                      data={
                          'type':
                          ('login' if self.is_login() else 'register'),
                          'nick': nick,
                          'act': act,
                          'pwd': pwd
                      },
                      signal=self.submit_signal,
                      req_id=self.req_id).start()
         self.dialog.exec()
     else:
         self.dialog = PopDialog(self.top,
                                 text='昵称,账号和密码必须是1-16位汉字,字母,数字或下划线',
                                 btn_list=['确认'],
                                 click_signal=self.dialog_click,
                                 captain='错误')
         self.dialog.exec()
Ejemplo n.º 2
0
 def check_login(self):
     if not self.top.login:
         dialog = PopDialog(self.top,
                            text='未登录!',
                            btn_list=['确定'],
                            captain='错误')
         dialog.exec()
         return False
     return True
Ejemplo n.º 3
0
 async def recv_pos(self):
     self.footer_frm.turn_signal.emit('other')
     recv_pos = await self.websocket.recv()
     exit_ = False
     if recv_pos == 'exit':
         self.refresh()
         await self.websocket.close()
         exit_ = True
     else:
         pos = eval(recv_pos)
         # 对方赢了
         if pos[0] < 0 and pos[1] < 0:
             pos = [-x for x in pos]
             self.body_frm.put_chess(pos)
             await self.websocket.close()
             PopDialog(self.top, text='你输了', captain='游戏结束').exec()
             exit_ = True
         else:
             self.body_frm.put_chess(pos)
         print('recv pos ' + recv_pos)
     if exit_:
         self.footer_frm.turn_signal.emit('exit')
         self.head_frm.toggle_playing(False)
         self.body_frm.chessboard.turn_to_me = False
     return exit_
Ejemplo n.º 4
0
 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()
Ejemplo n.º 5
0
 async def send_pos(self, what):
     self.footer_frm.turn_signal.emit('me')
     self.put_event.clear()
     self.put_event.wait()
     pos = self.body_frm.put_pos
     self.body_frm.put_event.clear()
     # 发送坐标
     await self.websocket.send(f'p{what}_{self.game_id}(' + str(pos) + ')')
     print('send pos ' + str(pos))
     # 我赢了
     if pos[0] < 0 and pos[1] < 0:
         await self.websocket.close()
         PopDialog(self.top, text='你赢了', captain='游戏结束').exec()
         return False
     return True
Ejemplo n.º 6
0
 def do_save(self):
     nick, pwd = self.user_info.nick.text(), self.user_info.pwd.text()
     if check_legal(nick) and check_legal(pwd):
         self.save_btn.setText('处理中...')
         self.save_btn.setEnabled(False)
         self.exit_btn.setEnabled(False)
         AsyncRequest(self.top,
                      url='/modify_info',
                      signal=self.save_signal,
                      data={
                          'cover': self.user_info.avatar.dialog.i,
                          'nick': nick,
                          'pwd': pwd
                      }).start()
     else:
         PopDialog(self.top, text='昵称或密码必须是1-16位汉字,字母,数字或下划线',
                   captain='错误').exec()
Ejemplo n.º 7
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()
Ejemplo n.º 8
0
class Login(qt.QFrame):
    submit_signal = qt.pyqtSignal(dict, int)
    dialog_click = qt.pyqtSignal(str)

    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)

    def toggle(self, is_login):
        if is_login:
            self.nick_ipt.hide()
            self.submit.setText('登录')
        else:
            self.nick_ipt.show()
            self.submit.setText('注册')

    def click_submit(self):
        nick, act, pwd = self.nick_ipt.text(), self.act_ipt.text(
        ), self.pwd_ipt.text()
        if check_legal(act) and check_legal(pwd) and (
                # 登录
            (self.is_login() and (not nick or check_legal(nick))) or
                # 注册
            (not self.is_login() and check_legal(nick))):
            self.dialog = PopDialog(self.top,
                                    text='正在请求服务器',
                                    btn_list=['取消'],
                                    click_signal=self.dialog_click,
                                    captain='登录中')
            self.dialog.finished.connect(self.cancel_req)
            self.req_id += 1
            AsyncRequest(self.top,
                         url='/login',
                         data={
                             'type':
                             ('login' if self.is_login() else 'register'),
                             'nick': nick,
                             'act': act,
                             'pwd': pwd
                         },
                         signal=self.submit_signal,
                         req_id=self.req_id).start()
            self.dialog.exec()
        else:
            self.dialog = PopDialog(self.top,
                                    text='昵称,账号和密码必须是1-16位汉字,字母,数字或下划线',
                                    btn_list=['确认'],
                                    click_signal=self.dialog_click,
                                    captain='错误')
            self.dialog.exec()

    # dialog点击
    def dialog_btn_click(self, text):
        if text == '取消' or text == '收到' or text == 'closeEvent':
            self.cancel_req()
        else:
            self.dialog.close()

    # 终止请求
    def cancel_req(self):
        self.req_id += 1
        if not self.dialog.isHidden():
            self.dialog.close()

    # 请求结果
    def result(self, dic, req_id):
        if req_id == self.req_id:
            # 登录
            if self.is_login():
                if dic['state'] == 'suc':
                    self.dialog.close()
                    self.top.login = dic['data']['id']
                    self.parent().info_frm.show()
                    # 传递个人信息
                    self.parent().info_frm.set_info(dic['data'])
                    self.top.game_frm.footer_frm.p1.update_info(dic['data'])
                    self.hide()
                elif dic['state'] == 'warn':
                    self.dialog.set_text('账号不存在或密码错误')
                else:
                    self.dialog.set_text('错误:' + dic['data'])
            else:
                if dic['state'] == 'suc':
                    self.dialog.set_text('注册成功!')
                elif dic['state'] == 'warn':
                    self.dialog.set_text('账号已被注册!')
                else:
                    self.dialog.set_text('错误:' + dic['data'])
            self.dialog.set_btn('取消', '收到')

    def is_login(self):
        return self.submit.text() == '登录'