コード例 #1
0
ファイル: zxMouselab.py プロジェクト: Bil369/zxMouselab
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
コード例 #2
0
ファイル: zxMouselab.py プロジェクト: Bil369/zxMouselab
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
コード例 #3
0
ファイル: zxMouselab.py プロジェクト: Bil369/zxMouselab
class Button():
    START, END = range(2)
    def __init__(self, win, pos, width, height, name, text='选择'):
        self.name = name
        self.rect = Rect(win, height=height, width=width, units='norm', pos=pos)
        self.mouse = event.Mouse(win=win)
        self.caption = TextStim(win, text=text, height=height - 0.01 , pos=pos, units='norm', color=(0, 0, 0), colorSpace='rgb255')
        self.state = self.START
        
    def draw(self):
        x, y = self.mouse.getPos()
        if self.rect.contains(x, y, units='norm'):
            self.rect.setLineColor(color=(0, 0, 204), colorSpace='rgb255')
            self.caption.setColor(color=(0, 0, 204), colorSpace='rgb255')
        else:
            self.rect.setLineColor(color=(0, 0, 0), colorSpace='rgb255')
            self.caption.setColor(color=(0, 0, 0), colorSpace='rgb255')
        self.rect.draw()
        self.caption.draw()
    
    def process(self):
        x, y = self.mouse.getPos()
        if self.rect.contains(x, y, units='norm') and self.mouse.getPressed()[0] == 1:
            self.state = self.END