Esempio n. 1
0
class SimpleCover():
    '''
        This class is a simplified version of class Cover for the practice mode.
    '''
    COVER, SHOW = range(2)
    def __init__(self, win, pos, name, width=0.15, height=0.1, color=(178, 178, 178)):
        self.rect = Rect(win, height=height, width=width, units='norm', pos=pos)
        self.rect.setFillColor(color=color, colorSpace='rgb255')
        self.rect.setLineColor(color=color, colorSpace='rgb255')
        self.mouse = event.Mouse(win=win)
        self.state = self.COVER
        
    def draw(self):
        if self.state == self.COVER:
            self.rect.draw()
        elif self.state == self.SHOW:
            pass
    
    def process(self):
        x, y = self.mouse.getPos()
        # if need to click to see the information, uncomment the following line and comment the line after the following line
        if self.rect.contains(x, y, units='norm') and self.mouse.getPressed()[0] == 1:
        # if self.rect.contains(x, y, units='norm'):
            self.state = self.SHOW
        elif not self.rect.contains(x, y, units='norm'):
            self.state = self.COVER
Esempio n. 2
0
class Cover():
    COVER, SHOW = range(2)
    def __init__(self, win, pos, name, detail_file, sub_id, test_id, width=0.15, height=0.1, color=(178, 178, 178)):
        self.name = name
        self.rect = Rect(win, height=height, width=width, units='norm', pos=pos)
        self.rect.setFillColor(color=color, colorSpace='rgb255')
        self.rect.setLineColor(color=color, colorSpace='rgb255')
        self.mouse = event.Mouse(win=win)
        self.state = self.COVER
        self.time = 0
        self.single_time = 0
        self.last_state = self.COVER
        self.last_time = 0
        self.clk = clock.Clock()

        self.detail_file = detail_file
        self.sub_id = sub_id
        self.test_id = test_id
        
    def draw(self):
        if self.state == self.COVER:
            self.rect.draw()
        elif self.state == self.SHOW:
            pass
    
    def process(self):
        x, y = self.mouse.getPos()
        # if need to click to see the information, uncomment the following line and comment the line after the following line
        if self.rect.contains(x, y, units='norm') and self.mouse.getPressed()[0] == 1:
        # if self.rect.contains(x, y, units='norm'):
            self.state = self.SHOW
        elif not self.rect.contains(x, y, units='norm'):
            self.state = self.COVER
        if self.last_state == self.SHOW:
            this_time = self.clk.getTime() - self.last_time
            self.time += this_time
            self.single_time += this_time
            # time记录累加时间,single_time记录单次时间
            if self.state == self.COVER:
                self.detail_file.write(','.join((str(self.sub_id), str(self.test_id), str(self.name), str(self.single_time))))
                self.detail_file.write('\n')
                self.single_time = 0
        self.last_time = self.clk.getTime()
        self.last_state = self.state