예제 #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()
예제 #2
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_
예제 #3
0
 def check_login(self):
     if not self.top.login:
         dialog = PopDialog(self.top,
                            text='未登录!',
                            btn_list=['确定'],
                            captain='错误')
         dialog.exec()
         return False
     return True
예제 #4
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
예제 #5
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()
예제 #6
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()