Go to the documentation of this file.00001
00002
00003 import rospy
00004 import std_msgs.msg
00005
00006
00007
00008 def mpe_dict(msg):
00009 for k, v in msg.items():
00010 if isinstance(v, dict):
00011 print k + ':'
00012 v = message_param_editor(v)
00013 else:
00014 v_type = type(v)
00015 v = raw_input(k + ': ')
00016 while True:
00017 try:
00018 v = eval("v_type(" + v + ")")
00019 break
00020 except:
00021 print "type error, you input type is :" + type(v).__name__ + " enter " + v_type.__name__ + " :"
00022 v = raw_input(k + ": ")
00023 msg[k] = v
00024
00025 def mpe_list(msg):
00026 for v in msg:
00027 if hasattr(v, '__iter__'):
00028 print type(v) + ':'
00029 value = message_param_editor(v)
00030 else:
00031 v_type = type(v)
00032 value = raw_input(v_type + ':')
00033 while True:
00034 try:
00035 v = eval("v_type(" + v + ")")
00036 break
00037 except:
00038 print "type error, you input type is :" + type(v).__name__ + " enter " + v_type.__name__ + " :"
00039 value = raw_input(v_type + ": ")
00040 msg[v] = value
00041
00042 def message_param_editor(msg):
00043 '''
00044 :param msg: A dictionary or a list that describes a message.
00045 :return obj: The same modified dictionary or list to fit to the modifications of the user.
00046 Prompts the user about the new parameters for an existing message.
00047 '''
00048 if isinstance(msg, dict):
00049 mpe_dict(msg)
00050 elif isinstance(msg, list):
00051 mpe_list(msg)
00052
00053
00054
00055
00056
00057
00058 return msg
00059
00060
00061 def our_raw_input(string, *args):
00062 valid_response = False
00063 while not valid_response:
00064 response = raw_input(string)
00065 if response.upper() == 'QUIT':
00066 raise ValueError("Quit!")
00067 for option in args:
00068 if option == response.upper():
00069 valid_response = True
00070 if not valid_response:
00071 print "-> Invalid response."
00072 return response
00073
00074 def message_raw_input(string):
00075 import roslib.message
00076 topic_msg = raw_input(string)
00077 while True:
00078 try:
00079 if roslib.message.get_message_class(topic_msg) == None:
00080 raise ValueError()
00081 break
00082 except ValueError as e:
00083 topic_msg = raw_input("The message type is invalid."
00084 " Enter a valid type: ")
00085 return topic_msg
00086