def add_editor(self, fileName=None, ignore_checkers=False): print("filename::", fileName) ninjaide = IDE.getInstance() editable = ninjaide.get_or_create_editable(fileName) if editable.editor: self.current_widget.set_current(editable) print("\n\nreturn") return self.current_widget.currentWidget() else: editable.ignore_checkers = ignore_checkers editorWidget = self.create_editor_from_editable(editable) #add the tab keep_index = (self.splitter.count() > 1 and self.combo_area.stacked.count() > 0) self.combo_area.add_editor(editable, keep_index) #emit a signal about the file open self.fileOpened.emit(fileName) if keep_index: self.current_widget.set_current(editable) self.stack.setCurrentWidget(self.splitter) return editorWidget
def install(self): """Install StatusBar as a service.""" self.hide() ide = IDE.getInstance() self._codeLocator = locator_widget.LocatorWidget(ide) ui_tools.install_shortcuts(self, actions.ACTIONS_STATUS, ide)
def _close(self, path, temp): if temp: nfile = self._temp_files.get(temp, None) else: ninjaide = IDE.getInstance() nfile = ninjaide.get_or_create_nfile(path) if nfile is not None: nfile.close()
def _get_save_folder(self, fileName): """ Returns the root directory of the 'Main Project' or the home folder """ ninjaide = IDE.getInstance() current_project = ninjaide.get_current_project() if current_project: return current_project.path return os.path.expanduser("~")
def _file_opened_by_main(self, path): index = self.stackedEditor.currentIndex() ninjaide = IDE.getInstance() editable = ninjaide.get_or_create_editable(path) print("_file_opened_by_main", editable) self.add_editor(editable) self.bar.set_current_by_index(index) if index == -1: self.bar.set_current_by_index(0)
def _file_opened_by_main(self, path): index = self.stacked.currentIndex() ninjaide = IDE.getInstance() editable = ninjaide.get_or_create_editable(path) print("_file_opened_by_main", editable) self.add_editor(editable) self.bar.set_current_by_index(index) if index == -1: self.bar.set_current_by_index(0)
def _add_model(self): print("_add_model:_add_model") ninjaide = IDE.getInstance() files = ninjaide.opened_files # print("_add_model::", files, "\n", self._model.keys()) # Update model # old = set(self._model.keys()) # now = set([nfile.file_path for nfile in files]) # new = old - now # for item in new: # del self._model[item] past = set(self._model.keys()) now = set([nfile.file_path for nfile in files]) old = past - now # print("\n_model:past:", past) # print("\n_model:now:", now) # print("\n_model:old:", old) for item in old: del self._model[item] current_editor = self._main_container.get_current_editor() current_path = None if current_editor: current_path = current_editor.file_path model = [] # print("len(files)", len(files), [nfile.file_path for nfile in files], "\n\n") for nfile in files: if (nfile.file_path not in self._model and nfile.file_path is not None): self._model[nfile.file_path] = 0 neditable = ninjaide.get_or_create_editable(nfile=nfile) checkers = neditable.sorted_checkers checks = [] for items in checkers: checker, color, _ = items if checker.dirty: # Colors needs to be reversed for QML color = "#%s" % color[::-1] checks.append( {"checker_text": checker.dirty_text, "checker_color": color}) modified = neditable.editor.is_modified temp_file = str(uuid.uuid4()) if nfile.file_path is None else "" filepath = nfile.file_path if nfile.file_path is not None else "" model.append([nfile.file_name, filepath, checks, modified, temp_file]) if temp_file: self._temp_files[temp_file] = nfile if current_path: index = self._model[current_path] self._max_index = max(self._max_index, index) + 1 self._model[current_path] = self._max_index model = sorted(model, key=lambda x: self._model.get(x[1], False), reverse=True) self._root.set_model(model)
def __init__(self): super(ConsoleWidget, self).__init__('>>> ') self.setUndoRedoEnabled(False) self.apply_editor_style() self.setToolTip(self.tr("Show/Hide (F4)")) self.moveCursor(QTextCursor.EndOfLine) self._patIsWord = re.compile('\w+') self.prompt = '>>> ' self._console = console.Console() self._history = [] self.history_index = 0 self._current_command = '' self._braces = None self.imports = ['import __builtin__'] self.patFrom = re.compile('^(\\s)*from ((\\w)+(\\.)*(\\w)*)+ import') self.patImport = re.compile('^(\\s)*import (\\w)+') self.patObject = re.compile('[^a-zA-Z0-9_\\.]') #self.completer = completer_widget.CompleterWidget(self) self.okPrefix = QRegExp('[.)}:,\]]') self._pre_key_press = { Qt.Key_Enter: self._enter_pressed, Qt.Key_Return: self._enter_pressed, Qt.Key_Tab: self._tab_pressed, Qt.Key_Home: self._home_pressed, Qt.Key_PageUp: lambda x: True, Qt.Key_PageDown: lambda x: True, Qt.Key_Left: self._left_pressed, Qt.Key_Up: self._up_pressed, Qt.Key_Down: self._down_pressed, Qt.Key_Backspace: self._backspace, } #Create Context Menu self._create_context_menu() #Set Font self.set_font(settings.FONT) #Create Highlighter parts_scanner, code_scanner, formats = \ syntax_highlighter.load_syntax(python_syntax.syntax) self.highlighter = syntax_highlighter.SyntaxHighlighter( self.document(), parts_scanner, code_scanner, formats) self.cursorPositionChanged.connect(self.highlight_current_line) self.highlight_current_line() self._proc = QProcess(self) self._proc.readyReadStandardOutput.connect(self._python_path_detected) self._proc.error['QProcess::ProcessError'].connect(self.process_error) self._add_system_path_for_frozen() ninjaide = IDE.getInstance() ninjaide.ns_preferences_editor_font.connect(self.set_font)
def open(self): """Open the selected file in the proper line.""" if not self._find_widget.isVisible(): ninjaide = IDE.getInstance() actual_projects_obj = ninjaide.filesystem.get_projects() actual_projects = [path for path in actual_projects_obj] actual = ninjaide.get_current_project() actual_path = None if actual: actual_path = actual.path self._find_widget.show(actual_project=actual_projects, actual=actual_path)
def install(self): ide = IDE.getInstance() ide.place_me_on("main_container", self, "central", top=True) self.combo_area = combo_editor.ComboEditor(original=True) self.combo_area.allFilesClosed.connect(self._files_closed) self.splitter.add_widget(self.combo_area) self.add_widget(self.splitter) self.current_widget = self.combo_area ui_tools.install_shortcuts(self, actions.ACTIONS, ide)
def __init__(self, editor): super(Pep8Checker, self).__init__() self._editor = editor self._path = '' self._encoding = '' self.checks = {} self.checker_icon = QStyle.SP_MessageBoxWarning ninjaide = IDE.getInstance() ninjaide.ns_preferences_editor_checkStyle.connect(lambda: remove_pep8_checker()) self.checkerCompleted.connect(self.refresh_display)
def install(self): ide = IDE.getInstance() ide.place_me_on("explorer_container", self, "lateral") for obj in ExplorerContainer.__TABS: tabname, icon = ExplorerContainer.__TABS[obj] self.add_tab(tabname, obj, icon) obj.dockWidget.connect(self._dock_widget) obj.undockWidget.connect(self._undock_widget) obj.changeTitle.connect(self._change_tab_title) if self.count() == 0: self.hide()
def __init__(self, editor): super(ErrorsChecker, self).__init__() self._editor = editor self._path = '' self._encoding = '' self.checks = {} self.reporter = None self.checker_icon = ":img/bug" ninjaide = IDE.getInstance() ninjaide.ns_preferences_editor_errors.connect(lambda: remove_error_checker()) self.checkerCompleted.connect(self.refresh_display)
def install(self): """Install triggered by the ide.""" self.setup_ui() ninjaide = IDE.getInstance() ninjaide.place_me_on("tools_dock", self, "central") ui_tools.install_shortcuts(self, actions.ACTIONS, ninjaide) ninjaide.goingDown.connect(self.save_configuration) qsettings = IDE.ninja_settings() value = qsettings.value("tools_dock/visible", True, type=bool) self.setVisible(value) print("\ninstall")
def __init__(self, editor): super(ErrorsChecker, self).__init__() self._editor = editor self._path = '' self._encoding = '' self.checks = {} self.reporter = None self.checker_icon = ":img/bug" ninjaide = IDE.getInstance() ninjaide.ns_preferences_editor_errors.connect( lambda: remove_error_checker()) self.checkerCompleted.connect(self.refresh_display)
def _open(self, path, temp, project): if project: path = os.path.join(os.path.split(project)[0], path) self._main_container.open_file(path) elif temp: nfile = self._temp_files[temp] ninjaide = IDE.getInstance() neditable = ninjaide.get_or_create_editable(nfile=nfile) self._main_container.current_widget.set_current(neditable) else: self._main_container.open_file(path) index = self._model[path] self._max_index = max(self._max_index, index) + 1 self._model[path] = self._max_index self.hide()
def _delete_file(self, path=''): if not path: path = self.model().filePath(self.currentIndex()) val = QMessageBox.question(self, translations.TR_DELETE_FILE, translations.TR_DELETE_FOLLOWING_FILE + path, QMessageBox.Yes, QMessageBox.No) if val == QMessageBox.Yes: path = file_manager.create_path(path) main_container = ide_srv = IDE.get_service('main_container') if main_container and main_container.is_open(path): main_container.close_deleted_file(path) #FIXME: Manage the deletion signal instead of main container #fiddling here ide_srv = IDE.getInstance() current_nfile = ide_srv.get_or_create_nfile(path) current_nfile.delete()
def _close_project(self, widget): """Close the project related to the tree widget.""" index = self._projects_area.currentIndex() self.projects.remove(widget) self._projects_area.takeAt(index) self._combo_project.removeItem(index) index = self._combo_project.currentIndex() self._projects_area.setCurrentIndex(index) ninjaide = IDE.getInstance() ninjaide.filesystem.close_project(widget.project.path) widget.deleteLater() if len(self.projects) > 1: title = "%s (%s)" % ( translations.TR_TAB_PROJECTS, len(self.projects)) else: title = translations.TR_TAB_PROJECTS self.changeTitle.emit(self, title)
def _close_project(self, widget): """Close the project related to the tree widget.""" index = self._projects_area.currentIndex() self.projects.remove(widget) self._projects_area.takeAt(index) self._combo_project.removeItem(index) index = self._combo_project.currentIndex() self._projects_area.setCurrentIndex(index) ninjaide = IDE.getInstance() ninjaide.filesystem.close_project(widget.project.path) widget.deleteLater() if len(self.projects) > 1: title = "%s (%s)" % (translations.TR_TAB_PROJECTS, len(self.projects)) else: title = translations.TR_TAB_PROJECTS self.changeTitle.emit(self, title)
def _filter_tabs(self, filterOptions, index): at_start = (index == 0) if at_start: ninjaide = IDE.getInstance() opened = ninjaide.filesystem.get_files() self.tempLocations = [ locator.ResultItem( locator.FILTERS['files'], opened[f].file_name, opened[f].file_path) for f in opened] search = filterOptions[index + 1].lstrip().lower() self.tempLocations = [ x for x in self.tempLocations if x.comparison.lower().find(search) > -1] index += 2 else: del filterOptions[index + 1] del filterOptions[index] return index
def _create(self, path): """Open the item received.""" if self._create_file_operation: path = os.path.join(self._base_path, path) folder = os.path.split(path)[0] if not os.path.exists(folder): file_manager.create_folder(folder) ninjaide = IDE.getInstance() current_nfile = ninjaide.get_or_create_nfile(path) current_nfile.create() main_container = IDE.get_service('main_container') if main_container: main_container.open_file(path) else: path = os.path.join(self._base_path, path) if not os.path.exists(path): file_manager.create_folder(path) self.hide()
def __init__(self, editor): super(MigrationTo3, self).__init__() self._editor = editor self._path = '' self.dirty = False self.checks = {} if settings.IS_WINDOWS and settings.PYTHON_EXEC_CONFIGURED_BY_USER: tool_path = os.path.join(os.path.dirname(settings.PYTHON_EXEC), 'Tools', 'Scripts', '2to3.py') self._command = [settings.PYTHON_EXEC, tool_path] else: self._command = ['2to3'] self.checker_icon = None ninjaide = IDE.getInstance() ninjaide.ns_preferences_editor_showMigrationTips.connect( lambda: remove_migration_checker()) self.checkerCompleted.connect(self.refresh_display)
def locate_code(self): self._locator_db = sqlite3.connect(db_path) ide = IDE.getInstance() projects = ide.filesystem.get_projects() if not projects: return projects = list(projects.values()) for nproject in projects: if self._cancel: break current_dir = QDir(nproject.path) #Skip not readable dirs! if not current_dir.isReadable(): continue queue_folders = Queue.Queue() queue_folders.put(current_dir) files_paths[nproject.path] = list() self.__locate_code_in_project(queue_folders, nproject) self.dirty = True self.get_locations()
def find_occurrences(self, word): """Trigger the find occurrences mode with pre-search data.""" self._find_widget.pattern_line_edit.setText(word) ninjaide = IDE.getInstance() editorWidget = self._main_container.get_current_editor() nproject = ninjaide.get_project_for_file(editorWidget.file_path) if nproject is None: nproject = ninjaide.get_current_project() if nproject is None: # self._find_widget.dir_combo.clear() print("editorWidget.file_path", editorWidget.file_path) #self._find_widget.dir_combo.addItem(nproject.path) # self._find_widget.case_checkbox.setChecked(True) self._find_widget._find_in_files() print("añadido!") return print("\n\n\nnproject.path", nproject.path) self._find_widget.dir_combo.clear() self._find_widget.dir_combo.addItem(nproject.path) self._find_widget.case_checkbox.setChecked(True) self._find_widget._find_in_files()
def find_occurrences(self, word): """Trigger the find occurrences mode with pre-search data.""" self._find_widget.pattern_line_edit.setText(word) ninjaide = IDE.getInstance() editorWidget = self._main_container.get_current_editor() nproject = ninjaide.get_project_for_file(editorWidget.file_path) if nproject is None: nproject = ninjaide.get_current_project() if nproject is None: # self._find_widget.dir_combo.clear() print("editorWidget.file_path",editorWidget.file_path) #self._find_widget.dir_combo.addItem(nproject.path) # self._find_widget.case_checkbox.setChecked(True) self._find_widget._find_in_files() print("añadido!") return print("\n\n\nnproject.path", nproject.path) self._find_widget.dir_combo.clear() self._find_widget.dir_combo.addItem(nproject.path) self._find_widget.case_checkbox.setChecked(True) self._find_widget._find_in_files()
def single_undock_editor(self): new_combo = ComboEditor(Force_Free=True) new_combo.setWindowTitle("NINJA-IDE") self.add_SingleUndocked(new_combo) nEdit = self.stackedEditor.takeAt( self.stackedEditor.currentIndex()).widget() ide = IDE.getInstance() ide.unload_NEditable(nEdit) neditable = self.bar.take_editable() print("\n\nsingle_undock_editor:::", neditable, neditable.editor, nEdit, neditable.nfile) if self.stackedEditor.isEmpty(): self.allFilesClosed.emit() new_combo.add_editor(neditable) new_combo.stackedEditor.setCurrentIndex( 0) # new_combo.stackedEditor.setCurrentWidget(nEdit) new_combo.resize(500, 500) new_combo.aboutToCloseComboEditor.connect(self.single__remove_undock) new_combo.show()
def _open(self, path, temp, project): print("\n\n_open", path, "|", temp, "|", project, "|", self) if project: path = os.path.join(os.path.split(project)[0], path) self._main_container.open_file(path) elif temp: nfile = self._temp_files[temp] ninjaide = IDE.getInstance() neditable = ninjaide.get_or_create_editable(nfile=nfile) print("nfile", nfile, neditable, self._temp_files, temp) self._main_container.current_comboEditor.set_current(neditable) else: # self._main_container.open_file(path) # self._main_container.open_file_from_nEditable(self.comboParent.get_editable_fromPath(path),\ # self.comboParent.ParentalComboEditor) self.comboParent.ParentalComboEditor.set_current(\ self.comboParent.get_editable_fromPath(path) ) index = self._filePathPosition[path] self._max_index = max(self._max_index, index) + 1 self._filePathPosition[path] = self._max_index self.hide()
def install_tab(self): ide = IDE.getInstance() ide.goingDown.connect(self.close)
def open_file(self, filename='', line=-1, col=0, ignore_checkers=False): logger.debug("will try to open %s" % filename) if not filename: logger.debug("has nofilename") if settings.WORKSPACE: directory = settings.WORKSPACE else: directory = os.path.expanduser("~") editorWidget = self.get_current_editor() ninjaide = IDE.getInstance() if ninjaide: current_project = ninjaide.get_current_project() if current_project is not None: directory = current_project elif editorWidget is not None and editorWidget.file_path: directory = file_manager.get_folder( editorWidget.file_path) extensions = ';;'.join( ['{}(*{})'.format(e.upper()[1:], e) for e in settings.SUPPORTED_EXTENSIONS + ['.*', '']]) fileNames = QFileDialog.getOpenFileNames(self, self.tr("Open File"), directory, extensions)[0]#list() else: logger.debug("has filename") fileNames = [filename] if not fileNames: return print("\n\nopen_file") othersFileNames = [] image_extensions = ('bmp', 'gif', 'jpeg', 'jpg', 'png') for filename in fileNames: print("nombre", filename) if QFileInfo(filename).isDir(): othersFileNames.extend( QFileDialog.getOpenFileNames(None, "Select files", filename, "Files (*.*)")[0] ) elif file_manager.get_file_extension(filename) in image_extensions: logger.debug("will open as image") self.open_image(filename) elif file_manager.get_file_extension(filename).endswith('ui'): logger.debug("will load in ui editor") self.w = uic.loadUi(filename) self.w.show() else: logger.debug("will try to open: " + filename) self.__open_file(filename, line, col, ignore_checkers) for filename in othersFileNames: print("nombre", filename) if QFileInfo(filename).isDir(): continue elif file_manager.get_file_extension(filename) in image_extensions: logger.debug("will open as image") self.open_image(filename) elif file_manager.get_file_extension(filename).endswith('ui'): logger.debug("will load in ui editor") self.w = uic.loadUi(filename) self.w.show() else: logger.debug("will try to open: " + filename) self.__open_file(filename, line, col, ignore_checkers)
def install(self): """Install SearchWidget as a service and its shortcuts.""" self.hide() ide = IDE.getInstance() ui_tools.install_shortcuts(self, actions.ACTIONS_STATUS_SEARCH, ide)
def install_tab(self): ide = IDE.getInstance() ui_tools.install_shortcuts(self, actions.PROJECTS_TREE_ACTIONS, ide) ide.goingDown.connect(self.close)
def _open_schemes_manager(self): ninjaide = IDE.getInstance() ninjaide.show_schemes()
def update_line_col(self, line, col): """Update the line and column position.""" #self.lbl_position.setText(self._pos_text % (line, col)) IDE.getInstance().showMessageStatus(self._pos_text % (line, col))
def install_tab(self): """Install the Tab on the IDE.""" ide = IDE.getInstance() ide.goingDown.connect(self.close)
def install_tab(self): """Connect signals for goingdown""" ide = IDE.getInstance() ide.goingDown.connect(self.close)
def install(self): ide = IDE.getInstance() ui_tools.install_shortcuts(self, actions.ACTIONS_CENTRAL, ide)
def open_file(self, filename='', line=-1, col=0, ignore_checkers=False): logger.debug("will try to open %s" % filename) if not filename: logger.debug("has nofilename") if settings.WORKSPACE: directory = settings.WORKSPACE else: directory = os.path.expanduser("~") editorWidget = self.get_current_editor() ninjaide = IDE.getInstance() if ninjaide: current_project = ninjaide.get_current_project() if current_project is not None: directory = current_project elif editorWidget is not None and editorWidget.file_path: directory = file_manager.get_folder( editorWidget.file_path) extensions = ';;'.join([ '{}(*{})'.format(e.upper()[1:], e) for e in settings.SUPPORTED_EXTENSIONS + ['.*', ''] ]) fileNames = QFileDialog.getOpenFileNames(self, self.tr("Open File"), directory, extensions)[0] #list() else: logger.debug("has filename") fileNames = [filename] if not fileNames: return print("\n\nopen_file") othersFileNames = [] image_extensions = ('bmp', 'gif', 'jpeg', 'jpg', 'png') for filename in fileNames: print("nombre", filename) if QFileInfo(filename).isDir(): othersFileNames.extend( QFileDialog.getOpenFileNames(None, "Select files", filename, "Files (*.*)")[0]) elif file_manager.get_file_extension(filename) in image_extensions: logger.debug("will open as image") self.open_image(filename) elif file_manager.get_file_extension(filename).endswith('ui'): logger.debug("will load in ui editor") self.w = uic.loadUi(filename) self.w.show() else: logger.debug("will try to open: " + filename) self.__open_file(filename, line, col, ignore_checkers) for filename in othersFileNames: print("nombre", filename) if QFileInfo(filename).isDir(): continue elif file_manager.get_file_extension(filename) in image_extensions: logger.debug("will open as image") self.open_image(filename) elif file_manager.get_file_extension(filename).endswith('ui'): logger.debug("will load in ui editor") self.w = uic.loadUi(filename) self.w.show() else: logger.debug("will try to open: " + filename) self.__open_file(filename, line, col, ignore_checkers)