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:
|
||||
registry = ActivityRegistry()
|
||||
activities = registry.get_activities_for_name(sys.argv[1])
|
||||
activities = registry.find_activity(sys.argv[1])
|
||||
if len(activities) > 0:
|
||||
activity_info = activities[0]
|
||||
|
||||
|
@ -4,18 +4,23 @@ service_in_files = \
|
||||
org.laptop.Clipboard.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)|" $< > $@
|
||||
|
||||
sugardir = $(pkgdatadir)/services/clipboard
|
||||
|
||||
sugar_PYTHON = \
|
||||
__init__.py \
|
||||
sugar_PYTHON = \
|
||||
__init__.py \
|
||||
clipboardobject.py \
|
||||
clipboardservice.py \
|
||||
objecttypeservice.py \
|
||||
objecttypeservice.py \
|
||||
typeregistry.py
|
||||
|
||||
bin_SCRIPTS = sugar-clipboard
|
||||
|
@ -15,7 +15,6 @@
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
import logging
|
||||
import gobject
|
||||
import os
|
||||
import shutil
|
||||
import dbus
|
||||
@ -32,14 +31,13 @@ PREVIEW_KEY = 'PREVIEW'
|
||||
ACTIVITY_KEY = 'ACTIVITY'
|
||||
FORMATS_KEY = 'FORMATS'
|
||||
|
||||
class ClipboardDBusServiceHelper(dbus.service.Object):
|
||||
class ClipboardService(dbus.service.Object):
|
||||
|
||||
_CLIPBOARD_DBUS_INTERFACE = "org.laptop.Clipboard"
|
||||
_CLIPBOARD_OBJECT_PATH = "/org/laptop/Clipboard"
|
||||
_CLIPBOARD_OBJECTS_PATH = _CLIPBOARD_OBJECT_PATH + "/Objects/"
|
||||
|
||||
def __init__(self, parent):
|
||||
self._parent = parent
|
||||
def __init__(self):
|
||||
self._objects = {}
|
||||
self._next_id = 0
|
||||
|
||||
@ -175,13 +173,3 @@ class ClipboardDBusServiceHelper(dbus.service.Object):
|
||||
def object_state_changed(self, object_path, values):
|
||||
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.service
|
||||
|
||||
from sugar.objects.objecttype import ObjectType
|
||||
|
||||
_REGISTRY_IFACE = "org.laptop.ObjectTypeRegistry"
|
||||
_REGISTRY_PATH = "/org/laptop/ObjectTypeRegistry"
|
||||
|
||||
class ObjectTypeRegistry(dbus.service.Object):
|
||||
def __init__(self):
|
||||
bus = dbus.SessionBus()
|
||||
bus_name = dbus.service.BusName(self._REGISTRY_IFACE, bus=bus)
|
||||
dbus.service.Object.__init__(self, bus_name, self._REGISTRY_PATH)
|
||||
bus_name = dbus.service.BusName(_REGISTRY_IFACE, bus=bus)
|
||||
dbus.service.Object.__init__(self, bus_name, _REGISTRY_PATH)
|
||||
|
||||
self._types = {}
|
||||
|
||||
self._add_primitive('Text', _('Text'), 'object-text',
|
||||
[ 'text/rtf' ])
|
||||
self._add_primitive('Image', _('Image'), 'object-image',
|
||||
from gettext import gettext as _
|
||||
self._add_primitive('Text', _('Text'), 'theme:object-text',
|
||||
[ 'text/plain', 'text/rtf', 'application/pdf',
|
||||
'application/x-pdf' ])
|
||||
self._add_primitive('Image', _('Image'), 'theme:object-image',
|
||||
[ 'image/png' ])
|
||||
|
||||
def _add_primitive(self, type_id, name, icon, mime_types):
|
||||
object_type = ObjectType(type_id, name, icon, mime_types)
|
||||
self._types.add(object_type)
|
||||
object_type = {'type_id': type_id,
|
||||
'name': name,
|
||||
'icon': icon,
|
||||
'mime_types': mime_types}
|
||||
self._types[type_id] = object_type
|
||||
|
||||
def _get_type_for_mime(self, mime_type):
|
||||
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
|
||||
|
||||
@dbus.service.method(_CLIPBOARD_DBUS_INTERFACE,
|
||||
@dbus.service.method(_REGISTRY_IFACE,
|
||||
in_signature="s", out_signature="a{sv}")
|
||||
def GetType(self, type_id):
|
||||
if self._types.has_key(type_id):
|
||||
return self._types[type_id].to_dict()
|
||||
return self._types[type_id]
|
||||
else:
|
||||
return []
|
||||
return {}
|
||||
|
||||
@dbus.service.method(_CLIPBOARD_DBUS_INTERFACE,
|
||||
@dbus.service.method(_REGISTRY_IFACE,
|
||||
in_signature="s", out_signature="a{sv}")
|
||||
def GetTypeForMIME(self, mime_type):
|
||||
object_type = self._get_type_for_mime(mime_type)
|
||||
if object_type:
|
||||
return object_type.to_dict()
|
||||
return object_type
|
||||
else:
|
||||
return []
|
||||
return {}
|
||||
|
@ -35,11 +35,18 @@ from sugar import env
|
||||
sys.path.append(env.get_service_path('clipboard'))
|
||||
|
||||
from clipboardservice import ClipboardService
|
||||
from objecttypeservice import ObjectTypeRegistry
|
||||
|
||||
logging.info('Starting clipboard service.')
|
||||
|
||||
gobject.threads_init()
|
||||
dbus.glib.threads_init()
|
||||
|
||||
app = ClipboardService()
|
||||
app.run()
|
||||
clipboard_service = ClipboardService()
|
||||
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 \
|
||||
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))
|
||||
|
@ -17,9 +17,6 @@
|
||||
"""D-bus service providing access to the shell's functionality"""
|
||||
import dbus
|
||||
|
||||
from sugar.activity import ActivityRegistry
|
||||
from sugar.activity import ActivityInfo
|
||||
|
||||
from model import bundleregistry
|
||||
|
||||
_DBUS_SERVICE = "org.laptop.Shell"
|
||||
@ -76,9 +73,19 @@ class ShellService(dbus.service.Object):
|
||||
registry = bundleregistry.get_registry()
|
||||
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,
|
||||
in_signature="s", out_signature="aa{sv}")
|
||||
def GetActivitiesForName(self, name):
|
||||
def FindActivity(self, name):
|
||||
result = []
|
||||
key = name.lower()
|
||||
|
||||
@ -86,8 +93,7 @@ class ShellService(dbus.service.Object):
|
||||
name = bundle.get_name().lower()
|
||||
service_name = bundle.get_service_name().lower()
|
||||
if name.find(key) != -1 or service_name.find(key) != -1:
|
||||
info = self._bundle_to_activity_info(bundle)
|
||||
result.append(info.to_dict())
|
||||
result.append(self._bundle_to_dict(bundle))
|
||||
|
||||
return result
|
||||
|
||||
@ -97,9 +103,8 @@ class ShellService(dbus.service.Object):
|
||||
result = []
|
||||
|
||||
for bundle in bundleregistry.get_registry():
|
||||
if mime_type in bundle.get_mime_types():
|
||||
info = self._bundle_to_activity_info(bundle)
|
||||
result.append(info.to_dict())
|
||||
if bundle.get_mime_types() and mime_type in bundle.get_mime_types():
|
||||
result.append(self._bundle_to_dict(bundle))
|
||||
|
||||
return result
|
||||
|
||||
@ -135,6 +140,8 @@ class ShellService(dbus.service.Object):
|
||||
if new_id:
|
||||
self.CurrentActivityChanged(new_id)
|
||||
|
||||
def _bundle_to_activity_info(self, bundle):
|
||||
return ActivityInfo(bundle.get_name(), bundle.get_icon(),
|
||||
bundle.get_service_name(), bundle.get_path())
|
||||
def _bundle_to_dict(self, bundle):
|
||||
return {'name': bundle.get_name(),
|
||||
'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['preview'] = ''
|
||||
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
|
||||
datastore.write(jobject)
|
||||
|
||||
|
@ -37,5 +37,3 @@ window, requesting sharing across the network, and basic
|
||||
"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)
|
||||
|
||||
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(';')
|
||||
|
||||
if cp.has_option(section, 'show_launcher'):
|
||||
|
@ -32,13 +32,6 @@ class ActivityInfo(object):
|
||||
self.service_name = service_name
|
||||
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):
|
||||
def __init__(self):
|
||||
bus = dbus.SessionBus()
|
||||
@ -53,10 +46,19 @@ class ActivityRegistry(object):
|
||||
|
||||
return result
|
||||
|
||||
def get_activities_for_name(self, name):
|
||||
info_list = self._registry.GetActivitiesForName(name)
|
||||
def get_activity(self, service_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)
|
||||
|
||||
def get_activities_for_type(self, mime_type):
|
||||
info_list = self._registry.GetActivitiesForType(mime_type)
|
||||
return self._convert_info_list(info_list)
|
||||
|
||||
_registry = ActivityRegistry()
|
||||
|
||||
def get_registry():
|
||||
return _registry
|
||||
|
@ -25,9 +25,17 @@ class DSMetadata(gobject.GObject):
|
||||
([]))
|
||||
}
|
||||
|
||||
def __init__(self, props={}):
|
||||
def __init__(self, props=None):
|
||||
gobject.GObject.__init__(self)
|
||||
self._props = props
|
||||
if not props:
|
||||
self._props = {}
|
||||
else:
|
||||
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):
|
||||
return self._props[key]
|
||||
@ -88,7 +96,7 @@ def create():
|
||||
return DSObject(object_id=None, metadata=DSMetadata(), file_path=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:
|
||||
dbus_helpers.update(ds_object.object_id,
|
||||
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"
|
||||
_PATH = "/org/laptop/ObjectTypeRegistry"
|
||||
_IFACE = "org.laptop.ObjectTypeRegistry"
|
||||
@ -11,33 +29,27 @@ def _object_type_from_dict(info_dict):
|
||||
return None
|
||||
|
||||
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.name = name
|
||||
self.icon = icon
|
||||
self.mime_types = []
|
||||
|
||||
def to_dict(self):
|
||||
return { 'type_id' : self.type_id,
|
||||
'name' : self.name,
|
||||
'icon' : self.icon
|
||||
}
|
||||
|
||||
class ObjectTypeRegistry(object):
|
||||
def __init__(self):
|
||||
bus = dbus.SessionBus()
|
||||
bus_object = bus.get_object(_SERVICE, _PATH)
|
||||
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)
|
||||
return _object_type_from_dict(type_dict)
|
||||
|
||||
def get_type_for_mime(mime_type):
|
||||
type_dict = self._registry.GetTypeForMime(type_id)
|
||||
def get_type_for_mime(self, mime_type):
|
||||
type_dict = self._registry.GetTypeForMIME(mime_type)
|
||||
return _object_type_from_dict(type_dict)
|
||||
|
||||
_registry = ObjectRegistry()
|
||||
_registry = ObjectTypeRegistry()
|
||||
|
||||
def get_registry():
|
||||
return _registry
|
||||
|
Loading…
Reference in New Issue
Block a user