~ubuntu-branches/ubuntu/karmic/zeroinstall-injector/karmic

« back to all changes in this revision

Viewing changes to zeroinstall/gtkui/gtkutils.py

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Leonard
  • Date: 2008-09-06 11:24:04 UTC
  • mfrom: (1.1.7 upstream) (6.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20080906112404-oogt9d2ir3tx8238
Tags: 0.36-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Useful utility methods for GTK."""
 
2
# Copyright (C) 2008, Thomas Leonard
 
3
# See the README file for details, or visit http://0install.net.
 
4
 
 
5
import gtk
 
6
import gtk.glade
 
7
 
 
8
class Template:
 
9
        """Wrapper for glade widget tree that throws a sensible exception if the widget isn't found."""
 
10
        def __init__(self, gladefile, root):
 
11
                """Constructor.
 
12
                @param gladefile: pathname of the .glade file to load
 
13
                @param root: the name of the top-level widget inside the file"""
 
14
                self.widgets = gtk.glade.XML(gladefile, root)
 
15
                self.gladefile = gladefile
 
16
                self.root = root
 
17
 
 
18
        def get_widget(self, name = None):
 
19
                """Look up a widget by name."""
 
20
                if not name:
 
21
                        name = self.root
 
22
                widget = self.widgets.get_widget(name)
 
23
                assert widget, "Widget '%s' not found in glade file '%s'" % (name, self.gladefile)
 
24
                return widget
 
25
 
 
26
def show_message_box(parent, message, type = gtk.MESSAGE_ERROR):
 
27
        """Display a non-modal message box with an OK button.
 
28
        @param parent: the parent window
 
29
        @param message: the message to be displayed
 
30
        @param type: the type of box (used for the icon)"""
 
31
        box = gtk.MessageDialog(parent, gtk.DIALOG_DESTROY_WITH_PARENT,
 
32
                                type, gtk.BUTTONS_OK,
 
33
                                str(message))
 
34
        box.set_position(gtk.WIN_POS_CENTER)
 
35
        def resp(b, r):
 
36
                b.destroy()
 
37
        box.connect('response', resp)
 
38
        box.show()
 
39
 
 
40
_busy_pointer = None
 
41
def get_busy_pointer():
 
42
        """Get a GDK background-activity cursor.
 
43
        Use this when something is happening, but the GUI is still responsive.
 
44
        @return: the busy cursor (a singleton)
 
45
        @rtype: gdk.Cursor
 
46
        """
 
47
        global _busy_pointer
 
48
        if _busy_pointer is not None:
 
49
                return _busy_pointer
 
50
 
 
51
        # This is crazy. We build a cursor that looks like the old
 
52
        # Netscape busy-with-a-pointer cursor and set that, then the
 
53
        # X server replaces it with a decent-looking one!!
 
54
        # See http://mail.gnome.org/archives/gtk-list/2007-May/msg00100.html
 
55
 
 
56
        bit_data = "\
 
57
\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\
 
58
\x0c\x00\x00\x00\x1c\x00\x00\x00\x3c\x00\x00\x00\
 
59
\x7c\x00\x00\x00\xfc\x00\x00\x00\xfc\x01\x00\x00\
 
60
\xfc\x3b\x00\x00\x7c\x38\x00\x00\x6c\x54\x00\x00\
 
61
\xc4\xdc\x00\x00\xc0\x44\x00\x00\x80\x39\x00\x00\
 
62
\x80\x39\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
 
63
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
 
64
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
 
65
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
 
66
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
 
67
\x00\x00\x00\x00\x00\x00\x00\x00"
 
68
 
 
69
        try:
 
70
                pix = gtk.gdk.bitmap_create_from_data(None, bit_data, 32, 32)
 
71
                color = gtk.gdk.Color()
 
72
                _busy_pointer = gtk.gdk.Cursor(pix, pix, color, color, 2, 2)
 
73
        except:
 
74
                #old bug http://bugzilla.gnome.org/show_bug.cgi?id=103616
 
75
                _busy_pointer = gtk.gdk.Cursor(gtk.gdk.WATCH)
 
76
        return _busy_pointer