PEATDB/IO.py
def doImport(self, event=None):
        """This does the import using the current dialog options
           and shows a preview. Only works within GUI context."""

        lines = self.lines
        data = []
        #set up start row        
        try:
            self.startnum = int(self.linenum.get())
        except:
            self.startnum = 0
        if self.startnum < 0 or self.startnum > len(lines):
            return -1
        #set up cols
        self.colnames = []
        s = self.separator.get()
        if s == '':
            s=' '

        line = lines[self.startnum].replace('#','')

        if self.column_row.get() == 0:
            if s == ' ':
                #splits by any non-single whitespace
                self.colnames = string.split(line)
            else:
                self.colnames=string.split(string.strip(line), s)
            self.do_checkboxes()
        #data in rows
        else:
            if self.xinfirstcol.get() == 1:   #use first row as x-column
              
                self.colnames = ['x','y']
            else:
                #x and y cols are in every row, so use manual entry of no cols
                print self.numcolsinrow.get()
                self.colnames=range(self.numcolsinrow.get())
            print 'self.colnames', self.colnames
            self.do_checkboxes()

        self.previewtext.component('columnheader').delete("1.0",END)
        headerline=''
        for c in range(len(self.colnames)):
            headerline = headerline + '%-7s   ' %self.colnames[c]
        self.previewtext.component('columnheader').insert('0.0', headerline)
        if self.column_row.get() == 0:
            #data in cols
            self.numrows = len(lines)
            self.previewtext.delete("1.0",END)
            for row in range(self.startnum, self.numrows):
                line = string.strip(lines[row])
                rowdata={}
                if self.ignorecomments.get() == 1 and line.startswith('#'):
                    continue
                else:
                    line = line.replace('#','')
                textline = ''
                if s == ' ':
                    items=string.split(line)
                else:
                    items=string.split(line, s)
                for c in range(len(items)):
                    textline = textline + '%-7s   ' %items[c]
                    colname = self.colnames[c]
                    rowdata[colname] = items[c]
                self.previewtext.insert(END, textline+ '\n')
                data.append(rowdata)
        else:
            #data in rows
            line = string.strip(lines[self.startnum])
            if s == 'tab':
                s='\t'
            xdata = string.split(line,s)
            self.numrows = len(xdata)
            print 'xdata',xdata
            print self.numrows
            datasets={}
            for row in range(self.startnum+1, len(lines)):
                line = string.strip(lines[row])
                if self.ignorecomments.get() == 1 and line.startswith('#'):
                    continue
                else:
                    line = line.replace('#','')
                items = string.split(line,s)
                name=items[0]
                data.remove(name)
                if len(data) >0:
                    datasets[name] = items
         
            self.previewtext.delete("1.0",END)
            
            #  Sort the datasets by name            
            datanames=datasets.keys()
            datanames.sort()
            for name in datanames:
                self.previewtext.insert(END, 'Dataset: ' + name + '\n')
                textline = ''
                for i in range(self.numrows):
                    try:
                        textline = str(xdata[i]) + '%+10s   ' %datasets[name][i]
                    except:
                        textline = ' '
                    self.previewtext.insert(END, textline + '\n')
                self.previewtext.insert(END, '---------------' + '\n')
            #keep ref to these 2 for import
            self.inrows_datasets = datasets
            self.inrows_xdata = xdata
        #print data
        self.data = data
        return 1
This does the import using the current dialog options
           and shows a preview. Only works within GUI context.
This does the import using the current dialog options
and shows a preview. Only works within GUI context.
This does the import using the current dialog options and shows a preview . Only works within GUI context .
def doImport(self, event=None):
        lines = self.lines
        data = []
        try:
            self.startnum = int(self.linenum.get())
        except:
            self.startnum = 0
        if self.startnum < 0 or self.startnum > len(lines):
            return -1
        self.colnames = []
        s = self.separator.get()
        if s == '':
            s=' '
        line = lines[self.startnum].replace('#','')
        if self.column_row.get() == 0:
            if s == ' ':
                self.colnames = string.split(line)
            else:
                self.colnames=string.split(string.strip(line), s)
            self.do_checkboxes()
        else:
            if self.xinfirstcol.get() == 1:   
                self.colnames = ['x','y']
            else:
                print self.numcolsinrow.get()
                self.colnames=range(self.numcolsinrow.get())
            print 'self.colnames', self.colnames
            self.do_checkboxes()
        self.previewtext.component('columnheader').delete("1.0",END)
        headerline=''
        for c in range(len(self.colnames)):
            headerline = headerline + '%-7s   ' %self.colnames[c]
        self.previewtext.component('columnheader').insert('0.0', headerline)
        if self.column_row.get() == 0:
            self.numrows = len(lines)
            self.previewtext.delete("1.0",END)
            for row in range(self.startnum, self.numrows):
                line = string.strip(lines[row])
                rowdata={}
                if self.ignorecomments.get() == 1 and line.startswith('#'):
                    continue
                else:
                    line = line.replace('#','')
                textline = ''
                if s == ' ':
                    items=string.split(line)
                else:
                    items=string.split(line, s)
                for c in range(len(items)):
                    textline = textline + '%-7s   ' %items[c]
                    colname = self.colnames[c]
                    rowdata[colname] = items[c]
                self.previewtext.insert(END, textline+ '\n')
                data.append(rowdata)
        else:
            line = string.strip(lines[self.startnum])
            if s == 'tab':
                s='\t'
            xdata = string.split(line,s)
            self.numrows = len(xdata)
            print 'xdata',xdata
            print self.numrows
            datasets={}
            for row in range(self.startnum+1, len(lines)):
                line = string.strip(lines[row])
                if self.ignorecomments.get() == 1 and line.startswith('#'):
                    continue
                else:
                    line = line.replace('#','')
                items = string.split(line,s)
                name=items[0]
                data.remove(name)
                if len(data) >0:
                    datasets[name] = items
            self.previewtext.delete("1.0",END)
            datanames=datasets.keys()
            datanames.sort()
            for name in datanames:
                self.previewtext.insert(END, 'Dataset: ' + name + '\n')
                textline = ''
                for i in range(self.numrows):
                    try:
                        textline = str(xdata[i]) + '%+10s   ' %datasets[name][i]
                    except:
                        textline = ' '
                    self.previewtext.insert(END, textline + '\n')
                self.previewtext.insert(END, '---------------' + '\n')
            self.inrows_datasets = datasets
            self.inrows_xdata = xdata
        self.data = data
        return 1
def doImport ( self , event = None ) : lines = self . lines data = [ ] try : self . startnum = int ( self . linenum . get ( ) ) except : self . startnum = 0 if self . startnum < 0 or self . startnum > len ( lines ) : return - 1 self . colnames = [ ] s = self . separator . get ( ) if s == '' : s = ' ' line = lines [ self . startnum ] . replace ( '#' , '' ) if self . column_row . get ( ) == 0 : if s == ' ' : self . colnames = string . split ( line ) else : self . colnames = string . split ( string . strip ( line ) , s ) self . do_checkboxes ( ) else : if self . xinfirstcol . get ( ) == 1 : self . colnames = [ 'x' , 'y' ] else : print self . numcolsinrow . get ( ) self . colnames = range ( self . numcolsinrow . get ( ) ) print 'self.colnames' , self . colnames self . do_checkboxes ( ) self . previewtext . component ( 'columnheader' ) . delete ( "1.0" , END ) headerline = '' for c in range ( len ( self . colnames ) ) : headerline = headerline + '%-7s   ' % self . colnames [ c ] self . previewtext . component ( 'columnheader' ) . insert ( '0.0' , headerline ) if self . column_row . get ( ) == 0 : self . numrows = len ( lines ) self . previewtext . delete ( "1.0" , END ) for row in range ( self . startnum , self . numrows ) : line = string . strip ( lines [ row ] ) rowdata = { } if self . ignorecomments . get ( ) == 1 and line . startswith ( '#' ) : continue else : line = line . replace ( '#' , '' ) textline = '' if s == ' ' : items = string . split ( line ) else : items = string . split ( line , s ) for c in range ( len ( items ) ) : textline = textline + '%-7s   ' % items [ c ] colname = self . colnames [ c ] rowdata [ colname ] = items [ c ] self . previewtext . insert ( END , textline + '\n' ) data . append ( rowdata ) else : line = string . strip ( lines [ self . startnum ] ) if s == 'tab' : s = '\t' xdata = string . split ( line , s ) self . numrows = len ( xdata ) print 'xdata' , xdata print self . numrows datasets = { } for row in range ( self . startnum + 1 , len ( lines ) ) : line = string . strip ( lines [ row ] ) if self . ignorecomments . get ( ) == 1 and line . startswith ( '#' ) : continue else : line = line . replace ( '#' , '' ) items = string . split ( line , s ) name = items [ 0 ] data . remove ( name ) if len ( data ) > 0 : datasets [ name ] = items self . previewtext . delete ( "1.0" , END ) datanames = datasets . keys ( ) datanames . sort ( ) for name in datanames : self . previewtext . insert ( END , 'Dataset: ' + name + '\n' ) textline = '' for i in range ( self . numrows ) : try : textline = str ( xdata [ i ] ) + '%+10s   ' % datasets [ name ] [ i ] except : textline = ' ' self . previewtext . insert ( END , textline + '\n' ) self . previewtext . insert ( END , '---------------' + '\n' ) self . inrows_datasets = datasets self . inrows_xdata = xdata self . data = data return 1
This does the import using the current dialog options
and shows a preview.
This does the import using the current dialog options and shows a preview .
"""This does the import using the current dialog options
           and shows a preview. Only works within GUI context.""" #set up start row         #set up cols #splits by any non-single whitespace #data in rows #use first row as x-column #x and y cols are in every row, so use manual entry of no cols #data in cols #data in rows #  Sort the datasets by name             #keep ref to these 2 for import #print data
self
event