ActionSet.py
Go to the documentation of this file.
00001 from Action import Action
00002 
00003 class ActionSet(Action):
00004 
00005     def __init__(self):
00006         super(ActionSet, self).__init__()
00007         self._actions = []
00008         self._executing = 0
00009 
00010     def add_action(self, action):
00011         self._actions.append(action)
00012 
00013     def remove_all_actions(self):
00014         self._actions = []
00015 
00016     def get_duration(self):
00017         duration = 0.0
00018         for action in self._actions:
00019             duration = max(duration, action.get_duration())
00020         return duration
00021 
00022     def set_duration(self, duration):
00023         for action in self._actions:
00024             action.set_duration(duration)
00025 
00026     def get_labels(self):
00027         labels = []
00028         for action in self._actions:
00029             try:
00030                 labels += action.get_labels()
00031             except AttributeError:
00032                 # action does not support get_value
00033                 pass
00034         return labels
00035 
00036     def get_value(self, label):
00037         for action in self._actions:
00038             try:
00039                 value = action.get_value(label)
00040                 return value
00041             except AttributeError:
00042                 # action does not support get_value
00043                 pass
00044             except KeyError:
00045                 # action does not have a joint with that label
00046                 pass
00047         raise KeyError('joint with label "%s" not found' % label)
00048 
00049     def get_joint_info(self, label):
00050         for action in self._actions:
00051             try:
00052                 indexes = [i for i, data in enumerate(action._joints) if data['label'] == label]
00053                 if len(indexes) == 1:
00054                     return action._joints[indexes[0]]
00055             except AttributeError:
00056                 # action does not support get_value
00057                 pass
00058         raise KeyError('joint with label "%s" not found' % label)
00059 
00060     def update_value(self, label, value):
00061         for action in self._actions:
00062             try:
00063                 action.update_value(label, value)
00064                 return
00065             except:
00066                 pass
00067         raise KeyError('joint with label "%s" not found' % label)
00068 
00069     def to_string(self):
00070         data = []
00071         for action in self._actions:
00072             data.append(action.to_string())
00073         return ';'.join(data)
00074 
00075     def deepcopy(self):
00076         set = super(ActionSet, self).deepcopy()
00077         for action in self._actions:
00078             set.add_action(action.deepcopy())
00079         return set
00080 
00081     def serialize(self, stream):
00082         stream.serialize_data(len(self._actions))
00083         for action in self._actions:
00084             stream.serialize_instance(action)
00085 
00086     def deserialize(self, stream):
00087         self.remove_all_actions()
00088         count = stream.deserialize_data()
00089         for i in range(count):
00090             action = stream.deserialize_instance()
00091             self.add_action(action)
00092 
00093     def execute(self):
00094         if self._executing > 0:
00095             print('ActionSet.execute() skipped because previous execute has not yet finished')
00096             return
00097         #print('ActionSet.execute() %d' % len(self._actions))
00098         self._executing = len(self._actions)
00099         for action in self._actions:
00100             action.execute_finished_signal.connect(self._action_finished)
00101             action.execute()
00102 
00103     def _action_finished(self):
00104         assert(self._executing > 0)
00105         self._executing -= 1
00106         if self._executing == 0:
00107             #print('ActionSet.execute() finished\n')
00108             self._stop()
00109             self._execute_finished()
00110 
00111     def stop(self):
00112         print('ActionSet.stop()\n')
00113         self._stop()
00114         self._executing = 0
00115 
00116     def _stop(self):
00117         for action in self._actions:
00118             action.execute_finished_signal.disconnect(self._action_finished)


slider_gui
Author(s): Dirk Thomas
autogenerated on Wed Aug 26 2015 15:37:50