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(_translate("TreeProjectsWidget", "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 = main_container.MainContainer() if 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, _translate("TreeProjectsWidget", "File Already Exists"), (_translate("TreeProjectsWidget", "Invalid Path: the file '%s' already exists.") % ex.filename))
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 __open_file(self, fileName='', cursorPosition=0,\ tabIndex=None, positionIsLineNumber=False, notStart=True): try: if not self.is_open(fileName): self.actualTab.notOpening = False content = file_manager.read_file_content(fileName) editorWidget = self.add_editor(fileName, tabIndex=tabIndex, content=content) editorWidget.ID = fileName encoding = file_manager._search_coding_line(content) editorWidget.encoding = encoding if not positionIsLineNumber: editorWidget.set_cursor_position(cursorPosition) else: editorWidget.go_to_line(cursorPosition) if not editorWidget.has_write_permission(): fileName += unicode(self.tr(" (Read-Only)")) index = self.actualTab.currentIndex() self.actualTab.setTabText(index, fileName) else: self.move_to_open(fileName) editorWidget = self.get_actual_editor() if editorWidget: if positionIsLineNumber: editorWidget.go_to_line(cursorPosition) else: editorWidget.set_cursor_position(cursorPosition) self.emit(SIGNAL("currentTabChanged(QString)"), fileName) except file_manager.NinjaIOException, reason: if not notStart: QMessageBox.information(self, self.tr("The file couldn't be open"), unicode(reason))
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 _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) 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 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 _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) 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): item = self.currentItem() if item.parent() is None: pathForFile = item.path else: pathForFile = os.path.join(item.path, unicode(item.text(0))) pathProject = self.get_selected_project_path() addToProject = ui_tools.AddToProject(pathProject, self) addToProject.setWindowTitle(self.tr("Copy File to")) addToProject.exec_() if not addToProject.pathSelected: return name = unicode(QInputDialog.getText(None, self.tr("Copy File"), self.tr("File Name:"))[0]) if not name: QMessageBox.information(self, self.tr("Indalid Name"), self.tr("The file name is empty, please enter a name")) return path = file_manager.create_path( unicode(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, ex: QMessageBox.information(self, self.tr("File Already Exists"), self.tr("Invalid Path: the file '%s' already exists." % \ ex.filename))
def __open_file(self, fileName='', cursorPosition=0,\ tabIndex=None, positionIsLineNumber=False, notStart=True): try: if not self.is_open(fileName): self.actualTab.notOpening = False content = file_manager.read_file_content(fileName) editorWidget = self.add_editor(fileName, tabIndex=tabIndex, content=content) editorWidget.ID = fileName encoding = file_manager._search_coding_line(content) editorWidget.encoding = encoding if not positionIsLineNumber: editorWidget.set_cursor_position(cursorPosition) else: editorWidget.go_to_line(cursorPosition) if not editorWidget.has_write_permission(): fileName += unicode(self.tr(" (Read-Only)")) index = self.actualTab.currentIndex() self.actualTab.setTabText(index, fileName) else: self.move_to_open(fileName) editorWidget = self.get_actual_editor() if editorWidget: if positionIsLineNumber: editorWidget.go_to_line(cursorPosition) else: editorWidget.set_cursor_position(cursorPosition) self.emit(SIGNAL("currentTabChanged(QString)"), fileName) except file_manager.NinjaIOException, reason: if not notStart: QMessageBox.information(self, self.tr("The file couldn't be open"), unicode(reason))
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 __open_file(self, fileName='', cursorPosition=-1, tabIndex=None, positionIsLineNumber=False, notStart=True): try: if not self.is_open(fileName): self.actualTab.notOpening = False content = file_manager.read_file_content(fileName) editorWidget = self.add_editor(fileName, tabIndex=tabIndex, use_open_highlight=True) editorWidget.highlighter.set_open_visible_area( positionIsLineNumber, cursorPosition) #Add content #we HAVE to add the editor's content before set the ID #because of the minimap logic editorWidget.setPlainText(content) editorWidget.ID = fileName editorWidget.async_highlight() encoding = file_manager.get_file_encoding(content) editorWidget.encoding = encoding if cursorPosition == -1: cursorPosition = 0 if not positionIsLineNumber: editorWidget.set_cursor_position(cursorPosition) else: editorWidget.go_to_line(cursorPosition) self.add_standalone_watcher(editorWidget.ID, notStart) #New file then try to add a coding line if not content: helpers.insert_coding_line(editorWidget) self.save_file(editorWidget=editorWidget) if not editorWidget.has_write_permission(): fileName += self.tr(" (Read-Only)") index = self.actualTab.currentIndex() self.actualTab.setTabText(index, fileName) else: self.move_to_open(fileName) editorWidget = self.get_actual_editor() if editorWidget and notStart and cursorPosition != -1: if positionIsLineNumber: editorWidget.go_to_line(cursorPosition) else: editorWidget.set_cursor_position(cursorPosition) self.emit(SIGNAL("currentTabChanged(QString)"), fileName) except file_manager.NinjaIOException as reason: if notStart: QMessageBox.information(self, self.tr("The file couldn't be open"), str(reason)) except Exception as reason: logger.error('open_file: %s', reason) self.actualTab.notOpening = True
def __open_file(self, fileName='', cursorPosition=-1, tabIndex=None, positionIsLineNumber=False, notStart=True): try: if not self.is_open(fileName): print("can not opened!") self.actualTab.notOpening = False content = file_manager.read_file_content(fileName) editorWidget = self.add_editor(fileName, tabIndex=tabIndex, use_open_highlight=True) #Add content #we HAVE to add the editor's content before set the ID #because of the minimap logic editorWidget.setPlainText(content) editorWidget.ID = fileName editorWidget.async_highlight() encoding = file_manager.get_file_encoding(content) editorWidget.encoding = encoding if cursorPosition == -1: cursorPosition = 0 if not positionIsLineNumber: editorWidget.set_cursor_position(cursorPosition) else: editorWidget.go_to_line(cursorPosition) self.add_standalone_watcher(editorWidget.ID, notStart) #New file then try to add a coding line if not content: helpers.insert_coding_line(editorWidget) self.save_file(editorWidget=editorWidget) if not editorWidget.has_write_permission(): fileName += _translate("_s_MainContainer", " (Read-Only)") index = self.actualTab.currentIndex() self.actualTab.setTabText(index, fileName) else: print("has opened") self.move_to_open(fileName) editorWidget = self.get_actual_editor() if editorWidget and notStart and cursorPosition != -1: if positionIsLineNumber: editorWidget.go_to_line(cursorPosition) else: editorWidget.set_cursor_position(cursorPosition) print("file.FileName::", fileName) self.currentTabChanged.emit(fileName) except file_manager.NinjaIOException as reason: if notStart: QMessageBox.information(self, _translate("_s_MainContainer", "The file couldn't be open"), str(reason)) except Exception as reason: logger.error('open_file: %s', reason) self.actualTab.notOpening = True
def __open_file(self, fileName='', cursorPosition=-1, tabIndex=None, positionIsLineNumber=False, notStart=True): try: if not self.is_open(fileName): self.actualTab.notOpening = False content = file_manager.read_file_content(fileName) editorWidget = self.add_editor(fileName, tabIndex=tabIndex, use_open_highlight=True) editorWidget.highlighter.set_open_visible_area( positionIsLineNumber, cursorPosition) #Add content editorWidget.ID = fileName editorWidget.setPlainText(content) editorWidget.async_highlight() encoding = file_manager.get_file_encoding(content) editorWidget.encoding = encoding if cursorPosition == -1: cursorPosition = 0 if not positionIsLineNumber: editorWidget.set_cursor_position(cursorPosition) else: editorWidget.go_to_line(cursorPosition) self.add_standalone_watcher(editorWidget.ID, notStart) #New file then try to add a coding line if not content: helpers.insert_coding_line(editorWidget) self.save_file(editorWidget=editorWidget) if not editorWidget.has_write_permission(): fileName += self.tr(" (Read-Only)") index = self.actualTab.currentIndex() self.actualTab.setTabText(index, fileName) else: self.move_to_open(fileName) editorWidget = self.get_actual_editor() if editorWidget and notStart and cursorPosition != -1: if positionIsLineNumber: editorWidget.go_to_line(cursorPosition) else: editorWidget.set_cursor_position(cursorPosition) self.emit(SIGNAL("currentTabChanged(QString)"), fileName) except file_manager.NinjaIOException as reason: if not notStart: QMessageBox.information(self, self.tr("The file couldn't be open"), reason) except Exception as reason: logger.error('open_file: %s', reason) self.actualTab.notOpening = True
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 __init__(self, url, process=None, parent=None): QWidget.__init__(self, parent) itab_item.ITabItem.__init__(self) self._id = url self._process = process vbox = QVBoxLayout(self) #Web Frame QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, True) self.webFrame = QWebView(self) self.webFrame.setAcceptDrops(False) factory = WebPluginFactory(self) self.webFrame.page().setPluginFactory(factory) self.webFrame.load(QUrl(url)) vbox.addWidget(self.webFrame) if process is not None: time.sleep(0.5) self.webFrame.load(QUrl(url)) if url == resources.START_PAGE_URL: self.webFrame.page().setLinkDelegationPolicy( QWebPage.DelegateAllLinks) self.connect(self.webFrame, SIGNAL("linkClicked(QUrl)"), self.start_page_operations) if sys.platform == "win32": content = file_manager.read_file_content(self.ID) pathCss = os.path.join(resources.PRJ_PATH, 'doc', 'css', 'style.css') pathJs = os.path.join(resources.PRJ_PATH, 'doc', 'js', 'libs') pathImg = os.path.join(resources.PRJ_PATH, 'doc', 'img') content = content.replace('css/style.css', pathCss).replace( 'src="js/libs/', 'src="%s\\' % pathJs).replace('src="img/', 'src="%s\\' % pathImg) self.webFrame.setHtml(content) self._id = 'Start Page' policy = Qt.ScrollBarAlwaysOff else: policy = Qt.ScrollBarAsNeeded self.webFrame.page().currentFrame().setScrollBarPolicy( Qt.Vertical, policy) self.webFrame.page().currentFrame().setScrollBarPolicy( Qt.Horizontal, policy)
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 __init__(self, url, process=None, parent=None): QWidget.__init__(self, parent) itab_item.ITabItem.__init__(self) self._id = url self._process = process vbox = QVBoxLayout(self) #Web Frame QWebSettings.globalSettings().setAttribute( QWebSettings.PluginsEnabled, True) self.webFrame = QWebView(self) self.webFrame.setAcceptDrops(False) factory = WebPluginFactory(self) self.webFrame.page().setPluginFactory(factory) self.webFrame.load(QUrl(url)) vbox.addWidget(self.webFrame) if process is not None: time.sleep(0.5) self.webFrame.load(QUrl(url)) if url == resources.START_PAGE_URL: self.webFrame.page().setLinkDelegationPolicy( QWebPage.DelegateAllLinks) self.connect(self.webFrame, SIGNAL("linkClicked(QUrl)"), self.start_page_operations) if sys.platform == "win32": content = file_manager.read_file_content(self.ID) pathCss = os.path.join( resources.PRJ_PATH, 'doc', 'css', 'style.css') pathJs = os.path.join(resources.PRJ_PATH, 'doc', 'js', 'libs') pathImg = os.path.join(resources.PRJ_PATH, 'doc', 'img') content = content.replace('css/style.css', pathCss).replace( 'src="js/libs/', 'src="%s\\' % pathJs).replace( 'src="img/', 'src="%s\\' % pathImg) self.webFrame.setHtml(content) self._id = 'Start Page' policy = Qt.ScrollBarAlwaysOff else: policy = Qt.ScrollBarAsNeeded self.webFrame.page().currentFrame().setScrollBarPolicy( Qt.Vertical, policy) self.webFrame.page().currentFrame().setScrollBarPolicy( Qt.Horizontal, policy)
def __open_file(self, fileName='', cursorPosition=-1,\ tabIndex=None, positionIsLineNumber=False, notStart=True): try: if not self.is_open(fileName): self.actualTab.notOpening = False content = file_manager.read_file_content(fileName) editorWidget = self.add_editor(fileName, tabIndex=tabIndex, use_open_highlight=True) editorWidget.highlighter.set_open_visible_area( positionIsLineNumber, cursorPosition) #Add content editorWidget.setPlainText(content) editorWidget.ID = fileName editorWidget.async_highlight() encoding = file_manager.get_file_encoding(content) editorWidget.encoding = encoding if cursorPosition == -1: cursorPosition = 0 if not positionIsLineNumber: editorWidget.set_cursor_position(cursorPosition) else: editorWidget.go_to_line(cursorPosition) self.add_standalone_watcher(editorWidget.ID, notStart) if not editorWidget.has_write_permission(): fileName += unicode(self.tr(" (Read-Only)")) index = self.actualTab.currentIndex() self.actualTab.setTabText(index, fileName) else: self.move_to_open(fileName) editorWidget = self.get_actual_editor() if editorWidget and notStart and cursorPosition != -1: if positionIsLineNumber: editorWidget.go_to_line(cursorPosition) else: editorWidget.set_cursor_position(cursorPosition) self.emit(SIGNAL("currentTabChanged(QString)"), fileName) except file_manager.NinjaIOException, reason: if not notStart: QMessageBox.information(self, self.tr("The file couldn't be open"), unicode(reason))
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)
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)