| 1 |
#!/usr/bin/python3 |
| 2 |
|
| 3 |
## Printing troubleshooter |
| 4 |
|
| 5 |
## Copyright (C) 2008, 2012 Red Hat, Inc. |
| 6 |
## Copyright (C) 2008, 2012 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 |
import locale |
| 23 |
|
| 24 |
from gi.repository import Gtk |
| 25 |
|
| 26 |
from .base import * |
| 27 |
|
| 28 |
class Locale(Question): |
| 29 |
def __init__ (self, troubleshooter): |
| 30 |
Question.__init__ (self, troubleshooter, "Locale issues") |
| 31 |
page = self.initial_vbox (_("Incorrect Page Size"), |
| 32 |
_("The page size for the print job was " |
| 33 |
"not the printer's default page size. " |
| 34 |
"If this is not intentional it may cause " |
| 35 |
"alignment problems.")) |
| 36 |
grid = Gtk.Grid() |
| 37 |
grid.set_row_spacing (6) |
| 38 |
grid.set_column_spacing (6) |
| 39 |
page.pack_start (grid, False, False, 0) |
| 40 |
self.printer_page_size = Gtk.Label () |
| 41 |
self.printer_page_size.set_alignment (0, 0) |
| 42 |
self.job_page_size = Gtk.Label () |
| 43 |
self.job_page_size.set_alignment (0, 0) |
| 44 |
label = Gtk.Label(label=_("Print job page size:")) |
| 45 |
label.set_alignment (0, 0) |
| 46 |
grid.attach (label, 0, 0, 1, 1) |
| 47 |
grid.attach (self.job_page_size, 1, 0, 1, 1) |
| 48 |
label = Gtk.Label(label=_("Printer page size:")) |
| 49 |
label.set_alignment (0, 0) |
| 50 |
grid.attach (label, 0, 1, 1, 1) |
| 51 |
grid.attach (self.printer_page_size, 1, 1, 1, 1) |
| 52 |
troubleshooter.new_page (page, self) |
| 53 |
|
| 54 |
def display (self): |
| 55 |
self.answers = {} |
| 56 |
(messages, encoding) = locale.getlocale (locale.LC_MESSAGES) |
| 57 |
(ctype, encoding) = locale.getlocale (locale.LC_CTYPE) |
| 58 |
self.answers['user_locale_messages'] = messages |
| 59 |
self.answers['user_locale_ctype'] = ctype |
| 60 |
|
| 61 |
try: |
| 62 |
system_lang = None |
| 63 |
conf = None |
| 64 |
for conffile in ["/etc/locale.conf", "/etc/sysconfig/i18n"]: |
| 65 |
try: |
| 66 |
conf = open (conffile).readlines () |
| 67 |
except IOError: |
| 68 |
continue |
| 69 |
|
| 70 |
if conf is not None: |
| 71 |
for line in conf: |
| 72 |
if line.startswith("LC_PAPER="): |
| 73 |
system_lang = line[9:].strip ('\n"') |
| 74 |
elif system_lang is None and line.startswith ("LANG="): |
| 75 |
system_lang = line[5:].strip ('\n"') |
| 76 |
|
| 77 |
if system_lang is not None: |
| 78 |
dot = system_lang.find ('.') |
| 79 |
if dot != -1: |
| 80 |
system_lang = system_lang[:dot] |
| 81 |
except: |
| 82 |
system_lang = None |
| 83 |
|
| 84 |
self.answers['system_locale_lang'] = system_lang |
| 85 |
|
| 86 |
printer_page_size = None |
| 87 |
try: |
| 88 |
ppd_defs = self.troubleshooter.answers['cups_printer_ppd_defaults'] |
| 89 |
for group, options in ppd_defs.items (): |
| 90 |
if "PageSize" in options: |
| 91 |
printer_page_size = options["PageSize"] |
| 92 |
break |
| 93 |
|
| 94 |
except KeyError: |
| 95 |
try: |
| 96 |
attrs = self.troubleshooter.answers['remote_cups_queue_attributes'] |
| 97 |
printer_page_size = attrs["media-default"] |
| 98 |
except KeyError: |
| 99 |
pass |
| 100 |
|
| 101 |
try: |
| 102 |
job_status = self.troubleshooter.answers["test_page_job_status"] |
| 103 |
except KeyError: |
| 104 |
job_status = [] |
| 105 |
|
| 106 |
self.answers['printer_page_size'] = printer_page_size |
| 107 |
if printer_page_size is not None: |
| 108 |
job_page_size = None |
| 109 |
for (test, jobid, printer, doc, status, attrs) in job_status: |
| 110 |
if test: |
| 111 |
if "PageSize" in attrs: |
| 112 |
job_page_size = attrs["PageSize"] |
| 113 |
self.answers['job_page_size'] = job_page_size |
| 114 |
if job_page_size != printer_page_size: |
| 115 |
self.printer_page_size.set_text (printer_page_size) |
| 116 |
self.job_page_size.set_text (job_page_size) |
| 117 |
return True |
| 118 |
|
| 119 |
return False |
| 120 |
|
| 121 |
def collect_answer (self): |
| 122 |
return self.answers |
| 123 |
|