def _save_dot(self):
        file_name, _ = QFileDialog.getSaveFileName(self._widget, self.tr('Save as DOT'), 'rospackgraph.dot', self.tr('DOT graph (*.dot)'))
        if file_name is None or file_name == '':
            return

        handle = QFile(file_name)
        if not handle.open(QIODevice.WriteOnly | QIODevice.Text):
            return

        handle.write(self._current_dotcode)
        handle.close()
Example #2
0
    def _save_dot(self):
        file_name, _ = QFileDialog.getSaveFileName(self._widget, self.tr('Save as DOT'), 'rosgraph.dot', self.tr('DOT graph (*.dot)'))
        if file_name is None or file_name == '':
            return

        handle = QFile(file_name)
        if not handle.open(QIODevice.WriteOnly | QIODevice.Text):
            return

        handle.write(self._current_dotcode)
        handle.close()
Example #3
0
    def save(self, force=False):
        '''
        Saves changes to the file.
        :return: saved, errors, msg
        :rtype: bool, bool, str
        '''
        if force or self.document().isModified() or not QFileInfo(
                self.filename).exists():
            f = QFile(self.filename)
            if f.open(QIODevice.WriteOnly | QIODevice.Text):
                f.write(self.toPlainText().encode('utf-8'))
                self.document().setModified(False)
                self.file_info = QFileInfo(self.filename)

                ext = os.path.splitext(self.filename)
                # validate the xml structure of the launch files
                if ext[1] in self.CONTEXT_FILE_EXT:
                    imported = False
                    try:
                        from lxml import etree
                        imported = True
                        parser = etree.XMLParser()
                        etree.fromstring(self.toPlainText().encode('utf-8'),
                                         parser)
                    except Exception as e:
                        if imported:
                            self.markLine(e.position[0])
                            return True, True, "%s" % e
                # validate the yaml structure of yaml files
                elif ext[1] in self.YAML_VALIDATION_FILES:
                    try:
                        import yaml
                        yaml.load(self.toPlainText().encode('utf-8'))
                    except yaml.MarkedYAMLError as e:
                        return True, True, "%s" % e
                return True, False, ''
            else:
                return False, True, "Cannot write XML file"
        return False, False, ''
    def save(self, force=False):
        '''
        Saves changes to the file.
        :return: saved, errors, msg
        :rtype: bool, bool, str
        '''
        if force or self.document().isModified() or not QFileInfo(self.filename).exists():
            f = QFile(self.filename)
            if f.open(QIODevice.WriteOnly | QIODevice.Text):
                f.write(self.toPlainText().encode('utf-8'))
                self.document().setModified(False)
                self.file_info = QFileInfo(self.filename)

                ext = os.path.splitext(self.filename)
                # validate the xml structure of the launch files
                if ext[1] in self.CONTEXT_FILE_EXT:
                    imported = False
                    try:
                        from lxml import etree
                        imported = True
                        parser = etree.XMLParser()
                        etree.fromstring(self.toPlainText().encode('utf-8'), parser)
                    except Exception as e:
                        if imported:
                            self.markLine(e.position[0])
                            return True, True, "%s" % e
                # validate the yaml structure of yaml files
                elif ext[1] in self.YAML_VALIDATION_FILES:
                    try:
                        import yaml
                        yaml.load(self.toPlainText().encode('utf-8'))
                    except yaml.MarkedYAMLError as e:
                        return True, True, "%s" % e
                return True, False, ''
            else:
                return False, True, "Cannot write XML file"
        return False, False, ''
import sys
from python_qt_binding.QtWidgets import QApplication, QWidget, QVBoxLayout
from python_qt_binding.QtCore import QFile, QIODevice, QObject
from rqt_graph.ros_graph import RosGraph


class FakePluginContext(QObject):
    def __init__(self):
        super(FakePluginContext, self).__init__()
        self.setObjectName('FakePluginContext')

    def serial_number(self):
        return 0

    def add_widget(self, widget):
        pass


if __name__ == "__main__":
    app = QApplication(sys.argv)
    fpc = FakePluginContext()
    r = RosGraph(fpc)

    handle = QFile(sys.argv[1])
    if not handle.open(QIODevice.WriteOnly | QIODevice.Text):
        exit(1)

    handle.write(r._generate_dotcode())
    handle.close()