# Bryan Schumaker (12/12/2010)

import libsaria
from libsaria import callbacks
import queue

visible = set()

def rm_ids(ids):
	global visible
	visible = visible - set(ids)
	queue.rm_ids(ids)

def reset():
	global visible
	visible = set()
	queue.reset()

def list_ids():
	for id in queue.queue_list:
		yield id

def add_ids(id_list):
	queue.add_ids(id_list)
	for id in id_list:
		if libsaria.sources.is_visible(id):
			visible.add(id)
	callbacks.queue_changed()

def set_visible(vset):
	global visible
	visible = queue.as_set().intersection(vset)

def num_visible():
	return len(visible)

def next():
	id = queue.pop()
	if id != None:
		visible.remove(id)
	return id

