''' Inserts a piece of text into the buffer, giving it the usual
appearance of a hyperlink in a web browser: blue and underlined.
Additionally, attaches some data on the tag, to make it recognizable
as a link.
'''
tag = buffer.create_tag(None, foreground = 'blue', underline = pango.UNDERLINE_SINGLE)
tag.set_data('page', page)
buffer.insert_with_tags(iter, text, tag)
def show_page(self, buffer, page):
''' Fills the buffer with text and interspersed links. In any real
hypertext app, this method would parse a file to identify the links.
'''
buffer.set_text('', 0)
iter = buffer.get_iter_at_offset(0)
if page == 1:
buffer.insert(iter, 'Some text to show that simple ')
self.insert_link(buffer, iter, 'hypertext', 3)
buffer.insert(iter, ' can easily be realized with ')
self.insert_link(buffer, iter, 'tags', 2)
buffer.insert(iter, '.')
elif page == 2:
buffer.insert(iter, 'A tag is an attribute that can be applied to some range of text. For example, a tag might be called "bold" and make the text inside the tag bold. However, the tag concept is more general than that tags don\'t have to affect appearance. They can instead affect the behavior of mouse and key presses, "lock" a range of text so the user can\'t edit it, or countless other things.\n', -1)
self.insert_link(buffer, iter, 'Go back', 1)
elif page == 3:
tag = buffer.create_tag(None, weight = pango.WEIGHT_BOLD)