Files
new_install/python/mine/ri_seq.py
lizhi-rocky 5ed4600bf7 ~~~
2010-07-12 17:35:16 +08:00

49 lines
1.6 KiB
Python

#!/usr/bin/python
current_sequence=""
previous_sequences=[]
dict={}
class Sequence:
''' implement sequence in interface xml'''
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_step(self, st):
''' set current step based on input step name'''
self.current_step = self.steps.index(st)
def construct(xml_root):
''' construct Sequence's static members'''
global current_sequence
current_sequence = xml_root.attributes["sequence"].value
for s in xml_root.childNodes:
if s.nodeType == s.ELEMENT_NODE and s.nodeName == "sequence":
dict[s.attributes["name"].value] = Sequence(s)
def previous():
global current_sequence
cur_seq = dict[current_sequence]
if cur_seq.current_step:
cur_seq.current_step -= 1
return cur_seq.steps[cur_seq.current_step]
# current sequence already in first step
elif previous_sequences:
current_sequence = previous_sequences.pop()
cur_seq = dict[current_sequence]
return cur_seq.steps[cur_seq.current_step]
def next():
global current_sequence
cur_seq = dict[current_sequence]
if cur_seq.current_step < len(cur_seq.steps)-1:
cur_seq.current_step += 1
return cur_seq.steps[cur_seq.current_step]
# current sequence already in last step
elif previous_sequences:
current_sequence = previous_sequences.pop()
cur_seq = dict[current_sequence]
return cur_seq.steps[cur_seq.current_step]