1 # -*- coding: utf-8 -*-
3 # (c) Copyright 2001-2008 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
28 from base import device, utils, pml
30 from base.codes import *
31 from ui_utils import *
34 from PyQt4.QtCore import *
35 from PyQt4.QtGui import *
38 from devicesetupdialog_base import Ui_Dialog
40 TAB_POWER_SETTINGS = 0
42 class DeviceSetupDialog(QDialog, Ui_Dialog):
43 def __init__(self, parent, device_uri):
44 QDialog.__init__(self, parent)
46 self.device_uri = device_uri
51 QTimer.singleShot(0, self.updateUi)
55 # connect signals/slots
56 self.connect(self.CancelButton, SIGNAL("clicked()"), self.CancelButton_clicked)
57 #self.connect(self.ApplyButton, SIGNAL("clicked()"), self.ApplyButton_clicked)
58 self.connect(self.DeviceComboBox, SIGNAL("DeviceUriComboBox_noDevices"), self.DeviceUriComboBox_noDevices)
59 self.connect(self.DeviceComboBox, SIGNAL("DeviceUriComboBox_currentChanged"),
60 self.DeviceUriComboBox_currentChanged)
62 self.DeviceComboBox.setFilter({'power-settings': (operator.gt, 0)})
65 self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
68 self.DeviceComboBox.setInitialDevice(self.device_uri)
70 self.DurationComboBox.addItem(self.__tr("15 minutes"), QVariant(15))
71 self.DurationComboBox.addItem(self.__tr("30 minutes"), QVariant(30))
72 self.DurationComboBox.addItem(self.__tr("45 minutes"), QVariant(45))
73 self.DurationComboBox.addItem(self.__tr("1 hour"), QVariant(60))
74 self.DurationComboBox.addItem(self.__tr("2 hours"), QVariant(120))
75 self.DurationComboBox.addItem(self.__tr("3 hours"), QVariant(180))
77 self.connect(self.DurationComboBox, SIGNAL("activated(int)"), self.DurationComboBox_activated)
79 self.connect(self.OnRadioButton, SIGNAL("toggled(bool)"), self.OnRadioButton_toggled)
82 def OnRadioButton_toggled(self, b):
83 i = self.DurationComboBox.currentIndex()
86 v, ok = self.DurationComboBox.itemData(i).toInt()
90 if self.power_settings == POWER_SETTINGS_EPML:
92 self.setPowerSettingsEPML('999')
94 self.setPowerSettingsEPML(string.zfill(v, 3))
96 elif self.power_settings == POWER_SETTINGS_PML:
98 self.setPowerSettingsPML(pml.OID_POWER_SETTINGS_NEVER)
100 self.setPowerSettingsPML(self.getPMLSettingsValue(v))
105 self.DeviceComboBox.updateUi()
108 def updatePowerSettingsUi(self):
112 def DeviceUriComboBox_currentChanged(self, device_uri):
115 self.device_uri = device_uri
117 if self.dev is not None:
120 self.dev = device.Device(self.device_uri)
123 self.mq = device.queryModelByURI(self.device_uri)
124 self.power_settings = self.mq.get('power-settings', POWER_SETTINGS_NONE)
126 self.TabWidget.setTabEnabled(TAB_POWER_SETTINGS, self.power_settings != POWER_SETTINGS_NONE)
128 if self.power_settings == POWER_SETTINGS_EPML:
129 self.updatePowerSettingsEPML()
131 elif self.power_settings == POWER_SETTINGS_PML:
132 self.updatePowerSettingsPML()
137 # DJ 4x0 battery power settings
147 def updatePowerSettingsEPML(self):
148 value = self.getPowerSettingsEPML()
151 self.OnRadioButton.setChecked(True)
152 self.OffRadioButton.setChecked(False)
154 self.OnRadioButton.setChecked(False)
155 self.OffRadioButton.setChecked(True)
158 index = self.DurationComboBox.findData(QVariant(find))
161 self.DurationComboBox.setCurrentIndex(index)
164 def getPowerSettingsEPML(self):
165 value = self.dev.getDynamicCounter(256, False)
166 log.debug("Current power settings: %s" % value)
167 self.dev.closePrint()
171 def setPowerSettingsEPML(self, value):
172 log.debug("Setting power setting to %s" % value)
174 """\x1b%%-12345X@PJL ENTER LANGUAGE=PCL3GUI\n\x1bE\x1b%%Pmech.set_battery_autooff %s;\nudw.quit;\x1b*rC\x1bE\x1b%%-12345X""" % value
175 self.dev.printData(pcl, direct=True)
176 self.dev.closePrint()
181 # OID_POWER_SETTINGS = ('1.1.2.118', TYPE_ENUMERATION)
182 # OID_POWER_SETTINGS_15MIN = 1
183 # OID_POWER_SETTINGS_30MIN = 2
184 # OID_POWER_SETTINGS_45MIN = 3
185 # OID_POWER_SETTINGS_1HR = 4
186 # OID_POWER_SETTINGS_2HR = 5
187 # OID_POWER_SETTINGS_3HR = 6
188 # OID_POWER_SETTINGS_NEVER = 999
190 def updatePowerSettingsPML(self):
191 value = self.getPowerSettingsPML()
192 if value == pml.OID_POWER_SETTINGS_NEVER:
193 self.OnRadioButton.setChecked(True)
194 self.OffRadioButton.setChecked(False)
196 self.OnRadioButton.setChecked(False)
197 self.OffRadioButton.setChecked(True)
200 if value == pml.OID_POWER_SETTINGS_15MIN:
202 elif value == pml.OID_POWER_SETTINGS_30MIN:
204 elif value == pml.OID_POWER_SETTINGS_45MIN:
206 elif value == pml.OID_POWER_SETTINGS_1HR:
208 elif value == pml.OID_POWER_SETTINGS_2HR:
210 elif value == pml.OID_POWER_SETTINGS_3HR:
213 index = self.DurationComboBox.findData(QVariant(find))
216 self.DurationComboBox.setCurrentIndex(index)
220 def getPowerSettingsPML(self):
221 pml_result_code, value = self.dev.getPML(pml.OID_POWER_SETTINGS)
223 log.debug("Current power settings: %s" % value)
227 def setPowerSettingsPML(self, value):
228 log.debug("Setting power setting to %s" % value)
229 pml_result_code = self.dev.setPML(pml.OID_POWER_SETTINGS, value)
232 # #####################
235 def DurationComboBox_activated(self, i):
238 v, ok = self.DurationComboBox.itemData(i).toInt()
241 if self.power_settings == POWER_SETTINGS_EPML:
244 self.setPowerSettingsEPML(string.zfill(v, 3))
248 elif self.power_settings == POWER_SETTINGS_PML:
251 self.setPowerSettingsPML(self.getPMLSettingsValue(v))
256 def getPMLSettingsValue(self, v):
257 x = pml.OID_POWER_SETTINGS_15MIN
260 x = pml.OID_POWER_SETTINGS_15MIN
262 x = pml.OID_POWER_SETTINGS_30MIN
264 x = pml.OID_POWER_SETTINGS_45MIN
266 x = pml.OID_POWER_SETTINGS_1HR
268 x = pml.OID_POWER_SETTINGS_2HR
270 x = pml.OID_POWER_SETTINGS_3HR
275 def DeviceUriComboBox_noDevices(self):
276 FailureUI(self, self.__tr("<b>No devices that support device setup found.</b>"))
280 def CancelButton_clicked(self):
281 if self.dev is not None:
287 # def ApplyButton_clicked(self):
294 def __tr(self,s,c = None):
295 return qApp.translate("DeviceSetupDialog",s,c)