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

import gtk, gobject
from lib import wrap_label

class progress_dialog(gtk.Dialog):
	def __init__(self, parent=None, title="Mise à jour des dépôts", comment="Téléchargement des bases de données d'applications"):
		self.pulse = False
		
		gtk.Dialog.__init__(self, title, parent, gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT|gtk.DIALOG_NO_SEPARATOR, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
		self.set_icon_list(gtk.gdk.pixbuf_new_from_file("icons/SynApps16.png"), gtk.gdk.pixbuf_new_from_file("icons/SynApps24.png"), gtk.gdk.pixbuf_new_from_file("icons/SynApps32.png"), gtk.gdk.pixbuf_new_from_file("icons/SynApps64.png"), gtk.gdk.pixbuf_new_from_file("icons/SynApps128.png"))
		self.set_border_width(5)
		self.connect("response", self.destroy)
		
		if title != "":
			label = gtk.Label()
			label.set_use_markup(True)
			label.set_markup("<b>" + title + "</b>")

			self.get_content_area().pack_start(label, False, False)
		
		if comment != "":
			label = gtk.Label(comment)
			self.get_content_area().pack_start(label, False, False)
		
		self.progress = gtk.ProgressBar()
		self.progress.set_text("Mise à jour en cours...")
		self.progress.set_pulse_step(0.05)
		self.get_content_area().pack_start(self.progress, False, False)
		
		self.button = self.get_action_area().get_children()[0]
	
	def timeout(self):
		self.progress.pulse()
		
		while gtk.events_pending():
			gtk.main_iteration()

		return self.pulse
	
	def run(self):
		self.show_all()
		self.pulse = True
		self.pulseid = gobject.timeout_add(50, self.timeout)
		
	def destroy(self, widget=None, tmp=None):
		self.pulse = False
		gtk.Dialog.destroy(self)
