PyANGKernel.GKTask

class GKTask

A class for tasks

Details

These tasks are used by Aimsun operations to give the user feedback on the amount of time required to complete the task. It allows also the cancel of such task.

The user will create a new task using the createTask . From this method the developer will set the label of the task (File Loading for example), the number of steps to complete the task (the simulation steps, the length of a file in kilobytes,…), the minimum step to refresh the task or the time between updates, if the task can be cancelled (if not the Cancel button will not appear) and if the dialog will process events (if it will refresh the GUI).

To start a task the developer has to call start() .

The current implementation refreshes the GUI each stepsToUpdate or timeToUpdate depending on what the user set.

After creating the dialog the developer must call stepTask to inform the dialog that the step N has been done. This method will return true if the task has been cancelled.

When a task is complete the developer has to call GKTask::end().

Example:

GKModel                         *model;
GTask                           *task;
uint                            i;
bool                            cancelled = false;

task = GKSystem::getSystem().createTask();
task->setName( tr( "Doing 10 Steps" ) );
task->setTotalSteps( 10 );
task->start();

for( i = 0; cancelled == false && i < 10; i++ ){
        // do something that requires some time...
        cancelled = task->stepTask( i );
}

task->end();

Inheritance diagram of PyANGKernel.GKTask

Synopsis

Methods

Signals

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

class Mode

The task mode: - eModal: No other task can be done. Update GUI (if available) from time to time. This is the default one. - eSemiInteractive: Other task can be started (if possible). Update GUI on every step - eInteractive: A task that can be controlled by the user. Update GUI on every step.

class Storable
__init__(_modelUID[, uid=""])
Parameters:
  • _modelUIDQUuid

  • uid – str

Creates a task that will perform work on the given model

addAlwaysEditableType(type)
Parameters:

typeGKType

Adds a GKType exception to model edition

addSubTask(iModel)
Parameters:

iModelGKModel

Return type:

GKTask

Add sub task

allowUserInput()
Return type:

bool

Returns true if user input should be processed during the ui update. true by default.

cancel()

Cancels the task if it can be canceled

disableModelEdition()

Marks this task as one whose execution forbids modifications on existing objects

end([store=GKTask.Storable.eDoStore])
Parameters:

storeStorable

failed(errorMsg)
Parameters:

errorMsg – str

Mark this task as failed

getCancelable()
Return type:

bool

Gets if the task can be canceled or not

getErrorMessage()
Return type:

str

If the task failed, the reason as set when calling failed

getExecutionInfo()
Return type:

str

Gets the execution info of the task.

getInteractiveTime()
Return type:

QDateTime

In an interactive task, the time in where the task is. For example, for Aimsun Next Micro the simulation time.

getInterativeExtension()
Return type:

QDialog

The extension widget that will control the task.

getInternalName()
Return type:

str

The internal (cannot be translated) name of the task

getIsMultiTask()
Return type:

bool

getMode()
Return type:

Mode

The task mode.

See also

Mode

getModelUID()
Return type:

QUuid

Returns the UID of the model that creates this task or a empty string for system tasks

getName()
Return type:

str

Gets the name of the task

getShowExtensionOnClose()
Return type:

bool

Returns the value set with setShowExtensionOnClose .

getSingleDay()
Return type:

bool

UnknownCommand setSingleDay

getStartTime()
Return type:

QDateTime

When this task was started.

getState()
Return type:

str

Gets the state of the task.

getStepsDone()
Return type:

int

Steps done in this task

getSubTasks()
Return type:

.list of QString

Get the sub task ids of this task

getTargetId()
Return type:

int

The target id. The target id the object in where we are doing the task.

getTimeUpdate()
Return type:

float

getTotalSteps()
Return type:

int

Gets the number of steps the task is divided in

getUID()
Return type:

str

getUUID()
Return type:

str

Returns the unique identifier of this task (generated using QUuid::createUuid())

isEditionAllowed(type)
Parameters:

typeGKType

Return type:

bool

Indicates if objects can be modified while this task is active

isInternal()
Return type:

bool

Don’t notify this task to external apps

isQuick()
Return type:

bool

Returns true if the task is quick. UnknownCommand setQuick

multiTaskEnd()
multiTaskStart()
percentageDone(percentage)
Parameters:

percentage – int

refresh()

Emit a stepDone witg update = true to refresh the status (in the GUI)

secondToFinish()
Return type:

int

Seconds required to finish this task (a guess). Returns -1 if it cannot guess because no times have been given in stepTask or because too few steps have been done

setAllowUserInput(allow)
Parameters:

allow – bool

Configures if on the ui update the user inputs should be allowed or ignored.

See also

allowUserInput()

setCancelable(cancelable)
Parameters:

cancelable – bool

Sets if the task can be canceled or not. Tasks are cancelable by default.

setExecutionInfo(info)
Parameters:

info – str

Sets extra execution info for this task. It is task dependand but usually has information related a simulation (iterations info, vehs in/out…) in JSON format.

setInteractiveTime(dt)
Parameters:

dtQDateTime

In an interactive task, the time in where the task is. For example, for Aimsun Next Micro the simulation time.

setInteractiveWidget(extension)
Parameters:

extensionQDialog

Mark this task as interactive as set the widget that wil control it.

setInternal()

Don’t notify this task to external apps

See also

isInternal()

setInternalName(aname)
Parameters:

aname – str

The internal (cannot be translated) name of the task

setIsMultiTask(isMultiTask)
Parameters:

isMultiTask – bool

setMode(mode)
Parameters:

modeMode

The task mode.

See also

Mode

setModelUID(uid)
Parameters:

uidQUuid

Set the model uid (if not set in the GKTask constructor)

setName(aname)
Parameters:

aname – str

Sets the name of the task.

setParent(uuid)
Parameters:

uuid – str

Parent task, if this is a subtask

See also

parent()

setQuick(isQuick)
Parameters:

isQuick – bool

Sets the task as quick (needn’t a long-time process).

Note

Setting the task as quick won’t make it faster to process ! it will just let know other objects (f.ex, the UI) that this task is likely to be processed very fast, quick.

See also

isQuick()

setShowExtensionOnClose(show)
Parameters:

show – bool

Sets if the task should display its GKTaskExtensionWrapper informations on ending. *

Note

This value only has an effect when the task has a GKTaskExtensionWrapper. * * Default: true

setSingleDay(value)
Parameters:

value – bool

For interactive task, sim will run between days? If so, we will show the date.

setStartTime(time)
Parameters:

timeQDateTime

Overwrites the start time. Usually not required as the start time is set automatically.

setState(astate)
Parameters:

astate – str

Sets the state of the task. This can be used to show a long task passing between one state and other, for example, first set the state to “Processing input” and then to “Generating the report”. State is not mandatory to be set.

setStepsUpdate(steps)
Parameters:

steps – int

Set the number of steps that pass between task updates. If the developer uses this method he should not call setTimeUpdate .

If steps is -1 then the dialog will be updated every 5% of the task. This is the default value if neither setTimeUpdate nor setStepsUpdate are called. If steps is 0 the update will be every time the developer calls stepTask

setSubTasks(_subTasks)
Parameters:

_subTasks – .list of QString

This task is a composition of tasks with ids in _subTasks

setTargetId(id)
Parameters:

id – int

The target id. The target id the object in where we are doing the task.

setTimeUpdate(seconds)
Parameters:

seconds – float

Set the number of seconds (or fraction) that pass between task updates. If the developer uses this method he should not call setStepsUpdate .

setTotalSteps(atotal)
Parameters:

atotal – int

Set the number of steps (the simulation steps, the length of a file in kilobytes,…) in which this task can be divided.

start()

Starts the task with the given extension and milliseconds to remain hidden

stateChanged()
statsInterval(currentStatInterval, currentDetecInterval, aggregatedInterval)
Parameters:
  • currentStatInterval – int

  • currentDetecInterval – int

  • aggregatedInterval – bool

The process in the task has calculated some statistical data. After this call this data can be read

statsIntervalDone(currentStatInterval, currentDetecInterval, aggregatedInterval)
Parameters:
  • currentStatInterval – int

  • currentDetecInterval – int

  • aggregatedInterval – bool

stepDone(update)
Parameters:

update – bool

stepTask()
Return type:

bool

Inform that one step in the task have been done. This method will return true if the task has been cancelled.

stepTask(progress[, seconds=-1.0])
Parameters:
  • progress – int

  • seconds – float

Return type:

bool

Inform that step “progress” in the task have been done. This method will return true if the task has been cancelled.

The last parameters (if non interactive) tells the task the amount of time used to perform these steps. If it is -1.0 means that no time has been calculated. If a time is provided (and then it must be provided for every call), then the task will calculated the aproximated duration of the operation.

If interactive this parameter will not be use

stop()

prepares the task to be stopped

taskCanceled()
taskEnded()
taskFailed(errorMessage)
Parameters:

errorMessage – str

taskStarted()
taskStopped()
taskTime()
Return type:

float

Seconds needed to complete the task (when finished) or second that this task has been running.

wasCancelled()
Return type:

bool

Returns true if the task been canceled

wasStopped()
Return type:

bool

returns whether the task is stopped or not