2 # -*- coding: utf-8 -*-
4 # (c) Copyright 2003-2008 Hewlett-Packard Development Company, L.P.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 __title__ = 'Testpage Print Utility'
25 __mod__ = 'hp-testpage'
26 __doc__ = "Print a tespage to a printer. Prints a summary of device information and shows the printer's margins."
37 from base import device, utils, tui, module
43 mod = module.Module(__mod__, __title__, __version__, __doc__, None,
44 (INTERACTIVE_MODE, GUI_MODE),
47 mod.setUsage(module.USAGE_FLAG_DEVICE_ARGS)
49 opts, device_uri, printer_name, mode, ui_toolkit, loc = \
52 printer_name, device_uri = mod.getPrinterName(printer_name, device_uri)
53 wait_for_printout = False
56 if not utils.canEnterGUIMode4():
57 log.error("%s -u/--gui requires Qt4 GUI support. Entering interactive mode." % __mod__)
58 mode = INTERACTIVE_MODE
62 from PyQt4.QtGui import QApplication
63 from ui4.printtestpagedialog import PrintTestPageDialog
65 log.error("Unable to load Qt4 support. Is it installed?")
68 log.set_module("%s(UI)" % __mod__)
71 app = QApplication(sys.argv)
73 dialog = PrintTestPageDialog(None, printer_name)
76 log.debug("Starting GUI loop...")
78 except KeyboardInterrupt:
83 if mode == INTERACTIVE_MODE:
84 #else: # INTERACTIVE_MODE
86 d = device.Device(device_uri, printer_name)
88 log.error("Device error (%s)." % e.msg)
95 log.error("Unable to print to printer. Please check device and try again.")
98 # TODO: Fix the wait for printout stuff... can't get device ID
99 # while hp: backend has device open in printing mode...
100 wait_for_printout = False
102 if d.isIdleAndNoError():
104 log.info( "Printing test page to printer %s..." % printer_name)
106 d.printTestPage(printer_name)
108 if e.opt == ERROR_NO_CUPS_QUEUE_FOUND_FOR_DEVICE:
109 log.error("No CUPS queue found for device. Please install the printer in CUPS and try again.")
111 log.error("An error occured (code=%d)." % e.opt)
113 if wait_for_printout:
114 log.info("Test page has been sent to printer. Waiting for printout to complete...")
123 d.queryDevice(quick=True)
125 log.error("An error has occured.")
127 if d.error_state == ERROR_STATE_CLEAR:
130 elif d.error_state == ERROR_STATE_ERROR:
132 log.error("An error has occured (code=%d). Please check the printer and try again." % d.status_code)
135 elif d.error_state == ERROR_STATE_WARNING:
137 log.warning("There is a problem with the printer (code=%d). Please check the printer." % d.status_code)
139 else: # ERROR_STATE_BUSY
150 log.info("Test page has been sent to printer.")
153 log.error("Device is busy or in an error state. Please check device and try again.")
161 log.notice("If an error occured, or the test page failed to print, refer to the HPLIP website")
162 log.notice("at: http://hplip.sourceforge.net for troubleshooting and support.")
165 except KeyboardInterrupt:
166 log.error("User exit")