action Package

action Package

class camelot.admin.action.Action

Bases: camelot.admin.action.base.ActionStep

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
icon = None
modes = []
name = u'action'
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.

shortcut = None
tooltip = None
verbose_name = None
class camelot.admin.action.ActionStep

Bases: object

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

blocking = 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

Bases: camelot.admin.action.base.GuiContext

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.

copy()
create_model_context()
model_context

alias of ApplicationActionModelContext

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

Bases: camelot.admin.action.base.Action

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.

get_state(model_context)
model_run(model_context)
class camelot.admin.action.OpenNewView(entity_admin)

Bases: camelot.admin.action.application_action.EntityAction

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
get_state(model_context)
gui_run(gui_context)
Returns:a new view
class camelot.admin.action.OpenTableView(entity_admin)

Bases: camelot.admin.action.application_action.EntityAction

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
get_state(model_context)
gui_run(gui_context)
modes = [<camelot.admin.action.base.Mode object at 0x956d3ac>]
class camelot.admin.action.GuiContext

Bases: object

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)

Bases: object

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

Bases: object

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 Module

class camelot.admin.action.application_action.ApplicationActionGuiContext[source]

Bases: camelot.admin.action.base.GuiContext

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.

copy()[source]
create_model_context()[source]
model_context

alias of ApplicationActionModelContext

class camelot.admin.action.application_action.ApplicationActionModelContext[source]

Bases: camelot.admin.action.base.ModelContext

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.

class camelot.admin.action.application_action.EntityAction(entity_admin)[source]

Bases: camelot.admin.action.base.Action

Generic ApplicationAction that acts upon an Entity class

class camelot.admin.action.application_action.OpenNewView(entity_admin)[source]

Bases: camelot.admin.action.application_action.EntityAction

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
get_state(model_context)[source]
gui_run(gui_context)[source]
Returns:a new view
class camelot.admin.action.application_action.OpenTableView(entity_admin)[source]

Bases: camelot.admin.action.application_action.EntityAction

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
get_state(model_context)[source]
gui_run(gui_context)[source]
modes = [<camelot.admin.action.base.Mode object at 0x956d3ac>]
class camelot.admin.action.application_action.ShowHelp

Bases: camelot.admin.action.base.Action

Display the help window

icon = Icon('tango/16x16/apps/help-browser.png')
shortcut = 1
tooltip = _('Help')
camelot.admin.action.application_action.structure_to_application_action(structure, application_admin)[source]

Convert a python structure to an ApplicationAction

Parameters:application_admin – the camelot.admin.application_admin.ApplicationAdmin to use to create other Admin classes.

base Module

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

Bases: camelot.admin.action.base.ActionStep

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()[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.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
icon = None
modes = []
name = u'action'
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.

shortcut = None
tooltip = None
verbose_name = None
class camelot.admin.action.base.ActionStep[source]

Bases: object

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

blocking = 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]

Bases: object

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

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]

Bases: object

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]

Bases: object

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]

Bases: object

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.

form_action Module

class camelot.admin.action.form_action.FormActionGuiContext[source]

Bases: camelot.admin.action.application_action.ApplicationActionGuiContext

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.

copy()[source]
create_model_context()[source]
model_context

alias of FormActionModelContext

class camelot.admin.action.form_action.FormActionModelContext[source]

Bases: camelot.admin.action.application_action.ApplicationActionModelContext

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

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)[source]
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()[source]
Returns:the object currently displayed in the form, None if no object

is displayed yet

get_selection(yield_per=None)[source]

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.
session[source]
camelot.admin.action.form_action.structure_to_form_actions(structure)[source]

Convert a list of python objects to a list of form actions. If the python object is a tuple, a CallMethod is constructed with this tuple as arguments. If the python object is an instance of as Action, it is kept as is.

list_action Module

class camelot.admin.action.list_action.CallMethod(verbose_name, method, enabled=None)[source]

Bases: camelot.admin.action.base.Action

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.

get_state(model_context)[source]
model_run(model_context)[source]
class camelot.admin.action.list_action.DeleteSelection

Bases: camelot.admin.action.base.Action

Delete the selected rows in a table

icon = Icon('tango/16x16/places/user-trash.png')
shortcut = 7
tooltip = _('Delete')
class camelot.admin.action.list_action.DuplicateSelection

Bases: camelot.admin.action.base.Action

Duplicate the selected rows in a table

icon = Icon('tango/16x16/actions/edit-copy.png')
shortcut = 9
tooltip = _('Duplicate')
class camelot.admin.action.list_action.ExportDocument

Bases: camelot.admin.action.base.Action

Export all rows in a table to a word document

icon = Icon('tango/16x16/mimetypes/x-office-document.png')
tooltip = _('Export to MS Word')
class camelot.admin.action.list_action.ExportSpreadsheet

Bases: camelot.admin.action.base.Action

Export all rows in a table to a spreadsheet

icon = Icon('tango/16x16/mimetypes/x-office-spreadsheet.png')
tooltip = _('Export to MS Excel')
class camelot.admin.action.list_action.ListActionGuiContext[source]

Bases: camelot.admin.action.application_action.ApplicationActionGuiContext

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

item_view

the QtGui.QAbstractItemView class that relates to the table view on which the widget will be placed.

copy()[source]
create_model_context()[source]
model_context

alias of ListActionModelContext

class camelot.admin.action.list_action.ListActionModelContext[source]

Bases: camelot.admin.action.application_action.ApplicationActionModelContext

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

session[source]

The session to which the objects in the list belong.

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)[source]
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()[source]
Returns:the object displayed in the current row or None
get_selection(yield_per=None)[source]
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
session[source]
class camelot.admin.action.list_action.OpenFormView[source]

Bases: camelot.admin.action.base.Action

Open a form view for the current row of a list.

gui_run(gui_context)[source]
class camelot.admin.action.list_action.PrintPreview

Bases: camelot.admin.action.base.Action

Print all rows in a table

icon = Icon('tango/16x16/actions/document-print-preview.png')
model_run(model_context)
tooltip = _('Print Preview')
class camelot.admin.action.list_action.SendEmail

Bases: camelot.admin.action.base.Action

Send all rows in a table by mail

icon = Icon('tango/16x16/actions/mail-message-new.png')
tooltip = _('Send by e-mail')
class camelot.admin.action.list_action.ToFirstRow

Bases: camelot.admin.action.list_action.ToPreviousRow

Move to the first row in a table

gui_run(gui_context)
icon = Icon('tango/16x16/actions/go-first.png')
shortcut = 42
tooltip = _('First')
class camelot.admin.action.list_action.ToLastRow

Bases: camelot.admin.action.list_action.ToNextRow

Move to the last row in a table

gui_run(gui_context)
icon = Icon('tango/16x16/actions/go-last.png')
shortcut = 43
tooltip = _('Last')
class camelot.admin.action.list_action.ToNextRow

Bases: camelot.admin.action.base.Action

Move to the next row in a table

get_state(model_context)
gui_run(gui_context)
icon = Icon('tango/16x16/actions/go-next.png')
shortcut = 36
tooltip = _('Next')
class camelot.admin.action.list_action.ToPreviousRow

Bases: camelot.admin.action.base.Action

Move to the previous row in a table

get_state(model_context)
gui_run(gui_context)
icon = Icon('tango/16x16/actions/go-previous.png')
shortcut = 37
tooltip = _('Previous')

Table Of Contents

This Page


Comments
blog comments powered by Disqus