~ubuntu-branches/ubuntu/karmic/quodlibet/karmic

« back to all changes in this revision

Viewing changes to qltk/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2009-01-30 23:55:34 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20090130235534-l4e72ulw0vqfo17w
Tags: 2.0-1ubuntu1
* Merge from Debian experimental (LP: #276856), remaining Ubuntu changes:
  + debian/patches/40-use-music-profile.patch:
    - Use the "Music and Movies" pipeline per default.
* Refresh the above patch for new upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2005 Joe Wreschnig, Michael Urman
2
 
#
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
6
 
#
7
 
# $Id: __init__.py 3554 2006-07-03 22:57:00Z mu $
8
 
 
9
 
import gtk
10
 
 
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)
16
 
 
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
25
 
 
26
 
        # fit menu to screen, aligned per text direction
27
 
        screen_width = screen.get_width()
28
 
        screen_height = screen.get_height()
29
 
        menu.realize()
30
 
        ma = menu.allocation
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)
36
 
        else:
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)
40
 
    return True
41
 
            
42
 
# Legacy plugin/code support.
43
 
from qltk.getstring import GetStringDialog
44
 
from qltk.msg import *
45
 
from qltk.x import *