Skip to content

Instantly share code, notes, and snippets.

@osiloke
Created July 30, 2014 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osiloke/df013e8d5f1481547580 to your computer and use it in GitHub Desktop.
Save osiloke/df013e8d5f1481547580 to your computer and use it in GitHub Desktop.
class AdImageX(Widget, Ad):
source = None # StringProperty()
texture = None
allow_stretch = BooleanProperty(True)
keep_ratio = BooleanProperty(False)
def __init__(self, **kwargs):
super(AdImageX, self).__init__(**kwargs)
self.opacity = 0
@profile
def update_texture(self, texture, dt):
self.dispatch('on_ready')
self.ad_loaded = True
self.opacity = 1
self.canvas.clear()
with self.canvas:
Rectangle(texture=texture, size=self.size, pos=self.pos)
@profile
def image_loaded(self, proxyImage):
# if proxyImage.image.texture:
Logger.debug("AdImageX: %s has been loaded" % proxyImage.image.filename)
Clock.schedule_once(partial(self.update_texture, proxyImage.image.texture), 0.)
# @profile
def on_ad(self, widget, item):
try:
self.source = item.absolute_url
except AttributeError:
self.source = item.path
Logger.debug("AdImageX: %s is going to be loaded" % self.source)
image = SignageLoader.image(self.source, nocache=True)
image.bind(on_load=self.image_loaded)
@property
def texture(self):
return self.texture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment