def generatePreview(self, textString=None): """ Generates a preview either from the provided text string or from the contents on the disk. Args: textString: Optional argument of a string from which to create the preview. Returns: A string containing a preview of the larger string. """ if textString == None: return general_functions.makePreviewFrom(self.loadContents()) else: return general_functions.makePreviewFrom(textString)
def cutFiles(self, savingChanges): """ Cuts the active files, and creates a formatted preview list with the results. Args: savingChanges: A boolean saying whether or not to save the changes made. Returns: A formatted list with an entry (tuple) for every active file, containing the preview information. """ activeFiles = [] for lFile in self.files.values(): if lFile.active: activeFiles.append(lFile) previews = [] for lFile in activeFiles: lFile.active = False childrenFileContents = lFile.cutContents() lFile.saveCutOptions(parentID=None) if savingChanges: for i, fileString in enumerate(childrenFileContents): originalFilename = lFile.name fileID = self.addFile( originalFilename, lFile.label + '_' + str(i + 1) + '.txt', fileString) self.files[fileID].setScrubOptionsFrom(parent=lFile) self.files[fileID].saveCutOptions(parentID=lFile.id) else: cutPreview = [] for i, fileString in enumerate(childrenFileContents): cutPreview.append( ('Segment ' + str(i + 1), general_functions.makePreviewFrom(fileString))) previews.append( (lFile.id, lFile.label, lFile.classLabel, cutPreview)) if savingChanges: previews = self.getPreviewsOfActive() return previews
def cutFiles(self, savingChanges): """ Cuts the active files, and creates a formatted preview list with the results. Args: savingChanges: A boolean saying whether or not to save the changes made. Returns: A formatted list with an entry (tuple) for every active file, containing the preview information. """ activeFiles = [] for lFile in self.files.values(): if lFile.active: activeFiles.append(lFile) previews = [] for lFile in activeFiles: lFile.active = False childrenFileContents = lFile.cutContents() lFile.saveCutOptions(parentID=None) if savingChanges: for i, fileString in enumerate(childrenFileContents): originalFilename = lFile.name fileID = self.addFile(originalFilename, lFile.label + '_' + str(i + 1) + '.txt', fileString) self.files[fileID].setScrubOptionsFrom(parent=lFile) self.files[fileID].saveCutOptions(parentID=lFile.id) self.files[fileID].setClassLabel(classLabel=lFile.classLabel) else: cutPreview = [] for i, fileString in enumerate(childrenFileContents): cutPreview.append(('Segment ' + str(i + 1), general_functions.makePreviewFrom(fileString))) previews.append((lFile.id, lFile.label, lFile.classLabel, cutPreview)) if savingChanges: previews = self.getPreviewsOfActive() return previews