00001
00002 def _update_server_list(self):
00003 while self._keep_running:
00004
00005 server_names = self._client.get_servers()
00006 new_server_names = [sn for sn in server_names if sn not in self._status_subs]
00007
00008
00009 for server_name in new_server_names:
00010 self._structure_subs[server_name] = rospy.Subscriber(
00011 server_name+smach_ros.introspection.STRUCTURE_TOPIC,
00012 SmachContainerStructure,
00013 callback = self._structure_msg_update,
00014 callback_args = server_name,
00015 queue_size=50)
00016
00017 self._status_subs[server_name] = rospy.Subscriber(
00018 server_name+smach_ros.introspection.STATUS_TOPIC,
00019 SmachContainerStatus,
00020 callback = self._status_msg_update,
00021 queue_size=50)
00022
00023
00024 rospy.sleep(1.0)
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 def _status_msg_update(self, msg):
00035 if not self._keep_running:
00036 return
00037 path = msg.path
00038
00039 needs_redraw = False
00040 if path in self._containers:
00041 container = self._containers[path]
00042 if container.update_status(msg):
00043
00044 """
00045 for child_label in container._children:
00046 child_path = '/'.join([path,child_label])
00047 if child_path in self.widget.items:
00048 if child_label in container._active_states:
00049 #print 'SET "'+child_path+'" ACTIVE'
00050 pass
00051 for shape in self.widget.items[child_path].shapes:
00052 if child_label in container._active_states:
00053 shape.pen.fillcolor = (0,1,0,1)
00054 elif child_label in container._last_active_states:
00055 shape.pen.fillcolor = (1,0.85,0.85,1)
00056 else:
00057 shape.pen.fillcolor = (1,1,1,1)
00058 """
00059 self._update_cond.acquire()
00060 self._update_cond.notify_all()
00061 self._update_cond.release()
00062
00063 path_input_str = self.path_input.GetValue()
00064 if path_input_str == path or get_parent_path(path_input_str) == path:
00065 wx.PostEvent(
00066 self.path_input.GetEventHandler(),
00067 wx.CommandEvent(wx.wxEVT_COMMAND_COMBOBOX_SELECTED,self.path_input.GetId()))
00068
00069 def _structure_msg_update(self, msg, server_name):
00070 if not self._keep_running:
00071 return
00072
00073 path = msg.path
00074 pathsplit = path.split('/')
00075 dir = '/'.join(pathsplit[0:-1])
00076
00077
00078
00079
00080 needs_redraw = False
00081 if path in self._containers:
00082 needs_redraw = self._containers[path].update_structure(msg)
00083 else:
00084
00085 needs_redraw= True
00086 self._needs_zoom = True
00087 container = ContainerNode(server_name, msg)
00088 self._containers[path] = container
00089
00090 if dir=='':
00091 self._top_containers[path] = container
00092
00093 self.path_combo.Append(path)
00094 self.path_input.Append(path)
00095
00096 self._update_cond.acquire()
00097 if needs_redraw:
00098 self._structure_changed = True
00099 self._needs_zoom = True
00100 self._update_cond.notify_all()
00101 self._update_cond.release()
00102
00103 def update_structure(self, msg):
00104 needs_update = False
00105
00106 if self._children != msg.children\
00107 or self._internal_outcomes != msg.internal_outcomes\
00108 or self._outcomes_from != msg.outcomes_from\
00109 or self._outcomes_to != msg.outcomes_to\
00110 or self._container_outcomes != msg.container_outcomes:
00111 needs_update = True
00112
00113 if needs_update:
00114 self._children = msg.children
00115 self._internal_outcomes = msg.internal_outcomes
00116 self._outcomes_from = msg.outcomes_from
00117 self._outcomes_to = msg.outcomes_to
00118
00119 self._container_outcomes = msg.container_outcomes
00120
00121 return needs_update
00122
00123
00124 def update_status(self, msg):
00125 needs_update = False
00126 if set(msg.initial_states) != set(self._initial_states):
00127 self._structure_changed = True
00128 needs_update = True
00129 if set(msg.active_states) != set(self._active_states):
00130 needs_update = True
00131
00132 self._initial_states = msg.initial_states
00133 self._last_active_states = self._active_states
00134 self._active_states = msg.active_states
00135 while True:
00136 try:
00137 self._local_data._data = pickle.loads(msg.local_data)
00138 break
00139 except ImportError as ie:
00140
00141 modulename = ie.args[0][16:]
00142 packagename = modulename[0:modulename.find('.')]
00143 roslib.load_manifest(packagename)
00144 self._local_data._data = pickle.loads(msg.local_data)
00145
00146 self._info = msg.info
00147
00148 return needs_update