Aha, brilliant, thanks!
Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Latest posts made by mestela
-
RE: What what what!! New version in TestFlight!!!
Anyone on testflight have stash working? When I run launch_stash I get the warning "module plistlib has no attribute readPlist'.
I can try and debug it, but assuming at least one person on the beta has got there first. :)
-
RE: What what what!! New version in TestFlight!!!
Any chance of new slots? I keep peeking at the testflight link, and keep making a sad face when it tells me 'beta full'.
-
RE: Photo album slideshow
Great stuff, thanks! All these little tips are great for getting my rusty python skills back online.
I used to do a lot more python in my main 3d animation software, but when I switched apps, the new one doesn't require as much python, so I haven't really touched python properly in about 8 years.
-
RE: Photo album slideshow
Yep, too easy. Now I have swipe working, but that in turn meant I had to replace the itertools endless cycle with a deque. Calling this done for now.
import ui import itertools import photos from pprint import pprint import time import random from objc_util import * import gestures from collections import deque class MyView (ui.View): hold_time = 15 albums = photos.get_albums() album = [x for x in albums if x.title == 'Tvstream'][0] assets = album.assets assets = [x for x in assets if x.media_type == 'image'] random.shuffle(assets) #assets = assets[-5:] print('total assets: ' + str(len(assets))) assets = deque(assets) asset = assets[0] start_time = time.time() current_time = start_time end_time = start_time + hold_time def layout(self): insets = self.objc_instance.safeAreaInsets() self.frame = self.frame.inset(insets.top, insets.left, insets.bottom, insets.right) def reset_timer(self): self.start_time = time.time() self.current_time = self.start_time self.end_time = self.start_time + self.hold_time def draw(self): iv.image=self.asset.get_ui_image() v = MyView() v.background_color = 'black' w,h = ui.get_screen_size() v.frame = (0,0,w,h) iv = ui.ImageView() iv.frame = v.frame iv.content_mode = ui.CONTENT_SCALE_ASPECT_FIT iv.alpha=0.0 iv.image=v.asset.get_ui_image() v.add_subview(iv) v.present('fullscreen',hide_title_bar=True) def swipe_left(data): v.assets.rotate(-1) v.asset = v.assets[0] v.reset_timer() v.set_needs_display() def swipe_right(data): v.assets.rotate(1) v.asset = v.assets[0] v.reset_timer() v.set_needs_display() gestures.swipe(v, swipe_left, direction=gestures.LEFT) gestures.swipe(v, swipe_right, direction=gestures.RIGHT) while 1: # interuptable timer iv.alpha = 0.0 while v.current_time < v.end_time: if iv.alpha < 1.0 and v.current_time-v.start_time<1.0: iv.alpha += 0.1 if v.end_time - v.current_time < 1.0: iv.alpha -= 0.1 time.sleep(0.05) v.current_time+=0.05 v.assets.rotate(-1) v.asset = v.assets[0] v.reset_timer() v.set_needs_display()
-
RE: Photo album slideshow
Nice, thanks!
Funny that often when I lookup how to implement the next feature I'm interested in, I also find a way to simplify code I've written. The gestures module looks perfect for handling swipe events, in finding that I also discovered I should be using ui.animate and ui.delay. Too many cool things!
I'm also pleased that this redesign seems to be more stable; if I left the previous script run overnight, in the morning pythonista had inevitably crashed. This morning I came in to see the ipad was still happily showing images. :)
-
RE: Photo album slideshow
eyy that works great, thanks!
update, now using the itertools.cycle properly so it runs endlessly without halting, the timer is properly reset on click, few other little things:
import ui import itertools import photos from pprint import pprint import time import random from objc_util import * class MyView (ui.View): hold_time = 15 albums = photos.get_albums() album = [x for x in albums if x.title == 'Tvstream'][0] assets = album.assets assets = [x for x in assets if x.media_type == 'image'] random.shuffle(assets) print('total assets: ' + str(len(assets))) assets = itertools.cycle(assets) asset = next(assets) start_time = time.time() current_time = start_time end_time = start_time + hold_time def layout(self): insets = self.objc_instance.safeAreaInsets() self.frame = self.frame.inset(insets.top, insets.left, insets.bottom, insets.right) def reset_timer(self): self.start_time = time.time() self.current_time = self.start_time self.end_time = self.start_time + self.hold_time def draw(self): iv.image=self.asset.get_ui_image() def touch_ended(self, touch): # Called when a touch begins. self.asset = next(self.assets) print('asset is now: '+str(self.asset)) self.reset_timer() self.set_needs_display() def touch_moved(self, touch): # Called when a touch moves. pass def touch_began(self, touch): # Called when a touch ends. pass v = MyView() v.background_color = 'black' w,h = ui.get_screen_size() v.frame = (0,0,w,h) iv = ui.ImageView() iv.frame = v.frame iv.content_mode = ui.CONTENT_SCALE_ASPECT_FIT iv.alpha=0.0 iv.image=v.asset.get_ui_image() v.add_subview(iv) v.reset_timer() v.present('fullscreen',hide_title_bar=True) v.asset = next(v.assets) while 1: # interuptable timer iv.alpha = 0.0 while v.current_time < v.end_time: if iv.alpha < 1.0 and v.current_time-v.start_time<1.0: iv.alpha += 0.1 if v.end_time - v.current_time < 1.0: iv.alpha -= 0.1 time.sleep(0.05) v.current_time+=0.05 v.reset_timer() v.asset = next(v.assets) v.set_needs_display()
-
RE: Photo album slideshow
Worked on the rest of it, so fade up/fade down of the images, and a tap will skip to the next one.
Still lots wrong with it (timer needs to reset when you tap, needs a subtle progress bar, play/pause controls, needs a ui to choose the album, code layout is terrible, etc), but again, its now behaving more like I want a photo slideshow to run. Loving pythonista!
import ui import itertools import photos import time import random class MyView (ui.View): # get image assets albums = photos.get_albums() album = [x for x in albums if x.title == 'Tvstream'][0] assets = album.assets random.shuffle(assets) assets = [x for x in assets if x.media_type == 'image'] print('total assets: ' + str(len(assets))) i = 0 asset = assets[i] def draw(self): img_view.image=self.asset.get_ui_image() def touch_ended(self, touch): # Called when a touch begins. self.i += 1 self.asset = self.assets[self.i] print('asset is now: '+str(self.asset)) self.set_needs_display() def touch_moved(self, touch): # Called when a touch moves. pass def touch_began(self, touch): # Called when a touch ends. pass v = MyView() v.background_color = 'black' w,h = ui.get_screen_size() v.frame = (0,0,w,h) img_view = ui.ImageView() img_view.frame = v.frame img_view.content_mode = ui.CONTENT_SCALE_ASPECT_FIT img_view.image=v.asset.get_ui_image() v.add_subview(img_view) v.present('fullscreen',hide_title_bar=True) for asset in itertools.cycle(v.assets): start_time = time.time() current_time = start_time hold_time = 15 end_time = start_time + hold_time # interruptable timer iv = img_view while current_time < end_time: if iv.alpha < 1.0 and current_time-start_time<1.0: iv.alpha += 0.1 if end_time - current_time < 1.0: iv.alpha -= 0.1 time.sleep(0.05) current_time+=0.05 v.i += 1 v.asset = v.assets[v.i] v.set_needs_display()