summaryrefslogtreecommitdiff
path: root/gui.py
blob: 7f38b65002f4bef369e7dd81caffc5cf3c1ed651 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import urwid.curses_display
import urwid

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 = 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)
		self.column2_disconnect = urwid.Button("Disconnect", lambda x: self.text.set_text("Disconnect"))
		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.text = urwid.Text("Bla bal asdasd")
		self.body = urwid.ListBox([urwid.Text("bla"), self.columns])

		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)],
		]

	def main(self):
		self.ui = urwid.curses_display.Screen()
		self.ui.register_palette([
			('header', 'black', 'dark cyan', 'standout'),
			('button', 'white', 'dark blue', 'standout'),
#			('I say', 'default', 'default', 'bold'),
			])
		self.ui.run_wrapper( self.run )
	
	def run(self):
		size = self.ui.get_cols_rows()

		while True:
			keys = self.ui.get_input()
			if "f8" in keys:
				break
			for k in keys:
				if k == "window resize":
					size = self.ui.get_cols_rows()
				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()
				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 )

Conversation().main()