gui.py
Go to the documentation of this file.
00001 #!/opt/grx/bin/hrpsyspy
00002 import os
00003 import time
00004 from java.lang import System
00005 from java.awt import *
00006 from javax.swing import *
00007 from guiinfo import *
00008 import math
00009 
00010 FILENAME_ROBOTHOST='.robothost'
00011 
00012 
00013 def reconnect():
00014   global txt
00015   robotHost = txt.getText().strip()
00016   System.setProperty('NS_OPT', '-ORBInitRef NameService=corbaloc:iiop:'+ robotHost +':2809/NameService')
00017   try:
00018     rtm.initCORBA()
00019     f = open(FILENAME_ROBOTHOST, 'w')
00020     f.write(robotHost+'\n')
00021     f.close()
00022     print ('reconnected')
00023     return True
00024   except IOError:
00025     print ('can not open to write: '+ FILENAME_ROBOTHOST)
00026   except:
00027     print ('can not connect to '+ robotHost)
00028   return False
00029 
00030 def setupRobot():
00031   if reconnect():
00032     init()
00033     setupLogger()
00034 
00035 def restart():
00036   waitInputConfirm('!! Caution !! \n Push [OK] to restart rtcd ')
00037   if reconnect():
00038     ms = rtm.findRTCmanager()
00039     ms.restart()
00040 
00041 def createButton(name, func):
00042     if not func.__class__.__name__ == 'function':
00043        return None
00044     exec('def tmpfunc(e): import time; t1=time.time();'+func.__name__+'(); t2=time.time(); print "['+name+']", t2- t1 ,"[sec]"')
00045     btn = JButton(label=name, actionPerformed = tmpfunc)
00046     del tmpfunc
00047     return btn
00048 
00049 frm = JFrame("sample GUI for "+bodyinfo.modelName, defaultCloseOperation = JFrame.EXIT_ON_CLOSE)
00050 frm.setAlwaysOnTop(True)
00051 pnl = frm.getContentPane()
00052 pnl.layout = BoxLayout(pnl, BoxLayout.Y_AXIS)
00053 pnl.add(JLabel("HOSTNAME of ROBOT"))
00054 
00055 if os.path.isfile(FILENAME_ROBOTHOST):
00056   f = open(FILENAME_ROBOTHOST, "r")
00057   txt = JTextField(f.readline())
00058 else:
00059   txt = JTextField("localhost")
00060 pnl.add(txt)
00061 
00062 funcList = [["setup rt-system", setupRobot],["restart rtcd", restart], " "] + funcList
00063 for func in funcList:
00064   if func.__class__.__name__ == 'str':
00065     obj = JLabel(func)
00066   elif func.__class__.__name__ == 'function':
00067     obj = createButton(func.__name__, func)
00068   elif func.__class__.__name__ == 'list':
00069     obj = createButton(func[0], func[1])
00070   if obj != None:
00071     pnl.add(obj)
00072 
00073 frm.pack()
00074 frm.show()
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


hironx_ros_bridge
Author(s): k-okada
autogenerated on Thu Jun 27 2013 14:58:35