In a previous post, I mentioned looking for some code implementing asynchronous operations that you can then attach a progress bar to.
I didn't end up finding anything, so as part of the ripping code I'm writing I prototyped a simple approach to it.
It's working nicely already; I have the basic class for a Task, a class for MultiTasks, and two runners - a command-line blocking one and a GtkProgressBar-using widget.
Here's the code if you're interested. You can run that file to see a simple DummyTask (one that takes 10 seconds to complete) progressing on the command line. Another example you can run (for which you need to check out the whole code) is examples/gtkchecksum.py which checksums decoded audio data using GStreamer and shows you a GTK+ progress bar. An even better example (but you'll need a complete CD rip with matching .cue file) is the ARcue.py program, which calculates AccurateRip checksums and compares them against the online database, and you can choose whether you want to run it in cli or gtk mode.
The cli one uses a GObject main loop to make the asynchronous code seem blocking again. I could easily add a Twisted reactor-using runner, but haven't needed it yet. Also, the one big annoyance I have with the otherwise excellent Twisted is the fact that you can't do much at all without the ugly 'global variable' that is the reactor.
I don't think I'm completely happy with these classes yet. I realized last week that unconsciously I was again moving towards an MVC approach with this, and realizing that also made me realize I'm not yet there. If you consider the Task the Model, then the Runner is currently both the View and Controller. I will probably need to split out the View part again, so I can attach multiple Views to the Model that is the task.
Also, I need to add a way to report on errors while executing the task, I'm considering adding timing statistics and finish estimation, and maybe something that allows doing global progress and subtask progress, the way ripping programs do too (showing current track percentage and complete disc percentage). Not sure how much I want to overengineer it though.
Feel free to comment, suggest improvements, or show me similar concepts and implementations!
In a previous post, I mentioned looking for some code implementing asynchronous operations that you can then attach a progress bar to. I didn't end up finding anything, so as...