#!/usr/bin/python
# -*- coding: utf-8 -*-

import gtk, os

class themelist(gtk.ComboBox):
	"""Liste des thèmes disponibles"""
	def __init__(self, config):
		self.config = config
		self.store = themestore(config)
		
		gtk.ComboBox.__init__(self, self.store)
		
		cell = gtk.CellRendererText()
		self.pack_start(cell, True)
		self.add_attribute(cell, 'text', 0)
		
	def get_theme(self):
		return self.store.get_value(self.get_active_iter(), 0)
		
	def update(self, theme):
		self.set_active_iter(self.store.update(theme))
		
class themestore(gtk.ListStore):
	def __init__(self, config):
		self.config = config
		gtk.ListStore.__init__(self, str)
		
	def update(self, theme):
		self.clear()
		themeiter = None
		
		for dir in os.listdir(self.config.get("FramaKioskTune", "FramaKioskPath") + "/Data/FramaKiosk/theme/"):
			if os.path.isdir(self.config.get("FramaKioskTune", "FramaKioskPath") + "/Data/FramaKiosk/theme/" + dir):
				iter = self.append([dir])
				
				if dir == theme:
					themeiter = iter
		
		if themeiter is None:
			themeiter = self.get_iter_first()
		
		return themeiter
