action — Camelot documentation

### Navigation

- index
- modules |
- next |
- previous |
- Camelot documentation »
- Camelot API »
- admin »

# action

class `camelot.admin.action.` `Action`

  An action has a set of attributes that define its appearance in the GUI.

  `name`

    The internal name of the action, this can be used to store preferences concerning the action in the settings

  These attributes are used at the default values for the creation of a `camelot.admin.action.base.State` object that defines the appearance of the action button. Subclasses of `Action` that require dynamic values for these attributes can reimplement the `Action.get_state` method.

  `verbose_name`

    The name as displayed to the user, this should be of type `camelot.core.utils.ugettext_lazy`

  `icon`

    The icon that represents the action, of type `camelot.view.art.Icon`

  `tooltip`

    The tooltip as displayed to the user, this should be of type `camelot.core.utils.ugettext_lazy`

  `modes`

    The modes in which an action can be triggered, a list of `Mode` objects.

  For each of these attributes there is a corresponding getter method which is used by the view. Subclasses of `Action` that require dynamic values for these attributes can reimplement the getter methods.

  `shortcut`

    The shortcut that can be used to trigger the action, this should be of type `camelot.core.utils.ugettext_lazy`

  An action has two important methods that can be reimplemented. These are `model_run()` for manipulations of the model and `gui_run()` for direct manipulations of the user interface without a need to access the model.

  `get_name`()

    Returns: | a string, by default the `name` attribute

  `get_shortcut`()

    Returns: | a `camelot.core.utils.ugettext_lazy`, by default the

    `shortcut` attribute

  `get_state`(model_context)

    This method is called inside the Model thread to verify if the state of the action widget visible to the current user.

    Parameters: | model_context – the context available in the Model thread
    Returns: | an instance of `camelot.action.base.State`

  `gui_run`(gui_context)

    This method is called inside the GUI thread, by default it executes the `model_run()` in the Model thread.

    Parameters: | gui_context – the context available in the GUI thread, of type `GuiContext`

  `render`(gui_context, parent)

    Create a widget to trigger the action. Depending on the type of gui_context and parent, a different widget type might be returned.

    Parameters: | gui_context – the context available in the GUI thread, a subclass of `camelot.action.GuiContext` parent – the parent `QtGui.QWidget`
    Returns: | a `QtGui.QWidget` which when triggered will execute the `gui_run()` method.

class `camelot.admin.action.` `ActionStep`

  A reusable part of an action. Action step object can be yielded inside the `model_run()`. When this happens, their `gui_run()` method will be called inside the GUI thread. The `gui_run()` can pop up a dialog box or perform other GUI related tasks.

  When the ActionStep is blocking, it will return control after the `gui_run()` is finished, and the return value of `gui_run()` will be the result of the `yield` statement.

  When the ActionStep is not blocking, the `yield` statement will return immediately and the `model_run()` will not be blocked.

  `blocking`

    a `boolean` indicating if the ActionStep is blocking, defaults to `True`

  `gui_run`(gui_context)

    This method is called in the GUI thread upon execution of the action step. The return value of this method is the result of the `yield` statement in the model thread.

    The default behavior of this method is to call the model_run generator in the model thread until it is finished.

    Parameters: | gui_context – An object of type `camelot.admin.action.GuiContext`, which is the context of this action available in the GUI thread. What is in the context depends on how the action was called.

    this method will raise a `camelot.core.exception.CancelRequest` exception, if the user canceled the operation.

  `model_run`(model_context=None)

    A generator that yields `camelot.admin.action.ActionStep` objects. This generator can be called in the model thread.

    Parameters: | context – An object of type `camelot.admin.action.ModelContext`, which is context of this action available in the model_thread. What is in the context depends on how the action was called.

class `camelot.admin.action.` `ApplicationActionGuiContext`

  The GUI context for an `camelot.admin.action.Action`. On top of the attributes of the `camelot.admin.action.base.GuiContext`, this context contains :

  `workspace`

    the the `camelot.view.workspace.DesktopWorkspace` of the application in which views can be opened or adapted.

  `admin`

    the application admin.

  `model_context`

    alias of `ApplicationActionModelContext`

class `camelot.admin.action.` `CallMethod`(verbose_name, method, enabled=None)

  Call a method on all objects in a selection, and flush the session.

  Parameters: | verbose_name – the name of the action, as it should appear to the user method – the method to call on the objects enabled – method to call on objects to verify if the action is enabled, by default the action is always enabled

  This action can be used either within `list_actions` or within `form_actions`.

class `camelot.admin.action.` `OpenNewView`(entity_admin)

  An application action that opens a new view of an Entity

  Parameters: | entity_admin – an instance of `camelot.admin.entity_admin.EntityAdmin` to be used to visualize the entities

  `gui_run`(gui_context)

    Returns: | a new view

class `camelot.admin.action.` `OpenTableView`(entity_admin)

  An application action that opens a TableView of an Entity

  Parameters: | entity_admin – an instance of `camelot.admin.entity_admin.EntityAdmin` to be used to visualize the entities

class `camelot.admin.action.` `GuiContext`

  The GUI context in which an action is running. This object can contain references to widgets and other usefull information. This object cannot contain reference to anything database or model related, as those belong strictly to the `ModelContext`

  `progress_dialog`

    an instance of `QtGui.QProgressDialog` or `None`

  `mode_name`

    the name of the mode in which the action was triggered

  `model_context`

    a subclass of `ModelContext` to be used in `create_model_context()` as the type of object to return.

  `copy`()

    Create a copy of the GuiContext, this function is used to create new GuiContext’s that are more specialized without modifying the original one.

  `create_model_context`()

    Create a `ModelContext` filled with base information, extracted from this GuiContext. This function will be called in the GUI thread, so it should not access the model directly, but rather extract all information needed from te GUI to be available in the model.

    Returns: | a `ModelContext`

  `model_context`

    alias of `ModelContext`

class `camelot.admin.action.` `Mode`(name, verbose_name=None, icon=None)

  A mode is a way in which an action can be triggered, a print action could be triggered as ‘Export to PDF’ or ‘Export to Word’. None always represents the default mode.

  `name`

    a string representing the mode to the developer and the authentication system. this name will be used in the `GuiContext`

  `verbose_name`

    The name shown to the user

  `icon`

    The icon of the mode

  `render`(parent)

    Create a `QtGui.QAction` that can be used to enable widget to trigger the action in a specific mode. The data attribute of the action will contain the name of the mode.

    Returns: | a `QtGui.QAction` class to use this mode

class `camelot.admin.action.` `State`

  A state represents the appearance and behavior of the widget that triggers the action. When the objects in the model change, the `Action.get_state()` method will be called, which should return the updated state for the widget.

  `verbose_name`

    The name of the action as it will appear in the button, this defaults to the verbose_name of the action.

  `icon`

    The icon that represents the action, of type `camelot.view.art.Icon`, this defaults to the icon of the action.

  `tooltip`

    The tooltip as displayed to the user, this should be of type `camelot.core.utils.ugettext_lazy`, this defaults to the tooltip op the action.

  `enabled`

    `True` if the widget should be enabled (the default), `False` otherwise

  `visible`

    `True` if the widget should be visible (the default), `False` otherwise

  `notification`

    `True` if the buttons should attract the attention of the user, defaults to `False`.

  `modes`

    The modes in which an action can be triggered, a list of `Mode` objects.

- application_action
- base
- form_action
- list_action

### Navigation

- index
- modules |
- next |
- previous |
- Camelot documentation »
- Camelot API »
- admin »

Comments
blog comments powered by Disqus