Tizen 2.1 base
[platform/upstream/hplip.git] / ui4 / pqdiagdialog.py
1 # -*- coding: utf-8 -*-
2 #
3 # (c) Copyright 2001-2008 Hewlett-Packard Development Company, L.P.
4 #
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.
9 #
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.
14 #
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
18 #
19 # Authors: Don Welch
20 #
21
22 # StdLib
23 import operator
24
25 # Local
26 from base.g import *
27 from base import device, utils, maint
28 from prnt import cups
29 from base.codes import *
30 from ui_utils import *
31
32 # Qt
33 from PyQt4.QtCore import *
34 from PyQt4.QtGui import *
35
36 # Ui
37 from pqdiagdialog_base import Ui_Dialog
38
39
40 class PQDiagDialog(QDialog, Ui_Dialog):
41     def __init__(self, parent, device_uri):
42         QDialog.__init__(self, parent)
43         self.setupUi(self)
44         self.device_uri = device_uri
45         self.initUi()
46
47         QTimer.singleShot(0, self.updateUi)
48
49
50     def initUi(self):
51         # connect signals/slots
52         self.connect(self.CancelButton, SIGNAL("clicked()"), self.CancelButton_clicked)
53         self.connect(self.RunButton, SIGNAL("clicked()"), self.RunButton_clicked)
54         self.connect(self.DeviceComboBox, SIGNAL("DeviceUriComboBox_noDevices"), self.DeviceUriComboBox_noDevices)
55         self.connect(self.DeviceComboBox, SIGNAL("DeviceUriComboBox_currentChanged"), self.DeviceUriComboBox_currentChanged)
56         self.DeviceComboBox.setFilter({'pq-diag-type': (operator.gt, 0)})
57
58         # Application icon
59         self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
60
61         if self.device_uri:
62             self.DeviceComboBox.setInitialDevice(self.device_uri)
63
64
65     def updateUi(self):
66         self.DeviceComboBox.updateUi()
67         self.LoadPaper.setButtonName(self.__tr("Run"))
68         self.LoadPaper.updateUi()
69
70
71     def DeviceUriComboBox_currentChanged(self, device_uri):
72         self.device_uri = device_uri
73
74
75     def DeviceUriComboBox_noDevices(self):
76         FailureUI(self, self.__tr("<b>No devices that support print quality diagnostics found.</b><p>Click <i>OK</i> to exit.</p>"))
77         self.close()
78
79
80     def CancelButton_clicked(self):
81         self.close()
82
83
84     def RunButton_clicked(self):
85         d = None
86
87         try:
88             try:
89                 d = device.Device(self.device_uri)
90             except Error:
91                 CheckDeviceUI(self)
92                 return
93
94             pqdiag_type = d.pq_diag_type
95
96             try:
97                 d.open()
98             except Error:
99                 CheckDeviceUI(self)
100             else:
101                 if d.isIdleAndNoError():
102                     if pqdiag_type == 1:
103                         maint.printQualityDiagType1(d, lambda : True)
104
105                     elif pqdiag_type == 2:
106                         maint.printQualityDiagType2(d, lambda : True)
107
108                 else:
109                     CheckDeviceUI(self)
110
111         finally:
112             if d is not None:
113                 d.close()
114
115         self.close()
116
117     #
118     # Misc
119     #
120
121     def __tr(self,s,c = None):
122         return qApp.translate("PQDiagDialog",s,c)
123
124