--
Not sure urlRequest will work for samba share. But yeah, in any case, a correct use of threal would avoid blocking the interface.
--
'''
Pictures demo
=============
This is a basic picture viewer, using the scatter widget.
'''
import kivy
kivy.require('1.0.6')
from glob import glob
from random import randint
from os.path import join, dirname
from kivy.app import App
from kivy.logger import Logger
from kivy.uix.scatter import Scatter
from kivy.properties import StringProperty
# FIXME this shouldn't be necessary
from kivy.core.window import Window
#START CODE I MODIFIED
import threading
from kivy.core.image import Image
class ThreadedLoader(threading.Thread):
source = ""
callback = None
def __init__(self, source, callback):
threading.Thread.__init__ ( self )
self.source = source
self.callback = callback
def run(self):
Image.load(self.source)
self.callback()
class Picture(Scatter):
'''Picture is the class that will show the image with a white border and a
shadow. They are nothing here because almost everything is inside the
picture.kv. Check the rule named <Picture> inside the file, and you'll see
how the Picture() is really constructed and used.
The source property will be the filename to show.
'''
source = StringProperty(None)
def __init__(self, **kwargs):
#Pop source property to prevent normal image loading.
self.cached_source = kwargs.pop("source", "")
super(Picture, self).__init__(**kwargs)
#Instruct our threaded loader to load the content
ThreadedLoader(self.cached_source, self.loaded).start()
def loaded(self):
#When receiving the callback, update the source property,
# and ideally Kivy's normal codepath should do the rest.
self.source = self.cached_source
#END CODE I MODIFIED
class PicturesApp(App):
def build(self):
# the root is created in pictures.kv
root = self.root
# get any files into images directory
curdir = dirname(__file__)
for filename in glob(join(curdir, 'images', '*')):
try:
# load the image
picture = Picture(source=filename, rotation=randint(-30,30))
# add to the main field
root.add_widget(picture)
except Exception, e:
Logger.exception('Pictures: Unable to load <%s>' % filename)
def on_pause(self):
return True
if __name__ in ('__main__', '__android__'):
PicturesApp().run()
--
'''
Pictures demo
=============
This is a basic picture viewer, using the scatter widget.
'''
from random import randint
from kivy.app import App
from kivy.uix.scatter import Scatter
from kivy.properties import StringProperty
from kivy.clock import Clock
from kivy.uix.videoplayer import VideoPlayer
from kivy.logger import Logger
from smb.SMBConnection import SMBConnection
userID = 'xxxxxxxx'
password = 'xxxxxxxx'
client_machine_name = ''
server_name = ''
server_ip = '192.168.11.99'
service_name = 'code' # share name
vid_service_name = 'meditation' # share name
path = 'multitouch/MT__code/akfork/kivy/examples/demo/pictures/images'
vid_file = 'Meditation/Deep Meditation Experience.flv'
import threading
import tempfile
class M_Loader(threading.Thread):
def __init__(self, **kwargs):
super(M_Loader, self).__init__(**kwargs)
def load_vid(self, fil, pic):
conn = SMBConnection(userID, password, client_machine_name,
server_name, use_ntlm_v2 = True)
assert conn.connect(server_ip, 139)
suffix = '.%s' % (fil.split('.')[-1])
file_obj = tempfile.NamedTemporaryFile(prefix='loader', suffix=suffix, delete = False)
servn = 'media'
pth = fil
file_attributes, filesize = conn.retrieveFile(servn, pth, file_obj)
pic.vid.source = file_obj.name
pic.vid.play = True
conn.close()
file_obj.close()
def load_pix(self, fil):
conn = SMBConnection(userID, password, client_machine_name,
server_name, use_ntlm_v2 = True)
assert conn.connect(server_ip, 139)
suffix = '.%s' % (fil.filename.split('.')[-1])
file_obj = tempfile.NamedTemporaryFile(prefix='loader', suffix=suffix,
delete=False)
file_attributes, filesize = conn.retrieveFile(service_name,
path + '/' + fil.filename, file_obj)
while filesize != fil.file_size:
pass
conn.close()
file_obj.close()
# using clock here is unnecessary cause all we are doing is changing
# the source string property which is updated in the main thread any way.
# Clock is used just to show a slight delay of 2 secs, one can simply do
# fil.picture.source = file_obj.name
Clock.schedule_once(lambda *args: fil.picture.func(file_obj.name), 2)
class Picture(Scatter):
'''Picture is the class that will show the image with a white border and a
shadow. They are nothing here because almost everything is inside the
picture.kv. Check the rule named <Picture> inside the file, and you'll see
how the Picture() is really constructed and used.
The source property will be the filename to show.
'''
source = StringProperty(None)
def func(self, filename):
self.source = filename
def on_touch_down(self, touch):
if self.collide_point(*touch.pos) and touch.is_double_tap:
if not hasattr(self, 'vid'):
self.vid = vid = VideoPlayer()
self.add_widget(vid)
self.bind(
pos = vid.setter('pos'),
size = vid.setter('size'))
M_Loader().load_vid(vid_file, self)
return super(Picture, self).on_touch_down(touch)
class PicturesApp(App):
def build(self):
# the root is created in pictures.kv
root = self.root
# get any files into images directory
conn = SMBConnection(userID, password, client_machine_name,
server_name, use_ntlm_v2 = True)
assert conn.connect(server_ip, 139)
file_list = conn.listPath(service_name, path, search=55, pattern='*'
,timeout=30)
conn.close()
for fil in file_list:
if fil.filename not in ('.', '..', '.empty'):
try:
# load the image
fil.picture = picture = Picture(source=
'data/images/image-loading.gif', rotation=randint(-30,30))
# add to the main field
root.add_widget(picture)
M_Loader().load_pix(fil)
except Exception, e:
Logger.exception('Pictures: Unable to load <%s>'
% fil.filename)
def on_pause(self):
return True
if __name__ == '__main__':
PicturesApp().run()
'''
Pictures demo
=============
This is a basic picture viewer, using the scatter widget.
'''
import kivy
kivy.require('1.0.6')
from glob import glob
from random import randint
from os.path import join, dirname
from kivy.app import App
from kivy.logger import Logger
from kivy.uix.scatter import Scatter
from kivy.properties import StringProperty
# FIXME this shouldn't be necessary
from kivy.core.window import Window
from smb.SMBConnection import SMBConnection
userID = 'xxxxxxxxxxxx'
password = 'xxxxxxxxxx'
client_machine_name = ''
server_name = ''
server_ip = '192.168.11.94'
service_name = 'code'
path = 'multitouch/MT__code/akfork/kivy/examples/demo/pictures/images'
class Picture(Scatter):
'''Picture is the class that will show the image with a white border and a
shadow. They are nothing here because almost everything is inside the
picture.kv. Check the rule named <Picture> inside the file, and you'll see
how the Picture() is really constructed and used.
The source property will be the filename to show.
'''
source = StringProperty(None)
class PicturesApp(App):
def build(self):
# the root is created in pictures.kv
root = self.root
# get any files into images directory
curdir = dirname(__file__)
conn = SMBConnection(userID, password, client_machine_name,
server_name, use_ntlm_v2 = True)
assert conn.connect(server_ip, 139)
file_list = conn.listPath(service_name, path, search=55, pattern='*', timeout=30)
conn.close()
for fil in file_list:
if fil.filename not in ('.', '..', '.empty'):
try:
# load the image
src = 'smb://%s:%s@%s/%s/%s/%s' %(userID, password, server_ip, service_name, path, fil.filename)
picture = Picture(source=src, rotation=randint(-30,30))
# add to the main field
root.add_widget(picture)
except Exception, e:
Logger.exception('Pictures: Unable to load <%s>' % fil.filename)
def on_pause(self):
return True
if __name__ == '__main__':
PicturesApp().run()
--