summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd>2009-05-29 14:32:57 +0000
committeryvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd>2009-05-29 14:32:57 +0000
commit6af8df1a442dcac86ba8d21c23c01677fb81121e (patch)
tree17552db2cb149f690d1f549fd4a3dc52b444fa24
parent2f908ad94636bed6fe1a20dfcfd7049bacf4a153 (diff)
downloadomegle-6af8df1a442dcac86ba8d21c23c01677fb81121e.tar.gz
omegle-6af8df1a442dcac86ba8d21c23c01677fb81121e.zip
gui
git-svn-id: http://xapek.org/svn/common/omegle@1038 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd
-rw-r--r--gui.py102
1 files changed, 56 insertions, 46 deletions
diff --git a/gui.py b/gui.py
index 9fe06ab..2af9f62 100644
--- a/gui.py
+++ b/gui.py
@@ -6,9 +6,7 @@ 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("Disconnect", lambda x:
- self.add_message(time.strftime("%H:%M:%S: ") + "FOO")
- )
+ self.column1_disconnect = urwid.Button("Disconnect", self.on_column1_disconnect)
self.column1 = urwid.ListBox([
self.column1_edit,
self.column1_check,
@@ -16,9 +14,7 @@ class Conversation(object):
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("Disconnect", lambda x:
- self.add_message(time.strftime("%H:%M:%S: ") + "FOO")
- )
+ self.column2_disconnect = urwid.Button("Disconnect", self.on_column1_disconnect)
self.column2 = urwid.ListBox([
self.column2_edit,
self.column2_check,
@@ -46,8 +42,9 @@ class Conversation(object):
def add_message(self,msg):
w=urwid.Text(msg)
- self.messages.append(w)
- self.textbox.set_focus(len(self.messages))
+ 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([
@@ -59,52 +56,65 @@ class Conversation(object):
def run(self):
size = self.ui.get_cols_rows()
-
- while True:
- try:
+ running=True
+ try:
+ while running:
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])
+
+ 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.on_column1_send(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.on_column2_send(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":
+ running=False
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 )
+
+ 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_link1_changed(self,a,b):
- pass
+ def on_link1_changed(self,*args):
+ self.add_message("DEBUG: on_link1_changed")
+
def on_link2_changed(self,a,b):
- pass
+ self.add_message("DEBUG: on_link2_changed")
+
+ def on_column1_send(self,message):
+ self.add_message("DEBUG: on_column1_send message=%s"%message)
+
+ def on_column2_send(self,message):
+ self.add_message("DEBUG: on_column2_send message=%s"%message)
+
+ def on_column1_disconnect(self,*args):
+ self.add_message("DEBUG: on_column1_disconnect")
+
+ def on_column2_disconnect(self,*args):
+ self.add_message("DEBUG: on_column2_disconnect")
Conversation().main()