def toggle_translucency(world): """Make certain building types translucent""" if not hasattr(world, "_translucent_buildings"): world._translucent_buildings = set() if not world._translucent_buildings: # no translucent buildings saved => enable building_types = world.session.db.get_translucent_buildings() add = world._translucent_buildings.add from weakref import ref as create_weakref for b in world.get_all_buildings(): if b.id in building_types: fife_instance = b._instance add(create_weakref(fife_instance)) fife_instance.keep_translucency = True fife_instance.get2dGfxVisual().setTransparency( BUILDINGS.TRANSPARENCY_VALUE) else: # undo translucency for inst in world._translucent_buildings: try: inst().get2dGfxVisual().setTransparency(0) inst().keep_translucency = False except AttributeError: pass # obj has been deleted, inst() returned None world._translucent_buildings.clear()
def toggle_translucency(world): """Make certain building types translucent""" if not hasattr(world, "_translucent_buildings"): world._translucent_buildings = set() if not world._translucent_buildings: # no translucent buildings saved => enable building_types = world.session.db.get_translucent_buildings() add = world._translucent_buildings.add from weakref import ref as create_weakref for b in world.get_all_buildings(): if b.id in building_types: fife_instance = b._instance add( create_weakref(fife_instance) ) fife_instance.keep_translucency = True fife_instance.get2dGfxVisual().setTransparency( BUILDINGS.TRANSPARENCY_VALUE ) else: # undo translucency for inst in world._translucent_buildings: try: inst().get2dGfxVisual().setTransparency( 0 ) inst().keep_translucency = False except AttributeError: pass # obj has been deleted, inst() returned None world._translucent_buildings.clear()