import urwid import urwid.curses_display import sys,time from omegle import OmegleChat class ConversationWindow(object): def __init__(self): self.edit = urwid.Edit(caption="Send: ",edit_text="Hi!",multiline=True) self.editbox = urwid.Filler(self.edit) self.messages = urwid.SimpleListWalker([]) self.textbox = urwid.ListBox(self.messages) self.body = urwid.Pile([('weight',1,self.editbox),('fixed',3,urwid.Filler(urwid.Divider('-'))),('weight',10,self.textbox)]) self.widget_header = urwid.Text("Omegle | F2 - Connect/Disconnect | F10 - EXIT") self.top = urwid.Frame(body=self.body, header=urwid.AttrWrap(self.widget_header,'header')) self.focus_ring = [ [(self.body,self.textbox)], [(self.body,self.editbox)]] def add_message(self,msg): w=urwid.Text(msg) self.messages.contents.append(w) self.textbox.set_focus(len(self.messages.contents)) def main(self): self.ui = urwid.curses_display.Screen() self.ui.register_palette([ ('header', 'black', 'dark cyan', 'standout'), ('button', 'white', 'dark blue', 'standout'), ('keylabel', 'white', 'dark cyan', 'standout'), ]) self.ui.run_wrapper( self.run ) def run(self): size = self.ui.get_cols_rows() running=True try: while running: keys = self.ui.get_input() for k in keys: if k == "window resize": size = self.ui.get_cols_rows() elif k == "enter": if self.body.get_focus() == self.editbox: self.on_send(self.edit.get_edit_text()) else: pass elif k == "tab": self.focus_ring.reverse() elem = self.focus_ring.pop() for pair in elem: pair[0].set_focus(pair[1]) self.focus_ring.insert(0,elem) self.focus_ring.reverse() elif k == "f2": self.on_toggle_connect() elif k == "f10": self.on_exit() else: self.top.keypress( size, k ) self.draw_screen( size ) except KeyboardInterrupt: pass def draw_screen(self, size): canvas = self.top.render( size, focus=True ) self.ui.draw_screen( size, canvas ) def on_send(self,message): self.add_message("DEBUG: on_column1_send message=%s"%message) def on_exit(self): sys.exit(0) def on_toggle_connect(self): pass class Omegle(OmegleChat): def __init__(self,chatwindow,host="omegle.com"): OmegleChat.__init__(self,host=host) self.chatwindow = chatwindow def on_message(self,message): self.chatwindow.add_message("%s Stranger: %s"%(time.strftime("%H:%M:%S"), message)) def on_connect(self): self.chatwindow.add_message("Connected") def on_typing(self): self.chatwindow.add_message("Stranger typing") def on_stopped_typing(self): self.chatwindow.add_message("Stranger stopped typing") def on_disconnect(self): self.chatwindow.add_message("Stranger disconnected") def on_wait(self): self.chatwindow.add_message("Server send Wait") class Chat(ConversationWindow): def __init__(self,host="omegle.com"): print "Chat(host=%s)" % (host) ConversationWindow.__init__(self) self.omegle = Omegle(self,host=host) def on_toggle_connect(self): if self.omegle.is_connected: self.add_message("Initiating disconnect") self.omegle.disconnect() else: self.add_message("Initiating connect") self.omegle.start() def on_exit(self): if self.omegle.is_connected: self.omegle.disconnect() sys.exit(0) def on_send(self,message): if self.omegle.is_confirmed: self.add_message("%s You: %s"%(time.strftime("%H:%M:%S"), message)) self.omegle.send(message) self.edit.set_edit_text("") else: self.add_message("Not connected/confirmed") if __name__ == "__main__": import logging logging.basicConfig(filename="chat.py.log",level=logging.DEBUG) Chat(host="localhost:8082").main() """ Unterstuetzt im moment noch nicht das senden des /typing partner sieht nicht wenn man tippt """