Debian Codegraph @

troubleshoot/Shrug.py

raw
1 #!/usr/bin/python3
2
3 ## Printing troubleshooter
4
5 ## Copyright (C) 2008, 2009, 2010, 2011, 2012 Red Hat, Inc.
6 ## Author: Tim Waugh <[email protected]>
7
8 ## This program is free software; you can redistribute it and/or modify
9 ## it under the terms of the GNU General Public License as published by
10 ## the Free Software Foundation; either version 2 of the License, or
11 ## (at your option) any later version.
12
13 ## This program is distributed in the hope that it will be useful,
14 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ## GNU General Public License for more details.
17
18 ## You should have received a copy of the GNU General Public License
19 ## along with this program; if not, write to the Free Software
20 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
22 from gi.repository import Gtk
23
24 from .base import *
25 class Shrug(Question):
26 def __init__ (self, troubleshooter):
27 Question.__init__ (self, troubleshooter, "Shrug")
28 page = self.initial_vbox (_("Sorry!"),
29 _("There is no obvious solution to this "
30 "problem. Your answers have been "
31 "collected together with "
32 "other useful information. If you "
33 "would like to report a bug, please "
34 "include this information."))
35
36 expander = Gtk.Expander.new(_("Diagnostic Output (Advanced)"))
37 expander.set_expanded (False)
38 sw = Gtk.ScrolledWindow ()
39 expander.add (sw)
40 textview = Gtk.TextView ()
41 textview.set_editable (False)
42 sw.add (textview)
43 page.pack_start (expander, True, True, 0)
44 self.buffer = textview.get_buffer ()
45
46 box = Gtk.HButtonBox ()
47 box.set_border_width (0)
48 box.set_spacing (3)
49 box.set_layout (Gtk.ButtonBoxStyle.END)
50 page.pack_start (box, False, False, 0)
51
52 self.save = Gtk.Button.new_from_stock (Gtk.STOCK_SAVE)
53 box.pack_start (self.save, False, False, 0)
54
55 troubleshooter.new_page (page, self)
56
57 def display (self):
58 self.buffer.set_text (self.troubleshooter.answers_as_text ())
59 return True
60
61 def connect_signals (self, handler):
62 self.save_sigid = self.save.connect ('clicked', self.on_save_clicked)
63
64 def disconnect_signals (self):
65 self.save.disconnect (self.save_sigid)
66
67 def on_save_clicked (self, button):
68 while True:
69 parent = self.troubleshooter.get_window()
70 dialog = Gtk.FileChooserDialog (transient_for=parent,
71 action=Gtk.FileChooserAction.SAVE)
72 dialog.add_buttons (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
73 Gtk.STOCK_SAVE, Gtk.ResponseType.OK)
74 dialog.set_do_overwrite_confirmation (True)
75 dialog.set_current_name ("troubleshoot.txt")
76 dialog.set_default_response (Gtk.ResponseType.OK)
77 dialog.set_local_only (True)
78 response = dialog.run ()
79 dialog.hide ()
80 if response != Gtk.ResponseType.OK:
81 return
82
83 try:
84 f = open (dialog.get_filename (), "w")
85 f.write (self.buffer.get_text (start=self.buffer.get_start_iter (),
86 end=self.buffer.get_end_iter (),
87 include_hidden_chars=False))
88 except IOError as e:
89 err = Gtk.MessageDialog (parent=parent,
90 modal=True, destroy_with_parent=True,
91 message_type=Gtk.MessageType.ERROR,
92 buttons=Gtk.ButtonsType.CLOSE,
93 text=_("Error saving file"))
94 err.format_secondary_text (_("There was an error saving "
95 "the file:") + "\n" +
96 e.strerror)
97 err.run ()
98 err.destroy ()
99 continue
100
101 del f
102 break