From d2303042d30c52650c256e542688681b8374bd50 Mon Sep 17 00:00:00 2001 From: yvesf Date: Tue, 9 Jun 2009 18:54:04 +0000 Subject: ahbla git-svn-id: http://xapek.org/svn/common/omegle@1093 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd --- chat_localhost.py | 6 +++ gui.py | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 chat_localhost.py create mode 100644 gui.py diff --git a/chat_localhost.py b/chat_localhost.py new file mode 100644 index 0000000..dcda24f --- /dev/null +++ b/chat_localhost.py @@ -0,0 +1,6 @@ +#!/usr/bin/python + +from chat import * + + +Chat(host="localhost:8082").main() diff --git a/gui.py b/gui.py new file mode 100644 index 0000000..9f81c69 --- /dev/null +++ b/gui.py @@ -0,0 +1,113 @@ +import urwid.curses_display +import urwid +from omegle import OmegleChat +import sys,time + +class Conversation(object): + def __init__(self): + self.column1_edit = urwid.Edit(caption="Send: ") + self.column1_check = urwid.CheckBox("Link to other",state=True,on_state_change=self.on_link1_changed) + self.column1_disconnect = urwid.Button("Connect", lambda x: + self.add_message(time.strftime("%H:%M:%S: ") + "FOO") + ) + self.column1 = urwid.ListBox([ + self.column1_edit, + self.column1_check, + urwid.AttrWrap(self.column1_disconnect,'button')]) + + self.column2_edit = urwid.Edit(caption="Send: ") + self.column2_check = urwid.CheckBox("Link to other",state=True,on_state_change=self.on_link2_changed) + self.column2_disconnect = urwid.Button("Connect", lambda x: + self.add_message(time.strftime("%H:%M:%S: ") + "FOO") + ) + self.column2 = urwid.ListBox([ + self.column2_edit, + self.column2_check, + urwid.AttrWrap(self.column2_disconnect,'button')]) + + self.columns = urwid.Columns([self.column1, self.column2]) + + self.messages = urwid.SimpleListWalker([urwid.Text("Nachricht:")]) + self.textbox = urwid.ListBox(self.messages) + self.body = urwid.Pile([self.columns,self.textbox]) + + self.widget_header = urwid.Text("F2 Toggle Link 1 | F3 Toggle Link 2 | | 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.columns), (self.columns, self.column1), (self.column1, 0)], + [(self.body,self.columns), (self.columns, self.column1), (self.column1, 1)], + [(self.body,self.columns), (self.columns, self.column1), (self.column1, 2)], + [(self.body,self.columns), (self.columns, self.column2), (self.column2, 0)], + [(self.body,self.columns), (self.columns, self.column2), (self.column2, 1)], + [(self.body,self.columns), (self.columns, self.column2), (self.column2, 2)], + ] + self.omegle1 = OmegleChat() + self.omegle2 = OmegleChat() + + def add_message(self,msg): + w=urwid.Text(msg) + self.messages.append(w) + self.textbox.set_focus(len(self.messages)) + 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() + + while True: + try: + keys = self.ui.get_input() + except KeyboardInterrupt: + sys.exit(0) + + for k in keys: + if k == "window resize": + size = self.ui.get_cols_rows() + elif k == "enter": + if self.body.get_focus() == self.columns \ + and self.columns.get_focus() == self.column1 \ + and self.column1.get_focus()[0] == self.column1_edit: + self.add_message(self.column1_edit.get_text()[0]) + elif self.body.get_focus() == self.columns \ + and self.columns.get_focus() == self.column2 \ + and self.column2.get_focus()[0] == self.column2_edit: + self.add_message(self.column2_edit.get_text()[0]) + else: + self.top.keypress( size, k ) + 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.column1_check.toggle_state() + elif k == "f3": + self.column2_check.toggle_state() + elif k == "f10": + sys.exit(0) + else: + self.top.keypress( size, k ) + + self.draw_screen( size ) + + def draw_screen(self, size): + canvas = self.top.render( size, focus=True ) + self.ui.draw_screen( size, canvas ) + + def on_link1_changed(self,a,b): + pass + def on_link2_changed(self,a,b): + pass + +Conversation().main() -- cgit v1.2.1