def __getTemplatesDownloadDirectory(self): """ Gets the Templates directory. """ LOGGER.debug("> Retrieving Templates download directory.") choice = messageBox.messageBox( "Question", "{0}".format(self.__class__.__name__), "{0} | Which directory do you want to install the Templates into?". format(self.__class__.__name__), buttons=QMessageBox.Cancel, customButtons=((QString("Factory"), QMessageBox.AcceptRole), (QString("User"), QMessageBox.AcceptRole), (QString("Custom"), QMessageBox.AcceptRole))) if choice == 0: return os.path.join(RuntimeGlobals.templatesFactoryDirectory) elif choice == 1: return os.path.join(RuntimeGlobals.templatesUserDirectory) elif choice == 2: return umbra.ui.common.storeLastBrowsedPath( QFileDialog.getExistingDirectory( self, "Choose Templates Directory:", RuntimeGlobals.lastBrowsedPath))
def delete(self, node): """ Deletes given Node associated path. :param node: Node. :type node: ProjectNode or DirectoryNode or FileNode :return: Method success. :rtype: bool """ path = node.path if self.__scriptEditor.model.isAuthoringNode(node): if not foundations.common.pathExists(path): return False if messageBox.messageBox("Question", "Question", "Are you sure you want to delete '{0}' {1}?".format(path, "file" if os.path.isfile(path) else "directory"), buttons=QMessageBox.Yes | QMessageBox.No) == QMessageBox.Yes: if os.path.isfile(path): LOGGER.info("{0} | Deleting '{1}' file!".format(self.__class__.__name__, path)) self.__deleteFile(path) else: LOGGER.info("{0} | Deleting '{1}' directory!".format(self.__class__.__name__, path)) self.__deleteDirectory(path) return True
def __iblSetsScannerWorkerThread__iblSetsRetrieved(self, iblSets): """ This method is triggered by the **IblSetsScanner_worker** when the Database has changed. :param iblSets: Retrieve Ibl Sets. ( Dictionary ) """ if messageBox.messageBox( "Question", "Question", "One or more neighbor Ibl Sets have been found! Would you like to add that content: '{0}' to the Database?" .format(", ".join( map(foundations.strings.getSplitextBasename, iblSets))), buttons=QMessageBox.Yes | QMessageBox.No) == QMessageBox.Yes: self.__engine.startProcessing("Adding Retrieved Ibl Sets ...", len(iblSets)) for path in iblSets: iblSet = foundations.strings.getSplitextBasename(path) LOGGER.info( "{0} | Adding '{1}' Ibl Set to the Database!".format( self.__class__.__name__, iblSet)) if not sibl_gui.components.core.database.operations.addIblSet( iblSet, path, self.__collectionsOutliner.getCollectionId( self.__collectionsOutliner.defaultCollection)): LOGGER.error( "!> {0} | Exception raised while adding '{1}' Ibl Set to the Database!" .format(self.__class__.__name__, iblSet)) self.__engine.stepProcessing() self.__engine.stopProcessing() self.__iblSetsOutliner.refreshNodes.emit()
def removeInvalidData(self): """ Removes invalid data from the Database. :return: Method success. :rtype: bool """ if messageBox.messageBox("Question", "Question", "Are you sure you want to remove invalid data from the Database?", buttons=QMessageBox.Yes | QMessageBox.No) == QMessageBox.Yes: for type in self.__types: for item in type.getMethod(): if foundations.common.pathExists(item.path): continue LOGGER.info("{0} | Removing non existing '{1}' {2} from the Database!".format(self.__class__.__name__, item.name, type.type)) type.removeMethod(item.id) self.__engine.processEvents() type.modelContainer.refreshNodes.emit() self.__engine.stopProcessing() self.__engine.notificationsManager.notify( "{0} | Invalid data removed from Database!".format(self.__class__.__name__)) return True
def updateDatabase(self): """ | Updates the Database. | Each type defined by :meth:`DatabaseOperations.sibl_gui.components.core.database.types` attribute will have its instances checked and updated by their associated methods. :return: Method success. :rtype: bool """ for type in self.__types: for item in type.getMethod(): if foundations.common.pathExists(item.path): if type.updateContentMethod(item): LOGGER.info("{0} | '{1}' {2} has been updated!".format(self.__class__.__name__, item.name, type.type)) else: choice = messageBox.messageBox("Question", "Error", "{0} | '{1}' {2} file is missing, would you like to update it's location?".format( self.__class__.__name__, item.name, type.type), QMessageBox.Critical, QMessageBox.Yes | QMessageBox.No, customButtons=((QString("No To All"), QMessageBox.RejectRole),)) if choice == 0: break if choice == QMessageBox.Yes: type.updateLocationMethod(item) self.__engine.processEvents() type.modelContainer.refreshNodes.emit() self.__engine.stopProcessing() self.__engine.notificationsManager.notify("{0} | Database update done!".format(self.__class__.__name__)) return True
def closeFile(self): """ Closes the editor file. :return: Method success. :rtype: bool """ if not self.isModified(): LOGGER.debug("> Closing '{0}' file.".format(self.__file)) self.fileClosed.emit() return True choice = messageBox.messageBox("Warning", "Warning", "'{0}' document has been modified!\nWould you like to save your changes?".format(self.getFileShortName()), buttons=QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) if choice == QMessageBox.Save: if self.saveFile(): LOGGER.debug("> Closing '{0}' file.".format(self.__file)) return True elif choice == QMessageBox.Discard: LOGGER.debug("> Discarding '{0}' file.".format(self.__file)) self.fileClosed.emit() return True else: return False
def removeInvalidData(self): """ This method removes invalid data from the Database. :return: Method success. ( Boolean ) """ if messageBox.messageBox("Question", "Question", "Are you sure you want to remove invalid data from the Database?", buttons=QMessageBox.Yes | QMessageBox.No) == QMessageBox.Yes: for type in self.__types: for item in type.getMethod(): if foundations.common.pathExists(item.path): continue LOGGER.info("{0} | Removing non existing '{1}' {2} from the Database!".format(self.__class__.__name__, item.name, type.type)) type.removeMethod(item.id) self.__engine.processEvents() type.modelContainer.refreshNodes.emit() self.__engine.stopProcessing() self.__engine.notificationsManager.notify( "{0} | Invalid data removed from Database!".format(self.__class__.__name__)) return True
def updateDatabase(self): """ | This method updates the Database. | Each type defined by :meth:`DatabaseOperations.sibl_gui.components.core.database.types` attribute will have its instances checked and updated by their associated methods. :return: Method success. ( Boolean ) """ for type in self.__types: for item in type.getMethod(): if foundations.common.pathExists(item.path): if type.updateContentMethod(item): LOGGER.info("{0} | '{1}' {2} has been updated!".format(self.__class__.__name__, item.name, type.type)) else: choice = messageBox.messageBox("Question", "Error", "{0} | '{1}' {2} file is missing, would you like to update it's location?".format( self.__class__.__name__, item.name, type.type), QMessageBox.Critical, QMessageBox.Yes | QMessageBox.No, customButtons=((QString("No To All"), QMessageBox.RejectRole),)) if choice == 0: break if choice == QMessageBox.Yes: type.updateLocationMethod(item) self.__engine.processEvents() type.modelContainer.refreshNodes.emit() self.__engine.stopProcessing() self.__engine.notificationsManager.notify("{0} | Database update done!".format(self.__class__.__name__)) return True
def removeCollectionsUi(self): """ Removes user selected Collections from the Database. :return: Method success. :rtype: bool :note: May require user interaction. """ selectedNodes = self.getSelectedNodes().keys() if self.__overallCollection in (node.name for node in selectedNodes) or \ self.__defaultCollection in (node.name for node in selectedNodes): self.__engine.notificationsManager.warnify( "{0} | '{1}' and '{2}' Collections cannot be removed!".format( self.__class__.__name__, self.__overallCollection, self.__defaultCollection)) selectedCollections = [ collection for collection in self.getSelectedCollections() if collection.name != self.__defaultCollection ] if not selectedCollections: return False if messageBox.messageBox( "Question", "Question", "Are you sure you want to remove '{0}' Collection(s)?".format( ", ".join((foundations.strings.toString(collection.name) for collection in selectedCollections))), buttons=QMessageBox.Yes | QMessageBox.No) == QMessageBox.Yes: self.__engine.startProcessing("Removing Collections ...", len(selectedCollections)) success = True for collection in selectedCollections: success *= self.removeCollection(collection) or False self.__engine.stepProcessing() self.__engine.stopProcessing() self.__view.selectionModel().setCurrentIndex( self.__model.index(0, 0), QItemSelectionModel.Current | QItemSelectionModel.Select | QItemSelectionModel.Rows) if success: return True else: raise Exception( "{0} | Exception raised while removing '{1}' Collections from the Database!" .format( self.__class__.__name__, ", ".join( (collection.name for collection in selectedCollections))))
def removeCollectionsUi(self): """ Removes user selected Collections from the Database. :return: Method success. :rtype: bool :note: May require user interaction. """ selectedNodes = self.getSelectedNodes().keys() if self.__overallCollection in (node.name for node in selectedNodes) or \ self.__defaultCollection in (node.name for node in selectedNodes): self.__engine.notificationsManager.warnify( "{0} | '{1}' and '{2}' Collections cannot be removed!".format(self.__class__.__name__, self.__overallCollection, self.__defaultCollection)) selectedCollections = [collection for collection in self.getSelectedCollections() if collection.name != self.__defaultCollection] if not selectedCollections: return False if messageBox.messageBox("Question", "Question", "Are you sure you want to remove '{0}' Collection(s)?".format(", ".join((foundations.strings.toString(collection.name) for collection in selectedCollections))), buttons=QMessageBox.Yes | QMessageBox.No) == QMessageBox.Yes: self.__engine.startProcessing("Removing Collections ...", len(selectedCollections)) success = True for collection in selectedCollections: success *= self.removeCollection(collection) or False self.__engine.stepProcessing() self.__engine.stopProcessing() self.__view.selectionModel().setCurrentIndex(self.__model.index(0, 0), QItemSelectionModel.Current | QItemSelectionModel.Select | QItemSelectionModel.Rows) if success: return True else: raise Exception("{0} | Exception raised while removing '{1}' Collections from the Database!".format( self.__class__.__name__, ", ". join((collection.name for collection in selectedCollections))))
def __getTemplatesDownloadDirectory(self): """ Gets the Templates directory. """ LOGGER.debug("> Retrieving Templates download directory.") choice = messageBox.messageBox("Question", "{0}".format(self.__class__.__name__), "{0} | Which directory do you want to install the Templates into?".format( self.__class__.__name__), buttons=QMessageBox.Cancel, customButtons=((QString("Factory"), QMessageBox.AcceptRole), (QString("User"), QMessageBox.AcceptRole), (QString("Custom"), QMessageBox.AcceptRole))) if choice == 0: return os.path.join(RuntimeGlobals.templatesFactoryDirectory) elif choice == 1: return os.path.join(RuntimeGlobals.templatesUserDirectory) elif choice == 2: return umbra.ui.common.storeLastBrowsedPath(QFileDialog.getExistingDirectory(self, "Choose Templates Directory:", RuntimeGlobals.lastBrowsedPath))
def __iblSetsScannerWorkerThread__iblSetsRetrieved(self, iblSets): """ This method is triggered by the **IblSetsScanner_worker** when the Database has changed. :param iblSets: Retrieve Ibl Sets. ( Dictionary ) """ if messageBox.messageBox("Question", "Question", "One or more neighbor Ibl Sets have been found! Would you like to add that content: '{0}' to the Database?".format( ", ".join(map(foundations.strings.getSplitextBasename, iblSets))), buttons=QMessageBox.Yes | QMessageBox.No) == QMessageBox.Yes: self.__engine.startProcessing("Adding Retrieved Ibl Sets ...", len(iblSets)) for path in iblSets: iblSet = foundations.strings.getSplitextBasename(path) LOGGER.info("{0} | Adding '{1}' Ibl Set to the Database!".format(self.__class__.__name__, iblSet)) if not sibl_gui.components.core.database.operations.addIblSet( iblSet, path, self.__collectionsOutliner.getCollectionId(self.__collectionsOutliner.defaultCollection)): LOGGER.error("!> {0} | Exception raised while adding '{1}' Ibl Set to the Database!".format( self.__class__.__name__, iblSet)) self.__engine.stepProcessing() self.__engine.stopProcessing() self.__iblSetsOutliner.refreshNodes.emit()