username = data['username'] color = random.choice(COLORS) userdata[client] = (username, color) client.hide('div#signin') client.show('div#chat') broadcast(username + ' entered the room.', color) client.jquery('input[name=message]', 'focus') @connect('div#chat form submit') def talk(client, data): username, color = userdata[client] client.set_val('input[name=message]', '') broadcast(username + ': ' + data['message'], color) @connect('connection_lost') def logoff(client, data): username, color = userdata.get(client) if username: del userdata[client] broadcast(username + ' left the room.', color) def broadcast(message, color): message = cgi.escape(message) for client in userdata.keys(): client.append_html('#messages', '<p style="color: {}">{}</p>'.format( color, message)) if __name__ == '__main__': app.run()
demo_dir = op.join(FILEBASE, div.get('demo')) div.set('demo', demo_dir) files = (f for f in os.listdir(demo_dir) if not f.startswith('.')) ul = E.UL(*(E.LI(E.A(f, href=op.join(demo_dir, f))) for f in files)) div.append(ul) def replace(el1, el2): parent = el1.getparent() parent.replace(el1, el2) @tulip.task def watch_input_file(): mtime = op.getmtime(FILENAME) while True: new_mtime = op.getmtime(FILENAME) if new_mtime > mtime: render_slides() mtime = new_mtime print('Updated page at {}'.format(time.ctime())) yield from tulip.sleep(.5) if __name__ == '__main__': app.run(port=9000, call_soon=watch_input_file)
demo_dir = op.join(FILEBASE, div.get('demo')) div.set('demo', demo_dir) files = (f for f in os.listdir(demo_dir) if not f.startswith('.')) ul = E.UL( *(E.LI(E.A(f, href=op.join(demo_dir, f))) for f in files) ) div.append(ul) def replace(el1, el2): parent = el1.getparent() parent.replace(el1, el2) @tulip.task def watch_input_file(): mtime = op.getmtime(FILENAME) while True: new_mtime = op.getmtime(FILENAME) if new_mtime > mtime: render_slides() mtime = new_mtime print('Updated page at {}'.format(time.ctime())) yield from tulip.sleep(.5) if __name__ == '__main__': app.run(port=9000, call_soon=watch_input_file)