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

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()
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.admin.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 QtWidgets.QWidget
Returns:

a QtWidgets.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

cancelable

a boolean indicating if the ActionStep is allowed to raise a CancelRequest exception when yielded, 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 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.ApplicationActionModelContext

The Model context for an camelot.admin.action.Action. On top of the attributes of the camelot.admin.action.base.ModelContext, this context contains :

admin

the application admin.

session

the active session

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.DocumentActionGuiContext

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

document

the QtGui.QTextDocument upon which this action is acting

view

the view that displays the document

class camelot.admin.action.FieldActionGuiContext

The context for an Action on a field. On top of the attributes of the camelot.admin.action.application_action.ApplicationActionGuiContext, this context contains :

editor

the editor through which the field is edited.

model_context

alias of FieldActionModelContext

class camelot.admin.action.FieldActionModelContext

The context for a Action on a field. On top of the attributes of the camelot.admin.action.application_action.ApplicationActionGuiContext, this context contains :

obj

the object of which the field displays a field

field

the name of the field that is being displayed

attribute:: value

the value of the field as it is displayed in the editor

field_attributes

A dictionary of field attributes of the field to which the context relates.

class camelot.admin.action.FormActionGuiContext

The context for an Action on a form. On top of the attributes of the camelot.admin.action.application_action.ApplicationActionGuiContext, this context contains :

widget_mapper

the QtGui.QDataWidgetMapper class that relates the form widget to the model.

view

a camelot.view.controls.view.AbstractView class that represents the view in which the action is triggered.

model_context

alias of FormActionModelContext

class camelot.admin.action.FormActionModelContext

On top of the attributes of the camelot.admin.action.application_action.ApplicationActionModelContext, this context contains :

current_row

the row in the list that is currently displayed in the form

collection_count

the number of objects that can be reached in the form.

selection_count

the number of objects displayed in the form, at most 1.

session

The session to which the objects in the list belong.

The selection_count attribute allows the model_run() to quickly evaluate the size of the collection without calling the potetially time consuming method get_collection().

get_collection(yield_per=None)
Parameters:yield_per – an integer number giving a hint on how many objects should fetched from the database at the same time.
Returns:a generator over the objects in the list
get_object()
Returns:the object currently displayed in the form, None if no object is displayed yet
get_selection(yield_per=None)

Method to be compatible with a camelot.admin.action.list_action.ListActionModelContext, this allows creating a single Action to be used on a form and on list.

Parameters:yield_per – this parameter has no effect, it’s here only for compatibility with camelot.admin.action.list_action.ListActionModelContext.get_selection()
Returns:a generator that yields the current object displayed in the form and does not yield anything if no object is displayed yet in the form.
class camelot.admin.action.ListActionModelContext

On top of the attributes of the camelot.admin.action.application_action.ApplicationActionModelContext, this context contains :

selection_count

the number of selected rows.

collection_count

the number of rows in the list.

selected_rows

an ordered list with tuples of selected row ranges. the range is inclusive.

current_row

the current row in the list if a cell is active

current_column

the current column in the table if a cell is active

current_field_name

the name of the field displayed in the current column

session

The session to which the objects in the list belong.

field_attributes

The field attributes of the field to which the list relates, for example the attributes of Person.addresses if the list is the list of addresses of the Person.

The collection_count and selection_count attributes allow the model_run() to quickly evaluate the size of the collection or the selection without calling the potentially time consuming methods get_collection() and get_selection().

get_collection(yield_per=None)
Parameters:yield_per – an integer number giving a hint on how many objects should fetched from the database at the same time.
Returns:a generator over the objects in the list
get_object()
Returns:the object displayed in the current row or None
get_selection(yield_per=None)
Parameters:yield_per – an integer number giving a hint on how many objects should fetched from the database at the same time.
Returns:a generator over the objects selected
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
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 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 QtWidgets.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)

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()

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
get_window()

The window to be used as a reference to position new windows. Returns None if there is no window yet.

Returns:a QtWidgets.QWidget
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 QtWidgets.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 QtWidgets.QAction class to use this mode
class camelot.admin.action.RowNumberAction

An action that simply displays the current row number as its name to the user.

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.