本文整理汇总了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)