Пример #1
0
    def updateTree(self, caller, deleteExisting = False):
        """updates caller's tree when all files are processed
            calls orderResults, giveFirst and giveSecond in the process
        """
        self._orderResults()

        toOpen = 0
        toOpenOK = 0

        # method items
        for count, control in enumerate(self.order):
            caller.contentTree.insert("", count, control[0], text = control[0],
                                      values = (self._giveFirst(control[0]),
                                                self._giveSecond(control[1])))
            toOpen += 1

            # file items
            countOK = 0
            for result in self.results[control[0]]:
                if result[2] != "OK":
                    caller.contentTree.insert(control[0], "end", result[0] + str(count),
                                              text = returnName(filename = result[0],
                                                                allFiles = self.files),
                                              values = result[1:3],
                                              tag = "file")
                    toOpen += 1
                else:
                    countOK += 1
                    
            # OK items
            if countOK:
                caller.contentTree.insert(control[0], "end", "OkFiles" + str(count),
                                          text = "Rest of files",
                                          values = ("{} files".format(countOK), "OK"))
                if self._giveFirst(control[0]) == "All files are OK":
                    caller.contentTree.see("OkFiles" + str(count))
                toOpen += 1
                for result in self.results[control[0]]:
                    if result[2] == "OK":
                        caller.contentTree.insert("OkFiles" + str(count), "end",
                                                  result[0] + str(count),
                                                  text = returnName(filename = result[0],
                                                                    allFiles = self.files),
                                                  values = result[1:3], tag = "file")
                        toOpenOK += 1

        # opens items
        if toOpen + toOpenOK <= 28:
            for control in self.controls:
                for child in caller.contentTree.get_children(control):
                    caller.contentTree.see(child)
                    for posterity in caller.contentTree.get_children(child):
                        caller.contentTree.see(posterity)
        elif toOpen <= 28:
            for control in self.controls:
                caller.contentTree.item(control, open = True)                
Пример #2
0
    def drawTree(self, selected = None):
        "initializes (or refreshes) tree"
        for child in self.tree.get_children():
            self.tree.delete(child)
            
        for count, file in enumerate(self.files):
            if file in self.fileStorage.tagged:
                tag = "x"
            else:
                tag = ""
                
            if self.controlled:
                problemKey = {"Problem": "P", "Warning": "W", "Concern": "C", "OK": "O"}
                methodKey = {"Reflections": "Ref", "Bad Points": "BP", "Outside Points": "OP"}
                problem = ""
                for method in self.root.root.controlReport.results:
                    importance = [i[2] for i in self.root.root.controlReport.results[method] if\
                                  i[0] == file]
                    problem = problem + methodKey[method] + ": " + problemKey[importance[0]] + ", "
                problem = problem[:-2]                  
                values = (problem, tag)
            else:
                values = (tag)
   
            self.tree.insert("", "end", str(count), text = returnName(file, self.files),
                             values = values)

        if selected:
            self.index = self.files.index(selected)

        if self.files:
            self.tree.selection_set(str(self.index))            
            self.tree.see(str(self.index))
Пример #3
0
    def drawTree(self, selected=None):
        "initializes (or refreshes) tree"
        for child in self.tree.get_children():
            self.tree.delete(child)

        for count, file in enumerate(self.files):
            tag = "x" if file in self.fileStorage.tagged else ""

            if self.controlled:
                problemKey = {
                    "Problem": "P",
                    "Warning": "W",
                    "Concern": "C",
                    "OK": "O"
                }
                methodKey = {
                    "Reflections": "Ref",
                    "Bad Points": "BP",
                    "Outside Points": "OP"
                }
                problem = ""
                for method in self.root.root.controlReport.results:
                    importance = [i[2] for i in self.root.root.controlReport.results[method] if\
                                  i[0] == file]
                    problem = problem + methodKey[method] + ": " + problemKey[
                        importance[0]] + ", "
                problem = problem[:-2]
                values = (problem, tag)
            else:
                values = (tag)

            comment = "comment" if self.fileStorage.comments[
                file] else "withoutComment"
            self.tree.insert("",
                             "end",
                             str(count),
                             text=returnName(file, self.files),
                             values=values,
                             tag=comment)

        if selected:
            self.index = self.files.index(selected)

        if self.files:
            self.tree.selection_set(str(self.index))
            self.tree.see(str(self.index))
Пример #4
0
    def drawTree(self, selected = None):
        "initializes (or refreshes) tree"
        for child in self.tree.get_children():
            self.tree.delete(child)
            
        for count, file in enumerate(self.files):
            if file in self.fileStorage.tagged:
                tag = "x"
            else:
                tag = ""                
            values = (tag)   
            self.tree.insert("", "end", str(count), text = returnName(
                file, self.files), values = values)

        if selected:
            self.index = self.files.index(selected)
        elif self.files:
            self.index = 0            

        if self.files:
            self.tree.selection_set(str(self.index))            
            self.tree.see(str(self.index))
Пример #5
0
 def saveFun(self):
     "writes results from controlReport to selected file"
     output = self.saveToFrame.saveToVar.get()
     if not self.controlReport.files:
         self.bell()
         self.status.set("No results prepared for saving.")
         return
     if not output:
         self.bell()
         self.status.set("You have to select a name of a file.")
         return
     
     separator = optionGet("ResultSeparator", ",", "str", True)
     results = separator.join(["File"] + self.controlReport.controls)
     for file in self.controlReport.files:
         filename = returnName(filename = file, allFiles = self.controlReport.files)
         result = [filename]
         for control in self.controlReport.controls:
             result += [i[3] for i in self.controlReport.results[control] if i[0] == file]
         results += "\n" + separator.join(map(str, result))
  
     writeResults(output, results)
     self.status.set("Results were saved.")
Пример #6
0
 def saveFun(self):
     "writes results from controlReport to selected file"
     output = self.saveToFrame.saveToVar.get()
     if not self.controlReport.files:
         self.bell()
         self.status.set("No results prepared for saving.")
         return
     if not output:
         self.bell()
         self.status.set("You have to select a name of a file.")
         return
     
     separator = optionGet("ResultSeparator", ",", "str")
     results = separator.join(["File"] + self.controlReport.controls)
     for file in self.controlReport.files:
         filename = returnName(filename = file, allFiles = self.controlReport.files)
         result = [filename]
         for control in self.controlReport.controls:
             result += [i[3] for i in self.controlReport.results[control] if i[0] == file]
         results += "\n" + separator.join(map(str, result))
  
     writeResults(output, results)
     self.status.set("Results were saved.")
Пример #7
0
    def processFun(self):
        "processes chosen files and saves the results in the save-to file"
        # checking for mistakes
        try:
            self.processCheck()
        except Exception as e:
            self.bell()
            self.status.set(e)
            return

        # files to be processed
        self.filesToProcess = [file for file in self.root.fileStorage.arenafiles if \
                               self.optionFrame.processFile(file)]

        # progressWindow and check for number of files for processing
        if len(self.filesToProcess) > 1:
            self.stoppedProcessing = False
            self.progressWindow = ProgressWindow(self,
                                                 len(self.filesToProcess))
        elif len(self.filesToProcess) == 0:
            self.bell()
            self.status.set("There is no file selected for processing!")
            return

        # selected methods
        methods = []
        for method in Parameters().parameters:
            if eval("self.parametersF.%sVar.get()" %
                    (method[0].replace(" ", ""))):
                methods.append(method[0])

        output = self.saveToFrame.saveToVar.get()
        startTime = float(self.timeFrame.startTimeVar.get())
        time = float(self.timeFrame.timeVar.get())
        separator = optionGet("ResultSeparator", ",", "str")

        results = separator.join(["File"] + methods)

        if self.optionFrame.saveTags.get():
            results += separator + "Tags"

        self.log = Log(methods, startTime, time, self.filesToProcess,
                       self.root.fileStorage,
                       self.optionFrame.removeReflectionsWhere.get(), output)
        self.someProblem = False

        developer = optionGet("Developer", False, 'bool')

        for file in self.filesToProcess:
            # loading of cm object
            if methods:
                try:
                    if file in self.root.fileStorage.pairedfiles:
                        cm = CM(file,
                                nameR=self.root.fileStorage.pairedfiles[file])
                    else:
                        cm = CM(file, nameR="auto")

                    if self.optionFrame.removeReflections(file):
                        cm.removeReflections(
                            points=self.root.fileStorage.reflections.get(
                                file, None))
                except Exception as e:
                    if developer:
                        print(e)
                    filename = returnName(
                        filename=file,
                        allFiles=self.root.fileStorage.arenafiles)
                    results += "\n" + filename + "{}NA".format(
                        separator) * len(methods)
                    self.log.failedToLoad.append(file)
                    self.someProblem = True
                    continue

            result = []
            for method in Parameters().parameters:
                if method[0] in methods:
                    try:
                        if method[2] == "custom":
                            exec("from Stuff.Parameters import {}".format(
                                method[5]))
                        result.append(eval(method[1]))
                    except Exception as e:
                        if developer:
                            print(e)
                        result.append("NA")
                        self.log.methodProblems[method[0]].append(file)
                        self.someProblem = True

            result = separator.join(map(str, result))
            if methods:
                result = separator + result
            filename = returnName(filename=file,
                                  allFiles=self.root.fileStorage.arenafiles)
            results += "\n" + filename + result

            if self.optionFrame.saveTags.get():  # tag inclusion in results
                if file in self.root.fileStorage.tagged:
                    results += separator + "1"
                else:
                    results += separator + "0"

            if len(self.filesToProcess) > 1:
                if self.stoppedProcessing:
                    writeResults(output, results)
                    self.log.stopped = file
                    self.log.writeLog()
                    self.status.set("Processing stopped")
                    return
                else:
                    self.progressWindow.addOne()

        writeResults(output, results)
        self.log.writeLog()

        # change of status bar and closing of progressWindow
        if len(self.filesToProcess) > 1:
            if self.someProblem:
                self.status.set("Files were processed.")
            else:
                self.status.set("Files were processed successfully.")
            self.progressWindow.destroy()
        else:
            if self.someProblem:
                self.status.set("File was processed.")
            else:
                self.status.set("File was processed successfully.")

        # removal of files from fileStorage if selected
        if self.optionFrame.clearFilesAfterProcessing.get():
            for file in self.filesToProcess:
                self.root.fileStorage.arenafiles.remove(file)
            self.fileStorageFrame.chosenVar.set(
                len(self.root.fileStorage.arenafiles))
            if not self.root.fileStorage.arenafiles:
                self.fileStorageFrame.removeFiles.state(["disabled"])
                self.process.state(["disabled"])

        if self.someProblem:
            ProcessingProblemDialog(self, self.log.filename)
Пример #8
0
    def updateTree(self):
        """updates self.root's tree when all files are processed
            calls orderResults, giveFirst and giveSecond in the process
        """
        self._orderResults()

        toOpen = 0
        toOpenOK = 0

        # method items
        for count, control in enumerate(self.order):
            self.root.contentTree.insert("", count, control[0], text = control[0],
                                         values = (self._giveFirst(control[0]),
                                                   self._giveSecond(control[1]),
                                                   ""), tag = "control")
            toOpen += 1

            # file items
            countOK = 0
            for result in self.results[control[0]]:
                if result[2] != "OK":
                    if self.fileStorage.comments[result[0]]:
                        tags = ("file", "comment")
                    else:                        
                        tags = "file"
                    self.root.contentTree.insert(control[0], "end", result[0] + str(count),
                                                 text = returnName(filename = result[0],
                                                                   allFiles = self.files),
                                                 values = tuple(result[1:3] + [result[4]]),
                                                 tag = tags)
                    toOpen += 1
                else:
                    countOK += 1
                    
            # OK items
            if countOK:
                self.root.contentTree.insert(control[0], "end", "OkFiles" + str(count),
                                             text = "Rest of files",
                                             values = ("{} files".format(countOK), "OK", ""),
                                             tag = "ok")
                if self._giveFirst(control[0]) == "All files are OK":
                    self.root.contentTree.see("OkFiles" + str(count))
                toOpen += 1
                for result in self.results[control[0]]:
                    if result[2] == "OK":
                        if self.fileStorage.comments[result[0]]:
                            tags = ("file", "comment")
                        else:                        
                            tags = "file"
                        self.root.contentTree.insert("OkFiles" + str(count), "end",
                                                     result[0] + str(count),
                                                     text = returnName(filename = result[0],
                                                                       allFiles = self.files),
                                                     values = tuple(result[1:3] + [result[4]]),
                                                     tag = tags)
                        toOpenOK += 1

        # opens items
        if toOpen + toOpenOK <= 28:
            for control in self.controls:
                for child in self.root.contentTree.get_children(control):
                    self.root.contentTree.see(child)
                    for posterity in self.root.contentTree.get_children(child):
                        self.root.contentTree.see(posterity)
        elif toOpen <= 28:
            for control in self.controls:
                self.root.contentTree.item(control, open = True)                
Пример #9
0
    def processFun(self):
        "processes chosen files and saves the results in the save-to file"
        # files to be processed
        self.filesToProcess = [file for file in self.fileStorage if \
                               self.optionFrame.processFile(file)]

        # checking for mistakes
        try:
            self.processCheck()
        except Exception as e:
            self.bell()
            self.status.set(e)
            return                   

        # progressWindow
        if len(self.filesToProcess) > 1:
            self.stoppedProcessing = False
            self.progressWindow = ProgressWindow(self, len(self.filesToProcess))     

        # initializations
        output = self.saveToFrame.saveToVar.get()
        if not os.path.splitext(output)[1]:
            output = output + optionGet("DefProcessOutputFileType", ".txt", "str", True)
        if not os.path.dirname(output):
            output = os.path.join(optionGet("ResultDirectory", os.getcwd(), "str", True), output)
        startTime = float(self.timeFrame.startTimeVar.get())
        time = float(self.timeFrame.timeVar.get())
        separator = optionGet("ResultSeparator", ",", "str", True)
        batchTime = self.selectedBatchTime if self.useBatchTimeVar.get() else None
        self.someProblem = False
        developer = optionGet("Developer", False, 'bool', True)

        # selected methods          
        methods = OrderedDict()
        parameters = m.parameters
        for name, par in parameters.items():
            if eval("self.parametersF.%sVar.get()" % (name.replace(" ", ""))):
                options = {name: optionGet(*option[0]) for name, option in par.options.items()}
                if not self.useBatchTimeVar.get():
                    methods[name] = [methodcaller(par.method, startTime = startTime,
                                                  time = time, **options)]
                elif name not in parameters.noBatch:
                    methods[name] = [methodcaller(par.method, startTime = times[0],
                                                  time = times[1], **options)
                                     for times in batchTime]
                else:
                    methods[name] = [methodcaller(par.method, **options)]

        # log
        self.log = Log(methods, startTime, time, self.filesToProcess, self.fileStorage,
                       self.optionFrame.removeReflectionsWhere.get(), output,
                       batchTime = batchTime)
                    
        # results header
        if self.useBatchTimeVar.get():
            results = ["File"]
            for method in methods:
                if method in parameters.noBatch:
                    results.append(method)
                else:
                    results.extend([method + " ({}-{})".format(start, end) for
                                    start, end in self.selectedBatchTime])
            results = separator.join(results)
        else:
            results = separator.join(["File"] + [method for method in methods])
        if self.optionFrame.saveTags.get():
            results += separator + "Tag"
        if self.optionFrame.saveComments.get():
            results += separator + "Comment"
        
        # computing of results
        for file in self.filesToProcess:
            # loading of cm object
            if methods:
                try:
                    if file in self.fileStorage.pairedfiles:
                        cm = m.CL(file, self.fileStorage.pairedfiles[file])
                    else:
                        cm = m.CL(file, "auto")

                    if self.optionFrame.removeReflections(file):
                        cm.removeReflections(points = self.fileStorage.reflections.get(file,
                                                                                            None))
                except Exception as e:
                    if developer:
                        print(e)   
                    filename = returnName(filename = file, allFiles =
                                          self.fileStorage.arenafiles) 
                    results += "\n" + filename + "{}NA".format(separator) * len(methods)
                    self.log.failedToLoad.append(file)
                    self.someProblem = True
                    continue
                                
            result = []

            for name, funcs in methods.items():
                for func in funcs:                        
                    try:
                        #if method[2] == "custom":
                            #exec("from Stuff.Parameters import {}".format(method[5]))               
                        result.append(func(cm))
                    except Exception as e:
                        if developer:
                            print(e)   
                        result.append("NA")
                        self.log.methodProblems[name].append(file)
                        self.someProblem = True

            result = separator.join(map(str, result))
            if methods:
                result = separator + result               
            filename = returnName(filename = file, allFiles = self.fileStorage.arenafiles)      
            results += "\n" + filename + result
            
            # tag inclusion in results
            if self.optionFrame.saveTags.get(): 
                if file in self.fileStorage.tagged:
                    results += separator + "1"
                else:
                    results += separator + "0"

            # comment inclusion in results
            if self.optionFrame.saveComments.get():
                results += separator + self.fileStorage.comments[file]
                    
            # progress window update
            if len(self.filesToProcess) > 1:
                if self.stoppedProcessing:
                    writeResults(output, results)
                    self.log.stopped = file
                    self.log.writeLog()
                    self.status.set("Processing stopped")
                    return
                else:
                    self.progressWindow.addOne()

        # results and log writing, ending of processing
        writeResults(output, results)
        self.log.writeLog()
        self._setStatusEndProgressWindow()

        if self.someProblem:
            ProcessingProblemDialog(self, self.log.filename, output)
        elif self.optionFrame.showResults.get():
            os.startfile(output)   
Пример #10
0
    def processFun(self):
        "processes chosen files and saves the results in the save-to file"
        # files to be processed
        self.filesToProcess = [file for file in self.fileStorage if \
                               self.optionFrame.processFile(file)]

        # checking for mistakes
        try:
            self.processCheck()
        except Exception as e:
            self.bell()
            self.status.set(e)
            return

        # progressWindow
        if len(self.filesToProcess) > 1:
            self.stoppedProcessing = False
            self.progressWindow = ProgressWindow(self,
                                                 len(self.filesToProcess))

        # selected methods
        methods = []
        for method in Parameters().parameters:
            if eval("self.parametersF.%sVar.get()" %
                    (method[0].replace(" ", ""))):
                methods.append(method[0])

        # initializations
        output = self.saveToFrame.saveToVar.get()
        startTime = float(self.timeFrame.startTimeVar.get())
        time = float(self.timeFrame.timeVar.get())
        separator = optionGet("ResultSeparator", ",", "str")
        batchTime = self.selectedBatchTime if self.useBatchTimeVar.get(
        ) else None
        self.log = Log(methods,
                       startTime,
                       time,
                       self.filesToProcess,
                       self.fileStorage,
                       self.optionFrame.removeReflectionsWhere.get(),
                       output,
                       batchTime=batchTime)
        self.someProblem = False
        developer = optionGet("Developer", False, 'bool')

        # results header
        if self.useBatchTimeVar.get():
            info = [
                method[0] for method in Parameters().parameters
                if method[2] == "info"
            ]
            results = ["File"]
            for method in methods:
                if method in info:
                    results.append(method)
                else:
                    results.extend([
                        method + " ({}-{})".format(start, end)
                        for start, end in self.selectedBatchTime
                    ])
            results = separator.join(results)
        else:
            results = separator.join(["File"] + methods)
        if self.optionFrame.saveTags.get():
            results += separator + "Tags"
        if self.optionFrame.saveComments.get():
            results += separator + "Comment"

        # computing of results
        for file in self.filesToProcess:
            # loading of cm object
            if methods:
                try:
                    if file in self.fileStorage.pairedfiles:
                        cm = CM(file, nameR=self.fileStorage.pairedfiles[file])
                    else:
                        cm = CM(file, nameR="auto")

                    if self.optionFrame.removeReflections(file):
                        cm.removeReflections(
                            points=self.fileStorage.reflections.get(
                                file, None))
                except Exception as e:
                    if developer:
                        print(e)
                    filename = returnName(filename=file,
                                          allFiles=self.fileStorage.arenafiles)
                    results += "\n" + filename + "{}NA".format(
                        separator) * len(methods)
                    self.log.failedToLoad.append(file)
                    self.someProblem = True
                    continue

            result = []
            for method in Parameters().parameters:
                if method[0] in methods:
                    if self.useBatchTimeVar.get():
                        for startTime, time in self.selectedBatchTime:
                            try:
                                if method[2] == "custom":
                                    exec("from Stuff.Parameters import {}".
                                         format(method[5]))
                                result.append(eval(method[1]))
                                if method[2] == "info":
                                    break
                            except Exception as e:
                                if developer:
                                    print(e)
                                result.append("NA")
                                self.log.methodProblems[method[0]].append(file)
                                self.someProblem = True
                    else:
                        try:
                            if method[2] == "custom":
                                exec("from Stuff.Parameters import {}".format(
                                    method[5]))
                            result.append(eval(method[1]))
                        except Exception as e:
                            if developer:
                                print(e)
                            result.append("NA")
                            self.log.methodProblems[method[0]].append(file)
                            self.someProblem = True

            result = separator.join(map(str, result))
            if methods:
                result = separator + result
            filename = returnName(filename=file,
                                  allFiles=self.fileStorage.arenafiles)
            results += "\n" + filename + result

            # tag inclusion in results
            if self.optionFrame.saveTags.get():
                if file in self.fileStorage.tagged:
                    results += separator + "1"
                else:
                    results += separator + "0"

            # comment inclusion in results
            if self.optionFrame.saveComments.get():
                results += separator + self.fileStorage.comments[file]

            # progress window update
            if len(self.filesToProcess) > 1:
                if self.stoppedProcessing:
                    writeResults(output, results)
                    self.log.stopped = file
                    self.log.writeLog()
                    self.status.set("Processing stopped")
                    return
                else:
                    self.progressWindow.addOne()

        # results and log writing, ending of processing
        writeResults(output, results)
        self.log.writeLog()
        self._setStatusEndProgressWindow()

        if self.someProblem:
            ProcessingProblemDialog(self, self.log.filename)
        elif self.optionFrame.showResults.get():
            os.startfile(output)
Пример #11
0
    def processFun(self):
        "processes chosen files and saves the results in the save-to file"
        # checking for mistakes
        try:
            self.processCheck()
        except Exception as e:
            self.bell()
            self.status.set(e)
            return                   

        # files to be processed
        self.filesToProcess = [file for file in self.root.fileStorage.arenafiles if \
                               self.optionFrame.processFile(file)]

        # progressWindow and check for number of files for processing
        if len(self.filesToProcess) > 1:
            self.stoppedProcessing = False
            self.progressWindow = ProgressWindow(self, len(self.filesToProcess))
        elif len(self.filesToProcess) == 0:
            self.bell()
            self.status.set("There is no file selected for processing!")
            return

        # selected methods          
        methods = []
        for method in Parameters().parameters:
            if eval("self.parametersF.%sVar.get()" % (method[0].replace(" ", ""))):
                methods.append(method[0])
           
        output = self.saveToFrame.saveToVar.get()
        startTime = float(self.timeFrame.startTimeVar.get())
        time = float(self.timeFrame.timeVar.get())
        separator = optionGet("ResultSeparator", ",", "str")
        
        results = separator.join(["File"] + methods)
        
        if self.optionFrame.saveTags.get():
            results += separator + "Tags"

        self.log = Log(methods, startTime, time, self.filesToProcess, self.root.fileStorage,
                       self.optionFrame.removeReflectionsWhere.get(), output)
        self.someProblem = False

        developer = optionGet("Developer", False, 'bool')
        
        for file in self.filesToProcess:
            # loading of cm object
            if methods:
                try:
                    if file in self.root.fileStorage.pairedfiles:
                        cm = CM(file, nameR = self.root.fileStorage.pairedfiles[file])
                    else:
                        cm = CM(file, nameR = "auto")

                    if self.optionFrame.removeReflections(file):
                        cm.removeReflections(points = self.root.fileStorage.reflections.get(file,
                                                                                            None))
                except Exception as e:
                    if developer:
                        print(e)   
                    filename = returnName(filename = file, allFiles =
                                          self.root.fileStorage.arenafiles) 
                    results += "\n" + filename + "{}NA".format(separator) * len(methods)
                    self.log.failedToLoad.append(file)
                    self.someProblem = True
                    continue
                    
            
            result = []
            for method in Parameters().parameters:
                if method[0] in methods:
                    try:
                        if method[2] == "custom":
                            exec("from Stuff.Parameters import {}".format(method[5]))
                        result.append(eval(method[1]))
                    except Exception as e:
                        if developer:
                            print(e)   
                        result.append("NA")
                        self.log.methodProblems[method[0]].append(file)
                        self.someProblem = True


            result = separator.join(map(str, result))
            if methods:
                result = separator + result               
            filename = returnName(filename = file, allFiles = self.root.fileStorage.arenafiles)      
            results += "\n" + filename + result
            
            if self.optionFrame.saveTags.get(): # tag inclusion in results
                if file in self.root.fileStorage.tagged:
                    results += separator + "1"
                else:
                    results += separator + "0"
            
            if len(self.filesToProcess) > 1:
                if self.stoppedProcessing:
                    writeResults(output, results)
                    self.log.stopped = file
                    self.log.writeLog()
                    self.status.set("Processing stopped")
                    return
                else:
                    self.progressWindow.addOne()


        writeResults(output, results)
        self.log.writeLog()

        # change of status bar and closing of progressWindow
        if len(self.filesToProcess) > 1:
            if self.someProblem:
                self.status.set("Files were processed.")
            else:
                self.status.set("Files were processed successfully.")
            self.progressWindow.destroy()
        else:
            if self.someProblem:
                self.status.set("File was processed.")
            else:
                self.status.set("File was processed successfully.")

        # removal of files from fileStorage if selected
        if self.optionFrame.clearFilesAfterProcessing.get():
            for file in self.filesToProcess:
                self.root.fileStorage.arenafiles.remove(file)
            self.fileStorageFrame.chosenVar.set(len(self.root.fileStorage.arenafiles))
            if not self.root.fileStorage.arenafiles:
                self.fileStorageFrame.removeFiles.state(["disabled"]) 
                self.process.state(["disabled"])

        if self.someProblem:
            ProcessingProblemDialog(self, self.log.filename)
Пример #12
0
    def updateTree(self):
        """updates self.root's tree when all files are processed
            calls orderResults, giveFirst and giveSecond in the process
        """
        self._orderResults()

        toOpen = 0
        toOpenOK = 0

        # method items
        for count, control in enumerate(self.order):
            self.root.contentTree.insert("", count, control[0], text = control[0],
                                         values = (self._giveFirst(control[0]),
                                                   self._giveSecond(control[1]),
                                                   ""), tag = "control")
            toOpen += 1

            # file items
            countOK = 0
            for result in self.results[control[0]]:
                if result[2] != "OK":
                    if self.fileStorage.comments[result[0]]:
                        tags = ("file", "comment")
                    else:                        
                        tags = "file"
                    self.root.contentTree.insert(control[0], "end", result[0] + str(count),
                                                 text = returnName(filename = result[0],
                                                                   allFiles = self.files),
                                                 values = tuple(result[1:3] + [result[4]]),
                                                 tag = tags)
                    toOpen += 1
                else:
                    countOK += 1
                    
            # OK items
            if countOK:
                self.root.contentTree.insert(control[0], "end", "OkFiles" + str(count),
                                             text = "Rest of files",
                                             values = ("{} files".format(countOK), "OK", ""),
                                             tag = "ok")
                if self._giveFirst(control[0]) == "All files are OK":
                    self.root.contentTree.see("OkFiles" + str(count))
                toOpen += 1
                for result in self.results[control[0]]:
                    if result[2] == "OK":
                        if self.fileStorage.comments[result[0]]:
                            tags = ("file", "comment")
                        else:                        
                            tags = "file"
                        self.root.contentTree.insert("OkFiles" + str(count), "end",
                                                     result[0] + str(count),
                                                     text = returnName(filename = result[0],
                                                                       allFiles = self.files),
                                                     values = tuple(result[1:3] + [result[4]]),
                                                     tag = tags)
                        toOpenOK += 1

        # opens items
        if toOpen + toOpenOK <= 28:
            for control in self.controls:
                for child in self.root.contentTree.get_children(control):
                    self.root.contentTree.see(child)
                    for posterity in self.root.contentTree.get_children(child):
                        self.root.contentTree.see(posterity)
        elif toOpen <= 28:
            for control in self.controls:
                self.root.contentTree.item(control, open = True)                
Пример #13
0
    def processFun(self):
        "processes chosen files and saves the results in the save-to file"
        # files to be processed
        self.filesToProcess = [file for file in self.fileStorage if \
                               self.optionFrame.processFile(file)]

        # checking for mistakes
        try:
            self.processCheck()
        except Exception as e:
            self.bell()
            self.status.set(e)
            return                   

        # progressWindow
        if len(self.filesToProcess) > 1:
            self.stoppedProcessing = False
            self.progressWindow = ProgressWindow(self, len(self.filesToProcess))     

        # selected methods          
        methods = []
        for method in Parameters().parameters:
            if eval("self.parametersF.%sVar.get()" % (method[0].replace(" ", ""))):
                methods.append(method[0])

        # initializations
        output = self.saveToFrame.saveToVar.get()
        startTime = float(self.timeFrame.startTimeVar.get())
        time = float(self.timeFrame.timeVar.get())
        separator = optionGet("ResultSeparator", ",", "str")
        batchTime = self.selectedBatchTime if self.useBatchTimeVar.get() else None
        self.log = Log(methods, startTime, time, self.filesToProcess, self.fileStorage,
                       self.optionFrame.removeReflectionsWhere.get(), output,
                       batchTime = batchTime)
        self.someProblem = False
        developer = optionGet("Developer", False, 'bool')

        # results header
        if self.useBatchTimeVar.get():
            info = [method[0] for method in Parameters().parameters if method[2] == "info"]
            results = ["File"]
            for method in methods:
                if method in info:
                    results.append(method)
                else:
                    results.extend([method + " ({}-{})".format(start, end) for
                                    start, end in self.selectedBatchTime])
            results = separator.join(results)
        else:
            results = separator.join(["File"] + methods)        
        if self.optionFrame.saveTags.get():
            results += separator + "Tags"
        if self.optionFrame.saveComments.get():
            results += separator + "Comment"
        
        # computing of results
        for file in self.filesToProcess:
            # loading of cm object
            if methods:
                try:
                    if file in self.fileStorage.pairedfiles:
                        cm = CM(file, nameR = self.fileStorage.pairedfiles[file])
                    else:
                        cm = CM(file, nameR = "auto")

                    if self.optionFrame.removeReflections(file):
                        cm.removeReflections(points = self.fileStorage.reflections.get(file,
                                                                                            None))
                except Exception as e:
                    if developer:
                        print(e)   
                    filename = returnName(filename = file, allFiles =
                                          self.fileStorage.arenafiles) 
                    results += "\n" + filename + "{}NA".format(separator) * len(methods)
                    self.log.failedToLoad.append(file)
                    self.someProblem = True
                    continue
                                
            result = []
            for method in Parameters().parameters:
                if method[0] in methods:
                    if self.useBatchTimeVar.get():
                        for startTime, time in self.selectedBatchTime:
                            try:
                                if method[2] == "custom":
                                    exec("from Stuff.Parameters import {}".format(method[5]))
                                result.append(eval(method[1]))
                                if method[2] == "info":
                                    break
                            except Exception as e:
                                if developer:
                                    print(e)   
                                result.append("NA")
                                self.log.methodProblems[method[0]].append(file)
                                self.someProblem = True
                    else:                          
                        try:
                            if method[2] == "custom":
                                exec("from Stuff.Parameters import {}".format(method[5]))
                            result.append(eval(method[1]))
                        except Exception as e:
                            if developer:
                                print(e)   
                            result.append("NA")
                            self.log.methodProblems[method[0]].append(file)
                            self.someProblem = True

            result = separator.join(map(str, result))
            if methods:
                result = separator + result               
            filename = returnName(filename = file, allFiles = self.fileStorage.arenafiles)      
            results += "\n" + filename + result
            
            # tag inclusion in results
            if self.optionFrame.saveTags.get(): 
                if file in self.fileStorage.tagged:
                    results += separator + "1"
                else:
                    results += separator + "0"

            # comment inclusion in results
            if self.optionFrame.saveComments.get():
                results += separator + self.fileStorage.comments[file]
                    
            # progress window update
            if len(self.filesToProcess) > 1:
                if self.stoppedProcessing:
                    writeResults(output, results)
                    self.log.stopped = file
                    self.log.writeLog()
                    self.status.set("Processing stopped")
                    return
                else:
                    self.progressWindow.addOne()

        # results and log writing, ending of processing
        writeResults(output, results)
        self.log.writeLog()
        self._setStatusEndProgressWindow()

        if self.someProblem:
            ProcessingProblemDialog(self, self.log.filename)
        elif self.optionFrame.showResults.get():
            os.startfile(output)