def MTImage(arg, **kwargs): ''' Convenience wrapper for MTContainer(Image(...)). Allows to easily display an image. For a full reference on the parameters accepted, please refer to the documentation of the `Image` class: ''' return MTContainer(Image(arg, **kwargs))
class MTScatterImage(MTScatterWidget): '''MTScatterImage is a image showed in a Scatter widget :Parameters: `filename` : str Filename of image `image` : Image Instead of using filename, use a Image object `opacity` : float, default to 1.0 Used to set the opacity of the image. `scale` : float, default is 1.0 Scaling of image, default is 100%, ie 1.0 ''' def __init__(self, **kwargs): kwargs.setdefault('filename', None) kwargs.setdefault('opacity', 1.0) kwargs.setdefault('scale', 1.0) kwargs.setdefault('image', None) if kwargs.get('filename') is None and kwargs.get('image') is None: raise Exception('No filename or image given to MTScatterImage') super(MTScatterImage, self).__init__(**kwargs) self._filename = '' self.image = kwargs.get('image') self.scale = kwargs.get('scale') self.filename = kwargs.get('filename') self.opacity = kwargs.get('opacity') self.size = self.image.size def _get_filename(self): return self._filename def _set_filename(self, filename): self._filename = filename if filename: self.image = Image(self.filename) filename = property(_get_filename, _set_filename) def draw(self): self.size = self.image.size self.image.opacity = self.opacity self.image.draw()
def parse_image(filename): '''Parse a filename to load an image ro svg''' filename = parse_filename(filename) if filename in (None, 'None', u'None'): return None if filename.endswith('.svg'): return Svg(filename) else: return Image(filename) raise Exception('Error trying to load image specified in css: %s' \ % filename)
def __init__(self, **kwargs): kwargs.setdefault('bordersize', 10) super(MTVideo, self).__init__(**kwargs) self._count = 0 self._controls = False self.bordersize = kwargs.get('bordersize') # images play/pause/mute self.f_play = Image(pymt_icons_dir + 'video-play.png') self.f_pause = Image(pymt_icons_dir + 'video-pause.png') self.f_vmute = Image(pymt_icons_dir + 'video-volume-mute.png') self.f_v100 = Image(pymt_icons_dir + 'video-volume-100.png') # create UI box = MTBoxLayout(orientation='horizontal', uniform_height=True, spacing=0, padding=0) self._btnplay = MTButtonVideo(image=self.f_play, cls='video-toggleplay') self._btnmute = MTButtonVideo(image=self.f_v100, cls='video-togglemute') self._timeline = MTSlider(orientation='horizontal', cls='video-timeline') box.add_widget(self._btnplay) box.add_widget(self._btnmute) box.add_widget(self._timeline) self.add_widget(box) # link self._btnplay.connect('on_press', self._on_toggle_play) self._btnmute.connect('on_press', self._on_toggle_mute) self.hide_controls()
def load_material_library(self, filename): material = None file = self.open_material_file(filename) for line in file: if line.startswith('#'): continue values = line.split() if not values: continue if values[0] == 'newmtl': material = Material(values[1]) self.materials[material.name] = material elif material is None: pymt_logger.warning('OBJ: Expected "newmtl" in %s' % filename) continue try: if values[0] == 'Kd': material.diffuse = map(float, values[1:]) elif values[0] == 'Ka': material.ambient = map(float, values[1:]) elif values[0] == 'Ks': material.specular = map(float, values[1:]) elif values[0] == 'Ke': material.emission = map(float, values[1:]) elif values[0] == 'Ns': material.shininess = float(values[1]) elif values[0] == 'd': material.opacity = float(values[1]) elif values[0] == 'map_Kd': try: filename = ' '.join(values[1:]) material.texture = Image(filename).texture material.texture.wrap = GL_REPEAT except: pymt_logger.warning('OBJ: Could not load texture %s' % values[1]) raise except: pymt_logger.warning('OBJ: Parse error in %s.' % filename) raise
def _set_filename(self, filename): self._filename = filename if filename: self.image = Image(self.filename)
def __init__(self, arg, **kwargs): Image.__init__(self, arg, **kwargs) EventDispatcher.__init__(self) self.register_event_type('on_load')