def change_input_method(): global manniquin_controllers_loaded global joint_observer index = main_window.input_method_comboBox.currentIndex() input_method = main_window.input_method_comboBox.itemData(index) print 'change_input_method()', index manniquin_controllers = ['r_arm_controller_loose', 'l_arm_controller_loose', 'head_traj_controller_loose'] standard_controllers = ['r_arm_controller', 'l_arm_controller', 'head_traj_controller'] if input_method == INPUT_METHOD_ROBOT: # setup controllers for manniquin mode if not manniquin_controllers_loaded: # load controllers once print 'change_input_method()', 'load manniquin controllers' manniquin_controllers_loaded = load_controllers(manniquin_controllers) if not manniquin_controllers_loaded: QMessageBox.critical(main_window, main_window.tr('Loading controllers failed'), main_window.tr('Could not load manniquin controllers.')) # switch to manniquin controllers success = switch_controllers(manniquin_controllers, standard_controllers) if success: joint_observer.start() else: # restore standard controllers success = switch_controllers(standard_controllers, manniquin_controllers) if success: joint_observer.stop() if not success: QMessageBox.critical(main_window, main_window.tr('Switching controllers failed'), main_window.tr('Could not switch controllers.'))
def _handle_start_following(self): #make sure server is available before sending goal QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) if (not self._client.wait_for_server(rospy.Duration.from_sec(10))): QApplication.restoreOverrideCursor() msg_box = QMessageBox() msg_box.setText("Timeout while looking for path following control server.") msg_box.exec_() return QApplication.restoreOverrideCursor() #get path file to load filename = QFileDialog.getOpenFileName(self, self.tr('Load Path from File'), '.', self.tr('Path File {.txt} (*.txt)')) if filename[0] != '': try: handle = open(filename[0]) except IOError as e: qWarning(str(e)) return # load path from file path_reader=csv.reader(open(filename[0],'rb'),delimiter=';') # parse path file and convert to numbers temp = [row[0].split() for row in path_reader] lines= [[float(num) for num in row] for row in temp] # first line of file is radius radius = lines[0] # remove radius del(lines[0]) now = rospy.Time.now() goal = auxos_messages.msg.PlanThenFollowDubinsPathGoal() goal.path.header.stamp = now goal.path.header.frame_id = self.path_frame_id # TODO: fix this!!! for line in lines: pose_msg = PoseStamped() pose_msg.header.stamp = now pose_msg.header.frame_id = goal.path.header.frame_id pose_msg.pose.position.x = line[0] pose_msg.pose.position.y = line[1] quat = qfe(0, 0, psi2theta(line[2])) pose_msg.pose.orientation.x = quat[0] pose_msg.pose.orientation.y = quat[1] pose_msg.pose.orientation.z = quat[2] pose_msg.pose.orientation.w = quat[3] goal.path.poses.append(pose_msg) self._client.send_goal(goal, self._handle_path_complete, self._handle_active, self._handle_feedback) print("start following")
def doAddWordButton(self, newWord, rank): additionResult = self.wordCollection.addToUserDict(newWord, rankInt=rank); if additionResult: QMessageBox.information(self, # dialog parent "Dictionary addition", "Word '%s' has been saved in user dictionary." % newWord, QMessageBox.Ok, QMessageBox.NoButton); else: QMessageBox.information(self, # dialog parent "Dictionary addition", "Word '%s' was already in the dictionary. No action taken" % newWord, QMessageBox.Ok, QMessageBox.NoButton);
def handleSaveWordButton(self): # Get content of output panel: currOutput = self.outputPanel.toPlainText(); # If noth'n there, done: if len(currOutput) == 0: QMessageBox.information(self, "Dictionary addition", "Output panel has no content; so there is no word to save.", QMessageBox.Ok, QMessageBox.NoButton); return; # Get the last word in the output panel: newWord = re.split("[.;:?! @()]", currOutput)[-1]; # Ask user about capitalization, and expected word frequency. # This call will raise a modal dialog box. Signal handlers # handleAddDictWordCapitalizeStateChanged(), and handleAddDictWordOK_Cancel() # take it from there: self.getAddWordUserInfo(newWord);
class DialogService(QWidget): ''' Provides popup windows for information and error messages ''' #---------------------------------- # Initializer #-------------- def __init__(self, parent=None): super(DialogService, self).__init__(parent); # All-purpose error popup message: # Used by self.showErrorMsgByErrorCode(<errorCode>), # or self.showErrorMsg(<string>). Returns a # QErrorMessage without parent, but with QWindowFlags set # properly to be a dialog popup box: self.errorMsgPopup = QErrorMessage.qtHandler(); # Re-parent the popup, retaining the window flags set # by the qtHandler: self.errorMsgPopup.setParent(parent, self.errorMsgPopup.windowFlags()); #self.errorMsgPopup.setStyleSheet(SpeakEasyGUI.stylesheetAppBG); self.infoMsg = QMessageBox(parent=parent); #self.infoMsg.setStyleSheet(SpeakEasyGUI.stylesheetAppBG); #---------------------------------- # showErrorMsg #-------------- QErrorMessage def showErrorMsg(self,errMsg): ''' Given a string, pop up an error dialog on top of the application window. @param errMsg: The message @type errMsg: string ''' self.errorMsgPopup.showMessage(errMsg); #---------------------------------- # showInfoMsg #-------------- def showInfoMsg(self, text): ''' Display a message window with an OK button on top of the application window. @param text: text to display @type text: string ''' self.infoMsg.setText(text); self.infoMsg.exec_();
def save_screenshot(): path = os.path.expanduser('~') filename_template = 'robot-%d.png' serial = 1 while True: filename = os.path.join(path, filename_template % serial) if not os.path.exists(filename): break serial += 1 widget = robot_view.children()[0] pixmap = QPixmap.grabWindow(widget.winId()) rc = pixmap.save(filename) if rc: QMessageBox.information(main_window, main_window.tr('Saved screenshot'), main_window.tr('Screenshot saved in file: %s') % filename) else: QMessageBox.critical(main_window, main_window.tr('Saving screenshot failed'), main_window.tr('Could not save screenshot.'))
def __init__(self, exception, level='critical', fmt=None): QMessageBox.__init__(self, parent=QApplication.activeWindow()) icon = self._icons.get(level, QMessageBox.NoIcon) self.setIcon(icon) title = self._titles.get(level, "") self.setWindowTitle(title) okBtn = self.addButton("ok", QMessageBox.AcceptRole) self.setDefaultButton(okBtn) if fmt is None: fmt = u"<nobr>{e}</nobr>" className, methodName = self.classAndMethodName() excName, excMsg = type(exception).__name__, str(exception) text = u"{3}\n[ {2} in {0}.{1} ]".format(className, methodName, excName, excMsg) self.setText(fmt.format(e=text.replace("\n", "<br />"))) logfunc = self._logging.get(level, logging.error) logfunc(traceback.format_exc()) # log exception traceback self.exec_()
def closeEvent(event): if not sigint_called: button = QMessageBox.question(main_window, main_window.tr('Close application'), main_window.tr('Do you really want to close the application?'), QMessageBox.Cancel | QMessageBox.Close) else: button = QMessageBox.Close if button == QMessageBox.Close: event.accept() else: event.ignore()
def on_apply_wrench_clicked_(self): success = True apply_body_wrench = rospy.ServiceProxy('/gazebo/apply_body_wrench', ApplyBodyWrench) body_name = self._widget.comboBoxObjectList.currentText() wrench = Wrench() wrench.force.x = float(str(self._widget.lineEdit.text())) wrench.force.y = float(str(self._widget.lineEdit_2.text())) wrench.force.z = float(str(self._widget.lineEdit_3.text())) try: resp1 = apply_body_wrench(body_name, "", None, wrench, rospy.Time.from_sec(0), rospy.Duration.from_sec(1.0)) except rospy.ServiceException: success = False if success: if not resp1.success: success = False if not success: QMessageBox.warning(self._widget, "Warning", "Could not apply wrench to selected object.")
def save_screenshot(): path = os.path.expanduser('~') filename_template = 'robot-%d.png' serial = 1 while True: filename = os.path.join(path, filename_template % serial) if not os.path.exists(filename): break serial += 1 widget = robot_view.children()[0] pixmap = QPixmap.grabWindow(widget.winId()) rc = pixmap.save(filename) if rc: QMessageBox.information( main_window, main_window.tr('Saved screenshot'), main_window.tr('Screenshot saved in file: %s') % filename) else: QMessageBox.critical(main_window, main_window.tr('Saving screenshot failed'), main_window.tr('Could not save screenshot.'))
def closeEvent(event): if not sigint_called: button = QMessageBox.question( main_window, main_window.tr('Close application'), main_window.tr('Do you really want to close the application?'), QMessageBox.Cancel | QMessageBox.Close) else: button = QMessageBox.Close if button == QMessageBox.Close: event.accept() else: event.ignore()
class DialogService(object): ''' Convenience class for popping up error and information messages in Qt based applications. Control whether any popup windows are actually shown by setting the class variable CURRENTLY_TESTING to True or False. If True, no dialogs will be shown. Used during automatic testing. ''' CURRENTLY_TESTING = False; #---------------------------------- # Initializer #-------------- def __init__(self, parent=None): # All-purpose error popup message: # Used by self.showErrorMsgByErrorCode(<errorCode>), # or self.showErrorMsg(<string>). Returns a # QErrorMessage without parent, but with QWindowFlags set # properly to be a dialog popup box: self.errorMsgPopup = QErrorMessage.qtHandler(); # Re-parent the popup, retaining the window flags set # by the qtHandler: self.errorMsgPopup.setParent(parent, self.errorMsgPopup.windowFlags()); #self.errorMsgPopup.setStyleSheet(SpeakEasyGUI.stylesheetAppBG); self.infoMsg = QMessageBox(parent=parent); self.infoMsg.setStyleSheet("background-color : rgb(160,182,191)"); #self.infoMsg.setStyleSheet(SpeakEasyGUI.stylesheetAppBG); #---------------------------------- # showErrorMsg #-------------- QErrorMessage def showErrorMsg(self,errMsg): ''' Given a string, pop up an error dialog, if DialogService.CURRENTLY_TESTING is False. Else method returns quietly, because unittesting is under way @param errMsg: The message @type errMsg: string ''' if not DialogService.CURRENTLY_TESTING: self.errorMsgPopup.showMessage(errMsg); #---------------------------------- # showInfoMsg #-------------- def showInfoMessage(self, text): ''' Given a string, pop up an info message, if DialogService.CURRENTLY_TESTING is False. Else method returns quietly, because unittesting is under way @param text: The message @type text: string ''' if not DialogService.CURRENTLY_TESTING: self.infoMsg.setText(text); self.infoMsg.exec_();
def change_input_method(): global manniquin_controllers_loaded global joint_observer index = main_window.input_method_comboBox.currentIndex() input_method = main_window.input_method_comboBox.itemData(index) print 'change_input_method()', index manniquin_controllers = [ 'r_arm_controller_loose', 'l_arm_controller_loose', 'head_traj_controller_loose' ] standard_controllers = [ 'r_arm_controller', 'l_arm_controller', 'head_traj_controller' ] if input_method == INPUT_METHOD_ROBOT: # setup controllers for manniquin mode if not manniquin_controllers_loaded: # load controllers once print 'change_input_method()', 'load manniquin controllers' manniquin_controllers_loaded = load_controllers( manniquin_controllers) if not manniquin_controllers_loaded: QMessageBox.critical( main_window, main_window.tr('Loading controllers failed'), main_window.tr('Could not load manniquin controllers.')) # switch to manniquin controllers success = switch_controllers(manniquin_controllers, standard_controllers) if success: joint_observer.start() else: # restore standard controllers success = switch_controllers(standard_controllers, manniquin_controllers) if success: joint_observer.stop() if not success: QMessageBox.critical(main_window, main_window.tr('Switching controllers failed'), main_window.tr('Could not switch controllers.'))
def queue_program(username, password, label): queue = ProgramQueue(username, password) try: rc = queue.login() except: rc = False if not rc: QMessageBox.critical( main_window, main_window.tr('Login failed'), main_window.tr('Could not log in to the program queue.')) return output = StringIO() storage = SimpleFormat(output) serialize(storage) program_data = output.getvalue() output.close() try: id = queue.upload_program(program_data, label) except: id = False if not id: QMessageBox.critical( main_window, main_window.tr('Upload failed'), main_window.tr('Could not upload program to queue.')) return try: queue.logout() except: pass QMessageBox.information( main_window, main_window.tr('Uploaded program'), main_window.tr('Uploaded program (%d) successfully.') % id)
def queue_program(username, password, label): queue = ProgramQueue(username, password) try: rc = queue.login() except: rc = False if not rc: QMessageBox.critical(main_window, main_window.tr('Login failed'), main_window.tr('Could not log in to the program queue.')) return output = StringIO() storage = SimpleFormat(output) serialize(storage) program_data = output.getvalue() output.close() try: id = queue.upload_program(program_data, label) except: id = False if not id: QMessageBox.critical(main_window, main_window.tr('Upload failed'), main_window.tr('Could not upload program to queue.')) return try: queue.logout() except: pass QMessageBox.information(main_window, main_window.tr('Uploaded program'), main_window.tr('Uploaded program (%d) successfully.') % id)
def clear_all(): global current_name confirmed = True if current_name is None: button = QMessageBox.question(main_window, main_window.tr('Clear all poses'), main_window.tr('Do you really want to delete all poses?'), QMessageBox.No | QMessageBox.Yes) confirmed = button == QMessageBox.Yes if confirmed: print 'clear_all()' for index in range(main_window.PoseList_tabWidget.count()): model = models[index] model.remove_all_actions() current_name = None set_tab(0) main_window.angled_view_radioButton.click()
def __init__(self, parent=None): super(DialogService, self).__init__(parent); # All-purpose error popup message: # Used by self.showErrorMsgByErrorCode(<errorCode>), # or self.showErrorMsg(<string>). Returns a # QErrorMessage without parent, but with QWindowFlags set # properly to be a dialog popup box: self.errorMsgPopup = QErrorMessage.qtHandler(); # Re-parent the popup, retaining the window flags set # by the qtHandler: self.errorMsgPopup.setParent(parent, self.errorMsgPopup.windowFlags()); #self.errorMsgPopup.setStyleSheet(SpeakEasyGUI.stylesheetAppBG); self.infoMsg = QMessageBox(parent=parent);
def on_set_to_position_clicked_(self): success = True set_model_state = rospy.ServiceProxy('/gazebo/set_model_state', SetModelState) model_state = ModelState() model_state.model_name = str(self._widget.comboBoxObjectList.currentText()).split('::')[0] model_state.pose = Pose() model_state.twist = Twist() model_state.reference_frame = "world" model_state.pose.position.x = float(str(self._widget.lineEdit_4.text())) model_state.pose.position.y = float(str(self._widget.lineEdit_5.text())) model_state.pose.position.z = float(str(self._widget.lineEdit_6.text())) try: resp1 = set_model_state(model_state) except rospy.ServiceException: success = False if success: if not resp1.success: success = False if not success: QMessageBox.warning(self._widget, "Warning", "Could not set model state.")
def on_refresh_list_clicked_(self): self._widget.comboBoxObjectList.clear() success = True get_world_properties = rospy.ServiceProxy('/gazebo/get_world_properties', GetWorldProperties) object_list = list() try: resp1 = get_world_properties() except rospy.ServiceException: success = False if success: get_model_properties = rospy.ServiceProxy('/gazebo/get_model_properties', GetModelProperties) for model in resp1.model_names: try: model_properties = get_model_properties(model) except rospy.ServiceException: success = False if success: for body in model_properties.body_names: object_list.append(model + '::' + body) self._widget.comboBoxObjectList.addItems(object_list) if not success: QMessageBox.warning(self._widget, "Warning", "Could not load object list from Gazebo.")
def clear_all(): global current_name confirmed = True if current_name is None: button = QMessageBox.question( main_window, main_window.tr('Clear all poses'), main_window.tr('Do you really want to delete all poses?'), QMessageBox.No | QMessageBox.Yes) confirmed = button == QMessageBox.Yes if confirmed: print 'clear_all()' for index in range(main_window.PoseList_tabWidget.count()): model = models[index] model.remove_all_actions() current_name = None set_tab(0) main_window.angled_view_radioButton.click()
def dashinfo(msg, obj, title = 'Info'): """Logs a message with ``rospy.loginfo`` and displays a ``QMessageBox`` to the user :param msg: Message to display. :type msg: str :param obj: Parent object for the ``QMessageBox`` :type obj: QObject :param title: An optional title for the `QMessageBox`` :type title: str """ rospy.loginfo(msg) box = QMessageBox() box.setText(msg) box.setWindowTitle(title) box.show() obj._message_box = box