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