Back to index

system-config-printer  1.3.9+20120706
base.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 ## Printing troubleshooter
00004 
00005 ## Copyright (C) 2008, 2010 Red Hat, Inc.
00006 ## Authors:
00007 ##  Tim Waugh <twaugh@redhat.com>
00008 
00009 ## This program is free software; you can redistribute it and/or modify
00010 ## it under the terms of the GNU General Public License as published by
00011 ## the Free Software Foundation; either version 2 of the License, or
00012 ## (at your option) any later version.
00013 
00014 ## This program is distributed in the hope that it will be useful,
00015 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 ## GNU General Public License for more details.
00018 
00019 ## You should have received a copy of the GNU General Public License
00020 ## along with this program; if not, write to the Free Software
00021 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00022 
00023 import gtk
00024 from gettext import gettext as _
00025 N_ = lambda x: x
00026 from debug import *
00027 
00028 __all__ = [ 'gtk',
00029             '_',
00030             'debugprint', 'get_debugging', 'set_debugging',
00031             'Question',
00032             'Multichoice',
00033             'TEXT_start_print_admin_tool' ]
00034 
00035 TEXT_start_print_admin_tool = N_("To start this tool, select "
00036                                  "System->Administration->Printing "
00037                                  "from the main menu.")
00038 
00039 class Question:
00040     def __init__ (self, troubleshooter, name=None):
00041         self.troubleshooter = troubleshooter
00042         if name:
00043             self.__str__ = lambda: name
00044 
00045     def display (self):
00046         """Returns True if this page should be displayed, or False
00047         if it should be skipped."""
00048         return True
00049 
00050     def connect_signals (self, handler):
00051         pass
00052 
00053     def disconnect_signals (self):
00054         pass
00055 
00056     def can_click_forward (self):
00057         return True
00058 
00059     def collect_answer (self):
00060         return {}
00061 
00062     def cancel_operation (self):
00063         pass
00064 
00065     ## Helper functions
00066     def initial_vbox (self, title='', text=''):
00067         vbox = gtk.VBox ()
00068         vbox.set_border_width (12)
00069         vbox.set_spacing (12)
00070         if title:
00071             s = '<span weight="bold" size="larger">' + title + '</span>\n\n'
00072         else:
00073             s = ''
00074         s += text
00075         label = gtk.Label (s)
00076         label.set_alignment (0, 0)
00077         label.set_line_wrap (True)
00078         label.set_use_markup (True)
00079         vbox.pack_start (label, False, False, 0)
00080         return vbox
00081 
00082 class Multichoice(Question):
00083     def __init__ (self, troubleshooter, question_tag, question_title,
00084                   question_text, choices, name=None):
00085         Question.__init__ (self, troubleshooter, name)
00086         page = self.initial_vbox (question_title, question_text)
00087         choice_vbox = gtk.VBox ()
00088         choice_vbox.set_spacing (6)
00089         page.pack_start (choice_vbox, False, False, 0)
00090         self.question_tag = question_tag
00091         self.widgets = []
00092         for choice, tag in choices:
00093             button = gtk.RadioButton (label=choice)
00094             if len (self.widgets) > 0:
00095                 button.set_group (self.widgets[0][0])
00096             choice_vbox.pack_start (button, False, False, 0)
00097             self.widgets.append ((button, tag))
00098 
00099         troubleshooter.new_page (page, self)
00100 
00101     def collect_answer (self):
00102         for button, answer_tag in self.widgets:
00103             if button.get_active ():
00104                 return { self.question_tag: answer_tag }