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 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()) 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))