219
def printButton_clicked(self):
220
if self.invalid_page_range:
221
self.form.FailureUI(self.__tr("<b>Cannot print: Invalid page range: %1</b><p>A valid page range is a list of pages or ranges of pages separated by commas (e.g., 1-2,4,6-7)").arg(self.pageRangeEdit.text()))
226
self.cur_device.open()
228
self.form.FailureUI(self.__tr("<b>Cannot print: Device is busy or not available.</b><p>Please check device and try again."))
231
if 1: # Go ahead and allow - print will be queued in CUPS if not rejecting
232
printers = cups.getPrinters()
234
if p.name == self.cur_printer:
237
if p.state == cups.IPP_PRINTER_STATE_STOPPED:
238
self.form.FailureUI(self.__tr("<b>Cannot print: Printer is stopped.</b><p>Please START the printer to continue this print. Job will begin printing once printer is started."))
241
self.form.FailureUI(self.__tr("<b>Cannot print: Printer is not accepting jobs.</b><p>Please set the printer to ACCEPTING JOBS to continue printing."))
244
copies = int(self.copiesSpinBox.value())
245
all_pages = self.pages_button_group == 0
246
page_range = unicode(self.pageRangeEdit.text())
247
page_set = int(self.pageSetComboBox.currentItem())
250
cups.openPPD(self.cur_printer)
251
current_options = dict(cups.getOptions())
254
nup = int(current_options.get("number-up", 1))
256
for p, t, d in self.file_list:
258
alt_nup = (nup > 1 and t == 'application/postscript' and utils.which('psnup'))
260
if utils.which('lpr'):
262
cmd = ' '.join(['psnup', '-%d' % nup, ''.join(['"', p, '"']), '| lpr -P', self.cur_printer])
264
cmd = ' '.join(['lpr -P', self.cur_printer])
267
cmd = ' '.join([cmd, '-#%d' % copies])
271
cmd = ' '.join(['psnup', '-%d' % nup, ''.join(['"', p, '"']), '| lp -c -d', self.cur_printer])
273
cmd = ' '.join(['lp -c -d', self.cur_printer])
276
cmd = ' '.join([cmd, '-n%d' % copies])
279
if not all_pages and len(page_range) > 0:
280
cmd = ' '.join([cmd, '-o page-ranges=%s' % page_range])
284
cmd = ' '.join([cmd, '-o page-set=even'])
286
cmd = ' '.join([cmd, '-o page-set=odd'])
290
# self.job_storage_mode = (0=Off, 1=P&H, 2=PJ, 3=QC, 4=SJ)
291
# self.job_storage_pin = u"" (dddd)
292
# self.job_storage_use_pin = True|False
293
# self.job_storage_username = u""
294
# self.job_storage_auto_username = True|False
295
# self.job_storage_jobname = u""
296
# self.job_storage_auto_jobname = True|False
297
# self.job_storage_job_exist = (0=replace, 1=job name+(1-99))
299
if self.job_storage_avail:
300
if self.job_storage_mode: # On
302
if self.job_storage_mode == 1: # Proof and Hold
303
cmd = ' '.join([cmd, '-o HOLD=PROOF'])
305
elif self.job_storage_mode == 2: # Private Job
306
if self.job_storage_use_pin:
307
cmd = ' '.join([cmd, '-o HOLD=ON'])
308
cmd = ' '.join([cmd, '-o HOLDTYPE=PRIVATE'])
309
cmd = ' '.join([cmd, '-o HOLDKEY=%s' % self.job_storage_pin.encode('ascii')])
311
cmd = ' '.join([cmd, '-o HOLD=PROOF'])
312
cmd = ' '.join([cmd, '-o HOLDTYPE=PRIVATE'])
314
elif self.job_storage_mode == 3: # Quick Copy
315
cmd = ' '.join([cmd, '-o HOLD=ON'])
316
cmd = ' '.join([cmd, '-o HOLDTYPE=PUBLIC'])
318
elif self.job_storage_mode == 4: # Store Job
319
if self.job_storage_use_pin:
320
cmd = ' '.join([cmd, '-o HOLD=STORE'])
321
cmd = ' '.join([cmd, '-o HOLDTYPE=PRIVATE'])
322
cmd = ' '.join([cmd, '-o HOLDKEY=%s' % self.job_storage_pin.encode('ascii')])
324
cmd = ' '.join([cmd, '-o HOLD=STORE'])
326
cmd = ' '.join([cmd, '-o USERNAME=%s' % self.job_storage_username.encode('ascii')\
329
cmd = ' '.join([cmd, '-o JOBNAME=%s' % self.job_storage_jobname.encode('ascii')\
332
if self.job_storage_job_exist == 1:
333
cmd = ' '.join([cmd, '-o DUPLICATEJOB=APPEND'])
335
cmd = ' '.join([cmd, '-o DUPLICATEJOB=REPLACE'])
338
cmd = ' '.join([cmd, '-o HOLD=OFF'])
342
cmd = ''.join([cmd, ' "', p, '"'])
344
log.debug("Printing: %s" % cmd)
346
code = os.system(cmd)
348
log.error("Print command failed.")
349
self.form.FailureUI(self.__tr("Print command failed with error code %1").arg(code))
354
self.cur_device.close()