Please can someone help me with a Python problem?
In my user interface plugin's main processing file the basic code looks something like this
Code:
class CopyCoverUiAction(InterfaceAction):
... ...
def genesis(self): ... ...
def apply_settings(self): ... ...
... ...
def copycover_selected(self):
# some validation actions
# get user selected book rows
for book in range(len(rows)):
# process the book
# some end actions
# open a QTextBrowser info dialog to display results
The user cannot do anything during the processing until the final info dialog box is displayed and needs to be manually closed. I'd like to keep it this way.
However, for some devices the book looping can be quite lengthy if many books are selected (max 99), and from a user POV it can appear that calibre isn't doing anything and is unresponsive. So what I want to do is add some kind of progress bar pop-up, starting just before the loops start, ending just after the loops finish and being updated once at the end of each cycle.
I've tried to get a QProgressBar() working but I'm obviously doing it wrong. In fact I've tried so many different combinations that I'm now completely scrambled. For the sake of my sanity please can someone show me some sample code of how to set up a simple ProgressBar with appropriate signals/slots so that the bar opens, visibly updates at the completion of each cycle then closes without any user interaction. The limited amount of python/Qt sample code I've found on Google, if it works at all, is using timer intervals or other widgets to update the Progbar and I'm not sure that's what I need.
I've also looked at some calibre source code but am not able to see the wood for the trees.
I've managed to pick up (I think) some basics like
self.pb = QProgressBar(self)
self.pbar.setRange(0, len(rows))
self.pbar.setValue(int step)
but am totally unable to arrange them into something that works. I also know that event handling can be complex and my OOP skills are very limited. So if there is a simple, robust way forward I'd be most grateful.
P.S. In some of my own non-calibre python experiments I've had some success with progressive screen updating using this piece of magic code
QApplication.instance().processEvents() (thanks to chaley) but I'm not sure how to apply it in this case.