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 = Spiderutils.istextfile(self.path) if typ == 1: if Spiderutils.isSpiderDocfile(self.path): return "docfile" elif Spiderutils.isSpiderBatchfile(self.path): return "procfile" elif Spiderutils.isSpiderProcedurefile(self.path): return "procfile" else: return "text" elif typ == -1: return "unknown" spi = Spiderutils.isSpiderBin(self.path) if spi == "image" or spi == "Fourier" or spi == "stack": return "spider" elif spi == "volume": return "volume" return "binary" # i.e. a non-spider binary file
def processargs(args): " returns (serverflag, filelist, directory) " serverflag = 0 readall = 0 filenames = [] cwd = os.getcwd() for item in args: if item == '-s': serverflag = 1 elif item == '-h' or item == '-help': helpmessage() elif os.path.isdir(item): # qview dir : reads all files in directory, but # qview * : should not read subdirectories if len(filenames) > 0: continue cwd = os.path.abspath(item) os.chdir(cwd) filenames = os.listdir(os.getcwd()) break else: filenames.append(item) if filenames == []: helpmessage() if readall: files = os.listdir(os.getcwd()) filenames = [] for file in files: if not os.path.exists(file): # why is this needed? continue # only include binary files if not os.path.isdir(file) \ and not Spiderutils.istextfile(file) \ and file[0] != '.': filenames.append(file) if len(filenames) == 0: print "no images found in %s" % os.getcwd() sys.exit() return (serverflag, filenames, cwd)
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 = int(self.textbox.limits[3].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.textbox.clear() self.textbox.settext(filelisting) # view text files in window (sometimes pdfs slip thru) elif self.ext != ".pdf" and Spiderutils.istextfile(self.path): # check if html files are sent to browser if self.ext == ".html" or self.ext == ".htm": browser = self.textbox.limits[4].get() if browser: webbrowser.open(self.path) return textmax = self.textbox.limits[2] 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() except: pass fp.close() self.textbox.clear() for line in B: self.textbox.component('text').insert(END, str(line)) # binaries else: spidertype = Spiderutils.isSpiderBin(self.path) if spidertype != 0: #== "image": infotxt = self.getSpiderInfo(self.path) self.textbox.clear() self.textbox.component('text').insert(END, infotxt) if spidertype == "image": self.putImage(self.path, clear=0) elif self.ext.lower() in self.imagetypes: self.putImage(self.path)