1 # -*- coding: utf-8 -*-
3 # (c) Copyright 2001-2008 Hewlett-Packard Development Company, L.P.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 from base import device, utils, maint
29 from base.codes import *
30 from ui_utils import *
33 from PyQt4.QtCore import *
34 from PyQt4.QtGui import *
37 from colorcaldialog_base import Ui_Dialog
40 COLOR_CAL_TYPE_INITIAL = 1000
41 COLOR_CAL_TYPE_TEST = 1001
61 class ColorCalDialog(QDialog, Ui_Dialog):
62 def __init__(self, parent, device_uri):
63 QDialog.__init__(self, parent)
65 self.device_uri = device_uri
66 self.color_cal_type = COLOR_CAL_TYPE_INITIAL
76 COLOR_CAL_TYPE_UNSUPPORTED : 1,
77 COLOR_CAL_TYPE_DESKJET_450 : 2,
78 COLOR_CAL_TYPE_MALIBU_CRICK : 0,
79 COLOR_CAL_TYPE_STRINGRAY_LONGBOW_TORNADO : 0,
80 COLOR_CAL_TYPE_CONNERY : 0,
81 COLOR_CAL_TYPE_COUSTEAU : 0,
82 COLOR_CAL_TYPE_CARRIER : 0,
83 COLOR_CAL_TYPE_TYPHOON : 0,
86 self.seq = { # (func|method, tuple of params|None)
87 COLOR_CAL_TYPE_INITIAL: [ # (used when starting up and align-type isn't known)
88 (self.showStartPage, None),
89 (self.endStartPage, None), # switch to a valid align-type here
92 COLOR_CAL_TYPE_UNSUPPORTED : [
93 (self.showFrontPanelPage, None),
94 (self.endFrontPanelPage, None),
98 COLOR_CAL_TYPE_DESKJET_450 : [ # 1
99 (self.colorCalType1PenCheck, None),
100 (self.showLoadPaperPage, None),
101 (self.endLoadPaperPage, None),
102 (maint.colorCalType1Phase1, (lambda: self.dev,)),
103 (self.setColorCalButton, (BUTTON_CALIBRATE,)),
104 (self.showDeskjet450Page, None),
105 (self.endDeskjet450Page, None),
106 (maint.colorCalType1Phase2, (lambda: self.dev, lambda: self.value)),
110 COLOR_CAL_TYPE_MALIBU_CRICK : [ # 2
111 (self.colorCalType2PenCheck, None),
112 (self.showLoadPaperPage, None),
113 (self.endLoadPaperPage, None),
114 (maint.colorCalType1Phase1, (lambda: self.dev,)),
115 (self.setColorCalButton, (BUTTON_CALIBRATE,)),
116 (self.showCrick, None),
117 (self.endCrick, None),
118 (maint.colorCalType2Phase2, (lambda: self.dev, lambda: self.value)),
122 COLOR_CAL_TYPE_STRINGRAY_LONGBOW_TORNADO : [ # 3
123 (self.colorCalType3PenCheck, None),
124 (self.showLoadPaperPage, None),
125 (self.endLoadPaperPage, None),
126 (maint.colorCalType3Phase1, (lambda: self.dev,)),
127 (self.showLBowPage, ('A', 21)),
128 (self.endLBowPage, ('A',)),
129 (self.setColorCalButton, (BUTTON_CALIBRATE,)),
130 (self.showLBowPage, ('B', 21)),
131 (self.endLBowPage, ('B',)),
132 (maint.colorCalType3Phase2, (lambda: self.dev, lambda: self.a,
137 COLOR_CAL_TYPE_CONNERY : [ #4
138 (self.showLoadPaperPage, None),
139 (self.endLoadPaperPage, None),
140 (maint.colorCalType4Phase1, (lambda: self.dev,)),
141 (self.setColorCalButton, (BUTTON_CALIBRATE,)),
142 (self.showConneryPage, None),
143 (self.endConneryPage, None), # sets self.values (list)
144 (maint.colorCalType4Phase2, (lambda: self.dev, lambda: self.values)),
145 (self.showLoadPaperPage, None),
146 (self.endLoadPaperPage, None),
147 (maint.colorCalType4Phase3, (lambda: self.dev,)),
151 COLOR_CAL_TYPE_COUSTEAU : [ #5
152 (self.setColorCalButton, (BUTTON_CALIBRATE,)),
153 (self.showLoadPaperPage, None),
154 (self.endLoadPaperPage, None),
155 (maint.colorCalType5, (lambda: self.dev, lambda: true)),
156 (self.showConneryPage, None),
157 (self.endConneryPage, None),
161 COLOR_CAL_TYPE_CARRIER : [ #6
162 (self.setColorCalButton, (BUTTON_CALIBRATE,)),
163 (self.showLoadPaperPage, None),
164 (self.endLoadPaperPage, None),
165 (maint.colorCalType6, (lambda: self.dev, lambda: true)),
169 COLOR_CAL_TYPE_TYPHOON : [ #7
170 (self.setColorCalButton, (BUTTON_CALIBRATE,)),
171 (self.showLoadPaperPage, None),
172 (self.endLoadPaperPage, None),
173 (maint.colorCalType7, (lambda: self.dev, lambda: true)),
181 QTimer.singleShot(0, self.nextSequence)
185 # connect signals/slots
186 self.connect(self.CancelButton, SIGNAL("clicked()"), self.CancelButton_clicked)
187 self.connect(self.NextButton, SIGNAL("clicked()"), self.NextButton_clicked)
188 self.connect(self.DeviceComboBox, SIGNAL("DeviceUriComboBox_noDevices"), self.DeviceUriComboBox_noDevices)
189 self.connect(self.DeviceComboBox, SIGNAL("DeviceUriComboBox_currentChanged"), self.DeviceUriComboBox_currentChanged)
190 self.DeviceComboBox.setFilter({'color-cal-type': (operator.gt, 0)})
193 self.DeviceComboBox.setInitialDevice(self.device_uri)
196 self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
197 self.updateStepText()
202 def DeviceUriComboBox_noDevices(self):
203 FailureUI(self, self.__tr("<b>No devices that support print cartridge alignment found.</b><p>Click <i>OK</i> to exit.</p>"))
207 def DeviceUriComboBox_currentChanged(self, device_uri):
208 self.device_uri = device_uri
211 def CancelButton_clicked(self):
215 def NextButton_clicked(self):
219 def nextSequence(self):
222 seq, params = self.seq[self.color_cal_type][self.seq_index]
230 self.new_page = False
233 if params is not None:
241 log.debug("%s(%s)" % (seq.func_name, ','.join([repr(x) for x in t])))
242 except AttributeError:
261 def showStartPage(self):
262 self.BackButton.setEnabled(False)
263 num_devices = self.DeviceComboBox.setDevices()
269 self.DeviceComboBox.updateUi()
270 self.displayPage(PAGE_START)
273 def endStartPage(self):
274 self.mq = device.queryModelByURI(self.device_uri)
275 self.color_cal_type = self.mq.get('color-cal-type', COLOR_CAL_TYPE_NONE)
278 #self.color_cal_type = COLOR_CAL_TYPE_TEST # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
280 log.debug("color-cal-type=%d" % self.color_cal_type)
281 self.step_max = self.max_steps[self.color_cal_type]
284 self.dev = device.Device(self.device_uri)
290 def showLoadPaperPage(self):
291 self.LoadPaper.updateUi()
292 self.displayPage(PAGE_LOAD_PAPER)
295 def endLoadPaperPage(self):
299 def showDeskjet450Page(self):
300 self.displayPage(PAGE_DESKJET_450)
303 def endDeskjet450Page(self):
304 self.value = int(unicode(self.Deskjet450ComboBox.currentText()))
308 self.displayPage(PAGE_CRICK)
312 self.value = self.CrickSpinBox.value()
314 def showLBowPage(self, line_id, count=21):
315 self.LBowComboBox.clear()
316 self.LBowIcon.setPixmap(load_pixmap('color_adj', 'other'))
317 self.LBowLabel.setText(self.__tr("Line %1:").arg(line_id))
319 for x in range(count):
320 self.LBowComboBox.addItem(QString("%1%2").arg(line_id).arg(x+1))
322 self.displayPage(PAGE_LBOW)
325 def endLBowPage(self, line_id):
326 v = int(str(self.LBowComboBox.currentText())[1:])
330 log.debug("A=%d" % v)
334 log.debug("B=%d" % v)
337 def showConneryPage(self):
338 self.ConneryGrayPatchIcon.setPixmap(load_pixmap('type4_gray_patch', 'other'))
339 self.ConneryColorPatchIcon.setPixmap(load_pixmap('type4_color_patch', 'other'))
341 for x in 'ABCDEFGHIJKLMN':
342 self.ConneryGrayLetterComboBox.addItem(QString(x))
345 self.ConneryGrayNumberComboBox.addItem(QString("%1").arg(x+1))
348 self.ConneryColorLetterComboBox.addItem(QString(x))
351 self.ConneryColorNumberComboBox.addItem(QString("%1").arg(x+1))
353 self.displayPage(PAGE_CONNERY)
356 def endConneryPage(self):
357 if self.ConneryUseFactoryDefaultsCheckBox.checkState() == Qt.Checked:
358 log.debug("Using factory defaults")
359 self.values = [-1, -1, -1, -1]
362 (ord(str(self.ConneryGrayLetterComboBox.currentText())) - ord('A')),
363 int(str(self.ConneryGrayNumberComboBox.currentText())),
364 (ord(str(self.ConneryColorLetterComboBox.currentText())) - ord('P')),
365 int(str(self.ConneryColorNumberComboBox.currentText()))
369 def showFrontPanelPage(self):
370 self.BackButton.setEnabled(False)
371 self.setColorCalButton(BUTTON_FINISH)
372 self.displayPage(PAGE_FRONT_PANEL)
375 def endFrontPanelPage(self):
382 def colorCalType1PenCheck(self):
383 if not maint.colorCalType1PenCheck(self.dev):
384 pass # TODO: Error message (photo pen must be inserted)
387 def colorCalType2PenCheck(self):
388 if not maint.colorCalType2PenCheck(self.dev):
389 pass # TODO: Error message (photo pen must be inserted)
392 def colorCalType3PenCheck(self):
393 if not maint.colorCalType3PenCheck(self.dev):
400 def displayPage(self, page):
401 self.updateStepText(self.step)
404 self.StackedWidget.setCurrentIndex(page)
409 self.new_page = False
412 def updateStepText(self, p=None):
413 if p is None or not self.step_max:
414 self.StepText.setText(QString(""))
416 self.StepText.setText(self.__tr("Step %1 of %2").arg(p).arg(self.step_max))
419 def setColorCalButton(self, typ=BUTTON_CALIBRATE):
420 if typ == BUTTON_CALIBRATE:
421 self.NextButton.setText(self.__tr("Calibrate"))
422 elif typ == BUTTON_NEXT:
423 self.NextButton.setText(self.__tr("Next >"))
424 elif typ == BUTTON_FINISH:
425 self.NextButton.setText(self.__tr("Finish"))
428 # def setPenConfig(self):
429 # self.dev.pen_config = status.getPenConfiguration(dev.getStatusFromDeviceID())
432 def __tr(self,s,c = None):
433 return qApp.translate("ColorCalDialog",s,c)