Skip to content
Snippets Groups Projects
sections.py 1.54 KiB
Newer Older
  • Learn to ignore specific revisions
  • Benoit Favre's avatar
    Benoit Favre committed
    from gi.repository import Gtk
    
    
    Benoit Favre's avatar
    Benoit Favre committed
    class DefaultConfirmer:
        def confirm(self, *args):
            pass
    
    
    Benoit Favre's avatar
    Benoit Favre committed
    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)
    
    
    Benoit Favre's avatar
    Benoit Favre committed
            self.confirmer = DefaultConfirmer()
    
    Benoit Favre's avatar
    Benoit Favre committed
    
            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))
    
    
    Benoit Favre's avatar
    Benoit Favre committed
            self.highlight = None
    
    
    Benoit Favre's avatar
    Benoit Favre committed
        def set_section(self, section):
            self.section = section
            self.label.set_text('Current section: %d' % self.section)
    
    
    Benoit Favre's avatar
    Benoit Favre committed
            if self.highlight:
                self.highlight.highlight_section(section)
    
        def set_highlight(self, highlight):
            self.highlight = highlight
    
    
    Benoit Favre's avatar
    Benoit Favre committed
        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