Back to index

system-config-printer  1.3.9+20120706
Locale.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 ## Printing troubleshooter
00004 
00005 ## Copyright (C) 2008 Red Hat, Inc.
00006 ## Copyright (C) 2008 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 import locale
00023 
00024 from base import *
00025 
00026 class Locale(Question):
00027     def __init__ (self, troubleshooter):
00028         Question.__init__ (self, troubleshooter, "Locale issues")
00029         page = self.initial_vbox (_("Incorrect Page Size"),
00030                                   _("The page size for the print job was "
00031                                     "not the printer's default page size.  "
00032                                     "If this is not intentional it may cause "
00033                                     "alignment problems."))
00034 
00035         table = gtk.Table (2, 2)
00036         table.set_row_spacings (6)
00037         table.set_col_spacings (6)
00038         page.pack_start (table)
00039         self.printer_page_size = gtk.Label ()
00040         self.printer_page_size.set_alignment (0, 0)
00041         self.job_page_size = gtk.Label ()
00042         self.job_page_size.set_alignment (0, 0)
00043         label = gtk.Label (_("Print job page size:"))
00044         label.set_alignment (0, 0)
00045         table.attach (label, 0, 1, 0, 1, xoptions=gtk.FILL, yoptions=0)
00046         table.attach (self.job_page_size, 1, 2, 0, 1,
00047                       xoptions=gtk.FILL, yoptions=0)
00048         label = gtk.Label (_("Printer page size:"))
00049         label.set_alignment (0, 0)
00050         table.attach (label, 0, 1, 1, 2, xoptions=gtk.FILL, yoptions=0)
00051         table.attach (self.printer_page_size, 1, 2, 1, 2,
00052                       xoptions=gtk.FILL, yoptions=0)
00053         troubleshooter.new_page (page, self)
00054 
00055     def display (self):
00056         self.answers = {}
00057         (messages, encoding) = locale.getlocale (locale.LC_MESSAGES)
00058         (ctype, encoding) = locale.getlocale (locale.LC_CTYPE)
00059         self.answers['user_locale_messages'] = messages
00060         self.answers['user_locale_ctype'] = ctype
00061 
00062         try:
00063             i18n = file ("/etc/sysconfig/i18n").readlines ()
00064             for line in i18n:
00065                 if line.startswith ("LANG="):
00066                     system_lang = line[5:].strip ('\n"')
00067                     dot = system_lang.find ('.')
00068                     if dot != -1:
00069                         system_lang = system_lang[:dot]
00070         except:
00071             system_lang = None
00072 
00073         self.answers['system_locale_lang'] = system_lang
00074 
00075         printer_page_size = None
00076         try:
00077             ppd_defs = self.troubleshooter.answers['cups_printer_ppd_defaults']
00078             for group, options in ppd_defs.iteritems ():
00079                 if options.has_key ("PageSize"):
00080                     printer_page_size = options["PageSize"]
00081                     break
00082 
00083         except KeyError:
00084             try:
00085                 attrs = self.troubleshooter.answers['remote_cups_queue_attributes']
00086                 printer_page_size = attrs["media-default"]
00087             except KeyError:
00088                 pass
00089 
00090         try:
00091             job_status = self.troubleshooter.answers["test_page_job_status"]
00092         except KeyError:
00093             job_status = []
00094 
00095         self.answers['printer_page_size'] = printer_page_size
00096         if printer_page_size != None:
00097             job_page_size = None
00098             for (test, jobid, printer, doc, status, attrs) in job_status:
00099                 if test:
00100                     if attrs.has_key ("PageSize"):
00101                         job_page_size = attrs["PageSize"]
00102                         self.answers['job_page_size'] = job_page_size
00103                         if job_page_size != printer_page_size:
00104                             self.printer_page_size.set_text (printer_page_size)
00105                             self.job_page_size.set_text (job_page_size)
00106                             return True
00107 
00108         return False
00109 
00110     def collect_answer (self):
00111         return self.answers
00112