/usr/share/hplip/ui4/infodialog.py is in hplip-data 3.14.3-0ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | # -*- coding: utf-8 -*-
#
# (c) Copyright 2001-2008 Hewlett-Packard Development Company, L.P.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Authors: Don Welch
#
# StdLib
import os.path
# Local
from base.g import *
from base import device, utils
from prnt import cups
from base.codes import *
from ui_utils import *
# Qt
from PyQt4.QtCore import *
from PyQt4.QtGui import *
# Ui
from infodialog_base import Ui_Dialog
from deviceuricombobox import DEVICEURICOMBOBOX_TYPE_PRINTER_AND_FAX
class InfoDialog(QDialog, Ui_Dialog):
def __init__(self, parent, device_uri):
QDialog.__init__(self, parent)
self.device_uri = device_uri
#self.tabs = []
self.setupUi(self)
self.initUi()
QTimer.singleShot(0, self.updateUi)
def initUi(self):
# connect signals/slots
self.connect(self.CancelButton, SIGNAL("clicked()"), self.CancelButton_clicked)
self.connect(self.DeviceComboBox, SIGNAL("DeviceUriComboBox_noDevices"), self.DeviceUriComboBox_noDevices)
self.connect(self.DeviceComboBox, SIGNAL("DeviceUriComboBox_currentChanged"), self.DeviceUriComboBox_currentChanged)
# Application icon
self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
if self.device_uri:
self.DeviceComboBox.setInitialDevice(self.device_uri)
self.DeviceComboBox.setType(DEVICEURICOMBOBOX_TYPE_PRINTER_AND_FAX)
self.headers = [self.__tr("Key"), self.__tr("Value")]
self.history_headers = [self.__tr("Date/Time"), None,
self.__tr("Event Code"), self.__tr("Description"),
self.__tr("User"), self.__tr("CUPS Job ID"),
self.__tr("Doc. Title")]
def updateUi(self):
self.DeviceComboBox.updateUi()
#self.updateInfoTable()
def updateInfoTable(self):
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
self.DynamicTableWidget.clear()
self.DynamicTableWidget.setRowCount(0)
self.DynamicTableWidget.setColumnCount(0)
flags = Qt.ItemIsSelectable | Qt.ItemIsEnabled
while self.TabWidget.count() > 3:
self.TabWidget.removeTab(3)
self.DynamicTableWidget.clear()
self.DynamicTableWidget.setRowCount(0)
self.DynamicTableWidget.setColumnCount(len(self.headers))
self.DynamicTableWidget.setHorizontalHeaderLabels(self.headers)
#
# Static Data
#
try:
d = device.Device(self.device_uri, None)
except Error:
QApplication.restoreOverrideCursor()
FailureUI(self, self.__tr("<b>Unable to open device %1.</b>").arg(self.device_uri))
#self.close()
return
self.StaticTableWidget.clear()
self.StaticTableWidget.setColumnCount(len(self.headers))
self.StaticTableWidget.setHorizontalHeaderLabels(self.headers)
mq_keys = d.mq.keys()
mq_keys.sort()
self.StaticTableWidget.setRowCount(len(mq_keys))
for row, key in enumerate(mq_keys):
i = QTableWidgetItem(QString(key))
i.setFlags(flags)
self.StaticTableWidget.setItem(row, 0, i)
i = QTableWidgetItem(QString(str(d.mq[key])))
i.setFlags(flags)
self.StaticTableWidget.setItem(row, 1, i)
self.StaticTableWidget.resizeColumnToContents(0)
self.StaticTableWidget.resizeColumnToContents(1)
self.StaticTableWidget.setSortingEnabled(True)
self.StaticTableWidget.sortItems(0)
#
# Dynamic Data
#
try:
try:
d.open()
d.queryDevice()
except Error, e:
QApplication.restoreOverrideCursor()
FailureUI(self, self.__tr("<b>Unable to open device %1.</b>").arg(self.device_uri))
#self.close()
return
dq_keys = d.dq.keys()
dq_keys.sort()
self.DynamicTableWidget.setRowCount(len(dq_keys))
for row, key in enumerate(dq_keys):
i = QTableWidgetItem(QString(key))
i.setFlags(flags)
self.DynamicTableWidget.setItem(row, 0, i)
i = QTableWidgetItem(QString(str(d.dq[key])))
i.setFlags(flags)
self.DynamicTableWidget.setItem(row, 1, i)
self.DynamicTableWidget.resizeColumnToContents(0)
self.DynamicTableWidget.resizeColumnToContents(1)
self.DynamicTableWidget.setSortingEnabled(True)
self.DynamicTableWidget.sortItems(0)
finally:
d.close()
#
# History Table
#
self.HistoryTableWidget.clear()
self.HistoryTableWidget.setRowCount(0)
if d.device_type == DEVICE_TYPE_FAX:
self.history_headers[1] = self.__tr("Fax")
else:
self.history_headers[1] = self.__tr("Printer")
self.HistoryTableWidget.setColumnCount(len(self.history_headers))
self.HistoryTableWidget.setHorizontalHeaderLabels(self.history_headers)
history = d.queryHistory()
history.reverse()
self.HistoryTableWidget.setRowCount(len(history))
for row, h in enumerate(history):
dt = QDateTime()
dt.setTime_t(int(h.timedate))
dt = dt.toString()
ess = device.queryString(h.event_code, 0)
for col, t in enumerate([dt, h.printer_name,
unicode(h.event_code), ess,
h.username, unicode(h.job_id),
h.title]):
i = QTableWidgetItem(QString(t))
i.setFlags(flags)
self.HistoryTableWidget.setItem(row, col, i)
self.HistoryTableWidget.resizeColumnToContents(0)
self.HistoryTableWidget.resizeColumnToContents(1)
self.HistoryTableWidget.setSortingEnabled(True)
self.HistoryTableWidget.sortItems(0)
#
# Printer Data
#
printers = cups.getPrinters()
for p in printers:
if p.device_uri == self.device_uri:
Tab = QWidget()
Tab.setObjectName(QString(p.name))
GridLayout = QGridLayout(Tab)
GridLayout.setObjectName(QString("GridLayout-%s" % p.name))
Table = QTableWidget(Tab)
Table.setAlternatingRowColors(True)
Table.setSelectionMode(QAbstractItemView.SingleSelection)
Table.setSelectionBehavior(QAbstractItemView.SelectRows)
Table.setVerticalScrollMode(QAbstractItemView.ScrollPerItem)
Table.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)
Table.setGridStyle(Qt.DotLine)
Table.setObjectName(QString("Table-%s" % p.name))
GridLayout.addWidget(Table, 0, 0, 1, 1)
self.TabWidget.addTab(Tab, QString(p.name))
Table.setColumnCount(len(self.headers))
Table.setHorizontalHeaderLabels(self.headers)
cups.resetOptions()
cups.openPPD(p.name)
current_options = dict(cups.getOptions())
#current_options['cups_error_log_level'] = cups.getErrorLogLevel()
try:
f = file(os.path.expanduser('~/.cups/lpoptions'))
except IOError, e:
log.debug(str(e))
current_options['lpoptions_file_data'] = QString("(%1)").arg(str(e))
else:
text = f.read()
for d in text.splitlines():
if p.name in d:
current_options['lpoptions_file_data'] = d
break
else:
current_options['lpoptions_file_data'] = self.__tr("(no data)")
keys = current_options.keys()
keys.sort()
Table.setRowCount(len(keys))
for row, key in enumerate(keys):
i = QTableWidgetItem(QString(key))
i.setFlags(flags)
Table.setItem(row, 0, i)
if key == 'printer-state':
state = int(current_options[key])
if state == cups.IPP_PRINTER_STATE_IDLE:
i = QTableWidgetItem(self.__tr("idle (%1)").arg(state))
elif state == cups.IPP_PRINTER_STATE_PROCESSING:
i = QTableWidgetItem(self.__tr("busy/printing (%1)").arg(state))
elif state == cups.IPP_PRINTER_STATE_STOPPED:
i = QTableWidgetItem(self.__tr("stopped (%1)").arg(state))
else:
i = QTableWidgetItem(QString(str(state)))
else:
i = QTableWidgetItem(QString(str(current_options[key])))
i.setFlags(flags)
Table.setItem(row, 1, i)
Table.resizeColumnToContents(0)
Table.resizeColumnToContents(1)
Table.setSortingEnabled(True)
Table.sortItems(0)
cups.closePPD()
self.TabWidget.setCurrentIndex(0)
QApplication.restoreOverrideCursor()
def DeviceUriComboBox_currentChanged(self, device_uri):
self.device_uri = device_uri
self.updateInfoTable()
def DeviceUriComboBox_noDevices(self):
FailureUI(self, self.__tr("<b>No devices found.</b>"))
self.close()
def CancelButton_clicked(self):
self.close()
#
# Misc
#
def __tr(self,s,c = None):
return qApp.translate("InfoDialog",s,c)
|