Exemple #1
0
 def GetIconName(self):
     if not self.IsExpandable():
         name, ext = os.path.splitext(self.path)
         if ext in ['.py']:   #, '.pyc','.pyo']:
             return "python"
         if ext.lower() in self.imagetypes:
             return "image"
         typ = spiderFtypes.istextfile(self.path)
         if typ == 1:
             if spiderFtypes.isSpiderDocfile(self.path):
                 return "docfile"
             elif spiderFtypes.isSpiderBatchfile(self.path):
                 return "procfile"
             elif spiderFtypes.isSpiderProcedurefile(self.path):
                 return "procfile"
             else:
                 return "text"
         elif typ == -1:
             return "unknown"
         
         spi = spiderFtypes.isSpiderBin(self.path)
         if spi == "image" or spi == "Fourier":
             return "spider"
         elif spi == "volume":
             return "volume"
         
         return "binary"   # i.e. a non-spider binary file
Exemple #2
0
def parmOpen():
    if not hasProject():
        displayError('Please open a project.')
        return
    dir = getProjDir()
    if dir == "" or chdir(dir) == 0: return

    parmfile = GG.sysprefs.paramFile
    if not os.path.exists(parmfile):
        askstr = "Unable to find parameter file\n '%s'\nCreate a new one?" % parmfile
        if askOKorCancel(askstr,'Error'):
            pf = parmForm(wintitle='SPIDER Parameters',
                          title='Project Parameters', new=1)
        return
    else:
        if istextfile(parmfile) and isSpiderDocfile(parmfile):
            pass
        else:
            displayError('%s\n does not appear to be a SPIDER doc file' % parmfile)
            return	

    GB.P.parameters = readParamTextfile(parmfile)

    pf = parmForm(wintitle='SPIDER Parameters',
                  title='Project Parameters',
                  subtitle=projFilename(GG.sysprefs.paramFile), new=0)
Exemple #3
0
def parmOpen():
    if not hasProject():
        displayError('Please open a project.')
        return
    dir = getProjDir()
    if dir == "" or chdir(dir) == 0: return

    parmfile = GG.sysprefs.paramFile
    if not os.path.exists(parmfile):
        askstr = "Unable to find parameter file\n '%s'\nCreate a new one?" % parmfile
        if askOKorCancel(askstr,'Error'):
            pf = parmForm(wintitle='SPIDER Parameters',
                          title='Project Parameters', new=1)
        return
    else:
        if istextfile(parmfile) and isSpiderDocfile(parmfile):
            pass
        else:
            displayError('%s\n does not appear to be a SPIDER doc file' % parmfile)
            return	

    GB.P.parameters = readParamTextfile(parmfile)

    pf = parmForm(wintitle='SPIDER Parameters',
                  title='Project Parameters',
                  subtitle=projFilename(GG.sysprefs.paramFile), new=0)
Exemple #4
0
    def GetIconName(self):
        if not self.IsExpandable():
            name, ext = os.path.splitext(self.path)
            if ext in ['.py']:  #, '.pyc','.pyo']:
                return "python"
            if ext.lower() in self.imagetypes:
                return "image"
            typ = spiderFtypes.istextfile(self.path)
            if typ == 1:
                if spiderFtypes.isSpiderDocfile(self.path):
                    return "docfile"
                elif spiderFtypes.isSpiderBatchfile(self.path):
                    return "procfile"
                elif spiderFtypes.isSpiderProcedurefile(self.path):
                    return "procfile"
                else:
                    return "text"
            elif typ == -1:
                return "unknown"

            spi = spiderFtypes.isSpiderBin(self.path)
            if spi == "image" or spi == "Fourier":
                return "spider"
            elif spi == "volume":
                return "volume"

            return "binary"  # i.e. a non-spider binary file
def viewFile(filename=None, type=None, verbose=0):  #0):
    " type can be 'text' (simple viewer), 'edit' (editor), 'image' (display) "
    if verbose: print "viewFile: %s" % filename
    if filename == None: filename = askfilename()
    if filename == "" or len(filename) == 0: return
    if not os.path.exists(filename):
        filename = truepath(filename)
        if not os.path.exists(filename):
            GB.errstream("Unable to find %s" % filename)
            return

    if type != None:
        if type == 'text':
            fn = os.path.basename(filename)
            tw = textWindow(title=fn, font='output', importfile=filename)
        elif type == 'edit':
            fileEdit(filename)
        elif type == 'image':
            spiderImage.displayImage(filename)
            if verbose:
                GB.outstream("displaying %s ..." % filename)
        elif type == 'volume':
            spiderImage.displayVolume(filename)
            if verbose:
                GB.outstream("displaying %s ..." % filename)

    elif type == None:
        # see if it has the project extension (i.e., a Spider file)
        base, ext = os.path.splitext(filename)
        extnodot = ext[1:]
        if extnodot == GB.P.dataext:
            if verbose: print "viewFile: %s is a Spider file" % filename
            if spiderFtypes.istextfile(filename):
                fileEdit(filename)
            elif spiderFtypes.isSpiderBin(filename):
                spiderImage.displayImage(filename)         
                if verbose:
                    GB.outstream("displaying %s ..." % filename)
        elif ext in GG.sysprefs.AppDict:
            if verbose: print "viewFile: %s is NOT a Spider file" % filename
            app = GG.sysprefs.AppDict[ext]
            executeCommand(app, [filename])
        else:
            if verbose: print filename
Exemple #6
0
    def OnDoubleClick(self):
        """Called on a double-click on the icon."""
        self.status.set(self.path)
        
        # Directories: list them in window
        if os.path.isdir(self.path):
            dirmax = self.textbox.vars['dirmax']
            dirmax = int(dirmax.get())
            dirsize = os.path.getsize(self.path)
            if dirsize > dirmax:
                basename = os.path.basename(self.path)
                txt = "%s may contain a very large number of files.\nDisplay anyway?" % (basename)
                if not askyesno("Warning", txt):
                    return
            
            cmd = "ls -lF %s " % self.path
            out = getoutput(cmd)
            filelisting = self.path + "\n" + out
            self.write(filelisting)

        # view text files in window (sometimes pdfs slip thru)   
        elif self.ext != ".pdf" and spiderFtypes.istextfile(self.path):
            # check if html files are sent to browser
            if self.ext == ".html" or self.ext == ".htm":
                browser = self.textbox.vars['html'].get()
                if browser:
                    webbrowser.open(self.path)
                    return
                
            textmax = self.textbox.vars['textmax']
            tmax = int(textmax.get())
            textsize = os.path.getsize(self.path)

            if textsize > tmax:
                basename = os.path.basename(self.path)
                txt = "%s is %d bytes.\nDisplay anyway?" % (basename, textsize)
                if not askyesno("Warning", txt):
                    return
            try:
                fp = open(self.path,'r')
                B = fp.readlines()
                fp.close()
                self.write(B)
            except:
                pass
            
            #self.textbox.clear()
            #for line in B:
                #self.textbox.component('text').insert(END, str(line))

        # binaries
        else:
            self.displayProg = self.textbox.vars['display'].get()

            spidertype = spiderFtypes.isSpiderBin(self.path)
            if spidertype != 0:  #== "image":
                infotxt = self.getSpiderInfo(self.path)
                self.write(infotxt)
                
                if self.displayProg == 'jweb':
                    if spidertype == "image":
                        spiderGUtils.viewFile(self.path, type="image")
                    elif spidertype == "volume":
                        spiderGUtils.viewFile(self.path, type="volume")
                else:
                    dp = self.displayProg
                    if dp == "qview.py":
                        dp = "qview.py -s"
                    cmd = "%s %s" % (dp, self.path)
                    # use a thread command because xv doesn't return
                    spiderUtils.threadCommand(cmd)
            
            elif self.ext.lower() in self.imagetypes:
                dp = self.displayProg
                if dp == 'jweb' or dp == "qview.py":
                    dp = 'qview.py -s'
                cmd = "%s %s" % (dp, self.path)
                #print cmd
                spiderUtils.threadCommand(cmd)
Exemple #7
0
    def OnDoubleClick(self):
        """Called on a double-click on the icon."""
        self.status.set(self.path)

        # Directories: list them in window
        if os.path.isdir(self.path):
            dirmax = self.textbox.vars['dirmax']
            dirmax = int(dirmax.get())
            dirsize = os.path.getsize(self.path)
            if dirsize > dirmax:
                basename = os.path.basename(self.path)
                txt = "%s may contain a very large number of files.\nDisplay anyway?" % (
                    basename)
                if not askyesno("Warning", txt):
                    return

            cmd = "ls -lF %s " % self.path
            out = getoutput(cmd)
            filelisting = self.path + "\n" + out
            self.write(filelisting)

        # view text files in window (sometimes pdfs slip thru)
        elif self.ext != ".pdf" and spiderFtypes.istextfile(self.path):
            # check if html files are sent to browser
            if self.ext == ".html" or self.ext == ".htm":
                browser = self.textbox.vars['html'].get()
                if browser:
                    webbrowser.open(self.path)
                    return

            textmax = self.textbox.vars['textmax']
            tmax = int(textmax.get())
            textsize = os.path.getsize(self.path)

            if textsize > tmax:
                basename = os.path.basename(self.path)
                txt = "%s is %d bytes.\nDisplay anyway?" % (basename, textsize)
                if not askyesno("Warning", txt):
                    return
            try:
                fp = open(self.path, 'r')
                B = fp.readlines()
                fp.close()
                self.write(B)
            except:
                pass

            #self.textbox.clear()
            #for line in B:
            #self.textbox.component('text').insert(END, str(line))

        # binaries
        else:
            self.displayProg = self.textbox.vars['display'].get()

            spidertype = spiderFtypes.isSpiderBin(self.path)
            if spidertype != 0:  #== "image":
                infotxt = self.getSpiderInfo(self.path)
                self.write(infotxt)

                if self.displayProg == 'jweb':
                    if spidertype == "image":
                        spiderGUtils.viewFile(self.path, type="image")
                    elif spidertype == "volume":
                        spiderGUtils.viewFile(self.path, type="volume")
                else:
                    dp = self.displayProg
                    if dp == "qview.py":
                        dp = "qview.py -s"
                    cmd = "%s %s" % (dp, self.path)
                    # use a thread command because xv doesn't return
                    spiderUtils.threadCommand(cmd)

            elif self.ext.lower() in self.imagetypes:
                dp = self.displayProg
                if dp == 'jweb' or dp == "qview.py":
                    dp = 'qview.py -s'
                cmd = "%s %s" % (dp, self.path)
                #print cmd
                spiderUtils.threadCommand(cmd)