Skip to content
Snippets Groups Projects
action.py 1001 B
Newer Older
  • Learn to ignore specific revisions
  • Benoit Favre's avatar
    Benoit Favre committed
    from gi.repository import Gtk
    
    class ActionView(Gtk.HBox):
        def __init__(self):
            super(ActionView, self).__init__()
            self.actions = set(['next', 'previous', 'light-on', 'light-off'])
    
            self.pack_start(Gtk.Label('Actions:'), False, False, 5)
            for action in self.actions:
                button = Gtk.Button(action)
                button.connect('clicked', self._perform)
                self.pack_start(button, False, False, 5)
    
            self.confiermer = None
    
        def _perform(self, button):
            action = button.get_label()
            if self.confirmer:
                self.confirmer.confirm('Perform action "%s"?' % action, 4, lambda: self.perform(action))
            else:
                self.perform(action)
    
        def perform(self, action):
            if action in self.actions:
                print 'PERFORM', action
                return True
            return False
    
        def actions(self):
            return self.actions
    
        def set_confirmer(self, confirmer):
            self.confirmer = confirmer