Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/reviewselection.py
blob: b3c2307a51accf9f042b49149cf833a57ea9346f (plain)
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
# -*- coding: utf-8 -*-
#Copyright (c) 2010, Kirk Winans

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
import gtk
from os import environ
from os.path import join, basename
import hippo

import shutil
import tempfile
from gettext import gettext as _
import logging
from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT
from sugar.graphics import style
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.icon import Icon
from sugar.graphics.palette import Palette
from port.widgets import ToggleToolButton
from port.widgets import CanvasRoundBox, ToolComboBox
#from port import chooser

from sugar.datastore import datastore
import xml.etree.ElementTree
from datetime import date
import time
_logger = logging.getLogger("test-activity")

from gettext import gettext as _



#
# Review Selection Panel for Flashcard Activity
#
class ReviewSelection(gtk.VBox):
    
    def __init__(self, activity_root):
        gtk.VBox.__init__(self)

        self.activity_root = activity_root

        self.box_selection_box = gtk.HBox()

        self.catagory_selection_box = gtk.HBox()

        self.box_label = gtk.Label(_('Select Box:'))

        self.box_selection = gtk.ComboBoxEntry()

        self.box_selection = gtk.combo_box_new_text()

        self.catagory_label = gtk.Label(_('Select Category:'))

        self.catagory_selection = gtk.ComboBoxEntry()
        
        self.catagory_selection = gtk.combo_box_new_text()

        self.expired = gtk.CheckButton(_("Review Only Expired Cards"))

        self.expired.set_active(True)

        self.cardfile = "testfile.xml"

        self.tree = xml.etree.ElementTree.parse(self.cardfile)

        boxes = self.get_boxes()

        catagories = self.get_catagories()

        # Sets text for dropdown menus
        for text in boxes:
            self.box_selection.append_text(text)

        for text in catagories:
            self.catagory_selection.append_text(text)

        self.box_selection.set_active(0)

        self.catagory_selection.set_active(0)

        self.box_selection_box.pack_start(self.box_label)

        self.box_selection_box.pack_start(self.box_selection)

        self.catagory_selection_box.pack_start(self.catagory_label)

        self.catagory_selection_box.pack_start(self.catagory_selection)

        self.add(self.box_selection_box)

        self.add(self.catagory_selection_box)

        self.add(self.expired)

        self.box_selection.show()

        self.catagory_selection.show()

        self.box_selection_box.show()

        self.box_label.show()

        self.catagory_selection_box.show()

        self.catagory_label.show()

        self.expired.show()

    # Returns name of selected box
    def get_selected_box(self):
        return self.box_selection.get_active_text()

    # Returns name of selected category
    def get_selected_catagory(self):
        return self.catagory_selection.get_active_text()

    # Returns the time boxes
    def get_boxes(self):
        boxes = ["All", "Every Day", "Every 2 Days", "Every 4 Days", 
                 "Every Week", "Every 2 Weeks", "Every Month"]
        return boxes

    # Returns the categories available
    def get_catagories(self):
        deck = self.tree.getroot()
        card_catagories = []
        card_catagories = card_catagories + ["All"]
        for card in deck:
                card_catagories = card_catagories + [card.find("catagory").text]

        card_catagories = set(card_catagories)
        card_catagories = list(card_catagories)

        card_catagories = self.move_all(sorted(card_catagories))

        return card_catagories

    # Returns True if only the expired cards are seleceted 
    def get_expired_only(self):
        return self.expired.get_active()

    # Moves the All option to top of the list and default selected
    def move_all(self, catagories):

        for idx in range(len(catagories)):
            if catagories[idx] == "All":
                catagories[idx] = catagories[0]
                catagories[0] = "All"

        return catagories