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
26 from ui_utils import *
27 from base import device
30 from PyQt4.QtCore import *
31 from PyQt4.QtGui import *
34 DEVICEURICOMBOBOX_TYPE_PRINTER_ONLY = 0
35 DEVICEURICOMBOBOX_TYPE_FAX_ONLY = 1
36 DEVICEURICOMBOBOX_TYPE_PRINTER_AND_FAX = 2
39 class DeviceUriComboBox(QWidget):
40 def __init__(self, parent):
41 QWidget.__init__(self, parent)
43 self.initial_device = None
45 self.typ = DEVICEURICOMBOBOX_TYPE_PRINTER_ONLY
49 self.user_settings = UserSettings()
50 self.user_settings.load()
51 self.user_settings.debug()
57 HBoxLayout = QHBoxLayout(self)
58 HBoxLayout.setObjectName("HBoxLayout")
60 self.NameLabel = QLabel(self)
61 self.NameLabel.setObjectName("NameLabel")
62 HBoxLayout.addWidget(self.NameLabel)
64 SpacerItem = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Minimum)
65 HBoxLayout.addItem(SpacerItem)
67 self.ComboBox = QComboBox(self)
68 sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
69 sizePolicy.setHorizontalStretch(0)
70 sizePolicy.setVerticalStretch(0)
71 sizePolicy.setHeightForWidth(self.ComboBox.sizePolicy().hasHeightForWidth())
72 self.ComboBox.setSizePolicy(sizePolicy)
73 self.ComboBox.setObjectName("ComboBox")
74 HBoxLayout.addWidget(self.ComboBox)
76 self.NameLabel.setText(self.__tr("Device:"))
78 # self.connect(self.ComboBox, SIGNAL("currentIndexChanged(int)"),
79 # self.ComboBox_currentIndexChanged)
81 self.connect(self.ComboBox, SIGNAL("currentIndexChanged(const QString &)"),
82 self.ComboBox_currentIndexChanged)
85 def setType(self, typ):
86 if typ in (DEVICEURICOMBOBOX_TYPE_PRINTER_ONLY,
87 DEVICEURICOMBOBOX_TYPE_FAX_ONLY,
88 DEVICEURICOMBOBOX_TYPE_PRINTER_AND_FAX):
92 def setFilter(self, filter):
96 def setInitialDevice(self, device_uri):
97 self.initial_device = device_uri
100 def setDevices(self):
101 if self.typ == DEVICEURICOMBOBOX_TYPE_PRINTER_ONLY:
104 elif self.typ == DEVICEURICOMBOBOX_TYPE_FAX_ONLY:
105 be_filter = ['hpfax']
106 self.NameLabel.setText(self.__tr("Fax Device:"))
108 else: # DEVICEURICOMBOBOX_TYPE_PRINTER_AND_FAX
109 be_filter = ['hp', 'hpfax']
111 self.devices = device.getSupportedCUPSDevices(be_filter, self.filter)
112 return len(self.devices)
116 if self.devices is None:
119 self.device_index = {}
122 if self.initial_device is None:
123 #self.initial_device = user_conf.get('last_used', 'device_uri')
124 self.initial_device = self.user_settings.last_used_device_uri
129 for i, d in enumerate(self.devices):
130 self.ComboBox.insertItem(i, d)
132 if self.initial_device is not None and d == self.initial_device:
133 self.initial_device = None
136 self.ComboBox.setCurrentIndex(-1)
138 self.updating = False
140 self.ComboBox.setCurrentIndex(k)
142 if len(self.devices) == 1:
143 self.emit(SIGNAL("DeviceUriComboBox_oneDevice"))
146 self.emit(SIGNAL("DeviceUriComboBox_noDevices"))
149 def ComboBox_currentIndexChanged(self, t):
153 self.device_uri = unicode(t)
155 #user_conf.set('last_used', 'device_uri', self.device_uri)
156 self.user_settings.last_used_device_uri = self.device_uri
157 self.user_settings.save()
159 self.emit(SIGNAL("DeviceUriComboBox_currentChanged"), self.device_uri)
162 def __tr(self,s,c = None):
163 return qApp.translate("DeviceUriComboBox",s,c)