1# -*- coding: utf-8 -*- 2# 3# (c) Copyright 2001-2015 HP Development Company, L.P. 4# 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. 9# 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. 14# 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 18# 19# Authors: Don Welch 20# 21 22# Std Lib 23import operator 24import signal 25 26# Local 27from base.g import * 28from base import device, utils 29from prnt import cups 30from base.codes import * 31from .ui_utils import * 32 33# Qt 34from PyQt4.QtCore import * 35from PyQt4.QtGui import * 36 37# Ui 38from .firmwaredialog_base import Ui_Dialog 39 40 41class FirmwareDialog(QDialog, Ui_Dialog): 42 def __init__(self, parent, device_uri): 43 QDialog.__init__(self, parent) 44 self.setupUi(self) 45 self.device_uri = device_uri 46 self.initUi() 47 QTimer.singleShot(0, self.updateUi) 48 49 50 def initUi(self): 51 self.DeviceComboBox.setFilter({'fw-download' : (operator.gt, 0)}) 52 53 self.connect(self.DeviceComboBox, SIGNAL("DeviceUriComboBox_noDevices"), self.DeviceUriComboBox_noDevices) 54 self.connect(self.DeviceComboBox, SIGNAL("DeviceUriComboBox_currentChanged"), self.DeviceUriComboBox_currentChanged) 55 self.connect(self.CancelButton, SIGNAL("clicked()"), self.close) 56 self.connect(self.DownloadFirmwareButton, SIGNAL("clicked()"), self.downloadFirmware) 57 signal.signal(signal.SIGINT, signal.SIG_DFL) 58 59 # Application icon 60 self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128'))) 61 62 if self.device_uri: 63 self.DeviceComboBox.setInitialDevice(self.device_uri) 64 65 66 def updateUi(self): 67 self.DeviceComboBox.updateUi() 68 69 70 def DeviceUriComboBox_currentChanged(self, device_uri): 71 self.device_uri = device_uri 72 # Update 73 74 75 def DeviceUriComboBox_noDevices(self): 76 FailureUI(self, self.__tr("<b>No devices that support firmware download found.</b>")) 77 self.close() 78 79 80 def downloadFirmware(self): 81 d = None 82 83 try: 84 try: 85 d = device.Device(self.device_uri) 86 except Error: 87 CheckDeviceUI(self) 88 return 89 90 try: 91 d.open() 92 except Error: 93 CheckDeviceUI(self) 94 else: 95 if d.isIdleAndNoError(): 96 ok = d.downloadFirmware() 97 98 else: 99 CheckDeviceUI(self) 100 101 finally: 102 if d is not None: 103 d.close() 104 105 self.close() 106 107 108 def __tr(self,s,c = None): 109 return qApp.translate("FirmwareDialog",s,c) 110 111