def __erase(self):
     """
     Private slot to handle the erase context menu action.
     
     This method erases the collected coverage data that is
     stored in the .coverage file.
     """
     cover = coverage(data_file = self.cfn)
     cover.use_cache(True)
     cover.load()
     cover.erase()
     
     self.reloadButton.setEnabled(False)
     self.resultList.clear()
     self.summaryList.clear()
 def __annotate(self):
     """
     Private slot to handle the annotate context menu action.
     
     This method produce an annotated coverage file of the
     selected file.
     """
     itm = self.resultList.currentItem()
     fn = unicode(itm.text(0))
     
     cover = coverage(data_file = self.cfn)
     cover.use_cache(True)
     cover.exclude(unicode(self.excludeList[0]))
     cover.load()
     cover.annotate([fn], None, True)
 def __annotateAll(self):
     """
     Private slot to handle the annotate all context menu action.
     
     This method produce an annotated coverage file of every
     file listed in the listview.
     """
     amount = self.resultList.topLevelItemCount()
     if amount == 0:
         return
     
     # get list of all filenames
     files = []
     for index in range(amount):
         itm = self.resultList.topLevelItem(index)
         files.append(unicode(itm.text(0)))
     
     cover = coverage(data_file = self.cfn)
     cover.use_cache(True)
     cover.exclude(unicode(self.excludeList[0]))
     cover.load()
     
     # now process them
     progress = KQProgressDialog(self.trUtf8("Annotating files..."), 
         self.trUtf8("Abort"), 0, len(files), self)
     progress.setMinimumDuration(0)
     count = 0
     
     for file in files:
         progress.setValue(count)
         if progress.wasCanceled():
             break
         cover.annotate([file], None)#, True)
         count += 1
     
     progress.setValue(len(files))
 def start(self, cfn, fn):
     """
     Public slot to start the coverage data evaluation.
     
     @param cfn basename of the coverage file (string)
     @param fn file or list of files or directory to be checked
             (string or list of strings)
     """
     self.__cfn = cfn
     self.__fn = fn
     
     self.basename = os.path.splitext(cfn)[0]
     
     self.cfn = "%s.coverage" % self.basename
     
     if type(fn) is types.ListType:
         files = fn
         self.path = os.path.dirname(cfn)
     elif os.path.isdir(fn):
         files = Utilities.direntries(fn, True, '*.py', False)
         self.path = fn
     else:
         files = [fn]
         self.path = os.path.dirname(cfn)
     files.sort()
     
     cover = coverage(data_file = self.cfn)
     cover.use_cache(True)
     cover.load()
     
     # set the exclude pattern
     self.excludeCombo.clear()
     self.excludeCombo.addItems(self.excludeList)
     
     self.checkProgress.setMaximum(len(files))
     QApplication.processEvents()
     
     total_statements = 0
     total_executed = 0
     
     cover.exclude(unicode(self.excludeList[0]))
     progress = 0
     
     try:
         # disable updates of the list for speed
         self.resultList.setUpdatesEnabled(False)
         self.resultList.setSortingEnabled(False)
         
         # now go through all the files
         for file in files:
             if self.cancelled:
                 return
             
             statements, excluded, missing, readable  = cover.analysis2(file)[1:]
             readableEx = excluded and self.__format_lines(excluded) or ''
             n = len(statements)
             m = n - len(missing)
             if n > 0:
                 pc = 100.0 * m / n
             else:
                 pc = 100.0
             self.__createResultItem(file, str(n), str(m), pc, readableEx, readable)
             
             total_statements = total_statements + n
             total_executed = total_executed + m
             
             progress += 1
             self.checkProgress.setValue(progress)
             QApplication.processEvents()
     finally:
         # reenable updates of the list
         self.resultList.setSortingEnabled(True)
         self.resultList.setUpdatesEnabled(True)
         self.checkProgress.reset()
     
     # show summary info
     if len(files) > 1:
         if total_statements > 0:
             pc = 100.0 * total_executed / total_statements
         else:
             pc = 100.0
         itm = QTreeWidgetItem(self.summaryList, QStringList() \
             << str(total_statements) << str(total_executed) << "%d%%" % pc)
         for col in range(0, 3):
             itm.setTextAlignment(col, Qt.AlignRight)
     
     self.__finish()