#!/usr/bin/python class Sequence: ''' implement sequence in interface xml''' dict={} def __init__(self, xml_node): self.steps = [ s.attributes["name"].value for s in xml_node.childNodes if s.nodeType == s.ELEMENT_NODE and s.nodeName == "widget" ] self.current_step = 0 def set_current_step(self, st): ''' set current step based on input step name''' self.current_step = self.steps.index(st) @staticmethod def set_current_sequence(name): Sequence.current_sequence = Sequence.dict[name] @staticmethod def current(): return (Sequence.current_sequence, Sequence.current_sequence.steps[Sequence.current_sequence.current_step]) @staticmethod def previous(): if Sequence.current_sequence.current_step: Sequence.current_sequence.current_step -= 1 return Sequence.current_sequence.steps[Sequence.current_sequence.current_step] @staticmethod def next(): if Sequence.current_sequence.current_step < len(Sequence.current_sequence.steps)-1: Sequence.current_sequence.current_step += 1 return Sequence.current_sequence.steps[Sequence.current_sequence.current_step] def construct(xml_root): ''' construct Sequence's static members''' for s in xml_root.childNodes: if s.nodeType == s.ELEMENT_NODE and s.nodeName == "sequence": Sequence.dict[s.attributes["name"].value] = Sequence(s)