Merge branch 'master' of git+ssh://dev.laptop.org/git/sugar
This commit is contained in:
@@ -122,7 +122,8 @@ class ActivityCreationHandler(gobject.GObject):
|
||||
error_handler=self._notify_launch_error_handler)
|
||||
|
||||
if not os.path.exists('/etc/olpc-security'):
|
||||
self._factory.create(self._activity_handle.get_dict(),
|
||||
handle = self._activity_handle.get_dict()
|
||||
self._factory.create(dbus.Dictionary(handle, signature='ss'),
|
||||
timeout=120 * 1000,
|
||||
reply_handler=self._no_reply_handler,
|
||||
error_handler=self._create_error_handler)
|
||||
|
||||
@@ -67,15 +67,13 @@ class ActivityHandle(object):
|
||||
|
||||
def get_dict(self):
|
||||
"""Retrieve our settings as a dictionary"""
|
||||
result = { }
|
||||
if self.activity_id:
|
||||
result['activity_id'] = str(self.activity_id)
|
||||
result = { 'activity_id' : self.activity_id }
|
||||
if self.pservice_id:
|
||||
result['pservice_id'] = str(self.pservice_id)
|
||||
result['pservice_id'] = self.pservice_id
|
||||
if self.object_id:
|
||||
result['object_id'] = str(self.object_id)
|
||||
result['object_id'] = self.object_id
|
||||
if self.uri:
|
||||
result['uri'] = str(self.uri)
|
||||
result['uri'] = self.uri
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@@ -249,5 +249,8 @@ def unmount(mount_point_id):
|
||||
def mounts():
|
||||
return dbus_helpers.mounts()
|
||||
|
||||
def complete_indexing():
|
||||
return dbus_helpers.complete_indexing()
|
||||
|
||||
def get_unique_values(key):
|
||||
return dbus_helpers.get_unique_values(key)
|
||||
|
||||
@@ -88,3 +88,6 @@ def mounts():
|
||||
def get_unique_values(key):
|
||||
return _get_data_store().get_uniquevaluesfor(key, dbus.Dictionary({}, signature='ss'))
|
||||
|
||||
def complete_indexing():
|
||||
return _get_data_store().complete_indexing()
|
||||
|
||||
|
||||
+56
-78
@@ -73,10 +73,6 @@ class Palette(gtk.Window):
|
||||
DEFAULT = 0
|
||||
AT_CURSOR = 1
|
||||
AROUND = 2
|
||||
BOTTOM = 3
|
||||
LEFT = 4
|
||||
RIGHT = 5
|
||||
TOP = 6
|
||||
|
||||
PRIMARY = 0
|
||||
SECONDARY = 1
|
||||
@@ -106,6 +102,7 @@ class Palette(gtk.Window):
|
||||
|
||||
self.palette_state = self.PRIMARY
|
||||
|
||||
self._current_alignment = None
|
||||
self._old_alloc = None
|
||||
self._full_request = [0, 0]
|
||||
self._cursor_x = 0
|
||||
@@ -278,21 +275,26 @@ class Palette(gtk.Window):
|
||||
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
|
||||
self._update_accept_focus()
|
||||
|
||||
def _in_screen(self, x, y):
|
||||
[width, height] = self._full_request
|
||||
def _in_screen(self, rect):
|
||||
screen_area = self._invoker.get_screen_area()
|
||||
return rect.x >= screen_area.x and \
|
||||
rect.y >= screen_area.y and \
|
||||
rect.x + rect.width <= screen_area.width and \
|
||||
rect.y + rect.height <= screen_area.height
|
||||
|
||||
return x >= screen_area.x and \
|
||||
y >= screen_area.y and \
|
||||
x + width <= screen_area.width and \
|
||||
y + height <= screen_area.height
|
||||
def _get_rectangle(self, alignments, full=False, inv_rect=None):
|
||||
palette_halign = alignments[0]
|
||||
palette_valign = alignments[1]
|
||||
invoker_halign = alignments[2]
|
||||
invoker_valign = alignments[3]
|
||||
|
||||
def _get_position(self, palette_halign, palette_valign,
|
||||
invoker_halign, invoker_valign, inv_rect=None):
|
||||
if inv_rect == None:
|
||||
inv_rect = self._invoker.get_rect()
|
||||
|
||||
palette_width, palette_height = self.size_request()
|
||||
if full:
|
||||
palette_width, palette_height = self._full_request
|
||||
else:
|
||||
palette_width, palette_height = self.size_request()
|
||||
|
||||
x = inv_rect.x + inv_rect.width * invoker_halign + \
|
||||
palette_width * palette_halign
|
||||
@@ -300,53 +302,24 @@ class Palette(gtk.Window):
|
||||
y = inv_rect.y + inv_rect.height * invoker_valign + \
|
||||
palette_height * palette_valign
|
||||
|
||||
return int(x), int(y)
|
||||
return gtk.gdk.Rectangle(int(x), int(y),
|
||||
palette_width, palette_height)
|
||||
|
||||
def _get_left_position(self, inv_rect=None):
|
||||
x, y = self._get_position(-1.0, 0.0, 0.0, 0.0, inv_rect)
|
||||
if not self._in_screen(x, y):
|
||||
x, y = self._get_position(-1.0, -1.0, 0.0, 1.0, inv_rect)
|
||||
return x, y
|
||||
def _get_around_alignments(self):
|
||||
return [(0.0, 0.0, 0.0, 1.0),
|
||||
(-1.0, 0.0, 1.0, 1.0),
|
||||
(0.0, 0.0, 1.0, 0.0),
|
||||
(0.0, -1.0, 1.0, 1.0),
|
||||
(0.0, -1.0, 0.0, 0.0),
|
||||
(-1.0, -1.0, 1.0, 0.0),
|
||||
(-1.0, 0.0, 0.0, 0.0),
|
||||
(-1.0, -1.0, 0.0, 1.0)]
|
||||
|
||||
def _get_right_position(self, inv_rect=None):
|
||||
x, y = self._get_position(0.0, 0.0, 1.0, 0.0, inv_rect)
|
||||
if not self._in_screen(x, y):
|
||||
x, y = self._get_position(0.0, -1.0, 1.0, 1.0, inv_rect)
|
||||
return x, y
|
||||
|
||||
def _get_top_position(self, inv_rect=None):
|
||||
x, y = self._get_position(0.0, -1.0, 0.0, 0.0, inv_rect)
|
||||
if not self._in_screen(x, y):
|
||||
x, y = self._get_position(-1.0, -1.0, 1.0, 0.0, inv_rect)
|
||||
return x, y
|
||||
|
||||
def _get_bottom_position(self, inv_rect=None):
|
||||
x, y = self._get_position(0.0, 0.0, 0.0, 1.0, inv_rect)
|
||||
if not self._in_screen(x, y):
|
||||
x, y = self._get_position(-1.0, 0.0, 1.0, 1.0, inv_rect)
|
||||
return x, y
|
||||
|
||||
def _get_around_position(self, inv_rect=None):
|
||||
x, y = self._get_bottom_position(inv_rect)
|
||||
if not self._in_screen(x, y):
|
||||
x, y = self._get_right_position(inv_rect)
|
||||
if not self._in_screen(x, y):
|
||||
x, y = self._get_top_position(inv_rect)
|
||||
if not self._in_screen(x, y):
|
||||
x, y = self._get_left_position(inv_rect)
|
||||
|
||||
return x, y
|
||||
|
||||
def _get_at_cursor_position(self, inv_rect=None):
|
||||
x, y = self._get_position(0.0, 0.0, 1.0, 1.0, inv_rect)
|
||||
if not self._in_screen(x, y):
|
||||
x, y = self._get_position(0.0, -1.0, 1.0, 0.0, inv_rect)
|
||||
if not self._in_screen(x, y):
|
||||
x, y = self._get_position(-1.0, -1.0, 0.0, 0.0, inv_rect)
|
||||
if not self._in_screen(x, y):
|
||||
x, y = self._get_position(-1.0, 0.0, 0.0, 1.0, inv_rect)
|
||||
|
||||
return x, y
|
||||
def _get_at_cursor_alignments(self, inv_rect=None):
|
||||
return [(0.0, 0.0, 1.0, 1.0),
|
||||
(0.0, -1.0, 1.0, 0.0),
|
||||
(-1.0, -1.0, 0.0, 0.0),
|
||||
(-1.0, 0.0, 0.0, 1.0)]
|
||||
|
||||
def _update_full_request(self):
|
||||
state = self.palette_state
|
||||
@@ -374,25 +347,24 @@ class Palette(gtk.Window):
|
||||
else:
|
||||
position = self._position
|
||||
|
||||
inv_rect = None
|
||||
if position == self.AT_CURSOR:
|
||||
dist = style.PALETTE_CURSOR_DISTANCE
|
||||
rect = gtk.gdk.Rectangle(self._cursor_x - dist,
|
||||
self._cursor_y - dist,
|
||||
dist * 2, dist * 2)
|
||||
inv_rect = gtk.gdk.Rectangle(self._cursor_x - dist,
|
||||
self._cursor_y - dist,
|
||||
dist * 2, dist * 2)
|
||||
|
||||
x, y = self._get_at_cursor_position(rect)
|
||||
elif position == self.AROUND:
|
||||
x, y = self._get_around_position()
|
||||
elif position == self.BOTTOM:
|
||||
x, y = self._get_bottom_position()
|
||||
elif position == self.LEFT:
|
||||
x, y = self._get_left_position()
|
||||
elif position == self.RIGHT:
|
||||
x, y = self._get_right_position()
|
||||
elif position == self.TOP:
|
||||
x, y = self._get_top_position()
|
||||
alignments = self._get_around_alignments()[:]
|
||||
if self._current_alignment is not None:
|
||||
alignments.remove(self._current_alignment)
|
||||
alignments.insert(0, self._current_alignment)
|
||||
|
||||
self.move(x, y)
|
||||
for align in alignments:
|
||||
rect = self._get_rectangle(align, inv_rect=inv_rect)
|
||||
if self._in_screen(rect):
|
||||
break
|
||||
|
||||
self.move(rect.x, rect.y)
|
||||
|
||||
def _show(self):
|
||||
if self._up:
|
||||
@@ -404,6 +376,12 @@ class Palette(gtk.Window):
|
||||
self._palette_popup_sid = _palette_observer.connect(
|
||||
'popup', self._palette_observer_popup_cb)
|
||||
|
||||
for align in self._get_around_alignments():
|
||||
rect = self._get_rectangle(align, full=True)
|
||||
if self._in_screen(rect):
|
||||
self._current_alignment = align
|
||||
break
|
||||
|
||||
self._update_position()
|
||||
self.menu.set_active(True)
|
||||
self.show()
|
||||
@@ -659,11 +637,11 @@ class CanvasInvoker(Invoker):
|
||||
context = self._item.get_context()
|
||||
if context:
|
||||
x, y = context.translate_to_screen(self._item)
|
||||
|
||||
width, height = self._item.get_allocation()
|
||||
|
||||
return gtk.gdk.Rectangle(x, y, width, height)
|
||||
|
||||
width, height = self._item.get_allocation()
|
||||
return gtk.gdk.Rectangle(x, y, width, height)
|
||||
else:
|
||||
return gtk.gdk.Rectangle()
|
||||
|
||||
def _motion_notify_event_cb(self, button, event):
|
||||
if event.detail == hippo.MOTION_DETAIL_ENTER:
|
||||
self.emit('mouse-enter')
|
||||
|
||||
+92
-32
@@ -22,13 +22,17 @@ from sugar.graphics import style
|
||||
from sugar.graphics.toolbutton import ToolButton
|
||||
from sugar.graphics.icon import Icon
|
||||
|
||||
_PREVIOUS_PAGE = 0
|
||||
_NEXT_PAGE = 1
|
||||
|
||||
class _TrayViewport(gtk.Viewport):
|
||||
__gproperties__ = {
|
||||
'can-scroll' : (bool, None, None, False,
|
||||
gobject.PARAM_READABLE),
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, orientation):
|
||||
self.orientation = orientation
|
||||
self._can_scroll = False
|
||||
|
||||
gobject.GObject.__init__(self)
|
||||
@@ -36,26 +40,47 @@ class _TrayViewport(gtk.Viewport):
|
||||
self.set_shadow_type(gtk.SHADOW_NONE)
|
||||
|
||||
self.traybar = gtk.Toolbar()
|
||||
self.traybar.set_orientation(orientation)
|
||||
self.traybar.set_show_arrow(False)
|
||||
self.add(self.traybar)
|
||||
self.traybar.show()
|
||||
|
||||
self.connect('size_allocate', self._size_allocate_cb)
|
||||
|
||||
def scroll_right(self):
|
||||
adj = self.get_hadjustment()
|
||||
new_value = adj.value + self.allocation.width
|
||||
adj.value = min(new_value, adj.upper - self.allocation.width)
|
||||
def scroll(self, direction):
|
||||
if direction == _PREVIOUS_PAGE:
|
||||
self._scroll_previous()
|
||||
elif direction == _NEXT_PAGE:
|
||||
self._scroll_next()
|
||||
|
||||
def scroll_left(self):
|
||||
adj = self.get_hadjustment()
|
||||
new_value = adj.value - self.allocation.width
|
||||
adj.value = max(adj.lower, new_value)
|
||||
def _scroll_next(self):
|
||||
if self.orientation == gtk.ORIENTATION_HORIZONTAL:
|
||||
adj = self.get_hadjustment()
|
||||
new_value = adj.value + self.allocation.width
|
||||
adj.value = min(new_value, adj.upper - self.allocation.width)
|
||||
else:
|
||||
adj = self.get_vadjustment()
|
||||
new_value = adj.value + self.allocation.height
|
||||
adj.value = min(new_value, adj.upper - self.allocation.height)
|
||||
|
||||
def _scroll_previous(self):
|
||||
if self.orientation == gtk.ORIENTATION_HORIZONTAL:
|
||||
adj = self.get_hadjustment()
|
||||
new_value = adj.value - self.allocation.width
|
||||
adj.value = max(adj.lower, new_value)
|
||||
else:
|
||||
adj = self.get_vadjustment()
|
||||
new_value = adj.value - self.allocation.height
|
||||
adj.value = max(adj.lower, new_value)
|
||||
|
||||
def do_size_request(self, requisition):
|
||||
child_requisition = self.child.size_request()
|
||||
requisition[0] = 0
|
||||
requisition[1] = child_requisition[1]
|
||||
if self.orientation == gtk.ORIENTATION_HORIZONTAL:
|
||||
requisition[0] = 0
|
||||
requisition[1] = child_requisition[1]
|
||||
else:
|
||||
requisition[0] = child_requisition[0]
|
||||
requisition[1] = 0
|
||||
|
||||
def do_get_property(self, pspec):
|
||||
if pspec.name == 'can-scroll':
|
||||
@@ -63,19 +88,23 @@ class _TrayViewport(gtk.Viewport):
|
||||
|
||||
def _size_allocate_cb(self, viewport, allocation):
|
||||
bar_requisition = self.traybar.get_child_requisition()
|
||||
if bar_requisition[0] < allocation.width:
|
||||
can_scroll = False
|
||||
if self.orientation == gtk.ORIENTATION_HORIZONTAL:
|
||||
can_scroll = bar_requisition[0] > allocation.width
|
||||
else:
|
||||
can_scroll = True
|
||||
can_scroll = bar_requisition[1] > allocation.height
|
||||
|
||||
if can_scroll != self._can_scroll:
|
||||
self._can_scroll = can_scroll
|
||||
self.notify('can-scroll')
|
||||
|
||||
class _TrayScrollButton(gtk.Button):
|
||||
def __init__(self, icon_name):
|
||||
def __init__(self, icon_name, scroll_direction):
|
||||
gobject.GObject.__init__(self)
|
||||
|
||||
self._viewport = None
|
||||
|
||||
self._scroll_direction = scroll_direction
|
||||
|
||||
self.set_relief(gtk.RELIEF_NONE)
|
||||
self.set_size_request(style.GRID_CELL_SIZE, style.GRID_CELL_SIZE)
|
||||
|
||||
@@ -84,34 +113,65 @@ class _TrayScrollButton(gtk.Button):
|
||||
self.set_image(icon)
|
||||
icon.show()
|
||||
|
||||
self.connect('clicked', self._clicked_cb)
|
||||
|
||||
def set_viewport(self, viewport):
|
||||
self._viewport = viewport
|
||||
self._viewport.connect('notify::can-scroll',
|
||||
self._viewport_can_scroll_changed_cb)
|
||||
|
||||
def _viewport_can_scroll_changed_cb(self, viewport, pspec):
|
||||
self.props.visible = self._viewport.props.can_scroll
|
||||
|
||||
def _clicked_cb(self, button):
|
||||
self._viewport.scroll(self._scroll_direction)
|
||||
|
||||
viewport = property(fset=set_viewport)
|
||||
|
||||
class HTray(gtk.HBox):
|
||||
def __init__(self, **kwargs):
|
||||
gobject.GObject.__init__(self, **kwargs)
|
||||
|
||||
self._scroll_left = _TrayScrollButton('go-left')
|
||||
self._scroll_left.connect('clicked', self._scroll_left_cb)
|
||||
self.pack_start(self._scroll_left, False)
|
||||
scroll_left = _TrayScrollButton('go-left', _PREVIOUS_PAGE)
|
||||
self.pack_start(scroll_left, False)
|
||||
|
||||
self._viewport = _TrayViewport()
|
||||
self._viewport.connect('notify::can-scroll',
|
||||
self._viewport_can_scroll_changed_cb)
|
||||
self._viewport = _TrayViewport(gtk.ORIENTATION_HORIZONTAL)
|
||||
self.pack_start(self._viewport)
|
||||
self._viewport.show()
|
||||
|
||||
self._scroll_right = _TrayScrollButton('go-right')
|
||||
self._scroll_right.connect('clicked', self._scroll_right_cb)
|
||||
self.pack_start(self._scroll_right, False)
|
||||
scroll_right = _TrayScrollButton('go-right', _NEXT_PAGE)
|
||||
self.pack_start(scroll_right, False)
|
||||
|
||||
def _viewport_can_scroll_changed_cb(self, viewport, pspec):
|
||||
if self._viewport.props.can_scroll:
|
||||
self._scroll_left.show()
|
||||
self._scroll_right.show()
|
||||
scroll_left.viewport = self._viewport
|
||||
scroll_right.viewport = self._viewport
|
||||
|
||||
def _scroll_left_cb(self, button):
|
||||
self._viewport.scroll_left()
|
||||
def add_item(self, item, index=-1):
|
||||
self._viewport.traybar.insert(item, index)
|
||||
|
||||
def _scroll_right_cb(self, button):
|
||||
self._viewport.scroll_right()
|
||||
def remove_item(self, item):
|
||||
self._viewport.traybar.remove(item)
|
||||
|
||||
def get_item_index(self, item):
|
||||
return self._viewport.traybar.get_item_index(item)
|
||||
|
||||
class VTray(gtk.VBox):
|
||||
def __init__(self, **kwargs):
|
||||
gobject.GObject.__init__(self, **kwargs)
|
||||
|
||||
# FIXME we need a go-up icon
|
||||
scroll_left = _TrayScrollButton('go-left', _PREVIOUS_PAGE)
|
||||
self.pack_start(scroll_left, False)
|
||||
|
||||
self._viewport = _TrayViewport(gtk.ORIENTATION_VERTICAL)
|
||||
self.pack_start(self._viewport)
|
||||
self._viewport.show()
|
||||
|
||||
# FIXME we need a go-down icon
|
||||
scroll_right = _TrayScrollButton('go-right', _NEXT_PAGE)
|
||||
self.pack_start(scroll_right, False)
|
||||
|
||||
scroll_left.viewport = self._viewport
|
||||
scroll_right.viewport = self._viewport
|
||||
|
||||
def add_item(self, item, index=-1):
|
||||
self._viewport.traybar.insert(item, index)
|
||||
|
||||
Reference in New Issue
Block a user