-
-
Save lsloan/0261d5a9f2c90b000c05 to your computer and use it in GitHub Desktop.
Play each .caf sound inside of Pythonista.app
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
# sounder.py | |
# play each of the .caf sounds inside the Pythonista.app | |
import os, os.path, scene, sound | |
framesPerSound = 60 | |
pythonistaDir = os.path.expanduser('~/Pythonista.app') | |
soundFileExtension = '.caf' | |
wallpaperAppIcon = ('/AppIcon76x76@2x~ipad.png', '/[email protected]') | |
def getSoundFunction(): | |
for fileName in os.listdir(pythonistaDir): | |
if fileName.endswith(soundFileExtension): | |
yield fileName.rstrip(soundFileExtension) | |
getSoundName = getSoundFunction() | |
def getWallpaper(inWallpaperFiles = wallpaperAppIcon): | |
for wallpaperFile in inWallpaperFiles: | |
wallpaperFile = pythonistaDir + wallpaperFile | |
if os.path.isfile(wallpaperFile): # does file exists? | |
return scene.load_image_file(wallpaperFile) | |
class WallpaperLayer(scene.Layer): | |
def __init__(self, inRect): | |
super(self.__class__, self).__init__(inRect) | |
self.image = getWallpaper() | |
def iPadScreen(inBounds): # Is screen larger than an iPhone? | |
return min(inBounds.w, inBounds.h) > 350 # iPhone == 320 | |
class MyScene(scene.Scene): | |
def __init__(self): | |
scene.run(self) | |
def setup(self): | |
self.frameCount = 0 | |
self.fontSize = 100 if iPadScreen(self.bounds) else 64 | |
self.add_layer(WallpaperLayer(self.bounds)) | |
def draw(self): | |
if not self.frameCount % framesPerSound: | |
try: | |
self.soundName = getSoundName.next() | |
sound.play_effect(self.soundName) | |
except StopIteration: | |
self.soundName = None | |
self.frameCount += 1 | |
scene.background(0, 0, 0) | |
self.root_layer.update(self.dt) | |
self.root_layer.draw() | |
if self.soundName: | |
x, y = self.bounds.center() | |
scene.text(self.soundName, x=x, y=y, font_size=self.fontSize) | |
MyScene() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment