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 import gtk
00019 import gtk.gdk
00020 import xdot
00021
00022 import pygraphviz as pgv
00023
00024 import rospy
00025 from std_msgs.msg import String
00026 from cob_script_server.msg import *
00027
00028 gtk.gdk.threads_init()
00029
00030
00031
00032 if rospy.has_param('script_server/graph'):
00033 dotcode = rospy.get_param("script_server/graph")
00034 G=pgv.AGraph(dotcode)
00035 else:
00036 G=pgv.AGraph()
00037 G.add_node('no graph available')
00038 dotcode = G.string()
00039
00040
00041 def graph_cb(msg):
00042 print "new graph received"
00043 global dotcode
00044 global G
00045 dotcode = msg.data
00046 print dotcode
00047 G=pgv.AGraph(dotcode)
00048
00049
00050 gtk.gdk.threads_enter()
00051 widget.set_dotcode(dotcode)
00052 widget.zoom_to_fit()
00053 gtk.gdk.threads_leave()
00054
00055
00056
00057 def state_cb(msg):
00058 global widget
00059
00060
00061 active_node = msg.full_graph_name
00062 rospy.loginfo("Received state <<%s>> from node <<%s>>",str(msg.state),active_node)
00063 try:
00064 n=G.get_node(active_node)
00065 except:
00066 rospy.logwarn("Node <<%s>> not found in graph",active_node)
00067 return
00068 n.attr['style']='filled'
00069 if msg.state == ScriptState.UNKNOWN:
00070 n.attr['fillcolor']='white'
00071 elif msg.state == ScriptState.ACTIVE:
00072 n.attr['fillcolor']='yellow'
00073 elif msg.state == ScriptState.SUCCEEDED:
00074 n.attr['fillcolor']='green'
00075 elif msg.state == ScriptState.FAILED:
00076 n.attr['fillcolor']='red'
00077 elif msg.state == ScriptState.PAUSED:
00078 n.attr['fillcolor']='orange'
00079 else:
00080 n.attr['fillcolor']='blue'
00081 dotcode = G.string()
00082
00083
00084 gtk.gdk.threads_enter()
00085 widget.set_dotcode(dotcode)
00086 widget.zoom_to_fit()
00087 gtk.gdk.threads_leave()
00088
00089
00090
00091 window = gtk.Window()
00092 window.set_title('script viewer')
00093 window.set_default_size(600, 800)
00094 vbox = gtk.VBox()
00095 window.add(vbox)
00096
00097 widget = xdot.DotWidget()
00098 widget.set_dotcode(dotcode)
00099 widget.zoom_to_fit()
00100
00101
00102 vbox.pack_start(widget)
00103
00104 window.show_all()
00105
00106 window.connect('destroy', gtk.main_quit)
00107
00108 rospy.init_node('script_viewer', anonymous=True)
00109 rospy.Subscriber("/script_server/graph", String, graph_cb)
00110 rospy.Subscriber("/script_server/state", ScriptState, state_cb)
00111 gtk.main()