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

import gtk

class addmenu(gtk.Menu):
	"""Menu Ajouter"""
	def __init__(self, callback=None):
		gtk.Menu.__init__(self)
		self.items = {}
		
		self.append_item("./img/app.png", "Lanceur", "app", callback)
		self.append_item("./img/sep.png", "Séparateur", "sep", callback)
		self.append_item("./img/cat.png", "Catégorie", "cat", callback)
		self.append_item("./img/clock.png", "Horloge", "clock", callback)
		self.append_item("./img/subpage.png", "Sous-page", "subpage", callback)
		
		self.show_items(["cat"])
	
	def append_item(self, img, label, name, callback=None):
		self.items[name] = gtk.ImageMenuItem(gtk.STOCK_HELP)
		image = gtk.Image()
		image.set_from_file(img)
		self.items[name].set_image(image)
		self.items[name].get_children()[0].set_label(label)
		self.append(self.items[name])
		
		if callback is not None:
			self.items[name].connect("activate", callback, name)
	
	def display_menu(self, widget=None):
		self.popup(None, None, None, 3, 0)
		
	def show_items(self, items):
		for key in self.items.keys():
			if key in items:
				self.items[key].show()
			else:
				self.items[key].hide()
				
	def select_cat(self, type):
		if type in ["panel_part", "panel_icon", "panel_sep"]:
			self.show_items(["app", "sep", "cat", "clock"])
		elif type in ["app", "separator"]:
			self.show_items(["app", "sep", "cat"])
		elif type == "subpage":
			self.show_items(["cat", "subpage"])
		elif type == "cat":
			self.show_items(["app", "sep", "cat", "subpage"])
		elif type == "cat-apps":
			self.show_items(["app", "sep", "cat"])
		elif type == "cat-subpages":
			self.show_items(["cat", "subpage"])
		else:
			self.show_items(["cat"])
			
