Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 import os
00012
00013
00014 import rocon_std_msgs.msg as rocon_std_msgs
00015
00016
00017 from .resources import find_resource_from_string
00018
00019
00020
00021
00022
00023
00024 def icon_to_msg(filename):
00025 '''
00026 Loads the specified filename and puts in
00027 rocon_std_msgs.Icon format
00028
00029 @param : filename to the icon resource.
00030 @type : string
00031 '''
00032 icon = rocon_std_msgs.Icon()
00033 if filename == None or filename == "":
00034 return icon
00035 unused_basename, extension = os.path.splitext(filename)
00036 if extension.lower() == ".jpg" or extension.lower() == ".jpeg":
00037 icon.format = "jpeg"
00038 elif extension.lower() == ".png":
00039 icon.format = "png"
00040 else:
00041 icon.format = ""
00042 return icon
00043 icon.data = open(filename, "rb").read()
00044 return icon
00045
00046
00047 def icon_resource_to_msg(resource):
00048 '''
00049 Loads the icon resource and puts in
00050 rocon_std_msgs.Icon format
00051
00052 @param resource : resource identifier (package/name)
00053 @type : string
00054
00055 @return the icon message
00056 @rtype rocon_std_msgs.msg.Icon
00057 '''
00058 filename = find_resource_from_string(resource)
00059 icon = icon_to_msg(filename)
00060 icon.resource_name = resource
00061 return icon