Component

class mnemosyne.libmnemosyne.component.Component(component_manager)

Base class of components that are registered with the component manager. This is a list of component types: config, log, database, scheduler, stopwatch, translator, card_type, card_type_converter, render_chain, renderer, filter, card_type_widget, generic_card_type_widget, ui_component, controller, main_widget, review_controller, review_widget, file format, plugin, hook, criterion, criterion_applier, statistics_page, sync_server, all the abstract dialogs, ...

‘used_for’ can store certain relationships between components, e.g. a card type widget is used for a certain card type.

Most of the time, instances are stored here, apart from widgets in which case classes are stored. (Instantiating a complex widget can take a lot of time on a mobile device, and should be done lazily.) Only the main widget is stored as an instance here.

When ‘instantiate == LATER’, the component is lazily created when needed. The instance is not cached for subsequent reuse, as these widgets typically can become obsolete/overwritten by plugins.

Each component has access to all of the context of the other components because it hold a reference to the user’s component manager.

We need to pass the context of the component manager already in the constructor, as many component make use of it in their __init__ method. This means that derived components should always call the Component.__init__ if they provide their own constructor.

IMMEDIATELY = 0
LATER = 1
activate()

Initialisation code called when the component is about to do actual work, and which can’t happen in the constructor, e.g. because components on which it relies have not yet been registered.

card_type_with_id(id)
card_types()
component_type = ''
config()
controller()
database()
deactivate()
flush_sync_server()

If there are still dangling sessions (i.e. those waiting in vain for more client input) in the sync server, we should flush them and make sure they restore from backup before doing anything that could change the database (e.g. adding a card). Otherwise, if these sessions close later during program shutdown, their backup restoration will override the changes.

instantiate = 0
log()
main_widget()
plugins()
render_chain(id='default')
review_controller()
review_widget()

Apart from the main widget, we create all other widgets lazily for efficiency reasons. The review widget instance is therefore not stored in the component manager, but is under the control of the review controller.

scheduler()
start_review()
stopwatch()
translator()
used_for = None

Previous topic

Libmnemosyne overview

Next topic

ComponentManager

This Page