Console: new nandflash status viewer
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user