Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ReckonPrimer.activity/views/feedback_view.py
blob: 39d42c050497d4f14589266121c5ee75e89cab3c (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
import gtk
import pango
from timer import Timer
import gobject

from sugar import profile # TODO remove dep.

class FeedbackView:
    
    def __init__(self):
        self.total_number_of_calculations = 99
        self.table = gtk.Table(14, 9, True)
        self.build_view()


    def update_time(self):
        minutes, seconds = divmod(self.stopwatch.elapsed, 60)
        if(minutes < 10 and seconds < 10):
            time = "0" + str(int(minutes)) + ":" + "0" + str(int(seconds))
        if(minutes > 9 and seconds > 9):
            time = str(int(minutes)) + ":" + str(int(seconds))
        if(minutes > 9 and seconds < 10):
            time = str(int(minutes)) + ":" + "0" + str(int(seconds))
        if(minutes < 10 and seconds > 10):
            time = "0" + str(int(minutes)) + ":" + str(int(seconds))
        self.stopwatch_label.set_label(time)
        self.stopwatch_label.queue_draw()
        return True
    
    # TODO     
    def update_error_counter(self, counter):
        self.false_counter.set_text(str(counter))
    
    def update_progressbar(self):
        self.progressbar.set_fraction(self.progressbar.get_fraction()+(float(1)/float(self.total_number_of_calculations)))
        self.correct_count = self.correct_count + 1
        self.correct_counter.set_text(str(self.correct_count))
        
    def hide(self):
        self.table.hide()
        # self.progressbar.set_fraction(0)
        # self.stopwatch_label.hide()
        # self.name_label.hide()
        # self.progressbar.hide()
        # self.progress0.hide()
        # self.correct_counter.hide()
        # self.false_counter.hide()
        # self.progress_total.hide()
        # self.sfb_butt.hide()
        
    def show(self):
        self.table.show()
        
    def build_view(self):
        """RENAME to draw_feedback_screen"""
        # Section for stopwatch
        self.stopwatch = Timer()
        self.stopwatch_label = gtk.Label("00:00")
        self.stopwatch_label.modify_font(pango.FontDescription("sans 16"))
        #self.table.attach(self.stopwatch_label, 3, 5, 12, 13)
        self.table.attach(self.stopwatch_label, 4, 6, 12, 13)
        
        # Section for nickname
        self.name = profile.get_nick_name()
        self.name_label = gtk.Label(self.name)
        self.name_label.modify_font(pango.FontDescription("sans 16"))
        #self.table.attach(self.name_label, 0, 6, 13, 14)
        self.table.attach(self.name_label, 0, 9, 13, 14)
        
        # Section for progress bar
        self.progressbar = gtk.ProgressBar(adjustment=None)
        
        # Color for progress bar
        style = self.progressbar.get_style()
        style.bg[gtk.STATE_PRELIGHT] = gtk.gdk.color_parse("green")
        self.progressbar.set_style (style)
        self.progressbar.set_fraction(0)      
        self.table.attach(self.progressbar, 0, 9, 8, 9)

        # Labels for progress bar
        self.progress0 = gtk.Label("0")
        self.progress0.modify_font(pango.FontDescription("sans 16"))
        self.table.attach(self.progress0, 0, 1, 9, 10 )
        
        # Labels for status update
        self.correct_count = 0
        self.correct_counter = gtk.Label(str(self.correct_count))
        self.correct_counter.modify_font(pango.FontDescription("sans 16"))
        
        # Ugly code for label color
        attr = pango.AttrList()
        fg_color = pango.AttrForeground(0, 65535, 0, 0, 6)
        attr.insert(fg_color) 
        self.correct_counter.set_attributes(attr)

        #self.table.attach(self.correct_counter, 2, 4, 9, 10 ) 
        self.table.attach(self.correct_counter, 3, 5, 9, 10 ) 
        
        self.false_count = 0
        self.false_counter = gtk.Label(str(self.false_count))
        self.false_counter.modify_font(pango.FontDescription("sans 16"))
        
        # Ugly code for label color
        attr = pango.AttrList()
        fg_color = pango.AttrForeground(0, 0, 65535, 0, 6)
        attr.insert(fg_color) 
        self.false_counter.set_attributes(attr)
        
        #self.table.attach(self.false_counter, 2, 4, 10, 11 )
        self.table.attach(self.false_counter, 3, 5, 10, 11 )
        
        self.stopwatch_label.show()
        gobject.timeout_add(1000, self.update_time)
        self.name_label.show()
        self.progressbar.show()
        self.progress0.show()
        self.correct_counter.show()
        self.false_counter.show()
        

        self.progress_total = gtk.Label(str(self.total_number_of_calculations))
        self.progress_total.modify_font(pango.FontDescription("sans 16"))
        #self.table.attach(self.progress_total, 5, 6, 9, 10 )
        self.table.attach(self.progress_total, 8, 9, 9, 10 )
        self.progress_total.show()
        
        self.sfb_butt = gtk.Button(None, gtk.STOCK_STOP) 
        # self.sfb_butt.connect("clicked", self.display.release_feedb_callback)     
        self.table.attach(self.sfb_butt, 0, 9, 13, 14)
        self.sfb_alignment = self.sfb_butt.get_children()[0]
        self.sfb_hbox = self.sfb_alignment.get_children()[0]
        self.sfb_image, self.sfb_label = self.sfb_hbox.get_children()
        self.sfb_label.set_label("feedback_table")
        self.sfb_butt.show()