dicogis.publishing.qgis_task module¶
Run a publication in a QgsTask: how QGIS expects long operations to run.
Imports QGIS: to be imported only once running inside QGIS. Out of dicogis.ui, whose modules reach Qt and QGIS through dicogis.ui.qt_compat only.
- class dicogis.publishing.qgis_task.PublishTask(description, publish_function, on_finished, on_error)¶
Bases:
QgsTaskRuns a publication in the background of QGIS.
- __init__(description, publish_function, on_finished, on_error)¶
Prepare the task.
- Parameters:
description (
str) – what the task manager showspublish_function (
Callable[[ProgressReporter,QgsFeedback],PublishReport]) – runs the publication, with a progress reporter and a feedback interrupting the running request when canceledon_finished (
Callable[[PublishReport],None]) – called in the main thread with the reporton_error (
Callable[[str],None]) – called in the main thread with the error message
- finished(result)¶
Tell the outcome, in the main thread.
- class dicogis.publishing.qgis_task.TaskProgressReporter(task)¶
Bases:
objectProgressReporter on top of QgsTask.setProgress() and QgsTask.isCanceled().
- __init__(task)¶
Bind the reporter to its task.
- Parameters:
task (
QgsTask) – running task
- increment(amount=1)¶
Increment the progress counter, as a percentage for the task manager.
- Return type:
- request_cancel()¶
Ask the task to stop, like the cancel button of the task manager.
- Return type:
- set_message(message)¶
Log the message: the task manager only shows the task’s description.
- Return type:
- dicogis.publishing.qgis_task.start_publish_task(description, publish_function, on_finished, on_error)¶
Hand a publication over to the task manager of QGIS.
- Parameters:
description (
str) – what the task manager showspublish_function (
Callable[[ProgressReporter,QgsFeedback],PublishReport]) – see PublishTaskon_finished (
Callable[[PublishReport],None]) – see PublishTask
- Return type:
- Returns:
the task, a reference to keep as long as it’s running