def mouseReleaseEvent(self, event):
     '''
     Opens the new editor, if the user clicked on the included file and sets the
     default cursor.
     '''
     if event.modifiers() == Qt.ControlModifier or event.modifiers() == Qt.ShiftModifier:
         cursor = self.cursorForPosition(event.pos())
         inc_files = LaunchConfig.included_files(cursor.block().text(), recursive=False)
         if inc_files:
             try:
                 qf = QFile(inc_files[0])
                 if not qf.exists():
                     # create a new file, if it does not exists
                     result = MessageBox.question(self, "File not found", '\n\n'.join(["Create a new file?", qf.fileName()]), buttons=MessageBox.Yes | MessageBox.No)
                     if result == MessageBox.Yes:
                         d = os.path.dirname(qf.fileName())
                         if not os.path.exists(d):
                             os.makedirs(d)
                         with open(qf.fileName(), 'w') as f:
                             if qf.fileName().endswith('.launch'):
                                 f.write('<launch>\n\n</launch>')
                         event.setAccepted(True)
                         self.load_request_signal.emit(qf.fileName())
                 else:
                     event.setAccepted(True)
                     self.load_request_signal.emit(qf.fileName())
             except Exception, e:
                 MessageBox.critical(self, "Error", "File not found %s" % inc_files[0], detailed_text=utf8(e))
 def _included_files(self, path):
     '''
     Returns all included files in the given file.
     '''
     result = []
     with open(path, 'r') as f:
         data = f.read()
         reg = QRegExp("=[\s\t]*\".*\"")
         reg.setMinimal(True)
         pos = reg.indexIn(data)
         while pos != -1 and self._isrunning:
             try:
                 pp = interpret_path(reg.cap(0).strip('"'))
                 f = QFile(pp)
                 ext = os.path.splitext(pp)
                 if f.exists() and ext[1] in nm.settings().SEARCH_IN_EXT:
                     result.append(pp)
             except Exception as exp:
                 parsed_text = pp
                 try:
                     parsed_text = reg.cap(0).strip('"')
                 except:
                     pass
                 self.warning_signal.emit("Error while parse '%s': %s" %
                                          (parsed_text, exp))
             pos += reg.matchedLength()
             pos = reg.indexIn(data, pos)
     return result
 def includedFiles(self):
     '''
     Returns all included files in the document.
     '''
     result = []
     b = self.document().begin()
     while b != self.document().end():
         text = b.text()
         index = self.index(text)
         if index > -1:
             startIndex = text.find('"', index)
             if startIndex > -1:
                 endIndex = text.find('"', startIndex + 1)
                 fileName = text[startIndex + 1:endIndex]
                 if len(fileName) > 0:
                     try:
                         path = interpret_path(fileName)
                         f = QFile(path)
                         ext = os.path.splitext(path)
                         if f.exists() and ext[1] in nm.settings().SEARCH_IN_EXT:
                             result.append(path)
                     except:
                         import traceback
                         print traceback.format_exc(1)
         b = b.next()
     return result
Beispiel #4
0
 def mouseReleaseEvent(self, event):
     '''
     Opens the new editor, if the user clicked on the included file and sets the
     default cursor.
     '''
     if event.modifiers() == Qt.ControlModifier or event.modifiers() == Qt.ShiftModifier:
         cursor = self.cursorForPosition(event.pos())
         index = self.index(cursor.block().text())
         if index > -1:
             startIndex = cursor.block().text().find('"', index)
             if startIndex > -1:
                 endIndex = cursor.block().text().find('"', startIndex + 1)
                 fileName = cursor.block().text()[startIndex + 1:endIndex]
                 if len(fileName) > 0:
                     try:
                         qf = QFile(interpret_path(fileName))
                         if not qf.exists():
                             # create a new file, if it does not exists
                             result = QMessageBox.question(self, "File not found", '\n\n'.join(["Create a new file?", qf.fileName()]), QMessageBox.Yes | QMessageBox.No)
                             if result == QMessageBox.Yes:
                                 d = os.path.dirname(qf.fileName())
                                 if not os.path.exists(d):
                                     os.makedirs(d)
                                 with open(qf.fileName(), 'w') as f:
                                     if qf.fileName().endswith('.launch'):
                                         f.write('<launch>\n\n</launch>')
                                 event.setAccepted(True)
                                 self.load_request_signal.emit(qf.fileName())
                         else:
                             event.setAccepted(True)
                             self.load_request_signal.emit(qf.fileName())
                     except Exception, e:
                         WarningMessageBox(QMessageBox.Warning, "File not found %s" % fileName, str(e)).exec_()
Beispiel #5
0
 def includedFiles(self):
     '''
     Returns all included files in the document.
     '''
     result = []
     b = self.document().begin()
     while b != self.document().end():
         text = b.text()
         index = self.index(text)
         if index > -1:
             startIndex = text.find('"', index)
             if startIndex > -1:
                 endIndex = text.find('"', startIndex + 1)
                 fileName = text[startIndex + 1:endIndex]
                 if len(fileName) > 0:
                     try:
                         path = interpret_path(fileName)
                         f = QFile(path)
                         ext = os.path.splitext(path)
                         if f.exists() and ext[1] in nm.settings(
                         ).SEARCH_IN_EXT:
                             result.append(path)
                     except:
                         import traceback
                         print traceback.format_exc(1)
         b = b.next()
     return result
 def _included_files(self, path):
     '''
     Returns all included files in the given file.
     '''
     result = []
     with open(path, 'r') as f:
         data = f.read()
         reg = QRegExp("=[\s\t]*\".*\"")
         reg.setMinimal(True)
         pos = reg.indexIn(data)
         while pos != -1 and self._isrunning:
             try:
                 pp = interpret_path(reg.cap(0).strip('"'))
                 f = QFile(pp)
                 ext = os.path.splitext(pp)
                 if f.exists() and ext[1] in nm.settings().SEARCH_IN_EXT:
                     result.append(pp)
             except Exception as exp:
                 parsed_text = pp
                 try:
                     parsed_text = reg.cap(0).strip('"')
                 except:
                     pass
                 self.warning_signal.emit("Error while parse '%s': %s" % (parsed_text, exp))
             pos += reg.matchedLength()
             pos = reg.indexIn(data, pos)
     return result
 def included_files(cls, text_or_path,
                    regexp_retruns=[],
                    regexp_filelist=[QRegExp("\\btextfile\\b"),
                                     QRegExp("\\bfile\\b"),
                                     QRegExp("\\bdefault\\b"),
                                     QRegExp("\\bvalue=.*pkg:\/\/\\b"),
                                     QRegExp("\\bvalue=.*package:\/\/\\b"),
                                     QRegExp("\\bvalue=.*\$\(find\\b"),
                                     QRegExp("\\bargs=.*\$\(find\\b")],
                    recursive=True, unique=True):
     '''
     :param regexp_retruns: the list with patterns which are returned as result. If empy it's the same as 'regexp_filelist'
     :param regexp_filelist: the list with all patterns to find include files
     '''
     result = []
     lines = []
     pwd = '.'
     f = QFile(text_or_path)
     if f.exists():
         pwd = os.path.dirname(text_or_path)
         with open(text_or_path, 'r') as f:
             content = f.read()
             # remove the comments
             comment_pattern = QRegExp("<!--.*?-->")
             pos = comment_pattern.indexIn(content)
             while pos != -1:
                 content = content[:pos] + content[pos + comment_pattern.matchedLength():]
                 pos = comment_pattern.indexIn(content)
             lines = content.splitlines()
     else:
         lines = [text_or_path]
     line_index = 0
     for line in lines:
         index = cls._index(line, regexp_filelist)
         if index > -1:
             startIndex = line.find('"', index)
             if startIndex > -1:
                 endIndex = line.find('"', startIndex + 1)
                 fileName = line[startIndex + 1:endIndex]
                 if len(fileName) > 0:
                     try:
                         path = cls.interpretPath(fileName, pwd)
                         if os.path.isfile(path):
                             if not regexp_retruns or cls._index(line, regexp_retruns) > -1:
                                 if not unique:
                                     result.append((line_index, path))
                                 else:
                                     result.append(path)
                             ext = os.path.splitext(path)
                             if recursive and ext[1] in nm.settings().SEARCH_IN_EXT:
                                 result += cls.included_files(path, regexp_retruns, regexp_filelist)
                     except Exception:
                         import traceback
                         print traceback.format_exc()
         line_index += 1
     if unique:
         return list(set(result))
     return result
 def included_files(cls, text_or_path, regexp_list=[QRegExp("\\btextfile\\b"),
                                                    QRegExp("\\bfile\\b"),
                                                    QRegExp("\\bdefault\\b"),
                                                    QRegExp("\\bvalue=.*pkg:\/\/\\b"),
                                                    QRegExp("\\bvalue=.*package:\/\/\\b"),
                                                    QRegExp("\\bvalue=.*\$\(find\\b"),
                                                    QRegExp("\\bargs=.*\$\(find\\b")],
                    recursive=True, unique=True):
     result = []
     lines = []
     pwd = '.'
     f = QFile(text_or_path)
     if f.exists():
         pwd = os.path.dirname(text_or_path)
         with open(text_or_path, 'r') as f:
             content = f.read()
             # remove the comments
             comment_pattern = QRegExp("<!--.*?-->")
             pos = comment_pattern.indexIn(content)
             while pos != -1:
                 content = content[:pos] + content[pos + comment_pattern.matchedLength():]
                 pos = comment_pattern.indexIn(content)
             lines = content.splitlines()
     else:
         lines = [text_or_path]
     line_index = 0
     for line in lines:
         index = cls._index(line, regexp_list)
         if index > -1:
             startIndex = line.find('"', index)
             if startIndex > -1:
                 endIndex = line.find('"', startIndex + 1)
                 fileName = line[startIndex + 1:endIndex]
                 if len(fileName) > 0:
                     try:
                         path = cls.interpretPath(fileName, pwd)
                         if os.path.isfile(path):
                             if not unique:
                                 result.append((line_index, path))
                             else:
                                 result.append(path)
                             ext = os.path.splitext(path)
                             if recursive and ext[1] in nm.settings().SEARCH_IN_EXT:
                                 result += cls.included_files(path, regexp_list)
                     except Exception:
                         import traceback
                         print traceback.format_exc()
         line_index += 1
     if unique:
         return list(set(result))
     return result
Beispiel #9
0
 def mouseReleaseEvent(self, event):
     '''
     Opens the new editor, if the user clicked on the included file and sets the
     default cursor.
     '''
     if event.modifiers() == Qt.ControlModifier or event.modifiers(
     ) == Qt.ShiftModifier:
         cursor = self.cursorForPosition(event.pos())
         index = self.index(cursor.block().text())
         if index > -1:
             startIndex = cursor.block().text().find('"', index)
             if startIndex > -1:
                 endIndex = cursor.block().text().find('"', startIndex + 1)
                 fileName = cursor.block().text()[startIndex + 1:endIndex]
                 if len(fileName) > 0:
                     try:
                         qf = QFile(interpret_path(fileName))
                         if not qf.exists():
                             # create a new file, if it does not exists
                             result = QMessageBox.question(
                                 self, "File not found", '\n\n'.join(
                                     ["Create a new file?",
                                      qf.fileName()]),
                                 QMessageBox.Yes | QMessageBox.No)
                             if result == QMessageBox.Yes:
                                 d = os.path.dirname(qf.fileName())
                                 if not os.path.exists(d):
                                     os.makedirs(d)
                                 with open(qf.fileName(), 'w') as f:
                                     if qf.fileName().endswith('.launch'):
                                         f.write('<launch>\n\n</launch>')
                                 event.setAccepted(True)
                                 self.load_request_signal.emit(
                                     qf.fileName())
                         else:
                             event.setAccepted(True)
                             self.load_request_signal.emit(qf.fileName())
                     except Exception, e:
                         WarningMessageBox(QMessageBox.Warning,
                                           "File not found %s" % fileName,
                                           str(e)).exec_()
 def mouseReleaseEvent(self, event):
     '''
     Opens the new editor, if the user clicked on the included file and sets the
     default cursor.
     '''
     if event.modifiers() == Qt.ControlModifier or event.modifiers(
     ) == Qt.ShiftModifier:
         cursor = self.cursorForPosition(event.pos())
         inc_files = LaunchConfig.included_files(cursor.block().text(),
                                                 recursive=False)
         if inc_files:
             try:
                 qf = QFile(inc_files[0])
                 if not qf.exists():
                     # create a new file, if it does not exists
                     result = MessageBox.question(
                         self,
                         "File not found",
                         '\n\n'.join(["Create a new file?",
                                      qf.fileName()]),
                         buttons=MessageBox.Yes | MessageBox.No)
                     if result == MessageBox.Yes:
                         d = os.path.dirname(qf.fileName())
                         if not os.path.exists(d):
                             os.makedirs(d)
                         with open(qf.fileName(), 'w') as f:
                             if qf.fileName().endswith('.launch'):
                                 f.write('<launch>\n\n</launch>')
                         event.setAccepted(True)
                         self.load_request_signal.emit(qf.fileName())
                 else:
                     event.setAccepted(True)
                     self.load_request_signal.emit(qf.fileName())
             except Exception, e:
                 MessageBox.critical(self,
                                     "Error",
                                     "File not found %s" % inc_files[0],
                                     detailed_text=utf8(e))