2 Copyright 2017 Shaun Edwards 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 8 http://www.apache.org/licenses/LICENSE-2.0 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 21 from threading
import Thread
23 from python_qt_binding
import loadUi
24 from python_qt_binding.QtCore
import Qt, QThread, QRunnable, QThreadPool
25 from python_qt_binding.QtWidgets
import QWidget
26 from python_qt_binding.QtGui
import QPalette
27 from std_srvs.srv
import Trigger
28 from packml_msgs.srv
import Transition
29 from packml_msgs.srv
import TransitionRequest
30 from packml_msgs.msg
import Status
31 from packml_msgs.msg
import State
32 from packml_msgs.msg
import Mode
48 super(Packml, self).
__init__(context)
49 self.setObjectName(
'Packml')
51 from argparse
import ArgumentParser
52 parser = ArgumentParser()
54 parser.add_argument(
"-q",
"--quiet", action=
"store_true",
56 help=
"Put plugin in silent mode")
57 args, unknowns = parser.parse_known_args(context.argv())
59 print 'arguments: ', args
60 print 'unknowns: ', unknowns
64 ui_file = os.path.join(rospkg.RosPack().get_path(
'packml_gui'),
'resource',
'packml.ui')
66 self._widget.setObjectName(
'Packml')
68 if context.serial_number() > 1:
69 self._widget.setWindowTitle(self._widget.windowTitle() + (
' (%d)' % context.serial_number()))
71 context.add_widget(self.
_widget)
85 self._service_thread.start()
92 self._widget.clear_button.setEnabled(
False)
93 self._widget.reset_button.setEnabled(
False)
94 self._widget.start_button.setEnabled(
False)
95 self._widget.stop_button.setEnabled(
False)
96 self._widget.hold_button.setEnabled(
False)
97 self._widget.suspend_button.setEnabled(
False)
98 self._widget.unhold_button.setEnabled(
False)
99 self._widget.unsuspend_button.setEnabled(
False)
100 self._widget.abort_button.setEnabled(
False)
103 self._widget.message_box.setText(
"Message: " + text)
112 if state == State.ABORTED:
113 self._widget.clear_button.setEnabled(
True)
114 elif state == State.STOPPED:
115 self._widget.reset_button.setEnabled(
True)
116 elif state == State.IDLE:
117 self._widget.start_button.setEnabled(
True)
118 elif state == State.EXECUTE:
119 self._widget.hold_button.setEnabled(
True)
120 self._widget.suspend_button.setEnabled(
True)
121 elif state == State.HELD:
122 self._widget.unhold_button.setEnabled(
True)
123 elif state == State.SUSPENDED:
124 self._widget.unsuspend_button.setEnabled(
True)
125 elif state == State.COMPLETE:
126 self._widget.reset_button.setEnabled(
True)
128 if state != State.STOPPED
and \
129 state != State.STOPPING
and \
130 state != State.ABORTED
and \
131 state != State.ABORTING
and \
132 state != State.CLEARING:
133 self._widget.stop_button.setEnabled(
True)
136 if state != State.ABORTED
and \
137 state != State.ABORTING:
138 self._widget.abort_button.setEnabled(
True)
142 self._widget.substate.setText(str(msg.sub_state))
144 self._widget.error_code.setText(str(msg.error))
145 self._widget.suberror_code.setText(str(msg.sub_error))
149 if state == State.UNDEFINED:
150 self._widget.state_name.setText(
"UNDEFINED")
151 elif state == State.OFF:
152 self._widget.state_name.setText(
"OFF")
153 elif state == State.STOPPED:
154 self._widget.state_name.setText(
"STOPPED")
155 elif state == State.STARTING:
156 self._widget.state_name.setText(
"STARTING")
157 elif state == State.IDLE:
158 self._widget.state_name.setText(
"IDLE")
159 elif state == State.SUSPENDED:
160 self._widget.state_name.setText(
"SUSPENDED")
161 elif state == State.EXECUTE:
162 self._widget.state_name.setText(
"EXECUTE")
163 elif state == State.STOPPING:
164 self._widget.state_name.setText(
"STOPPING")
165 elif state == State.ABORTING:
166 self._widget.state_name.setText(
"ABORTING")
167 elif state == State.ABORTED:
168 self._widget.state_name.setText(
"ABORTED")
169 elif state == State.HOLDING:
170 self._widget.state_name.setText(
"HOLDING")
171 elif state == State.HELD:
172 self._widget.state_name.setText(
"HELD")
173 elif state == State.RESETTING:
174 self._widget.state_name.setText(
"RESETTING")
175 elif state == State.SUSPENDING:
176 self._widget.state_name.setText(
"SUSPENDING")
177 elif state == State.UNSUSPENDING:
178 self._widget.state_name.setText(
"UNSUSPENDING")
179 elif state == State.CLEARING:
180 self._widget.state_name.setText(
"CLEARING")
181 elif state == State.UNHOLDING:
182 self._widget.state_name.setText(
"UNHOLDING")
183 elif state == State.COMPLETING:
184 self._widget.state_name.setText(
"COMPLETING")
185 elif state == State.COMPLETE:
186 self._widget.state_name.setText(
"COMPLETE")
188 self._widget.state_name.setTest(
"UNKNOWN")
193 if mode == Mode.UNDEFINED:
194 self._widget.mode_name.setText(
"UNDEFINED")
195 elif mode == Mode.AUTOMATIC:
196 self._widget.mode_name.setText(
"AUTOMATIC")
197 elif mode == Mode.SEMI_AUTOMATIC:
198 self._widget.mode_name.setText(
"SEMI-AUTOMATIC")
199 elif mode == Mode.MANUAL:
200 self._widget.mode_name.setText(
"MANUAL")
201 elif mode == Mode.IDLE:
202 self._widget.mode_name.setText(
"IDLE")
203 elif mode == Mode.SETUP:
204 self._widget.mode_name.setText(
"SETUP")
206 self._widget.mode_name.setText(
"UNKNOWN")
211 self._widget.setEnabled(
False)
212 transition_service_name =
'packml/transition' 213 rospy.wait_for_service(transition_service_name, 30)
215 self._widget.setEnabled(
True)
218 self._status_sub.unregister()
234 service_thread =
WorkerThread(self.transition_service, request, self.set_message_text)
235 if self.threadpool.activeThreadCount() >= 1:
238 self.threadpool.start(service_thread)
239 except rospy.ServiceException
as exc:
240 rospy.logerror(
"Service did not process request: " + str(exc))
243 rospy.loginfo(
"Start button press")
247 rospy.loginfo(
"Stop button press")
251 rospy.loginfo(
"Reset button press")
255 rospy.loginfo(
"Clear button press")
259 rospy.loginfo(
"Hold button press")
263 rospy.loginfo(
"Unhold button press")
267 rospy.loginfo(
"Suspend button press")
271 rospy.loginfo(
"Unsuspend button press")
275 rospy.loginfo(
"Abort button press")
280 rospy.loginfo(
"Add arguments callback")
281 group = parser.add_argument_group(
'Options for PackML plugin')
282 group.add_argument(
'--arg1', action=
'store_true', help=
'arg1 help')
def update_button_states(self, state)
def set_message_text(self, text)
def disable_all_buttons(self)
def __handle_suspend_clicked(self, checked)
def wait_for_services(self)
def __handle_reset_clicked(self, checked)
def add_arguments(parser)
def update_status_fields(self, msg)
def handle_click_thread(self, request)
def __handle_unhold_clicked(self, checked)
def __handle_stop_clicked(self, checked)
def save_settings(self, plugin_settings, instance_settings)
def restore_settings(self, plugin_settings, instance_settings)
def __handle_start_clicked(self, checked)
def __handle_clear_clicked(self, checked)
def update_mode_field(self, mode)
def shutdown_plugin(self)
def __handle_abort_clicked(self, checked)
def __handle_unsuspend_clicked(self, checked)
def update_state_field(self, state)
def __handle_hold_clicked(self, checked)
def __init__(self, context)
def __init__(self, service, req, set_msg)
def status_callback(self, msg)