예제 #1
0
 def doAll(self, methods=['method 1']):
     """Process all datasets in ekinprj"""
     E=self.E
     vals={}
     from Dialogs import PEATDialog
     pb=PEATDialog(self.mainwin, option='progressbar',
                                   message='Analysing Data..')
     pb.update_progress(0)
     total = len(E.datasets); count=0
     for d in E.datasets:
         if '_diff' in d or '_vanthoff' in d:
             continue
         vals[d]={}
         name = d
         if 'method 1' in methods:
             vals[d]['dH1'], vals[d]['dS1'], ax = self.fitVantHoff(E,d,
                                                      transwidth=int(self.tw.getvalue()),
                                                      show=False,figname=name)
         if 'method 2' in methods:
             vals[d]['dH2'], vals[d]['dTm2'], vals[d]['dCp2'] = self.fitElwellSchellman(E,d,show=False,figname=name)
         if 'method 3' in methods:
             vals[d]['dH3'], vals[d]['dTm3'] = self.fitDifferentialCurve(E,d,show=False,figname=name)
         count += 1
         pb.update_progress(float(count)/total*100.0)
     pb.close()
     self.showTable(vals)
     return
예제 #2
0
 def doAll(self, methods=['method 1']):
     """Process all datasets in ekinprj"""
     E = self.E
     vals = {}
     from Dialogs import PEATDialog
     pb = PEATDialog(self.mainwin,
                     option='progressbar',
                     message='Analysing Data..')
     pb.update_progress(0)
     total = len(E.datasets)
     count = 0
     for d in E.datasets:
         if '_diff' in d or '_vanthoff' in d:
             continue
         vals[d] = {}
         name = d
         if 'method 1' in methods:
             vals[d]['dH1'], vals[d]['dS1'], ax = self.fitVantHoff(
                 E,
                 d,
                 transwidth=int(self.tw.getvalue()),
                 show=False,
                 figname=name)
         if 'method 2' in methods:
             vals[d]['dH2'], vals[d]['dTm2'], vals[d][
                 'dCp2'] = self.fitElwellSchellman(E,
                                                   d,
                                                   show=False,
                                                   figname=name)
         if 'method 3' in methods:
             vals[d]['dH3'], vals[d]['dTm3'] = self.fitDifferentialCurve(
                 E, d, show=False, figname=name)
         count += 1
         pb.update_progress(float(count) / total * 100.0)
     pb.close()
     self.showTable(vals)
     return
예제 #3
0
class FileHandler(object):
    """Class to handle external files for peatdb, uses some stuff from
       old peat from db_actions etc
       Should add thumbnail stuff here??"""

    extensions = {
        'image':
        ['.jpg', '.jpeg', '.tiff', '.tif', '.gif', '.ps', '.png', '.ico'],
        'doc':
        ['.doc', '.xls', '.ppt', '.pdf', '.docx', '.txt', '.csv', '.odt'],
        'compressed': ['.zip', '.gz', '.bz', '.tar'],
        'any': ''
    }

    def __init__(self, parent=None, DB=None):
        self.parent = parent
        self.currplatform = platform.system()

        return

    def displayFile(self, filerec):
        """Uses a new method of file storage with blobs"""
        #now we just get the blob from the filerecord object...
        from PILView import PILViewer
        from PEATDB.Record import FileRecord
        #check class
        if not type(filerec) is FileRecord:
            return False
        myblob = filerec.blob
        ext = filerec.ext
        mtype = filerec.mimetype
        print 'mimetype is', mtype
        if myblob != None:
            f = myblob.open("r")
            filename = f.name
            f.close()
        else:
            return False

        if self.currplatform == 'Linux':
            #try using mailcaps on linux system
            import mailcap, os
            d = mailcap.getcaps()
            print mtype, filename
            f = mailcap.findmatch(d, mtype)[1]
            os.system(f['view'] % filename)
            return
        else:
            import os, tempfile, shutil
            tempname = os.path.normpath(
                os.path.join(tempfile.gettempdir(), filerec.name))
            if not os.path.exists(tempname):
                #os.remove(tempname)
                shutil.copy(filename, tempname)
            os.startfile(tempname)

        return True

    def addFileDialog(self, filerec=None):
        """Do the front-end stuff for adding files to peat"""
        import tkFileDialog
        filename = tkFileDialog.askopenfilename(defaultextension='.*',
                                                initialdir=os.getcwd(),
                                                filetypes=[("All files", "*.*")
                                                           ])
        self.newfile = filename
        return filename

    def importFileset(self, DB, parentframe=None, callback=None):
        """Import a series of external files in a folder to peat"""
        def getdir():
            import tkFileDialog, os
            d = tkFileDialog.askdirectory(initialdir=importdir.get(),
                                          title='Select directory files',
                                          mustexist=1,
                                          parent=self.parent.master)
            if d:
                importdir.set(d)
                return

        def doimport():
            idir = importdir.get()
            ext = filetype.get()
            if idir == None:
                return
            files = os.listdir(idir)
            okfiles = []
            for f in files:
                pth = os.path.join(idir, f)
                if os.path.isfile(pth):
                    if ext != 'any':
                        if os.path.splitext(
                                pth)[1] not in self.extensions[ext]:
                            continue
                    okfiles.append(pth)
            print 'files to be used:', okfiles
            DB.addField('file', 'File')
            from Dialogs import PEATDialog
            self.pb = PEATDialog(self.parent.master,
                                 option='progressbar',
                                 message='Importing files')
            self.pb.update_progress(0)
            total = len(okfiles)
            row = 0
            #iterate over filenames in folder and add one rec to DB for each file
            for f in okfiles:
                recname = os.path.basename(f)
                DB.addBlob(recname, 'file', f)
                print 'added %s as %s' % (f, recname)
                row = row + 1
                c = float(row) / float(total) * 100.0
                self.pb.update_progress(c)
            self.pb.close()
            if callback != None:
                callback()
            return

        def close():
            win.destroy()
            return

        if parentframe != None:
            win = Frame(master=parentframe, relief=RAISED)
            win.pack(fill=BOTH)
        else:
            win = Toplevel()
            win.title('Import ext files')

        importdir = StringVar()
        importdir.set(os.getcwd())
        Label(win, textvariable=importdir, bg='white',
              justify=RIGHT).pack(fill=BOTH, side=TOP)
        Button(win, text='Select Directory', command=getdir).pack(fill=BOTH,
                                                                  side=TOP)
        filetype = StringVar()
        filetype.set('any')
        optmenu = Pmw.OptionMenu(win,
                                 labelpos='w',
                                 label_text='File Type:',
                                 menubutton_textvariable=filetype,
                                 items=self.extensions.keys(),
                                 menubutton_width=10)
        optmenu.pack(fill=BOTH, side=TOP)
        Button(win, text='Import', command=doimport).pack(fill=BOTH, side=TOP)
        Button(win, text='Cancel', command=close).pack(fill=BOTH, side=TOP)

        return

    def exportExtFiles(self, DB):
        """Get all stored ext files in DB and save to folder"""
        import tkFileDialog, os, shutil
        expdir = tkFileDialog.askdirectory(initialdir=os.getcwd(),
                                           title='Select a directory',
                                           mustexist=1,
                                           parent=self.parent.master)
        if not expdir:
            return
        path = os.path.join(expdir, 'peat-export')
        if not os.path.exists(path):
            os.mkdir(path)
        count = 0
        files = DB.getExtFilenames()
        for f in files:
            shutil.copyfile(files[f], os.path.join(path, f))
            count += 1
        tkMessageBox.showinfo("Exported",
                              'Done. Exported %s files to\n%s' % (count, path))
        return

    def displayExtFiles(self, DB):
        """Display blobs in DB as web page links"""
        files = DB.getExtFilenames()
        print files
        if len(files) == 0:
            return
        items = []
        for f in files:
            print f, files[f]
            items.append('<a href=%s>%s</a>' % (files[f], f))
        import markup
        page = markup.page()
        page.init(title="PEATDB Files Preview",
                  css=('one.css'),
                  header="Preview for project",
                  footer="PEATDB")
        page.ul(class_='mylist')
        page.li(items, class_='myitem')
        page.ul.close()

        filename = '/tmp/prevtemp.html'
        hf = open(filename, 'w')
        for c in page.content:
            hf.write(c)
        hf.close()
        import webbrowser
        webbrowser.open(filename, autoraise=1)
        return
예제 #4
0
파일: Extfile.py 프로젝트: shambo001/peat
class FileHandler(object):
    """Class to handle external files for peatdb, uses some stuff from
       old peat from db_actions etc
       Should add thumbnail stuff here??"""

    extensions = {'image' : ['.jpg','.jpeg','.tiff','.tif','.gif','.ps','.png','.ico'],
                  'doc' : ['.doc','.xls','.ppt','.pdf','.docx','.txt','.csv','.odt'],
                  'compressed' : ['.zip','.gz','.bz','.tar'],
                  'any':''}

    def __init__(self, parent=None, DB=None):
        self.parent = parent
        self.currplatform = platform.system()

        return

    def displayFile(self, filerec):
        """Uses a new method of file storage with blobs"""
        #now we just get the blob from the filerecord object...
        from PILView import PILViewer
        from PEATDB.Record import FileRecord
        #check class        
        if not type(filerec) is FileRecord:           
            return False
        myblob = filerec.blob
        ext = filerec.ext
        mtype = filerec.mimetype
        print 'mimetype is', mtype
        if myblob != None:
            f = myblob.open("r")
            filename = f.name
            f.close()
        else:
            return False

        if self.currplatform == 'Linux':
            #try using mailcaps on linux system
            import mailcap, os
            d=mailcap.getcaps()
            print mtype, filename
            f=mailcap.findmatch(d, mtype)[1]
            os.system(f['view'] %filename)
            return
        else:
            import os, tempfile, shutil
            tempname = os.path.normpath(os.path.join(tempfile.gettempdir(), filerec.name))
            if not os.path.exists(tempname):
                #os.remove(tempname)
                shutil.copy(filename, tempname)
            os.startfile(tempname)

        return True

    def addFileDialog(self, filerec=None):
        """Do the front-end stuff for adding files to peat"""
        import tkFileDialog
        filename=tkFileDialog.askopenfilename(defaultextension='.*',
                                              initialdir=os.getcwd(),
                                              filetypes=[("All files","*.*")])
        self.newfile = filename
        return filename


    def importFileset(self, DB, parentframe=None, callback=None):
        """Import a series of external files in a folder to peat"""

        def getdir():
            import tkFileDialog, os
            d=tkFileDialog.askdirectory(initialdir=importdir.get(),title='Select directory files',
                                                mustexist=1,parent=self.parent.master)
            if d:
                importdir.set(d)
                return

        def doimport():
            idir = importdir.get()
            ext = filetype.get()
            if idir == None:
                return
            files = os.listdir(idir)
            okfiles = []
            for f in files:
                pth = os.path.join(idir,f)
                if os.path.isfile(pth):
                    if ext != 'any':
                        if os.path.splitext(pth)[1] not in self.extensions[ext]:
                            continue
                    okfiles.append(pth)
            print 'files to be used:', okfiles
            DB.addField('file', 'File')
            from Dialogs import PEATDialog
            self.pb=PEATDialog(self.parent.master, option='progressbar',
                                          message='Importing files')
            self.pb.update_progress(0)
            total = len(okfiles)
            row=0
            #iterate over filenames in folder and add one rec to DB for each file
            for f in okfiles:
                recname=os.path.basename(f)
                DB.addBlob(recname, 'file', f)
                print 'added %s as %s' %(f,recname)
                row=row+1
                c=float(row)/float(total)*100.0
                self.pb.update_progress(c)
            self.pb.close()
            if callback!=None:
                callback()
            return

        def close():
            win.destroy()
            return

        if parentframe!=None:
            win = Frame(master=parentframe,relief=RAISED)
            win.pack(fill=BOTH)
        else:
            win = Toplevel()
            win.title('Import ext files')

        importdir=StringVar(); importdir.set(os.getcwd())
        Label(win,textvariable=importdir,bg='white',justify=RIGHT).pack(fill=BOTH,side=TOP)
        Button(win,text='Select Directory',command=getdir).pack(fill=BOTH,side=TOP)
        filetype=StringVar(); filetype.set('any')
        optmenu = Pmw.OptionMenu (win,
                labelpos = 'w',
                label_text = 'File Type:',
                menubutton_textvariable = filetype,
                items = self.extensions.keys(),
                menubutton_width = 10 )
        optmenu.pack(fill=BOTH,side=TOP)
        Button(win,text='Import',command=doimport).pack(fill=BOTH,side=TOP)
        Button(win,text='Cancel',command=close).pack(fill=BOTH,side=TOP)

        return

    def exportExtFiles(self, DB):
        """Get all stored ext files in DB and save to folder"""
        import tkFileDialog, os, shutil
        expdir=tkFileDialog.askdirectory(initialdir=os.getcwd(),title='Select a directory',
                                          mustexist=1,parent=self.parent.master)
        if not expdir:
            return
        path = os.path.join(expdir,'peat-export')
        if not os.path.exists(path):
            os.mkdir(path)
        count=0
        files = DB.getExtFilenames()
        for f in files:
            shutil.copyfile(files[f], os.path.join(path, f))
            count+=1
        tkMessageBox.showinfo("Exported",
                             'Done. Exported %s files to\n%s'%(count,path))
        return

    def displayExtFiles(self, DB):
        """Display blobs in DB as web page links"""
        files = DB.getExtFilenames()
        print files
        if len(files) == 0:
            return
        items=[]
        for f in files:
            print f, files[f]
            items.append('<a href=%s>%s</a>' %(files[f],f)
                         )
        import markup
        page = markup.page( )
        page.init( title="PEATDB Files Preview",
                   css=( 'one.css' ),
                   header="Preview for project",
                   footer="PEATDB" )
        page.ul( class_='mylist' )
        page.li( items, class_='myitem' )
        page.ul.close()

        filename = '/tmp/prevtemp.html'
        hf = open(filename,'w')
        for c in page.content:
            hf.write(c)
        hf.close()
        import webbrowser
        webbrowser.open(filename, autoraise=1)
        return