Exemplo n.º 1
0
    def do_login(self):
        username = self.username.get()
        password = self.password.get()
        if not username:
            messagebox.showerror("Error", "username can not be blank")
            return
        if not password:
            messagebox.showerror("Error", "password can not be blank")

        send_message(self.s, MessageType.login, [username, password])
        print("登录请求已发送")

        msg = recv_message(self.s)
        if not msg:
            messagebox.showerror("Error", "connection wrong")
            self.destroy_window()
            return

        if msg[type] == MessageType.loginFailed:
            messagebox.showerror("登录失败", "用户名或密码错误!")
            return

        if msg[type] == MessageType.loginSucc:
            info.current_user = username
            print("登录成功")
            self.master.destroy()
            homepage = Toplevel(info.tk_root, takefocus=True)
            HomePageForm(homepage)
            return
Exemplo n.º 2
0
    def do_signup(self):
        username = self.username.get()
        password = self.password.get()
        password_confirm = self.password_confirm.get()

        if not username:
            messagebox.showerror("Error", "username can not be blank")
            return
        if not password or not password_confirm:
            messagebox.showerror("Error", "password can not be blank")
            return
        if password != password_confirm:
            messagebox.showerror("Error", "passwords are not the same")
            return

        send_message(self.s, MessageType.signup, [username, password])
        msg = recv_message(self.s)
        if not msg:
            messagebox.showerror("Error", "connection wrong")
            return
        if msg['type'] == MessageType.usernameTaken:
            messagebox.showerror("Error", "the username has been used")
            return
        if msg['type'] == MessageType.signupSucc:
            messagebox.showerror("注册成功!")
            self.master.destroy()
            return
Exemplo n.º 3
0
    def start_read(self):
        # 查找书签
        send_message(self.s, MessageType.startRead, self.user + '&' + self.bookname)
        msg = recv_message(self.s)
        if msg['type'] == MessageType.noBook:
            messagebox.showerror("Error", "No such book!")
            return
        elif msg['type'] == MessageType.pageNum:
            self.page_num = msg['parameters']
        else:
            messagebox.showerror("Error", "Can not receive bookmark! {}".format(msg['type']))
            return

        # 接收总页数
        msg = recv_message(self.s)
        if msg['type'] == MessageType.totalPage:
            self.total_num = msg['parameters']
        else:
            messagebox.showerror("Error", "Can not receive total page! {}".format(msg['type']))
            return

        # 接收章节列表
        msg = recv_message(self.s)
        if msg['type'] == MessageType.sendChapter:
            self.chapter = msg['parameters']
            self.total_chapter = len(self.chapter)
            self.chapter_num = self.get_chapter()
            self.chapbtn['text'] = self.chapter[self.chapter_num]
        else:
            messagebox.showerror("Error", "Can not receive chapter list! {}".format(msg['type']))
            return

        # 接收书签那一页
        msg = recv_message(self.s)
        if not msg:
            messagebox.showerror("Error", "Connection wrong...")
        elif msg['type'] == MessageType.sendPage:
            if msg['parameters'][0] == '#':
                msg['parameters'] = msg['parameters'][1:]
            self.text.insert(1.0, msg['parameters'])
        else:
            messagebox.showerror("Error", "Can not receive the text! {}".format(msg['type']))
        return
Exemplo n.º 4
0
 def get_booklist(self):
     send_message(self.s, MessageType.requireList)
     msg = recv_message(self.s)
     if not msg:
         messagebox.showerror("Error", "connection wrong")
         return
     if msg['type'] == MessageType.bookList:
         return msg['parameters']
     else:
         messagebox.showerror("请求失败", "服务器未返回书籍列表")
         return
Exemplo n.º 5
0
 def show_page(self):
     send_message(self.s, MessageType.requirePage, [self.bookname, self.page_num])
     msg = recv_message(self.s)
     if not msg:
         messagebox.showerror("Error", "Connection wrong!")
     elif msg['type'] == MessageType.sendPage:
         self.chapter_num = self.get_chapter()
         self.chapbtn['text'] = self.chapter[self.chapter_num][0]
         self.pagebtn['text'] = str(self.page_num + 1) + '/' + str(self.total_num + 1)
         self.text.delete('1.0', 'end')
         if msg['parameters'][0] == '#':
             msg['parameters'] = msg['parameters'][1:]
         self.text.insert(1.0, msg['parameters'])
     else:
         messagebox.showerror("Error", "Can not jump to the page {}".format(msg['type']))
     return