class TabsHandler(QFrame): def __init__(self, parent=None): super(TabsHandler, self).__init__(None, Qt.FramelessWindowHint | Qt.Popup) self._main_container = parent self.setAttribute(Qt.WA_TranslucentBackground) self.setStyleSheet("background:transparent;") # Create the QML user interface. self.view = QDeclarativeView() self.view.setResizeMode(QDeclarativeView.SizeRootObjectToView) self.view.setSource(ui_tools.get_qml_resource("TabsHandler.qml")) self._root = self.view.rootObject() vbox = QVBoxLayout(self) vbox.setContentsMargins(0, 0, 0, 0) vbox.setSpacing(0) vbox.addWidget(self.view) self._model = {} self._max_index = 0 self.connect(self._root, SIGNAL("open(QString)"), self._open) self.connect(self._root, SIGNAL("close(QString)"), self._close) self.connect(self._root, SIGNAL("hide()"), self.hide) def _open(self, path): 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 _close(self, path): ninjaide = IDE.get_service("ide") nfile = ninjaide.get_or_create_nfile(path) nfile.close() def _add_model(self): ninjaide = IDE.get_service("ide") files = ninjaide.filesystem.get_files() files_data = list(files.values()) # Update model old = set(self._model.keys()) new = set([nfile.file_path for nfile in files_data]) result = old - new for item in result: 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 = [] for nfile in files_data: if nfile.file_path not in self._model: self._model[nfile.file_path] = 0 neditable = ninjaide.get_or_create_editable(nfile.file_path) checkers = neditable.sorted_checkers checks = [] for items in checkers: checker, color, _ = items if checker.dirty: checks.append({"checker_text": checker.dirty_text, "checker_color": color}) modified = neditable.document.isModified() model.append([nfile.file_name, nfile.file_path, checks, modified]) 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[x[1]], reverse=True) self._root.set_model(model) def showEvent(self, event): self._add_model() width = max(self._main_container.width() / 3, 300) logger.debug("This is the width") logger.debug(width) height = max(self._main_container.height() / 2, 400) logger.debug("This is the height") logger.debug(height) self.view.setFixedWidth(width) self.view.setFixedHeight(height) super(TabsHandler, self).showEvent(event) self._root.show_animation() point = self._main_container.mapToGlobal(self.view.pos()) y_diff = self._main_container.combo_header_size self.move(point.x(), point.y() + y_diff) self.view.setFocus() def hideEvent(self, event): super(TabsHandler, self).hideEvent(event) self._root.clear_model() def next_item(self): if not self.isVisible(): self.show() self._root.next_item() def previous_item(self): if not self.isVisible(): self.show() self._root.previous_item() def keyPressEvent(self, event): if event.key() == Qt.Key_Escape: self.hide() elif (event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_PageDown) or event.key() == Qt.Key_Down: self._root.next_item() elif (event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_PageUp) or event.key() == Qt.Key_Up: self._root.previous_item() elif event.key() in (Qt.Key_Return, Qt.Key_Enter): self._root.open_item() super(TabsHandler, self).keyPressEvent(event)
class FilesHandler(QFrame): def __init__(self, parent=None): super(FilesHandler, self).__init__(None, Qt.FramelessWindowHint | Qt.Popup) self._main_container = parent self.setAttribute(Qt.WA_TranslucentBackground) self.setStyleSheet("background:transparent;") # Create the QML user interface. self.view = QDeclarativeView() self.view.setResizeMode(QDeclarativeView.SizeRootObjectToView) self.view.setSource(ui_tools.get_qml_resource("FilesHandler.qml")) self._root = self.view.rootObject() vbox = QVBoxLayout(self) vbox.setContentsMargins(0, 0, 0, 0) vbox.setSpacing(0) vbox.addWidget(self.view) self._model = {} self._temp_files = {} self._max_index = 0 self.connect(self._root, SIGNAL("open(QString, QString, QString)"), self._open) self.connect(self._root, SIGNAL("close(QString, QString)"), self._close) self.connect(self._root, SIGNAL("hide()"), self.hide) self.connect(self._root, SIGNAL("fuzzySearch(QString)"), self._fuzzy_search) 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.get_service("ide") 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 _close(self, path, temp): if temp: nfile = self._temp_files.get(temp, None) else: ninjaide = IDE.get_service("ide") nfile = ninjaide.get_or_create_nfile(path) if nfile is not None: nfile.close() def _fuzzy_search(self, search): search = '.+'.join(re.escape(search).split('\\ ')) pattern = re.compile(search, re.IGNORECASE) model = [] for project_path in locator.files_paths: files_in_project = locator.files_paths[project_path] base_project = os.path.basename(project_path) for file_path in files_in_project: file_path = os.path.join( base_project, os.path.relpath(file_path, project_path)) if pattern.search(file_path): model.append( [os.path.basename(file_path), file_path, project_path]) self._root.set_fuzzy_model(model) def _add_model(self): ninjaide = IDE.get_service("ide") files = ninjaide.opened_files # Update model old = set(self._model.keys()) new = set([nfile.file_path for nfile in files]) result = old - new for item in result: 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 = [] 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: checks.append({ "checker_text": checker.dirty_text, "checker_color": color }) modified = neditable.document.isModified() 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 showEvent(self, event): self._add_model() widget = self._main_container.get_current_editor() if widget is None: widget = self._main_container if self._main_container.splitter.count() < 2: width = max(widget.width() / 2, 500) height = max(widget.height() / 2, 400) else: width = widget.width() height = widget.height() self.view.setFixedWidth(width) self.view.setFixedHeight(height) super(FilesHandler, self).showEvent(event) self._root.show_animation() point = widget.mapToGlobal(self.view.pos()) self.move(point.x(), point.y()) self.view.setFocus() self._root.activateInput() def hideEvent(self, event): super(FilesHandler, self).hideEvent(event) self._temp_files = {} self._root.clear_model() def next_item(self): if not self.isVisible(): self.show() self._root.next_item() def previous_item(self): if not self.isVisible(): self.show() self._root.previous_item() def keyPressEvent(self, event): if event.key() == Qt.Key_Escape: self.hide() elif (event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_PageDown) or event.key() == Qt.Key_Down: self._root.next_item() elif (event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_PageUp) or event.key() == Qt.Key_Up: self._root.previous_item() elif event.key() in (Qt.Key_Return, Qt.Key_Enter): self._root.open_item() super(FilesHandler, self).keyPressEvent(event)
class TabsHandler(QFrame): def __init__(self, parent=None): super(TabsHandler, self).__init__(None, Qt.FramelessWindowHint | Qt.Popup) self._main_container = parent self.setAttribute(Qt.WA_TranslucentBackground) self.setStyleSheet("background:transparent;") # Create the QML user interface. self.view = QDeclarativeView() self.view.setResizeMode(QDeclarativeView.SizeRootObjectToView) self.view.setSource(ui_tools.get_qml_resource("TabsHandler.qml")) self._root = self.view.rootObject() vbox = QVBoxLayout(self) vbox.setContentsMargins(0, 0, 0, 0) vbox.setSpacing(0) vbox.addWidget(self.view) self._model = {} self._max_index = 0 self.connect(self._root, SIGNAL("open(QString)"), self._open) self.connect(self._root, SIGNAL("close(QString)"), self._close) def _open(self, path): 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 _close(self, path): ninjaide = IDE.get_service("ide") nfile = ninjaide.get_or_create_nfile(path) nfile.close() def _add_model(self): ninjaide = IDE.get_service("ide") files = ninjaide.filesystem.get_files() files_data = list(files.values()) # Update model old = set(self._model.keys()) new = set([nfile.file_path for nfile in files_data]) result = old - new for item in result: 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 = [] for nfile in files_data: if nfile.file_path not in self._model: self._model[nfile.file_path] = 0 neditable = ninjaide.get_or_create_editable(nfile.file_path) checkers = neditable.sorted_checkers checks = [] for items in checkers: checker, color, _ = items if checker.dirty: checks.append( {"checker_text": checker.dirty_text, "checker_color": color}) modified = neditable.document.isModified() model.append([nfile.file_name, nfile.file_path, checks, modified]) 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[x[1]], reverse=True) self._root.set_model(model) def showEvent(self, event): self._add_model() width = max(self._main_container.width() / 3, 300) height = max(self._main_container.height() / 2, 400) self.view.setFixedWidth(width) self.view.setFixedHeight(height) super(TabsHandler, self).showEvent(event) self._root.show_animation() point = self._main_container.mapToGlobal(self.view.pos()) y_diff = self._main_container.combo_header_size self.move(point.x(), point.y() + y_diff) self.view.setFocus() def hideEvent(self, event): super(TabsHandler, self).hideEvent(event) self._root.clear_model() def next_item(self): if not self.isVisible(): self.show() self._root.next_item() def previous_item(self): if not self.isVisible(): self.show() self._root.previous_item() def keyPressEvent(self, event): if event.key() == Qt.Key_Escape: self.hide() elif (event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_PageDown) or event.key() == Qt.Key_Down: self._root.next_item() elif (event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_PageUp) or event.key() == Qt.Key_Up: self._root.previous_item() elif event.key() in (Qt.Key_Return, Qt.Key_Enter): self._root.open_item() super(TabsHandler, self).keyPressEvent(event)
class FilesHandler(QFrame): def __init__(self, parent=None): super(FilesHandler, self).__init__( None, Qt.FramelessWindowHint | Qt.Popup) self._main_container = parent self.setAttribute(Qt.WA_TranslucentBackground) self.setStyleSheet("background:transparent;") # Create the QML user interface. self.view = QDeclarativeView() self.view.setResizeMode(QDeclarativeView.SizeRootObjectToView) self.view.setSource(ui_tools.get_qml_resource("FilesHandler.qml")) self._root = self.view.rootObject() vbox = QVBoxLayout(self) vbox.setContentsMargins(0, 0, 0, 0) vbox.setSpacing(0) vbox.addWidget(self.view) self._model = {} self._temp_files = {} self._max_index = 0 self.connect(self._root, SIGNAL("open(QString, QString, QString)"), self._open) self.connect(self._root, SIGNAL("close(QString, QString)"), self._close) self.connect(self._root, SIGNAL("hide()"), self.hide) self.connect(self._root, SIGNAL("fuzzySearch(QString)"), self._fuzzy_search) 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.get_service("ide") 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 _close(self, path, temp): if temp: nfile = self._temp_files.get(temp, None) else: ninjaide = IDE.get_service("ide") nfile = ninjaide.get_or_create_nfile(path) if nfile is not None: nfile.close() def _fuzzy_search(self, search): search = '.+'.join(re.escape(search).split('\\ ')) pattern = re.compile(search, re.IGNORECASE) model = [] for project_path in locator.files_paths: files_in_project = locator.files_paths[project_path] base_project = os.path.basename(project_path) for file_path in files_in_project: file_path = os.path.join( base_project, os.path.relpath(file_path, project_path)) if pattern.search(file_path): model.append([os.path.basename(file_path), file_path, project_path]) self._root.set_fuzzy_model(model) def _add_model(self): ninjaide = IDE.get_service("ide") files = ninjaide.opened_files # Update model old = set(self._model.keys()) new = set([nfile.file_path for nfile in files]) result = old - new for item in result: 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 = [] 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: checks.append( {"checker_text": checker.dirty_text, "checker_color": color}) modified = neditable.document.isModified() 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 showEvent(self, event): self._add_model() widget = self._main_container.get_current_editor() if widget is None: widget = self._main_container if self._main_container.splitter.count() < 2: width = max(widget.width() / 2, 500) height = max(widget.height() / 2, 400) else: width = widget.width() height = widget.height() self.view.setFixedWidth(width) self.view.setFixedHeight(height) super(FilesHandler, self).showEvent(event) self._root.show_animation() point = widget.mapToGlobal(self.view.pos()) self.move(point.x(), point.y()) self.view.setFocus() self._root.activateInput() def hideEvent(self, event): super(FilesHandler, self).hideEvent(event) self._temp_files = {} self._root.clear_model() def next_item(self): if not self.isVisible(): self.show() self._root.next_item() def previous_item(self): if not self.isVisible(): self.show() self._root.previous_item() def keyPressEvent(self, event): if event.key() == Qt.Key_Escape: self.hide() elif (event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_PageDown) or event.key() == Qt.Key_Down: self._root.next_item() elif (event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_PageUp) or event.key() == Qt.Key_Up: self._root.previous_item() elif event.key() in (Qt.Key_Return, Qt.Key_Enter): self._root.open_item() super(FilesHandler, self).keyPressEvent(event)
class AddFileFolderWidget(QDialog): """LocatorWidget class with the Logic for the QML UI""" def __init__(self, parent=None): super(AddFileFolderWidget, self).__init__( parent, Qt.Dialog | Qt.FramelessWindowHint) self._main_container = parent self.setModal(True) self.setAttribute(Qt.WA_TranslucentBackground) self.setStyleSheet("background:transparent;") self.setFixedHeight(70) self.setFixedWidth(650) # Create the QML user interface. self.view = QDeclarativeView() self.view.setResizeMode(QDeclarativeView.SizeRootObjectToView) self.view.setSource(ui_tools.get_qml_resource("AddFileFolder.qml")) self._root = self.view.rootObject() vbox = QVBoxLayout(self) vbox.setContentsMargins(0, 0, 0, 0) vbox.setSpacing(0) vbox.addWidget(self.view) self._base_path = "" self._create_file_operation = True self.connect(self._root, SIGNAL("create(QString)"), self._create) def create_file(self, base_path, project_path): self._create_file_operation = True self._base_path = project_path base_path = os.path.relpath(base_path, project_path) self._root.setDialogType(self._create_file_operation) self._root.setBasePath(base_path + os.path.sep) self.show() def create_folder(self, base_path, project_path): self._create_file_operation = False self._base_path = project_path base_path = os.path.relpath(base_path, project_path) self._root.setDialogType(self._create_file_operation) self._root.setBasePath(base_path + os.path.sep) self.show() def showEvent(self, event): """Method takes an event to show the Notification""" super(AddFileFolderWidget, self).showEvent(event) ninjaide = IDE.get_service("ide") point = self._main_container.mapToGlobal(self.view.pos()) x = point.x() + (ninjaide.width() / 2) - (self.width() / 2) self.move(x, point.y()) self.view.setFocus() self._root.activateInput() 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.get_service('ide') 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 hideEvent(self, event): super(AddFileFolderWidget, self).hideEvent(event) self._root.cleanText()
class AddFileFolderWidget(QDialog): """LocatorWidget class with the Logic for the QML UI""" def __init__(self, parent=None): super(AddFileFolderWidget, self).__init__(parent, Qt.Dialog | Qt.FramelessWindowHint) self._main_container = parent self.setModal(True) self.setAttribute(Qt.WA_TranslucentBackground) self.setStyleSheet("background:transparent;") self.setFixedHeight(70) self.setFixedWidth(650) # Create the QML user interface. self.view = QDeclarativeView() self.view.setResizeMode(QDeclarativeView.SizeRootObjectToView) self.view.setSource(ui_tools.get_qml_resource("AddFileFolder.qml")) self._root = self.view.rootObject() vbox = QVBoxLayout(self) vbox.setContentsMargins(0, 0, 0, 0) vbox.setSpacing(0) vbox.addWidget(self.view) self._base_path = "" self._create_file_operation = True self.connect(self._root, SIGNAL("create(QString)"), self._create) def create_file(self, base_path, project_path): self._create_file_operation = True self._base_path = project_path base_path = os.path.relpath(base_path, project_path) self._root.setDialogType(self._create_file_operation) self._root.setBasePath(base_path + os.path.sep) self.show() def create_folder(self, base_path, project_path): self._create_file_operation = False self._base_path = project_path base_path = os.path.relpath(base_path, project_path) self._root.setDialogType(self._create_file_operation) self._root.setBasePath(base_path + os.path.sep) self.show() def showEvent(self, event): """Method takes an event to show the Notification""" super(AddFileFolderWidget, self).showEvent(event) ninjaide = IDE.get_service("ide") point = self._main_container.mapToGlobal(self.view.pos()) x = point.x() + (ninjaide.width() / 2) - (self.width() / 2) self.move(x, point.y()) self.view.setFocus() self._root.activateInput() 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.get_service('ide') 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 hideEvent(self, event): super(AddFileFolderWidget, self).hideEvent(event) self._root.cleanText()