Go to the documentation of this file.00001 """
00002 Copyright 2013 Southwest Research Institute
00003
00004 Licensed under the Apache License, Version 2.0 (the "License");
00005 you may not use this file except in compliance with the License.
00006 You may obtain a copy of the License at
00007
00008 http://www.apache.org/licenses/LICENSE-2.0
00009
00010 Unless required by applicable law or agreed to in writing, software
00011 distributed under the License is distributed on an "AS IS" BASIS,
00012 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013 See the License for the specific language governing permissions and
00014 limitations under the License.
00015 """
00016
00017 import roslib
00018 roslib.load_manifest('mtconnect_example_gui')
00019
00020 import os
00021 import rospy
00022
00023 from qt_gui.plugin import Plugin
00024 from python_qt_binding import loadUi
00025 from python_qt_binding.QtGui import QWidget
00026
00027
00028 from mtconnect_example_msgs.srv import StateMachineCmd
00029 from mtconnect_example_msgs.msg import StateMachineStatus
00030
00031 class SMInterfaceGUI(Plugin):
00032
00033 def __init__(self, context):
00034 super(SMInterfaceGUI, self).__init__(context)
00035
00036 self.setObjectName('SMInterfaceGUI')
00037
00038
00039 from argparse import ArgumentParser
00040 parser = ArgumentParser()
00041
00042 parser.add_argument("-q", "--quiet", action="store_true",
00043 dest="quiet",
00044 help="Put plugin in silent mode")
00045 args, unknowns = parser.parse_known_args(context.argv())
00046 if not args.quiet:
00047 print 'arguments: ', args
00048 print 'unknowns: ', unknowns
00049
00050
00051 self._widget = QWidget()
00052
00053
00054 ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'sm_interface.ui')
00055
00056 loadUi(ui_file, self._widget)
00057
00058 self._widget.setObjectName('SMInterfaceUi')
00059
00060
00061
00062
00063
00064 if context.serial_number() > 1:
00065 self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number()))
00066
00067 context.add_widget(self._widget)
00068
00069
00070 self._widget.start_button.clicked[bool].connect(self.__handle_start_clicked)
00071 self._widget.stop_button.clicked[bool].connect(self.__handle_stop_clicked)
00072 self._widget.reset_button.clicked[bool].connect(self.__handle_reset_clicked)
00073
00074 self.cmd_service = rospy.ServiceProxy('external_command', StateMachineCmd)
00075 self.sm_status_sub = rospy.Subscriber('state_machine_status', StateMachineStatus, self.__sm_status_callback)
00076
00077 def shutdown_plugin(self):
00078 self.sm_status_sub.unregister()
00079
00080 pass
00081
00082 def save_settings(self, plugin_settings, instance_settings):
00083
00084
00085 pass
00086
00087 def restore_settings(self, plugin_settings, instance_settings):
00088
00089
00090 pass
00091
00092
00093 def __handle_start_clicked(self, checked):
00094 self.cmd_service(2)
00095
00096 def __handle_stop_clicked(self, checked):
00097 self.cmd_service(3)
00098
00099 def __handle_reset_clicked(self, checked):
00100 self.cmd_service(1)
00101
00102 def __sm_status_callback(self, msg):
00103 self._widget.state_name.setText(msg.state_name + '(' + str(msg.state) + ')')
00104
00105
00106
00107
00108