Add a ToolInvoker which position the palette depending

on the toolbar orientation. Make all tool items use it.
This commit is contained in:
Marco Pesenti Gritti 2007-09-01 12:12:32 +02:00
parent 8a9bc3b702
commit 8712ab6b58
4 changed files with 17 additions and 8 deletions

View File

@ -467,7 +467,6 @@ class Invoker(gobject.GObject):
self._screen_area = gtk.gdk.Rectangle(0, 0, gtk.gdk.screen_width(),
gtk.gdk.screen_height())
self._alignments = self.BOTTOM + self.RIGHT + self.TOP + self.LEFT
self._position_hint = self.ANCHORED
self._cursor_x = -1
self._cursor_y = -1
@ -516,7 +515,7 @@ class Invoker(gobject.GObject):
(-1.0, -1.0, 0.0, 0.0),
(-1.0, 0.0, 0.0, 1.0)]
else:
return self._alignments
return self.BOTTOM + self.RIGHT + self.TOP + self.LEFT
def get_position_for_alignment(self, alignment, palette_dim):
rect = self._get_position_for_alignment(alignment, palette_dim)
@ -648,6 +647,16 @@ class CanvasInvoker(Invoker):
def get_toplevel(self):
return hippo.get_canvas_for_item(self._item).get_toplevel()
class ToolInvoker(WidgetInvoker):
def get_aligments(self):
if self.parent is None:
return WidgetInvoker.get_alignments()
if self.parent.get_orientation() is gtk.ORIENTATION_HORIZONTAL:
return self.BOTTOM + self.TOP
else:
return self.LEFT + self.RIGHT
class _PaletteObserver(gobject.GObject):
__gtype_name__ = 'SugarPaletteObserver'

View File

@ -19,7 +19,7 @@
import gtk
from sugar.graphics.icon import Icon
from sugar.graphics.palette import Palette, WidgetInvoker
from sugar.graphics.palette import Palette, ToolInvoker
class RadioToolButton(gtk.RadioToolButton):
__gtype_name__ = "SugarRadioToolButton"
@ -42,7 +42,7 @@ class RadioToolButton(gtk.RadioToolButton):
def set_palette(self, palette):
self._palette = palette
self._palette.props.invoker = WidgetInvoker(self.child)
self._palette.props.invoker = ToolInvoker(self.child)
def set_tooltip(self, text):
self.set_palette(Palette(text))

View File

@ -18,7 +18,7 @@
import gtk
from sugar.graphics.icon import Icon
from sugar.graphics.palette import Palette, WidgetInvoker
from sugar.graphics.palette import Palette, ToolInvoker
class ToggleToolButton(gtk.ToggleToolButton):
__gtype_name__ = "SugarToggleToolButton"
@ -38,7 +38,7 @@ class ToggleToolButton(gtk.ToggleToolButton):
def set_palette(self, palette):
self._palette = palette
self._palette.props.invoker = WidgetInvoker(self.child)
self._palette.props.invoker = ToolInvoker(self.child)
def set_tooltip(self, text):
self.set_palette(Palette(text))

View File

@ -20,7 +20,7 @@ import gobject
import time
from sugar.graphics.icon import Icon
from sugar.graphics.palette import Palette, WidgetInvoker
from sugar.graphics.palette import Palette, ToolInvoker
class ToolButton(gtk.ToolButton):
__gtype_name__ = "SugarToolButton"
@ -42,7 +42,7 @@ class ToolButton(gtk.ToolButton):
def set_palette(self, palette):
self._palette = palette
self._palette.props.invoker = WidgetInvoker(self.child)
self._palette.props.invoker = ToolInvoker(self.child)
def set_tooltip(self, text):
self.set_palette(Palette(text))