def multi_seed_dialog(self, n): vbox = QVBoxLayout() scroll = QScrollArea() scroll.setEnabled(True) scroll.setWidgetResizable(True) vbox.addWidget(scroll) w = QWidget() scroll.setWidget(w) innerVbox = QVBoxLayout() w.setLayout(innerVbox) vbox1, seed_e1 = seed_dialog.enter_seed_box(MSG_ENTER_SEED_OR_MPK, self, 'hot') innerVbox.addLayout(vbox1) entries = [seed_e1] for i in range(n): vbox2, seed_e2 = seed_dialog.enter_seed_box(MSG_ENTER_SEED_OR_MPK, self, 'cold') innerVbox.addLayout(vbox2) entries.append(seed_e2) vbox.addStretch(1) button = OkButton(self, _('Next')) vbox.addLayout(Buttons(CancelButton(self), button)) button.setEnabled(False) f = lambda: button.setEnabled( map(lambda e: self.is_any( self.get_seed_text(e)), entries) == [True] * len(entries)) for e in entries: e.textChanged.connect(f) self.set_layout(vbox) if not self.exec_(): return return map(lambda e: self.get_seed_text(e), entries)
def multi_mpk_dialog(self, xpub_hot, n): vbox = QVBoxLayout() scroll = QScrollArea() scroll.setEnabled(True) scroll.setWidgetResizable(True) vbox.addWidget(scroll) w = QWidget() scroll.setWidget(w) innerVbox = QVBoxLayout() w.setLayout(innerVbox) vbox0 = seed_dialog.show_seed_box(MSG_SHOW_MPK, xpub_hot, 'hot') innerVbox.addLayout(vbox0) entries = [] for i in range(n): msg = _("Please enter the master public key of cosigner") + ' %d' % (i + 1) vbox2, seed_e2 = seed_dialog.enter_seed_box(msg, self, 'cold') innerVbox.addLayout(vbox2) entries.append(seed_e2) vbox.addStretch(1) button = OkButton(self, _('Next')) vbox.addLayout(Buttons(CancelButton(self), button)) button.setEnabled(False) f = lambda: button.setEnabled( map(lambda e: Wallet.is_xpub( self.get_seed_text(e)), entries) == [True] * len(entries)) for e in entries: e.textChanged.connect(f) self.set_layout(vbox) if not self.exec_(): return return map(lambda e: self.get_seed_text(e), entries)
def scrollable_wrapper(widget): scrollable = QScrollArea() scrollable.setWidget(widget) scrollable.setWidgetResizable(True) scrollable.setEnabled(True) return scrollable
class ProjectTreeColumn(QWidget): def __init__(self, *args, **kwargs): super(ProjectTreeColumn, self).__init__(*args, **kwargs) #self._widget = QWidget() self._layout = QVBoxLayout() self._layout.setSizeConstraint(QVBoxLayout.SetDefaultConstraint) self._layout.setContentsMargins(0, 0, 0, 0) self._layout.setSpacing(0) self.setLayout(self._layout) self._vbox = QVBoxLayout() self._vbox.setContentsMargins(0, 0, 0, 0) self._vbox.setSpacing(0) self._vbox.setSizeConstraint(QVBoxLayout.SetDefaultConstraint) self._buttons = [] self._projects_area = QWidget() logger.debug("This is the projects area") logger.debug(self._projects_area) self._projects_area.setLayout(self._vbox) self._scroll_area = QScrollArea() self.layout().addWidget(self._scroll_area) self._scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self._scroll_area.setWidgetResizable(True) self._scroll_area.setEnabled(True) self._scroll_area.setWidget(self._projects_area) self._scroll_area.setGeometry(self.geometry()) #self._projects_area.setGeometry(self.geometry()) self._vbox.setGeometry(self.geometry()) self.projects = [] self._active_project = None #for each_test in range(50): # button = QPushButton('Test%d' % each_test) # self._buttons.append(button) # self._projects_area.layout().addWidget(button) connections = ( {'target': 'main_container', 'signal_name': 'addToProject(QString)', 'slot': self._add_file_to_project}, ) IDE.register_service('projects_explorer', self) IDE.register_signals('projects_explorer', connections) ExplorerContainer.register_tab(translations.TR_TAB_PROJECTS, self) #TODO: check this: #self.connect(ide, SIGNAL("goingDown()"), #self.tree_projects.shutdown) #self.connect(self.tree_projects, #SIGNAL("addProjectToConsole(QString)"), #self._add_project_to_console) #self.connect(self.tree_projects, #SIGNAL("removeProjectFromConsole(QString)"), #self._remove_project_from_console) #def close_project_signal(): #self.emit(SIGNAL("updateLocator()")) #def close_files_related_to_closed_project(project): #if project: #self.emit(SIGNAL("projectClosed(QString)"), project) #self.connect(self.tree_projects, SIGNAL("closeProject(QString)"), #close_project_signal) #self.connect(self.tree_projects, SIGNAL("refreshProject()"), #close_project_signal) #self.connect(self.tree_projects, #SIGNAL("closeFilesFromProjectClosed(QString)"), #close_files_related_to_closed_project) def install_tab(self): ide = IDE.get_service('ide') ui_tools.install_shortcuts(self, actions.PROJECTS_TREE_ACTIONS, ide) def open_project_folder(self): if settings.WORKSPACE: directory = settings.WORKSPACE else: directory = os.path.expanduser("~") folderName = QFileDialog.getExistingDirectory(self, self.tr("Open Project Directory"), directory) logger.debug("Choosing Foldername") if folderName: logger.debug("Opening %s" % folderName) ninjaide = IDE.get_service("ide") project = NProject(folderName) qfsm = ninjaide.filesystem.open_project(project) if qfsm: self.add_project(project) def _add_file_to_project(self, path): """Add the file for 'path' in the project the user choose here.""" if self._active_project: pathProject = [self._active_project.project] addToProject = add_to_project.AddToProject(pathProject, self) addToProject.exec_() if not addToProject.pathSelected: return main_container = IDE.get_service('main_container') if not main_container: return editorWidget = main_container.get_current_editor() if not editorWidget.file_path: name = QInputDialog.getText(None, self.tr("Add File To Project"), self.tr("File Name:"))[0] if not name: QMessageBox.information(self, self.tr("Invalid Name"), self.tr("The file name is empty, please enter a name")) return else: name = file_manager.get_basename(editorWidget.file_path) path = file_manager.create_path(addToProject.pathSelected, name) try: #FIXME path = file_manager.store_file_content( path, editorWidget.get_text(), newFile=True) editorWidget.nfile = path self.emit(SIGNAL("changeWindowTitle(QString)"), path) name = file_manager.get_basename(path) main_container.actualTab.setTabText( main_container.actualTab.currentIndex(), name) editorWidget._file_saved() 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)) else: pass # Message about no project def add_project(self, project): if project not in self.projects: ptree = TreeProjectsWidget(project) self.connect(ptree, SIGNAL("setActiveProject(PyQt_PyObject)"), self._set_active_project) self.connect(ptree, SIGNAL("closeProject(PyQt_PyObject)"), self._close_project) pmodel = project.model ptree.setModel(pmodel) ptree.header().title = project.name pindex = pmodel.index(pmodel.rootPath()) ptree.setRootIndex(pindex) #self._widget.layout().addWidget(scrollable_wrapper(ptree)) self._projects_area.layout().addWidget(ptree) if self._active_project is None: ptree.set_default_project() self.projects.append(ptree) ptree.setGeometry(self.geometry()) def _close_project(self, widget): """Close the project related to the tree widget.""" self.projects.remove(widget) if self._active_project == widget and len(self.projects) > 0: self.projects[0].set_default_project() self._widget.layout().removeWidget(widget) widget.deleteLater() def _set_active_project(self, tree_proj): if self._active_project is not None: self._active_project.set_default_project(False) self._active_project = tree_proj def close_opened_projects(self): for project in reversed(self.projects): self._close_project(project) def save_project(self): """Save all the opened files that belongs to the actual project.""" path = self._active_project.project.path main_container = IDE.get_service('main_container') if path and main_container: main_container.save_project(path) def create_new_project(self): if not self.tree_projects: QMessageBox.information(self, self.tr("Projects Disabled"), self.tr("Project support has been disabled from Preferences")) return wizard = wizard_new_project.WizardNewProject(self) wizard.show()
class ProjectTreeColumn(QDialog): def __init__(self, parent=None): super(ProjectTreeColumn, self).__init__(parent, Qt.WindowStaysOnTopHint) self._layout = QVBoxLayout() self._layout.setSizeConstraint(QVBoxLayout.SetDefaultConstraint) self._layout.setContentsMargins(0, 0, 0, 0) self._layout.setSpacing(0) self.setLayout(self._layout) self._vbox = QVBoxLayout() self._vbox.setContentsMargins(0, 0, 0, 0) self._vbox.setSpacing(0) self._vbox.setSizeConstraint(QVBoxLayout.SetDefaultConstraint) self._buttons = [] self._projects_area = QWidget() logger.debug("This is the projects area") logger.debug(self._projects_area) self._projects_area.setLayout(self._vbox) self._scroll_area = QScrollArea() self.layout().addWidget(self._scroll_area) self._scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self._scroll_area.setWidgetResizable(True) self._scroll_area.setEnabled(True) self._scroll_area.setWidget(self._projects_area) self._scroll_area.setGeometry(self.geometry()) self._vbox.setGeometry(self.geometry()) self.projects = [] self._active_project = None connections = ( {'target': 'main_container', 'signal_name': 'addToProject(QString)', 'slot': self._add_file_to_project}, {'target': 'main_container', 'signal_name': 'showFileInExplorer(QString)', 'slot': self._show_file_in_explorer}, ) IDE.register_service('projects_explorer', self) IDE.register_signals('projects_explorer', connections) ExplorerContainer.register_tab(translations.TR_TAB_PROJECTS, self) #FIXME: Should have a ninja settings object that stores tree state #FIXME: Or bettter, application data object #TODO: check this: #self.connect(ide, SIGNAL("goingDown()"), #self.tree_projects.shutdown) #def close_project_signal(): #self.emit(SIGNAL("updateLocator()")) def install_tab(self): ide = IDE.get_service('ide') ui_tools.install_shortcuts(self, actions.PROJECTS_TREE_ACTIONS, ide) self.connect(ide, SIGNAL("goingDown()"), self.close) def load_session_projects(self, projects): for project in projects: if os.path.exists(project): self._open_project_folder(project) def open_project_folder(self, folderName=None): if settings.WORKSPACE: directory = settings.WORKSPACE else: directory = os.path.expanduser("~") if folderName is None: folderName = QFileDialog.getExistingDirectory( self, translations.TR_OPEN_PROJECT_DIRECTORY, directory) logger.debug("Choosing Foldername") if folderName: logger.debug("Opening %s" % folderName) self._open_project_folder(folderName) def _open_project_folder(self, folderName): ninjaide = IDE.get_service("ide") project = NProject(folderName) qfsm = ninjaide.filesystem.open_project(project) if qfsm: self.add_project(project) self.emit(SIGNAL("updateLocator()")) self.save_recent_projects(folderName) main_container = IDE.get_service('main_container') if main_container: main_container.show_editor_area() def _add_file_to_project(self, path): """Add the file for 'path' in the project the user choose here.""" if self._active_project: pathProject = [self._active_project.project] addToProject = add_to_project.AddToProject(pathProject, self) addToProject.exec_() if not addToProject.pathSelected: return main_container = IDE.get_service('main_container') if not main_container: return editorWidget = main_container.get_current_editor() if not editorWidget.file_path: name = QInputDialog.getText(None, translations.TR_ADD_FILE_TO_PROJECT, translations.TR_FILENAME + ": ")[0] if not name: QMessageBox.information( self, translations.TR_INVALID_FILENAME, translations.TR_INVALID_FILENAME_ENTER_A_FILENAME) return else: name = file_manager.get_basename(editorWidget.file_path) new_path = file_manager.create_path(addToProject.pathSelected, name) ide_srv = IDE.get_service("ide") old_file = ide_srv.get_or_create_nfile(path) new_file = old_file.save(editorWidget.get_text(), new_path) #FIXME: Make this file replace the original in the open tab else: pass # Message about no project def _show_file_in_explorer(self, path): '''Iterate through the list of available projects and show the current file in the explorer view for the first project that contains it (i.e. if the same file is included in multiple open projects, the path will be expanded for the first project only). Note: This slot is connected to the main container's "showFileInExplorer(QString)" signal.''' for project in self.projects: index = project.model().index(path) if index.isValid(): # Show the explorer if it is currently hidden central = IDE.get_service('central_container') if central and not central.is_lateral_panel_visible(): central.change_lateral_visibility() # This highlights the index in the tree for us project.setCurrentIndex(index) # Loop through the parents to expand the tree # all the way up to the selected index. while index.isValid(): project.expand(index) index = index.parent() break @property def children(self): return self._projects_area.layout().count() def add_project(self, project): if project not in self.projects: ptree = TreeProjectsWidget(project) ptree.setParent(self) self.connect(ptree, SIGNAL("setActiveProject(PyQt_PyObject)"), self._set_active_project) self.connect(ptree, SIGNAL("closeProject(PyQt_PyObject)"), self._close_project) pmodel = project.model ptree.setModel(pmodel) ptree.header().title = project.name ptree.header().path = project.path pindex = pmodel.index(pmodel.rootPath()) ptree.setRootIndex(pindex) #self._widget.layout().addWidget(scrollable_wrapper(ptree)) self._projects_area.layout().addWidget(ptree) if self._active_project is None: ptree.set_default_project() self.projects.append(ptree) ptree.setGeometry(self.geometry()) def _close_project(self, widget): """Close the project related to the tree widget.""" self.projects.remove(widget) if self._active_project == widget and len(self.projects) > 0: self.projects[0].set_default_project() self._layout.removeWidget(widget) ninjaide = IDE.get_service('ide') ninjaide.filesystem.close_project(widget.project.path) widget.deleteLater() def _set_active_project(self, tree_proj): if self._active_project is not None: self._active_project.set_default_project(False) self._active_project = tree_proj def close_opened_projects(self): for project in reversed(self.projects): self._close_project(project) def save_project(self): """Save all the opened files that belongs to the actual project.""" if self._active_project: path = self._active_project.project.path main_container = IDE.get_service('main_container') if path and main_container: main_container.save_project(path) def create_new_project(self): wizard = new_project_manager.NewProjectManager(self) wizard.show() @property def current_project(self): if self._active_project: return self._active_project.project @property def current_tree(self): return self._active_project def save_recent_projects(self, folder): settings = IDE.data_settings() recent_project_list = settings.value('recentProjects', {}) #if already exist on the list update the date time projectProperties = json_manager.read_ninja_project(folder) name = projectProperties.get('name', '') description = projectProperties.get('description', '') if name == '': name = file_manager.get_basename(folder) if description == '': description = translations.TR_NO_DESCRIPTION if folder in recent_project_list: properties = recent_project_list[folder] properties["lastopen"] = QDateTime.currentDateTime() properties["name"] = name properties["description"] = description recent_project_list[folder] = properties else: recent_project_list[folder] = { "name": name, "description": description, "isFavorite": False, "lastopen": QDateTime.currentDateTime()} #if the length of the project list it's high that 10 then delete #the most old #TODO: add the length of available projects to setting if len(recent_project_list) > 10: del recent_project_list[self.find_most_old_open( recent_project_list)] settings.setValue('recentProjects', recent_project_list) def find_most_old_open(self, recent_project_list): listFounder = [] for recent_project_path, content in list(recent_project_list.items()): listFounder.append((recent_project_path, int( content["lastopen"].toString("yyyyMMddHHmmzzz")))) listFounder = sorted(listFounder, key=lambda date: listFounder[1], reverse=True) # sort by date last used return listFounder[0][0] def reject(self): if self.parent() is None: self.emit(SIGNAL("dockWidget(PyQt_PyObject)"), self) def closeEvent(self, event): self.emit(SIGNAL("dockWidget(PyQt_PyObject)"), self) event.ignore()
def scrollable_wrapper(widget): scrollable = QScrollArea() scrollable.setWidget(widget) scrollable.setWidgetResizable(True) scrollable.setEnabled(True) return scrollable
class ProjectTreeColumn(QWidget): def __init__(self, *args, **kwargs): super(ProjectTreeColumn, self).__init__(*args, **kwargs) self._layout = QVBoxLayout() self._layout.setSizeConstraint(QVBoxLayout.SetDefaultConstraint) self._layout.setContentsMargins(0, 0, 0, 0) self._layout.setSpacing(0) self.setLayout(self._layout) self._vbox = QVBoxLayout() self._vbox.setContentsMargins(0, 0, 0, 0) self._vbox.setSpacing(0) self._vbox.setSizeConstraint(QVBoxLayout.SetDefaultConstraint) self._buttons = [] self._projects_area = QWidget() logger.debug("This is the projects area") logger.debug(self._projects_area) self._projects_area.setLayout(self._vbox) self._scroll_area = QScrollArea() self.layout().addWidget(self._scroll_area) self._scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self._scroll_area.setWidgetResizable(True) self._scroll_area.setEnabled(True) self._scroll_area.setWidget(self._projects_area) self._scroll_area.setGeometry(self.geometry()) self._vbox.setGeometry(self.geometry()) self.projects = [] self._active_project = None connections = ({ 'target': 'main_container', 'signal_name': 'addToProject(QString)', 'slot': self._add_file_to_project }, ) IDE.register_service('projects_explorer', self) IDE.register_signals('projects_explorer', connections) ExplorerContainer.register_tab(translations.TR_TAB_PROJECTS, self) #FIXME: Should have a ninja settings object that stores tree state #FIXME: Or bettter, application data object #TODO: check this: #self.connect(ide, SIGNAL("goingDown()"), #self.tree_projects.shutdown) #self.connect(self.tree_projects, #SIGNAL("addProjectToConsole(QString)"), #self._add_project_to_console) #self.connect(self.tree_projects, #SIGNAL("removeProjectFromConsole(QString)"), #self._remove_project_from_console) #def close_project_signal(): #self.emit(SIGNAL("updateLocator()")) #def close_files_related_to_closed_project(project): #if project: #self.emit(SIGNAL("projectClosed(QString)"), project) #self.connect(self.tree_projects, SIGNAL("closeProject(QString)"), #close_project_signal) #self.connect(self.tree_projects, SIGNAL("refreshProject()"), #close_project_signal) #self.connect(self.tree_projects, #SIGNAL("closeFilesFromProjectClosed(QString)"), #close_files_related_to_closed_project) def install_tab(self): ide = IDE.get_service('ide') ui_tools.install_shortcuts(self, actions.PROJECTS_TREE_ACTIONS, ide) def load_session_projects(self, projects): for project in projects: self._open_project_folder(project) def open_project_folder(self): if settings.WORKSPACE: directory = settings.WORKSPACE else: directory = os.path.expanduser("~") folderName = QFileDialog.getExistingDirectory( self, self.tr("Open Project Directory"), directory) logger.debug("Choosing Foldername") if folderName: logger.debug("Opening %s" % folderName) self._open_project_folder(folderName) def _open_project_folder(self, folderName): ninjaide = IDE.get_service("ide") project = NProject(folderName) qfsm = ninjaide.filesystem.open_project(project) if qfsm: self.add_project(project) self.emit(SIGNAL("updateLocator()")) def _add_file_to_project(self, path): """Add the file for 'path' in the project the user choose here.""" if self._active_project: pathProject = [self._active_project.project] addToProject = add_to_project.AddToProject(pathProject, self) addToProject.exec_() if not addToProject.pathSelected: return main_container = IDE.get_service('main_container') if not main_container: return editorWidget = main_container.get_current_editor() if not editorWidget.file_path: name = QInputDialog.getText(None, self.tr("Add File To Project"), self.tr("File Name:"))[0] if not name: QMessageBox.information( self, self.tr("Invalid Name"), self.tr("The file name is empty, please enter a name")) return else: name = file_manager.get_basename(editorWidget.file_path) new_path = file_manager.create_path(addToProject.pathSelected, name) ide_srv = IDE.get_service("ide") old_file, ide_srv.get_or_create_nfile(path) new_file = old_file.save(editorWidget.get_text(), path) #FIXME: Make this file replace the original in the open tab else: pass # Message about no project def add_project(self, project): if project not in self.projects: ptree = TreeProjectsWidget(project) self.connect(ptree, SIGNAL("setActiveProject(PyQt_PyObject)"), self._set_active_project) self.connect(ptree, SIGNAL("closeProject(PyQt_PyObject)"), self._close_project) pmodel = project.model ptree.setModel(pmodel) ptree.header().title = project.name ptree.header().path = project.path pindex = pmodel.index(pmodel.rootPath()) ptree.setRootIndex(pindex) #self._widget.layout().addWidget(scrollable_wrapper(ptree)) self._projects_area.layout().addWidget(ptree) if self._active_project is None: ptree.set_default_project() self.projects.append(ptree) ptree.setGeometry(self.geometry()) def _close_project(self, widget): """Close the project related to the tree widget.""" self.projects.remove(widget) if self._active_project == widget and len(self.projects) > 0: self.projects[0].set_default_project() self._layout.removeWidget(widget) ninjaide = IDE.get_service('ide') ninjaide.filesystem.close_project(widget.project.path) widget.deleteLater() def _set_active_project(self, tree_proj): if self._active_project is not None: self._active_project.set_default_project(False) self._active_project = tree_proj def close_opened_projects(self): for project in reversed(self.projects): self._close_project(project) def save_project(self): """Save all the opened files that belongs to the actual project.""" if self._active_project: path = self._active_project.project.path main_container = IDE.get_service('main_container') if path and main_container: main_container.save_project(path) def create_new_project(self): if not self.tree_projects: QMessageBox.information( self, self.tr("Projects Disabled"), self.tr("Project support has been disabled from Preferences")) return wizard = wizard_new_project.WizardNewProject(self) wizard.show() @property def current_project(self): if self._active_project: return self._active_project.project @property def current_tree(self): return self._active_project
class ProjectTreeColumn(QDialog): def __init__(self, parent=None): super(ProjectTreeColumn, self).__init__(parent, Qt.WindowStaysOnTopHint) self._layout = QVBoxLayout() self._layout.setSizeConstraint(QVBoxLayout.SetDefaultConstraint) self._layout.setContentsMargins(0, 0, 0, 0) self._layout.setSpacing(0) self.setLayout(self._layout) self._vbox = QVBoxLayout() self._vbox.setContentsMargins(0, 0, 0, 0) self._vbox.setSpacing(0) self._vbox.setSizeConstraint(QVBoxLayout.SetDefaultConstraint) self._buttons = [] self._projects_area = QWidget() logger.debug("This is the projects area") logger.debug(self._projects_area) self._projects_area.setLayout(self._vbox) self._scroll_area = QScrollArea() self.layout().addWidget(self._scroll_area) self._scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self._scroll_area.setWidgetResizable(True) self._scroll_area.setEnabled(True) self._scroll_area.setWidget(self._projects_area) self._scroll_area.setGeometry(self.geometry()) self._vbox.setGeometry(self.geometry()) self.projects = [] self._active_project = None connections = ({ 'target': 'main_container', 'signal_name': 'addToProject(QString)', 'slot': self._add_file_to_project }, ) IDE.register_service('projects_explorer', self) IDE.register_signals('projects_explorer', connections) ExplorerContainer.register_tab(translations.TR_TAB_PROJECTS, self) #FIXME: Should have a ninja settings object that stores tree state #FIXME: Or bettter, application data object #TODO: check this: #self.connect(ide, SIGNAL("goingDown()"), #self.tree_projects.shutdown) #def close_project_signal(): #self.emit(SIGNAL("updateLocator()")) def install_tab(self): ide = IDE.get_service('ide') ui_tools.install_shortcuts(self, actions.PROJECTS_TREE_ACTIONS, ide) self.connect(ide, SIGNAL("goingDown()"), self.close) def load_session_projects(self, projects): for project in projects: self._open_project_folder(project) def open_project_folder(self, folderName=None): if settings.WORKSPACE: directory = settings.WORKSPACE else: directory = os.path.expanduser("~") if folderName is None: folderName = QFileDialog.getExistingDirectory( self, self.tr("Open Project Directory"), directory) logger.debug("Choosing Foldername") if folderName: logger.debug("Opening %s" % folderName) self._open_project_folder(folderName) def _open_project_folder(self, folderName): ninjaide = IDE.get_service("ide") project = NProject(folderName) qfsm = ninjaide.filesystem.open_project(project) if qfsm: self.add_project(project) self.emit(SIGNAL("updateLocator()")) self.save_recent_projects(folderName) main_container = IDE.get_service('main_container') if main_container: main_container.show_editor_area() def _add_file_to_project(self, path): """Add the file for 'path' in the project the user choose here.""" if self._active_project: pathProject = [self._active_project.project] addToProject = add_to_project.AddToProject(pathProject, self) addToProject.exec_() if not addToProject.pathSelected: return main_container = IDE.get_service('main_container') if not main_container: return editorWidget = main_container.get_current_editor() if not editorWidget.file_path: name = QInputDialog.getText(None, self.tr("Add File To Project"), self.tr("File Name:"))[0] if not name: QMessageBox.information( self, self.tr("Invalid Name"), self.tr("The file name is empty, please enter a name")) return else: name = file_manager.get_basename(editorWidget.file_path) new_path = file_manager.create_path(addToProject.pathSelected, name) ide_srv = IDE.get_service("ide") old_file = ide_srv.get_or_create_nfile(path) new_file = old_file.save(editorWidget.get_text(), new_path) #FIXME: Make this file replace the original in the open tab else: pass # Message about no project @property def children(self): return self._projects_area.layout().count() def add_project(self, project): if project not in self.projects: ptree = TreeProjectsWidget(project) ptree.setParent(self) self.connect(ptree, SIGNAL("setActiveProject(PyQt_PyObject)"), self._set_active_project) self.connect(ptree, SIGNAL("closeProject(PyQt_PyObject)"), self._close_project) pmodel = project.model ptree.setModel(pmodel) ptree.header().title = project.name ptree.header().path = project.path pindex = pmodel.index(pmodel.rootPath()) ptree.setRootIndex(pindex) #self._widget.layout().addWidget(scrollable_wrapper(ptree)) self._projects_area.layout().addWidget(ptree) if self._active_project is None: ptree.set_default_project() self.projects.append(ptree) ptree.setGeometry(self.geometry()) def _close_project(self, widget): """Close the project related to the tree widget.""" self.projects.remove(widget) if self._active_project == widget and len(self.projects) > 0: self.projects[0].set_default_project() self._layout.removeWidget(widget) ninjaide = IDE.get_service('ide') ninjaide.filesystem.close_project(widget.project.path) widget.deleteLater() def _set_active_project(self, tree_proj): if self._active_project is not None: self._active_project.set_default_project(False) self._active_project = tree_proj def close_opened_projects(self): for project in reversed(self.projects): self._close_project(project) def save_project(self): """Save all the opened files that belongs to the actual project.""" if self._active_project: path = self._active_project.project.path main_container = IDE.get_service('main_container') if path and main_container: main_container.save_project(path) def create_new_project(self): wizard = wizard_new_project.WizardNewProject(self) wizard.show() @property def current_project(self): if self._active_project: return self._active_project.project @property def current_tree(self): return self._active_project def save_recent_projects(self, folder): settings = IDE.data_settings() recent_project_list = settings.value('recentProjects', {}) #if already exist on the list update the date time projectProperties = json_manager.read_ninja_project(folder) name = projectProperties.get('name', '') description = projectProperties.get('description', '') if name == '': name = file_manager.get_basename(folder) if description == '': description = self.tr('no description available') if folder in recent_project_list: properties = recent_project_list[folder] properties["lastopen"] = QDateTime.currentDateTime() properties["name"] = name properties["description"] = description recent_project_list[folder] = properties else: recent_project_list[folder] = { "name": name, "description": description, "isFavorite": False, "lastopen": QDateTime.currentDateTime() } #if the length of the project list it's high that 10 then delete #the most old #TODO: add the length of available projects to setting if len(recent_project_list) > 10: del recent_project_list[self.find_most_old_open( recent_project_list)] settings.setValue('recentProjects', recent_project_list) def find_most_old_open(self, recent_project_list): listFounder = [] for recent_project_path, content in list(recent_project_list.items()): listFounder.append( (recent_project_path, int(content["lastopen"].toString("yyyyMMddHHmmzzz")))) listFounder = sorted(listFounder, key=lambda date: listFounder[1], reverse=True) # sort by date last used return listFounder[0][0] def closeEvent(self, event): self.emit(SIGNAL("dockWidget(PyQt_PyObject)"), self) event.ignore()