当前位置: 首页>>代码示例>>Python>>正文


Python Client.logout方法代码示例

本文整理汇总了Python中Client.Client.logout方法的典型用法代码示例。如果您正苦于以下问题:Python Client.logout方法的具体用法?Python Client.logout怎么用?Python Client.logout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Client.Client的用法示例。


在下文中一共展示了Client.logout方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ChatInterface

# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import logout [as 别名]
class ChatInterface(object):

    def __init__(self, host, port, username):
        '''
        Sets up and initializes
        '''
        self.host = host
        self.port = port
        self.username = username
        self.running = True
        self.client = Client(self)
        self.client.start(self.host, int(self.port))
        self.lock = Lock()
        self.NR_OF_MESSAGES_TO_DISPLAY = 15

        self.stdscr = None
        curses.wrapper(self.main)

    def main(self, stdscr):
        self.stdscr = stdscr
        curses.echo()
        self.client.login(self.username)
        time.sleep(1) #delay, in case of poor connection

        self.main_loop(stdscr)
    
    def main_loop(self, stdscr):
        while self.running:
            if self.client.logged_in:
                self.stdscr.clear()
                with self.lock:
                    self.display_messages()
                message = self.stdscr.getstr()
                self.parse(message)
                self.stdscr.refresh()
            else:
                self.stdscr.clear()
                for i in xrange(len(self.client.messages)):
                    self.stdscr.addstr(i, 0, self.client.messages[i])
                self.stdscr.addstr(self.NR_OF_MESSAGES_TO_DISPLAY, 0, '--> Please enter username to log in:')
                self.stdscr.move(self.NR_OF_MESSAGES_TO_DISPLAY + 1, 0)
                username = self.stdscr.getstr()
                self.client.login(username)
                self.stdscr.refresh()
                time.sleep(1)
    
    def display_messages(self):
        if self.client.messages:
            if len(self.client.messages) < self.NR_OF_MESSAGES_TO_DISPLAY:
                for i in xrange(len(self.client.messages)):
                    self.stdscr.addstr(i, 0, self.client.messages[i])
            else:
                for i in xrange(self.NR_OF_MESSAGES_TO_DISPLAY):
                    self.stdscr.addstr(i, 0, self.client.messages[len(self.client.messages) - (self.NR_OF_MESSAGES_TO_DISPLAY) + i])
        self.stdscr.addstr(self.NR_OF_MESSAGES_TO_DISPLAY, 0, '--> Enter a message:')
        self.stdscr.move(self.NR_OF_MESSAGES_TO_DISPLAY + 1, 0)
        self.stdscr.refresh()
        

    def parse(self, message):
        if message == 'logout':
            self.client.logout()
        else:
            self.client.send_message(message)
开发者ID:oyvindrobertsen,项目名称:fellesprosjekt,代码行数:66,代码来源:ChatInterface.py


注:本文中的Client.Client.logout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。