View Single Post
Old 09-03-2012, 10:32 AM   #7
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,252
Karma: 16544692
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
At the risk of the blind leading the blind, this is what I did after having looked at kiwidude's Quality Check code.

I used a QProgressDialog rather than QProgressBar.

This was the dialog:

Code:
class CoverProgressDialog(QProgressDialog):

    def __init__(self, gui, total_books, some_more_params):
        self.total_books = total_books
        QProgressDialog.__init__(self, '', QString('Cancel'), 0, self.total_books, gui)
        self.gui = gui
        # ... ...
        self.i = 0
        # ... ...      
        QTimer.singleShot(0, self.do_book_action)
        self.exec_()

    def do_book_action(self):
        if self.wasCanceled():
            return self.do_close()
        if self.i >= self.total_books:
            return self.do_close()

        # code for processing a single book ...

        self.i += 1
        self.setLabelText('%d of %d' % (self.i, self.total_books))
        self.setValue(self.i)
        QTimer.singleShot(0, self.do_book_action)

    def do_close(self):
        self.hide()
        self.gui = None
and this was the code which called the dialog
Code:
dlg = CoverProgressDialog(self.gui, total_books, some_more_params)
if dlg.wasCanceled():
    # do whatever should be done if user cancelled
Hope this helps
jackie_w is offline   Reply With Quote