def _replace_results(self): """Replace the search with the proper text in all the files.""" result = QMessageBox.question( self, translations.TR_REPLACE_FILES_CONTENTS, translations.TR_ARE_YOU_SURE_WANT_TO_REPLACE, buttons=QMessageBox.Yes | QMessageBox.No) if result == QMessageBox.Yes: for index in range(self._result_widget.topLevelItemCount()): parent = self._result_widget.topLevelItem(index) root_dir_name = parent.dir_name_root file_name = parent.text(0) file_path = file_manager.create_path(root_dir_name, file_name) try: content = file_manager.read_file_content(file_path) pattern = self._find_widget.pattern_line_edit.text() flags = 0 if not self._find_widget.case_checkbox.isChecked(): flags |= re.IGNORECASE if self._find_widget.type_checkbox.isChecked(): pattern = r'\b%s\b' % pattern new_content = re.sub(pattern, self._find_widget.replace_line.text(), content, flags=flags) file_manager.store_file_content(file_path, new_content, False) except: print(('File: {} content, could not be replaced'.format( file_path)))
def _move_file(self): path = self.model().filePath(self.currentIndex()) global projectsColumn pathProjects = [p.path for p in projectsColumn.projects] addToProject = add_to_project.AddToProject(pathProjects, self) addToProject.setWindowTitle(self.tr("Copy File to")) addToProject.exec_() if not addToProject.pathSelected: return name = file_manager.get_basename(path) path = file_manager.create_path(addToProject.pathSelected, name) try: content = file_manager.read_file_content(path) path = file_manager.store_file_content(path, content, newFile=True) file_manager.delete_file(path) # Update path of opened file main = IDE.get_service('main_container') if main and main.is_open(path): widget = main.get_widget_for_path(path) if widget: widget.ID = path except file_manager.NinjaFileExistsException as ex: QMessageBox.information(self, self.tr("File Already Exists"), (self.tr("Invalid Path: the file '%s' already exists.") % ex.filename))
def _replace_results(self): result = QMessageBox.question( self, self.tr("Replace Files Contents"), self.tr("Are you sure you want to replace the content in " "this files?\n(The change is not reversible)"), buttons=QMessageBox.Yes | QMessageBox.No) if result == QMessageBox.Yes: for index in range(self._result_widget.topLevelItemCount()): parent = self._result_widget.topLevelItem(index) root_dir_name = parent.dir_name_root file_name = parent.text(0) file_path = file_manager.create_path(root_dir_name, file_name) try: content = file_manager.read_file_content(file_path) pattern = self._find_widget.pattern_line_edit.text() flags = 0 if not self._find_widget.case_checkbox.isChecked(): flags |= re.IGNORECASE if self._find_widget.type_checkbox.isChecked(): pattern = r'\b%s\b' % pattern new_content = re.sub(pattern, self._find_widget.replace_line.text(), content, flags=flags) file_manager.store_file_content(file_path, new_content, False) except: print('File: %s content, could not be replaced' % file_path)
def _copy_file(self): #get the selected QTreeWidgetItem item = self.currentItem() if item.parent() is None: pathForFile = item.path else: pathForFile = os.path.join(item.path, item.text(0)) pathProjects = [p.path for p in self.get_open_projects()] addToProject = ui_tools.AddToProject(pathProjects, self) addToProject.setWindowTitle(self.tr("Copy File to")) addToProject.exec_() if not addToProject.pathSelected: return name = QInputDialog.getText(self, self.tr("Copy File"), self.tr("File Name:"), text=item.text(0))[0] if not name: QMessageBox.information( self, self.tr("Invalid Name"), self.tr("The file name is empty, please enter a name")) return path = file_manager.create_path(addToProject.pathSelected, name) try: content = file_manager.read_file_content(pathForFile) path = file_manager.store_file_content(path, content, newFile=True) self.add_existing_file(path) except file_manager.NinjaFileExistsException as ex: QMessageBox.information( self, self.tr("File Already Exists"), (self.tr("Invalid Path: the file '%s' already exists.") % ex.filename))
def _copy_file(self): #get the selected QTreeWidgetItem path = self.model().filePath(self.currentIndex()) name = file_manager.get_basename(path) global projectsColumn pathProjects = [p.path for p in projectsColumn.projects] addToProject = add_to_project.AddToProject(pathProjects, self) addToProject.setWindowTitle(self.tr("Copy File to")) addToProject.exec_() if not addToProject.pathSelected: return name = QInputDialog.getText(self, self.tr("Copy File"), self.tr("File Name:"), text=name)[0] if not name: QMessageBox.information(self, self.tr("Invalid Name"), self.tr("The file name is empty, please enter a name")) return path = file_manager.create_path(addToProject.pathSelected, name) try: content = file_manager.read_file_content(path) path = file_manager.store_file_content(path, content, newFile=True) except file_manager.NinjaFileExistsException as ex: QMessageBox.information(self, self.tr("File Already Exists"), (self.tr("Invalid Path: the file '%s' already exists.") % ex.filename))
def _move_file(self): item = self.currentItem() if item.parent() is None: pathForFile = item.path else: pathForFile = os.path.join(item.path, item.text(0)) pathProjects = [p.path for p in self.get_open_projects()] addToProject = ui_tools.AddToProject(pathProjects, self) addToProject.setWindowTitle(self.tr("Copy File to")) addToProject.exec_() if not addToProject.pathSelected: return name = file_manager.get_basename(pathForFile) path = file_manager.create_path(addToProject.pathSelected, name) try: content = file_manager.read_file_content(pathForFile) path = file_manager.store_file_content(path, content, newFile=True) file_manager.delete_file(pathForFile) index = item.parent().indexOfChild(item) item.parent().takeChild(index) self.add_existing_file(path) # Update path of opened file main = IDE.get_service('main_container') if main and main.is_open(pathForFile): widget = main.get_widget_for_path(pathForFile) if widget: widget.ID = path except file_manager.NinjaFileExistsException as ex: QMessageBox.information( self, self.tr("File Already Exists"), (self.tr("Invalid Path: the file '%s' already exists.") % ex.filename))
def _move_file(self): item = self.currentItem() if item.parent() is None: pathForFile = item.path else: pathForFile = os.path.join(item.path, item.text(0)) pathProjects = [p.path for p in self.get_open_projects()] addToProject = ui_tools.AddToProject(pathProjects, self) addToProject.setWindowTitle(self.tr("Copy File to")) addToProject.exec_() if not addToProject.pathSelected: return name = file_manager.get_basename(pathForFile) path = file_manager.create_path(addToProject.pathSelected, name) try: content = file_manager.read_file_content(pathForFile) path = file_manager.store_file_content(path, content, newFile=True) file_manager.delete_file(pathForFile) index = item.parent().indexOfChild(item) item.parent().takeChild(index) self.add_existing_file(path) # Update path of opened file main = IDE.get_service('main_container') if main and main.is_open(pathForFile): widget = main.get_widget_for_path(pathForFile) if widget: widget.ID = path except file_manager.NinjaFileExistsException as ex: QMessageBox.information(self, self.tr("File Already Exists"), (self.tr("Invalid Path: the file '%s' already exists.") % ex.filename))
def _replace_results(self): """Replace the search with the proper text in all the files.""" result = QMessageBox.question(self, translations.TR_REPLACE_FILES_CONTENTS, translations.TR_ARE_YOU_SURE_WANT_TO_REPLACE, buttons=QMessageBox.Yes | QMessageBox.No) if result == QMessageBox.Yes: for index in range(self._result_widget.topLevelItemCount()): parent = self._result_widget.topLevelItem(index) root_dir_name = parent.dir_name_root file_name = parent.text(0) file_path = file_manager.create_path(root_dir_name, file_name) try: content = file_manager.read_file_content(file_path) pattern = self._find_widget.pattern_line_edit.text() flags = 0 if not self._find_widget.case_checkbox.isChecked(): flags |= re.IGNORECASE if self._find_widget.type_checkbox.isChecked(): pattern = r'\b%s\b' % pattern new_content = re.sub(pattern, self._find_widget.replace_line.text(), content, flags=flags) file_manager.store_file_content(file_path, new_content, False) except: print(('File: {} content, could not be replaced'.format( file_path)))
def _copy_file(self): #get the selected QTreeWidgetItem item = self.currentItem() if item.parent() is None: pathForFile = item.path else: pathForFile = os.path.join(item.path, item.text(0)) pathProjects = [p.path for p in self.get_open_projects()] addToProject = ui_tools.AddToProject(pathProjects, self) addToProject.setWindowTitle(self.tr("Copy File to")) addToProject.exec_() if not addToProject.pathSelected: return name = QInputDialog.getText(self, self.tr("Copy File"), self.tr("File Name:"), text=item.text(0))[0] if not name: QMessageBox.information(self, self.tr("Invalid Name"), self.tr("The file name is empty, please enter a name")) return path = file_manager.create_path(addToProject.pathSelected, name) try: content = file_manager.read_file_content(pathForFile) path = file_manager.store_file_content(path, content, newFile=True) self.add_existing_file(path) except file_manager.NinjaFileExistsException as ex: QMessageBox.information(self, self.tr("File Already Exists"), (self.tr("Invalid Path: the file '%s' already exists.") % ex.filename))
def _replace_results(self): result = QMessageBox.question(self, self.tr("Replace Files Contents"), self.tr("Are you sure you want to replace the content in " "this files?\n(The change is not reversible)"), buttons=QMessageBox.Yes | QMessageBox.No) if result == QMessageBox.Yes: for index in range(self._result_widget.topLevelItemCount()): parent = self._result_widget.topLevelItem(index) root_dir_name = parent.dir_name_root file_name = parent.text(0) file_path = file_manager.create_path(root_dir_name, file_name) try: content = file_manager.read_file_content(file_path) pattern = self._find_widget.pattern_line_edit.text() flags = 0 if not self._find_widget.case_checkbox.isChecked(): flags |= re.IGNORECASE if self._find_widget.type_checkbox.isChecked(): pattern = r'\b%s\b' % pattern new_content = re.sub(pattern, self._find_widget.replace_line.text(), content, flags=flags) file_manager.store_file_content(file_path, new_content, False) except: print('File: %s content, could not be replaced' % file_path)
def create_class(self, path): content = file_manager.read_file_content(path) items = introspection.obtain_symbols(content) mYPadding = 10 mXPadding = 10 for classname, classdetail in list(items["classes"].items()): cl = ClassModel(self.graphicView, self.scene) cl.set_class_name(classname) self.fill_clases(cl, classdetail[1]) self.scene.addItem(cl) cl.setPos(self.mX, self.mY) self.mX += cl._get_width() + mXPadding if self.hightestY < self.mY + cl.get_height(): self.hightestY = self.mY + cl.get_height() if self.mX > 2000: self.mX = -400 self.mY += self.hightestY + mYPadding
def test_read_file_content(self): filename = os.path.join(self.examples_dir, 'file_for_tests.py') content = file_manager.read_file_content(filename) expected = ("# -*- coding: utf-8 -*-\n\nprint 'testing'\n" "print 'ñandú testing'\n").encode('utf-8') self.assertEqual(content, expected)