def prepare(self): """Prepare a canvas with a fixation dot.""" # Call parent functions. item.prepare(self) generic_response.prepare(self) # Create a canvas. self.c = canvas(self.experiment, self.get(u'background'), \ self.get(u'foreground')) # Set the coordinates. self._x = self.get(u'x') + self.c.xcenter() self._y = self.get(u'y') + self.c.ycenter() # Draw the fixation dot. self.c.set_penwidth(self.get(u'penwidth')) if self.style == u'default': self.c.fixdot(self._x, self._y) elif self.style == u'filled': self.c.ellipse(self._x - 10, self._y - 10, 20, 20, True) elif self.style == u'filled-small': self.c.ellipse(self._x - 5, self._y - 5, 10, 10, True) elif self.style == u'empty': self.c.ellipse(self._x - 10, self._y - 10, 20, 20, False) elif self.style == u'empty-small': self.c.ellipse(self._x - 5, self._y - 5, 10, 10, False) elif self.style == u'cross': self.c.line(self._x - 10, self._y, self._x + 10, self._y) self.c.line(self._x, self._y - 10, self._x, self._y + 10) elif self.style == u'cross-small': self.c.line(self._x - 5, self._y, self._x + 5, self._y) self.c.line(self._x, self._y - 5, self._x, self._y + 5)
def prepare(self): # Call parent functions. item.prepare(self) # Prepare your plug-in here. generic_response.prepare(self) path = self.experiment.pool[self.var.media_src] self.c = canvas(self.experiment, background_color=self.var.background, color=self.var.foreground) if not os.path.isfile(path): raise osexception(u"Media file '%s' was not found." % (os.path.basename(path), self.name)) if self.var.HMDtype == u"Oculus DK1 (1280x800px)" and self.var.stereoscopic == u"No (No 3D depth)" and self.var.isVideo == u"No": self.c.image(path, x=-252, y=0.0) self.c.image(path, x=252, y=0.0) elif self.var.HMDtype == u"Oculus DK1 (1280x800px)" and self.var.stereoscopic == u"Yes" and self.var.isVideo == u"No": self.c.image(path, x=0, y=0.0) elif self.var.HMDtype == u"Oculus DK2 (1920x1080px)" and self.var.stereoscopic == u"No" and self.var.isVideo == u"No": self.c.image(path, x=-378, y=0.0) self.c.image(path, x=378, y=0.0) elif self.var.HMDtype == u"Oculus DK2 (1920x1080px)" and self.var.stereoscopic == u"Yes" and self.var.isVideo == u"No": self.c.image(path, x=0, y=0.0) elif self.var.HMDtype == u"Oculus Rift 2016 (2160x1200px)" and self.var.stereoscopic == u"No" and self.var.isVideo == u"No": self.c.image(path, x=-415.8, y=0.0) self.c.image(path, x=415.8, y=0.0) elif self.var.HMDtype == u"Oculus Rift 2016 (2160x1200px)" and self.var.stereoscopic == u"Yes" and self.var.isVideo == u"No": self.c.image(path, x=0, y=0.0) elif self.var.HMDtype == u"HTC Vive (2160x1200px)" and self.var.stereoscopic == u"No" and self.var.isVideo == u"No": self.c.image(path, x=-415.8, y=0.0) self.c.image(path, x=415.8, y=0.0) elif self.var.HMDtype == u"HTC Vive (2160x1200px)" and self.var.stereoscopic == u"Yes" and self.var.isVideo == u"No": self.c.image(path, x=0, y=0.0)
def prepare(self): """Prepares the text display canvas.""" # Pass the word on to the parent item.prepare(self) # Create an offline canvas self.c = openexp.canvas.canvas(self.experiment, self.get( \ u"background"), self.get(u"foreground")) self.c.set_font(self.get(u"font_family"), self.get(u"font_size")) # Make sure that the content is a unicode string that is evaluated # for variables and then split into separated lines, using either the # os-specific or the Unix-style line separator. content = self.unistr(self.get(u'content')) content = content.replace(os.linesep, u'\n') content = self.eval_text(content).split(u"\n") # Do line wrapping _content = [] for line in content: while len(line) > self.get(u"maxchar"): i = line.rfind(" ", 0, self.get(u"maxchar")) if i < 0: raise osexception( \ u"Failed to do line wrapping in text_display '%s'. Perhaps one of the words is longer than the maximum number of characters per line?" \ % self.name) _content.append(line[:i]) line = line[i+1:] _content.append(line) content = _content if self.get(u"align") != u"center": try: max_width = 0 max_height = 0 for line in content: size = self.c.text_size(line) max_width = max(max_width, size[0]) max_height = max(max_height, size[1]) except: raise osexception( \ u"Failed to use alignment '%s' in text_display '%s'. Perhaps this alignment is not supported by the back-end. Please use 'center' alignment." \ % (self.get(u"align"), self.name)) line_nr = -len(content) / 2 for line in content: if self.get(u"align") == u"center": self.c.textline(line, line_nr) elif self.get(u"align") == u"left": self.c.text(line, False, self.c.xcenter()-0.5*max_width, \ self.c.ycenter()+1.5*line_nr*max_height) else: width = self.c.text_size(line)[0] self.c.text(line, False, self.c.xcenter()+0.5*max_width-width, \ self.c.ycenter()+1.5*line_nr*max_height) line_nr += 1 generic_response.prepare(self)
def prepare(self): """Prepares the text display canvas.""" # Pass the word on to the parent item.prepare(self) # Create an offline canvas self.c = openexp.canvas.canvas(self.experiment, self.get( \ u"background"), self.get(u"foreground")) self.c.set_font(self.get(u"font_family"), self.get(u"font_size")) # Make sure that the content is a unicode string that is evaluated # for variables and then split into separated lines, using either the # os-specific or the Unix-style line separator. content = self.unistr(self.get(u'content')) content = content.replace(os.linesep, u'\n') content = self.eval_text(content).split(u"\n") # Do line wrapping _content = [] for line in content: while len(line) > self.get(u"maxchar"): i = line.rfind(" ", 0, self.get(u"maxchar")) if i < 0: raise osexception( \ u"Failed to do line wrapping in text_display '%s'. Perhaps one of the words is longer than the maximum number of characters per line?" \ % self.name) _content.append(line[:i]) line = line[i + 1:] _content.append(line) content = _content if self.get(u"align") != u"center": try: max_width = 0 max_height = 0 for line in content: size = self.c.text_size(line) max_width = max(max_width, size[0]) max_height = max(max_height, size[1]) except: raise osexception( \ u"Failed to use alignment '%s' in text_display '%s'. Perhaps this alignment is not supported by the back-end. Please use 'center' alignment." \ % (self.get(u"align"), self.name)) line_nr = -len(content) / 2 for line in content: if self.get(u"align") == u"center": self.c.textline(line, line_nr) elif self.get(u"align") == u"left": self.c.text(line, False, self.c.xcenter()-0.5*max_width, \ self.c.ycenter()+1.5*line_nr*max_height) else: width = self.c.text_size(line)[0] self.c.text(line, False, self.c.xcenter()+0.5*max_width-width, \ self.c.ycenter()+1.5*line_nr*max_height) line_nr += 1 generic_response.prepare(self)
def prepare(self): """ desc: Prepares the canvas. """ super(sketchpad, self).prepare() generic_response.prepare(self) self.canvas = canvas(self.experiment, color=self.var.foreground, background_color=self.var.background, auto_prepare=False) for element in self.elements: if element.is_shown(): element.draw() self.canvas.prepare()
def prepare(self): """ desc: Prepare a canvas with a fixation dot. """ # Call parent functions. item.prepare(self) generic_response.prepare(self) # Create a canvas. self.c = canvas(self.experiment, background_color=self.var.background, color=self.var.foreground, penwidth=self.var.penwidth) self.c.color = self.var.foreground self.c.background_color = self.var.background # Set the coordinates. self._x = self.var.x self._y = self.var.y if self.var.uniform_coordinates != u'yes': self._x += self.c.width/2 self._y += self.c.height/2 # For backwards compatibility, we support a few special fixdot styles if self.var.style == u'filled': self.c.ellipse(self._x - 10, self._y - 10, 20, 20, fill=True) elif self.var.style == u'filled-small': self.c.ellipse(self._x - 5, self._y - 5, 10, 10, fill=True) elif self.var.style == u'empty': self.c.ellipse(self._x - 10, self._y - 10, 20, 20, fill=False) elif self.var.style == u'empty-small': self.c.ellipse(self._x - 5, self._y - 5, 10, 10, fill=False) elif self.var.style == u'cross': self.c.line(self._x - 10, self._y, self._x + 10, self._y) self.c.line(self._x, self._y - 10, self._x, self._y + 10) elif self.var.style == u'cross-small': self.c.line(self._x - 5, self._y, self._x + 5, self._y) self.c.line(self._x, self._y - 5, self._x, self._y + 5) # But the new way is to use the style keyword else: self.c.fixdot(self._x, self._y, style=self.var.style)