[packagekit] Python GTK widgets and async client
Sebastian Heinlein
glatzor at ubuntu.com
Fri Oct 31 08:54:22 PDT 2008
Hello,
I hacked on the PyGTK widgets recently. I run into the problem that I
need a lot more async data than what the progress callback of the
current client could provide. E.g. I would like to show reported
packages immediately in the TreeView or show the status of a transaction
as soon at it gets started.
* Async methods
So I added the PackageKitTransaction class to packagekit.client. If a
client method is called with the async=True parameter the method will
return a PackageKitTransaction instance which was not yet started
instead of the results.
PackageKitTransaction now does all the signal wrapping and holds a
reference to the DBus interface of the corresponding transaction. This
allows me to hook the widgets to a transaction before running it. The
transaction can be started by calling run(). The run method also has got
a wait parameter, which allows to still run the transaction
synchronously. So I am not sure if the naming of the async parameter is
correct. :)
Do you agree with this approach? Is there a better name for the
parameter async? Should I use different methods instead: e.b.
SearchNameAsync?
I haven't converted all client methods to the new API since I wanted to
wait for feedback.
* PyGTK widgets
I introduced the python modules genums and widgets which are shipped in
gnome-packagekit. The first one is an automatically created python
version of gpk-enum.c. The later one contains the following widgets:
* PackageKitCancelButton
* PackageKitStatusIcon
* PackageKitStatusAnimation
* PackageKitStatusLabel
* PackageKitProgressBar: The run method also runs the associated
transaction.
* PackageKitMessageDialog
* PackageListStore :An enhanced gtk.ListStore which holds the
corresponding PackageKitPackage instances of Package signals which have
been emitted by a transaction.
* PackageListView: Renders the content of the above PackageListStore.
Except of the PackageListView all widgets are connected to a transaction
by using the transaction parameter with a PackageKitTransaction instance
at creation time or the set_transaction method afterwards.
Here is a code example how to refresh the cache, show the progress in a
dialog and handle errors in an error dialog:
pk = PackageKitClient()
trans = pk.RefreshCache(async=True)
dialog = PackageKitProgressDialog(transaction=trans, parent=win)
try:
dialog.run()
except PackageKitError, e:
msg = PackageKitMessageDialog(enum=e.error, details=e.desc,
parent=win)
msg.run()
msg.hide()
dialog.hide()
The widgets module provides a fully working test application, which can
search, refresh, get updates, install and remove packages.
You can find the code in the async-client branch of PackageKit and the
python-widgets branch of gnome-packagekit. The branches are some days
behind master.
Cheers,
Sebastian
More information about the PackageKit
mailing list