From 71c9a57d4fbc4713b9f5892e1e9140d12cb256fc Mon Sep 17 00:00:00 2001 From: C. Scott Ananian Date: Fri, 14 Dec 2007 18:45:23 +0000 Subject: Move imports around to ensure 'import pippy' is as fast as possible. --- (limited to 'library') diff --git a/library/pippy/game.py b/library/pippy/game.py index c6a96b9..03a51f4 100644 --- a/library/pippy/game.py +++ b/library/pippy/game.py @@ -1,10 +1,9 @@ """pygame support for pippy.""" -import pygame - def pause(): """Display a "Paused" screen and suspend.""" from gettext import gettext as _ + import pygame caption, icon_caption = pygame.display.get_caption() screen = pygame.display.get_surface() old_screen = screen.copy() # save this for later. @@ -43,14 +42,19 @@ def pause(): pygame.display.flip() _last_event_time=0 -def next_frame(max_fps=20, idle_timeout=20, - clock=pygame.time.Clock(), pause=pause): +_default_clock=None +def next_frame(max_fps=20, idle_timeout=20, clock=None, pause=pause): """Limit maximum frame rate of pygame. Returns True. If idle longer than the idle_timeout (in seconds), then we'll put up a "paused" message and the XO will suspend. This ensures that we don't burn up all of our battery running an animation!""" - global _last_event_time + import pygame + global _last_event_time, _default_clock + if _default_clock is None: + _default_clock = pygame.time.Clock() + if clock is None: + clock = _default_clock clock.tick(max_fps) if pygame.event.peek(xrange(pygame.NOEVENT, pygame.USEREVENT)): diff --git a/library/pippy/sound.py b/library/pippy/sound.py index 570c10c..319e190 100755 --- a/library/pippy/sound.py +++ b/library/pippy/sound.py @@ -2,18 +2,19 @@ # added frequency modulation genertor # audioOut write a wave file if a string is given as argument -import os orchlines = [] scorelines = [] instrlist = [] fnum = [100] +"""XXX: This function seems to be broken. (CSA) def quit(self): perf.Stop() perf.Join() cs.Reset() cs = None +""" def defAdsr(attack=0.01, decay=0.1, sustain=0.8, release=0.1): """Define an ADSR envelope. fnum = defADSR(attack = [0.01], decay = [0.1], sustain = [0.8], release = [0.1])""" @@ -166,13 +167,16 @@ def playWave(sound='horse', pitch=1, amplitude=1, loop=False, duration=1, startt scorelines.append('i9 %f %f "%s" %s %s %s %s %s\n' % (float(starttime), float(duration), fullname, str(pitch), str(amplitude), str(lp), str(pitenv), str(ampenv))) def getSoundList(): + import os return sorted(os.listdir('/usr/share/activities/TamTamEdit.activity/common/Resources/Sounds/')) def audioOut(file=None): """Compile a .csd file and start csound to run it. If a string is given as argument, it write a wave file on disk instead of sending sound to hp. (file = [None])""" global temp_path + import os if temp_path is None: from sugar import env + import os.path temp_path = env.get_profile_path() + '/pippy' if not os.path.isdir(temp_path): os.mkdir(temp_path) -- cgit v0.9.1