~emihalac/mnemosyne-proj/mnemosyne-proj

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#
# review_wdgt.py <Peter.Bienstman@UGent.be>
#

import os
from string import Template

from mnemosyne.libmnemosyne.translator import _
from mnemosyne.libmnemosyne.ui_components.review_widget import ReviewWidget


class ReviewWdgt(ReviewWidget):

    """I've tried fiddling with css to get the grades area always show up at
    the bottom of the screen, no matter the contents of the cards, but I
    never got this to work satisfactory both on Firefox and IE. There would
    always be issues with spurious scrollbars or the card areas not expanding
    to fill the entire screen.
    Therefore, we place the grades at the top, where they are also always at
    the same location for easy ergonomic access.

    """

    def __init__(self, component_manager):
        ReviewWidget.__init__(self, component_manager)
        self.client_on_same_machine_as_server = False
        self.question_label = ""
        self.question = ""
        self.is_question_box_visible = True
        self.answer = ""
        self.answer_label = _("Answer:")
        self.is_answer_box_visible = True
        self.show_button = ""
        self.is_show_button_enabled = True
        self.is_grade_buttons_enabled = False
        self.status_bar = ""
        self.template = Template("""
<!DOCTYPE html>
<html>
<head>
  <title>Mnemosyne</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
table {
  width: 100%;
  border: 1px solid black;
  padding: 1em;
}
table.buttonarea {
  border: 0;
  padding: 0;
  background-color: white;
}
input {
  width: 100%;
}

$card_css
</style>
</head>
<body>

<table class="buttonarea">
  <tr>
  $buttons
  </tr>
</table>

<p>$question_label</p>

<table id="mnem1" class="mnem">
  <tr>
    <td>$question</td>
  </tr>
</table>

<p>$answer_label</p>

<table id="mnem1" class="mnem">
  <tr>
    <td>$answer</td>
  </tr>
</table>

<p>$status_bar</p>

</body>
</html>
""")
        
    def set_client_on_same_machine_as_server\
        (self, client_on_same_machine_as_server):
        self.client_on_same_machine_as_server = \
            client_on_same_machine_as_server

    def redraw_now(self):
        pass

    def show_answer(self):
        self.review_controller().show_answer()

    def grade_answer(self, grade):
        self.review_controller().grade_answer(grade)

    def set_question_box_visible(self, is_visible):
        self.is_question_box_visible = is_visible

    def set_answer_box_visible(self, is_visible):
        self.is_answer_box_visible = is_visible

    def set_question_label(self, text):
        self.question_label = text

    def set_question(self, text):
        self.question = text

    def set_answer(self, text):
        self.answer = text

    def clear_question(self):
        self.question = ""

    def clear_answer(self):
        self.answer = ""

    def update_show_button(self, text, is_default, is_enabled):
        self.show_button = text
        self.is_show_button_enabled = is_enabled

    def set_grades_enabled(self, is_enabled):
        self.is_grade_buttons_enabled = is_enabled

    def set_default_grade(self, grade):
        pass

    def update_status_bar_counters(self):
        scheduled_count, non_memorised_count, active_count = \
            self.review_controller().counters()
        counters = "Sch.: %d Not mem.: %d Act.: %d" % \
            (scheduled_count, non_memorised_count, active_count)
        self.status_bar = """
              <table class="buttonarea">
              <tr>
                <td> """ + counters + """ </td>
                <td>
                  <form action="" method="post">
                    <input type="submit" name="star" value="Star">
                  </form>
                </td>
              </tr></table>"""

    def to_html(self):
        self.controller().heartbeat()
        card_css = ""
        card = self.review_controller().card
        if card:
            card_css = self.render_chain().renderer_for_card_type\
                (card.card_type).card_type_css(card.card_type)
        buttons = ""
        if self.is_grade_buttons_enabled:
            buttons = ""
            for i in range(6):
                buttons += """
                  <td>
                    <form action="" method="post">
                      <input type="submit" name="grade" accesskey="%d"
                       value="%d">
                    </form>
                  </td>""" % (i, i)
        if self.is_show_button_enabled:
            buttons = """
              <td>
                <form action="" method="post">
                  <input type="submit" name="show_answer" value="%s">
                </form>
              </td>""" % (self.show_button)
        if not self.question:
            self.question = "&nbsp;"  # For esthetic reasons.
        if not self.answer:
            self.answer = "&nbsp;"
        extended_status_bar = self.status_bar
        if self.client_on_same_machine_as_server:
            extended_status_bar = extended_status_bar.replace(\
            "</tr></table>", \
            """<td>
                  <form action="" method="post">
                    <input type="submit" name="exit" value="Exit">
                  </form>
                </td>
            </tr></table>""")
            
        print(self.question)
        print(11111111111111111111)
        return self.template.substitute(card_css=card_css, buttons=buttons,
            question_label=self.question_label, question=self.question,
            answer_label=self.answer_label, answer=self.answer,
            status_bar=extended_status_bar).encode("utf-8")