summaryrefslogtreecommitdiff
path: root/gui.py
diff options
context:
space:
mode:
Diffstat (limited to 'gui.py')
-rw-r--r--gui.py43
1 files changed, 34 insertions, 9 deletions
diff --git a/gui.py b/gui.py
index 7f38b65..93a14c0 100644
--- a/gui.py
+++ b/gui.py
@@ -1,11 +1,14 @@
import urwid.curses_display
import urwid
+import time
class Conversation(object):
def __init__(self):
self.column1_edit = urwid.Edit(caption="Send: ")
self.column1_check = urwid.CheckBox("Link to other",state=True)
- self.column1_disconnect = urwid.Button("Disconnect", lambda x: self.text.set_text("Disconnect"))
+ self.column1_disconnect = urwid.Button("Disconnect", lambda x:
+ self.add_message(time.strftime("%H:%M:%S: ") + "FOO")
+ )
self.column1 = urwid.ListBox([
self.column1_edit,
self.column1_check,
@@ -13,27 +16,38 @@ class Conversation(object):
self.column2_edit = urwid.Edit(caption="Send: ")
self.column2_check = urwid.CheckBox("Link to other",state=True)
- self.column2_disconnect = urwid.Button("Disconnect", lambda x: self.text.set_text("Disconnect"))
+ self.column2_disconnect = urwid.Button("Disconnect", 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],box_columns=[0,1])
+ self.columns = urwid.Columns([self.column1, self.column2])
- self.text = urwid.Text("Bla bal asdasd")
- self.body = urwid.ListBox([urwid.Text("bla"), self.columns])
+ self.messages = urwid.SimpleListWalker([urwid.Text("bbalasdasd"), urwid.Text("blasasd")])
+ self.textbox = urwid.ListBox(self.messages)
+ self.body = urwid.Pile([self.columns,self.textbox])
self.widget_header = urwid.Text("F1 ... | ... | F8 - EXIT")
self.top = urwid.Frame(body=self.body, header=urwid.AttrWrap(self.widget_header,'header'))
- self.focus_ring = [ [(self.body,1), (self.columns, self.column1), (self.column1, 1)],
- [(self.body,1), (self.columns, self.column1), (self.column1, 2)],
- [(self.body,1), (self.columns, self.column2), (self.column2, 1)],
- [(self.body,1), (self.columns, self.column2), (self.column2, 2)],
+ 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)],
]
+ 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([
@@ -53,6 +67,17 @@ class Conversation(object):
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()