Created
July 30, 2014 01:26
-
-
Save osiloke/df013e8d5f1481547580 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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