def __init__(self, title, header='', can_cancel=False, cancel_callback=None, message_area=False, parent=None): """ Specify the title and the current pass header. """ from gi.repository import Gtk self.__mode = ProgressMeter.MODE_FRACTION self.__pbar_max = 100.0 self.__pbar_index = 0.0 self.__old_val = -1 self.__can_cancel = can_cancel self.__cancelled = False if cancel_callback: self.__cancel_callback = cancel_callback else: self.__cancel_callback = self.handle_cancel if has_display(): self.__dialog = Gtk.Dialog() else: self.__dialog = CLIDialog() if self.__can_cancel: self.__dialog.connect('delete_event', self.__cancel_callback) else: self.__dialog.connect('delete_event', self.__warn) self.__dialog.set_title(title) self.__dialog.set_border_width(12) self.__dialog.vbox.set_spacing(10) self.__dialog.vbox.set_border_width(24) self.__dialog.set_size_request(400, 125) if not parent: # if we don't have an explicit parent, try to find one for win in Gtk.Window.list_toplevels(): if win.is_active(): parent = win break # if we still don't have a parent, give up if parent: self.__dialog.set_transient_for(parent) self.__dialog.set_modal(True) tlbl = Gtk.Label(label='<span size="larger" weight="bold">%s</span>' % title) tlbl.set_use_markup(True) self.__dialog.vbox.add(tlbl) self.__lbl = Gtk.Label(label=header) self.__lbl.set_use_markup(True) self.__dialog.vbox.add(self.__lbl) self.__pbar = Gtk.ProgressBar() self.__dialog.vbox.add(self.__pbar) if self.__can_cancel: self.__dialog.set_size_request(350, 170) self.__cancel_button = Gtk.Button.new_with_mnemonic(_('_Cancel')) self.__cancel_button.connect('clicked', self.__cancel_callback) self.__dialog.vbox.add(self.__cancel_button) self.message_area = None if message_area: area = Gtk.ScrolledWindow() text = Gtk.TextView() text.set_border_width(6) text.set_editable(False) self.message_area = text area.add(text) area.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.__dialog.vbox.add(area) self.message_area_ok = Gtk.Button.new_with_mnemonic(_('_OK')) self.message_area_ok.connect("clicked", self.close) self.message_area_ok.set_sensitive(False) self.__dialog.vbox.pack_start(self.message_area_ok, expand=False, fill=False) self.__dialog.set_size_request(500, 350) self.__dialog.show_all() if header == '': self.__lbl.hide()