50
50
super(ActionBar, self).__init__(spacing=self.PADDING)
51
51
self._btns = Gtk.HBox(spacing=self.PADDING)
52
52
self._btns.set_border_width(self.PADDING)
53
self._label = Gtk.HBox()
54
self._label.set_border_width(self.PADDING)
53
self._label_hbox = Gtk.HBox()
54
self._label_hbox.set_border_width(self.PADDING)
55
55
# So that all buttons children right align
56
56
self._btn_bin = Gtk.Alignment.new(1.0, 0.0, 1.0, 1.0)
57
57
self._btn_bin.set_padding(0, 0, 0, 10)
58
58
self._btn_bin.add(self._btns)
59
59
# Buttons go on the right, labels on the left (in LTR mode)
60
super(ActionBar, self).pack_start(self._label, False, False, 10)
60
super(ActionBar, self).pack_start(self._label_hbox, False, False, 10)
61
61
super(ActionBar, self).pack_end(self._btn_bin, False, True, 0)
63
63
# Don't show_all() by default.
64
64
self.set_no_show_all(True)
65
self._label.show_all()
65
self._label_hbox.show_all()
66
66
self._btn_bin.show_all()
67
67
self._visible = False
128
128
LOG.debug("got sections '%s'" % sections)
129
129
self._label_text = text
131
# Unfortunately, gtk has no native method for embedding a link
132
# in a Gtk.Label with non-link elements. To represent the label,
133
# this method makes an eventbox for each link and non-link
134
# section. If the section corresponds to a link, it hooks hover,
135
# unhover, and click behavior to the box.
136
while len(self._label) > len(sections):
137
last = self._label.get_children()[-1]
138
self._label.remove(last)
139
while len(self._label) < len(sections):
141
self._label.pack_start(box, True, True, 0)
142
# Sections alternate between link and non-link types, so
143
# hook up link methods to even sections.
144
if not len(self._label) % 2:
145
box.connect("button-press-event",
146
self._callback(link_result, link_result_args))
147
box.connect("enter-notify-event", self._hover_link)
148
box.connect("leave-notify-event", self._unhover_link)
131
for i, text_for_label in enumerate(sections):
132
action_bar_item = Gtk.Label(text_for_label)
133
# every second item in the bar is a clickable link,
134
# this is because the text.split("_") earlier (all links
135
# are put into "_foo_"
136
# FIXME: actually remove the "_" and use proper <a href>"
137
# in the label, but this requires a string change
138
# so we need to do it after 12.04
140
markup = text_for_label
141
action_bar_item.set_markup(markup)
143
markup = '<a href="">%s</a>' % text_for_label
144
action_bar_item.set_markup(markup)
145
action_bar_item.connect("activate-link",
146
self._callback(link_result, link_result_args))
147
self._label_hbox.pack_start(action_bar_item, True, True, 0)
150
# Finally, place the text segments in their respective event
151
# boxes. Use pango to underline link segments.
152
for i, box in enumerate(self._label):
156
markup = "<u>%s</u>" % markup
157
label.set_markup(markup)
159
box.remove(box.get_child())
149
self._label_hbox.show_all()
162
150
self._show(animate=False)
164
152
def unset_label(self):