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: QgsTask

Runs 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 shows

  • publish_function (Callable[[ProgressReporter, QgsFeedback], PublishReport]) – runs the publication, with a progress reporter and a feedback interrupting the running request when canceled

  • on_finished (Callable[[PublishReport], None]) – called in the main thread with the report

  • on_error (Callable[[str], None]) – called in the main thread with the error message

cancel()

Interrupt the running request too, instead of waiting for its end.

Return type:

None

finished(result)

Tell the outcome, in the main thread.

Parameters:

result (bool) – what run() returned, False if it was canceled before starting

Return type:

None

run()

Run the publication, in the thread of the task: no widget allowed here.

Return type:

bool

Returns:

True if the publication ran to its end or was canceled along the way

class dicogis.publishing.qgis_task.TaskProgressReporter(task)

Bases: object

ProgressReporter 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:

None

is_canceled()

Whether the task has been asked to stop.

Return type:

bool

request_cancel()

Ask the task to stop, like the cancel button of the task manager.

Return type:

None

set_message(message)

Log the message: the task manager only shows the task’s description.

Return type:

None

set_total(total)

Set the total value of the progress counter.

Return type:

None

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:
Return type:

PublishTask

Returns:

the task, a reference to keep as long as it’s running