Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 import gtk
00061 import gtk.gdk
00062 import roslib; roslib.load_manifest('cob_script_server')
00063 import rospy
00064 import xdot
00065 from std_msgs.msg import String
00066 from cob_script_server.msg import *
00067
00068 import pygraphviz as pgv
00069
00070 gtk.gdk.threads_init()
00071
00072
00073
00074 if rospy.has_param('script_server/graph'):
00075 dotcode = rospy.get_param("script_server/graph")
00076 G=pgv.AGraph(dotcode)
00077 else:
00078 G=pgv.AGraph()
00079 G.add_node('no graph available')
00080 dotcode = G.string()
00081
00082
00083 def graph_cb(msg):
00084 print "new graph received"
00085 global dotcode
00086 global G
00087 dotcode = msg.data
00088 print dotcode
00089 G=pgv.AGraph(dotcode)
00090
00091
00092 gtk.gdk.threads_enter()
00093 widget.set_dotcode(dotcode)
00094 widget.zoom_to_fit()
00095 gtk.gdk.threads_leave()
00096
00097
00098
00099 def state_cb(msg):
00100 global widget
00101
00102
00103 active_node = msg.full_graph_name
00104 rospy.loginfo("Received state <<%s>> from node <<%s>>",str(msg.state),active_node)
00105 try:
00106 n=G.get_node(active_node)
00107 except:
00108 rospy.logwarn("Node <<%s>> not found in graph",active_node)
00109 return
00110 n.attr['style']='filled'
00111 if msg.state == ScriptState.UNKNOWN:
00112 n.attr['fillcolor']='white'
00113 elif msg.state == ScriptState.ACTIVE:
00114 n.attr['fillcolor']='yellow'
00115 elif msg.state == ScriptState.SUCCEEDED:
00116 n.attr['fillcolor']='green'
00117 elif msg.state == ScriptState.FAILED:
00118 n.attr['fillcolor']='red'
00119 elif msg.state == ScriptState.PAUSED:
00120 n.attr['fillcolor']='orange'
00121 else:
00122 n.attr['fillcolor']='blue'
00123 dotcode = G.string()
00124
00125
00126 gtk.gdk.threads_enter()
00127 widget.set_dotcode(dotcode)
00128 widget.zoom_to_fit()
00129 gtk.gdk.threads_leave()
00130
00131
00132
00133 window = gtk.Window()
00134 window.set_title('script viewer')
00135 window.set_default_size(600, 800)
00136 vbox = gtk.VBox()
00137 window.add(vbox)
00138
00139 widget = xdot.DotWidget()
00140 widget.set_dotcode(dotcode)
00141 widget.zoom_to_fit()
00142
00143
00144 vbox.pack_start(widget)
00145
00146 window.show_all()
00147
00148 window.connect('destroy', gtk.main_quit)
00149
00150 rospy.init_node('script_viewer', anonymous=True)
00151 rospy.Subscriber("/script_server/graph", String, graph_cb)
00152 rospy.Subscriber("/script_server/state", ScriptState, state_cb)
00153 gtk.main()