confirm_conf.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Software License Agreement (BSD License)
00003 #
00004 # Copyright (c) 2008, Willow Garage, Inc.
00005 # All rights reserved.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions
00009 # are met:
00010 #
00011 #  * Redistributions of source code must retain the above copyright
00012 #    notice, this list of conditions and the following disclaimer.
00013 #  * Redistributions in binary form must reproduce the above
00014 #    copyright notice, this list of conditions and the following
00015 #    disclaimer in the documentation and/or other materials provided
00016 #    with the distribution.
00017 #  * Neither the name of the Willow Garage nor the names of its
00018 #    contributors may be used to endorse or promote products derived
00019 #    from this software without specific prior written permission.
00020 #
00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 # POSSIBILITY OF SUCH DAMAGE.
00033 #
00034 
00035 
00036 ## Prompts the user with a Y/N message if MCB's aren't configured
00037 # Called from configure/program_mcb.py through the mcb_conf_results service
00038 
00039 PKG = 'qualification' 
00040 NAME = 'confirm_conf'
00041 
00042 import roslib
00043 roslib.load_manifest(PKG) 
00044 import wx 
00045 from wx import xrc
00046 from pr2_self_test_msgs.srv import ConfirmConf, ConfirmConfRequest, ConfirmConfResponse
00047 import rospy 
00048 import time
00049 import os
00050 
00051 import signal
00052 
00053 prev_handler = None
00054 
00055 
00056 app = wx.PySimpleApp(clearSigInt = True)
00057 process_done = False
00058 prompt_done = False
00059 prompt_click =False
00060 frame=wx.Frame(None)
00061 
00062 #def shutdown(sig, stackframe):
00063 #    rospy.logerr('confirm conf shutting down')
00064 #    frame.Close()
00065 #    app.Destroy()
00066 #    if prev_handler is not None:
00067 #        prev_handler(signal.SIGINT, None)
00068   
00069  
00070 def msg_detail_prompt(msg, details):
00071   # Load MCB conf dialog box from gui.xrc
00072   xrc_path = os.path.join(roslib.packages.get_pkg_dir('qualification'), 'xrc/gui.xrc')
00073   xrc_resource = xrc.XmlResource(xrc_path)
00074   # See if it works to set a parent
00075   dialog = xrc_resource.LoadDialog(None, 'confirm_conf_dialog')
00076   # Set text in message text
00077   xrc.XRCCTRL(dialog, 'message_text').SetLabel(msg)
00078   xrc.XRCCTRL(dialog, 'message_text').Wrap(400)  
00079   xrc.XRCCTRL(dialog, 'detail_text').AppendText(details)
00080 
00081   global prompt_click, prompt_done
00082   
00083   dialog.Layout()
00084   #dialog.Fit()
00085 
00086   prompt_click = (dialog.ShowModal() == wx.ID_OK)
00087   prompt_done = True
00088   dialog.Destroy()
00089    
00090 def check_w_user(req):
00091   global prompt_done, prompt_click
00092 
00093   wx.CallAfter(msg_detail_prompt, req.message, req.details)
00094 
00095   while(not prompt_done and not rospy.is_shutdown()):
00096     rospy.loginfo("Waiting for retry prompt . . .")
00097     for i in range(0, 20):
00098       time.sleep(0.5) 
00099 
00100   resp = ConfirmConfResponse()
00101   if prompt_click:
00102     resp.retry = ConfirmConfResponse.RETRY
00103   else:
00104     resp.retry = ConfirmConfResponse.FAIL
00105 
00106   prompt_done = False
00107   prompt_click = False
00108   return resp
00109 
00110  
00111 def confirm_conf():
00112   rospy.init_node(NAME)
00113   s = rospy.Service('mcb_conf_results', ConfirmConf, check_w_user)  
00114 
00115   # Allow it to kill on exit w/o SIGKILL
00116   signal.signal(signal.SIGINT, signal.SIG_DFL)
00117 
00118   app.MainLoop()
00119 
00120   rospy.spin()
00121   time.sleep(1)
00122   
00123 
00124 if __name__ == "__main__":  
00125   confirm_conf()


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