from gi.repository import Gtk class DefaultConfirmer: def confirm(self, *args): pass class SectionManager(Gtk.HBox): def __init__(self): super(SectionManager, self).__init__() self.set_name('SessionManager') self.button_next = Gtk.Button('Next') self.button_prev = Gtk.Button('Previous') self.label = Gtk.Label() self.label.get_style_context().add_class('current-section') self.pack_start(self.button_prev, False, False, 5) self.pack_start(self.label, True, True, 5) self.pack_start(self.button_next, False, False, 5) self.confirmer = DefaultConfirmer() self.button_next.connect('clicked', lambda widget: self.confirmer.confirm('Go to next section?', 3, self.next_section)) self.button_prev.connect('clicked', lambda widget: self.confirmer.confirm('Go to previous section?', 3, self.previous_section)) self.highlight = None def set_section(self, section): self.section = section self.label.set_text('Current section: %d' % self.section) if self.highlight: self.highlight.highlight_section(section) def set_highlight(self, highlight): self.highlight = highlight def get_view(self): return self.hbox def get_section(self): return self.section def next_section(self): self.set_section(self.section + 1) def previous_section(self): self.set_section(self.section - 1) def set_confirmer(self, confirmer): self.confirmer = confirmer