1 # -*- coding: utf-8 -*-
3 # (c) Copyright 2001-2009 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, pml
28 from copier import copier
29 from ui_utils import load_pixmap
33 from scrollcopy import ScrollCopyView
35 class MakeCopiesForm(QMainWindow):
36 def __init__(self, bus='cups', device_uri=None, printer_name=None,
37 num_copies=None, contrast=None, quality=None,
38 reduction=None, fit_to_page=None,
39 parent=None, name=None, modal=0, fl=0):
41 QMainWindow.__init__(self,parent,name,fl)
43 self.setIcon(load_pixmap('hp_logo', '128x128'))
45 self.cur_device_uri = device_uri
46 self.printer_name = printer_name
47 self.init_failed = False
48 self.num_copies = num_copies
49 self.contrast = contrast
50 self.quality = quality
51 self.reduction = reduction
52 self.fit_to_page = fit_to_page
54 self.setCentralWidget(QWidget(self,"qt_central_widget"))
55 self.FormLayout = QGridLayout(self.centralWidget(),1,1,11,6,"FormLayout")
56 self.resize(QSize(600,480).expandedTo(self.minimumSizeHint()))
57 self.clearWState(Qt.WState_Polished)
60 if self.cur_device_uri and self.printer_name:
61 log.error("You may not specify both a printer (-p) and a device (-d).")
62 self.FailureUI(self.__tr("<p><b>You may not specify both a printer (-p) and a device (-d)."))
63 self.cur_device_uri, self.printer_name = None, None
64 self.init_failed = True
66 self.cups_printers = cups.getPrinters()
67 log.debug(self.cups_printers)
69 if not self.cur_device_uri and not self.printer_name:
70 t = device.probeDevices(bus=bus, filter={'copy-type': (operator.gt, 0)})
74 if d.startswith('hp:'):
75 probed_devices.append(d)
77 log.debug(probed_devices)
79 max_deviceid_size, x, devices = 0, 0, {}
81 for d in probed_devices:
83 for p in self.cups_printers:
85 printers.append(p.name)
86 devices[x] = (d, printers)
88 max_deviceid_size = max(len(d), max_deviceid_size)
91 from nodevicesform import NoDevicesForm
92 self.FailureUI(self.__tr("<p><b>No devices found.</b><p>Please make sure your device is properly installed and try again."))
93 self.init_failed = True
96 log.info(log.bold("Using device: %s" % devices[0][0]))
97 self.cur_device_uri = devices[0][0]
101 from choosedevicedlg import ChooseDeviceDlg
102 dlg = ChooseDeviceDlg(devices) #, ['hp'])
104 if dlg.exec_loop() == QDialog.Accepted:
105 self.cur_device_uri = dlg.device_uri
107 self.init_failed = True
110 self.CopyView = ScrollCopyView(None, num_copies=num_copies,
111 contrast=contrast, quality=quality,
112 reduction=reduction, fit_to_page=fit_to_page,
113 parent=self.centralWidget(), form=self)
115 self.FormLayout.addWidget(self.CopyView,0,0)
117 self.cur_device = self.cur_device_uri
119 if not self.init_failed:
121 self.cur_device = copier.PMLCopyDevice(device_uri=self.cur_device_uri,
122 printer_name=self.printer_name)
124 log.error("Invalid device URI or printer name.")
125 self.FailureUI("<b>Invalid device URI or printer name.</b><p>Please check the parameters to hp-print and try again.")
126 self.init_failed = True
130 if self.cur_device.copy_type == COPY_TYPE_NONE:
131 self.FailureUI(self.__tr("<b>Sorry, make copies functionality is not implemented for this device.</b>"))
135 self.cur_device_uri = self.cur_device.device_uri
136 user_conf.set('last_used', 'device_uri', self.cur_device_uri)
138 log.debug(self.cur_device_uri)
140 self.statusBar().message(self.cur_device.device_uri)
143 QTimer.singleShot(0, self.InitialUpdate)
145 def InitialUpdate(self):
150 self.CopyView.onDeviceChange(self.cur_device)
152 def languageChange(self):
153 self.setCaption(self.__tr("HP Device Manager - Make Copies"))
155 def FailureUI(self, error_text):
156 QMessageBox.critical(self,
160 QMessageBox.NoButton,
161 QMessageBox.NoButton)
163 def WarningUI(self, msg):
164 QMessageBox.warning(self,
168 QMessageBox.NoButton,
169 QMessageBox.NoButton)
172 def __tr(self,s,c = None):
173 return qApp.translate("MakeCopiesForm",s,c)