def find_default_args(self, path, inc_args): ''' Searches for args with default value not overwritten by including file. :param str path: file content or a launch file path :param dict(str,str) inc_args: a dictionary with arguments set while include the given path. :return: a dictinary with default arguments not overwriting while include. :rtype: dict(str: str) ''' not_set_args = {} if path and not (path.endswith('.launch') or path.find('.launch.') > 0): return not_set_args if rospy.is_shutdown(): return not_set_args try: # get file content _, _, data = nm.nmd().file.get_file_content(path) launch_node = None # create xml node xml_nodes = minidom.parseString(data.encode('utf-8')).getElementsByTagName('launch') if xml_nodes: launch_node = xml_nodes[-1] if launch_node is not None: # read XML content and get default arguments default_args = get_internal_args(data, only_default=True) for arg_in_file, arg_value in default_args.items(): if arg_in_file not in inc_args: not_set_args[arg_in_file] = arg_value except Exception as err: msg = "can't get default arguments for %s: %s" % (path, utf8(err)) self.error.emit(msg) rospy.logwarn(msg) return not_set_args
def __init__(self, filename, parent=None): self.parent = parent QTextEdit.__init__(self, parent) self.setObjectName('Editor - %s' % filename) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.show_custom_context_menu) # self.setFrameStyle(QFrame.StyledPanel | QFrame.Sunken) self.setAcceptRichText(False) font = QFont() font.setFamily("Fixed".decode("utf-8")) font.setPointSize(12) self.setFont(font) self.setLineWrapMode(QTextEdit.NoWrap) self.setTabStopWidth(25) self.setAcceptRichText(False) self.setCursorWidth(2) self.setFontFamily("courier new") self.setProperty("backgroundVisible", True) bg_style = "QTextEdit { background-color: #fffffc;}" self.setStyleSheet("%s" % (bg_style)) self.setTextColor(QColor(0, 0, 0)) self.regexp_list = [QRegExp("\\binclude\\b"), QRegExp("\\btextfile\\b"), QRegExp("\\bfile\\b"), QRegExp("\\bvalue=.*pkg:\/\/\\b"), QRegExp("\\bvalue=.*package:\/\/\\b"), QRegExp("\\bvalue=.*\$\(find\\b"), QRegExp("\\bargs=.*\$\(find\\b"), QRegExp("\\bdefault=.*\$\(find\\b")] self.filename = filename self.file_mtime = 0 # f = QFile(filename) # if f.open(QIODevice.ReadOnly | QIODevice.Text): # self.file_info = QFileInfo(filename) # self.setText(unicode(f.readAll(), "utf-8")) self.path = '.' # enables drop events self.setAcceptDrops(True) # variables for threaded search self._search_thread = None self._stop = False self._internal_args = {} ext = os.path.splitext(filename) if self.filename: self.setText("") _, self.file_mtime, file_content = nm.nmd().file.get_file_content(filename) if ext[1] in ['.launch', '.xml']: self._internal_args = get_internal_args(file_content) self.setText(file_content) self._is_launchfile = False if ext[1] in ['.launch', '.xml', '.xacro', '.srdf', '.urdf']: if ext[1] in ['.launch']: self._is_launchfile = True self.hl = XmlHighlighter(self.document(), is_launch=False) self.cursorPositionChanged.connect(self._document_position_changed) else: self.hl = YamlHighlighter(self.document())
def _apply_file_content(self, filename, file_size, file_mtime, content): if not self.isReadOnly(): return if self.filename == filename: self.setText("") self.file_mtime = file_mtime if self._ext in self.CONTEXT_FILE_EXT: self._internal_args = get_internal_args(content) self.setText(content) self._is_launchfile = False if self._ext in ['.launch', '.xml', '.xacro', '.srdf', '.urdf']: if self._ext in self.CONTEXT_FILE_EXT: self._is_launchfile = True self.hl = XmlHighlighter(self.document(), is_launch=False) self.cursorPositionChanged.connect(self._document_position_changed) else: self.hl = YamlHighlighter(self.document()) self.setReadOnly(False) # enables drop events self.setAcceptDrops(True) self._select()