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 cleandialog_base import Ui_Dialog
40 CLEAN_TYPE_INITIAL = 1000
41 CLEAN_TYPE_TEST = 1001
60 class CleanDialog(QDialog, Ui_Dialog):
61 def __init__(self, parent, device_uri):
62 QDialog.__init__(self, parent)
64 self.device_uri = device_uri
65 self.clean_type = CLEAN_TYPE_INITIAL
72 CLEAN_TYPE_UNSUPPORTED : 1,
75 CLEAN_TYPE_PCL_WITH_PRINTOUT : 4,
78 self.seq = { # (func|method, tuple of params|None)
79 CLEAN_TYPE_INITIAL: [ # (used when starting up and clean-type isn't known)
80 (self.showStartPage, None),
81 (self.endStartPage, None), # switch to a valid clean-type here
84 CLEAN_TYPE_UNSUPPORTED : [
85 (self.showFrontPanelPage, None),
86 (self.endFrontPanelPage, None),
90 CLEAN_TYPE_PCL : [ # 1
91 (self.showLevel1Page, None),
92 (self.endLevel1Page, None),
94 (self.showLevel2Page, None),
95 (self.endLevel2Page, None),
97 (self.showLevel3Page, None),
98 (self.endLevel3Page, None),
103 CLEAN_TYPE_LIDIL : [ # 2
104 (self.showLevel1Page, None),
105 (self.endLevel1Page, None),
106 (self.doClean, (1,)),
107 (self.showLevel2Page, None),
108 (self.endLevel2Page, None),
109 (self.doClean, (2,)),
110 (self.showLevel3Page, None),
111 (self.endLevel3Page, None),
112 (self.doClean, (3,)),
116 CLEAN_TYPE_PCL_WITH_PRINTOUT : [ # 3
117 (self.showLevel1Page, None),
118 (self.endLevel1Page, None),
119 (self.doClean, (1,)),
120 (self.showLevel2Page, None),
121 (self.endLevel2Page, None),
122 (self.doClean, (2,)),
123 (self.showLevel3Page, None),
124 (self.endLevel3Page, None),
125 (self.doClean, (3,)),
126 # TODO: Add print-out
133 QTimer.singleShot(0, self.nextSequence)
137 # connect signals/slots
138 self.connect(self.CancelButton, SIGNAL("clicked()"), self.CancelButton_clicked)
139 self.connect(self.NextButton, SIGNAL("clicked()"), self.NextButton_clicked)
140 self.connect(self.DeviceComboBox, SIGNAL("DeviceUriComboBox_noDevices"), self.DeviceUriComboBox_noDevices)
141 self.connect(self.DeviceComboBox, SIGNAL("DeviceUriComboBox_currentChanged"), self.DeviceUriComboBox_currentChanged)
142 self.DeviceComboBox.setFilter({'clean-type': (operator.gt, 0)})
145 self.DeviceComboBox.setInitialDevice(self.device_uri)
148 self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
151 def NextButton_clicked(self):
155 def nextSequence(self):
158 seq, params = self.seq[self.clean_type][self.seq_index]
166 self.new_page = False
169 if params is not None:
177 log.debug("%s(%s)" % (seq.func_name, ','.join([repr(x) for x in t])))
178 except AttributeError:
196 def showStartPage(self):
197 self.setCleanButton(BUTTON_NEXT)
198 num_devices = self.DeviceComboBox.setDevices()
204 self.DeviceComboBox.updateUi()
205 self.displayPage(PAGE_START)
208 def endStartPage(self):
209 self.mq = device.queryModelByURI(self.device_uri)
210 self.clean_type = self.mq.get('clean-type', CLEAN_TYPE_NONE)
213 log.debug("clean-type=%d" % self.clean_type)
214 self.step_max = self.max_steps[self.clean_type]
217 self.dev = device.Device(self.device_uri)
223 def showLevel1Page(self):
224 self.setCleanButton(BUTTON_CLEAN)
225 self.displayPage(PAGE_LEVEL_1)
228 def endLevel1Page(self):
232 def showLevel2Page(self):
233 self.displayPage(PAGE_LEVEL_2)
236 def endLevel2Page(self):
240 def showLevel3Page(self):
241 self.displayPage(PAGE_LEVEL_3)
244 def endLevel3Page(self):
248 def showFrontPanelPage(self):
249 self.setCleanButton(BUTTON_FINISH)
250 self.displayPage(PAGE_FRONT_PANEL)
253 def endFrontPanelPage(self):
257 def DeviceUriComboBox_currentChanged(self, device_uri):
258 self.device_uri = device_uri
261 def DeviceUriComboBox_noDevices(self):
262 FailureUI(self, self.__tr("<b>No devices that support print cartridge cleaning found.</b><p>Click <i>OK</i> to exit.</p>"))
266 def CancelButton_clicked(self):
270 def doClean(self, level):
277 if self.dev.isIdleAndNoError():
278 if self.clean_type in (CLEAN_TYPE_PCL, # 1
279 CLEAN_TYPE_PCL_WITH_PRINTOUT): # 3
282 maint.cleanType1(self.dev)
285 maint.primeType1(self.dev)
288 maint.wipeAndSpitType1(self.dev)
291 elif self.clean_type == CLEAN_TYPE_LIDIL: # 2
293 maint.cleanType2(self.dev)
296 maint.primeType2(self.dev)
299 maint.wipeAndSpitType2(self.dev)
301 maint.print_clean_test_page(self.dev)
307 if self.dev is not None:
315 def displayPage(self, page):
316 self.updateStepText(self.step)
319 self.StackedWidget.setCurrentIndex(page)
324 self.new_page = False
327 def updateStepText(self, p=None):
328 if p is None or not self.step_max:
329 self.StepText.setText(QString(""))
331 self.StepText.setText(self.__tr("Step %1 of %2").arg(p).arg(self.step_max))
334 def setCleanButton(self, typ=BUTTON_CLEAN):
335 if typ == BUTTON_CLEAN:
336 self.NextButton.setText(self.__tr("Clean"))
337 elif typ == BUTTON_NEXT:
338 self.NextButton.setText(self.__tr("Next >"))
339 elif typ == BUTTON_FINISH:
340 self.NextButton.setText(self.__tr("Finish"))
343 def __tr(self,s,c = None):
344 return qApp.translate("CleanDialog",s,c)