1
# Copyright 2005 Joe Wreschnig, Michael Urman
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License version 2 as
5
# published by the Free Software Foundation
7
# $Id: __init__.py 3554 2006-07-03 22:57:00Z mu $
11
def get_top_parent(widget):
12
"""Return the ultimate parent of a widget; the assumption that code
13
using this makes is that it will be a gtk.Window, i.e. the widget
14
is fully packed when this is called."""
15
return widget and widget.get_ancestor(gtk.Window)
17
def popup_menu_under_widget(menu, widget, button, time):
18
def pos_func(menu, widget=widget):
19
screen = widget.get_screen()
20
ref = get_top_parent(widget)
21
menu.set_screen(screen)
22
x, y = widget.translate_coordinates(ref, 0, 0)
23
dx, dy = ref.window.get_origin()
24
wa = widget.allocation
26
# fit menu to screen, aligned per text direction
27
screen_width = screen.get_width()
28
screen_height = screen.get_height()
31
menu_y = y + dy + wa.height
32
if menu_y + ma.height > screen_height and y + dy - ma.height > 0:
33
menu_y = y + dy - ma.height
34
if gtk.widget_get_default_direction() == gtk.TEXT_DIR_LTR:
35
menu_x = min(x + dx, screen_width - ma.width)
37
menu_x = max(0, x + dx - ma.width + wa.width)
38
return (menu_x, menu_y, True) # x, y, move_within_screen
39
menu.popup(None, None, pos_func, button, time)
42
# Legacy plugin/code support.
43
from qltk.getstring import GetStringDialog
44
from qltk.msg import *