1
# -*- coding: utf-8 -*-
3
# (c) Copyright 2001-2015 HP 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 .ui_utils import *
28
from base import device
29
from base.sixext import to_unicode
32
from PyQt4.QtCore import *
33
from PyQt4.QtGui import *
36
PRINTERNAMECOMBOBOX_TYPE_PRINTER_ONLY = 0
37
PRINTERNAMECOMBOBOX_TYPE_FAX_ONLY = 1
38
PRINTERNAMECOMBOBOX_TYPE_PRINTER_AND_FAX = 2
41
class PrinterNameComboBox(QWidget):
42
def __init__(self, parent):
43
QWidget.__init__(self, parent)
44
self.printer_name = ''
46
self.printer_index = {}
47
self.initial_printer = None
49
self.typ = PRINTERNAMECOMBOBOX_TYPE_PRINTER_ONLY
51
self.user_settings = UserSettings()
52
self.user_settings.load()
53
self.user_settings.debug()
59
#print "PrinterNameComboBox.initUi()"
60
HBoxLayout = QHBoxLayout(self)
61
HBoxLayout.setObjectName("HBoxLayout")
63
self.NameLabel = QLabel(self)
64
self.NameLabel.setObjectName("NameLabel")
65
HBoxLayout.addWidget(self.NameLabel)
67
SpacerItem = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Minimum)
68
HBoxLayout.addItem(SpacerItem)
70
self.ComboBox = QComboBox(self)
71
sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
72
sizePolicy.setHorizontalStretch(0)
73
sizePolicy.setVerticalStretch(0)
74
sizePolicy.setHeightForWidth(self.ComboBox.sizePolicy().hasHeightForWidth())
75
self.ComboBox.setSizePolicy(sizePolicy)
76
self.ComboBox.setObjectName("ComboBox")
77
HBoxLayout.addWidget(self.ComboBox)
79
self.NameLabel.setText(self.__tr("Printer:"))
81
#self.connect(self.ComboBox, SIGNAL("currentIndexChanged(int)"),
82
# self.ComboBox_currentIndexChanged)
84
self.connect(self.ComboBox, SIGNAL("currentIndexChanged(const QString &)"),
85
self.ComboBox_currentIndexChanged)
87
def setType(self, typ):
88
if typ in (PRINTERNAMECOMBOBOX_TYPE_PRINTER_ONLY,
89
PRINTERNAMECOMBOBOX_TYPE_FAX_ONLY,
90
PRINTERNAMECOMBOBOX_TYPE_PRINTER_AND_FAX):
94
def setInitialPrinter(self, printer_name):
95
self.initial_printer = printer_name
99
#print "PrinterNameComboBox.updateUi()"
100
if self.typ == PRINTERNAMECOMBOBOX_TYPE_PRINTER_ONLY:
101
self.NameLabel.setText(self.__tr("Printer Name:"))
104
elif self.typ == PRINTERNAMECOMBOBOX_TYPE_FAX_ONLY:
105
self.NameLabel.setText(self.__tr("Fax Name:"))
106
be_filter = ['hpfax']
108
else: # PRINTERNAMECOMBOBOX_TYPE_PRINTER_AND_FAX
109
self.NameLabel.setText(self.__tr("Printer/Fax Name:"))
110
be_filter = ['hp', 'hpfax']
112
self.printers = device.getSupportedCUPSPrinters(be_filter)
113
self.printer_index.clear() # = {}
116
if self.initial_printer is None:
117
#user_conf.get('last_used', 'printer_name')
118
self.initial_printer = self.user_settings.last_used_printer
123
for i, p in enumerate(self.printers):
124
self.printer_index[p.name] = p.device_uri
125
self.ComboBox.insertItem(i, p.name)
127
if self.initial_printer is not None and to_unicode(p.name).lower() == to_unicode(self.initial_printer).lower():
128
self.initial_printer = None
131
self.ComboBox.setCurrentIndex(-1)
134
self.updating = False
136
self.ComboBox.setCurrentIndex(k)
138
self.emit(SIGNAL("PrinterNameComboBox_noPrinters"))
141
def ComboBox_currentIndexChanged(self, t):
142
self.printer_name = to_unicode(t)
147
self.device_uri = self.printer_index[self.printer_name]
148
#user_conf.set('last_used', 'printer_name', self.printer_name)
149
self.user_settings.last_used_printer = self.printer_name
150
self.user_settings.save()
152
self.emit(SIGNAL("PrinterNameComboBox_currentChanged"), self.device_uri, self.printer_name)
155
def __tr(self,s,c = None):
156
return qApp.translate("PrinterNameComboBox",s,c)