Console: new battery status box
This commit is contained in:
parent
361581c0d1
commit
29d23cbe77
@ -10,7 +10,8 @@ $(service_DATA): $(service_in_files) Makefile
|
||||
sugardir = $(pkgdatadir)/services/console
|
||||
sugar_PYTHON = \
|
||||
__init__.py \
|
||||
console.py
|
||||
console.py \
|
||||
label.py
|
||||
|
||||
bin_SCRIPTS = sugar-console
|
||||
|
||||
|
@ -24,6 +24,7 @@ import sys
|
||||
import gtk
|
||||
import gobject
|
||||
|
||||
sys.path.append(os.path.dirname(__file__))
|
||||
sys.path.append(os.path.dirname(__file__) + '/lib')
|
||||
sys.path.append(os.path.dirname(__file__) + '/interface')
|
||||
|
||||
@ -71,8 +72,7 @@ class Console:
|
||||
self.notebook.append_page(widget, gtk.Label(label))
|
||||
|
||||
def _delete_event_cb(self, window, gdkevent):
|
||||
window.hide()
|
||||
return True
|
||||
gtk.main_quit()
|
||||
|
||||
class Service(dbus.service.Object):
|
||||
def __init__(self, bus, object_path=CONSOLE_PATH):
|
||||
|
@ -4,6 +4,8 @@ sugar_PYTHON = \
|
||||
drwarea.py \
|
||||
xo.py \
|
||||
cpu.py \
|
||||
system.py
|
||||
system.py \
|
||||
battery.py
|
||||
|
||||
|
||||
|
||||
|
128
services/console/interface/xo/battery.py
Normal file
128
services/console/interface/xo/battery.py
Normal file
@ -0,0 +1,128 @@
|
||||
#!/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 label import Label
|
||||
|
||||
class XO_Battery(gtk.Fixed):
|
||||
|
||||
def __init__(self):
|
||||
gtk.Fixed.__init__(self)
|
||||
|
||||
self.frame = gtk.Frame('Battery Status')
|
||||
self.set_border_width(10)
|
||||
|
||||
self._battery_charge = self._get_battery_status()
|
||||
|
||||
self._battery_drw = gtk.DrawingArea()
|
||||
self._battery_drw.set_size_request(70, 150)
|
||||
self._battery_drw.connect("expose-event", self.do_expose)
|
||||
|
||||
fixed = gtk.Fixed();
|
||||
fixed.set_border_width(10)
|
||||
fixed.add(self._battery_drw)
|
||||
|
||||
hbox = gtk.HBox(False, 0)
|
||||
hbox.pack_start(fixed, False, False, 4)
|
||||
|
||||
# Battery info
|
||||
table = gtk.Table(2, 2)
|
||||
table.set_border_width(5)
|
||||
table.set_col_spacings(7)
|
||||
table.set_row_spacings(7)
|
||||
|
||||
label_charge = Label('Charge: ' , Label.DESCRIPTION)
|
||||
self.label_charge_value = Label(str(self._battery_charge) + '%', Label.DESCRIPTION)
|
||||
|
||||
table.attach(label_charge, 0, 1, 0, 1)
|
||||
table.attach(self.label_charge_value, 1,2, 0,1)
|
||||
|
||||
# Charging
|
||||
"""
|
||||
hbox_charging = gtk.HBox(False, 2)
|
||||
l_charging = gtk.Label('Charging: ')
|
||||
l_charging.set_justify(gtk.JUSTIFY_LEFT)
|
||||
hbox_charging.pack_start(l_charging, False, False, 0)
|
||||
|
||||
self._label_charging = gtk.Label('No')
|
||||
self._label_charging.set_justify(gtk.JUSTIFY_LEFT)
|
||||
|
||||
hbox_charging.pack_start(self._label_charging, False, False, 0)
|
||||
"""
|
||||
|
||||
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_all()
|
||||
|
||||
# Update every 2 seconds
|
||||
gobject.timeout_add(2000, self._update_battery_status)
|
||||
|
||||
def _update_battery_status(self):
|
||||
|
||||
self._battery_charge = self._get_battery_status()
|
||||
self.label_charge_value.set_text(str(self._battery_charge) + '%')
|
||||
self._battery_drw.queue_draw()
|
||||
return True
|
||||
|
||||
def do_expose(self, widget, event):
|
||||
context = widget.window.cairo_create()
|
||||
|
||||
[width, height] = widget.size_request()
|
||||
context.rectangle(0, 0, width, height)
|
||||
|
||||
context.set_source_rgb (0,0,0)
|
||||
context.fill_preserve()
|
||||
context.stroke()
|
||||
|
||||
self._draw_battery_usage(context, width, height)
|
||||
|
||||
def _get_battery_status(self):
|
||||
battery_class_path = '/sys/class/battery/psu_0/'
|
||||
capacity_path = battery_class_path + 'capacity_percentage'
|
||||
try:
|
||||
f = open(capacity_path, 'r')
|
||||
val = f.read().split('\n')
|
||||
capacity = int(val[0])
|
||||
f.close()
|
||||
except:
|
||||
capacity = 0
|
||||
|
||||
return capacity
|
||||
|
||||
def _draw_battery_usage(self, context, width, height):
|
||||
|
||||
usage_height = (self._battery_charge*height)/100
|
||||
|
||||
context.rectangle(0, height - usage_height, width, height)
|
||||
|
||||
if self._battery_charge > 50:
|
||||
context.set_source_rgb (0,1,0)
|
||||
|
||||
if self._battery_charge > 10 and self._battery_charge <= 50:
|
||||
context.set_source_rgb (1,1,0)
|
||||
|
||||
if self._battery_charge <= 10:
|
||||
context.set_source_rgb (1,0,0)
|
||||
|
||||
context.fill_preserve()
|
@ -251,11 +251,3 @@ class XO_CPU(gtk.Frame):
|
||||
freq+=1
|
||||
|
||||
context.stroke()
|
||||
|
||||
"""
|
||||
window = gtk.Window()
|
||||
window.add(XO_CPU())
|
||||
window.set_size_request(gtk.gdk.screen_width() * 85 / 100, 400)
|
||||
window.show_all()
|
||||
gtk.main()
|
||||
"""
|
@ -20,6 +20,9 @@ import os
|
||||
import gtk
|
||||
import pango
|
||||
|
||||
from label import Label
|
||||
from label import Style
|
||||
|
||||
class XO_System(gtk.Fixed):
|
||||
|
||||
def __init__(self):
|
||||
@ -33,13 +36,13 @@ class XO_System(gtk.Fixed):
|
||||
|
||||
# BUILD
|
||||
build = self._get_system_build()
|
||||
label_build = self.get_label('OLPC Build:')
|
||||
label_build_value = self.get_label(build)
|
||||
label_build = Label('OLPC Build:', Label.DESCRIPTION)
|
||||
label_build_value = Label(str(build), Label.DESCRIPTION)
|
||||
|
||||
# KERNEL
|
||||
sysinfo = os.uname()
|
||||
label_kernel = self.get_label('Kernel Version: ')
|
||||
label_kernel_value = self.get_label(sysinfo[0] + '-' + sysinfo[2])
|
||||
label_kernel = Label('Kernel Version:', Label.DESCRIPTION)
|
||||
label_kernel_value = Label(sysinfo[0] + '-' + sysinfo[2], Label.DESCRIPTION)
|
||||
|
||||
# OLPC Build
|
||||
table.attach(label_build, 0, 1, 0, 1)
|
||||
@ -50,6 +53,8 @@ class XO_System(gtk.Fixed):
|
||||
table.attach(label_kernel_value, 1, 2, 1, 2)
|
||||
|
||||
frame = gtk.Frame('System Information')
|
||||
style = Style()
|
||||
style.set_title_font(frame);
|
||||
frame.add(table)
|
||||
|
||||
self.add(frame)
|
||||
@ -67,14 +72,3 @@ class XO_System(gtk.Fixed):
|
||||
except:
|
||||
return "None"
|
||||
|
||||
def get_label(self, string):
|
||||
label = gtk.Label(string)
|
||||
label.set_alignment(0.0, 0.5)
|
||||
label.modify_font(self._set_font())
|
||||
return label
|
||||
|
||||
def _set_font(self):
|
||||
font = pango.FontDescription('Sans 8')
|
||||
font.set_weight(pango.WEIGHT_NORMAL)
|
||||
|
||||
return font
|
||||
|
@ -26,6 +26,7 @@ import drwarea
|
||||
|
||||
from cpu import XO_CPU
|
||||
from system import XO_System
|
||||
from battery import XO_Battery
|
||||
|
||||
class Interface:
|
||||
|
||||
@ -33,10 +34,16 @@ class Interface:
|
||||
|
||||
self.widget = self.vbox = gtk.VBox(False, 3)
|
||||
|
||||
# System information
|
||||
xo_system = XO_System()
|
||||
self.vbox.pack_start(xo_system, False, False, 0)
|
||||
|
||||
# CPU usage / Graph
|
||||
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)
|
||||
|
||||
self.vbox.show_all()
|
||||
|
53
services/console/label.py
Normal file
53
services/console/label.py
Normal file
@ -0,0 +1,53 @@
|
||||
#!/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 pango
|
||||
|
||||
class Label(gtk.Label):
|
||||
TITLE = 0
|
||||
DESCRIPTION = 1
|
||||
|
||||
def __init__(self, text, font_type):
|
||||
gtk.Label.__init__(self)
|
||||
|
||||
self.set_text(text)
|
||||
self.set_alignment(0.0, 0.5)
|
||||
|
||||
s = {
|
||||
self.TITLE: self._set_title_font,
|
||||
self.DESCRIPTION: self._set_description_font
|
||||
}[font_type]()
|
||||
|
||||
def _set_title_font(self):
|
||||
font = pango.FontDescription('Sans 12')
|
||||
font.set_weight(pango.WEIGHT_NORMAL)
|
||||
self.modify_font(font)
|
||||
|
||||
def _set_description_font(self):
|
||||
font = pango.FontDescription('Sans 8')
|
||||
font.set_weight(pango.WEIGHT_NORMAL)
|
||||
self.modify_font(font)
|
||||
|
||||
class Style:
|
||||
|
||||
def set_title_font(self, object):
|
||||
font = pango.FontDescription('Sans 20')
|
||||
font.set_weight(pango.WEIGHT_NORMAL)
|
||||
object.modify_font(font)
|
||||
|
Loading…
Reference in New Issue
Block a user