示例#1
0
    def showRemovePage(self):
        self.displayPage(PAGE_REMOVE)
        self.StepText.setText(self.__tr("Step 1 of 1"))
        self.setNextButton(BUTTON_REMOVE)
        self.BackButton.setEnabled(False)
        self.NextButton.setEnabled(False)

        self.RemoveDevicesTableWidget.verticalHeader().hide()

        self.installed_printers = device.getSupportedCUPSPrinters(['hp', 'hpfax'])
        log.debug(self.installed_printers)

        if not self.installed_printers:
            FailureUI(self, self.__tr("<b>No printers or faxes found to remove.</b><p>You must setup a least one printer or fax before you can remove it."))
            self.close()
            return

        self.RemoveDevicesTableWidget.setRowCount(len(self.installed_printers))

        headers = [self.__tr("Select"), self.__tr('Printer (Queue) Name'), self.__tr('Type'), self.__tr('Device URI')]

        self.RemoveDevicesTableWidget.setColumnCount(len(headers))
        self.RemoveDevicesTableWidget.setHorizontalHeaderLabels(headers)
        flags = Qt.ItemIsSelectable | Qt.ItemIsEnabled

        row = 0
        for p in self.installed_printers:
            widget = QCheckBox(self.RemoveDevicesTableWidget)
            self.connect(widget, SIGNAL("stateChanged(int)"), self.CheckBox_stateChanged)
            self.RemoveDevicesTableWidget.setCellWidget(row, 0, widget)

            back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \
                device.parseDeviceURI(p.device_uri)

            if self.device_uri is not None and self.device_uri == p.device_uri:
                widget.setCheckState(Qt.Checked)

            i = QTableWidgetItem(QString(p.name))
            i.setFlags(flags)
            i.setData(Qt.UserRole, QVariant(p.name))
            self.RemoveDevicesTableWidget.setItem(row, 1, i)

            if back_end == 'hpfax':
                typ = self.__tr("Fax")
            else:
                typ = self.__tr("Printer")

            i = QTableWidgetItem(typ)
            i.setFlags(flags)
            self.RemoveDevicesTableWidget.setItem(row, 2, i)

            i = QTableWidgetItem(QString(p.device_uri))
            i.setFlags(flags)
            self.RemoveDevicesTableWidget.setItem(row, 3, i)

            row += 1

        self.RemoveDevicesTableWidget.resizeColumnsToContents()
示例#2
0
    def __init__(self, device_uri=None, name=None):
        self.name = None
        self.device_uri = None
        self.dev = None

        hp_printers = device.getSupportedCUPSPrinters(["hp"])
        for printer in hp_printers:
            if (device_uri is None and name is None) or \
                    (device_uri and device_uri == printer.device_uri and name and printer.name == name):
                self.name = printer.name
                self.device_uri = printer.device_uri
                break

        try:
            self._init_device()
        except Exception as e:
            log.warning(str(e))

        log.info("hp")
    def updateUi(self):
        #print "PrinterNameComboBox.updateUi()"
        if self.typ == PRINTERNAMECOMBOBOX_TYPE_PRINTER_ONLY:
            self.NameLabel.setText(self.__tr("Printer Name:"))
            be_filter = ['hp']

        elif self.typ == PRINTERNAMECOMBOBOX_TYPE_FAX_ONLY:
            self.NameLabel.setText(self.__tr("Fax Name:"))
            be_filter = ['hpfax']

        else:  # PRINTERNAMECOMBOBOX_TYPE_PRINTER_AND_FAX
            self.NameLabel.setText(self.__tr("Printer/Fax Name:"))
            be_filter = ['hp', 'hpfax']

        self.printers = device.getSupportedCUPSPrinters(be_filter)
        self.printer_index.clear()  # = {}

        if self.printers:
            if self.initial_printer is None:
                #user_conf.get('last_used', 'printer_name')
                self.initial_printer = self.user_settings.last_used_printer

            self.updating = True
            try:
                k = 0
                for i, p in enumerate(self.printers):
                    self.printer_index[p.name] = p.device_uri
                    self.ComboBox.insertItem(i, p.name)

                    if self.initial_printer is not None and to_unicode(
                            p.name).lower() == to_unicode(
                                self.initial_printer).lower():
                        self.initial_printer = None
                        k = i

                self.ComboBox.setCurrentIndex(-1)

            finally:
                self.updating = False

            self.ComboBox.setCurrentIndex(k)
        else:
            self.emit(SIGNAL("PrinterNameComboBox_noPrinters"))
    def updateUi(self):
        #print "PrinterNameComboBox.updateUi()"
        if self.typ == PRINTERNAMECOMBOBOX_TYPE_PRINTER_ONLY:
            self.NameLabel.setText(self.__tr("Printer Name:"))
            be_filter = ['hp']

        elif self.typ == PRINTERNAMECOMBOBOX_TYPE_FAX_ONLY:
            self.NameLabel.setText(self.__tr("Fax Name:"))
            be_filter = ['hpfax']

        else: # PRINTERNAMECOMBOBOX_TYPE_PRINTER_AND_FAX
            self.NameLabel.setText(self.__tr("Printer/Fax Name:"))
            be_filter = ['hp', 'hpfax']

        self.printers = device.getSupportedCUPSPrinters(be_filter)
        self.printer_index.clear() # = {}

        if self.printers:
            if self.initial_printer is None:
                #user_conf.get('last_used', 'printer_name')
                self.initial_printer = self.user_settings.last_used_printer

            self.updating = True
            try:
                k = 0
                for i, p in enumerate(self.printers):
                    self.printer_index[p.name] = p.device_uri
                    self.ComboBox.insertItem(i, p.name)

                    if self.initial_printer is not None and to_unicode(p.name).lower() == to_unicode(self.initial_printer).lower():
                        self.initial_printer = None
                        k = i

                self.ComboBox.setCurrentIndex(-1)

            finally:
                self.updating = False

            self.ComboBox.setCurrentIndex(k)
        else:
            # self.emit(SIGNAL("PrinterNameComboBox_noPrinters"))
            self.PrinterNameComboBox_noPrinters.emit()
示例#5
0
    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 as 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)

        QTimer.singleShot(0, self.InitialUpdate)
示例#6
0
    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 as 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)

        QTimer.singleShot(0, self.InitialUpdate)