Console: new nandflash status viewer
This commit is contained in:
		
							parent
							
								
									7e8160871a
								
							
						
					
					
						commit
						cc604e0815
					
				| @ -4,7 +4,5 @@ sugar_PYTHON =				\ | ||||
| 	xo.py				\
 | ||||
| 	cpu.py				\
 | ||||
| 	system.py			\
 | ||||
| 	battery.py | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 	battery.py			\
 | ||||
| 	nandflash.py | ||||
|  | ||||
| @ -27,7 +27,8 @@ class XO_Battery(gtk.Fixed): | ||||
|     def __init__(self): | ||||
|         gtk.Fixed.__init__(self) | ||||
| 
 | ||||
|         self.frame = gtk.Frame('Battery Status') | ||||
|         self._frame_text = 'Battery Status' | ||||
|         self.frame = gtk.Frame(self._frame_text) | ||||
|         self.set_border_width(10) | ||||
|                  | ||||
|         self._battery_charge = self._get_battery_status() | ||||
| @ -76,20 +77,16 @@ class XO_Battery(gtk.Fixed): | ||||
|         self.add(self.frame) | ||||
|         self.show_all() | ||||
| 
 | ||||
|         # Update every 2 seconds | ||||
|         gobject.timeout_add(2000, self._update_battery_status) | ||||
|          | ||||
|     def _update_battery_status(self): | ||||
|     def update_status(self): | ||||
|          | ||||
|         new_charge = self._get_battery_status() | ||||
|          | ||||
|         frame_label = str(self._battery_charge) + '%' | ||||
| 
 | ||||
|         if new_charge != self._battery_charge: | ||||
|             self._battery_charge = self._get_battery_status() | ||||
|             self.label_charge_value.set_text(str(self._battery_charge) + '%') | ||||
|             self.label_charge_value.set_text(frame_label) | ||||
|             self._battery_box.set_capacity(self._battery_charge) | ||||
| 
 | ||||
|         return True | ||||
| 
 | ||||
|     def _get_battery_status(self): | ||||
|         battery_class_path = '/sys/class/battery/psu_0/' | ||||
|         capacity_path = battery_class_path + 'capacity_percentage' | ||||
|  | ||||
| @ -75,7 +75,7 @@ class CPU_Usage: | ||||
| 
 | ||||
|         self._times +=1 | ||||
|         self._last_jiffies = used_jiffies | ||||
|          | ||||
| 
 | ||||
|         return pcpu | ||||
| 
 | ||||
| class XO_CPU(gtk.Frame): | ||||
| @ -85,7 +85,6 @@ class XO_CPU(gtk.Frame): | ||||
|         gtk.Frame.__init__(self, 'System CPU Usage') | ||||
|         self.set_border_width(10) | ||||
| 
 | ||||
|         self._updated = False | ||||
|         width = (gtk.gdk.screen_width() * 99 / 100) - 50 | ||||
|         height = (gtk.gdk.screen_height() * 15 / 100) - 20 | ||||
| 
 | ||||
| @ -100,15 +99,16 @@ class XO_CPU(gtk.Frame): | ||||
|         self.add(fixed) | ||||
| 
 | ||||
|         self._DRW_CPU = CPU_Usage() | ||||
|         self._DRW_CPU.frequency = 1000 # 1 Second | ||||
|         self._DRW_CPU.frequency = 1200 # 1 Second | ||||
| 
 | ||||
|         gobject.timeout_add(self._DRW_CPU.frequency, self._update_cpu_usage) | ||||
| 
 | ||||
|     def _update_cpu_usage(self): | ||||
|         print "update XO CPU" | ||||
|         self._cpu = self._DRW_CPU._get_CPU_usage() | ||||
|         self._updated = True | ||||
| 
 | ||||
|         self.set_label('System CPU Usage: ' + str(self._cpu) + '%') | ||||
| 
 | ||||
|         # Draw the value into the graphic | ||||
|         self._graphic.draw_value(self._cpu) | ||||
| 
 | ||||
|         return True | ||||
|  | ||||
							
								
								
									
										121
									
								
								services/console/interface/xo/nandflash.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										121
									
								
								services/console/interface/xo/nandflash.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,121 @@ | ||||
| #!/usr/bin/env python | ||||
| 
 | ||||
| # Copyright (C) 2007, Eduardo Silva (edsiper@gmail.com). | ||||
| # | ||||
| # This program is free software; you can redistribute it and/or modify | ||||
| # it under the terms of the GNU General Public License as published by | ||||
| # the Free Software Foundation; either version 2 of the License, or | ||||
| # (at your option) any later version. | ||||
| # | ||||
| # This program is distributed in the hope that it will be useful, | ||||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| # GNU General Public License for more details. | ||||
| # | ||||
| # You should have received a copy of the GNU General Public License | ||||
| # along with this program; if not, write to the Free Software | ||||
| # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA | ||||
| 
 | ||||
| import gtk | ||||
| import gobject | ||||
| 
 | ||||
| from os import statvfs | ||||
| from label import Label | ||||
| from graphics.box import * | ||||
| 
 | ||||
| class XO_NandFlash(gtk.Fixed): | ||||
|     _MOUNT_POINT = '/' | ||||
| 
 | ||||
|     def __init__(self): | ||||
|         gtk.Fixed.__init__(self) | ||||
|          | ||||
|         self._frame_text = 'Nand Flash' | ||||
|         self._frame = gtk.Frame(self._frame_text) | ||||
|         self.set_border_width(10) | ||||
|          | ||||
| 
 | ||||
|         self._nandflash_box = BoxGraphic(color_mode=COLOR_MODE_REVERSE) | ||||
|         self._nandflash_box.set_size_request(70, 150) | ||||
| 
 | ||||
|         fixed = gtk.Fixed(); | ||||
|         fixed.set_border_width(10) | ||||
|         fixed.add(self._nandflash_box) | ||||
| 
 | ||||
|         hbox = gtk.HBox(False, 0) | ||||
|         hbox.pack_start(fixed, False, False, 4) | ||||
| 
 | ||||
|         # Battery info | ||||
|         table = gtk.Table(2, 3) | ||||
|         table.set_border_width(5) | ||||
|         table.set_col_spacings(7) | ||||
|         table.set_row_spacings(7) | ||||
| 
 | ||||
|         label_total_size = Label('Total: ' , Label.DESCRIPTION) | ||||
|         self._label_total_value = Label('0 KB', Label.DESCRIPTION) | ||||
| 
 | ||||
|         label_used_size = Label('Used: ' , Label.DESCRIPTION) | ||||
|         self._label_used_value = Label('0 KB', Label.DESCRIPTION) | ||||
| 
 | ||||
|         label_free_size = Label('Free: ' , Label.DESCRIPTION) | ||||
|         self._label_free_value = Label('0 KB', Label.DESCRIPTION) | ||||
| 
 | ||||
|         # Total | ||||
|         table.attach(label_total_size, 0, 1, 0, 1) | ||||
|         table.attach(self._label_total_value, 1,2, 0,1) | ||||
|         # Used | ||||
|         table.attach(label_used_size, 0, 2, 1, 2) | ||||
|         table.attach(self._label_used_value, 1,3, 1,2) | ||||
|         # Free | ||||
|         table.attach(label_free_size, 0, 3, 2, 3) | ||||
|         table.attach(self._label_free_value, 1,4, 2,3) | ||||
| 
 | ||||
|         alignment = gtk.Alignment(0,0,0,0) | ||||
|         alignment.add(table) | ||||
| 
 | ||||
|         hbox.pack_start(alignment, False, False, 0) | ||||
|         self._frame.add(hbox) | ||||
|         self.add(self._frame) | ||||
|         self.show() | ||||
|         self.update_status() | ||||
| 
 | ||||
|     def update_status(self): | ||||
|         nand = StorageDevice(self._MOUNT_POINT) | ||||
| 
 | ||||
|         # Byte values | ||||
|         total = (nand.f_bsize*nand.f_blocks) | ||||
|         free = (nand.f_bsize*nand.f_bavail) | ||||
|         used = (total - free) | ||||
| 
 | ||||
|         self._label_total_value.set_label(str(total/1024) + ' KB') | ||||
|         self._label_used_value.set_label(str(used/1024) + ' KB') | ||||
|         self._label_free_value.set_label(str(free/1024) + ' KB') | ||||
|         self._usage_percent = ((used*100)/total) | ||||
|          | ||||
|         frame_label = self._frame_text + ': ' + str(self._usage_percent) + '%' | ||||
|         self._frame.set_label(frame_label) | ||||
|         self._nandflash_box.set_capacity(self._usage_percent) | ||||
| 
 | ||||
| class StorageDevice: | ||||
|     f_bsize = 0 | ||||
|     f_frsize = 0 | ||||
|     f_blocks = 0 | ||||
|     f_bfree = 0 | ||||
|     f_bavail = 0 | ||||
|     f_files = 0 | ||||
|     f_ffree = 0 | ||||
|     f_favail = 0 | ||||
|     f_flag = 0 | ||||
|     f_namemax = 0 | ||||
| 
 | ||||
|     def __init__(self, mount_point): | ||||
|         self.f_bsize, self.f_frsize, self.f_blocks, self.f_bfree, \ | ||||
|             self.f_bavail, self.f_files, self.f_ffree, \ | ||||
|             self.f_favail, self.f_flag, self.f_namemax = statvfs(mount_point) | ||||
| 
 | ||||
| """ | ||||
| w = gtk.Window() | ||||
| a = XO_NandFlash() | ||||
| w.add(a) | ||||
| w.show_all() | ||||
| gtk.main() | ||||
| """ | ||||
| @ -26,13 +26,13 @@ import string | ||||
| from cpu import XO_CPU | ||||
| from system import XO_System | ||||
| from battery import XO_Battery | ||||
| from nandflash import XO_NandFlash | ||||
| 
 | ||||
| class Interface: | ||||
|          | ||||
|     def __init__(self): | ||||
|          | ||||
|         self.widget = self.vbox = gtk.VBox(False, 3) | ||||
|          | ||||
| 
 | ||||
|         # System information | ||||
|         xo_system = XO_System() | ||||
|         self.vbox.pack_start(xo_system, False, False, 0) | ||||
| @ -41,8 +41,23 @@ class Interface: | ||||
|         xo_cpu = XO_CPU() | ||||
|         self.vbox.pack_start(xo_cpu, False, False, 0) | ||||
| 
 | ||||
|         # Battery Status / Graph | ||||
|         xo_battery = XO_Battery() | ||||
|         self.vbox.pack_start(xo_battery, False, False, 0) | ||||
|         # Graphics: Battery Status, NandFlash | ||||
|         self._xo_battery = XO_Battery() | ||||
|         self._xo_nandflash = XO_NandFlash() | ||||
| 
 | ||||
|         hbox = gtk.HBox(False, 2) | ||||
|         hbox.pack_start(self._xo_battery, False, False, 0) | ||||
|         hbox.pack_start(self._xo_nandflash, False, False, 0) | ||||
| 
 | ||||
|         self.vbox.pack_start(hbox, False, False, 0) | ||||
|         self.vbox.show_all() | ||||
| 
 | ||||
|         # Update every 5 seconds | ||||
|         gobject.timeout_add(5000, self._update_components) | ||||
| 
 | ||||
|     def _update_components(self): | ||||
|         self._xo_battery.update_status() | ||||
|         self._xo_nandflash.update_status() | ||||
| 
 | ||||
|         return True | ||||
| 
 | ||||
|  | ||||
| @ -17,14 +17,34 @@ | ||||
| # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA | ||||
| 
 | ||||
| import gtk | ||||
| import gobject | ||||
| import cairo | ||||
| 
 | ||||
| COLOR_MODE_NORMAL = 0 | ||||
| COLOR_MODE_REVERSE = 1 | ||||
| 
 | ||||
| class BoxGraphic(gtk.DrawingArea): | ||||
|     def __init__(self): | ||||
|     __gtype_name__ = 'ConsoleBoxGraphic' | ||||
| 
 | ||||
|     __gproperties__ = { | ||||
|         'color-mode': (gobject.TYPE_INT, None, None, 0, 1, COLOR_MODE_NORMAL, | ||||
|                     gobject.PARAM_READWRITE | gobject.PARAM_CONSTRUCT_ONLY) | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     _color_status_high = [0, 0, 0] | ||||
|     _color_status_medium = [0, 0, 0] | ||||
|     _color_status_low = [0, 0, 0] | ||||
| 
 | ||||
|     _limit_high = 0 | ||||
|     _limit_medium = 0 | ||||
|     _limit_low = 0 | ||||
| 
 | ||||
|     def __init__(self, **kwargs): | ||||
|         gobject.GObject.__init__(self, **kwargs) | ||||
|         gtk.DrawingArea.__init__(self) | ||||
|         self.connect("expose-event", self.do_expose) | ||||
|         self.connect('size-allocate', self._change_size_cb) | ||||
|         self.set_capacity(0) | ||||
| 
 | ||||
|     def do_expose(self, widget, event): | ||||
|         context = widget.window.cairo_create() | ||||
| @ -33,27 +53,47 @@ class BoxGraphic(gtk.DrawingArea): | ||||
|         context.set_source_rgb (0,0,0) | ||||
|         context.fill_preserve() | ||||
|         context.stroke() | ||||
|          | ||||
|         print self._percent | ||||
| 
 | ||||
|         self._draw_content(context, self._percent) | ||||
| 
 | ||||
|     def do_set_property(self, pspec, value): | ||||
|         if pspec.name == 'color-mode': | ||||
|             self._configure(mode=value) | ||||
|         else: | ||||
|             raise AssertionError | ||||
| 
 | ||||
|     def set_capacity(self, percent): | ||||
|         self._percent = percent | ||||
|         self.queue_draw() | ||||
| 
 | ||||
|     def _configure(self, mode): | ||||
|         # Normal mode configure the box as a battery | ||||
|         # full is good, empty is bad | ||||
|         if mode == COLOR_MODE_NORMAL: | ||||
|             self._color_status_high = [0, 1, 0] | ||||
|             self._color_status_medium = [1,1,0] | ||||
|             self._color_status_low = [1,0,0] | ||||
|             self._limit_high = 60 | ||||
|             self._limit_medium = 10 | ||||
|         # Reverse mode configure the box as a storage device | ||||
|         # full is bad, empty is good | ||||
|         elif mode == COLOR_MODE_REVERSE: | ||||
|             self._color_status_high = [1,0,0]  | ||||
|             self._color_status_medium = [1,1,0] | ||||
|             self._color_status_low = [0, 1, 0] | ||||
|             self._limit_high = 85 | ||||
|             self._limit_medium = 40 | ||||
| 
 | ||||
|     def _draw_content(self, context, percent): | ||||
|         usage_height = (percent*self._height)/100 | ||||
| 
 | ||||
|         context.rectangle(0, self._height - usage_height, self._width, self._height) | ||||
| 
 | ||||
|         if self._percent > 50: | ||||
|             context.set_source_rgb (0,1,0) | ||||
| 
 | ||||
|         if self._percent > 10 and self._percent <= 50: | ||||
|             context.set_source_rgb (1,1,0) | ||||
| 
 | ||||
|         if self._percent <= 10: | ||||
|             context.set_source_rgb (1,0,0) | ||||
|         if self._percent > self._limit_high: | ||||
|             context.set_source_rgb(*self._color_status_high) | ||||
|         elif self._percent >= self._limit_medium and self._percent <= self._limit_high: | ||||
|             context.set_source_rgb(*self._color_status_medium) | ||||
|         elif self._percent < self._limit_medium: | ||||
|             context.set_source_rgb(*self._color_status_low) | ||||
| 
 | ||||
|         context.fill_preserve() | ||||
| 
 | ||||
|  | ||||
| @ -41,9 +41,8 @@ class HorizontalGraphic(gtk.DrawingArea): | ||||
| 
 | ||||
|         if event.area.x == 0: | ||||
|             draw_all = True | ||||
| 
 | ||||
|             self._draw_border_lines(context) | ||||
|             context.stroke()             | ||||
|             context.stroke() | ||||
|         else: | ||||
|             draw_all = False | ||||
|             context.rectangle(event.area.x, event.area.y, event.area.width, event.area.height) | ||||
| @ -75,9 +74,9 @@ class HorizontalGraphic(gtk.DrawingArea): | ||||
|             height = self._height | ||||
|             width = self._width | ||||
|         else: | ||||
|             area_x = (length*self._GRAPH_OFFSET) | ||||
|             area_x = self._graph_x + (length*self._GRAPH_OFFSET) | ||||
|             area_y = self._graph_y | ||||
|             width = self._GRAPH_OFFSET * 2 | ||||
|             width = self._GRAPH_OFFSET*2 | ||||
|             height = self._graph_height | ||||
| 
 | ||||
|         self.queue_draw_area(area_x, area_y, width, height) | ||||
| @ -115,8 +114,8 @@ class HorizontalGraphic(gtk.DrawingArea): | ||||
| 
 | ||||
|         for percent in self._buffer[buffer_offset:length]: | ||||
|             if buffer_offset == 0: | ||||
|                 from_y = self._height - self._GRAPH_OFFSET | ||||
|                 from_x = self._GRAPH_OFFSET | ||||
|                 from_y = self._get_y(self._buffer[0]) | ||||
|                 from_x = self._graph_x | ||||
|             else: | ||||
|                 from_y = self._get_y(self._buffer[buffer_offset-1]) | ||||
|                 from_x = (freq * self._GRAPH_OFFSET) | ||||
| @ -131,14 +130,18 @@ class HorizontalGraphic(gtk.DrawingArea): | ||||
|         context.stroke() | ||||
| 
 | ||||
|     def _get_y(self, percent): | ||||
|         y_value = self._GRAPH_OFFSET + (self._graph_height - ((percent*self._graph_height)/100)) | ||||
|         return int(y_value)  | ||||
|         if percent==0: | ||||
|             percent = 1 | ||||
|          | ||||
|         graph_y = ((self._height)/(100 - 1))*(percent - 1) | ||||
|         y = self._LINE_WIDTH + abs(abs(self._height - graph_y) - self._MARGIN*2) | ||||
|         return int(y) | ||||
| 
 | ||||
|     def _change_size_cb(self, widget, allocation): | ||||
|         self._width = allocation.width | ||||
|         self._height = allocation.height | ||||
| 
 | ||||
|         self._graph_x = self._MARGIN + self._LINE_WIDTH | ||||
|         self._graph_y = self._MARGIN + self._LINE_WIDTH | ||||
|         self._graph_width = self._width - (self._MARGIN + self._LINE_WIDTH) | ||||
|         self._graph_height = self._height - ((self._MARGIN + self._LINE_WIDTH)*2) | ||||
|         self._graph_y = self._MARGIN | ||||
|         self._graph_width = self._width - (self._MARGIN*2 + self._LINE_WIDTH) | ||||
|         self._graph_height = self._height - ((self._MARGIN*2 + self._LINE_WIDTH)) | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Eduardo Silva
						Eduardo Silva