2007-03-22 19:59:10 -05:00
|
|
|
# Error dialog with extensible "details" button.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2007-11-20 10:12:20 -06:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
# MA 02110-1301 USA.
|
2007-03-22 19:59:10 -05:00
|
|
|
|
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
|
|
|
|
2008-09-06 12:24:47 -05:00
|
|
|
import logging
|
|
|
|
|
2010-01-19 13:09:43 -06:00
|
|
|
import virtManager.util as util
|
|
|
|
|
2010-01-14 09:09:52 -06:00
|
|
|
def safe_set_text(self, text):
|
2010-01-19 13:09:43 -06:00
|
|
|
# pygtk < 2.10 doesn't support test property
|
|
|
|
if not util.safe_set_prop(self, "text", text):
|
2010-01-14 09:09:52 -06:00
|
|
|
self.set_markup(text)
|
|
|
|
|
2010-01-19 13:09:43 -06:00
|
|
|
|
2007-03-22 19:59:10 -05:00
|
|
|
class vmmErrorDialog (gtk.MessageDialog):
|
2008-11-18 14:42:51 -06:00
|
|
|
def __init__ (self, parent=None, flags=0, typ=gtk.MESSAGE_INFO,
|
2007-03-22 19:59:10 -05:00
|
|
|
buttons=gtk.BUTTONS_NONE, message_format=None,
|
2008-03-14 12:18:44 -05:00
|
|
|
message_details=None, default_title=_("Error")):
|
2007-03-22 19:59:10 -05:00
|
|
|
gtk.MessageDialog.__init__ (self,
|
2008-11-18 14:42:51 -06:00
|
|
|
parent, flags, typ, buttons,
|
2007-03-22 19:59:10 -05:00
|
|
|
message_format)
|
2009-01-21 15:28:54 -06:00
|
|
|
|
|
|
|
self.val_err_box = None
|
|
|
|
|
2008-03-14 12:18:44 -05:00
|
|
|
self.message_format = message_format
|
|
|
|
self.message_details = message_details
|
|
|
|
self.buffer = None
|
|
|
|
self.default_title = default_title
|
|
|
|
self.set_title(self.default_title)
|
2009-01-21 15:28:54 -06:00
|
|
|
self.connect("response", self.response_cb)
|
|
|
|
self.connect("delete-event", self.hide_on_delete)
|
2007-03-22 19:59:10 -05:00
|
|
|
|
|
|
|
if not message_details is None:
|
|
|
|
# Expander section with details.
|
|
|
|
expander = gtk.Expander (_("Details"))
|
2008-03-14 12:18:44 -05:00
|
|
|
self.buffer = gtk.TextBuffer ()
|
|
|
|
self.buffer.set_text (self.message_details)
|
2007-03-22 19:59:10 -05:00
|
|
|
sw = gtk.ScrolledWindow ()
|
|
|
|
sw.set_shadow_type (gtk.SHADOW_IN)
|
2007-04-10 18:07:40 -05:00
|
|
|
sw.set_size_request (400, 240)
|
2007-03-22 19:59:10 -05:00
|
|
|
sw.set_policy (gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
2008-03-14 12:18:44 -05:00
|
|
|
details = gtk.TextView (self.buffer)
|
2007-03-22 19:59:10 -05:00
|
|
|
details.set_editable (False)
|
|
|
|
details.set_overwrite (False)
|
|
|
|
details.set_cursor_visible (False)
|
|
|
|
details.set_wrap_mode (gtk.WRAP_WORD)
|
|
|
|
sw.add (details)
|
|
|
|
details.show ()
|
|
|
|
expander.add (sw)
|
|
|
|
sw.show ()
|
2008-11-19 09:21:22 -06:00
|
|
|
self.vbox.pack_start (expander)
|
2007-03-22 19:59:10 -05:00
|
|
|
expander.show ()
|
2008-03-14 12:18:44 -05:00
|
|
|
|
2009-11-20 12:11:33 -06:00
|
|
|
def set_parent(self, parent):
|
|
|
|
self.set_transient_for(parent)
|
|
|
|
|
2009-01-21 15:28:54 -06:00
|
|
|
def response_cb(self, src, ignore):
|
|
|
|
src.hide()
|
|
|
|
|
2009-01-24 13:29:41 -06:00
|
|
|
def show_err(self, summary, details, title=None, async=True):
|
2009-01-21 15:28:54 -06:00
|
|
|
self.hide()
|
|
|
|
|
2008-03-14 12:18:44 -05:00
|
|
|
if title is None:
|
|
|
|
title = self.default_title
|
|
|
|
self.set_title(title)
|
2010-01-14 09:09:52 -06:00
|
|
|
safe_set_text(self, summary)
|
2008-03-14 12:18:44 -05:00
|
|
|
self.buffer.set_text(details)
|
2008-09-06 12:24:47 -05:00
|
|
|
logging.debug("Uncaught Error: %s : %s" % (summary, details))
|
2009-01-21 15:28:54 -06:00
|
|
|
|
2009-01-24 13:29:41 -06:00
|
|
|
if async:
|
|
|
|
self.show()
|
|
|
|
else:
|
|
|
|
self.run()
|
2008-03-14 12:18:44 -05:00
|
|
|
|
2010-02-22 08:04:48 -06:00
|
|
|
def _show_ok(self, dialog_type, text1, text2, title, async=True):
|
2009-01-21 15:28:54 -06:00
|
|
|
def response_destroy(src, ignore):
|
|
|
|
src.destroy()
|
|
|
|
|
|
|
|
if self.val_err_box:
|
|
|
|
self.val_err_box.destroy()
|
|
|
|
|
2009-11-20 12:11:33 -06:00
|
|
|
self.val_err_box = gtk.MessageDialog(self.get_transient_for(),
|
2009-01-21 15:28:54 -06:00
|
|
|
gtk.DIALOG_DESTROY_WITH_PARENT,
|
2009-07-02 11:45:48 -05:00
|
|
|
dialog_type,
|
2009-01-21 15:28:54 -06:00
|
|
|
gtk.BUTTONS_OK, text1)
|
|
|
|
|
|
|
|
self.val_err_box.set_title(title)
|
2008-03-14 12:18:44 -05:00
|
|
|
if text2 is not None:
|
2009-01-21 15:28:54 -06:00
|
|
|
self.val_err_box.format_secondary_text(text2)
|
|
|
|
|
|
|
|
self.val_err_box.connect("response", response_destroy)
|
2010-02-22 08:04:48 -06:00
|
|
|
if async:
|
|
|
|
self.val_err_box.show()
|
|
|
|
else:
|
|
|
|
self.val_err_box.run()
|
|
|
|
|
2008-03-14 12:18:44 -05:00
|
|
|
return False
|
|
|
|
|
2010-02-22 08:04:48 -06:00
|
|
|
def val_err(self, text1, text2=None, title=None, async=True):
|
2009-07-02 11:45:48 -05:00
|
|
|
logging.debug("Validation Error: %s" % text1)
|
|
|
|
if title is None:
|
|
|
|
title = _("Input Error")
|
2010-02-22 08:04:48 -06:00
|
|
|
return self._show_ok(gtk.MESSAGE_ERROR, text1, text2, title, async)
|
2009-07-02 11:45:48 -05:00
|
|
|
|
2010-02-22 08:04:48 -06:00
|
|
|
def show_info(self, text1, text2=None, title=None, async=True):
|
2009-07-02 11:45:48 -05:00
|
|
|
if title is None:
|
|
|
|
title = ""
|
2010-02-22 08:04:48 -06:00
|
|
|
return self._show_ok(gtk.MESSAGE_INFO, text1, text2, title, async)
|
2009-02-15 20:20:14 -06:00
|
|
|
|
|
|
|
def _show_warning(self, buttons, text1, text2):
|
2009-11-20 12:11:33 -06:00
|
|
|
message_box = gtk.MessageDialog(self.get_transient_for(),
|
2009-07-02 11:45:48 -05:00
|
|
|
gtk.DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
gtk.MESSAGE_WARNING,
|
2009-02-15 20:20:14 -06:00
|
|
|
buttons, text1)
|
2008-03-14 12:18:44 -05:00
|
|
|
if text2 != None:
|
|
|
|
message_box.format_secondary_text(text2)
|
2009-02-15 20:20:14 -06:00
|
|
|
if message_box.run() in [ gtk.RESPONSE_YES, gtk.RESPONSE_OK ]:
|
2008-03-14 12:18:44 -05:00
|
|
|
res = True
|
|
|
|
else:
|
|
|
|
res = False
|
|
|
|
message_box.destroy()
|
|
|
|
return res
|
|
|
|
|
2009-02-15 20:20:14 -06:00
|
|
|
def yes_no(self, text1, text2=None):
|
|
|
|
return self._show_warning(gtk.BUTTONS_YES_NO, text1, text2)
|
|
|
|
|
|
|
|
def ok_cancel(self, text1, text2=None):
|
|
|
|
return self._show_warning(gtk.BUTTONS_OK_CANCEL, text1, text2)
|
|
|
|
|
2009-11-18 15:11:17 -06:00
|
|
|
def warn_chkbox(self, text1, text2=None, chktext=None, buttons=None):
|
2009-11-20 12:11:33 -06:00
|
|
|
chkbox = vmmCheckDialog(self.get_transient_for(),
|
|
|
|
gtk.MESSAGE_WARNING, buttons)
|
2009-09-23 15:42:56 -05:00
|
|
|
return chkbox.show_chkbox(text1, text2, chktext)
|
|
|
|
|
2009-11-18 15:11:17 -06:00
|
|
|
def err_chkbox(self, text1, text2=None, chktext=None, buttons=None):
|
2009-11-20 12:11:33 -06:00
|
|
|
chkbox = vmmCheckDialog(self.get_transient_for(),
|
|
|
|
gtk.MESSAGE_ERROR, buttons)
|
2009-09-23 15:42:56 -05:00
|
|
|
return chkbox.show_chkbox(text1, text2, chktext)
|
|
|
|
|
|
|
|
class vmmCheckDialog (gtk.MessageDialog):
|
2009-11-18 15:11:17 -06:00
|
|
|
def __init__ (self, parent=None, typ=gtk.MESSAGE_INFO,
|
|
|
|
buttons=None):
|
|
|
|
if not buttons:
|
|
|
|
if typ == gtk.MESSAGE_WARNING:
|
|
|
|
buttons = gtk.BUTTONS_OK_CANCEL
|
|
|
|
else:
|
|
|
|
buttons = gtk.BUTTONS_OK
|
2009-09-23 15:42:56 -05:00
|
|
|
|
|
|
|
gtk.MessageDialog.__init__ (self, parent, 0, typ, buttons)
|
|
|
|
|
|
|
|
self.connect("response", self.response_cb)
|
|
|
|
self.connect("delete-event", self.hide_on_delete)
|
|
|
|
self.set_title("")
|
|
|
|
|
|
|
|
self.chk_vbox = gtk.VBox(False, False)
|
|
|
|
self.chk_vbox.set_spacing(0)
|
|
|
|
|
|
|
|
self.chk_align = gtk.Alignment()
|
|
|
|
self.chk_align.set_padding(0, 0, 62, 0)
|
|
|
|
self.chk_align.add(self.chk_vbox)
|
|
|
|
|
|
|
|
self.chk_align.show_all()
|
|
|
|
self.vbox.pack_start(self.chk_align)
|
|
|
|
|
|
|
|
def response_cb(self, src, ignore):
|
|
|
|
src.hide()
|
|
|
|
|
|
|
|
def show_chkbox(self, text1, text2=None, chktext=None):
|
|
|
|
chkbox = None
|
|
|
|
res = None
|
|
|
|
|
|
|
|
self.hide()
|
|
|
|
for c in self.chk_vbox.get_children():
|
|
|
|
self.chk_vbox.remove(c)
|
|
|
|
|
2010-01-14 09:09:52 -06:00
|
|
|
safe_set_text(self, text1)
|
2009-09-23 15:42:56 -05:00
|
|
|
|
|
|
|
if text2:
|
|
|
|
self.format_secondary_text(text2)
|
|
|
|
|
|
|
|
if chktext:
|
|
|
|
chkbox = gtk.CheckButton(chktext)
|
|
|
|
self.chk_vbox.add(chkbox)
|
|
|
|
chkbox.show()
|
|
|
|
|
|
|
|
res = self.run() in [ gtk.RESPONSE_YES, gtk.RESPONSE_OK ]
|
|
|
|
if chktext:
|
|
|
|
res = [res, chkbox.get_active()]
|
|
|
|
|
|
|
|
return res
|