Esempio n. 1
0
class MultiGraphDisplay:
	def __init__(self, cols, urwid_ui):
		if urwid_ui == "smoothed":
			smoothed = True
			self.palette = self.smoothed_palette
		else:
			smoothed = False
			self.palette = self.blocky_palette
		self.displays = []
		l = []
		for c in cols:
			a = []
			for tap in c:
				if tap.ftype == 'file_exp':
					d = GraphDisplayProgress(tap, smoothed)
				else:
					d = GraphDisplay(tap, smoothed)
				a.append(d)
				self.displays.append(d)
			l.append(a)
			
		graphs = urwid.Columns( [BoxPile(a) for a in l], 1 )
		graphs = urwid.AttrWrap( graphs, 'background' )
		title = urwid.Text("Speedometer "+__version__)
		title = urwid.AttrWrap( urwid.Filler( title ), 'title' )
		self.top = urwid.Overlay( title, graphs,
			('fixed left', 0), 16, ('fixed top', 0), 1 )

		self.urwid_ui = urwid_ui

	blocky_palette = [
		('background', 'dark gray', 'black'),
		('reading', 'light gray', 'black'),
		('1MB/s',   'dark cyan','light gray','standout'),
		('32KB/s',  'light gray', 'dark cyan','standout'),
		('1KB/s',   'dark blue','dark cyan','standout'),
		('32B/s',   'light cyan','dark blue','standout'),
		('bar:num', 'light gray', 'black' ),
		('ca:background', 'light gray','black'),
		('ca:c',    'yellow','black','standout'),
		('ca:a',    'dark gray','black','standout'),
		('ca:c:num','yellow','black','standout'),
		('ca:a:num','dark gray','black','standout'),
		('title',   'white', 'black','underline'),
		('pr:n',    'white', 'dark blue'),
		('pr:c',    'white', 'dark green','standout'),]
	
	smoothed_palette = [
		('background', 'dark gray', 'black'),
		('reading', 'light gray', 'black'),
		('bar:top', 'dark cyan', 'black' ),
		('bar',     'black', 'dark cyan','standout'),
		('bar:num', 'dark cyan', 'black' ),
		('ca:background', 'light gray','black'),
		('ca:c:top','dark blue','black'),
		('ca:c',    'black','dark blue','standout'),
		('ca:c:num','light blue','black'),
		('ca:a:top','light gray','black'),
		('ca:a',    'black','light gray','standout'),
		('ca:a:num','light gray', 'black'),
		('title',   'white', 'black','underline'),
		('pr:n',    'white', 'dark blue'),
		('pr:c',    'white', 'dark green','standout'),
		('pr:cn',   'dark green', 'dark blue'),
		]
		
		
	def main(self):
		self.ui = Screen()
		self.ui.set_input_timeouts( max_wait=INTERVAL_DELAY )
		
		self.ui.register_palette(self.palette)
		self.ui.run_wrapper( self.run )
	
	def run(self):
		try:
			self.update_readings()
		except EndOfData:
			return
		time.sleep(INITIAL_DELAY)
		resizing = False
		
		size = self.ui.get_cols_rows()
		while True:
			if not resizing:
				try:
					self.update_readings()
				except EndOfData:
					self.end_of_data()
					return
			resizing = False
			
			self.draw_screen(size)

			if isinstance(time,SimulatedTime):
				time.sleep( INTERVAL_DELAY )
				continue
				
			keys = self.ui.get_input()
			for k in keys:
				if k == "window resize":
					size = self.ui.get_cols_rows()
					resizing = True
				else:
					return
	
	def update_readings(self):
		for d in self.displays:
			d.update_readings()
	
	def end_of_data(self):
		# pause for taking screenshot of simulated data
		if isinstance(time, SimulatedTime):
			while not self.ui.get_input():
				pass

	def draw_screen(self, size):
		canvas = self.top.render( size, focus=True )
		self.ui.draw_screen( size, canvas )