def error_image(self): '''Image used for error (readonly)''' if not self._error_image: error_png_fn = join(kivy_base_dir, 'tools/theming/defaulttheme', 'image-missing.png') self._error_image = ImageLoader.load(filename=error_png_fn) return self._error_image
def error_image(self): '''Image used for error (readonly)''' if not self._error_image: error_png_fn = join( 'atlas://data/images/defaulttheme/image-missing') self._error_image = ImageLoader.load(filename=error_png_fn) return self._error_image
def load(self, atlas_page, image_name): image = ImageLoader.load(join(self.images_path, image_name)) texture = image.texture texture.mag_filter = self.texture_filter_type[atlas_page.mag_filter] texture.min_filter = self.texture_filter_type[atlas_page.min_filter] atlas_page.renderer_object = texture atlas_page.width = texture.width atlas_page.height = texture.height
def _load_local(self, filename): '''(internal) Loading a local file''' # With recent changes to CoreImage, we must keep data otherwise, # we might be unable to recreate the texture afterwise. try: im = ImageLoader.load(filename, keep_data=True) except Exception,ex: Logger.warning('Loader: Unable to load image <%s>' % filename) im = self.error_image
def load_thumbnail(self, filename): """Load from thumbnail screenDatabase, or generate a new thumbnail of the given image filename. Argument: filename: Image filename. Returns: A Kivy image""" root_widget = True if root_widget or self.loadanyway: app = App.get_running_app() full_filename = filename photo = self.photo file_found = isfile2(full_filename) # if file_found: # modified_date = int(os.path.getmtime(full_filename)) # if modified_date > photo.modify_date: #if not self.temporary: # app.Photo.update(photo) # app.update_photoinfo(folders=[photo[1]]) #app.Photo.thumbnail_update(photo[Photo.FULLPATH], photo[Photo.DATABASEFOLDER], modified_date, photo[Photo.ORIENTATION], temporary=self.temporary) thumbnail_image = photo.thumbnail if thumbnail_image: imagedata = bytes(thumbnail_image) data = BytesIO() data.write(imagedata) data.seek(0) image = CoreImage(data, ext='jpg') else: # if file_found: # updated = app.Photo.thumbnail_update(photo[Photo.FULLPATH], photo[Photo.DATABASEFOLDER], modified_date, photo[Photo.ORIENTATION], temporary=self.temporary) # if updated: # thumbnail_image = app.Photo.thumbnail(photo[Photo.FULLPATH], temporary=self.temporary) # data = BytesIO(thumbnail_image[2]) # image = CoreImage(data, ext='jpg') # else: # image = ImageLoader.load(full_filename) # else: image = ImageLoader.load('data/null.jpg') return image else: return ImageLoader.load('data/null.jpg')
def _set_filename(self, value): #Logger.info('CoreImageOpenCV: value %s' % (value)) if value is None or value == self._filename: return self._filename = value # construct uid as a key for Cache if (self.res_width > 0) or (self.res_height > 0): uid = '%s|%d|%d|%s|%s' % (self.filename, self.res_width, self.res_height, self._mipmap, 0) else: uid = '%s|%s|%s' % (self.filename, self._mipmap, 0) # in case of Image have been asked with keep_data # check the kv.image cache instead of texture. image = Cache.get('kv.image', uid) if image: # we found an image, yeah ! but reset the texture now. self.image = image # if image.__class__ is core image then it's a texture # from atlas or other sources and has no data so skip if (image.__class__ != self.__class__ and not image.keep_data and self._keep_data): self.remove_from_cache() self._filename = '' self._set_filename(value) else: self._texture = None self._img_iterate() return else: # if we already got a texture, it will be automatically reloaded. _texture = Cache.get('kv.texture', uid) if _texture: self._texture = _texture return # if image not already in cache then load tmpfilename = self._filename #Logger.info('CoreImageOpenCV: set_filename %s' % (tmpfilename)) #Logger.info('CoreImageOpenCV: %d %d' % (self.res_width, self.res_height)) image = ImageLoader.load( self._filename, keep_data=self._keep_data, mipmap=self._mipmap, nocache=self._nocache, res_width=self.res_width, res_height=self.res_height, load_exif=self.load_exif) self._filename = tmpfilename # put the image into the cache if needed if isinstance(image, Texture): self._texture = image self._size = image.size else: self.image = image if not self._nocache: Cache.append('kv.image', uid, self.image)
def get_thumbnail(source, orientation, **kwargs): orig_dir = os.path.dirname(source) orig_name, orig_ext = os.path.splitext(os.path.basename(source).lower()) thumb_dir = os.path.join(orig_dir, 'thumb') thumb_name = 't_' + orig_name + '.jpg' thumb_path = os.path.join(thumb_dir, thumb_name) if os.path.exists(thumb_path): return ImageLoader.load(thumb_path, keep_data=True, **kwargs) else: try: os.makedirs(thumb_dir, exist_ok=True) if orig_ext in flickrUploader.image_ext: save_image_thumbnail(source, thumb_path, orientation) elif orig_ext in flickrUploader.video_ext: save_video_thumbnail(source, thumb_path) return ImageLoader.load(thumb_path, keep_data=True, **kwargs) except Exception as e: print("no thumbnail for file: %s" % source) return None
def load_data(self): global movies self.video_data = {} for folder in glob('content/movies/*'): movie_id = folder.split('/')[-1] #print movie_id movie_data = json.loads(open(folder+'/data.json').read()) movies[movie_id] = Movie(movie_data) movies[movie_id].set_trailer(folder+'/trailer.avi'); #self.video_data[movie_id] = VideoBuffer(filename=movies[movie_id].trailer) #preload data, so it wont hang on loading self.ad_images = {} for fname in glob('content/offers/*.png'): self.ad_images[fname] = ImageLoader.load(fname) self.offers = self.ad_images.keys() self.suggestions = movies.keys()[:3]
def load_data(self): global movies self.video_data = {} for folder in glob('content/movies/*'): movie_id = folder.split('/')[-1] #print movie_id movie_data = json.loads(open(folder + '/data.json').read()) movies[movie_id] = Movie(movie_data) movies[movie_id].set_trailer(folder + '/trailer.avi') #self.video_data[movie_id] = VideoBuffer(filename=movies[movie_id].trailer) #preload data, so it wont hang on loading self.ad_images = {} for fname in glob('content/offers/*.png'): self.ad_images[fname] = ImageLoader.load(fname) self.offers = self.ad_images.keys() self.suggestions = movies.keys()[:3]
def error_image(self): '''Image used for error (readonly)''' if not self._error_image: error_png_fn = join(kivy_data_dir, 'images', 'image-missing.png') self._error_image = ImageLoader.load(filename=error_png_fn) return self._error_image
def loading_image(self): '''Image used for loading (readonly)''' if not self._loading_image: loading_png_fn = join(kivy_data_dir, 'images', 'image-loading.gif') self._loading_image = ImageLoader.load(filename=loading_png_fn) return self._loading_image
# Twisted initialization from kivy.support import install_twisted_reactor try: if platform in ['win', 'windows']: import sys if 'twisted.internet.reactor' in sys.modules: del sys.modules['twisted.internet.reactor'] install_twisted_reactor() except Exception as e: print('TWISTED: error installing -- %s' % str(e)) from kivy.app import App from kivy.logger import Logger # set refresh icon ALoaderOpenCV.loading_image = ImageLoader.load('data/placeholder.png', allow_stretch=False) ImageLoader.loading_image = ImageLoader.load('data/placeholder.png', allow_stretch=False) # start login process in parallel to App initialization from authentication import authenticate def on_login(token): print ('on_start: logged in') from api.streams.posts import Manager as PostsManager PostsManager.logged_in = True from modules.core.android_utils import LogTestFairy LogTestFairy('Successful login ') authenticate(on_login=on_login) from kivy.factory import Factory Factory.register('MainScreenManager', module='widgets.mainscreenmanager')
def _load_local(self, filename): '''(internal) Loading a local file''' return ImageLoader.load(filename)
def loading_image(self): """Image used for loading (readonly)""" if not self._loading_image: loading_png_fn = join(kivy_data_dir, "images", "image-loading.gif") self._loading_image = ImageLoader.load(filename=loading_png_fn) return self._loading_image
def _set_error_image(self, image): if isinstance(image, string_types): self._error_image = ImageLoader.load(filename=image) else: self._error_image = image
def _set_error_image(self, image): if isinstance(image, basestring): self._error_image = ImageLoader.load(filename=image) else: self._error_image = image
def _get_loading_image(self): if not self._loading_image: loading_png_fn = join(kivy_data_dir, 'images', 'image-loading.gif') self._loading_image = ImageLoader.load(filename=loading_png_fn) return self._loading_image
# Twisted initialization from kivy.support import install_twisted_reactor try: if platform in ['win', 'windows']: import sys if 'twisted.internet.reactor' in sys.modules: del sys.modules['twisted.internet.reactor'] install_twisted_reactor() except Exception as e: print('TWISTED: error installing -- %s' % str(e)) from kivy.app import App from kivy.logger import Logger # set refresh icon ALoaderOpenCV.loading_image = ImageLoader.load('data/placeholder.png', allow_stretch=False) ImageLoader.loading_image = ImageLoader.load('data/placeholder.png', allow_stretch=False) # start login process in parallel to App initialization from authentication import authenticate def on_login(token): print('on_start: logged in') from api.streams.posts import Manager as PostsManager PostsManager.logged_in = True from modules.core.android_utils import LogTestFairy LogTestFairy('Successful login ')
def error_image(self): """Image used for error (readonly)""" if not self._error_image: error_png_fn = join(kivy_data_dir, "error.png") self._error_image = ImageLoader.load(filename=error_png_fn) return self._error_image
def _load_local(self, filename): """(internal) Loading a local file""" return ImageLoader.load(filename)
def _get_error_image(self): if not self._error_image: error_png_fn = join( 'atlas://data/images/defaulttheme/image-missing') self._error_image = ImageLoader.load(filename=error_png_fn) return self._error_image
def load_resources(): global images_textures, sound_fx images_textures['img_brick_red_1_0'] = ImageLoader.load('res/brick_red_1.png').texture images_textures['img_brick_red_2_0'] = ImageLoader.load('res/brick_red_2.png').texture images_textures['img_brick_red_3_0'] = ImageLoader.load('res/brick_red_3.png').texture images_textures['img_brick_red_4_0'] = ImageLoader.load('res/brick_red_4.png').texture images_textures['img_brick_blu_1_0'] = ImageLoader.load('res/brick_blu_1.png').texture images_textures['img_brick_blu_2_0'] = ImageLoader.load('res/brick_blu_2.png').texture images_textures['img_brick_blu_3_0'] = ImageLoader.load('res/brick_blu_3.png').texture images_textures['img_brick_blu_4_0'] = ImageLoader.load('res/brick_blu_4.png').texture images_textures['img_brick_green_1_0'] = ImageLoader.load('res/brick_green_1.png').texture images_textures['img_brick_green_2_0'] = ImageLoader.load('res/brick_green_2.png').texture images_textures['img_brick_green_3_0'] = ImageLoader.load('res/brick_green_3.png').texture images_textures['img_brick_green_4_0'] = ImageLoader.load('res/brick_green_4.png').texture images_textures['img_brick_pink_1_0'] = ImageLoader.load('res/brick_pink_1.png').texture images_textures['img_brick_pink_2_0'] = ImageLoader.load('res/brick_pink_2.png').texture images_textures['img_brick_pink_3_0'] = ImageLoader.load('res/brick_pink_3.png').texture images_textures['img_brick_pink_4_0'] = ImageLoader.load('res/brick_pink_4.png').texture images_textures['img_brick_silv_1_0'] = ImageLoader.load('res/brick_silv_1.png').texture images_textures['img_brick_silv_2_0'] = ImageLoader.load('res/brick_silv_2.png').texture images_textures['img_brick_silv_3_0'] = ImageLoader.load('res/brick_silv_3.png').texture images_textures['img_brick_silv_4_0'] = ImageLoader.load('res/brick_silv_4.png').texture images_textures['img_brick_gold_1_0'] = ImageLoader.load('res/brick_gold_1.png').texture images_textures['img_brick_gold_2_0'] = ImageLoader.load('res/brick_gold_2.png').texture images_textures['img_brick_gold_3_0'] = ImageLoader.load('res/brick_gold_3.png').texture images_textures['img_brick_gold_4_0'] = ImageLoader.load('res/brick_gold_4.png').texture images_textures['img_brick_concrete_1_0'] = ImageLoader.load('res/brick_concrete_1.png').texture images_textures['pad_plain'] = ImageLoader.load('res/pad_plain.png').texture images_textures['line_blu'] = ImageLoader.load('res/line_blu.png').texture images_textures['touch_area'] = ImageLoader.load('res/bkg_touch.png').texture images_textures['ball_plain'] = ImageLoader.load('res/ball_200x200.png').texture images_textures['pad_yellow_2_0'] = ImageLoader.load('res/pad_yel_2_0.png').texture images_textures['pad_yellow_2_1'] = ImageLoader.load('res/pad_yel_2_1.png').texture sound_fx['game_over'] = SoundLoader.load('res/audio/gameover.ogg') sound_fx['game_start'] = SoundLoader.load('res/audio/gamestart.ogg') sound_fx['brick_hit'] = SoundLoader.load('res/audio/brickhit.ogg') sound_fx['pad_hit'] = SoundLoader.load('res/audio/padhit.ogg')
def _load_local(self, filename, kwargs): '''(internal) Loading a local file''' # With recent changes to CoreImage, we must keep data otherwise, # we might be unable to recreate the texture afterwise. return ImageLoader.load(filename, keep_data=True, **kwargs)
def _set_loading_image(self, image): if isinstance(image, string_types): self._loading_image = ImageLoader.load(filename=image) else: self._loading_image = image
def __init__(self, **kwargs): self.texture = ImageLoader.load('snake.png').texture super(SnakeLogo, self).__init__(**kwargs)
def _set_loading_image(self, image): if isinstance(image, basestring): self._loading_image = ImageLoader.load(filename=image) else: self._loading_image = image