Skip to content
Snippets Groups Projects
actions.py 1.66 KiB
Newer Older
  • Learn to ignore specific revisions
  • import re
    
    import osc, log
    
    class Action:
        def __init__(self, text, **kwargs):
            self.text = text
    
    Benoit Favre's avatar
    Benoit Favre committed
            for key, value in kwargs.items():
    
                setattr(self, key, value)
    
    class ActionManager:
    
    Benoit Favre's avatar
    Benoit Favre committed
        def __init__(self, confirmer, highlighter, logger=log.ConsoleLogger()):
    
            #self.client = osc.Client(host, port)
            self.confirmer = confirmer
            self.highlighter = highlighter
            self.logger = logger
    
        def confirmed_perform(self, action):
            osc.client.send_action(action)
            self.highlighter.highlight(action)
            self.logger.log(action)
    
        def perform(self, action, confirm=True, timeout=3):
            if confirm:
    
    Benoit Favre's avatar
    Benoit Favre committed
                self.confirmer.confirm('Perform action "%s"?' % action.text, timeout, lambda: self.confirmed_perform(action))
    
            else:
                self.confirmed_perform(action)
    
    manager = None
    
    
    Benoit Favre's avatar
    Benoit Favre committed
    def setup(confirmer, highlighter, logger=log.ConsoleLogger()):
    
        global manager
        manager = ActionManager(confirmer, highlighter, logger)
    
    def perform_action(action, confirm=True, timeout=3):
        global manager
        manager.perform(action, confirm, timeout)
    
    
    #action(1,1,"#ENDSECTION(1)","")
    def parse_slu_action(text):
    
        found = re.search(r'^action\((\d+),(\d+),(\d+),"(([^"\\]|\\")*)","(([^"\\]|\\")*)"\)$', text)
    
        if found:
            section_id = int(found.group(1))
            sequence_id = int(found.group(2))
    
            action_id = int(found.group(3))
            action_name = found.group(4)
            action_text = found.group(6)
    
            return Action(action_name, section=section_id, sequence=sequence_id, words=action_text, action_id=action_id)
    
        print "Warning: could not parse slu action '%s'" % text
        return Action(text)