2 # -*- coding: utf-8 -*-
4 # (c) Copyright 2003-2009 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
20 # Author: Don Welch, Naga Samrat Chowdary Narla,
24 __title__ = 'Printer Cartridge Alignment Utility'
26 __doc__ = "Cartridge alignment utility for HPLIP supported inkjet printers. (Note: Not all printers require the use of this utility)."
37 from base import device, status, utils, maint, tui, module
41 def enterAlignmentNumber(letter, hortvert, colors, line_count, maximum):
42 ok, value = tui.enter_range("From the printed Alignment page, Enter the best aligned value for line %s (1-%d): " %
52 def enterPaperEdge(maximum):
53 ok, value = tui.enter_range("Enter numbered arrow that is best aligned with the paper edge (1-%d): "
63 def colorAdj(line, maximum):
64 ok, value = tui.enter_range("Enter the numbered box on line %s that is best color matched to the background color (1-%d): " %
74 def bothPensRequired():
75 log.error("Cannot perform alignment with 0 or 1 cartridges installed.\nPlease install both cartridges and try again.")
79 log.error("Invalid cartridge(s) installed.\nPlease install valid cartridges and try again.")
83 log.error("Invalid cartridge(s) installed. Cannot align with only the photo cartridge installed.\nPlease install other cartridges and try again.")
87 log.info("To perform alignment, you will need the alignment page that is automatically\nprinted after you install a print cartridge.")
88 log.info("\np\t\tPrint the alignment page and continue.")
89 log.info("n\t\tDo Not print the alignment page (you already have one) and continue.")
90 log.info("q\t\tQuit.\n")
92 ok, choice = tui.enter_choice("Choice (p=print page*, n=do not print page, q=quit) ? ", ['p', 'n', 'q'], 'p')
100 def type10and11and14Align(pattern, align_type):
101 controls = maint.align10and11and14Controls(pattern, align_type)
103 s_controls = controls.keys()
106 for line in s_controls:
107 if not controls[line][0]:
110 ok, value = tui.enter_range("Enter the numbered box on line %s where the inner lines best line up with the outer lines (1-%d): "
111 % (line, controls[line][1]), 1, controls[line][1])
122 log.info(log.bold("Follow these steps to complete the alignment:"))
123 log.info("1. Place the alignment page, with the printed side facing down, ")
124 log.info(" in the scanner.")
125 log.info("2. Press the Enter or Scan button on the printer.")
126 log.info('3. "Alignment Complete" will be displayed when the process is finished (on some models).')
132 mod = module.Module(__mod__, __title__, __version__, __doc__, None,
133 (INTERACTIVE_MODE, GUI_MODE), (UI_TOOLKIT_QT4,))
135 mod.setUsage(module.USAGE_FLAG_DEVICE_ARGS,
136 see_also_list=['hp-clean', 'hp-colorcal', 'hp-linefeedcal',
139 opts, device_uri, printer_name, mode, ui_toolkit, lang = \
142 device_uri = mod.getDeviceUri(device_uri, printer_name,
143 filter={'align-type': (operator.ne, ALIGN_TYPE_NONE)})
146 if not utils.canEnterGUIMode4():
147 log.error("%s -u/--gui requires Qt4 GUI support. Entering interactive mode." % __mod__)
148 mode = INTERACTIVE_MODE
150 if mode == INTERACTIVE_MODE:
152 d = device.Device(device_uri, printer_name)
154 log.error("Unable to open device: %s" % e.msg)
161 log.error("Device is busy or in an error state. Please check device and try again.")
164 if d.isIdleAndNoError():
165 align_type = d.mq.get('align-type', ALIGN_TYPE_NONE)
166 log.debug("Alignment type=%d" % align_type)
169 if align_type == ALIGN_TYPE_UNSUPPORTED:
170 log.error("Alignment through HPLIP not supported for this printer. Please use the printer's front panel to perform cartrdige alignment.")
172 elif align_type == ALIGN_TYPE_AUTO:
173 maint.AlignType1PML(d, tui.load_paper_prompt)
175 elif align_type == ALIGN_TYPE_AIO:
176 maint.AlignType13(d, tui.load_paper_prompt, tui.load_scanner_for_align_prompt)
178 elif align_type == ALIGN_TYPE_8XX:
179 maint.AlignType2(d, tui.load_paper_prompt, enterAlignmentNumber,
182 elif align_type in (ALIGN_TYPE_9XX,ALIGN_TYPE_9XX_NO_EDGE_ALIGN):
183 maint.AlignType3(d, tui.load_paper_prompt, enterAlignmentNumber,
184 enterPaperEdge, update_spinner)
186 elif align_type == ALIGN_TYPE_LIDIL_AIO:
187 maint.AlignType6(d, aioUI1, aioUI2, tui.load_paper_prompt)
189 elif align_type == ALIGN_TYPE_DESKJET_450:
190 maint.AlignType8(d, tui.load_paper_prompt, enterAlignmentNumber)
192 elif align_type in (ALIGN_TYPE_LIDIL_0_3_8, ALIGN_TYPE_LIDIL_0_4_3, ALIGN_TYPE_LIDIL_VIP):
194 maint.AlignxBow(d, align_type, tui.load_paper_prompt, enterAlignmentNumber, enterPaperEdge,
195 invalidPen, colorAdj)
197 elif align_type == ALIGN_TYPE_LBOW:
198 maint.AlignType10(d, tui.load_paper_prompt, type10and11and14Align)
200 elif align_type == ALIGN_TYPE_LIDIL_0_5_4:
201 maint.AlignType11(d, tui.load_paper_prompt, type10and11and14Align, invalidPen2)
203 elif align_type == ALIGN_TYPE_OJ_PRO:
204 maint.AlignType12(d, tui.load_paper_prompt)
206 elif align_type == ALIGN_TYPE_LIDIL_DJ_D1600:
207 maint.AlignType14(d, tui.load_paper_prompt, type10and11and14Align, invalidPen2)
209 elif align_type == ALIGN_TYPE_LEDM:
210 maint.AlignType15(d, tui.load_paper_prompt, aioUI2)
212 elif align_type == ALIGN_TYPE_LEDM_MANUAL:
213 maint.AlignType16(d, tui.load_paper_prompt, enterAlignmentNumber)
215 elif align_type == ALIGN_TYPE_LEDM_FF_CC_0:
216 maint.AlignType17(d, tui.load_paper_prompt, aioUI2)
219 log.error("Invalid alignment type.")
222 log.error("Device is busy or in an error state. Please check device and try again.")
227 else: # GUI_MODE (qt4)
229 from PyQt4.QtGui import QApplication
230 from ui4.aligndialog import AlignDialog
232 log.error("Unable to load Qt4 support. Is it installed?")
238 app = QApplication(sys.argv)
240 dlg = AlignDialog(None, device_uri)
243 log.debug("Starting GUI loop...")
245 except KeyboardInterrupt:
252 except KeyboardInterrupt:
253 log.error("User exit")