~johannes.baiter/mnemosyne-proj/mnemodroid

« back to all changes in this revision

Viewing changes to src/com/mnemodroid/mnemosyne/mnemosyne/libmnemosyne/criterion.py

  • Committer: Johannes Baiter
  • Date: 2011-02-15 00:30:59 UTC
  • Revision ID: johannes.baiter@gmail.com-20110215003059-83fn5ebmjs89jl2d
Relocated python scripts, added README and shellscript for tarball-creation, some bugfixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# criterion.py <Peter.Bienstman@UGent.be>
3
 
#
4
 
 
5
 
from mnemosyne.libmnemosyne.utils import rand_uuid
6
 
from mnemosyne.libmnemosyne.component import Component
7
 
 
8
 
 
9
 
class Criterion(Component):
10
 
 
11
 
    """Used to select a subset of cards, e.g. which cards are currently
12
 
    active, i.e. included in the review process.
13
 
 
14
 
    The available Criteria are stored as classes in the component_manager.
15
 
 
16
 
    The actual instances together with their data are stored in the database.
17
 
 
18
 
    """
19
 
 
20
 
    component_type = "activity_criterion"   
21
 
    criterion_type = ""
22
 
    instantiate = Component.LATER
23
 
    
24
 
    def __init__(self, component_manager, id=None):
25
 
        Component.__init__(self, component_manager)
26
 
        self.name = ""
27
 
        if id is None:
28
 
            id = rand_uuid()
29
 
        self.id = id
30
 
        self._id = None
31
 
            
32
 
    def apply_to_card(self, card):
33
 
 
34
 
        """Set the card active or not depending on the criterion. Does not
35
 
        write to the database. Called after creating or updating cards, to
36
 
        see whether these cards should start out their life as active or not.
37
 
 
38
 
        Also called after reviewing a card.
39
 
 
40
 
        The tag and card type creation and deletion function are callbacks
41
 
        called by the rest of libmnemosyne when these objects get created or
42
 
        destroyed, such that Criteria can update their status if needed.
43
 
 
44
 
        """
45
 
        
46
 
        raise NotImplementedError
47
 
 
48
 
    def tag_created(self, tag):
49
 
        pass
50
 
 
51
 
    def tag_deleted(self, tag):
52
 
        pass
53
 
 
54
 
    def card_type_created(self, card_type):
55
 
        pass
56
 
 
57
 
    def card_type_deleted(self, card_type):
58
 
        pass
59
 
    
60
 
    def data_to_string(self):
61
 
 
62
 
        """Convert variables to a string for storage in the database. We don't
63
 
        use pickle here as that would make it difficult for non-Python programs
64
 
        to read the database.
65
 
 
66
 
        """
67
 
        
68
 
        raise NotImplementedError
69
 
 
70
 
    def set_data_from_string(self, data_string):
71
 
        raise NotImplementedError
72
 
    
73
 
    def data_to_sync_string(self):
74
 
 
75
 
        """Convert variables to a string for sending across during syncing.
76
 
        Could be different from 'data_to_string', as it should use ids instead
77
 
        of _ids."""
78
 
 
79
 
        raise NotImplementedError
80
 
    
81
 
    def set_data_from_sync_string(self, data_string):
82
 
        raise NotImplementedError
83
 
 
84
 
 
85
 
class CriterionApplier(Component):
86
 
 
87
 
    """Can be registered 'used_for' a certain Criterion to apply it in bulk to
88
 
    all the cards in the database. Is much faster than fetching each card from
89
 
    the database, calling Criterion.apply_to_card, and storing it back in the
90
 
    database.
91
 
 
92
 
    This code is not part of Criterion, because it is dependent on the database
93
 
    backend.
94
 
 
95
 
    """
96
 
 
97
 
    component_type = "criterion_applier"
98
 
 
99
 
    def apply_to_database(self, criterion):
100
 
        raise NotImplementedError