Merge branch 'master' of git+ssh://dev.laptop.org/git/sugar
This commit is contained in:
commit
f5bb269849
@ -52,7 +52,7 @@ activity_info = None
|
|||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
registry = ActivityRegistry()
|
registry = ActivityRegistry()
|
||||||
activities = registry.get_activities_for_name(sys.argv[1])
|
activities = registry.find_activity(sys.argv[1])
|
||||||
if len(activities) > 0:
|
if len(activities) > 0:
|
||||||
activity_info = activities[0]
|
activity_info = activities[0]
|
||||||
|
|
||||||
|
@ -4,9 +4,14 @@ service_in_files = \
|
|||||||
org.laptop.Clipboard.service.in \
|
org.laptop.Clipboard.service.in \
|
||||||
org.laptop.ObjectTypeRegistry.service.in
|
org.laptop.ObjectTypeRegistry.service.in
|
||||||
|
|
||||||
service_DATA = $(service_in_files:.service.in=.service)
|
service_DATA = \
|
||||||
|
org.laptop.Clipboard.service \
|
||||||
|
org.laptop.ObjectTypeRegistry.service
|
||||||
|
|
||||||
$(service_DATA): $(service_in_files) Makefile
|
org.laptop.Clipboard.service: org.laptop.Clipboard.service.in Makefile
|
||||||
|
@sed -e "s|\@bindir\@|$(bindir)|" $< > $@
|
||||||
|
|
||||||
|
org.laptop.ObjectTypeRegistry.service: org.laptop.ObjectTypeRegistry.service.in Makefile
|
||||||
@sed -e "s|\@bindir\@|$(bindir)|" $< > $@
|
@sed -e "s|\@bindir\@|$(bindir)|" $< > $@
|
||||||
|
|
||||||
sugardir = $(pkgdatadir)/services/clipboard
|
sugardir = $(pkgdatadir)/services/clipboard
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import gobject
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import dbus
|
import dbus
|
||||||
@ -32,14 +31,13 @@ PREVIEW_KEY = 'PREVIEW'
|
|||||||
ACTIVITY_KEY = 'ACTIVITY'
|
ACTIVITY_KEY = 'ACTIVITY'
|
||||||
FORMATS_KEY = 'FORMATS'
|
FORMATS_KEY = 'FORMATS'
|
||||||
|
|
||||||
class ClipboardDBusServiceHelper(dbus.service.Object):
|
class ClipboardService(dbus.service.Object):
|
||||||
|
|
||||||
_CLIPBOARD_DBUS_INTERFACE = "org.laptop.Clipboard"
|
_CLIPBOARD_DBUS_INTERFACE = "org.laptop.Clipboard"
|
||||||
_CLIPBOARD_OBJECT_PATH = "/org/laptop/Clipboard"
|
_CLIPBOARD_OBJECT_PATH = "/org/laptop/Clipboard"
|
||||||
_CLIPBOARD_OBJECTS_PATH = _CLIPBOARD_OBJECT_PATH + "/Objects/"
|
_CLIPBOARD_OBJECTS_PATH = _CLIPBOARD_OBJECT_PATH + "/Objects/"
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self):
|
||||||
self._parent = parent
|
|
||||||
self._objects = {}
|
self._objects = {}
|
||||||
self._next_id = 0
|
self._next_id = 0
|
||||||
|
|
||||||
@ -175,13 +173,3 @@ class ClipboardDBusServiceHelper(dbus.service.Object):
|
|||||||
def object_state_changed(self, object_path, values):
|
def object_state_changed(self, object_path, values):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class ClipboardService(object):
|
|
||||||
def __init__(self):
|
|
||||||
self._dbus_helper = ClipboardDBusServiceHelper(self)
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
loop = gobject.MainLoop()
|
|
||||||
try:
|
|
||||||
loop.run()
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print 'Ctrl+C pressed, exiting...'
|
|
||||||
|
@ -17,46 +17,49 @@
|
|||||||
import dbus
|
import dbus
|
||||||
import dbus.service
|
import dbus.service
|
||||||
|
|
||||||
from sugar.objects.objecttype import ObjectType
|
|
||||||
|
|
||||||
_REGISTRY_IFACE = "org.laptop.ObjectTypeRegistry"
|
_REGISTRY_IFACE = "org.laptop.ObjectTypeRegistry"
|
||||||
_REGISTRY_PATH = "/org/laptop/ObjectTypeRegistry"
|
_REGISTRY_PATH = "/org/laptop/ObjectTypeRegistry"
|
||||||
|
|
||||||
class ObjectTypeRegistry(dbus.service.Object):
|
class ObjectTypeRegistry(dbus.service.Object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
bus = dbus.SessionBus()
|
bus = dbus.SessionBus()
|
||||||
bus_name = dbus.service.BusName(self._REGISTRY_IFACE, bus=bus)
|
bus_name = dbus.service.BusName(_REGISTRY_IFACE, bus=bus)
|
||||||
dbus.service.Object.__init__(self, bus_name, self._REGISTRY_PATH)
|
dbus.service.Object.__init__(self, bus_name, _REGISTRY_PATH)
|
||||||
|
|
||||||
self._types = {}
|
self._types = {}
|
||||||
|
|
||||||
self._add_primitive('Text', _('Text'), 'object-text',
|
from gettext import gettext as _
|
||||||
[ 'text/rtf' ])
|
self._add_primitive('Text', _('Text'), 'theme:object-text',
|
||||||
self._add_primitive('Image', _('Image'), 'object-image',
|
[ 'text/plain', 'text/rtf', 'application/pdf',
|
||||||
|
'application/x-pdf' ])
|
||||||
|
self._add_primitive('Image', _('Image'), 'theme:object-image',
|
||||||
[ 'image/png' ])
|
[ 'image/png' ])
|
||||||
|
|
||||||
def _add_primitive(self, type_id, name, icon, mime_types):
|
def _add_primitive(self, type_id, name, icon, mime_types):
|
||||||
object_type = ObjectType(type_id, name, icon, mime_types)
|
object_type = {'type_id': type_id,
|
||||||
self._types.add(object_type)
|
'name': name,
|
||||||
|
'icon': icon,
|
||||||
|
'mime_types': mime_types}
|
||||||
|
self._types[type_id] = object_type
|
||||||
|
|
||||||
def _get_type_for_mime(self, mime_type):
|
def _get_type_for_mime(self, mime_type):
|
||||||
for object_type in self._types.values():
|
for object_type in self._types.values():
|
||||||
if mime_type in object_type.mime_types:
|
if mime_type in object_type['mime_types']:
|
||||||
return object_type
|
return object_type
|
||||||
|
|
||||||
@dbus.service.method(_CLIPBOARD_DBUS_INTERFACE,
|
@dbus.service.method(_REGISTRY_IFACE,
|
||||||
in_signature="s", out_signature="a{sv}")
|
in_signature="s", out_signature="a{sv}")
|
||||||
def GetType(self, type_id):
|
def GetType(self, type_id):
|
||||||
if self._types.has_key(type_id):
|
if self._types.has_key(type_id):
|
||||||
return self._types[type_id].to_dict()
|
return self._types[type_id]
|
||||||
else:
|
else:
|
||||||
return []
|
return {}
|
||||||
|
|
||||||
@dbus.service.method(_CLIPBOARD_DBUS_INTERFACE,
|
@dbus.service.method(_REGISTRY_IFACE,
|
||||||
in_signature="s", out_signature="a{sv}")
|
in_signature="s", out_signature="a{sv}")
|
||||||
def GetTypeForMIME(self, mime_type):
|
def GetTypeForMIME(self, mime_type):
|
||||||
object_type = self._get_type_for_mime(mime_type)
|
object_type = self._get_type_for_mime(mime_type)
|
||||||
if object_type:
|
if object_type:
|
||||||
return object_type.to_dict()
|
return object_type
|
||||||
else:
|
else:
|
||||||
return []
|
return {}
|
||||||
|
@ -35,11 +35,18 @@ from sugar import env
|
|||||||
sys.path.append(env.get_service_path('clipboard'))
|
sys.path.append(env.get_service_path('clipboard'))
|
||||||
|
|
||||||
from clipboardservice import ClipboardService
|
from clipboardservice import ClipboardService
|
||||||
|
from objecttypeservice import ObjectTypeRegistry
|
||||||
|
|
||||||
logging.info('Starting clipboard service.')
|
logging.info('Starting clipboard service.')
|
||||||
|
|
||||||
gobject.threads_init()
|
gobject.threads_init()
|
||||||
dbus.glib.threads_init()
|
dbus.glib.threads_init()
|
||||||
|
|
||||||
app = ClipboardService()
|
clipboard_service = ClipboardService()
|
||||||
app.run()
|
object_type_registry = ObjectTypeRegistry()
|
||||||
|
|
||||||
|
loop = gobject.MainLoop()
|
||||||
|
try:
|
||||||
|
loop.run()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print 'Ctrl+C pressed, exiting...'
|
||||||
|
@ -4,7 +4,5 @@ sugar_PYTHON = \
|
|||||||
xo.py \
|
xo.py \
|
||||||
cpu.py \
|
cpu.py \
|
||||||
system.py \
|
system.py \
|
||||||
battery.py
|
battery.py \
|
||||||
|
nandflash.py
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,7 +27,8 @@ class XO_Battery(gtk.Fixed):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
gtk.Fixed.__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.set_border_width(10)
|
||||||
|
|
||||||
self._battery_charge = self._get_battery_status()
|
self._battery_charge = self._get_battery_status()
|
||||||
@ -76,20 +77,16 @@ class XO_Battery(gtk.Fixed):
|
|||||||
self.add(self.frame)
|
self.add(self.frame)
|
||||||
self.show_all()
|
self.show_all()
|
||||||
|
|
||||||
# Update every 2 seconds
|
def update_status(self):
|
||||||
gobject.timeout_add(2000, self._update_battery_status)
|
|
||||||
|
|
||||||
def _update_battery_status(self):
|
|
||||||
|
|
||||||
new_charge = self._get_battery_status()
|
new_charge = self._get_battery_status()
|
||||||
|
frame_label = str(self._battery_charge) + '%'
|
||||||
|
|
||||||
if new_charge != self._battery_charge:
|
if new_charge != self._battery_charge:
|
||||||
self._battery_charge = self._get_battery_status()
|
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)
|
self._battery_box.set_capacity(self._battery_charge)
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _get_battery_status(self):
|
def _get_battery_status(self):
|
||||||
battery_class_path = '/sys/class/battery/psu_0/'
|
battery_class_path = '/sys/class/battery/psu_0/'
|
||||||
capacity_path = battery_class_path + 'capacity_percentage'
|
capacity_path = battery_class_path + 'capacity_percentage'
|
||||||
|
@ -85,7 +85,6 @@ class XO_CPU(gtk.Frame):
|
|||||||
gtk.Frame.__init__(self, 'System CPU Usage')
|
gtk.Frame.__init__(self, 'System CPU Usage')
|
||||||
self.set_border_width(10)
|
self.set_border_width(10)
|
||||||
|
|
||||||
self._updated = False
|
|
||||||
width = (gtk.gdk.screen_width() * 99 / 100) - 50
|
width = (gtk.gdk.screen_width() * 99 / 100) - 50
|
||||||
height = (gtk.gdk.screen_height() * 15 / 100) - 20
|
height = (gtk.gdk.screen_height() * 15 / 100) - 20
|
||||||
|
|
||||||
@ -100,15 +99,16 @@ class XO_CPU(gtk.Frame):
|
|||||||
self.add(fixed)
|
self.add(fixed)
|
||||||
|
|
||||||
self._DRW_CPU = CPU_Usage()
|
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)
|
gobject.timeout_add(self._DRW_CPU.frequency, self._update_cpu_usage)
|
||||||
|
|
||||||
def _update_cpu_usage(self):
|
def _update_cpu_usage(self):
|
||||||
|
print "update XO CPU"
|
||||||
self._cpu = self._DRW_CPU._get_CPU_usage()
|
self._cpu = self._DRW_CPU._get_CPU_usage()
|
||||||
self._updated = True
|
|
||||||
|
|
||||||
self.set_label('System CPU Usage: ' + str(self._cpu) + '%')
|
self.set_label('System CPU Usage: ' + str(self._cpu) + '%')
|
||||||
|
|
||||||
# Draw the value into the graphic
|
# Draw the value into the graphic
|
||||||
self._graphic.draw_value(self._cpu)
|
self._graphic.draw_value(self._cpu)
|
||||||
|
|
||||||
return True
|
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,11 +26,11 @@ import string
|
|||||||
from cpu import XO_CPU
|
from cpu import XO_CPU
|
||||||
from system import XO_System
|
from system import XO_System
|
||||||
from battery import XO_Battery
|
from battery import XO_Battery
|
||||||
|
from nandflash import XO_NandFlash
|
||||||
|
|
||||||
class Interface:
|
class Interface:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self.widget = self.vbox = gtk.VBox(False, 3)
|
self.widget = self.vbox = gtk.VBox(False, 3)
|
||||||
|
|
||||||
# System information
|
# System information
|
||||||
@ -41,8 +41,23 @@ class Interface:
|
|||||||
xo_cpu = XO_CPU()
|
xo_cpu = XO_CPU()
|
||||||
self.vbox.pack_start(xo_cpu, False, False, 0)
|
self.vbox.pack_start(xo_cpu, False, False, 0)
|
||||||
|
|
||||||
# Battery Status / Graph
|
# Graphics: Battery Status, NandFlash
|
||||||
xo_battery = XO_Battery()
|
self._xo_battery = XO_Battery()
|
||||||
self.vbox.pack_start(xo_battery, False, False, 0)
|
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()
|
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
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
import gtk
|
import gtk
|
||||||
|
import gobject
|
||||||
import cairo
|
import cairo
|
||||||
|
|
||||||
|
COLOR_MODE_NORMAL = 0
|
||||||
|
COLOR_MODE_REVERSE = 1
|
||||||
|
|
||||||
class BoxGraphic(gtk.DrawingArea):
|
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)
|
gtk.DrawingArea.__init__(self)
|
||||||
self.connect("expose-event", self.do_expose)
|
self.connect("expose-event", self.do_expose)
|
||||||
self.connect('size-allocate', self._change_size_cb)
|
self.connect('size-allocate', self._change_size_cb)
|
||||||
self.set_capacity(0)
|
|
||||||
|
|
||||||
def do_expose(self, widget, event):
|
def do_expose(self, widget, event):
|
||||||
context = widget.window.cairo_create()
|
context = widget.window.cairo_create()
|
||||||
@ -34,26 +54,46 @@ class BoxGraphic(gtk.DrawingArea):
|
|||||||
context.fill_preserve()
|
context.fill_preserve()
|
||||||
context.stroke()
|
context.stroke()
|
||||||
|
|
||||||
print self._percent
|
|
||||||
self._draw_content(context, 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):
|
def set_capacity(self, percent):
|
||||||
self._percent = percent
|
self._percent = percent
|
||||||
self.queue_draw()
|
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):
|
def _draw_content(self, context, percent):
|
||||||
usage_height = (percent*self._height)/100
|
usage_height = (percent*self._height)/100
|
||||||
|
|
||||||
context.rectangle(0, self._height - usage_height, self._width, self._height)
|
context.rectangle(0, self._height - usage_height, self._width, self._height)
|
||||||
|
|
||||||
if self._percent > 50:
|
if self._percent > self._limit_high:
|
||||||
context.set_source_rgb (0,1,0)
|
context.set_source_rgb(*self._color_status_high)
|
||||||
|
elif self._percent >= self._limit_medium and self._percent <= self._limit_high:
|
||||||
if self._percent > 10 and self._percent <= 50:
|
context.set_source_rgb(*self._color_status_medium)
|
||||||
context.set_source_rgb (1,1,0)
|
elif self._percent < self._limit_medium:
|
||||||
|
context.set_source_rgb(*self._color_status_low)
|
||||||
if self._percent <= 10:
|
|
||||||
context.set_source_rgb (1,0,0)
|
|
||||||
|
|
||||||
context.fill_preserve()
|
context.fill_preserve()
|
||||||
|
|
||||||
|
@ -41,7 +41,6 @@ class HorizontalGraphic(gtk.DrawingArea):
|
|||||||
|
|
||||||
if event.area.x == 0:
|
if event.area.x == 0:
|
||||||
draw_all = True
|
draw_all = True
|
||||||
|
|
||||||
self._draw_border_lines(context)
|
self._draw_border_lines(context)
|
||||||
context.stroke()
|
context.stroke()
|
||||||
else:
|
else:
|
||||||
@ -75,7 +74,7 @@ class HorizontalGraphic(gtk.DrawingArea):
|
|||||||
height = self._height
|
height = self._height
|
||||||
width = self._width
|
width = self._width
|
||||||
else:
|
else:
|
||||||
area_x = (length*self._GRAPH_OFFSET)
|
area_x = self._graph_x + (length*self._GRAPH_OFFSET)
|
||||||
area_y = self._graph_y
|
area_y = self._graph_y
|
||||||
width = self._GRAPH_OFFSET*2
|
width = self._GRAPH_OFFSET*2
|
||||||
height = self._graph_height
|
height = self._graph_height
|
||||||
@ -115,8 +114,8 @@ class HorizontalGraphic(gtk.DrawingArea):
|
|||||||
|
|
||||||
for percent in self._buffer[buffer_offset:length]:
|
for percent in self._buffer[buffer_offset:length]:
|
||||||
if buffer_offset == 0:
|
if buffer_offset == 0:
|
||||||
from_y = self._height - self._GRAPH_OFFSET
|
from_y = self._get_y(self._buffer[0])
|
||||||
from_x = self._GRAPH_OFFSET
|
from_x = self._graph_x
|
||||||
else:
|
else:
|
||||||
from_y = self._get_y(self._buffer[buffer_offset-1])
|
from_y = self._get_y(self._buffer[buffer_offset-1])
|
||||||
from_x = (freq * self._GRAPH_OFFSET)
|
from_x = (freq * self._GRAPH_OFFSET)
|
||||||
@ -131,14 +130,18 @@ class HorizontalGraphic(gtk.DrawingArea):
|
|||||||
context.stroke()
|
context.stroke()
|
||||||
|
|
||||||
def _get_y(self, percent):
|
def _get_y(self, percent):
|
||||||
y_value = self._GRAPH_OFFSET + (self._graph_height - ((percent*self._graph_height)/100))
|
if percent==0:
|
||||||
return int(y_value)
|
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):
|
def _change_size_cb(self, widget, allocation):
|
||||||
self._width = allocation.width
|
self._width = allocation.width
|
||||||
self._height = allocation.height
|
self._height = allocation.height
|
||||||
|
|
||||||
self._graph_x = self._MARGIN + self._LINE_WIDTH
|
self._graph_x = self._MARGIN + self._LINE_WIDTH
|
||||||
self._graph_y = self._MARGIN + self._LINE_WIDTH
|
self._graph_y = self._MARGIN
|
||||||
self._graph_width = self._width - (self._MARGIN + self._LINE_WIDTH)
|
self._graph_width = self._width - (self._MARGIN*2 + self._LINE_WIDTH)
|
||||||
self._graph_height = self._height - ((self._MARGIN + self._LINE_WIDTH)*2)
|
self._graph_height = self._height - ((self._MARGIN*2 + self._LINE_WIDTH))
|
||||||
|
@ -17,9 +17,6 @@
|
|||||||
"""D-bus service providing access to the shell's functionality"""
|
"""D-bus service providing access to the shell's functionality"""
|
||||||
import dbus
|
import dbus
|
||||||
|
|
||||||
from sugar.activity import ActivityRegistry
|
|
||||||
from sugar.activity import ActivityInfo
|
|
||||||
|
|
||||||
from model import bundleregistry
|
from model import bundleregistry
|
||||||
|
|
||||||
_DBUS_SERVICE = "org.laptop.Shell"
|
_DBUS_SERVICE = "org.laptop.Shell"
|
||||||
@ -76,9 +73,19 @@ class ShellService(dbus.service.Object):
|
|||||||
registry = bundleregistry.get_registry()
|
registry = bundleregistry.get_registry()
|
||||||
return registry.add_bundle(bundle_path)
|
return registry.add_bundle(bundle_path)
|
||||||
|
|
||||||
|
@dbus.service.method(_DBUS_ACTIVITY_REGISTRY_IFACE,
|
||||||
|
in_signature="s", out_signature="a{sv}")
|
||||||
|
def GetActivity(self, service_name):
|
||||||
|
registry = bundleregistry.get_registry()
|
||||||
|
bundle = registry.get_bundle(service_name)
|
||||||
|
if not bundle:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
return self._bundle_to_dict(bundle)
|
||||||
|
|
||||||
@dbus.service.method(_DBUS_ACTIVITY_REGISTRY_IFACE,
|
@dbus.service.method(_DBUS_ACTIVITY_REGISTRY_IFACE,
|
||||||
in_signature="s", out_signature="aa{sv}")
|
in_signature="s", out_signature="aa{sv}")
|
||||||
def GetActivitiesForName(self, name):
|
def FindActivity(self, name):
|
||||||
result = []
|
result = []
|
||||||
key = name.lower()
|
key = name.lower()
|
||||||
|
|
||||||
@ -86,8 +93,7 @@ class ShellService(dbus.service.Object):
|
|||||||
name = bundle.get_name().lower()
|
name = bundle.get_name().lower()
|
||||||
service_name = bundle.get_service_name().lower()
|
service_name = bundle.get_service_name().lower()
|
||||||
if name.find(key) != -1 or service_name.find(key) != -1:
|
if name.find(key) != -1 or service_name.find(key) != -1:
|
||||||
info = self._bundle_to_activity_info(bundle)
|
result.append(self._bundle_to_dict(bundle))
|
||||||
result.append(info.to_dict())
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -97,9 +103,8 @@ class ShellService(dbus.service.Object):
|
|||||||
result = []
|
result = []
|
||||||
|
|
||||||
for bundle in bundleregistry.get_registry():
|
for bundle in bundleregistry.get_registry():
|
||||||
if mime_type in bundle.get_mime_types():
|
if bundle.get_mime_types() and mime_type in bundle.get_mime_types():
|
||||||
info = self._bundle_to_activity_info(bundle)
|
result.append(self._bundle_to_dict(bundle))
|
||||||
result.append(info.to_dict())
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -135,6 +140,8 @@ class ShellService(dbus.service.Object):
|
|||||||
if new_id:
|
if new_id:
|
||||||
self.CurrentActivityChanged(new_id)
|
self.CurrentActivityChanged(new_id)
|
||||||
|
|
||||||
def _bundle_to_activity_info(self, bundle):
|
def _bundle_to_dict(self, bundle):
|
||||||
return ActivityInfo(bundle.get_name(), bundle.get_icon(),
|
return {'name': bundle.get_name(),
|
||||||
bundle.get_service_name(), bundle.get_path())
|
'icon': bundle.get_icon(),
|
||||||
|
'service_name': bundle.get_service_name(),
|
||||||
|
'path': bundle.get_path()}
|
||||||
|
@ -223,7 +223,7 @@ class Shell(gobject.GObject):
|
|||||||
jobject.metadata['buddies'] = ''
|
jobject.metadata['buddies'] = ''
|
||||||
jobject.metadata['preview'] = ''
|
jobject.metadata['preview'] = ''
|
||||||
jobject.metadata['icon-color'] = profile.get_color().to_string()
|
jobject.metadata['icon-color'] = profile.get_color().to_string()
|
||||||
jobject.metadata['mime-type'] = 'image/png'
|
jobject.metadata['mime_type'] = 'image/png'
|
||||||
jobject.file_path = file_path
|
jobject.file_path = file_path
|
||||||
datastore.write(jobject)
|
datastore.write(jobject)
|
||||||
|
|
||||||
|
@ -37,5 +37,3 @@ window, requesting sharing across the network, and basic
|
|||||||
"what type of application are you" queries.
|
"what type of application are you" queries.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from sugar.activity.registry import ActivityRegistry
|
|
||||||
from sugar.activity.registry import ActivityInfo
|
|
||||||
|
@ -93,7 +93,7 @@ class Bundle:
|
|||||||
logging.error('%s must specify exec or class' % self._path)
|
logging.error('%s must specify exec or class' % self._path)
|
||||||
|
|
||||||
if cp.has_option(section, 'mime_types'):
|
if cp.has_option(section, 'mime_types'):
|
||||||
mime_list = cp.get(section, 'show_launcher')
|
mime_list = cp.get(section, 'mime_types')
|
||||||
self._mime_types = mime_list.strip(';')
|
self._mime_types = mime_list.strip(';')
|
||||||
|
|
||||||
if cp.has_option(section, 'show_launcher'):
|
if cp.has_option(section, 'show_launcher'):
|
||||||
|
@ -32,13 +32,6 @@ class ActivityInfo(object):
|
|||||||
self.service_name = service_name
|
self.service_name = service_name
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
def to_dict(self):
|
|
||||||
return { 'name' : self.name,
|
|
||||||
'icon' : self.icon,
|
|
||||||
'service_name' : self.service_name,
|
|
||||||
'path' : self.path
|
|
||||||
}
|
|
||||||
|
|
||||||
class ActivityRegistry(object):
|
class ActivityRegistry(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
bus = dbus.SessionBus()
|
bus = dbus.SessionBus()
|
||||||
@ -53,10 +46,19 @@ class ActivityRegistry(object):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get_activities_for_name(self, name):
|
def get_activity(self, service_name):
|
||||||
info_list = self._registry.GetActivitiesForName(name)
|
info_dict = self._registry.GetActivity(service_name)
|
||||||
|
return _activity_info_from_dict(info_dict)
|
||||||
|
|
||||||
|
def find_activity(self, name):
|
||||||
|
info_list = self._registry.FindActivity(name)
|
||||||
return self._convert_info_list(info_list)
|
return self._convert_info_list(info_list)
|
||||||
|
|
||||||
def get_activities_for_type(self, mime_type):
|
def get_activities_for_type(self, mime_type):
|
||||||
info_list = self._registry.GetActivitiesForType(mime_type)
|
info_list = self._registry.GetActivitiesForType(mime_type)
|
||||||
return self._convert_info_list(info_list)
|
return self._convert_info_list(info_list)
|
||||||
|
|
||||||
|
_registry = ActivityRegistry()
|
||||||
|
|
||||||
|
def get_registry():
|
||||||
|
return _registry
|
||||||
|
@ -25,10 +25,18 @@ class DSMetadata(gobject.GObject):
|
|||||||
([]))
|
([]))
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, props={}):
|
def __init__(self, props=None):
|
||||||
gobject.GObject.__init__(self)
|
gobject.GObject.__init__(self)
|
||||||
|
if not props:
|
||||||
|
self._props = {}
|
||||||
|
else:
|
||||||
self._props = props
|
self._props = props
|
||||||
|
|
||||||
|
default_keys = ['activity', 'mime_type']
|
||||||
|
for key in default_keys:
|
||||||
|
if not self._props.has_key(key):
|
||||||
|
self._props[key] = ''
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
return self._props[key]
|
return self._props[key]
|
||||||
|
|
||||||
@ -88,7 +96,7 @@ def create():
|
|||||||
return DSObject(object_id=None, metadata=DSMetadata(), file_path=None)
|
return DSObject(object_id=None, metadata=DSMetadata(), file_path=None)
|
||||||
|
|
||||||
def write(ds_object, reply_handler=None, error_handler=None):
|
def write(ds_object, reply_handler=None, error_handler=None):
|
||||||
logging.debug('datastore.write')
|
logging.debug('datastore.write: %r' % ds_object.metadata.get_dictionary())
|
||||||
if ds_object.object_id:
|
if ds_object.object_id:
|
||||||
dbus_helpers.update(ds_object.object_id,
|
dbus_helpers.update(ds_object.object_id,
|
||||||
ds_object.metadata.get_dictionary(),
|
ds_object.metadata.get_dictionary(),
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
# Copyright (C) 2007, Red Hat, Inc.
|
||||||
|
#
|
||||||
|
# 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 dbus
|
||||||
|
|
||||||
_SERVICE = "org.laptop.ObjectTypeRegistry"
|
_SERVICE = "org.laptop.ObjectTypeRegistry"
|
||||||
_PATH = "/org/laptop/ObjectTypeRegistry"
|
_PATH = "/org/laptop/ObjectTypeRegistry"
|
||||||
_IFACE = "org.laptop.ObjectTypeRegistry"
|
_IFACE = "org.laptop.ObjectTypeRegistry"
|
||||||
@ -11,33 +29,27 @@ def _object_type_from_dict(info_dict):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
class ObjectType(object):
|
class ObjectType(object):
|
||||||
def __init__(self, type_id, name, icon, mime_types):
|
def __init__(self, type_id, name, icon):
|
||||||
self.type_id = type_id
|
self.type_id = type_id
|
||||||
self.name = name
|
self.name = name
|
||||||
self.icon = icon
|
self.icon = icon
|
||||||
self.mime_types = []
|
self.mime_types = []
|
||||||
|
|
||||||
def to_dict(self):
|
|
||||||
return { 'type_id' : self.type_id,
|
|
||||||
'name' : self.name,
|
|
||||||
'icon' : self.icon
|
|
||||||
}
|
|
||||||
|
|
||||||
class ObjectTypeRegistry(object):
|
class ObjectTypeRegistry(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
bus = dbus.SessionBus()
|
bus = dbus.SessionBus()
|
||||||
bus_object = bus.get_object(_SERVICE, _PATH)
|
bus_object = bus.get_object(_SERVICE, _PATH)
|
||||||
self._registry = dbus.Interface(bus_object, _IFACE)
|
self._registry = dbus.Interface(bus_object, _IFACE)
|
||||||
|
|
||||||
def get_type(type_id):
|
def get_type(self, type_id):
|
||||||
type_dict = self._registry.GetType(type_id)
|
type_dict = self._registry.GetType(type_id)
|
||||||
return _object_type_from_dict(type_dict)
|
return _object_type_from_dict(type_dict)
|
||||||
|
|
||||||
def get_type_for_mime(mime_type):
|
def get_type_for_mime(self, mime_type):
|
||||||
type_dict = self._registry.GetTypeForMime(type_id)
|
type_dict = self._registry.GetTypeForMIME(mime_type)
|
||||||
return _object_type_from_dict(type_dict)
|
return _object_type_from_dict(type_dict)
|
||||||
|
|
||||||
_registry = ObjectRegistry()
|
_registry = ObjectTypeRegistry()
|
||||||
|
|
||||||
def get_registry():
|
def get_registry():
|
||||||
return _registry
|
return _registry
|
||||||
|
Loading…
Reference in New Issue
Block a user