diff options
author | Eduardo Silva <edsiper@monotop.(none)> | 2007-06-12 18:32:48 (GMT) |
---|---|---|
committer | Eduardo Silva <edsiper@monotop.(none)> | 2007-06-12 18:32:48 (GMT) |
commit | cc604e0815d77a5417fa5af50eeb5bdb4ffe32f6 (patch) | |
tree | 82278f57e3019a039415c3accec1dc3c917b0aa2 /services | |
parent | 7e8160871accd725c3be4f58dddc82bdbc9d3e93 (diff) |
Console: new nandflash status viewer
Diffstat (limited to 'services')
-rw-r--r-- | services/console/interface/xo/Makefile.am | 6 | ||||
-rw-r--r-- | services/console/interface/xo/battery.py | 15 | ||||
-rw-r--r-- | services/console/interface/xo/cpu.py | 10 | ||||
-rw-r--r-- | services/console/interface/xo/nandflash.py | 121 | ||||
-rw-r--r-- | services/console/interface/xo/xo.py | 25 | ||||
-rw-r--r-- | services/console/lib/graphics/box.py | 66 | ||||
-rw-r--r-- | services/console/lib/graphics/frequency.py | 25 |
7 files changed, 221 insertions, 47 deletions
diff --git a/services/console/interface/xo/Makefile.am b/services/console/interface/xo/Makefile.am index 202b14b..be9be79 100644 --- a/services/console/interface/xo/Makefile.am +++ b/services/console/interface/xo/Makefile.am @@ -4,7 +4,5 @@ sugar_PYTHON = \ xo.py \ cpu.py \ system.py \ - battery.py - - - + battery.py \ + nandflash.py diff --git a/services/console/interface/xo/battery.py b/services/console/interface/xo/battery.py index a5bff6b..98b7b82 100644 --- a/services/console/interface/xo/battery.py +++ b/services/console/interface/xo/battery.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' diff --git a/services/console/interface/xo/cpu.py b/services/console/interface/xo/cpu.py index 520725c..827a2a5 100644 --- a/services/console/interface/xo/cpu.py +++ b/services/console/interface/xo/cpu.py @@ -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 diff --git a/services/console/interface/xo/nandflash.py b/services/console/interface/xo/nandflash.py new file mode 100644 index 0000000..1049f41 --- /dev/null +++ b/services/console/interface/xo/nandflash.py @@ -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() +"""
\ No newline at end of file diff --git a/services/console/interface/xo/xo.py b/services/console/interface/xo/xo.py index 525ff71..487b965 100644 --- a/services/console/interface/xo/xo.py +++ b/services/console/interface/xo/xo.py @@ -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 + diff --git a/services/console/lib/graphics/box.py b/services/console/lib/graphics/box.py index f2363ac..6aec096 100644 --- a/services/console/lib/graphics/box.py +++ b/services/console/lib/graphics/box.py @@ -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() diff --git a/services/console/lib/graphics/frequency.py b/services/console/lib/graphics/frequency.py index 4e184c9..13ed859 100644 --- a/services/console/lib/graphics/frequency.py +++ b/services/console/lib/graphics/frequency.py @@ -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)) |