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
25 from base import device
26 from ui_utils import *
29 from PyQt4.QtCore import *
30 from PyQt4.QtGui import *
33 from printtestpagedialog_base import Ui_Dialog
36 class PrintTestPageDialog(QDialog, Ui_Dialog):
37 def __init__(self, parent, printer_name):
38 QDialog.__init__(self, parent)
40 self.printer_name = printer_name
45 QTimer.singleShot(0, self.updateUi)
49 #print "PrintTestPageDialog.initUi()"
50 self.HPLIPTestPageRadioButton.setChecked(True)
51 self.LoadPaper.setButtonName(self.__tr("Print Test Page"))
53 self.connect(self.CancelButton, SIGNAL("clicked()"), self.CancelButton_clicked)
54 self.connect(self.PrintTestpageButton, SIGNAL("clicked()"), self.PrintTestpageButton_clicked)
56 self.connect(self.PrinterNameCombo, SIGNAL("PrinterNameComboBox_currentChanged"),
57 self.PrinterNameCombo_currentChanged)
59 self.connect(self.PrinterNameCombo, SIGNAL("PrinterNameComboBox_noPrinters"),
60 self.PrinterNameComboBox_noPrinters)
63 self.PrinterNameCombo.setInitialPrinter(self.printer_name)
66 self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
70 self.PrinterNameCombo.updateUi()
71 self.LoadPaper.updateUi()
72 #self.updatePrintButton()
75 def PrinterNameComboBox_noPrinters(self):
76 FailureUI(self, self.__tr("<b>No printers found.</b><p>Please setup a printer and try again."))
80 def updatePrintButton(self):
81 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
82 self.PrintTestpageButton.setEnabled(False)
86 d = device.Device(self.device_uri, self.printer_name)
88 log.error("Device error (%s)." % e.msg)
93 log.error("Unable to print to printer. Please check device and try again.")
95 ok = d.isIdleAndNoError()
97 self.PrintTestpageButton.setEnabled(ok)
100 QApplication.restoreOverrideCursor()
101 FailureUI(self, self.__tr("<b>Unable to communicate with printer %1.</b><p>Please check the printer and try again.").arg(self.printer_name))
106 QApplication.restoreOverrideCursor()
109 def CancelButton_clicked(self):
113 def PrinterNameCombo_currentChanged(self, device_uri, printer_name):
114 self.printer_name = printer_name
115 self.device_uri = device_uri
116 self.updatePrintButton()
120 def PrintTestpageButton_clicked(self):
121 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
125 d = device.Device(self.device_uri, self.printer_name)
127 log.error("Device error (%s)." % e.msg)
132 log.error("Unable to print to printer. Please check device and try again.")
134 ok = d.isIdleAndNoError()
137 QApplication.restoreOverrideCursor()
140 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
142 d.printTestPage(self.printer_name)
144 QApplication.restoreOverrideCursor()
149 FailureUI(self, self.__tr("<b>A error occured sending the test page to printer %1.</b><p>Please check the printer and try again.").arg(self.printer_name))
154 def __tr(self, s, c=None):
155 return qApp.translate("PrintTestPageDialog", s, c)