Back to index

system-config-printer  1.3.9+20120706
Shrug.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 ## Printing troubleshooter
00004 
00005 ## Copyright (C) 2008, 2009, 2010, 2011 Red Hat, Inc.
00006 ## Author: Tim Waugh <twaugh@redhat.com>
00007 
00008 ## This program is free software; you can redistribute it and/or modify
00009 ## it under the terms of the GNU General Public License as published by
00010 ## the Free Software Foundation; either version 2 of the License, or
00011 ## (at your option) any later version.
00012 
00013 ## This program is distributed in the hope that it will be useful,
00014 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 ## GNU General Public License for more details.
00017 
00018 ## You should have received a copy of the GNU General Public License
00019 ## along with this program; if not, write to the Free Software
00020 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00021 
00022 from base import *
00023 class Shrug(Question):
00024     def __init__ (self, troubleshooter):
00025         Question.__init__ (self, troubleshooter, "Shrug")
00026         page = self.initial_vbox (_("Sorry!"),
00027                                   _("There is no obvious solution to this "
00028                                     "problem.  Your answers have been "
00029                                     "collected together with "
00030                                     "other useful information.  If you "
00031                                     "would like to report a bug, please "
00032                                     "include this information."))
00033 
00034         expander = gtk.Expander (_("Diagnostic Output (Advanced)"))
00035         expander.set_expanded (False)
00036         sw = gtk.ScrolledWindow ()
00037         expander.add (sw)
00038         textview = gtk.TextView ()
00039         textview.set_editable (False)
00040         sw.add (textview)
00041         page.pack_start (expander)
00042         self.buffer = textview.get_buffer ()
00043 
00044         box = gtk.HButtonBox ()
00045         box.set_border_width (0)
00046         box.set_spacing (3)
00047         box.set_layout (gtk.BUTTONBOX_END)
00048         page.pack_start (box, False, False, 0)
00049 
00050         self.save = gtk.Button (stock=gtk.STOCK_SAVE)
00051         box.pack_start (self.save, False, False, 0)
00052 
00053         troubleshooter.new_page (page, self)
00054 
00055     def display (self):
00056         self.buffer.set_text (self.troubleshooter.answers_as_text ())
00057         return True
00058 
00059     def connect_signals (self, handler):
00060         self.save_sigid = self.save.connect ('clicked', self.on_save_clicked)
00061 
00062     def disconnect_signals (self):
00063         self.save.disconnect (self.save_sigid)
00064 
00065     def on_save_clicked (self, button):
00066         while True:
00067             parent = self.troubleshooter.get_window()
00068             dialog = gtk.FileChooserDialog (parent=parent,
00069                                             action=gtk.FILE_CHOOSER_ACTION_SAVE,
00070                                             buttons=(gtk.STOCK_CANCEL,
00071                                                      gtk.RESPONSE_CANCEL,
00072                                                      gtk.STOCK_SAVE,
00073                                                      gtk.RESPONSE_OK))
00074             dialog.set_do_overwrite_confirmation (True)
00075             dialog.set_current_name ("troubleshoot.txt")
00076             dialog.set_default_response (gtk.RESPONSE_OK)
00077             dialog.set_local_only (True)
00078             response = dialog.run ()
00079             dialog.hide ()
00080             if response != gtk.RESPONSE_OK:
00081                 return
00082 
00083             try:
00084                 f = file (dialog.get_filename (), "w")
00085                 f.write (self.buffer.get_text (self.buffer.get_start_iter (),
00086                                                self.buffer.get_end_iter ()))
00087             except IOError, e:
00088                 err = gtk.MessageDialog (parent,
00089                                          gtk.DIALOG_MODAL |
00090                                          gtk.DIALOG_DESTROY_WITH_PARENT,
00091                                          gtk.MESSAGE_ERROR,
00092                                          gtk.BUTTONS_CLOSE,
00093                                          _("Error saving file"))
00094                 err.format_secondary_text (_("There was an error saving "
00095                                              "the file:") + "\n" +
00096                                            e.strerror)
00097                 err.run ()
00098                 err.destroy ()
00099                 continue
00100 
00101             del f
00102             break