The util module#

Various utility classes and functions.

class Job(function, finished=None, with_result=False)[source]#

Bases: QThread

Simple QThread helper that runs a function in a background thread.

If you specify a finished callable, it will be called when the function has finished. If with_result is True, the finished callable will be called with the result of the function.

The job is started immediately. You do not need to store the job, it will keep a reference itself as long as it is running.

run()[source]#

Run the function and store the result.

class SingleInstance(parent, *args, **kwargs)[source]#

Bases: QObject

Keeps a single instance around for another object.

We keep only a weak reference to the object, if the object is garbage collected, we disappear as well.

classmethod instance(parent, *args, **kwargs)[source]#

Get or create the instance for parent.

classmethod delete_instance(parent)[source]#

Actively remove the stored instance.

classmethod get_instance(parent)[source]#

Return the instance if it already exists, else returns None.

delete()[source]#

Delete the stored reference to ourself.

Other cleanup code could be added by reimplementing this method. This is not called on garbage collection, but only when called directly or via delete_instance().

call_async(function, finished=None)[source]#

Call function() in a background thread and then finished() when done in the main thread.

call_async_with_result(function, finished=None)[source]#

Call result = function() in a background thread and then finished(result) when done in the main thread.