Debian Codegraph @

troubleshoot/base.py

raw
1 #!/usr/bin/python3
2
3 ## Printing troubleshooter
4
5 ## Copyright (C) 2008, 2010, 2012 Red Hat, Inc.
6 ## Authors:
7 ## Tim Waugh <[email protected]>
8
9 ## This program is free software; you can redistribute it and/or modify
10 ## it under the terms of the GNU General Public License as published by
11 ## the Free Software Foundation; either version 2 of the License, or
12 ## (at your option) any later version.
13
14 ## This program is distributed in the hope that it will be useful,
15 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ## GNU General Public License for more details.
18
19 ## You should have received a copy of the GNU General Public License
20 ## along with this program; if not, write to the Free Software
21 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
23 from gi.repository import Gtk
24 N_ = lambda x: x
25 from debug import *
26
27 import config
28 import gettext
29 gettext.install(domain=config.PACKAGE, localedir=config.localedir)
30
31 __all__ = [ 'debugprint', 'get_debugging', 'set_debugging',
32 'Question',
33 'Multichoice',
34 'TEXT_start_print_admin_tool' ]
35
36 TEXT_start_print_admin_tool = N_("To start this tool, select "
37 "System->Administration->Print Settings "
38 "from the main menu.")
39
40 class Question:
41 def __init__ (self, troubleshooter, name=None):
42 self.troubleshooter = troubleshooter
43 if name:
44 self.__str__ = lambda: name
45
46 def display (self):
47 """Returns True if this page should be displayed, or False
48 if it should be skipped."""
49 return True
50
51 def connect_signals (self, handler):
52 pass
53
54 def disconnect_signals (self):
55 pass
56
57 def can_click_forward (self):
58 return True
59
60 def collect_answer (self):
61 return {}
62
63 def cancel_operation (self):
64 pass
65
66 ## Helper functions
67 def initial_vbox (self, title='', text=''):
68 vbox = Gtk.VBox ()
69 vbox.set_border_width (12)
70 vbox.set_spacing (12)
71 if title:
72 s = '<span weight="bold" size="larger">' + title + '</span>\n\n'
73 else:
74 s = ''
75 s += text
76 label = Gtk.Label(label=s)
77 label.set_alignment (0, 0)
78 label.set_line_wrap (True)
79 label.set_use_markup (True)
80 vbox.pack_start (label, False, False, 0)
81 return vbox
82
83 class Multichoice(Question):
84 def __init__ (self, troubleshooter, question_tag, question_title,
85 question_text, choices, name=None):
86 Question.__init__ (self, troubleshooter, name)
87 page = self.initial_vbox (question_title, question_text)
88 choice_vbox = Gtk.VBox ()
89 choice_vbox.set_spacing (6)
90 page.pack_start (choice_vbox, False, False, 0)
91 self.question_tag = question_tag
92 self.widgets = []
93 button = None
94 for choice, tag in choices:
95 if button:
96 button = Gtk.RadioButton.new_with_label_from_widget(button, choice)
97 else:
98 # special case to work around GNOME#635253
99 button = Gtk.RadioButton.new_with_label([], choice)
100 choice_vbox.pack_start (button, False, False, 0)
101 self.widgets.append ((button, tag))
102
103 troubleshooter.new_page (page, self)
104
105 def collect_answer (self):
106 for button, answer_tag in self.widgets:
107 if button.get_active ():
108 return { self.question_tag: answer_tag }