base

class camelot.admin.action.base.Action[source]

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

drop_mime_types

A list of strings with the mime types that can be used to trigger this action by dropping objects on the related widget. Example

drop_mime_types = ['text/plain']

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()[source]
Returns:a string, by default the name attribute
get_shortcut()[source]
Returns:a camelot.core.utils.ugettext_lazy, by default the

shortcut attribute

get_state(model_context)[source]

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.admin.action.base.State
gui_run(gui_context)[source]

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)[source]

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.base.ActionStep[source]

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)[source]

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)[source]

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.base.GuiContext[source]

The GUI context in which an action is running. This object can contain references to widgets and other useful 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(base_class=None)[source]

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

Parameters:base_class – the type of the new context to be created, None if the new context should be of the same type as the copied context.
create_model_context()[source]

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.base.Mode(name, verbose_name=None, icon=None)[source]

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)[source]

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.base.ModelContext[source]

The Model context in which an action is running. The model context can contain reference to database sessions or other model related data. This object can not contain references to widgets as those belong strictly to the GuiContext.

mode_name

the name of the mode in which the action was triggered

class camelot.admin.action.base.State[source]

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.

Previous topic

application_action

Next topic

document_action

This Page