| 1 |
#!/usr/bin/python3 |
| 2 |
|
| 3 |
## system-config-printer |
| 4 |
|
| 5 |
## Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Red Hat, Inc. |
| 6 |
## Authors: |
| 7 |
## Tim Waugh <[email protected]> |
| 8 |
## Florian Festi <[email protected]> |
| 9 |
|
| 10 |
## This program is free software; you can redistribute it and/or modify |
| 11 |
## it under the terms of the GNU General Public License as published by |
| 12 |
## the Free Software Foundation; either version 2 of the License, or |
| 13 |
## (at your option) any later version. |
| 14 |
|
| 15 |
## This program is distributed in the hope that it will be useful, |
| 16 |
## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
## GNU General Public License for more details. |
| 19 |
|
| 20 |
## You should have received a copy of the GNU General Public License |
| 21 |
## along with this program; if not, write to the Free Software |
| 22 |
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 23 |
|
| 24 |
# config is generated from config.py.in by configure |
| 25 |
import config |
| 26 |
|
| 27 |
import os, tempfile |
| 28 |
from gi.repository import Gtk |
| 29 |
import cups |
| 30 |
import locale |
| 31 |
import gettext |
| 32 |
gettext.install(domain=config.PACKAGE, localedir=config.localedir) |
| 33 |
|
| 34 |
import cupshelpers, options |
| 35 |
from gi.repository import GObject |
| 36 |
from gi.repository import GLib |
| 37 |
from gui import GtkGUI |
| 38 |
import html # requires python3.2 |
| 39 |
from optionwidgets import OptionWidget |
| 40 |
from debug import * |
| 41 |
import authconn |
| 42 |
from errordialogs import * |
| 43 |
import gtkinklevel |
| 44 |
import ppdcache |
| 45 |
import statereason |
| 46 |
import monitor |
| 47 |
import newprinter |
| 48 |
from newprinter import busy, ready |
| 49 |
|
| 50 |
import ppdippstr |
| 51 |
pkgdata = config.pkgdatadir |
| 52 |
|
| 53 |
def CUPS_server_hostname (): |
| 54 |
host = cups.getServer () |
| 55 |
if host[0] == '/': |
| 56 |
return 'localhost' |
| 57 |
return host |
| 58 |
|
| 59 |
def on_delete_just_hide (widget, event): |
| 60 |
widget.hide () |
| 61 |
return True # stop other handlers |
| 62 |
|
| 63 |
class PrinterPropertiesDialog(GtkGUI): |
| 64 |
|
| 65 |
__gsignals__ = { |
| 66 |
'destroy': ( GObject.SignalFlags.RUN_LAST, None, ()), |
| 67 |
'dialog-closed': ( GObject.SignalFlags.RUN_LAST, None, ()), |
| 68 |
} |
| 69 |
|
| 70 |
printer_states = { cups.IPP_PRINTER_IDLE: |
| 71 |
_("Idle"), |
| 72 |
cups.IPP_PRINTER_PROCESSING: |
| 73 |
_("Processing"), |
| 74 |
cups.IPP_PRINTER_BUSY: |
| 75 |
_("Busy"), |
| 76 |
cups.IPP_PRINTER_STOPPED: |
| 77 |
_("Stopped") } |
| 78 |
|
| 79 |
def __init__(self): |
| 80 |
GObject.GObject.__init__ (self) |
| 81 |
|
| 82 |
try: |
| 83 |
self.language = locale.getlocale(locale.LC_MESSAGES) |
| 84 |
self.encoding = locale.getlocale(locale.LC_CTYPE) |
| 85 |
except: |
| 86 |
nonfatalException() |
| 87 |
os.environ['LC_ALL'] = 'C' |
| 88 |
locale.setlocale (locale.LC_ALL, "") |
| 89 |
self.language = locale.getlocale(locale.LC_MESSAGES) |
| 90 |
self.encoding = locale.getlocale(locale.LC_CTYPE) |
| 91 |
|
| 92 |
self.parent = None |
| 93 |
self.printer = self.ppd = None |
| 94 |
self.conflicts = set() # of options |
| 95 |
self.changed = set() # of options |
| 96 |
self.signal_ids = dict() |
| 97 |
|
| 98 |
# WIDGETS |
| 99 |
# ======= |
| 100 |
self.updating_widgets = False |
| 101 |
self.getWidgets({"PrinterPropertiesDialog": |
| 102 |
["PrinterPropertiesDialog", |
| 103 |
"tvPrinterProperties", |
| 104 |
"btnPrinterPropertiesCancel", |
| 105 |
"btnPrinterPropertiesOK", |
| 106 |
"btnPrinterPropertiesApply", |
| 107 |
"btnPrinterPropertiesClose", |
| 108 |
"ntbkPrinter", |
| 109 |
"entPDescription", |
| 110 |
"entPLocation", |
| 111 |
"entPMakeModel", |
| 112 |
"lblPMakeModel2", |
| 113 |
"entPState", |
| 114 |
"entPDevice", |
| 115 |
"lblPDevice2", |
| 116 |
"btnSelectDevice", |
| 117 |
"btnChangePPD", |
| 118 |
"chkPEnabled", |
| 119 |
"chkPAccepting", |
| 120 |
"chkPShared", |
| 121 |
"lblNotPublished", |
| 122 |
"btnPrintTestPage", |
| 123 |
"btnSelfTest", |
| 124 |
"btnCleanHeads", |
| 125 |
"btnConflict", |
| 126 |
|
| 127 |
"cmbPStartBanner", |
| 128 |
"cmbPEndBanner", |
| 129 |
"cmbPErrorPolicy", |
| 130 |
"cmbPOperationPolicy", |
| 131 |
|
| 132 |
"rbtnPAllow", |
| 133 |
"rbtnPDeny", |
| 134 |
"tvPUsers", |
| 135 |
"entPUser", |
| 136 |
"btnPAddUser", |
| 137 |
"btnPDelUser", |
| 138 |
|
| 139 |
"lblPInstallOptions", |
| 140 |
"swPInstallOptions", |
| 141 |
"vbPInstallOptions", |
| 142 |
"swPOptions", |
| 143 |
"lblPOptions", |
| 144 |
"vbPOptions", |
| 145 |
"vbClassMembers", |
| 146 |
"lblClassMembers", |
| 147 |
"tvClassMembers", |
| 148 |
"tvClassNotMembers", |
| 149 |
"btnClassAddMember", |
| 150 |
"btnClassDelMember", |
| 151 |
"btnRefreshMarkerLevels", |
| 152 |
"tvPrinterStateReasons", |
| 153 |
"ntbkPrinterStateReasons", |
| 154 |
|
| 155 |
# Job options |
| 156 |
"sbJOCopies", "btnJOResetCopies", |
| 157 |
"cmbJOOrientationRequested", "btnJOResetOrientationRequested", |
| 158 |
"cbJOFitplot", "btnJOResetFitplot", |
| 159 |
"cmbJONumberUp", "btnJOResetNumberUp", |
| 160 |
"cmbJONumberUpLayout", "btnJOResetNumberUpLayout", |
| 161 |
"sbJOBrightness", "btnJOResetBrightness", |
| 162 |
"cmbJOFinishings", "btnJOResetFinishings", |
| 163 |
"sbJOJobPriority", "btnJOResetJobPriority", |
| 164 |
"cmbJOMedia", "btnJOResetMedia", |
| 165 |
"cmbJOSides", "btnJOResetSides", |
| 166 |
"cmbJOHoldUntil", "btnJOResetHoldUntil", |
| 167 |
"cmbJOOutputOrder", "btnJOResetOutputOrder", |
| 168 |
"cmbJOPrintQuality", "btnJOResetPrintQuality", |
| 169 |
"cmbJOPrinterResolution", |
| 170 |
"btnJOResetPrinterResolution", |
| 171 |
"cmbJOOutputBin", "btnJOResetOutputBin", |
| 172 |
"cbJOMirror", "btnJOResetMirror", |
| 173 |
"sbJOScaling", "btnJOResetScaling", |
| 174 |
"sbJOSaturation", "btnJOResetSaturation", |
| 175 |
"sbJOHue", "btnJOResetHue", |
| 176 |
"sbJOGamma", "btnJOResetGamma", |
| 177 |
"sbJOCpi", "btnJOResetCpi", |
| 178 |
"sbJOLpi", "btnJOResetLpi", |
| 179 |
"sbJOPageLeft", "btnJOResetPageLeft", |
| 180 |
"sbJOPageRight", "btnJOResetPageRight", |
| 181 |
"sbJOPageTop", "btnJOResetPageTop", |
| 182 |
"sbJOPageBottom", "btnJOResetPageBottom", |
| 183 |
"cbJOPrettyPrint", "btnJOResetPrettyPrint", |
| 184 |
"cbJOWrap", "btnJOResetWrap", |
| 185 |
"sbJOColumns", "btnJOResetColumns", |
| 186 |
"tblJOOther", |
| 187 |
"entNewJobOption", "btnNewJobOption", |
| 188 |
|
| 189 |
# Marker levels |
| 190 |
"vboxMarkerLevels", |
| 191 |
"btnRefreshMarkerLevels"]}, |
| 192 |
|
| 193 |
domain=config.PACKAGE) |
| 194 |
|
| 195 |
|
| 196 |
self.dialog = self.PrinterPropertiesDialog |
| 197 |
|
| 198 |
# Don't let delete-event destroy the dialog. |
| 199 |
self.dialog.connect ("delete-event", self.on_delete) |
| 200 |
|
| 201 |
# Printer properties combo boxes |
| 202 |
for combobox in [self.cmbPStartBanner, |
| 203 |
self.cmbPEndBanner, |
| 204 |
self.cmbPErrorPolicy, |
| 205 |
self.cmbPOperationPolicy]: |
| 206 |
cell = Gtk.CellRendererText () |
| 207 |
combobox.clear () |
| 208 |
combobox.pack_start (cell, True) |
| 209 |
combobox.add_attribute (cell, 'text', 0) |
| 210 |
|
| 211 |
btn = self.btnRefreshMarkerLevels |
| 212 |
btn.connect ("clicked", self.on_btnRefreshMarkerLevels_clicked) |
| 213 |
|
| 214 |
# Printer state reasons list |
| 215 |
column = Gtk.TreeViewColumn (_("Message")) |
| 216 |
icon = Gtk.CellRendererPixbuf () |
| 217 |
column.pack_start (icon, False) |
| 218 |
text = Gtk.CellRendererText () |
| 219 |
column.pack_start (text, False) |
| 220 |
column.set_cell_data_func (icon, self.set_printer_state_reason_icon, None) |
| 221 |
column.set_cell_data_func (text, self.set_printer_state_reason_text, None) |
| 222 |
column.set_resizable (True) |
| 223 |
self.tvPrinterStateReasons.append_column (column) |
| 224 |
selection = self.tvPrinterStateReasons.get_selection () |
| 225 |
selection.set_mode (Gtk.SelectionMode.NONE) |
| 226 |
store = Gtk.ListStore (int, str) |
| 227 |
self.tvPrinterStateReasons.set_model (store) |
| 228 |
self.PrinterPropertiesDialog.connect ("delete-event", |
| 229 |
on_delete_just_hide) |
| 230 |
|
| 231 |
self.static_tabs = 3 |
| 232 |
|
| 233 |
# setup some lists |
| 234 |
for name, treeview in ( |
| 235 |
(_("Members of this class"), self.tvClassMembers), |
| 236 |
(_("Others"), self.tvClassNotMembers), |
| 237 |
(_("Users"), self.tvPUsers), |
| 238 |
): |
| 239 |
|
| 240 |
model = Gtk.ListStore(str) |
| 241 |
cell = Gtk.CellRendererText() |
| 242 |
column = Gtk.TreeViewColumn(name, cell, text=0) |
| 243 |
treeview.set_model(model) |
| 244 |
treeview.append_column(column) |
| 245 |
treeview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE) |
| 246 |
|
| 247 |
# Printer Properties dialog |
| 248 |
self.dialog.connect ('response', self.printer_properties_response) |
| 249 |
|
| 250 |
# Printer Properties tree view |
| 251 |
col = Gtk.TreeViewColumn ('', Gtk.CellRendererText (), markup=0) |
| 252 |
self.tvPrinterProperties.append_column (col) |
| 253 |
sel = self.tvPrinterProperties.get_selection () |
| 254 |
sel.connect ('changed', self.on_tvPrinterProperties_selection_changed) |
| 255 |
sel.set_mode (Gtk.SelectionMode.SINGLE) |
| 256 |
|
| 257 |
# Job Options widgets. |
| 258 |
for (widget, |
| 259 |
opts) in [(self.cmbJOOrientationRequested, |
| 260 |
[[_("Portrait (no rotation)")], |
| 261 |
[_("Landscape (90 degrees)")], |
| 262 |
[_("Reverse landscape (270 degrees)")], |
| 263 |
[_("Reverse portrait (180 degrees)")]]), |
| 264 |
|
| 265 |
(self.cmbJONumberUp, |
| 266 |
[["1"], ["2"], ["4"], ["6"], ["9"], ["16"]]), |
| 267 |
|
| 268 |
(self.cmbJONumberUpLayout, |
| 269 |
[[_("Left to right, top to bottom")], |
| 270 |
[_("Left to right, bottom to top")], |
| 271 |
[_("Right to left, top to bottom")], |
| 272 |
[_("Right to left, bottom to top")], |
| 273 |
[_("Top to bottom, left to right")], |
| 274 |
[_("Top to bottom, right to left")], |
| 275 |
[_("Bottom to top, left to right")], |
| 276 |
[_("Bottom to top, right to left")]]), |
| 277 |
|
| 278 |
(self.cmbJOFinishings, |
| 279 |
# See section 4.2.6 of this document for explanation of finishing types: |
| 280 |
# ftp://ftp.pwg.org/pub/pwg/candidates/cs-ippfinishings10-20010205-5100.1.pdf |
| 281 |
[[_("None")], |
| 282 |
[_("Staple")], |
| 283 |
[_("Punch")], |
| 284 |
[_("Cover")], |
| 285 |
[_("Bind")], |
| 286 |
[_("Saddle stitch")], |
| 287 |
[_("Edge stitch")], |
| 288 |
[_("Fold")], |
| 289 |
[_("Trim")], |
| 290 |
[_("Bale")], |
| 291 |
[_("Booklet maker")], |
| 292 |
[_("Job offset")], |
| 293 |
[_("Staple (top left)")], |
| 294 |
[_("Staple (bottom left)")], |
| 295 |
[_("Staple (top right)")], |
| 296 |
[_("Staple (bottom right)")], |
| 297 |
[_("Edge stitch (left)")], |
| 298 |
[_("Edge stitch (top)")], |
| 299 |
[_("Edge stitch (right)")], |
| 300 |
[_("Edge stitch (bottom)")], |
| 301 |
[_("Staple dual (left)")], |
| 302 |
[_("Staple dual (top)")], |
| 303 |
[_("Staple dual (right)")], |
| 304 |
[_("Staple dual (bottom)")], |
| 305 |
[_("Bind (left)")], |
| 306 |
[_("Bind (top)")], |
| 307 |
[_("Bind (right)")], |
| 308 |
[_("Bind (bottom)")]]), |
| 309 |
|
| 310 |
(self.cmbJOMedia, []), |
| 311 |
|
| 312 |
(self.cmbJOSides, |
| 313 |
[[_("One-sided")], |
| 314 |
[_("Two-sided (long edge)")], |
| 315 |
[_("Two-sided (short edge)")]]), |
| 316 |
|
| 317 |
(self.cmbJOHoldUntil, []), |
| 318 |
|
| 319 |
(self.cmbJOOutputOrder, |
| 320 |
[[_("Normal")], |
| 321 |
[_("Reverse")]]), |
| 322 |
|
| 323 |
(self.cmbJOPrintQuality, |
| 324 |
[[_("Draft")], |
| 325 |
[_("Normal")], |
| 326 |
[_("High")]]), |
| 327 |
|
| 328 |
(self.cmbJOOutputBin, []), |
| 329 |
]: |
| 330 |
model = Gtk.ListStore (str) |
| 331 |
for row in opts: |
| 332 |
model.append (row=row) |
| 333 |
|
| 334 |
cell = Gtk.CellRendererText () |
| 335 |
widget.pack_start (cell, True) |
| 336 |
widget.add_attribute (cell, 'text', 0) |
| 337 |
widget.set_model (model) |
| 338 |
|
| 339 |
opts = [ options.OptionAlwaysShown ("copies", int, 1, |
| 340 |
self.sbJOCopies, |
| 341 |
self.btnJOResetCopies), |
| 342 |
|
| 343 |
options.OptionAlwaysShownSpecial \ |
| 344 |
("orientation-requested", int, 3, |
| 345 |
self.cmbJOOrientationRequested, |
| 346 |
self.btnJOResetOrientationRequested, |
| 347 |
combobox_map = [3, 4, 5, 6], |
| 348 |
special_choice=_("Automatic rotation")), |
| 349 |
|
| 350 |
options.OptionAlwaysShown ("fitplot", bool, False, |
| 351 |
self.cbJOFitplot, |
| 352 |
self.btnJOResetFitplot), |
| 353 |
|
| 354 |
options.OptionAlwaysShown ("number-up", int, 1, |
| 355 |
self.cmbJONumberUp, |
| 356 |
self.btnJOResetNumberUp, |
| 357 |
combobox_map=[1, 2, 4, 6, 9, 16], |
| 358 |
use_supported = True), |
| 359 |
|
| 360 |
options.OptionAlwaysShown ("number-up-layout", str, "lrtb", |
| 361 |
self.cmbJONumberUpLayout, |
| 362 |
self.btnJOResetNumberUpLayout, |
| 363 |
combobox_map = [ "lrtb", |
| 364 |
"lrbt", |
| 365 |
"rltb", |
| 366 |
"rlbt", |
| 367 |
"tblr", |
| 368 |
"tbrl", |
| 369 |
"btlr", |
| 370 |
"btrl" ]), |
| 371 |
|
| 372 |
options.OptionAlwaysShown ("brightness", int, 100, |
| 373 |
self.sbJOBrightness, |
| 374 |
self.btnJOResetBrightness), |
| 375 |
|
| 376 |
options.OptionAlwaysShown ("finishings", int, 3, |
| 377 |
self.cmbJOFinishings, |
| 378 |
self.btnJOResetFinishings, |
| 379 |
combobox_map = [ 3, 4, 5, 6, |
| 380 |
7, 8, 9, 10, |
| 381 |
11, 12, 13, 14, |
| 382 |
20, 21, 22, 23, |
| 383 |
24, 25, 26, 27, |
| 384 |
28, 29, 30, 31, |
| 385 |
50, 51, 52, 53 ], |
| 386 |
use_supported = True), |
| 387 |
|
| 388 |
options.OptionAlwaysShown ("job-priority", int, 50, |
| 389 |
self.sbJOJobPriority, |
| 390 |
self.btnJOResetJobPriority), |
| 391 |
|
| 392 |
options.OptionAlwaysShown ("media", str, |
| 393 |
"A4", # This is the default for |
| 394 |
# when media-default is |
| 395 |
# not supplied by the IPP |
| 396 |
# server. Fortunately it |
| 397 |
# is a mandatory attribute. |
| 398 |
self.cmbJOMedia, |
| 399 |
self.btnJOResetMedia, |
| 400 |
use_supported = True), |
| 401 |
|
| 402 |
options.OptionAlwaysShown ("sides", str, "one-sided", |
| 403 |
self.cmbJOSides, |
| 404 |
self.btnJOResetSides, |
| 405 |
combobox_map = |
| 406 |
[ "one-sided", |
| 407 |
"two-sided-long-edge", |
| 408 |
"two-sided-short-edge" ], |
| 409 |
use_supported = True), |
| 410 |
|
| 411 |
options.OptionAlwaysShown ("job-hold-until", str, |
| 412 |
"no-hold", |
| 413 |
self.cmbJOHoldUntil, |
| 414 |
self.btnJOResetHoldUntil, |
| 415 |
use_supported = True), |
| 416 |
|
| 417 |
options.OptionAlwaysShown ("outputorder", str, |
| 418 |
"normal", |
| 419 |
self.cmbJOOutputOrder, |
| 420 |
self.btnJOResetOutputOrder, |
| 421 |
combobox_map = |
| 422 |
[ "normal", |
| 423 |
"reverse" ]), |
| 424 |
|
| 425 |
options.OptionAlwaysShown ("print-quality", int, 3, |
| 426 |
self.cmbJOPrintQuality, |
| 427 |
self.btnJOResetPrintQuality, |
| 428 |
combobox_map = [ 3, 4, 5 ], |
| 429 |
use_supported = True), |
| 430 |
|
| 431 |
options.OptionAlwaysShown ("printer-resolution", |
| 432 |
options.IPPResolution, |
| 433 |
options.IPPResolution((300,300,3)), |
| 434 |
self.cmbJOPrinterResolution, |
| 435 |
self.btnJOResetPrinterResolution, |
| 436 |
use_supported = True), |
| 437 |
|
| 438 |
options.OptionAlwaysShown ("output-bin", str, |
| 439 |
"face-up", |
| 440 |
self.cmbJOOutputBin, |
| 441 |
self.btnJOResetOutputBin, |
| 442 |
use_supported = True), |
| 443 |
|
| 444 |
options.OptionAlwaysShown ("mirror", bool, False, |
| 445 |
self.cbJOMirror, |
| 446 |
self.btnJOResetMirror), |
| 447 |
|
| 448 |
options.OptionAlwaysShown ("scaling", int, 100, |
| 449 |
self.sbJOScaling, |
| 450 |
self.btnJOResetScaling), |
| 451 |
|
| 452 |
options.OptionAlwaysShown ("saturation", int, 100, |
| 453 |
self.sbJOSaturation, |
| 454 |
self.btnJOResetSaturation), |
| 455 |
|
| 456 |
options.OptionAlwaysShown ("hue", int, 0, |
| 457 |
self.sbJOHue, |
| 458 |
self.btnJOResetHue), |
| 459 |
|
| 460 |
options.OptionAlwaysShown ("gamma", int, 1000, |
| 461 |
self.sbJOGamma, |
| 462 |
self.btnJOResetGamma), |
| 463 |
|
| 464 |
options.OptionAlwaysShown ("cpi", float, 10.0, |
| 465 |
self.sbJOCpi, self.btnJOResetCpi), |
| 466 |
|
| 467 |
options.OptionAlwaysShown ("lpi", float, 6.0, |
| 468 |
self.sbJOLpi, self.btnJOResetLpi), |
| 469 |
|
| 470 |
options.OptionAlwaysShown ("page-left", int, 0, |
| 471 |
self.sbJOPageLeft, |
| 472 |
self.btnJOResetPageLeft), |
| 473 |
|
| 474 |
options.OptionAlwaysShown ("page-right", int, 0, |
| 475 |
self.sbJOPageRight, |
| 476 |
self.btnJOResetPageRight), |
| 477 |
|
| 478 |
options.OptionAlwaysShown ("page-top", int, 0, |
| 479 |
self.sbJOPageTop, |
| 480 |
self.btnJOResetPageTop), |
| 481 |
|
| 482 |
options.OptionAlwaysShown ("page-bottom", int, 0, |
| 483 |
self.sbJOPageBottom, |
| 484 |
self.btnJOResetPageBottom), |
| 485 |
|
| 486 |
options.OptionAlwaysShown ("prettyprint", bool, False, |
| 487 |
self.cbJOPrettyPrint, |
| 488 |
self.btnJOResetPrettyPrint), |
| 489 |
|
| 490 |
options.OptionAlwaysShown ("wrap", bool, False, self.cbJOWrap, |
| 491 |
self.btnJOResetWrap), |
| 492 |
|
| 493 |
options.OptionAlwaysShown ("columns", int, 1, |
| 494 |
self.sbJOColumns, |
| 495 |
self.btnJOResetColumns), |
| 496 |
] |
| 497 |
self.job_options_widgets = {} |
| 498 |
self.job_options_buttons = {} |
| 499 |
for option in opts: |
| 500 |
self.job_options_widgets[option.widget] = option |
| 501 |
self.job_options_buttons[option.button] = option |
| 502 |
|
| 503 |
self._monitor = None |
| 504 |
self._ppdcache = None |
| 505 |
self.connect_signals () |
| 506 |
debugprint ("+%s" % self) |
| 507 |
|
| 508 |
def __del__ (self): |
| 509 |
debugprint ("-%s" % self) |
| 510 |
del self._monitor |
| 511 |
|
| 512 |
def _connect (self, collection, obj, name, handler): |
| 513 |
c = self.signal_ids.get (collection, []) |
| 514 |
c.append ((obj, obj.connect (name, handler))) |
| 515 |
self.signal_ids[collection] = c |
| 516 |
|
| 517 |
def _disconnect (self, collection=None): |
| 518 |
if collection: |
| 519 |
collection = [collection] |
| 520 |
else: |
| 521 |
collection = list(self.signal_ids.keys ()) |
| 522 |
|
| 523 |
for coll in collection: |
| 524 |
if coll in self.signal_ids: |
| 525 |
for (obj, signal_id) in self.signal_ids[coll]: |
| 526 |
obj.disconnect (signal_id) |
| 527 |
|
| 528 |
del self.signal_ids[coll] |
| 529 |
|
| 530 |
def do_destroy (self): |
| 531 |
if self.PrinterPropertiesDialog: |
| 532 |
self.PrinterPropertiesDialog.destroy () |
| 533 |
self.PrinterPropertiesDialog = None |
| 534 |
|
| 535 |
def destroy (self): |
| 536 |
debugprint ("DESTROY: %s" % self) |
| 537 |
self._disconnect () |
| 538 |
self.ppd = None |
| 539 |
self.ppd_local = None |
| 540 |
self.printer = None |
| 541 |
self.emit ('destroy') |
| 542 |
|
| 543 |
def set_monitor (self, monitor): |
| 544 |
self._monitor = monitor |
| 545 |
if not monitor: |
| 546 |
return |
| 547 |
|
| 548 |
self._monitor.connect ('printer-event', self.on_printer_event) |
| 549 |
self._monitor.connect ('printer-removed', self.on_printer_removed) |
| 550 |
self._monitor.connect ('state-reason-added', self.on_state_reason_added) |
| 551 |
self._monitor.connect ('state-reason-removed', |
| 552 |
self.on_state_reason_removed) |
| 553 |
self._monitor.connect ('cups-connection-error', |
| 554 |
self.on_cups_connection_error) |
| 555 |
|
| 556 |
def show (self, name, host=None, encryption=None, parent=None): |
| 557 |
self.parent = parent |
| 558 |
self._host = host |
| 559 |
self._encryption = encryption |
| 560 |
if not host: |
| 561 |
self._host = cups.getServer() |
| 562 |
if not encryption: |
| 563 |
self._encryption = cups.getEncryption () |
| 564 |
|
| 565 |
if self._monitor is None: |
| 566 |
self.set_monitor (monitor.Monitor (monitor_jobs=False)) |
| 567 |
|
| 568 |
self._ppdcache = self._monitor.get_ppdcache () |
| 569 |
|
| 570 |
self._disconnect ("newPrinterGUI") |
| 571 |
self.newPrinterGUI = newprinter.NewPrinterGUI () |
| 572 |
self._connect ("newPrinterGUI", self.newPrinterGUI, |
| 573 |
"printer-modified", self.on_printer_modified) |
| 574 |
self._connect ("newPrinterGUI", self.newPrinterGUI, |
| 575 |
"dialog-canceled", self.on_printer_not_modified) |
| 576 |
if parent: |
| 577 |
self.dialog.set_transient_for (parent) |
| 578 |
|
| 579 |
self.load (name, host=host, encryption=encryption, parent=parent) |
| 580 |
if not self.printer: |
| 581 |
return |
| 582 |
|
| 583 |
for button in [self.btnPrinterPropertiesCancel, |
| 584 |
self.btnPrinterPropertiesOK, |
| 585 |
self.btnPrinterPropertiesApply]: |
| 586 |
if self.printer.discovered: |
| 587 |
button.hide () |
| 588 |
else: |
| 589 |
button.show () |
| 590 |
if self.printer.discovered: |
| 591 |
self.btnPrinterPropertiesClose.show () |
| 592 |
else: |
| 593 |
self.btnPrinterPropertiesClose.hide () |
| 594 |
self.setDataButtonState () |
| 595 |
self.btnPrintTestPage.set_tooltip_text(_("CUPS test page")) |
| 596 |
self.btnSelfTest.set_tooltip_text(_("Typically shows whether all jets " |
| 597 |
"on a print head are functioning " |
| 598 |
"and that the print feed mechanisms" |
| 599 |
" are working properly.")) |
| 600 |
treeview = self.tvPrinterProperties |
| 601 |
treeview.set_cursor (Gtk.TreePath(), None, False) |
| 602 |
host = CUPS_server_hostname () |
| 603 |
self.dialog.set_title (_("Printer Properties - " |
| 604 |
"'%s' on %s") % (name, host)) |
| 605 |
self.dialog.show () |
| 606 |
|
| 607 |
def printer_properties_response (self, dialog, response): |
| 608 |
if not self.printer: |
| 609 |
response = Gtk.ResponseType.CANCEL |
| 610 |
|
| 611 |
if response == Gtk.ResponseType.REJECT: |
| 612 |
# The Conflict button was pressed. |
| 613 |
message = _("There are conflicting options.\n" |
| 614 |
"Changes can only be applied after\n" |
| 615 |
"these conflicts are resolved.") |
| 616 |
message += "\n\n" |
| 617 |
for option in self.conflicts: |
| 618 |
message += option.option.text + "\n" |
| 619 |
dialog = Gtk.MessageDialog(parent=self.dialog, |
| 620 |
modal=True, destroy_with_parent=True, |
| 621 |
message_type=Gtk.MessageType.WARNING, |
| 622 |
buttons=Gtk.ButtonsType.CLOSE, |
| 623 |
text=message) |
| 624 |
dialog.run() |
| 625 |
dialog.destroy() |
| 626 |
return |
| 627 |
|
| 628 |
if (response == Gtk.ResponseType.OK or |
| 629 |
response == Gtk.ResponseType.APPLY): |
| 630 |
if (response == Gtk.ResponseType.OK and len (self.changed) == 0): |
| 631 |
failed = False |
| 632 |
else: |
| 633 |
failed = self.save_printer (self.printer) |
| 634 |
|
| 635 |
if response == Gtk.ResponseType.APPLY and not failed: |
| 636 |
try: |
| 637 |
self.load (self.printer.name) |
| 638 |
except: |
| 639 |
pass |
| 640 |
|
| 641 |
self.setDataButtonState () |
| 642 |
|
| 643 |
if ((response == Gtk.ResponseType.OK and not failed) or |
| 644 |
response == Gtk.ResponseType.CANCEL): |
| 645 |
self.ppd = None |
| 646 |
self.ppd_local = None |
| 647 |
self.printer = None |
| 648 |
dialog.hide () |
| 649 |
self.emit ('dialog-closed') |
| 650 |
|
| 651 |
if self.newPrinterGUI.NewPrinterWindow.get_property ("visible"): |
| 652 |
self.newPrinterGUI.on_NPCancel (None) |
| 653 |
|
| 654 |
# Data handling |
| 655 |
|
| 656 |
def on_delete(self, dialog, event): |
| 657 |
self.printer_properties_response (dialog, Gtk.ResponseType.CANCEL) |
| 658 |
|
| 659 |
def on_printer_changed(self, widget): |
| 660 |
if isinstance(widget, Gtk.CheckButton): |
| 661 |
value = widget.get_active() |
| 662 |
elif isinstance(widget, Gtk.Entry): |
| 663 |
value = widget.get_text() |
| 664 |
elif isinstance(widget, Gtk.RadioButton): |
| 665 |
value = widget.get_active() |
| 666 |
elif isinstance(widget, Gtk.ComboBox): |
| 667 |
model = widget.get_model () |
| 668 |
iter = widget.get_active_iter() |
| 669 |
value = model.get_value (iter, 1) |
| 670 |
else: |
| 671 |
raise ValueError("Widget type not supported (yet)") |
| 672 |
|
| 673 |
p = self.printer |
| 674 |
old_values = { |
| 675 |
self.entPDescription : p.info, |
| 676 |
self.entPLocation : p.location, |
| 677 |
self.entPDevice : p.device_uri, |
| 678 |
self.chkPEnabled : p.enabled, |
| 679 |
self.chkPAccepting : not p.rejecting, |
| 680 |
self.chkPShared : p.is_shared, |
| 681 |
self.cmbPStartBanner : p.job_sheet_start, |
| 682 |
self.cmbPEndBanner : p.job_sheet_end, |
| 683 |
self.cmbPErrorPolicy : p.error_policy, |
| 684 |
self.cmbPOperationPolicy : p.op_policy, |
| 685 |
self.rbtnPAllow: p.default_allow, |
| 686 |
} |
| 687 |
|
| 688 |
old_value = old_values[widget] |
| 689 |
|
| 690 |
if old_value == value: |
| 691 |
self.changed.discard(widget) |
| 692 |
else: |
| 693 |
self.changed.add(widget) |
| 694 |
self.setDataButtonState() |
| 695 |
|
| 696 |
def option_changed(self, option): |
| 697 |
if option.is_changed(): |
| 698 |
self.changed.add(option) |
| 699 |
else: |
| 700 |
self.changed.discard(option) |
| 701 |
|
| 702 |
if option.conflicts: |
| 703 |
self.conflicts.add(option) |
| 704 |
else: |
| 705 |
self.conflicts.discard(option) |
| 706 |
self.setDataButtonState() |
| 707 |
|
| 708 |
if (self.option_manualfeed and self.option_inputslot and |
| 709 |
option == self.option_manualfeed): |
| 710 |
if option.get_current_value() == "True": |
| 711 |
self.option_inputslot.disable () |
| 712 |
else: |
| 713 |
self.option_inputslot.enable () |
| 714 |
|
| 715 |
# Access control |
| 716 |
def getPUsers(self): |
| 717 |
"""return list of usernames from the GUI""" |
| 718 |
model = self.tvPUsers.get_model() |
| 719 |
result = [] |
| 720 |
model.foreach(lambda model, path, iter, data: |
| 721 |
result.append(model.get(iter, 0)[0]), None) |
| 722 |
result.sort() |
| 723 |
return result |
| 724 |
|
| 725 |
def setPUsers(self, users): |
| 726 |
"""write list of usernames into the GUI""" |
| 727 |
model = self.tvPUsers.get_model() |
| 728 |
model.clear() |
| 729 |
for user in users: |
| 730 |
model.append((user,)) |
| 731 |
|
| 732 |
self.on_entPUser_changed(self.entPUser) |
| 733 |
self.on_tvPUsers_cursor_changed(self.tvPUsers) |
| 734 |
|
| 735 |
def checkPUsersChanged(self): |
| 736 |
"""check if users in GUI and printer are different |
| 737 |
and set self.changed""" |
| 738 |
if not self.printer: |
| 739 |
return |
| 740 |
|
| 741 |
if self.getPUsers() != self.printer.except_users: |
| 742 |
self.changed.add(self.tvPUsers) |
| 743 |
else: |
| 744 |
self.changed.discard(self.tvPUsers) |
| 745 |
|
| 746 |
self.on_tvPUsers_cursor_changed(self.tvPUsers) |
| 747 |
self.setDataButtonState() |
| 748 |
|
| 749 |
def on_btnPAddUser_clicked(self, button): |
| 750 |
user = self.entPUser.get_text() |
| 751 |
if user: |
| 752 |
self.tvPUsers.get_model().insert(0, (user,)) |
| 753 |
self.entPUser.set_text("") |
| 754 |
self.checkPUsersChanged() |
| 755 |
|
| 756 |
def on_btnPDelUser_clicked(self, button): |
| 757 |
model, rows = self.tvPUsers.get_selection().get_selected_rows() |
| 758 |
rows = [Gtk.TreeRowReference.new (model, row) for row in rows] |
| 759 |
for row in rows: |
| 760 |
path = row.get_path() |
| 761 |
iter = model.get_iter(path) |
| 762 |
model.remove(iter) |
| 763 |
self.checkPUsersChanged() |
| 764 |
|
| 765 |
def on_entPUser_changed(self, widget): |
| 766 |
self.btnPAddUser.set_sensitive(bool(widget.get_text())) |
| 767 |
|
| 768 |
def on_tvPUsers_cursor_changed(self, widget): |
| 769 |
selection = widget.get_selection () |
| 770 |
if selection is None: |
| 771 |
return |
| 772 |
|
| 773 |
model, rows = selection.get_selected_rows() |
| 774 |
self.btnPDelUser.set_sensitive(bool(rows)) |
| 775 |
|
| 776 |
# Server side options |
| 777 |
def on_job_option_reset(self, button): |
| 778 |
option = self.job_options_buttons[button] |
| 779 |
option.reset () |
| 780 |
# Remember to set this option for removal in the IPP request. |
| 781 |
if option.name in self.server_side_options: |
| 782 |
del self.server_side_options[option.name] |
| 783 |
if option.is_changed (): |
| 784 |
self.changed.add(option) |
| 785 |
else: |
| 786 |
self.changed.discard(option) |
| 787 |
self.setDataButtonState() |
| 788 |
|
| 789 |
def on_job_option_changed(self, widget): |
| 790 |
if not self.printer: |
| 791 |
return |
| 792 |
option = self.job_options_widgets[widget] |
| 793 |
option.changed () |
| 794 |
if option.is_changed (): |
| 795 |
self.server_side_options[option.name] = option |
| 796 |
self.changed.add(option) |
| 797 |
else: |
| 798 |
if option.name in self.server_side_options: |
| 799 |
del self.server_side_options[option.name] |
| 800 |
self.changed.discard(option) |
| 801 |
self.setDataButtonState() |
| 802 |
# Don't set the reset button insensitive if the option hasn't |
| 803 |
# changed from the original value: it's still meaningful to |
| 804 |
# reset the option to the system default. |
| 805 |
|
| 806 |
def draw_other_job_options (self, editable=True): |
| 807 |
n = len (self.other_job_options) |
| 808 |
if n == 0: |
| 809 |
self.tblJOOther.hide() |
| 810 |
return |
| 811 |
|
| 812 |
children = self.tblJOOther.get_children () |
| 813 |
for child in children: |
| 814 |
self.tblJOOther.remove (child) |
| 815 |
i = 0 |
| 816 |
for opt in self.other_job_options: |
| 817 |
self.tblJOOther.attach (opt.label, 0, i, 1, 1) |
| 818 |
opt.label.set_alignment (0.0, 0.5) |
| 819 |
self.tblJOOther.attach (opt.selector, 1, i, 1, 1) |
| 820 |
opt.selector.set_sensitive (editable) |
| 821 |
|
| 822 |
btn = Gtk.Button.new_from_icon_name (Gtk.STOCK_REMOVE, |
| 823 |
Gtk.IconSize.BUTTON) |
| 824 |
btn.connect("clicked", self.on_btnJOOtherRemove_clicked) |
| 825 |
btn.pyobject = opt |
| 826 |
btn.set_sensitive (editable) |
| 827 |
self.tblJOOther.attach(btn, 2, i, 1, 1) |
| 828 |
i += 1 |
| 829 |
|
| 830 |
self.tblJOOther.show_all () |
| 831 |
|
| 832 |
def add_job_option(self, name, value = "", supported = "", is_new=True, |
| 833 |
editable=True): |
| 834 |
try: |
| 835 |
option = options.OptionWidget(name, value, supported, |
| 836 |
self.option_changed) |
| 837 |
except ValueError: |
| 838 |
# We can't deal with this option type for some reason. |
| 839 |
nonfatalException () |
| 840 |
return |
| 841 |
|
| 842 |
option.is_new = is_new |
| 843 |
self.other_job_options.append (option) |
| 844 |
self.draw_other_job_options (editable=editable) |
| 845 |
self.server_side_options[name] = option |
| 846 |
if name in self.changed: # was deleted before |
| 847 |
option.is_new = False |
| 848 |
self.changed.add(option) |
| 849 |
self.setDataButtonState() |
| 850 |
if is_new: |
| 851 |
option.selector.grab_focus () |
| 852 |
|
| 853 |
def on_btnJOOtherRemove_clicked(self, button): |
| 854 |
option = button.pyobject |
| 855 |
self.other_job_options.remove (option) |
| 856 |
self.draw_other_job_options () |
| 857 |
if option.is_new: |
| 858 |
self.changed.discard(option) |
| 859 |
else: |
| 860 |
# keep name as reminder that option got deleted |
| 861 |
self.changed.add(option.name) |
| 862 |
del self.server_side_options[option.name] |
| 863 |
self.setDataButtonState() |
| 864 |
|
| 865 |
def on_btnNewJobOption_clicked(self, button): |
| 866 |
name = self.entNewJobOption.get_text() |
| 867 |
self.add_job_option(name) |
| 868 |
self.tblJOOther.show_all() |
| 869 |
self.entNewJobOption.set_text ('') |
| 870 |
self.btnNewJobOption.set_sensitive (False) |
| 871 |
self.setDataButtonState() |
| 872 |
|
| 873 |
def on_entNewJobOption_changed(self, widget): |
| 874 |
text = self.entNewJobOption.get_text() |
| 875 |
active = (len(text) > 0) and text not in self.server_side_options |
| 876 |
self.btnNewJobOption.set_sensitive(active) |
| 877 |
|
| 878 |
def on_entNewJobOption_activate(self, widget): |
| 879 |
self.on_btnNewJobOption_clicked (widget) # wrong widget but ok |
| 880 |
|
| 881 |
# set buttons sensitivity |
| 882 |
def setDataButtonState(self): |
| 883 |
try: |
| 884 |
attrs = self.printer.other_attributes |
| 885 |
formats = attrs.get('document-format-supported', []) |
| 886 |
printable = (not bool (self.changed) and |
| 887 |
self.printer.enabled and |
| 888 |
not self.printer.rejecting) |
| 889 |
try: |
| 890 |
formats.index ('application/postscript') |
| 891 |
testpage = printable |
| 892 |
except ValueError: |
| 893 |
# PostScript not accepted |
| 894 |
testpage = False |
| 895 |
|
| 896 |
self.btnPrintTestPage.set_sensitive (testpage) |
| 897 |
adjustable = not (self.printer.discovered or bool (self.changed)) |
| 898 |
for button in [self.btnChangePPD, |
| 899 |
self.btnSelectDevice]: |
| 900 |
button.set_sensitive (adjustable) |
| 901 |
|
| 902 |
selftest = False |
| 903 |
cleanheads = False |
| 904 |
if (printable and |
| 905 |
(self.printer.type & cups.CUPS_PRINTER_COMMANDS) != 0): |
| 906 |
try: |
| 907 |
# Is the command format supported? |
| 908 |
formats.index ('application/vnd.cups-command') |
| 909 |
|
| 910 |
# Yes... |
| 911 |
commands = attrs.get('printer-commands', []) |
| 912 |
for command in commands: |
| 913 |
if command == "PrintSelfTestPage": |
| 914 |
selftest = True |
| 915 |
if cleanheads: |
| 916 |
break |
| 917 |
|
| 918 |
elif command == "Clean": |
| 919 |
cleanheads = True |
| 920 |
if selftest: |
| 921 |
break |
| 922 |
except ValueError: |
| 923 |
# Command format not supported. |
| 924 |
pass |
| 925 |
|
| 926 |
for cond, button in [(selftest, self.btnSelfTest), |
| 927 |
(cleanheads, self.btnCleanHeads)]: |
| 928 |
if cond: |
| 929 |
button.show () |
| 930 |
else: |
| 931 |
button.hide () |
| 932 |
except: |
| 933 |
nonfatalException() |
| 934 |
|
| 935 |
if self.ppd or \ |
| 936 |
((self.printer.remote or \ |
| 937 |
((self.printer.device_uri.startswith('dnssd:') or \ |
| 938 |
self.printer.device_uri.startswith('mdns:')) and \ |
| 939 |
self.printer.device_uri.endswith('/cups'))) and not \ |
| 940 |
self.printer.discovered): |
| 941 |
self.btnPrintTestPage.show () |
| 942 |
else: |
| 943 |
self.btnPrintTestPage.hide () |
| 944 |
|
| 945 |
installablebold = False |
| 946 |
optionsbold = False |
| 947 |
if self.conflicts: |
| 948 |
debugprint ("Conflicts detected") |
| 949 |
self.btnConflict.show() |
| 950 |
for option in self.conflicts: |
| 951 |
if option.tab_label.get_text () == self.lblPInstallOptions.get_text (): |
| 952 |
installablebold = True |
| 953 |
else: |
| 954 |
optionsbold = True |
| 955 |
else: |
| 956 |
self.btnConflict.hide() |
| 957 |
installabletext = _("Installable Options") |
| 958 |
optionstext = _("Printer Options") |
| 959 |
if installablebold: |
| 960 |
installabletext = "<b>%s</b>" % installabletext |
| 961 |
if optionsbold: |
| 962 |
optionstext = "<b>%s</b>" % optionstext |
| 963 |
self.lblPInstallOptions.set_markup (installabletext) |
| 964 |
self.lblPOptions.set_markup (optionstext) |
| 965 |
|
| 966 |
store = self.tvPrinterProperties.get_model () |
| 967 |
if store: |
| 968 |
for n in range (self.ntbkPrinter.get_n_pages ()): |
| 969 |
page = self.ntbkPrinter.get_nth_page (n) |
| 970 |
label = self.ntbkPrinter.get_tab_label (page).get_text () |
| 971 |
try: |
| 972 |
if label == self.lblPInstallOptions.get_text(): |
| 973 |
iter = store.get_iter ((n,)) |
| 974 |
store.set_value (iter, 0, installabletext) |
| 975 |
elif label == self.lblPOptions.get_text (): |
| 976 |
iter = store.get_iter ((n,)) |
| 977 |
store.set_value (iter, 0, optionstext) |
| 978 |
except ValueError: |
| 979 |
# If we get here, the store has not yet been set |
| 980 |
# up (trac #111). |
| 981 |
pass |
| 982 |
|
| 983 |
self.btnPrinterPropertiesApply.set_sensitive (len (self.changed) > 0 and |
| 984 |
not self.conflicts) |
| 985 |
self.btnPrinterPropertiesOK.set_sensitive (not self.conflicts) |
| 986 |
|
| 987 |
def save_printer(self, printer, saveall=False, parent=None): |
| 988 |
if parent is None: |
| 989 |
parent = self.dialog |
| 990 |
class_deleted = False |
| 991 |
name = printer.name |
| 992 |
|
| 993 |
if printer.is_class: |
| 994 |
self.cups._begin_operation (_("modifying class %s") % name) |
| 995 |
else: |
| 996 |
self.cups._begin_operation (_("modifying printer %s") % name) |
| 997 |
|
| 998 |
try: |
| 999 |
if not printer.is_class and self.ppd: |
| 1000 |
self.getPrinterSettings() |
| 1001 |
if self.ppd.nondefaultsMarked() or saveall: |
| 1002 |
self.cups.addPrinter(name, ppd=self.ppd) |
| 1003 |
|
| 1004 |
if printer.is_class: |
| 1005 |
# update member list |
| 1006 |
new_members = newprinter.getCurrentClassMembers(self.tvClassMembers) |
| 1007 |
if not new_members: |
| 1008 |
dialog = Gtk.MessageDialog( |
| 1009 |
flags=0, |
| 1010 |
message_type=Gtk.MessageType.WARNING, |
| 1011 |
buttons=Gtk.ButtonsType.NONE, |
| 1012 |
text=_("This will delete this class!")) |
| 1013 |
dialog.format_secondary_text(_("Proceed anyway?")) |
| 1014 |
dialog.add_buttons (Gtk.STOCK_CANCEL, Gtk.ResponseType.NO, |
| 1015 |
Gtk.STOCK_DELETE, Gtk.ResponseType.YES) |
| 1016 |
result = dialog.run() |
| 1017 |
dialog.destroy() |
| 1018 |
if result==Gtk.ResponseType.NO: |
| 1019 |
self.cups._end_operation () |
| 1020 |
return True |
| 1021 |
class_deleted = True |
| 1022 |
|
| 1023 |
# update member list |
| 1024 |
old_members = printer.class_members[:] |
| 1025 |
|
| 1026 |
for member in new_members: |
| 1027 |
if member in old_members: |
| 1028 |
old_members.remove(member) |
| 1029 |
else: |
| 1030 |
self.cups.addPrinterToClass(member, name) |
| 1031 |
for member in old_members: |
| 1032 |
self.cups.deletePrinterFromClass(member, name) |
| 1033 |
|
| 1034 |
location = self.entPLocation.get_text() |
| 1035 |
info = self.entPDescription.get_text() |
| 1036 |
device_uri = self.entPDevice.get_text() |
| 1037 |
|
| 1038 |
enabled = self.chkPEnabled.get_active() |
| 1039 |
accepting = self.chkPAccepting.get_active() |
| 1040 |
shared = self.chkPShared.get_active() |
| 1041 |
|
| 1042 |
if info!=printer.info or saveall: |
| 1043 |
self.cups.setPrinterInfo(name, info) |
| 1044 |
if location!=printer.location or saveall: |
| 1045 |
self.cups.setPrinterLocation(name, location) |
| 1046 |
if (not printer.is_class and |
| 1047 |
(device_uri!=printer.device_uri or saveall)): |
| 1048 |
self.cups.setPrinterDevice(name, device_uri) |
| 1049 |
|
| 1050 |
if enabled != printer.enabled or saveall: |
| 1051 |
printer.setEnabled(enabled) |
| 1052 |
if accepting == printer.rejecting or saveall: |
| 1053 |
printer.setAccepting(accepting) |
| 1054 |
if shared != printer.is_shared or saveall: |
| 1055 |
printer.setShared(shared) |
| 1056 |
|
| 1057 |
def get_combo_value (cmb): |
| 1058 |
model = cmb.get_model () |
| 1059 |
iter = cmb.get_active_iter () |
| 1060 |
return model.get_value (iter, 1) |
| 1061 |
|
| 1062 |
job_sheet_start = get_combo_value (self.cmbPStartBanner) |
| 1063 |
job_sheet_end = get_combo_value (self.cmbPEndBanner) |
| 1064 |
error_policy = get_combo_value (self.cmbPErrorPolicy) |
| 1065 |
op_policy = get_combo_value (self.cmbPOperationPolicy) |
| 1066 |
|
| 1067 |
if (job_sheet_start != printer.job_sheet_start or |
| 1068 |
job_sheet_end != printer.job_sheet_end) or saveall: |
| 1069 |
printer.setJobSheets(job_sheet_start, job_sheet_end) |
| 1070 |
if error_policy != printer.error_policy or saveall: |
| 1071 |
printer.setErrorPolicy(error_policy) |
| 1072 |
if op_policy != printer.op_policy or saveall: |
| 1073 |
printer.setOperationPolicy(op_policy) |
| 1074 |
|
| 1075 |
default_allow = self.rbtnPAllow.get_active() |
| 1076 |
except_users = self.getPUsers() |
| 1077 |
|
| 1078 |
if (default_allow != printer.default_allow or |
| 1079 |
except_users != printer.except_users) or saveall: |
| 1080 |
printer.setAccess(default_allow, except_users) |
| 1081 |
|
| 1082 |
for option in printer.attributes: |
| 1083 |
if option not in self.server_side_options: |
| 1084 |
printer.unsetOption(option) |
| 1085 |
for option in self.server_side_options.values(): |
| 1086 |
if (option.is_changed() or |
| 1087 |
(saveall and |
| 1088 |
option.get_current_value () != option.get_default())): |
| 1089 |
debugprint ("Set %s = %s" % (option.name, |
| 1090 |
option.get_current_value())) |
| 1091 |
printer.setOption(option.name, option.get_current_value()) |
| 1092 |
|
| 1093 |
except cups.IPPError as e: |
| 1094 |
(e, s) = e.args |
| 1095 |
show_IPP_Error(e, s, parent) |
| 1096 |
self.cups._end_operation () |
| 1097 |
return True |
| 1098 |
self.cups._end_operation () |
| 1099 |
self.changed = set() # of options |
| 1100 |
|
| 1101 |
if not self.cups._use_pk and "server_settings" not in self.__dict__: |
| 1102 |
# We can authenticate with the server correctly at this point, |
| 1103 |
# but we have never fetched the server settings to see whether |
| 1104 |
# the server is publishing shared printers. Fetch the settings |
| 1105 |
# now so that we can update the "not published" label if necessary. |
| 1106 |
self.cups._begin_operation (_("fetching server settings")) |
| 1107 |
try: |
| 1108 |
self.server_settings = self.cups.adminGetServerSettings() |
| 1109 |
except: |
| 1110 |
nonfatalException() |
| 1111 |
|
| 1112 |
self.cups._end_operation () |
| 1113 |
|
| 1114 |
if not class_deleted: |
| 1115 |
# Update our copy of the printer's settings. |
| 1116 |
try: |
| 1117 |
printer.getAttributes () |
| 1118 |
self.updatePrinterProperties () |
| 1119 |
except cups.IPPError: |
| 1120 |
pass |
| 1121 |
|
| 1122 |
self._monitor.update () |
| 1123 |
return False |
| 1124 |
|
| 1125 |
def getPrinterSettings(self): |
| 1126 |
#self.ppd.markDefaults() |
| 1127 |
for option in self.options.values(): |
| 1128 |
option.writeback() |
| 1129 |
|
| 1130 |
### Printer Properties tree view signal handlers |
| 1131 |
def on_tvPrinterProperties_selection_changed (self, selection): |
| 1132 |
# Prevent selection from being de-selected. |
| 1133 |
(model, iter) = selection.get_selected () |
| 1134 |
if iter: |
| 1135 |
self.printer_properties_last_iter_selected = iter |
| 1136 |
else: |
| 1137 |
try: |
| 1138 |
iter = self.printer_properties_last_iter_selected |
| 1139 |
except AttributeError: |
| 1140 |
# Not set yet. |
| 1141 |
return |
| 1142 |
|
| 1143 |
if model.iter_is_valid (iter): |
| 1144 |
selection.select_iter (iter) |
| 1145 |
|
| 1146 |
def on_tvPrinterProperties_cursor_changed (self, treeview): |
| 1147 |
# Adjust notebook to reflect selected item. |
| 1148 |
(path, column) = treeview.get_cursor () |
| 1149 |
if path is not None: |
| 1150 |
model = treeview.get_model () |
| 1151 |
iter = model.get_iter (path) |
| 1152 |
n = model.get_value (iter, 1) |
| 1153 |
self.ntbkPrinter.set_current_page (n) |
| 1154 |
|
| 1155 |
# print test page |
| 1156 |
|
| 1157 |
def printTestPage (self): |
| 1158 |
self.btnPrintTestPage.clicked () |
| 1159 |
|
| 1160 |
def on_btnPrintTestPage_clicked(self, button): |
| 1161 |
printer = self.printer |
| 1162 |
if not printer: |
| 1163 |
# Printer has been deleted meanwhile |
| 1164 |
return |
| 1165 |
|
| 1166 |
# if we have a page size specific custom test page, use it; |
| 1167 |
# otherwise use cups' default one |
| 1168 |
custom_testpage = None |
| 1169 |
if self.ppd != False: |
| 1170 |
opt = self.ppd.findOption ("PageSize") |
| 1171 |
if opt: |
| 1172 |
custom_testpage = os.path.join(pkgdata, |
| 1173 |
'testpage-%s.ps' % |
| 1174 |
opt.defchoice.lower()) |
| 1175 |
|
| 1176 |
# Connect as the current user so that the test page can be managed |
| 1177 |
# as a normal job. |
| 1178 |
user = cups.getUser () |
| 1179 |
cups.setUser ('') |
| 1180 |
try: |
| 1181 |
c = authconn.Connection (self.parent, try_as_root=False, |
| 1182 |
host=self._host, |
| 1183 |
encryption=self._encryption) |
| 1184 |
except RuntimeError as e: |
| 1185 |
show_IPP_Error (None, e, self.parent) |
| 1186 |
return |
| 1187 |
|
| 1188 |
job_id = None |
| 1189 |
c._begin_operation (_("printing test page")) |
| 1190 |
try: |
| 1191 |
if custom_testpage and os.path.exists(custom_testpage): |
| 1192 |
debugprint ('Printing custom test page ' + custom_testpage) |
| 1193 |
job_id = c.printTestPage(printer.name, |
| 1194 |
file=custom_testpage) |
| 1195 |
else: |
| 1196 |
debugprint ('Printing default test page') |
| 1197 |
job_id = c.printTestPage(printer.name) |
| 1198 |
except cups.IPPError as e: |
| 1199 |
(e, msg) = e.args |
| 1200 |
if (e == cups.IPP_NOT_AUTHORIZED and |
| 1201 |
self._host != 'localhost' and |
| 1202 |
self._host[0] != '/'): |
| 1203 |
show_error_dialog (_("Not possible"), |
| 1204 |
_("The remote server did not accept " |
| 1205 |
"the print job, most likely " |
| 1206 |
"because the printer is not " |
| 1207 |
"shared."), |
| 1208 |
self.parent) |
| 1209 |
else: |
| 1210 |
show_IPP_Error(e, msg, self.parent) |
| 1211 |
|
| 1212 |
c._end_operation () |
| 1213 |
cups.setUser (user) |
| 1214 |
|
| 1215 |
if job_id is not None: |
| 1216 |
show_info_dialog (_("Submitted"), |
| 1217 |
_("Test page submitted as job %d") % job_id, |
| 1218 |
parent=self.parent) |
| 1219 |
|
| 1220 |
def maintenance_command (self, command): |
| 1221 |
printer = self.printer |
| 1222 |
if not printer: |
| 1223 |
# Printer has been deleted meanwhile |
| 1224 |
return |
| 1225 |
|
| 1226 |
with tempfile.NamedTemporaryFile(mode='wt') as tmpfile: |
| 1227 |
tmpfile.write ("#CUPS-COMMAND\n%s\n" % command) |
| 1228 |
tmpfile.flush() |
| 1229 |
self.cups._begin_operation (_("sending maintenance command")) |
| 1230 |
try: |
| 1231 |
format = "application/vnd.cups-command" |
| 1232 |
job_id = self.cups.printTestPage (printer.name, |
| 1233 |
format=format, |
| 1234 |
file=tmpfile.name, |
| 1235 |
user=cups.getUser ()) |
| 1236 |
show_info_dialog (_("Submitted"), |
| 1237 |
_("Maintenance command submitted as " |
| 1238 |
"job %d") % job_id, |
| 1239 |
parent=self.parent) |
| 1240 |
except cups.IPPError as e: |
| 1241 |
(e, msg) = e.args |
| 1242 |
if (e == cups.IPP_NOT_AUTHORIZED and |
| 1243 |
self.printer.name != 'localhost'): |
| 1244 |
show_error_dialog (_("Not possible"), |
| 1245 |
_("The remote server did not accept " |
| 1246 |
"the print job, most likely " |
| 1247 |
"because the printer is not " |
| 1248 |
"shared."), |
| 1249 |
self.parent) |
| 1250 |
else: |
| 1251 |
show_IPP_Error(e, msg, self.parent) |
| 1252 |
self.cups._end_operation () |
| 1253 |
|
| 1254 |
def on_btnSelfTest_clicked(self, button): |
| 1255 |
self.maintenance_command ("PrintSelfTestPage") |
| 1256 |
|
| 1257 |
def on_btnCleanHeads_clicked(self, button): |
| 1258 |
self.maintenance_command ("Clean all") |
| 1259 |
|
| 1260 |
def fillComboBox(self, combobox, values, value, translationdict=None): |
| 1261 |
if translationdict is None: |
| 1262 |
translationdict = ppdippstr.TranslationDict () |
| 1263 |
|
| 1264 |
model = Gtk.ListStore (str, |
| 1265 |
str) |
| 1266 |
combobox.set_model (model) |
| 1267 |
set_active = False |
| 1268 |
for nr, val in enumerate(values): |
| 1269 |
model.append ([(translationdict.get (val)), val]) |
| 1270 |
if val == value: |
| 1271 |
combobox.set_active(nr) |
| 1272 |
set_active = True |
| 1273 |
|
| 1274 |
if not set_active: |
| 1275 |
combobox.set_active (0) |
| 1276 |
|
| 1277 |
def load (self, name, host=None, encryption=None, parent=None): |
| 1278 |
self.changed = set() # of options |
| 1279 |
self.options = {} # keyword -> Option object |
| 1280 |
self.conflicts = set() # of options |
| 1281 |
|
| 1282 |
if not host: |
| 1283 |
host = cups.getServer() |
| 1284 |
if not encryption: |
| 1285 |
encryption = cups.getEncryption () |
| 1286 |
|
| 1287 |
c = authconn.Connection (parent=self.dialog, |
| 1288 |
host=host, |
| 1289 |
encryption=encryption) |
| 1290 |
self.cups = c |
| 1291 |
|
| 1292 |
printer = cupshelpers.Printer (name, self.cups) |
| 1293 |
self.printer = printer |
| 1294 |
try: |
| 1295 |
# CUPS 1.4 |
| 1296 |
publishing = printer.other_attributes['server-is-sharing-printers'] |
| 1297 |
self.server_is_publishing = publishing |
| 1298 |
except KeyError: |
| 1299 |
pass |
| 1300 |
|
| 1301 |
editable = not self.printer.discovered |
| 1302 |
|
| 1303 |
try: |
| 1304 |
self.ppd = printer.getPPD() |
| 1305 |
self.ppd_local = printer.getPPD() |
| 1306 |
if self.ppd_local != False: |
| 1307 |
self.ppd_local.localize() |
| 1308 |
except cups.IPPError as e: |
| 1309 |
(e, m) = e.args |
| 1310 |
# We might get IPP_INTERNAL_ERROR if this is a memberless |
| 1311 |
# class. |
| 1312 |
if e != cups.IPP_INTERNAL_ERROR: |
| 1313 |
# Some IPP error other than IPP_NOT_FOUND. |
| 1314 |
show_IPP_Error(e, m, self.parent) |
| 1315 |
|
| 1316 |
if e in [cups.IPP_SERVICE_UNAVAILABLE, |
| 1317 |
cups.IPP_INTERNAL_ERROR]: |
| 1318 |
show_dialog(_("Raw Queue"), |
| 1319 |
_("Unable to get queue details. Treating queue " |
| 1320 |
"as raw."), |
| 1321 |
Gtk.MessageType.ERROR, |
| 1322 |
self.parent) |
| 1323 |
|
| 1324 |
# Treat it as a raw queue. |
| 1325 |
self.ppd = False |
| 1326 |
except RuntimeError as e: |
| 1327 |
# Either the underlying cupsGetPPD2() function returned |
| 1328 |
# NULL without setting an IPP error (so it'll be something |
| 1329 |
# like a failed connection), or the PPD could not be parsed. |
| 1330 |
if str (e).startswith ("ppd"): |
| 1331 |
show_error_dialog (_("Error"), |
| 1332 |
_("The PPD file for this queue " |
| 1333 |
"is damaged."), |
| 1334 |
self.parent) |
| 1335 |
else: |
| 1336 |
show_error_dialog (_("Error"), |
| 1337 |
_("There was a problem connecting to " |
| 1338 |
"the CUPS server."), |
| 1339 |
self.parent) |
| 1340 |
raise |
| 1341 |
|
| 1342 |
for widget in (self.entPDescription, self.entPLocation, |
| 1343 |
self.entPDevice): |
| 1344 |
widget.set_editable(editable) |
| 1345 |
|
| 1346 |
for widget in (self.btnSelectDevice, self.btnChangePPD, |
| 1347 |
self.chkPEnabled, self.chkPAccepting, self.chkPShared, |
| 1348 |
self.cmbPStartBanner, self.cmbPEndBanner, |
| 1349 |
self.cmbPErrorPolicy, self.cmbPOperationPolicy, |
| 1350 |
self.rbtnPAllow, self.rbtnPDeny, self.tvPUsers, |
| 1351 |
self.entPUser, self.btnPAddUser, self.btnPDelUser): |
| 1352 |
widget.set_sensitive(editable) |
| 1353 |
|
| 1354 |
# Description page |
| 1355 |
self.entPDescription.set_text(printer.info) |
| 1356 |
self.entPLocation.set_text(printer.location) |
| 1357 |
|
| 1358 |
uri = printer.device_uri |
| 1359 |
self.entPDevice.set_text(uri) |
| 1360 |
self.changed.discard(self.entPDevice) |
| 1361 |
|
| 1362 |
# Hide make/model and Device URI for classes |
| 1363 |
for widget in (self.lblPMakeModel2, self.entPMakeModel, |
| 1364 |
self.btnChangePPD, self.lblPDevice2, |
| 1365 |
self.entPDevice, self.btnSelectDevice): |
| 1366 |
if printer.is_class: |
| 1367 |
widget.hide() |
| 1368 |
else: |
| 1369 |
widget.show() |
| 1370 |
|
| 1371 |
|
| 1372 |
# Policy tab |
| 1373 |
# ---------- |
| 1374 |
|
| 1375 |
try: |
| 1376 |
if printer.is_shared: |
| 1377 |
if self.server_is_publishing: |
| 1378 |
self.lblNotPublished.hide() |
| 1379 |
else: |
| 1380 |
self.lblNotPublished.show_all () |
| 1381 |
else: |
| 1382 |
self.lblNotPublished.hide() |
| 1383 |
except: |
| 1384 |
nonfatalException() |
| 1385 |
self.lblNotPublished.hide() |
| 1386 |
|
| 1387 |
# Job sheets |
| 1388 |
self.cmbPStartBanner.set_sensitive(editable) |
| 1389 |
self.cmbPEndBanner.set_sensitive(editable) |
| 1390 |
|
| 1391 |
# Policies |
| 1392 |
self.cmbPErrorPolicy.set_sensitive(editable) |
| 1393 |
self.cmbPOperationPolicy.set_sensitive(editable) |
| 1394 |
|
| 1395 |
# Access control |
| 1396 |
self.entPUser.set_text("") |
| 1397 |
|
| 1398 |
# Server side options (Job options) |
| 1399 |
self.server_side_options = {} |
| 1400 |
for option in self.job_options_widgets.values (): |
| 1401 |
if option.name == "media" and self.ppd: |
| 1402 |
# Slightly special case because the 'system default' |
| 1403 |
# (i.e. what you get when you press Reset) depends |
| 1404 |
# on the printer's PageSize. |
| 1405 |
opt = self.ppd.findOption ("PageSize") |
| 1406 |
if opt: |
| 1407 |
option.set_default (opt.defchoice) |
| 1408 |
|
| 1409 |
option_editable = editable |
| 1410 |
try: |
| 1411 |
value = self.printer.attributes[option.name] |
| 1412 |
except KeyError: |
| 1413 |
option.reinit (None) |
| 1414 |
else: |
| 1415 |
try: |
| 1416 |
if option.name in self.printer.possible_attributes: |
| 1417 |
supported = self.printer.\ |
| 1418 |
possible_attributes[option.name][1] |
| 1419 |
# Set the option widget. |
| 1420 |
# In CUPS 1.3.x the orientation-requested-default |
| 1421 |
# attribute may have the value None; this means there |
| 1422 |
# is no value set. This suits our needs here, as None |
| 1423 |
# resets the option to the system default and makes the |
| 1424 |
# Reset button insensitive. |
| 1425 |
option.reinit (value, supported=supported) |
| 1426 |
else: |
| 1427 |
option.reinit (value) |
| 1428 |
|
| 1429 |
self.server_side_options[option.name] = option |
| 1430 |
except: |
| 1431 |
nonfatalException() |
| 1432 |
option_editable = False |
| 1433 |
debugprint ("Option '%s' has value '%s' and cannot be edited." % (option.name, value)) |
| 1434 |
option.widget.set_sensitive (option_editable) |
| 1435 |
if not editable: |
| 1436 |
option.button.set_sensitive (False) |
| 1437 |
self.other_job_options = [] |
| 1438 |
self.draw_other_job_options (editable=editable) |
| 1439 |
for option in self.printer.attributes.keys (): |
| 1440 |
if option in self.server_side_options: |
| 1441 |
continue |
| 1442 |
if option == "output-mode" or option == "media-col": |
| 1443 |
# Not settable |
| 1444 |
continue |
| 1445 |
value = self.printer.attributes[option] |
| 1446 |
if option in self.printer.possible_attributes: |
| 1447 |
supported = self.printer.possible_attributes[option][1] |
| 1448 |
else: |
| 1449 |
if isinstance (value, bool): |
| 1450 |
supported = ["true", "false"] |
| 1451 |
value = str (value).lower () |
| 1452 |
else: |
| 1453 |
supported = "" |
| 1454 |
value = str (value) |
| 1455 |
|
| 1456 |
self.add_job_option (option, value=value, |
| 1457 |
supported=supported, is_new=False, |
| 1458 |
editable=editable) |
| 1459 |
self.entNewJobOption.set_text ('') |
| 1460 |
self.entNewJobOption.set_sensitive (editable) |
| 1461 |
self.btnNewJobOption.set_sensitive (False) |
| 1462 |
|
| 1463 |
if printer.is_class: |
| 1464 |
# remove InstallOptions tab |
| 1465 |
tab_nr = self.ntbkPrinter.page_num(self.swPInstallOptions) |
| 1466 |
if tab_nr != -1: |
| 1467 |
self.ntbkPrinter.remove_page(tab_nr) |
| 1468 |
self.fillClassMembers(editable) |
| 1469 |
else: |
| 1470 |
# real Printer |
| 1471 |
self.fillPrinterOptions(name, editable) |
| 1472 |
|
| 1473 |
self.updateMarkerLevels() |
| 1474 |
self.updateStateReasons() |
| 1475 |
self.updatePrinterPropertiesTreeView() |
| 1476 |
|
| 1477 |
self.changed = set() # of options |
| 1478 |
self.updatePrinterProperties () |
| 1479 |
self.setDataButtonState() |
| 1480 |
|
| 1481 |
def updatePrinterPropertiesTreeView (self): |
| 1482 |
# Now update the tree view (which we use instead of the notebook tabs). |
| 1483 |
store = Gtk.ListStore (str, int) |
| 1484 |
self.ntbkPrinter.set_show_tabs (False) |
| 1485 |
for n in range (self.ntbkPrinter.get_n_pages ()): |
| 1486 |
page = self.ntbkPrinter.get_nth_page (n) |
| 1487 |
label = self.ntbkPrinter.get_tab_label (page) |
| 1488 |
iter = store.append (None) |
| 1489 |
store.set_value (iter, 0, label.get_text ()) |
| 1490 |
store.set_value (iter, 1, n) |
| 1491 |
sel = self.tvPrinterProperties.get_selection () |
| 1492 |
self.tvPrinterProperties.set_model (store) |
| 1493 |
|
| 1494 |
def updateMarkerLevels (self): |
| 1495 |
printer = self.printer |
| 1496 |
if not printer: |
| 1497 |
# Printer has been deleted meanwhile |
| 1498 |
return |
| 1499 |
|
| 1500 |
# Marker levels |
| 1501 |
for widget in self.vboxMarkerLevels.get_children (): |
| 1502 |
self.vboxMarkerLevels.remove (widget) |
| 1503 |
|
| 1504 |
marker_info = dict() |
| 1505 |
num_markers = 0 |
| 1506 |
for (attr, typ) in [('marker-colors', str), |
| 1507 |
('marker-names', str), |
| 1508 |
('marker-types', str), |
| 1509 |
('marker-levels', float)]: |
| 1510 |
val = printer.other_attributes.get (attr, []) |
| 1511 |
if typ != str and len (val) > 0: |
| 1512 |
try: |
| 1513 |
# Can the value be coerced into the right type? |
| 1514 |
typ (val[0]) |
| 1515 |
except TypeError as s: |
| 1516 |
debugprint ("%s value not coercible to %s: %s" % |
| 1517 |
(attr, typ, s)) |
| 1518 |
val = [0.0 for x in val] |
| 1519 |
|
| 1520 |
marker_info[attr] = [0.0 if (typ != str and x < 0) \ |
| 1521 |
else x for x in val] |
| 1522 |
if num_markers == 0 or len (val) < num_markers: |
| 1523 |
num_markers = len (val) |
| 1524 |
|
| 1525 |
for attr in ['marker-colors', 'marker-names', |
| 1526 |
'marker-types', 'marker-levels']: |
| 1527 |
if len (marker_info[attr]) > num_markers: |
| 1528 |
debugprint ("Trimming %s from %s" % |
| 1529 |
(marker_info[attr][num_markers:], attr)) |
| 1530 |
del marker_info[attr][num_markers:] |
| 1531 |
|
| 1532 |
markers = list(map (lambda color, name, type, level: |
| 1533 |
(color, name, type, level), |
| 1534 |
marker_info['marker-colors'], |
| 1535 |
marker_info['marker-names'], |
| 1536 |
marker_info['marker-types'], |
| 1537 |
marker_info['marker-levels'])) |
| 1538 |
debugprint (markers) |
| 1539 |
|
| 1540 |
can_refresh = (printer.type & cups.CUPS_PRINTER_COMMANDS) != 0 |
| 1541 |
if can_refresh: |
| 1542 |
self.btnRefreshMarkerLevels.show () |
| 1543 |
else: |
| 1544 |
self.btnRefreshMarkerLevels.hide () |
| 1545 |
|
| 1546 |
if len (markers) == 0: |
| 1547 |
label = Gtk.Label(label=_("Marker levels are not reported " |
| 1548 |
"for this printer.")) |
| 1549 |
label.set_line_wrap (True) |
| 1550 |
label.set_alignment (0.0, 0.0) |
| 1551 |
self.vboxMarkerLevels.pack_start (label, False, False, 0) |
| 1552 |
else: |
| 1553 |
num_markers = 0 |
| 1554 |
cols = len (markers) |
| 1555 |
rows = 1 + (cols - 1) / 4 |
| 1556 |
if cols > 4: |
| 1557 |
cols = 4 |
| 1558 |
grid = Gtk.Grid() |
| 1559 |
grid.set_column_homogeneous(True) |
| 1560 |
grid.set_row_homogeneous(True) |
| 1561 |
grid.set_column_spacing (6) |
| 1562 |
grid.set_row_spacing (12) |
| 1563 |
self.vboxMarkerLevels.pack_start (grid, False, False, 0) |
| 1564 |
for color, name, marker_type, level in markers: |
| 1565 |
if name is None: |
| 1566 |
name = '' |
| 1567 |
elif self.ppd != False: |
| 1568 |
localized_name = self.ppd.localizeMarkerName(name) |
| 1569 |
if localized_name is not None: |
| 1570 |
name = localized_name |
| 1571 |
|
| 1572 |
row = num_markers / 4 |
| 1573 |
col = num_markers % 4 |
| 1574 |
|
| 1575 |
vbox = Gtk.Box (spacing=6) |
| 1576 |
subhbox = Gtk.Box () |
| 1577 |
inklevel = gtkinklevel.GtkInkLevel (color, level) |
| 1578 |
inklevel.set_tooltip_text ("%d%%" % level) |
| 1579 |
subhbox.pack_start (inklevel, True, False, 0) |
| 1580 |
vbox.pack_start (subhbox, False, False, 0) |
| 1581 |
label = Gtk.Label(label=name) |
| 1582 |
label.set_width_chars (10) |
| 1583 |
label.set_line_wrap (True) |
| 1584 |
vbox.pack_start (label, False, False, 0) |
| 1585 |
grid.attach (vbox, col, row, 1, 1) |
| 1586 |
num_markers += 1 |
| 1587 |
|
| 1588 |
self.vboxMarkerLevels.show_all () |
| 1589 |
|
| 1590 |
def on_btnRefreshMarkerLevels_clicked (self, button): |
| 1591 |
self.maintenance_command ("ReportLevels") |
| 1592 |
|
| 1593 |
def updateStateReasons (self): |
| 1594 |
printer = self.printer |
| 1595 |
reasons = printer.other_attributes.get ('printer-state-reasons', []) |
| 1596 |
store = Gtk.ListStore (str, str) |
| 1597 |
any = False |
| 1598 |
for reason in reasons: |
| 1599 |
if reason == "none": |
| 1600 |
break |
| 1601 |
|
| 1602 |
any = True |
| 1603 |
iter = store.append (None) |
| 1604 |
r = statereason.StateReason (printer.name, reason, self._ppdcache) |
| 1605 |
if r.get_reason () == "paused": |
| 1606 |
icon = Gtk.STOCK_MEDIA_PAUSE |
| 1607 |
else: |
| 1608 |
icon = statereason.StateReason.LEVEL_ICON[r.get_level ()] |
| 1609 |
store.set_value (iter, 0, icon) |
| 1610 |
(title, text) = r.get_description () |
| 1611 |
store.set_value (iter, 1, text) |
| 1612 |
|
| 1613 |
self.tvPrinterStateReasons.set_model (store) |
| 1614 |
page = 0 |
| 1615 |
if any: |
| 1616 |
page = 1 |
| 1617 |
|
| 1618 |
self.ntbkPrinterStateReasons.set_current_page (page) |
| 1619 |
|
| 1620 |
def set_printer_state_reason_icon (self, column, cell, model, iter, *data): |
| 1621 |
icon = model.get_value (iter, 0) |
| 1622 |
theme = Gtk.IconTheme.get_default () |
| 1623 |
try: |
| 1624 |
pixbuf = theme.load_icon (icon, 22, 0) |
| 1625 |
cell.set_property ("pixbuf", pixbuf) |
| 1626 |
except GLib.GError: |
| 1627 |
pass # Couldn't load icon |
| 1628 |
|
| 1629 |
def set_printer_state_reason_text (self, column, cell, model, iter, *data): |
| 1630 |
cell.set_property ("text", model.get_value (iter, 1)) |
| 1631 |
|
| 1632 |
def updatePrinterProperties(self): |
| 1633 |
debugprint ("update printer properties") |
| 1634 |
printer = self.printer |
| 1635 |
self.entPDevice.set_text(printer.device_uri) |
| 1636 |
self.entPMakeModel.set_text(printer.make_and_model) |
| 1637 |
state = self.printer_states.get (printer.state, |
| 1638 |
_("Unknown")) |
| 1639 |
reason = printer.other_attributes.get ('printer-state-message', '') |
| 1640 |
if len (reason) > 0: |
| 1641 |
state += ' - ' + reason |
| 1642 |
self.entPState.set_text(state) |
| 1643 |
if len (self.changed) == 0: |
| 1644 |
debugprint ("no changes yet: full printer properties update") |
| 1645 |
# State |
| 1646 |
self.chkPEnabled.set_active(printer.enabled) |
| 1647 |
self.chkPAccepting.set_active(not printer.rejecting) |
| 1648 |
self.chkPShared.set_active(printer.is_shared) |
| 1649 |
|
| 1650 |
# Job sheets |
| 1651 |
self.fillComboBox(self.cmbPStartBanner, |
| 1652 |
printer.job_sheets_supported, |
| 1653 |
printer.job_sheet_start, |
| 1654 |
ppdippstr.job_sheets) |
| 1655 |
self.fillComboBox(self.cmbPEndBanner, printer.job_sheets_supported, |
| 1656 |
printer.job_sheet_end, |
| 1657 |
ppdippstr.job_sheets) |
| 1658 |
|
| 1659 |
# Policies |
| 1660 |
self.fillComboBox(self.cmbPErrorPolicy, |
| 1661 |
printer.error_policy_supported, |
| 1662 |
printer.error_policy, |
| 1663 |
ppdippstr.printer_error_policy) |
| 1664 |
self.fillComboBox(self.cmbPOperationPolicy, |
| 1665 |
printer.op_policy_supported, |
| 1666 |
printer.op_policy, |
| 1667 |
ppdippstr.printer_op_policy) |
| 1668 |
|
| 1669 |
# Access control |
| 1670 |
self.rbtnPAllow.set_active(printer.default_allow) |
| 1671 |
self.rbtnPDeny.set_active(not printer.default_allow) |
| 1672 |
self.setPUsers(printer.except_users) |
| 1673 |
|
| 1674 |
# Marker levels |
| 1675 |
self.updateMarkerLevels () |
| 1676 |
self.updateStateReasons () |
| 1677 |
|
| 1678 |
self.updatePrinterPropertiesTreeView () |
| 1679 |
|
| 1680 |
def fillPrinterOptions(self, name, editable): |
| 1681 |
# remove Class membership tab |
| 1682 |
tab_nr = self.ntbkPrinter.page_num(self.vbClassMembers) |
| 1683 |
if tab_nr != -1: |
| 1684 |
self.ntbkPrinter.remove_page(tab_nr) |
| 1685 |
|
| 1686 |
# clean Installable Options Tab |
| 1687 |
for widget in self.vbPInstallOptions.get_children(): |
| 1688 |
self.vbPInstallOptions.remove(widget) |
| 1689 |
|
| 1690 |
# clean Options Tab |
| 1691 |
for widget in self.vbPOptions.get_children(): |
| 1692 |
self.vbPOptions.remove(widget) |
| 1693 |
|
| 1694 |
# insert Options Tab |
| 1695 |
if self.ntbkPrinter.page_num(self.swPOptions) == -1: |
| 1696 |
self.ntbkPrinter.insert_page( |
| 1697 |
self.swPOptions, self.lblPOptions, self.static_tabs) |
| 1698 |
|
| 1699 |
if not self.ppd: |
| 1700 |
tab_nr = self.ntbkPrinter.page_num(self.swPInstallOptions) |
| 1701 |
if tab_nr != -1: |
| 1702 |
self.ntbkPrinter.remove_page(tab_nr) |
| 1703 |
tab_nr = self.ntbkPrinter.page_num(self.swPOptions) |
| 1704 |
if tab_nr != -1: |
| 1705 |
self.ntbkPrinter.remove_page(tab_nr) |
| 1706 |
return |
| 1707 |
ppd = self.ppd |
| 1708 |
ppd.markDefaults() |
| 1709 |
self.ppd_local.markDefaults() |
| 1710 |
|
| 1711 |
hasInstallableOptions = False |
| 1712 |
|
| 1713 |
# build option tabs |
| 1714 |
for group in self.ppd_local.optionGroups: |
| 1715 |
if group.name == "InstallableOptions": |
| 1716 |
hasInstallableOptions = True |
| 1717 |
container = self.vbPInstallOptions |
| 1718 |
tab_nr = self.ntbkPrinter.page_num(self.swPInstallOptions) |
| 1719 |
if tab_nr == -1: |
| 1720 |
self.ntbkPrinter.insert_page(self.swPInstallOptions, |
| 1721 |
Gtk.Label(label=group.text), |
| 1722 |
self.static_tabs) |
| 1723 |
tab_label = self.lblPInstallOptions |
| 1724 |
else: |
| 1725 |
group_name = ppdippstr.ppd.get (group.text) |
| 1726 |
frame = Gtk.Frame(label="<b>%s</b>" % html.escape (group_name)) |
| 1727 |
frame.get_label_widget().set_use_markup(True) |
| 1728 |
frame.set_shadow_type (Gtk.ShadowType.NONE) |
| 1729 |
self.vbPOptions.pack_start (frame, False, False, 0) |
| 1730 |
container = Gtk.Alignment.new(0.5, 0.5, 1.0, 1.0) |
| 1731 |
# We want a left padding of 12, but there is a Table with |
| 1732 |
# spacing 6, and the left-most column of it (the conflict |
| 1733 |
# icon) is normally hidden, so just use 6 here. |
| 1734 |
container.set_padding (6, 12, 6, 0) |
| 1735 |
frame.add (container) |
| 1736 |
tab_label = self.lblPOptions |
| 1737 |
|
| 1738 |
grid = Gtk.Grid() |
| 1739 |
grid.set_column_spacing(6) |
| 1740 |
grid.set_row_spacing(6) |
| 1741 |
container.add(grid) |
| 1742 |
|
| 1743 |
rows = 0 |
| 1744 |
|
| 1745 |
# InputSlot and ManualFeed need special handling. With |
| 1746 |
# libcups, if ManualFeed is True, InputSlot gets unset. |
| 1747 |
# Likewise, if InputSlot is set, ManualFeed becomes False. |
| 1748 |
# We handle it by toggling the sensitivity of InputSlot |
| 1749 |
# based on ManualFeed. |
| 1750 |
self.option_inputslot = self.option_manualfeed = None |
| 1751 |
|
| 1752 |
for nr, option in enumerate(group.options): |
| 1753 |
if option.keyword == "PageRegion": |
| 1754 |
continue |
| 1755 |
rows += 1 |
| 1756 |
o = OptionWidget(option, ppd, self, tab_label=tab_label) |
| 1757 |
grid.attach(o.conflictIcon, 0, nr, 1, 1) |
| 1758 |
|
| 1759 |
hbox = Gtk.Box() |
| 1760 |
if o.label: |
| 1761 |
a = Gtk.Alignment.new(0.5, 0.5, 1.0, 1.0) |
| 1762 |
a.set_padding (0, 0, 0, 6) |
| 1763 |
a.add (o.label) |
| 1764 |
grid.attach(a, 1, nr, 1, 1) |
| 1765 |
grid.attach(hbox, 2, nr, 1, 1) |
| 1766 |
else: |
| 1767 |
grid.attach(hbox, 1, nr, 2, 1) |
| 1768 |
hbox.pack_start(o.selector, False, False, 0) |
| 1769 |
self.options[option.keyword] = o |
| 1770 |
o.selector.set_sensitive(editable) |
| 1771 |
if option.keyword == "InputSlot": |
| 1772 |
self.option_inputslot = o |
| 1773 |
elif option.keyword == "ManualFeed": |
| 1774 |
self.option_manualfeed = o |
| 1775 |
|
| 1776 |
# remove Installable Options tab if not needed |
| 1777 |
if not hasInstallableOptions: |
| 1778 |
tab_nr = self.ntbkPrinter.page_num(self.swPInstallOptions) |
| 1779 |
if tab_nr != -1: |
| 1780 |
self.ntbkPrinter.remove_page(tab_nr) |
| 1781 |
|
| 1782 |
# check for conflicts |
| 1783 |
for option in self.options.values(): |
| 1784 |
conflicts = option.checkConflicts() |
| 1785 |
if conflicts: |
| 1786 |
self.conflicts.add(option) |
| 1787 |
|
| 1788 |
self.swPInstallOptions.show_all() |
| 1789 |
self.swPOptions.show_all() |
| 1790 |
|
| 1791 |
# Class members |
| 1792 |
|
| 1793 |
def fillClassMembers(self, editable): |
| 1794 |
self.btnClassAddMember.set_sensitive(editable) |
| 1795 |
self.btnClassDelMember.set_sensitive(editable) |
| 1796 |
|
| 1797 |
# remove Options tab |
| 1798 |
tab_nr = self.ntbkPrinter.page_num(self.swPOptions) |
| 1799 |
if tab_nr != -1: |
| 1800 |
self.ntbkPrinter.remove_page(tab_nr) |
| 1801 |
|
| 1802 |
# insert Member Tab |
| 1803 |
if self.ntbkPrinter.page_num(self.vbClassMembers) == -1: |
| 1804 |
self.ntbkPrinter.insert_page( |
| 1805 |
self.vbClassMembers, self.lblClassMembers, |
| 1806 |
self.static_tabs) |
| 1807 |
|
| 1808 |
model_members = self.tvClassMembers.get_model() |
| 1809 |
model_not_members = self.tvClassNotMembers.get_model() |
| 1810 |
model_members.clear() |
| 1811 |
model_not_members.clear() |
| 1812 |
|
| 1813 |
names = list (self._monitor.get_printers ()) |
| 1814 |
names.sort () |
| 1815 |
for name in names: |
| 1816 |
if name != self.printer.name: |
| 1817 |
if name in self.printer.class_members: |
| 1818 |
model_members.append((name, )) |
| 1819 |
elif not self.printer.type & cups.CUPS_PRINTER_CLASS: |
| 1820 |
model_not_members.append((name, )) |
| 1821 |
|
| 1822 |
def on_btnClassAddMember_clicked(self, button): |
| 1823 |
newprinter.moveClassMembers(self.tvClassNotMembers, |
| 1824 |
self.tvClassMembers) |
| 1825 |
if newprinter.getCurrentClassMembers(self.tvClassMembers) != self.printer.class_members: |
| 1826 |
self.changed.add(self.tvClassMembers) |
| 1827 |
else: |
| 1828 |
self.changed.discard(self.tvClassMembers) |
| 1829 |
self.setDataButtonState() |
| 1830 |
|
| 1831 |
def on_btnClassDelMember_clicked(self, button): |
| 1832 |
newprinter.moveClassMembers(self.tvClassMembers, |
| 1833 |
self.tvClassNotMembers) |
| 1834 |
if newprinter.getCurrentClassMembers(self.tvClassMembers) != self.printer.class_members: |
| 1835 |
self.changed.add(self.tvClassMembers) |
| 1836 |
else: |
| 1837 |
self.changed.discard(self.tvClassMembers) |
| 1838 |
self.setDataButtonState() |
| 1839 |
|
| 1840 |
def sensitise_new_printer_widgets (self, sensitive=True): |
| 1841 |
sensitive = (sensitive and |
| 1842 |
self.printer is not None and |
| 1843 |
not (self.printer.discovered or |
| 1844 |
bool (self.changed))) |
| 1845 |
for button in [self.btnChangePPD, |
| 1846 |
self.btnSelectDevice]: |
| 1847 |
button.set_sensitive (sensitive) |
| 1848 |
|
| 1849 |
def desensitise_new_printer_widgets (self): |
| 1850 |
self.sensitise_new_printer_widgets (False) |
| 1851 |
|
| 1852 |
# change device |
| 1853 |
def on_btnSelectDevice_clicked(self, button): |
| 1854 |
busy (self.dialog) |
| 1855 |
self.desensitise_new_printer_widgets () |
| 1856 |
if not self.newPrinterGUI.init("device", device_uri=self.printer.device_uri, |
| 1857 |
name=self.printer.name, |
| 1858 |
host=self._host, |
| 1859 |
encryption=self._encryption, |
| 1860 |
parent=self.dialog): |
| 1861 |
self.sensitise_new_printer_widgets () |
| 1862 |
|
| 1863 |
ready (self.dialog) |
| 1864 |
|
| 1865 |
# change PPD |
| 1866 |
def on_btnChangePPD_clicked(self, button): |
| 1867 |
busy (self.dialog) |
| 1868 |
self.desensitise_new_printer_widgets () |
| 1869 |
if not self.newPrinterGUI.init("ppd", device_uri=self.printer.device_uri, |
| 1870 |
ppd=self.ppd, |
| 1871 |
name=self.printer.name, |
| 1872 |
host=self._host, |
| 1873 |
encryption=self._encryption, |
| 1874 |
parent=self.dialog): |
| 1875 |
self.sensitise_new_printer_widgets () |
| 1876 |
|
| 1877 |
ready (self.dialog) |
| 1878 |
|
| 1879 |
# NewPrinterGUI signal handlers |
| 1880 |
def on_printer_modified (self, obj, name, ppd_has_changed): |
| 1881 |
debugprint ("on_printer_modified called") |
| 1882 |
self.sensitise_new_printer_widgets () |
| 1883 |
if self.dialog.get_property ('visible') and self.printer: |
| 1884 |
try: |
| 1885 |
self.printer.getAttributes () |
| 1886 |
if ppd_has_changed: |
| 1887 |
self.load (name) |
| 1888 |
else: |
| 1889 |
self.updatePrinterProperties () |
| 1890 |
|
| 1891 |
except cups.IPPError: |
| 1892 |
pass |
| 1893 |
|
| 1894 |
def on_printer_not_modified (self, obj): |
| 1895 |
self.sensitise_new_printer_widgets () |
| 1896 |
|
| 1897 |
# Monitor signal handlers |
| 1898 |
def on_printer_event (self, mon, printer, eventname, event): |
| 1899 |
self.on_printer_modified (None, printer, False) |
| 1900 |
|
| 1901 |
def on_printer_removed (self, mon, printer): |
| 1902 |
if (self.dialog.get_property ('visible') and |
| 1903 |
self.printer and self.printer.name == printer): |
| 1904 |
self.dialog.response (Gtk.ResponseType.CANCEL) |
| 1905 |
|
| 1906 |
if self.printer and self.printer.name == printer: |
| 1907 |
self.printer = None |
| 1908 |
|
| 1909 |
def on_state_reason_added (self, mon, reason): |
| 1910 |
if (self.dialog.get_property ('visible') and |
| 1911 |
self.printer and self.printer.name == reason.get_printer ()): |
| 1912 |
try: |
| 1913 |
self.printer.getAttributes () |
| 1914 |
self.updatePrinterProperties () |
| 1915 |
except cups.IPPError: |
| 1916 |
pass |
| 1917 |
|
| 1918 |
def on_state_reason_removed (self, mon, reason): |
| 1919 |
if (self.dialog.get_property ('visible') and |
| 1920 |
self.printer and self.printer.name == reason.get_printer ()): |
| 1921 |
try: |
| 1922 |
self.printer.getAttributes () |
| 1923 |
self.updatePrinterProperties () |
| 1924 |
except cups.IPPError: |
| 1925 |
pass |
| 1926 |
|
| 1927 |
def on_cups_connection_error (self, mon): |
| 1928 |
# FIXME: figure out how to handle this |
| 1929 |
pass |
| 1930 |
|
| 1931 |
if __name__ == '__main__': |
| 1932 |
import sys |
| 1933 |
|
| 1934 |
if len (sys.argv) < 2: |
| 1935 |
print("Specify queue name") |
| 1936 |
sys.exit (1) |
| 1937 |
|
| 1938 |
set_debugging (True) |
| 1939 |
os.environ["SYSTEM_CONFIG_PRINTER_UI"] = "ui" |
| 1940 |
locale.setlocale (locale.LC_ALL, "") |
| 1941 |
ppdippstr.init () |
| 1942 |
loop = GObject.MainLoop () |
| 1943 |
def on_dialog_closed (obj): |
| 1944 |
obj.destroy () |
| 1945 |
loop.quit () |
| 1946 |
|
| 1947 |
properties = PrinterPropertiesDialog () |
| 1948 |
properties.connect ('dialog-closed', on_dialog_closed) |
| 1949 |
properties.show (sys.argv[1]) |
| 1950 |
|
| 1951 |
loop.run () |