Use size request to position the palette.

This commit is contained in:
Marco Pesenti Gritti 2007-06-29 14:56:12 +02:00
parent 893ffe92da
commit f825c108da

View File

@ -122,40 +122,40 @@ class Palette(gobject.GObject):
def _get_position(self, alignment): def _get_position(self, alignment):
# Invoker: x, y, width and height # Invoker: x, y, width and height
inv_rect = self._invoker.get_rect() inv_rect = self._invoker.get_rect()
palette_rect = self._menu.get_allocation() palette_width, palette_height = self._menu.size_request()
if alignment == _BOTTOM_LEFT: if alignment == _BOTTOM_LEFT:
x = inv_rect.x x = inv_rect.x
y = inv_rect.y + inv_rect.height y = inv_rect.y + inv_rect.height
elif alignment == _BOTTOM_RIGHT: elif alignment == _BOTTOM_RIGHT:
x = (inv_rect.x + inv_rect.width) - palette_rect.width x = (inv_rect.x + inv_rect.width) - palette_width
y = inv_rect.y + inv_rect.height y = inv_rect.y + inv_rect.height
elif alignment == _LEFT_BOTTOM: elif alignment == _LEFT_BOTTOM:
x = inv_rect.x - palette_rect.width x = inv_rect.x - palette_width
y = inv_rect.y y = inv_rect.y
elif alignment == _LEFT_TOP: elif alignment == _LEFT_TOP:
x = inv_rect.x - palette_rect.width x = inv_rect.x - palette_width
y = (inv_rect.y + inv_rect.height) - palette_rect.height y = (inv_rect.y + inv_rect.height) - palette_height
elif alignment == _RIGHT_BOTTOM: elif alignment == _RIGHT_BOTTOM:
x = inv_rect.x + inv_rect.width x = inv_rect.x + inv_rect.width
y = inv_rect.y y = inv_rect.y
elif alignment == _RIGHT_TOP: elif alignment == _RIGHT_TOP:
x = inv_rect.x + inv_rect.width x = inv_rect.x + inv_rect.width
y = (inv_rect.y + inv_rect.height) - palette_rect.height y = (inv_rect.y + inv_rect.height) - palette_height
elif alignment == _TOP_LEFT: elif alignment == _TOP_LEFT:
x = inv_rect.x x = inv_rect.x
y = inv_rect.y - palette_rect.height y = inv_rect.y - palette_height
elif alignment == _TOP_RIGHT: elif alignment == _TOP_RIGHT:
x = (inv_rect.x + inv_rect.width) - palette_rect.width x = (inv_rect.x + inv_rect.width) - palette_width
y = inv_rect.y - palette_rect.height y = inv_rect.y - palette_height
return x, y return x, y
def _in_screen(self, x, y): def _in_screen(self, x, y):
allocation = self._menu.get_allocation() [width, height] = self._menu.get_size_request()
return x + allocation.width < gtk.gdk.screen_width() and \ return x + width < gtk.gdk.screen_width() and \
y + allocation.height < gtk.gdk.screen_height() and \ y + height < gtk.gdk.screen_height() and \
x >= 0 and y >= 0 x >= 0 and y >= 0
def _get_automatic_position(self): def _get_automatic_position(self):