def load(self, target=None, name=None, function=lambda: None, synch=False, onLoad=None, onCancel=None): if self.logLoadings == 1: Log.notice("Loading %s.%s %s" % (target.__class__.__name__, name, synch and "synchronously" or "asynchronously")) l = Loader(target, name, function, self.resultQueue, self.loaderSemaphore, onLoad=onLoad, onCancel=onCancel) if synch: l.load() return l.finish() else: self.loaders.append(l) l.start() return l
def keyName(value): if value in CONTROL1: name = "Controller 1" control = CONTROL1 n = 0 elif value in CONTROL2: name = "Controller 2" control = CONTROL2 n = 1 elif value in CONTROL3: name = "Controller 3" control = CONTROL3 n = 2 else: name = "Controller 4" control = CONTROL4 n = 3 for j in range(20): if value == control[j]: if self.type[n] == 2: return name + " " + drumkey4names[j] elif self.type[n] == 3: return name + " " + drumkey5names[j] else: return name + " " + guitarkeynames[j] else: Log.notice("Key value not found.") return "Error"
def __init__(self, guitarScene, configFileName, coOp=False): self.scene = guitarScene self.engine = guitarScene.engine self.layers = {} #collection of all the layers in the rockmeter self.layersForRender = { } #collection of layers that are rendered separate from any group self.layerGroups = {} #collection of layer groups self.sharedLayerGroups = {} self.sharedLayers = {} #these layers are for coOp use only self.sharedLayersForRender = {} self.sharedGroups = {} self.coOp = coOp self.config = LinedConfigParser() self.config.read(configFileName) self.themename = self.engine.data.themeLabel try: themepath = os.path.join(Version.dataPath(), "themes", self.themename) fp, pathname, description = imp.find_module( "CustomRMLayers", [themepath]) self.customRMLayers = imp.load_module("CustomRMLayers", fp, pathname, description) except ImportError: self.customRMLayers = None Log.notice("Custom Rockmeter layers are not available") # Build the layers for i in range(Rockmeter._layerLimit): types = ["Image", "Text", "Circle", "Custom"] for t in types: self.section = "layer%d:%s" % (i, t) if not self.config.has_section(self.section): continue else: if t == types[1]: self.createFont(self.section, i) elif t == types[2]: self.createCircle(self.section, i) elif t == types[3]: self.createCustom(self.section, i) else: self.createImage(self.section, i) break for i in range(Rockmeter._groupLimit): self.section = "Group%d" % i if not self.config.has_section(self.section): continue else: self.createGroup(self.section, i) print self.layerGroups print self.sharedLayerGroups print self.layersForRender self.reset()
def finishGame(self): if not self.world: Log.notice("GameEngine.finishGame called before World created.") return self.world.finishGame() self.world = None self.gameStarted = False self.view.pushLayer(self.mainMenu)
def fileName(self, *name, **args): #myfingershurt: the following should be global, and only done at startup. Not every damn time a file is loaded. songPath = self.songPath if not args.get("writable", False): for dataPath in self.dataPaths + songPath: readOnlyPath = os.path.join(dataPath, *name) # If the requested file is in the read-write path and not in the # read-only path, use the existing read-write one. if os.path.isfile(readOnlyPath): return readOnlyPath elif os.path.isdir(readOnlyPath): return readOnlyPath readWritePath = os.path.join(getWritableResourcePath(), *name) if os.path.isfile(readWritePath): return readWritePath return readOnlyPath else: for dataPath in [self.dataPaths[-1]] + songPath: readOnlyPath = os.path.join(dataPath, *name) if not (os.path.isfile(readOnlyPath) or os.path.isdir(readOnlyPath)): continue try: # First see if we can write to the original file if os.access(readOnlyPath, os.W_OK): return readOnlyPath # If the original file does not exist, see if we can write to its directory if not os.path.isfile(readOnlyPath) and os.access( os.path.dirname(readOnlyPath), os.W_OK): pass except: raise # If the resource exists in the read-only path, make a copy to the # read-write path. readWritePath = os.path.join(getWritableResourcePath(), *name) if not os.path.isfile(readWritePath) and os.path.isfile( readOnlyPath): Log.notice("Copying '%s' to writable data directory." % "/".join(name)) try: os.makedirs(os.path.dirname(readWritePath)) except: pass shutil.copy(readOnlyPath, readWritePath) self.makeWritable(readWritePath) # Create directories if needed if not os.path.isdir(readWritePath) and os.path.isdir( readOnlyPath): Log.notice("Creating writable directory '%s'." % "/".join(name)) os.makedirs(readWritePath) self.makeWritable(readWritePath) return readWritePath return readOnlyPath
def load(self, target = None, name = None, function = lambda: None, synch = False, onLoad = None, onCancel = None): if self.logLoadings == 1: Log.notice("Loading %s.%s %s" % (target.__class__.__name__, name, synch and "synchronously" or "asynchronously")) l = Loader(target, name, function, self.resultQueue, self.loaderSemaphore, onLoad = onLoad, onCancel = onCancel) if synch: l.load() return l.finish() else: self.loaders.append(l) l.start() return l
def fileName(self, *name, **args): #myfingershurt: the following should be global, and only done at startup. Not every damn time a file is loaded. songPath = self.songPath if not args.get("writable", False): for dataPath in self.dataPaths + songPath: readOnlyPath = os.path.join(dataPath, *name) # If the requested file is in the read-write path and not in the # read-only path, use the existing read-write one. if os.path.isfile(readOnlyPath): return readOnlyPath elif os.path.isdir(readOnlyPath): return readOnlyPath readWritePath = os.path.join(getWritableResourcePath(), *name) if os.path.isfile(readWritePath): return readWritePath return readOnlyPath else: for dataPath in [self.dataPaths[-1]] + songPath: readOnlyPath = os.path.join(dataPath, *name) if not (os.path.isfile(readOnlyPath) or os.path.isdir(readOnlyPath)): continue try: # First see if we can write to the original file if os.access(readOnlyPath, os.W_OK): return readOnlyPath # If the original file does not exist, see if we can write to its directory if not os.path.isfile(readOnlyPath) and os.access(os.path.dirname(readOnlyPath), os.W_OK): pass except: raise # If the resource exists in the read-only path, make a copy to the # read-write path. readWritePath = os.path.join(getWritableResourcePath(), *name) if not os.path.isfile(readWritePath) and os.path.isfile(readOnlyPath): Log.notice("Copying '%s' to writable data directory." % "/".join(name)) try: os.makedirs(os.path.dirname(readWritePath)) except: pass shutil.copy(readOnlyPath, readWritePath) self.makeWritable(readWritePath) # Create directories if needed if not os.path.isdir(readWritePath) and os.path.isdir(readOnlyPath): Log.notice("Creating writable directory '%s'." % "/".join(name)) os.makedirs(readWritePath) self.makeWritable(readWritePath) return readWritePath return readOnlyPath
def finish(self): if self.canceled: if self.onCancel: self.onCancel() return if self.logLoadings == 1: Log.notice("Loaded %s.%s in %.3f seconds" % (self.target.__class__.__name__, self.name, self.time)) if self.exception: raise self.exception[0], self.exception[1], self.exception[2] if self.target and self.name: setattr(self.target, self.name, self.result) if self.onLoad: self.onLoad(self.result) return self.result
def run(self, ticks): while self.mic.get_read_available() > 1024: try: chunk = self.mic.read(1024) except IOError, e: if e.args[1] == pyaudio.paInputOverflowed: Log.notice('Microphone: ignoring input buffer overflow') chunk = '\x00' * 4096 else: raise if self.passthroughStream is not None: self.passthroughQueue.append(chunk) self.analyzer.input(np.frombuffer(chunk, dtype=np.float32)) self.analyzer.process() pk = self.analyzer.getPeak() if self.detectTaps: if pk > self.tapThreshold and pk > self.lastPeak + 5.0: self.tapStatus = True self.lastPeak = pk
def run(self, ticks): while self.mic.get_read_available() > 1024: try: chunk = self.mic.read(1024) except IOError, e: if e.args[1] == pyaudio.paInputOverflowed: Log.notice( 'Microphone: ignoring input buffer overflow') chunk = '\x00' * 4096 else: raise if self.passthroughStream is not None: self.passthroughQueue.append(chunk) self.analyzer.input(np.frombuffer(chunk, dtype=np.float32)) self.analyzer.process() pk = self.analyzer.getPeak() if self.detectTaps: if pk > self.tapThreshold and pk > self.lastPeak + 5.0: self.tapStatus = True self.lastPeak = pk
def getImgDrawing(self, fileName, openImage=True): imgDrawing = None for dataPath in self.resource.dataPaths: fileName1 = os.path.join(dataPath, fileName) if self.logLoadings == 1: if openImage: Log.notice("Trying to load image: %s" % fileName1) else: Log.notice("Checking image: %s" % fileName1) #check if fileName1 exists (has extension) if os.path.exists(fileName1): if openImage == True: try: imgDrawing = ImgDrawing(self.svg, fileName1) return imgDrawing except IOError: Log.warn("Unable to load image file: %s" % fileName1) except OverflowError: Log.warn("Unable to read image file: %s" % fileName1) else: return True else: #find extension fileName1 = os.path.splitext(fileName1)[0] files = glob.glob('%s.*' % fileName1) if openImage == True: for i in range(len(files)): try: imgDrawing = ImgDrawing(self.svg, files[i]) return imgDrawing except IOError: Log.warn("Unable to load image file: %s" % files[i]) elif len(files) > 0: return True #image not found if self.logImageNotFound: Log.debug("Image not found: %s" % fileName) return False
def getImgDrawing(self, fileName, openImage=True): imgDrawing = None for dataPath in self.resource.dataPaths: fileName1 = os.path.join(dataPath, fileName) if self.logLoadings == 1: if openImage: Log.notice("Trying to load image: %s" % fileName1) else: Log.notice("Checking image: %s" % fileName1) # check if fileName1 exists (has extension) if os.path.exists(fileName1): if openImage == True: try: imgDrawing = ImgDrawing(self.svg, fileName1) return imgDrawing except IOError: Log.warn("Unable to load image file: %s" % fileName1) except OverflowError: Log.warn("Unable to read image file: %s" % fileName1) else: return True else: # find extension fileName1 = os.path.splitext(fileName1)[0] files = glob.glob("%s.*" % fileName1) if openImage == True: for i in range(len(files)): try: imgDrawing = ImgDrawing(self.svg, files[i]) return imgDrawing except IOError: Log.warn("Unable to load image file: %s" % files[i]) elif len(files) > 0: return True # image not found if self.logImageNotFound: Log.debug("Image not found: %s" % fileName) return False
videoLayer = True engine.ticksAtStart = pygame.time.get_ticks() while not vidPlayer.finished: engine.run() engine.view.popLayer(vidPlayer) engine.view.pushLayer(MainMenu(engine)) if not videoLayer: engine.setStartupLayer(MainMenu(engine)) # Run the main game loop. try: engine.ticksAtStart = pygame.time.get_ticks() while engine.run(): pass except KeyboardInterrupt: Log.notice("Left mainloop due to KeyboardInterrupt.") # don't reraise # Restart the program if the engine is asking that we do so. if engine.restartRequested: Log.notice("Restarting.") engine.audio.close() try: # Extra arguments to insert between the executable we call and our # command line arguments. args = [] # Figure out what executable to call. if hasattr(sys, "frozen"): if os.name == "nt": # When py2exe'd, sys.executable is the name of the EXE. exe = os.path.abspath(unicode(sys.executable, sys.getfilesystemencoding()))
def __init__(self): self.logClassInits = Config.get("game", "log_class_inits") if self.logClassInits == 1: Log.debug("Input class init (Input.py)...") Task.__init__(self) self.mouse = pygame.mouse self.mouseListeners = [] self.keyListeners = [] self.systemListeners = [] self.priorityKeyListeners = [] self.controls = Controls() self.activeGameControls = [] self.p2Nav = self.controls.p2Nav self.type1 = self.controls.type[0] self.keyCheckerMode = Config.get("game", "key_checker_mode") self.disableKeyRepeat() self.gameGuitars = 0 self.gameDrums = 0 self.gameMics = 0 self.gameBots = 0 # Initialize joysticks pygame.joystick.init() self.joystickNames = {} self.joystickAxes = {} self.joystickHats = {} self.joysticks = [ pygame.joystick.Joystick(id) for id in range(pygame.joystick.get_count()) ] for j in self.joysticks: j.init() self.joystickNames[j.get_id()] = j.get_name() self.joystickAxes[j.get_id()] = [0] * j.get_numaxes() self.joystickHats[j.get_id()] = [(0, 0)] * j.get_numhats() Log.debug("%d joysticks found." % len(self.joysticks)) # Enable music events Audio.Music.setEndEvent(MusicFinished) #Audio.Music.setEndEvent() #MFH - no event required? # Custom key names self.getSystemKeyName = pygame.key.name pygame.key.name = self.getKeyName self.midi = [] if haveMidi: pygame.midi.init() for i in range(pygame.midi.get_count()): interface, name, is_input, is_output, is_opened = pygame.midi.get_device_info( i) Log.debug("Found MIDI device: %s on %s" % (name, interface)) if not is_input: Log.debug("MIDI device is not an input device.") continue try: self.midi.append(pygame.midi.Input(i)) Log.debug("Device opened as device number %d." % len(self.midi)) except pygame.midi.MidiException: Log.error("Error opening device for input.") if len(self.midi) == 0: Log.debug("No MIDI input ports found.") else: Log.notice( "MIDI input support is not available; install at least pygame 1.9 to get it." )
def __init__(self): self.logClassInits = Config.get("game", "log_class_inits") if self.logClassInits == 1: Log.debug("Input class init (Input.py)...") Task.__init__(self) self.mouse = pygame.mouse self.mouseListeners = [] self.keyListeners = [] self.systemListeners = [] self.priorityKeyListeners = [] self.controls = Controls() self.activeGameControls = [] self.p2Nav = self.controls.p2Nav self.type1 = self.controls.type[0] self.keyCheckerMode = Config.get("game","key_checker_mode") self.disableKeyRepeat() self.gameGuitars = 0 self.gameDrums = 0 self.gameMics = 0 self.gameBots = 0 # Initialize joysticks pygame.joystick.init() self.joystickNames = {} self.joystickAxes = {} self.joystickHats = {} self.joysticks = [pygame.joystick.Joystick(id) for id in range(pygame.joystick.get_count())] for j in self.joysticks: j.init() self.joystickNames[j.get_id()] = j.get_name() self.joystickAxes[j.get_id()] = [0] * j.get_numaxes() self.joystickHats[j.get_id()] = [(0, 0)] * j.get_numhats() Log.debug("%d joysticks found." % len(self.joysticks)) # Enable music events Audio.Music.setEndEvent(MusicFinished) #Audio.Music.setEndEvent() #MFH - no event required? # Custom key names self.getSystemKeyName = pygame.key.name pygame.key.name = self.getKeyName self.midi = [] if haveMidi: pygame.midi.init() for i in range(pygame.midi.get_count()): interface, name, is_input, is_output, is_opened = pygame.midi.get_device_info(i) Log.debug("Found MIDI device: %s on %s" % (name, interface)) if not is_input: Log.debug("MIDI device is not an input device.") continue try: self.midi.append(pygame.midi.Input(i)) Log.debug("Device opened as device number %d." % len(self.midi)) except pygame.midi.MidiException: Log.error("Error opening device for input.") if len(self.midi) == 0: Log.debug("No MIDI input ports found.") else: Log.notice("MIDI input support is not available; install at least pygame 1.9 to get it.")
def __init__(self, guitarScene, configFileName, coOp = False): self.scene = guitarScene self.engine = guitarScene.engine self.layers = {} #collection of all the layers in the rockmeter self.layersForRender = {} #collection of layers that are rendered separate from any group self.layerGroups = {} #collection of layer groups self.sharedLayerGroups = {} self.sharedLayers = {} #these layers are for coOp use only self.sharedLayersForRender = {} self.sharedGroups = {} self.coOp = coOp self.config = LinedConfigParser() self.config.read(configFileName) self.themename = self.engine.data.themeLabel try: themepath = os.path.join(Version.dataPath(), "themes", self.themename) fp, pathname, description = imp.find_module("CustomRMLayers",[themepath]) self.customRMLayers = imp.load_module("CustomRMLayers", fp, pathname, description) except ImportError: self.customRMLayers = None Log.notice("Custom Rockmeter layers are not available") # Build the layers for i in range(Rockmeter._layerLimit): types = [ "Image", "Text", "Circle", "Custom" ] for t in types: self.section = "layer%d:%s" % (i, t) if not self.config.has_section(self.section): continue else: if t == types[1]: self.createFont(self.section, i) elif t == types[2]: self.createCircle(self.section, i) elif t == types[3]: self.createCustom(self.section, i) else: self.createImage(self.section, i) break for i in range(Rockmeter._groupLimit): self.section = "Group%d" % i if not self.config.has_section(self.section): continue else: self.createGroup(self.section, i) print self.layerGroups print self.sharedLayerGroups print self.layersForRender self.reset()
def load(self, libraryName, songName, practiceMode = False): if self.scene.coOpType: rm = os.path.join("themes", self.themename, "rockmeter_coop.ini") elif self.scene.battle or self.scene.battleGH: rm = os.path.join("themes", self.themename, "rockmeter_profaceoff.ini") elif self.scene.gamePlayers > 1: rm = os.path.join("themes", self.themename, "rockmeter_faceoff.ini") else: rm = os.path.join("themes", self.themename, "rockmeter.ini") if os.path.exists(os.path.join("..", "data", rm)): rockmeter = self.engine.resource.fileName(rm) else: rockmeter = self.engine.resource.fileName(os.path.join("themes", self.themename, "rockmeter.ini")) self.rockmeter = Rockmeter.Rockmeter(self.scene, rockmeter, self.scene.coOpType) # evilynux - Fixes a self.background not defined crash self.background = None #MFH - new background stage logic: if self.mode == 2: #blank / no stage self.songStage = 0 self.rotationMode = 0 elif practiceMode: #check for existing practice stage; always disable stage rotation here self.songStage = 0 self.rotationMode = 0 self.mode = 1 #separated practice stages for the instruments by k.i.d if self.scene.instruments[0].isDrum: background = "practicedrum" elif self.scene.instruments[0].isBassGuitar: background = "practicebass" else: background = "practice" if not self.engine.loadImgDrawing(self, "background", os.path.join("themes",self.themename,"backgrounds",background)): #MFH - must first fall back on the old practice.png before forcing blank stage mode! if not self.engine.loadImgDrawing(self, "background", os.path.join("themes",self.themename,"backgrounds","practice")): Log.warn("No practice stage, falling back on a forced Blank stage mode") # evilynux self.mode = 2 #if no practice stage, just fall back on a forced Blank stage mode elif self.songStage == 1: #check for song-specific background test = True if not self.engine.loadImgDrawing(self, "background", os.path.join(libraryName, songName, "background")): Log.notice("No song-specific stage found") # evilynux test = False if test: #does a song-specific background exist? self.rotationMode = 0 self.mode = 1 else: self.songStage = 0 #MFH - now, after the above logic, we can run the normal stage mode logic # only worrying about checking for Blank, song-specific and # practice stage modes if self.mode != 2 and self.mode != 3 and self.songStage == 0 and not practiceMode: #still need to load stage(s) #myfingershurt: assign this first if self.mode == 1: #just use Default.png if not self.engine.loadImgDrawing(self, "background", os.path.join(self.path, "default")): Log.warn("No default stage; falling back on a forced Blank stage mode") # evilynux self.mode = 2 #if no practice stage, just fall back on a forced Blank stage mode ##This checks how many Stage-background we have to select from if self.mode == 0 and self.rotationMode == 0: #MFH: just display a random stage files = [] fileIndex = 0 allfiles = os.listdir(self.pathfull) for name in allfiles: if os.path.splitext(name)[0].lower() != "practice" and os.path.splitext(name)[0].lower() != "practicedrum" and os.path.splitext(name)[0].lower() != "practicebass" and name != ".svn": Log.debug("Valid background found, index (" + str(fileIndex) + "): " + name) files.append(name) fileIndex += 1 else: Log.debug("Practice background filtered: " + name) # evilynux - improved error handling, fallback to blank background if no background are found if fileIndex == 0: Log.warn("No valid stage found!") self.mode = 2; else: i = random.randint(0,len(files)-1) filename = files[i] ##End check number of Stage-backgrounds if not self.engine.loadImgDrawing(self, "background", os.path.join(self.path, filename)): self.mode = 2; elif self.rotationMode > 0 and self.mode != 2: files = [] fileIndex = 0 if self.animatedFolder == "Random": #Select one of the subfolders under stages\ to animate randomly numAniStageFolders = len(self.engine.stageFolders) if numAniStageFolders > 0: self.animatedFolder = random.choice(self.engine.stageFolders) else: self.animatedFolder = "Normal" elif self.animatedFolder == "None": self.mode = 2 if self.animatedFolder != "Normal" and self.mode != 2: #just use the base Stages folder for rotation self.path = os.path.join("themes",self.themename,"backgrounds",self.animatedFolder) self.pathfull = self.engine.getPath(self.path) self.animation = True allfiles = os.listdir(self.pathfull) for name in allfiles: if os.path.splitext(name)[1].lower() == ".png" or os.path.splitext(name)[1].lower() == ".jpg" or os.path.splitext(name)[1].lower() == ".jpeg": if os.path.splitext(name)[0].lower() != "practice" and os.path.splitext(name)[0].lower() != "practicedrum" and os.path.splitext(name)[0].lower() != "practicebass": Log.debug("Valid background found, index (" + str(fileIndex) + "): " + name) files.append(name) fileIndex += 1 else: Log.debug("Practice background filtered: " + name) files.sort() if self.rotationMode > 0 and self.mode != 2: #alarian: blank stage option is not selected #myfingershurt: just populate the image array in order, they are pulled in whatever order requested: for j in range(len(files)): self.engine.loadImgDrawing(self, "backgroundA", os.path.join(self.path, files[j])) self.imgArr.append(getattr(self, "backgroundA", os.path.join(self.path, files[j]))) if self.rotationMode > 0 and len(self.imgArr) == 0: self.rotationMode = 0
def load(self, libraryName, songName, practiceMode=False): if self.scene.coOpType: rm = os.path.join("themes", self.themename, "rockmeter_coop.ini") elif self.scene.battle or self.scene.battleGH: rm = os.path.join("themes", self.themename, "rockmeter_profaceoff.ini") elif self.scene.gamePlayers > 1: rm = os.path.join("themes", self.themename, "rockmeter_faceoff.ini") else: rm = os.path.join("themes", self.themename, "rockmeter.ini") if os.path.exists(os.path.join("..", "data", rm)): rockmeter = self.engine.resource.fileName(rm) else: rockmeter = self.engine.resource.fileName( os.path.join("themes", self.themename, "rockmeter.ini")) self.rockmeter = Rockmeter.Rockmeter(self.scene, rockmeter, self.scene.coOpType) # evilynux - Fixes a self.background not defined crash self.background = None #MFH - new background stage logic: if self.mode == 2: #blank / no stage self.songStage = 0 self.rotationMode = 0 elif practiceMode: #check for existing practice stage; always disable stage rotation here self.songStage = 0 self.rotationMode = 0 self.mode = 1 #separated practice stages for the instruments by k.i.d if self.scene.instruments[0].isDrum: background = "practicedrum" elif self.scene.instruments[0].isBassGuitar: background = "practicebass" else: background = "practice" if not self.engine.loadImgDrawing( self, "background", os.path.join("themes", self.themename, "backgrounds", background)): #MFH - must first fall back on the old practice.png before forcing blank stage mode! if not self.engine.loadImgDrawing( self, "background", os.path.join("themes", self.themename, "backgrounds", "practice")): Log.warn( "No practice stage, falling back on a forced Blank stage mode" ) # evilynux self.mode = 2 #if no practice stage, just fall back on a forced Blank stage mode elif self.songStage == 1: #check for song-specific background test = True if not self.engine.loadImgDrawing( self, "background", os.path.join(libraryName, songName, "background")): Log.notice("No song-specific stage found") # evilynux test = False if test: #does a song-specific background exist? self.rotationMode = 0 self.mode = 1 else: self.songStage = 0 #MFH - now, after the above logic, we can run the normal stage mode logic # only worrying about checking for Blank, song-specific and # practice stage modes if self.mode != 2 and self.mode != 3 and self.songStage == 0 and not practiceMode: #still need to load stage(s) #myfingershurt: assign this first if self.mode == 1: #just use Default.png if not self.engine.loadImgDrawing( self, "background", os.path.join(self.path, "default")): Log.warn( "No default stage; falling back on a forced Blank stage mode" ) # evilynux self.mode = 2 #if no practice stage, just fall back on a forced Blank stage mode ##This checks how many Stage-background we have to select from if self.mode == 0 and self.rotationMode == 0: #MFH: just display a random stage files = [] fileIndex = 0 allfiles = os.listdir(self.pathfull) for name in allfiles: if os.path.splitext(name)[0].lower( ) != "practice" and os.path.splitext(name)[0].lower( ) != "practicedrum" and os.path.splitext(name)[0].lower( ) != "practicebass" and name != ".svn": Log.debug("Valid background found, index (" + str(fileIndex) + "): " + name) files.append(name) fileIndex += 1 else: Log.debug("Practice background filtered: " + name) # evilynux - improved error handling, fallback to blank background if no background are found if fileIndex == 0: Log.warn("No valid stage found!") self.mode = 2 else: i = random.randint(0, len(files) - 1) filename = files[i] ##End check number of Stage-backgrounds if not self.engine.loadImgDrawing( self, "background", os.path.join(self.path, filename)): self.mode = 2 elif self.rotationMode > 0 and self.mode != 2: files = [] fileIndex = 0 if self.animatedFolder == "Random": #Select one of the subfolders under stages\ to animate randomly numAniStageFolders = len(self.engine.stageFolders) if numAniStageFolders > 0: self.animatedFolder = random.choice( self.engine.stageFolders) else: self.animatedFolder = "Normal" elif self.animatedFolder == "None": self.mode = 2 if self.animatedFolder != "Normal" and self.mode != 2: #just use the base Stages folder for rotation self.path = os.path.join("themes", self.themename, "backgrounds", self.animatedFolder) self.pathfull = self.engine.getPath(self.path) self.animation = True allfiles = os.listdir(self.pathfull) for name in allfiles: if os.path.splitext( name)[1].lower() == ".png" or os.path.splitext( name)[1].lower() == ".jpg" or os.path.splitext( name)[1].lower() == ".jpeg": if os.path.splitext(name)[0].lower( ) != "practice" and os.path.splitext(name)[0].lower( ) != "practicedrum" and os.path.splitext( name)[0].lower() != "practicebass": Log.debug("Valid background found, index (" + str(fileIndex) + "): " + name) files.append(name) fileIndex += 1 else: Log.debug("Practice background filtered: " + name) files.sort() if self.rotationMode > 0 and self.mode != 2: #alarian: blank stage option is not selected #myfingershurt: just populate the image array in order, they are pulled in whatever order requested: for j in range(len(files)): self.engine.loadImgDrawing( self, "backgroundA", os.path.join(self.path, files[j])) self.imgArr.append( getattr(self, "backgroundA", os.path.join(self.path, files[j]))) if self.rotationMode > 0 and len(self.imgArr) == 0: self.rotationMode = 0