Beispiel #1
0
    def saveSelections(self):
        """
        savasfilename can't append to a file - if the file exists an error
        message pops up.
        if output specified, don't ask (put it in window in menubar?)
        """
        filename = asksaveasfilename(title="Save points into a doc file",
                                     initialfile=self.savefilename)
        if len(filename) == 0:
            return

        # construct a dictionary to pass to writedocfile
        headers = ['file_number', 'class']
        F = {}
        key = self.startkey.get()
        try:
            key = int(key)
        except:
            key = 1

        for photo in self.photolist:
            filenumber = Spiderutils.getfilenumber(photo.filename)
            try:
                int(filenumber)
                if hasattr(photo, 'selectvalue'):
                    val = photo.selectvalue
                else:
                    val = '0'
                F[key] = [filenumber, val]
                key = key + 1
            except:
                print "error getting file number from %s" % photo.filename
                continue

        if Spiderutils.writedoc(filename, F, headers=headers, mode='a'):
            showinfo("Data saved to file",
                     "Data written to %s" % os.path.basename(filename))
        else:
            showerror("Error!",
                      "Unable to write to %s" % os.path.basename(filename))
Beispiel #2
0
    def saveSelections(self):
        """
        Savasfilename can't append to a file - if the file exists an error
        message pops up.
        if output specified, don't ask (put it in window in menubar?)
        """
        filename = asksaveasfilename(title="Save points into a doc file",
                                     initialfile=self.savefilename)
        if len(filename) == 0:
            return

        # Construct a dictionary to pass to writedocfile
        headers = ['file_number', 'class']
        F = {}
        key = self.startkey.get()
        try:
            key = int(key)
        except:
            key = 1

        for photo in self.photolist:
            filenumber = Spiderutils.getfilenumber(photo.filename)
            try:
                int(filenumber)
                if hasattr(photo, 'selectvalue'):
                    val = photo.selectvalue
                else:
                    val = '0'
                F[key] = [filenumber, val]
                key = key + 1
            except:
                print "error getting file number from %s" % photo.filename
                continue

        if Spiderutils.writedoc(filename, F, headers=headers, mode='a'):
            showinfo("Data saved to file", "Data written to %s" % os.path.basename(filename))
        else:
            showerror("Error!", "Unable to write to %s" % os.path.basename(filename))
Beispiel #3
0
    def saveDefocus(self, filename=None):
        "save current defocus and file number to a doc file"
        if filename != None:
            self.savefile = filename
        if self.savefile == "":
            filename = asksaveasfilename()
            if filename == "":
                return
            self.savefile = filename
        self.setFileLabels()

        if self.tfedfile == "":
            print "defocus data will be saved to %s" % self.savefile
            return

        micnum = self.filenumber(os.path.basename(self.tfedfile))
        defocus = int(float(self.defocus.get()))
        outfile = self.savefile
        headers = Spiderutils.getDocfileHeaders(outfile)
        if os.path.exists(outfile):
            # try to replace the line
            d = Spiderutils.readdoc(outfile, keys='all')
            keys = d.keys()
            found = 0
            for k in keys:
                mic = d[k][0]
                if mic == micnum:
                    d[k][1] = defocus
                    found = 1
                    break
            if found:
                Spiderutils.writedoc(outfile, columns=d)
            else:
                Spiderutils.writedoc(outfile,
                                     columns=[[micnum], [defocus]],
                                     mode='a')
        else:
            Spiderutils.writedoc(outfile,
                                 columns=[[micnum], [defocus]],
                                 headers=headers)
        #if writedoc(self.savefile, column1=micnum, column2=defocus):
        print "defocus %s saved to %s" % (defocus, outfile)
Beispiel #4
0
    def saveDefocus(self, filename=None):
        "save current defocus and file number to a doc file"
        if filename != None:
            self.savefile = filename
        if self.savefile == "":
            filename = asksaveasfilename()
            if filename == "":
                return 
            self.savefile = filename
        self.setFileLabels()

        if self.tfedfile == "":
            print "defocus data will be saved to %s" % self.savefile
            return

        micnum = self.filenumber(os.path.basename(self.tfedfile))
        defocus = int(float(self.defocus.get()))
        outfile = self.savefile
        headers = Spiderutils.getDocfileHeaders(outfile)
        if os.path.exists(outfile):
            # try to replace the line
            d = Spiderutils.readdoc(outfile, keys='all')
            keys = d.keys()
            found = 0
            for k in keys:
                mic = d[k][0]
                if mic == micnum:
                    d[k][1] = defocus
                    found = 1
                    break
            if found:
                Spiderutils.writedoc(outfile,columns=d)
            else:
                Spiderutils.writedoc(outfile,columns=[[micnum],[defocus]],mode='a')
        else:
            Spiderutils.writedoc(outfile,columns=[[micnum],[defocus]],headers=headers)
        #if writedoc(self.savefile, column1=micnum, column2=defocus):
        print "defocus %s saved to %s" % (defocus, outfile)