display.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Software License Agreement (BSD License)
00004 #
00005 # Copyright (c) 2010, Willow Garage, Inc.
00006 # All rights reserved.
00007 #
00008 # Redistribution and use in source and binary forms, with or without
00009 # modification, are permitted provided that the following conditions
00010 # are met:
00011 #
00012 #  * Redistributions of source code must retain the above copyright
00013 #    notice, this list of conditions and the following disclaimer.
00014 #  * Redistributions in binary form must reproduce the above
00015 #    copyright notice, this list of conditions and the following
00016 #    disclaimer in the documentation and/or other materials provided
00017 #    with the distribution.
00018 #  * Neither the name of the Willow Garage nor the names of its
00019 #    contributors may be used to endorse or promote products derived
00020 #    from this software without specific prior written permission.
00021 #
00022 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 # POSSIBILITY OF SUCH DAMAGE.
00034 
00035 ##\author Kevin Watts
00036 ##\brief Displays results from qual tests
00037 
00038 PKG = 'qualification'
00039 
00040 import roslib; roslib.load_manifest(PKG)
00041 from qualification.qual_frame import PlotsPanel
00042 from qualification.test import SubTest
00043 from qualification.result import SubTestResult
00044 
00045 import wx
00046 from wx import xrc
00047 from wx import html
00048 
00049 import os
00050 import rospy
00051 
00052 from pr2_self_test_msgs.srv import TestResult, TestResultResponse
00053 
00054 ##\brief Makes waiting page for subtests
00055 def make_waiting_page():
00056     return '<html><H2 align=center>Waiting for Test Data...</H2></html>'
00057 
00058 class QualDisplayFrame(wx.Frame):
00059     def __init__(self, parent):
00060         wx.Frame.__init__(self, parent, wx.ID_ANY, "Qualification Display")
00061         
00062         # Load the XRC resource
00063         xrc_path = os.path.join(roslib.packages.get_pkg_dir(PKG), 'xrc/gui.xrc')
00064         xrc_res = xrc.XmlResource(xrc_path)
00065 
00066         self._shutdown_timer = wx.Timer(self, wx.ID_ANY)
00067         self.Bind(wx.EVT_TIMER, self._on_shutdown_timer, self._shutdown_timer)
00068         self._shutdown_timer.Start(10)
00069 
00070         self._plots_panel = PlotsPanel(self, xrc_res, self)
00071         self._plots_panel.show_waiting(make_waiting_page())
00072 
00073         sizer = wx.BoxSizer(wx.HORIZONTAL)
00074         self.SetSizer(sizer)
00075         sizer.Add(self._plots_panel, 1, wx.EXPAND)
00076 
00077         self._result_service = rospy.Service('test_result', TestResult, self.subtest_callback)
00078 
00079     ##\brief Check if we're shut down
00080     def _on_shutdown_timer(self, event):
00081         if rospy.is_shutdown():
00082             self.Close(True)
00083 
00084     def subtest_callback(self, msg):
00085         wx.CallAfter(self._st_data, msg)
00086         return TestResultResponse()
00087 
00088     def _st_data(self, msg):
00089         self._result_service.shutdown()
00090         self._result_service = None
00091         
00092         test = SubTest(os.path.join(roslib.packages.get_pkg_dir(PKG), 'N/A'), 1, "Qual Test")
00093         result = SubTestResult(test, msg)
00094         self._plots_panel.show_plots(result.make_result_page(),
00095                                      True)
00096 
00097     # Callback from the PlotsPanel
00098     def retry_subtest(self, notes):
00099         self.subtest_result(False, notes)
00100         
00101     def subtest_result(self, ok, notes):
00102         are_you_sure = wx.MessageDialog(self, 
00103                                         "This will clear the results window for the next result. Are you sure you want to clear the window? Press OK to clear.", 
00104                                         "Clear Window?",
00105                                         wx.OK|wx.CANCEL)
00106         if (are_you_sure.ShowModal() != wx.ID_OK):
00107             return
00108         
00109         
00110         self._plots_panel.show_waiting(make_waiting_page())
00111         self._result_service = rospy.Service('test_result', TestResult, self.subtest_callback)
00112         
00113 
00114     def cancel(self):
00115         are_you_sure = wx.MessageDialog(self, "Are you sure you want to quit?", "Confirm shut down",
00116                                         wx.OK|wx.CANCEL)
00117         if are_you_sure.ShowModal() != wx.ID_OK:
00118             return
00119 
00120         self.Close(True)
00121 
00122 class QualDisplayApp(wx.App):
00123     def OnInit(self):
00124         from qualification.result_dir import check_qual_result_dir
00125         if not check_qual_result_dir():
00126             wx.MessageBox("Unable to write to the temporary results directory. This will cause weird problems. Open a terminal and type, \"sudo rm /tmp/* -rf\" to remove the offending directory.", 
00127                           "Unable to Write Results", wx.OK|wx.ICON_ERROR, None)
00128             return False
00129 
00130         self._frame = QualDisplayFrame(None)
00131         self._frame.SetSize(wx.Size(700, 900))
00132         self._frame.Layout()
00133 
00134         self._frame.Show(True)
00135 
00136         return True
00137 
00138 if __name__ == '__main__':
00139     rospy.init_node('qual_display', anonymous=True)
00140     try:
00141         app = QualDisplayApp()
00142         app.MainLoop()
00143     except KeyboardInterrupt:
00144         pass
00145     except Exception, e:
00146         import traceback
00147         traceback.print_exc()


qualification
Author(s): Kevin Watts (watts@willowgarage.com), Josh Faust (jfaust@willowgarage.com)
autogenerated on Sat Dec 28 2013 17:57:34