bugfix
This commit is contained in:
parent
a0c7c8b0be
commit
27b10b025b
@ -1,6 +1,7 @@
|
||||
import os
|
||||
# from kivy.logger import logging
|
||||
__version_info__ = "0.5.0"
|
||||
from .defaultimage import DefaultImage
|
||||
from .version import __version__
|
||||
|
||||
path = os.path.dirname(__file__)
|
||||
|
38
kivyblocks/defaultimage.py
Normal file
38
kivyblocks/defaultimage.py
Normal file
@ -0,0 +1,38 @@
|
||||
from kivy.uix.image import AsyncImage
|
||||
from kivy.factory import Factory
|
||||
from kivy.properties import StringProperty
|
||||
from urllib.request import urlopen
|
||||
from kivyblocks.utils import blockImage
|
||||
|
||||
class DefaultImage(AsyncImage):
|
||||
default_source = StringProperty(None)
|
||||
def __init__(self, default_source=None, **kw):
|
||||
self.default_source = default_source
|
||||
super().__init__(**kw)
|
||||
if self.default_source is None:
|
||||
self.default_source = blockImage('broken.png')
|
||||
|
||||
def can_access(self, src):
|
||||
if os.path.isfile(src):
|
||||
return True
|
||||
if self.is_uri(src):
|
||||
with urlopen(src, timeout=0.5):
|
||||
return True
|
||||
return None
|
||||
|
||||
def on_source(self, o, s):
|
||||
if not self.can_access(s):
|
||||
self.source = self.default_source
|
||||
|
||||
Factory.register('DefaultImage', DefaultImage)
|
||||
|
||||
if __name__ == '__main__':
|
||||
import os
|
||||
import sys
|
||||
from kivy.app import App
|
||||
class TestApp(App):
|
||||
def build(self):
|
||||
return DefaultImage(source=sys.argv[1], default_source='/Volumes/home/ymq/pydev/github/kivyblocks/kivyblocks/imgs/doing.gif')
|
||||
|
||||
app = TestApp()
|
||||
app.run()
|
@ -1 +1,3 @@
|
||||
__version__ = '0.2.8'
|
||||
# add a new class DefaultImage, if the source load failed, source set to default_source
|
||||
__version__ = '0.2.9'
|
||||
# __version__ = '0.2.8'
|
||||
|
Loading…
Reference in New Issue
Block a user