def __init__(self, device_uri, printer_name, args, parent=None, name=None, modal=0, fl=0): QMainWindow.__init__(self, parent, name, fl) self.setIcon(load_pixmap('hp_logo', '128x128')) self.init_failed = False self.device_uri = device_uri self.dev = None self.printer_name = printer_name bus = ['cups'] self.filename = '' self.username = prop.username self.args = args self.setCentralWidget(QWidget(self, "qt_central_widget")) self.FormLayout = QGridLayout(self.centralWidget(), 1, 1, 11, 6, "FormLayout") self.resize(QSize(600, 480).expandedTo(self.minimumSizeHint())) self.clearWState(Qt.WState_Polished) self.languageChange() # if self.device_uri and self.printer_name: # log.error("You may not specify both a printer (-p) and a device (-d).") # self.FailureUI(self.__tr("<p><b>You may not specify both a printer (-p) and a device (-d).")) # self.device_uri, self.printer_name = None, None # self.init_failed = True self.cups_printers = cups.getPrinters() log.debug(self.cups_printers) if self.printer_name: found = False for p in self.cups_printers: if p.name == printer_name: self.device_uri = p.device_uri found = True break if not found: self.FailureUI( self.__tr( "<b>Unknown printer name: %1</b><p>Please check the printer name and try again." ).arg(self.printer_name)) if found and not p.device_uri.startswith('hpfax:/'): self.FailureUI( self.__tr( "You must specify a printer that has a device URI in the form 'hpfax:/...'" )) self.init_failed = True if not self.device_uri and not self.printer_name: t = device.probeDevices( bus=bus, filter={'fax-type': (operator.gt, FAX_TYPE_NONE)}) #print t probed_devices = [] for d in t: probed_devices.append(d.replace('hp:/', 'hpfax:/')) #print probed_devices probed_devices = utils.uniqueList(probed_devices) log.debug(probed_devices) max_deviceid_size, x, devices = 0, 0, {} for d in probed_devices: printers = [] for p in self.cups_printers: #print p.device_uri, d if p.device_uri == d: #print "OK" printers.append(p.name) devices[x] = (d, printers) x += 1 max_deviceid_size = max(len(d), max_deviceid_size) x = len(devices) #print devices if x == 0: from nodevicesform import NoDevicesForm self.FailureUI( self.__tr( "<p><b>No devices found.</b><p>Please make sure your device is properly installed and try again." )) self.init_failed = True elif x == 1: log.info(log.bold("Using device: %s" % devices[0][0])) self.device_uri = devices[0][0] else: from chooseprinterdlg import ChoosePrinterDlg dlg = ChoosePrinterDlg(self.cups_printers, ['hpfax']) if dlg.exec_loop() == QDialog.Accepted: self.device_uri = dlg.device_uri else: self.init_failed = True self.dbus_avail, self.service, session_bus = device.init_dbus() self.FaxView = ScrollFaxView(self.service, self.centralWidget(), self) self.FormLayout.addWidget(self.FaxView, 0, 0) if not self.init_failed: if not self.device_uri or not self.device_uri.startswith("hpfax:"): log.error("Invalid device URI: %s" % repr(device_uri)) self.FailureUI( self.__tr( "<b>Invalid device URI %1.</b><p>Please check the parameters to hp-print and try again." ).arg(repr(device_uri))) self.init_failed = True else: try: self.cur_device = device.Device( device_uri=self.device_uri, printer_name=self.printer_name) except Error, e: log.error("Invalid device URI or printer name.") self.FailureUI( "<b>Invalid device URI or printer name.</b><p>Please check the parameters to hp-print and try again." ) self.init_failed = True else: self.device_uri = self.cur_device.device_uri user_conf.set('last_used', 'device_uri', self.device_uri) log.debug(self.device_uri) self.statusBar().message(self.device_uri)
def __init__(self, printer_name=None, args=None, parent=None,name=None,modal=0,fl=0): QMainWindow.__init__(self,parent,name,fl) self.printer_name = printer_name self.file_list = [] self.args = args self.init_failed = False self.statusBar() self.setIcon(load_pixmap('hp_logo', '128x128')) signal.signal(signal.SIGINT, signal.SIG_DFL) if not name: self.setName("PrinterForm") self.setCentralWidget(QWidget(self,"qt_central_widget")) self.FormLayout = QGridLayout(self.centralWidget(),1,1,11,6,"FormLayout") self.resize(QSize(600,480).expandedTo(self.minimumSizeHint())) self.clearWState(Qt.WState_Polished) self.languageChange() self.cups_printers = device.getSupportedCUPSPrinters() log.debug(self.cups_printers) if not self.printer_name: # no -p provided t = device.probeDevices(['cups']) probed_devices = [] for d in t: if d.startswith('hp:'): probed_devices.append(d) log.debug(probed_devices) max_deviceid_size, x, devices = 0, 0, {} for d in probed_devices: printers = [] for p in self.cups_printers: if p.device_uri == d: printers.append(p.name) devices[x] = (d, printers) x += 1 max_deviceid_size = max(len(d), max_deviceid_size) if x == 0: from nodevicesform import NoDevicesForm self.FailureUI(self.__tr("<p><b>No devices found.</b><p>Please make sure your device is properly installed and try again.")) self.init_failed = True elif x == 1: log.info(log.bold("Using device: %s" % devices[0][0])) self.device_uri = devices[0][0] else: from chooseprinterdlg import ChoosePrinterDlg dlg = ChoosePrinterDlg(self.cups_printers) if dlg.exec_loop() == QDialog.Accepted: self.printer_name = dlg.printer_name self.device_uri = dlg.device_uri else: self.init_failed = True else: # -p provided for p in self.cups_printers: if p.name == self.printer_name: self.device_uri = p.device_uri break else: self.FailureUI("<b>Invalid printer name.</b><p>Please check the parameters to hp-print and try again.") self.init_failed = True if not self.init_failed: self.PrintView = ScrollPrintView(None, self.centralWidget(), self, "PrintView") self.FormLayout.addWidget(self.PrintView,0,0) try: self.cur_device = device.Device(device_uri=self.device_uri, printer_name=self.printer_name) except Error, e: log.error("Invalid device URI or printer name.") self.FailureUI("<b>Invalid device URI or printer name.</b><p>Please check the parameters to hp-print and try again.") self.init_failed = True else: self.device_uri = self.cur_device.device_uri user_conf.set('last_used', 'device_uri', self.device_uri) log.debug(self.device_uri) self.statusBar().message(self.device_uri)
def __init__(self, device_uri, printer_name, args, parent=None, name=None, modal=0, fl=0): QMainWindow.__init__(self,parent,name,fl) self.setIcon(load_pixmap('hp_logo', '128x128')) self.init_failed = False self.device_uri = device_uri self.dev = None self.printer_name = printer_name bus = ['cups'] self.filename = '' self.username = prop.username self.args = args self.setCentralWidget(QWidget(self,"qt_central_widget")) self.FormLayout = QGridLayout(self.centralWidget(),1,1,11,6,"FormLayout") self.resize(QSize(600,480).expandedTo(self.minimumSizeHint())) self.clearWState(Qt.WState_Polished) self.languageChange() # if self.device_uri and self.printer_name: # log.error("You may not specify both a printer (-p) and a device (-d).") # self.FailureUI(self.__tr("<p><b>You may not specify both a printer (-p) and a device (-d).")) # self.device_uri, self.printer_name = None, None # self.init_failed = True self.cups_printers = cups.getPrinters() log.debug(self.cups_printers) if self.printer_name: found = False for p in self.cups_printers: if p.name == printer_name: self.device_uri = p.device_uri found = True break if not found: self.FailureUI(self.__tr("<b>Unknown printer name: %1</b><p>Please check the printer name and try again.").arg(self.printer_name)) if found and not p.device_uri.startswith('hpfax:/'): self.FailureUI(self.__tr("You must specify a printer that has a device URI in the form 'hpfax:/...'")) self.init_failed = True if not self.device_uri and not self.printer_name: t = device.probeDevices(bus=bus, filter={'fax-type':(operator.gt, FAX_TYPE_NONE)}) #print t probed_devices = [] for d in t: probed_devices.append(d.replace('hp:/', 'hpfax:/')) #print probed_devices probed_devices = utils.uniqueList(probed_devices) log.debug(probed_devices) max_deviceid_size, x, devices = 0, 0, {} for d in probed_devices: printers = [] for p in self.cups_printers: #print p.device_uri, d if p.device_uri == d: #print "OK" printers.append(p.name) devices[x] = (d, printers) x += 1 max_deviceid_size = max(len(d), max_deviceid_size) x = len(devices) #print devices if x == 0: from nodevicesform import NoDevicesForm self.FailureUI(self.__tr("<p><b>No devices found.</b><p>Please make sure your device is properly installed and try again.")) self.init_failed = True elif x == 1: log.info(log.bold("Using device: %s" % devices[0][0])) self.device_uri = devices[0][0] else: from chooseprinterdlg import ChoosePrinterDlg dlg = ChoosePrinterDlg(self.cups_printers, ['hpfax']) if dlg.exec_loop() == QDialog.Accepted: self.device_uri = dlg.device_uri else: self.init_failed = True self.dbus_avail, self.service, session_bus = device.init_dbus() self.FaxView = ScrollFaxView(self.service, self.centralWidget(), self) self.FormLayout.addWidget(self.FaxView,0,0) if not self.init_failed: if not self.device_uri or not self.device_uri.startswith("hpfax:"): log.error("Invalid device URI: %s" % repr(device_uri)) self.FailureUI(self.__tr("<b>Invalid device URI %1.</b><p>Please check the parameters to hp-print and try again.").arg(repr(device_uri))); self.init_failed = True else: try: self.cur_device = device.Device(device_uri=self.device_uri, printer_name=self.printer_name) except Error, e: log.error("Invalid device URI or printer name.") self.FailureUI("<b>Invalid device URI or printer name.</b><p>Please check the parameters to hp-print and try again.") self.init_failed = True else: self.device_uri = self.cur_device.device_uri user_conf.set('last_used', 'device_uri', self.device_uri) log.debug(self.device_uri) self.statusBar().message(self.device_uri)