Component
¶
- class mnemosyne.libmnemosyne.component.Component(component_manager, **kwds)¶
Base class of components that are registered with the component manager. This is a list of component types: config, log, database, scheduler, stopwatch, gui_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, study_mode, translator, pronouncer, 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.
To achieve this lazy instantiation for widget, set ‘instantiate == LATER’. Other components can then instantiate the widget when they see fit. The instance is not cached for subsequent reuse, as these widgets typically can become obsolete/overwritten by plugins.
It can be that when instantiating a component, not all the other components on which it relies have been instantiated yet. E.g., the log and the database depend on each other before doing actual work. Therefore, some of the actual initialisation work can be postponed to the ‘activate’ function.
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.
In case the GUI needs to add functionality to a certain component, that can be done through component_manager.add_gui_to_component() function (lower level) or through the gui_for_component class variable (higher level).
- 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.
- activate_gui_components()¶
GUI classes are only instantiated when activated, since that can take a lot of time on mobile clients.
Classes that require more control over this, e.g. when needing to return values from the UI, can subclass this.
- 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.
Also stop any running media.
- gui_translator()¶
- instantiate = 0¶
- language_with_id(id)¶
- languages()¶
- log()¶
- main_widget()¶
- plugins()¶
- render_chain(id='default')¶
- review_controller()¶
- review_widget()¶
- scheduler()¶
- stopwatch()¶
- study_mode_with_id(id)¶
- used_for = None¶