(self, function, filter=lambda: True, *args, **kwargs)
call function once for each sheet and display a progressbar
call function once for each sheet and display a progressbar
call function once for each sheet and display a progressbar
def iterate_progressbar(self, function, filter=lambda: True, *args, **kwargs):
        '''call function once for each sheet and display a progressbar
        '''
        with self._db as con:
            c = con.cursor()
            c.execute('SELECT count(*) FROM sheets WHERE survey_rowid=?', (self._survey_rowid,))
            count = c.fetchone()[0]

            # The old code used to first filter, and then run; but that is
            # a bit ineffective in a way
            print(ungettext('%i sheet', '%i sheets', count) % count)
            if count == 0:
                return

            log.progressbar.start(count)

            processed = 0
            c.execute('SELECT rowid FROM sheets WHERE survey_rowid=? ORDER BY sort,rowid', (self._survey_rowid,))
            for index, (sheetid,) in enumerate(c.fetchall()):
                self.goto_sheet(self._db_get_sheet(sheetid))
                if filter():
                    function(*args, **kwargs)
                    processed += 1

                log.progressbar.update(index + 1)

        print(_('Processed %i of %i sheets, took %f seconds') % (processed, count, log.progressbar.elapsed_time))
def iterate_progressbar ( self , function , filter = lambda : True , * args , * * kwargs ) : with self . _db as con : c = con . cursor ( ) c . execute ( 'SELECT count(*) FROM sheets WHERE survey_rowid=?' , ( self . _survey_rowid , ) ) count = c . fetchone ( ) [ 0 ] # The old code used to first filter, and then run; but that is # a bit ineffective in a way print ( ungettext ( '%i sheet' , '%i sheets' , count ) % count ) if count == 0 : return log . progressbar . start ( count ) processed = 0 c . execute ( 'SELECT rowid FROM sheets WHERE survey_rowid=? ORDER BY sort,rowid' , ( self . _survey_rowid , ) ) for index , ( sheetid , ) in enumerate ( c . fetchall ( ) ) : self . goto_sheet ( self . _db_get_sheet ( sheetid ) ) if filter ( ) : function ( * args , * * kwargs ) processed += 1 log . progressbar . update ( index + 1 ) print ( _ ( 'Processed %i of %i sheets, took %f seconds' ) % ( processed , count , log . progressbar . elapsed_time ) )