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_();        
Esempio n. 2
0
    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")
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_();        
Esempio n. 4
0
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