summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/ui/crumbs
diff options
context:
space:
mode:
authorJoshua Lock <josh@linux.intel.com>2012-03-02 15:36:45 -0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-03-12 02:24:04 +0000
commit8a8a6568fa90128862123eb976396434feabff0a (patch)
tree32be95f122f1326f76e78a7fd56c8d0894aa48cb /bitbake/lib/bb/ui/crumbs
parent19b38a6486086b62efbff2bf8192adbaa34ecc0a (diff)
downloadpoky-8a8a6568fa90128862123eb976396434feabff0a.tar.gz
crumbs/persistenttooltip: a new Gtk+ widget for use in Hob
The Hob interaction design calls for a top level widget which shows a persistent tooltip. This tooltip will not disappear until the user explicitly closes it. This allows us to provide clickable hyperlinks, longer instructions and deeper information in the tooltips. Note: by design the tooltip should dismiss when the user clicks off it, this implementation does include that functionality. It's a to do item. (Bitbake rev: b310fd429150d3a96ecde477934fffad4b4031da) Signed-off-by: Joshua Lock <josh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/ui/crumbs')
-rw-r--r--bitbake/lib/bb/ui/crumbs/persistenttooltip.py118
1 files changed, 118 insertions, 0 deletions
diff --git a/bitbake/lib/bb/ui/crumbs/persistenttooltip.py b/bitbake/lib/bb/ui/crumbs/persistenttooltip.py
new file mode 100644
index 0000000000..0167363380
--- /dev/null
+++ b/bitbake/lib/bb/ui/crumbs/persistenttooltip.py
@@ -0,0 +1,118 @@
1#
2# BitBake Graphical GTK User Interface
3#
4# Copyright (C) 2012 Intel Corporation
5#
6# Authored by Joshua Lock <josh@linux.intel.com>
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License version 2 as
10# published by the Free Software Foundation.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21import gobject
22import gtk
23
24class PersistentTooltip(gtk.Window):
25 """
26 A tooltip which persists once shown until the user dismisses it with the Esc
27 key or by clicking the close button.
28
29 # FIXME: the PersistentTooltip should be disabled when the user clicks anywhere off
30 # it. We can't do this with focus-out-event becuase modal ensures we have focus?
31
32 markup: some Pango text markup to display in the tooltip
33 """
34 def __init__(self, markup):
35 gtk.Window.__init__(self, gtk.WINDOW_POPUP)
36
37 # We need to ensure we're only shown once
38 self.shown = False
39
40 # We don't want any WM decorations
41 self.set_decorated(False)
42 # We don't want to show in the taskbar or window switcher
43 self.set_skip_pager_hint(True)
44 self.set_skip_taskbar_hint(True)
45 # We must be modal to ensure we grab focus when presented from a gtk.Dialog
46 self.set_modal(True)
47
48 self.set_border_width(6)
49 self.set_position(gtk.WIN_POS_MOUSE)
50 self.set_opacity(0.95)
51
52 # Draw our label and close buttons
53 hbox = gtk.HBox(False, 0)
54 hbox.show()
55 vbox = gtk.VBox(False, 0)
56 vbox.show()
57 vbox.pack_start(hbox, True, True, 0)
58
59 img = gtk.Image()
60 img.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_BUTTON)
61
62 self.button = gtk.Button()
63 self.button.set_image(img)
64 self.button.connect("clicked", self._dismiss_cb)
65 self.button.set_can_default(True)
66 self.button.grab_focus()
67 self.button.show()
68 hbox.pack_end(self.button, False, False, 0)
69
70 self.set_default(self.button)
71
72 self.label = gtk.Label()
73 self.label.set_markup(markup)
74 self.label.show()
75 vbox.pack_end(self.label, True, True, 6)
76
77 self.connect("key-press-event", self._catch_esc_cb)
78
79 # Inherit the system theme for a tooltip
80 style = gtk.rc_get_style_by_paths(gtk.settings_get_default(),
81 'gtk-tooltip', 'gtk-tooltip', gobject.TYPE_NONE)
82 self.set_style(style)
83
84 self.add(vbox)
85
86 """
87 Callback when the PersistentTooltip's close button is clicked.
88 Hides the PersistentTooltip.
89 """
90 def _dismiss_cb(self, button):
91 self.hide()
92 return True
93
94 """
95 Callback when the Esc key is detected. Hides the PersistentTooltip.
96 """
97 def _catch_esc_cb(self, widget, event):
98 keyname = gtk.gdk.keyval_name(event.keyval)
99 if keyname == "Escape":
100 self.hide()
101 return True
102
103 """
104 Called to present the PersistentTooltip.
105 Overrides the superclasses show() method to include state tracking.
106 """
107 def show(self):
108 if not self.shown:
109 self.shown = True
110 gtk.Window.show(self)
111
112 """
113 Called to hide the PersistentTooltip.
114 Overrides the superclasses hide() method to include state tracking.
115 """
116 def hide(self):
117 self.shown = False
118 gtk.Window.hide(self)