home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / hplip / ui / devmgr4.py < prev    next >
Encoding:
Python Source  |  2006-08-30  |  65.8 KB  |  1,771 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2001-2006 Hewlett-Packard Development Company, L.P.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18. #
  19. # Authors: Don Welch, Pete Parks
  20. #
  21.  
  22. from __future__ import generators
  23.  
  24. # Std Lib
  25. import sys, time, os
  26.  
  27. # Local
  28. from base.g import *
  29. from base import device, status, msg, maint, utils, service, pml
  30. from prnt import cups
  31. from base.codes import *
  32.  
  33. # Qt
  34. from qt import *
  35.  
  36. # Main form
  37. from devmgr4_base import DevMgr4_base
  38.  
  39. # Alignment forms
  40. from alignform import AlignForm
  41. from aligntype6form1 import AlignType6Form1
  42. from aligntype6form2 import AlignType6Form2
  43. from paperedgealignform import PaperEdgeAlignForm
  44. from colorcalform import ColorCalForm # Type 1 color cal
  45. from coloradjform import ColorAdjForm  # Type 5 and 6 color adj
  46. from colorcalform2 import ColorCalForm2 # Type 2 color cal
  47. from colorcal4form import ColorCal4Form # Type 4 color cal
  48. from align10form import Align10Form 
  49.  
  50. # Misc forms
  51. from loadpaperform import LoadPaperForm
  52. from settingsdialog import SettingsDialog
  53. from nodevicesform import NoDevicesForm
  54. from aboutdlg import AboutDlg
  55. from cleaningform import CleaningForm
  56. from cleaningform2 import CleaningForm2
  57. from waitform import WaitForm
  58. from faxsettingsform import FaxSettingsForm
  59. from informationform import InformationForm
  60. from supportform import SupportForm
  61.  
  62. # all in minutes
  63. MIN_AUTO_REFRESH_RATE = 1
  64. MAX_AUTO_REFRESH_RATE = 60
  65. DEF_AUTO_REFRESH_RATE = 1
  66.  
  67.  
  68. class JobListViewItem(QListViewItem):
  69.     def __init__(self, parent, printer, job_id, state, user, title):
  70.         QListViewItem.__init__(self, parent, printer, str(job_id), state, user, title)
  71.         self.job_id = job_id
  72.         self.printer = printer
  73.  
  74.  
  75.  
  76. class ScrollToolView(QScrollView):
  77.     def __init__(self,parent = None,name = None,fl = 0):
  78.         QScrollView.__init__(self,parent,name,fl)
  79.         self.items = {}
  80.         self.setStaticBackground(True)
  81.         self.enableClipper(True)
  82.         self.viewport().setPaletteBackgroundColor(qApp.palette().color(QPalette.Active, QColorGroup.Base))
  83.         self.row_height = 120
  84.  
  85.     def viewportResizeEvent(self, e):
  86.         for x in self.items:
  87.             self.items[x].resize(e.size().width(), self.row_height)
  88.  
  89.     def addItem(self, name, title, pix, text, button_text, button_func):
  90.         num_items = len(self.items)
  91.         LayoutWidget = QWidget(self.viewport(),"layoutwidget")
  92.         LayoutWidget.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum))
  93.         LayoutWidget.setGeometry(QRect(0, 0, self.width(), self.row_height))
  94.         LayoutWidget.setPaletteBackgroundColor(qApp.palette().color(QPalette.Active, QColorGroup.Base))
  95.         self.addChild(LayoutWidget)
  96.  
  97.         if num_items:
  98.             self.moveChild(LayoutWidget, 0, self.row_height*num_items)
  99.  
  100.         layout = QGridLayout(LayoutWidget,1,1,10,10,"layout")
  101.  
  102.         pushButton = QPushButton(LayoutWidget,"pushButton")
  103.         pushButton.setSizePolicy(QSizePolicy(QSizePolicy.Maximum,QSizePolicy.Fixed,0,0,
  104.                                  pushButton.sizePolicy().hasHeightForWidth()))
  105.  
  106.         self.connect(pushButton,SIGNAL("clicked()"), button_func) 
  107.  
  108.         layout.addWidget(pushButton,2,2)
  109.         textLabel = QLabel(LayoutWidget,"textLabel")
  110.         layout.addWidget(textLabel,1,1)
  111.  
  112.         pixmap = QLabel(LayoutWidget,"pixmapLabel2")
  113.         pixmap.setSizePolicy(QSizePolicy(QSizePolicy.Fixed,QSizePolicy.Fixed,0,0,
  114.                              pixmap.sizePolicy().hasHeightForWidth()))
  115.         pixmap.setMinimumSize(QSize(32,32))
  116.         pixmap.setMaximumSize(QSize(32,32))
  117.         pixmap.setPixmap(pix)
  118.         pixmap.setScaledContents(1)
  119.         layout.addWidget(pixmap,1,0)
  120.  
  121.         textLabel2 = QLabel(LayoutWidget,"textLabel2")
  122.         textLabel2.setAlignment(QLabel.WordBreak | QLabel.AlignTop)
  123.         textLabel2.setSizePolicy(QSizePolicy(QSizePolicy.Minimum,QSizePolicy.Expanding))
  124.         layout.addWidget(textLabel2,2,1)
  125.  
  126.         if num_items:
  127.             line = QFrame(LayoutWidget,"line")
  128.             line.setFrameShadow(QFrame.Sunken)
  129.             line.setFrameShape(QFrame.HLine)
  130.             line.setPaletteBackgroundColor(qApp.palette().color(QPalette.Active, QColorGroup.Foreground))
  131.             layout.addMultiCellWidget(line,0,0,0,2)        
  132.  
  133.         textLabel.setText(title)
  134.         textLabel2.setText(text)
  135.         pushButton.setText(button_text)
  136.         self.resizeContents(self.width(), num_items*self.row_height*2)
  137.  
  138.         LayoutWidget.show()
  139.  
  140.         try:
  141.             self.items[name]
  142.         except KeyError:
  143.             self.items[name] = LayoutWidget
  144.         else:
  145.             print "ERROR: Duplicate button name:", name
  146.  
  147.     def clear(self):
  148.         if len(self.items):
  149.             for x in self.items:
  150.                 self.removeChild(self.items[x])
  151.                 self.items[x].hide()
  152.  
  153.             self.items.clear()
  154.             self.resizeContents(self.width(), 0)
  155.  
  156.  
  157. class ScrollSuppliesView(QScrollView):
  158.     def __init__(self,parent = None,name = None,fl = 0):
  159.         QScrollView.__init__(self,parent,name,fl)
  160.         self.items = {}
  161.         self.setStaticBackground(True)
  162.         self.enableClipper(True)
  163.         self.viewport().setPaletteBackgroundColor(qApp.palette().color(QPalette.Active, QColorGroup.Base))
  164.  
  165.         self.pix_black = QPixmap(os.path.join(prop.image_dir, 'icon_black.png'))
  166.         self.pix_blue = QPixmap(os.path.join(prop.image_dir, 'icon_blue.png'))
  167.         self.pix_cyan = QPixmap(os.path.join(prop.image_dir, 'icon_cyan.png'))
  168.         self.pix_grey = QPixmap(os.path.join(prop.image_dir, 'icon_grey.png'))
  169.         self.pix_magenta = QPixmap(os.path.join(prop.image_dir, 'icon_magenta.png'))
  170.         self.pix_photo = QPixmap(os.path.join(prop.image_dir, 'icon_photo.png'))
  171.         self.pix_photo_cyan = QPixmap(os.path.join(prop.image_dir, 'icon_photo_cyan.png'))
  172.         self.pix_photo_magenta = QPixmap(os.path.join(prop.image_dir, 'icon_photo_magenta.png'))
  173.         self.pix_photo_yellow = QPixmap(os.path.join(prop.image_dir, 'icon_photo_yellow.png'))
  174.         self.pix_tricolor = QPixmap(os.path.join(prop.image_dir, 'icon_tricolor.png'))
  175.         self.pix_yellow = QPixmap(os.path.join(prop.image_dir, 'icon_yellow.png'))
  176.         self.pix_battery = QPixmap(os.path.join(prop.image_dir, 'icon_battery.png'))
  177.         self.pix_photo_cyan_and_photo_magenta = QPixmap(os.path.join(prop.image_dir, 'icon_photo_magenta_and_photo_cyan.png'))
  178.         self.pix_magenta_and_yellow = QPixmap(os.path.join(prop.image_dir, 'icon_magenta_and_yellow.png'))
  179.         self.pix_black_and_cyan = QPixmap(os.path.join(prop.image_dir, 'icon_black_and_cyan.png'))
  180.         self.pix_light_gray_and_photo_black = QPixmap(os.path.join(prop.image_dir, 'icon_light_grey_and_photo_black.png'))
  181.         self.pix_light_gray = QPixmap(os.path.join(prop.image_dir, 'icon_light_grey.png'))
  182.         self.pix_photo_gray = QPixmap(os.path.join(prop.image_dir, 'icon_photo_black.png'))
  183.  
  184.         self.TYPE_TO_PIX_MAP = {AGENT_TYPE_BLACK: self.pix_black,
  185.                                AGENT_TYPE_CMY: self.pix_tricolor,
  186.                                AGENT_TYPE_KCM: self.pix_photo,
  187.                                AGENT_TYPE_GGK: self.pix_grey,
  188.                                AGENT_TYPE_YELLOW: self.pix_yellow,
  189.                                AGENT_TYPE_MAGENTA: self.pix_magenta,
  190.                                AGENT_TYPE_CYAN: self.pix_cyan,
  191.                                AGENT_TYPE_CYAN_LOW: self.pix_photo_cyan,
  192.                                AGENT_TYPE_YELLOW_LOW: self.pix_photo_yellow,
  193.                                AGENT_TYPE_MAGENTA_LOW: self.pix_photo_magenta,
  194.                                AGENT_TYPE_BLUE: self.pix_blue,
  195.                                AGENT_TYPE_KCMY_CM: self.pix_grey,
  196.                                AGENT_TYPE_LC_LM: self.pix_photo_cyan_and_photo_magenta,
  197.                                AGENT_TYPE_Y_M: self.pix_magenta_and_yellow,
  198.                                AGENT_TYPE_C_K: self.pix_black_and_cyan,
  199.                                AGENT_TYPE_LG_PK: self.pix_light_gray_and_photo_black,
  200.                                AGENT_TYPE_LG: self.pix_light_gray,
  201.                                AGENT_TYPE_G: self.pix_grey,
  202.                                AGENT_TYPE_PG: self.pix_photo_gray,                             
  203.                                }
  204.  
  205.         self.row_height = 100
  206.  
  207.     def viewportResizeEvent(self, e):
  208.         for x in self.items:
  209.             self.items[x].resize(e.size().width(), self.row_height)
  210.  
  211.     def getIcon(self, agent_kind, agent_type):
  212.         if agent_kind in (AGENT_KIND_SUPPLY,
  213.                           AGENT_KIND_HEAD,
  214.                           AGENT_KIND_HEAD_AND_SUPPLY,
  215.                           AGENT_KIND_TONER_CARTRIDGE):
  216.  
  217.             return self.TYPE_TO_PIX_MAP[agent_type] 
  218.  
  219.         elif agent_kind == AGENT_KIND_INT_BATTERY:
  220.                 return self.pix_battery
  221.  
  222.  
  223.     def createBarGraph(self, percent, agent_type, w=100, h=18):
  224.         fw = w/100*percent
  225.         px = QPixmap(w, h)
  226.         pp = QPainter(px)
  227.         pp.setBackgroundMode(Qt.OpaqueMode)
  228.         pp.setPen(Qt.black)
  229.  
  230.         pp.setBackgroundColor(Qt.white)
  231.  
  232.         # erase the background
  233.         b = QBrush(QColor(Qt.white))
  234.         pp.fillRect(0, 0, w, h, b)
  235.  
  236.         # fill in the bar
  237.         if agent_type in (AGENT_TYPE_BLACK, AGENT_TYPE_UNSPECIFIED):
  238.             b = QBrush(QColor(Qt.black))
  239.             pp.fillRect(0, 0, fw, h, b)
  240.         elif agent_type == AGENT_TYPE_CMY:
  241.             h3 = h/3
  242.             b = QBrush(QColor(Qt.cyan))
  243.             pp.fillRect(0, 0, fw, h3, b)
  244.             b = QBrush(QColor(Qt.magenta))
  245.             pp.fillRect(0, h3, fw, 2*h3, b)
  246.             b = QBrush(QColor(Qt.yellow))
  247.             pp.fillRect(0, 2*h3, fw, h, b)
  248.         elif agent_type == AGENT_TYPE_KCM:
  249.             h3 = h/3
  250.             b = QBrush(QColor(Qt.cyan).light())
  251.             pp.fillRect(0, 0, fw, h3, b)
  252.             b = QBrush(QColor(Qt.magenta).light())
  253.             pp.fillRect(0, h3, fw, 2*h3, b)
  254.             b = QBrush(QColor(Qt.yellow).light())
  255.             pp.fillRect(0, 2*h3, fw, h, b)
  256.         elif agent_type == AGENT_TYPE_GGK:
  257.             b = QBrush(QColor(Qt.gray))
  258.             pp.fillRect(0, 0, fw, h, b)
  259.         elif agent_type == AGENT_TYPE_YELLOW:
  260.             b = QBrush(QColor(Qt.yellow))
  261.             pp.fillRect(0, 0, fw, h, b)
  262.         elif agent_type == AGENT_TYPE_MAGENTA:
  263.             b = QBrush(QColor(Qt.magenta))
  264.             pp.fillRect(0, 0, fw, h, b)
  265.         elif agent_type == AGENT_TYPE_CYAN:
  266.             b = QBrush(QColor(Qt.cyan))
  267.             pp.fillRect(0, 0, fw, h, b)
  268.         elif agent_type == AGENT_TYPE_CYAN_LOW:
  269.             b = QBrush(QColor(225, 246, 255))
  270.             pp.fillRect(0, 0, fw, h, b)
  271.         elif agent_type == AGENT_TYPE_YELLOW_LOW:
  272.             b = QBrush(QColor(255, 253, 225))
  273.             pp.fillRect(0, 0, fw, h, b)
  274.         elif agent_type == AGENT_TYPE_MAGENTA_LOW:
  275.             b = QBrush(QColor(255, 225, 240))
  276.             pp.fillRect(0, 0, fw, h, b)
  277.         elif agent_type == AGENT_TYPE_BLUE:
  278.             b = QBrush(QColor(0, 0, 255))
  279.             pp.fillRect(0, 0, fw, h, b)
  280.         elif agent_type == AGENT_TYPE_LG:
  281.             b = QBrush(QColor(192, 192, 192))
  282.             pp.fillRect(0, 0, fw, h, b)
  283.         elif agent_type == AGENT_TYPE_PG:
  284.             b = QBrush(QColor(128, 128, 128))
  285.             pp.fillRect(0, 0, fw, h, b)
  286.  
  287.  
  288.  
  289.         # draw black frame
  290.         pp.drawRect(0, 0, w, h)
  291.  
  292.         if percent > 75 and agent_type in \
  293.           (AGENT_TYPE_BLACK, AGENT_TYPE_UNSPECIFIED, AGENT_TYPE_BLUE):
  294.             pp.setPen(Qt.white)
  295.  
  296.         # 75% ticks
  297.         w1 = 3*w/4
  298.         h6 = h/6
  299.         pp.drawLine(w1, 0, w1, h6)
  300.         pp.drawLine(w1, h, w1, h-h6)
  301.  
  302.         if percent > 50 and agent_type in \
  303.           (AGENT_TYPE_BLACK, AGENT_TYPE_UNSPECIFIED, AGENT_TYPE_BLUE):
  304.             pp.setPen(Qt.white)
  305.  
  306.         # 50% ticks
  307.         w2 = w/2
  308.         h4 = h/4
  309.         pp.drawLine(w2, 0, w2, h4)
  310.         pp.drawLine(w2, h, w2, h-h4)
  311.  
  312.         if percent > 25 and agent_type in \
  313.           (AGENT_TYPE_BLACK, AGENT_TYPE_UNSPECIFIED, AGENT_TYPE_BLUE):
  314.             pp.setPen(Qt.white)
  315.  
  316.         # 25% ticks
  317.         w4 = w/4
  318.         pp.drawLine(w4, 0, w4, h6)
  319.         pp.drawLine(w4, h, w4, h-h6)
  320.  
  321.         return px   
  322.  
  323.  
  324.     def addItem(self, name, title_text, part_num_text, status_text, 
  325.                 agent_kind, agent_type, percent):
  326.  
  327.         num_items = len(self.items)
  328.         LayoutWidget = QWidget(self.viewport(), name)
  329.         LayoutWidget.setGeometry(QRect(0, 0, self.width(), self.row_height))
  330.         LayoutWidget.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum))
  331.         LayoutWidget.setPaletteBackgroundColor(qApp.palette().color(QPalette.Active, QColorGroup.Base))
  332.         self.addChild(LayoutWidget)
  333.  
  334.         if num_items:
  335.             self.moveChild(LayoutWidget, 0, self.row_height*num_items)
  336.  
  337.         layout = QGridLayout(LayoutWidget,1,1,10,10,"layout")
  338.         textStatus = QLabel(LayoutWidget,"textStatus")
  339.         layout.addWidget(textStatus,1,2)
  340.         pixmapLevel = QLabel(LayoutWidget,"pixmapLevel")
  341.         pixmapLevel.setSizePolicy(QSizePolicy(QSizePolicy.Fixed,QSizePolicy.Fixed,0,0,
  342.             pixmapLevel.sizePolicy().hasHeightForWidth()))
  343.  
  344.         pixmapLevel.setMinimumSize(QSize(100,20))
  345.         pixmapLevel.setMaximumSize(QSize(100,20))
  346.         layout.addWidget(pixmapLevel,2,2)
  347.         textTitle = QLabel(LayoutWidget,"textTitle")
  348.         layout.addWidget(textTitle,1,1)
  349.         textPartNo = QLabel(LayoutWidget,"textPartNo")
  350.         layout.addWidget(textPartNo,2,1)
  351.         pixmapIcon = QLabel(LayoutWidget,"pixmapIcon")
  352.         pixmapIcon.setSizePolicy(QSizePolicy(QSizePolicy.Fixed,QSizePolicy.Fixed,0,0,
  353.             pixmapIcon.sizePolicy().hasHeightForWidth()))
  354.  
  355.         pixmapIcon.setMinimumSize(QSize(32,32))
  356.         pixmapIcon.setMaximumSize(QSize(32,32))
  357.         layout.addWidget(pixmapIcon,1,0)
  358.  
  359.         if num_items:
  360.             line = QFrame(LayoutWidget,"line")
  361.             line.setFrameShadow(QFrame.Sunken)
  362.             line.setFrameShape(QFrame.HLine)
  363.             line.setPaletteBackgroundColor(qApp.palette().color(QPalette.Active, QColorGroup.Foreground))
  364.             layout.addMultiCellWidget(line,0,0,0,2)
  365.  
  366.         textTitle.setText(title_text)
  367.         textPartNo.setText(part_num_text)
  368.         textStatus.setText(status_text)
  369.  
  370.         # Bar graph level
  371.         if agent_kind in (AGENT_KIND_SUPPLY,
  372.                           #AGENT_KIND_HEAD,
  373.                           AGENT_KIND_HEAD_AND_SUPPLY,
  374.                           AGENT_KIND_TONER_CARTRIDGE,
  375.                           AGENT_KIND_MAINT_KIT,
  376.                           AGENT_KIND_ADF_KIT,
  377.                           AGENT_KIND_INT_BATTERY,
  378.                           AGENT_KIND_DRUM_KIT,
  379.                           ):
  380.  
  381.             pixmapLevel.setPixmap(self.createBarGraph(percent, agent_type))
  382.  
  383.         # Color icon
  384.         if agent_kind in (AGENT_KIND_SUPPLY,
  385.                           AGENT_KIND_HEAD,
  386.                           AGENT_KIND_HEAD_AND_SUPPLY,
  387.                           AGENT_KIND_TONER_CARTRIDGE,
  388.                           #AGENT_KIND_MAINT_KIT,
  389.                           #AGENT_KIND_ADF_KIT,
  390.                           AGENT_KIND_INT_BATTERY,
  391.                           #AGENT_KIND_DRUM_KIT,
  392.                           ):
  393.  
  394.             pix = self.getIcon(agent_kind, agent_type)
  395.  
  396.             if pix is not None:
  397.                 pixmapIcon.setPixmap(pix)
  398.  
  399.         self.resizeContents(self.width(), num_items*self.row_height*2)
  400.         LayoutWidget.show()
  401.  
  402.         try:
  403.             self.items[name]
  404.         except KeyError:
  405.             self.items[name] = LayoutWidget
  406.  
  407.  
  408.     def clear(self):
  409.         if len(self.items):
  410.             for x in self.items:
  411.                 self.removeChild(self.items[x])
  412.                 self.items[x].hide()
  413.  
  414.             self.items.clear()
  415.             self.resizeContents(self.width(), 0)
  416.  
  417.  
  418.  
  419. class IconViewItem(QIconViewItem):
  420.     def __init__(self, parent, text, pixmap, device_uri, is_avail=True):
  421.         QIconViewItem.__init__(self, parent, text, pixmap)
  422.         self.device_uri = device_uri
  423.         self.is_avail = is_avail
  424.  
  425.  
  426.  
  427. class devmgr4(DevMgr4_base):
  428.     def __init__(self, hpiod_sock, hpssd_sock, 
  429.                  cleanup=None, initial_device_uri=None,
  430.                  parent=None, name=None, fl = 0):
  431.  
  432.         DevMgr4_base.__init__(self, parent, name, fl)
  433.  
  434.         icon = QPixmap(os.path.join(prop.image_dir, 'HPmenu.png'))
  435.         self.setIcon(icon)
  436.  
  437.         log.debug("Initializing toolbox UI")
  438.         self.cleanup = cleanup
  439.         self.hpiod_sock = hpiod_sock
  440.         self.hpssd_sock = hpssd_sock
  441.  
  442.         # Make some adjustments to the UI
  443.         self.StatusHistoryList.setSorting(-1)
  444.         self.PrintJobList.setSorting(1) # Sort on job ID column
  445.         self.DeviceList.setAutoArrange(False)
  446.         self.StatusHistoryList.setColumnWidth(0, 16)
  447.         self.StatusHistoryList.setColumnText(0, ' ')
  448.         self.StatusHistoryList.setColumnWidthMode(1, QListView.Maximum)
  449.         self.StatusHistoryList.setColumnWidthMode(2, QListView.Maximum)
  450.         self.StatusHistoryList.setColumnWidthMode(3, QListView.Maximum)
  451.         self.StatusHistoryList.setColumnWidthMode(4, QListView.Maximum)
  452.         self.StatusHistoryList.setColumnWidthMode(5, QListView.Maximum)
  453.         self.StatusHistoryList.setColumnWidthMode(6, QListView.Maximum)
  454.  
  455.         self.PrintJobList.setColumnWidth(0, 150)
  456.         self.PrintJobList.setColumnWidthMode(0, QListView.Maximum)
  457.         self.PrintJobList.setColumnWidth(1, 60)
  458.         self.PrintJobList.setColumnWidthMode(1, QListView.Maximum)
  459.         self.PrintJobList.setColumnWidth(2, 80)
  460.         self.PrintJobList.setColumnWidthMode(2, QListView.Maximum)
  461.         self.PrintJobList.setColumnWidth(3, 100)
  462.         self.PrintJobList.setColumnWidthMode(3, QListView.Maximum)
  463.         self.PrintJobList.setColumnWidth(4, 200)
  464.         self.PrintJobList.setColumnWidthMode(4, QListView.Maximum)
  465.  
  466.         self.initial_device_uri = initial_device_uri
  467.  
  468.         self.warning_pix = QPixmap(os.path.join(prop.image_dir, "warning.png"))
  469.         self.error_pix = QPixmap(os.path.join(prop.image_dir, "error.png"))
  470.         self.ok_pix = QPixmap(os.path.join(prop.image_dir, "ok.png"))
  471.         self.lowink_pix = QPixmap(os.path.join(prop.image_dir, 'inkdrop.png'))
  472.         self.lowtoner_pix = QPixmap(os.path.join(prop.image_dir, 'toner.png'))
  473.         self.busy_pix = QPixmap(os.path.join(prop.image_dir, 'busy.png'))
  474.         self.lowpaper_pix = QPixmap(os.path.join(prop.image_dir, 'paper.png'))
  475.  
  476.         self.warning_pix_small = QPixmap(os.path.join(prop.image_dir, "warning_small.png"))
  477.         self.error_pix_small = QPixmap(os.path.join(prop.image_dir, "error_small.png"))
  478.         self.ok_pix_small = QPixmap(os.path.join(prop.image_dir, "ok_small.png"))
  479.         self.lowink_pix_small = QPixmap(os.path.join(prop.image_dir, 'inkdrop_small.png'))
  480.         self.lowtoner_pix_small = QPixmap(os.path.join(prop.image_dir, 'toner_small.png'))
  481.         self.busy_pix_small = QPixmap(os.path.join(prop.image_dir, 'busy_small.png'))
  482.         self.lowpaper_pix_small = QPixmap(os.path.join(prop.image_dir, 'paper_small.png'))
  483.  
  484.         self.blank_lcd = os.path.join(prop.image_dir, "panel_lcd.xpm")
  485.         self.Panel.setPixmap(QPixmap(self.blank_lcd))
  486.  
  487.         # pixmaps: (inkjet, laserjet)
  488.         self.STATUS_HISTORY_ICONS = { ERROR_STATE_CLEAR : (None, None),
  489.                                       ERROR_STATE_BUSY : (self.busy_pix_small, self.busy_pix_small),
  490.                                       ERROR_STATE_ERROR : (self.error_pix_small, self.error_pix_small),
  491.                                       ERROR_STATE_LOW_SUPPLIES : (self.lowink_pix_small, self.lowtoner_pix_small),
  492.                                       ERROR_STATE_OK : (self.ok_pix_small, self.ok_pix_small),
  493.                                       ERROR_STATE_WARNING : (self.warning_pix_small, self.warning_pix_small),
  494.                                       ERROR_STATE_LOW_PAPER: (self.lowpaper_pix_small, self.lowpaper_pix_small),
  495.                                     }
  496.  
  497.         self.STATUS_ICONS = { ERROR_STATE_CLEAR : (None, None),
  498.                               ERROR_STATE_BUSY : (self.busy_pix, self.busy_pix),
  499.                               ERROR_STATE_ERROR : (self.error_pix, self.error_pix),
  500.                               ERROR_STATE_LOW_SUPPLIES : (self.lowink_pix, self.lowtoner_pix),
  501.                               ERROR_STATE_OK : (self.ok_pix, self.ok_pix),
  502.                               ERROR_STATE_WARNING : (self.warning_pix, self.warning_pix),
  503.                               ERROR_STATE_LOW_PAPER: (self.lowpaper_pix, self.lowpaper_pix),
  504.                             }
  505.  
  506.         self.JOB_STATES = { 3 : self.__tr("Pending"),
  507.                             4 : self.__tr("On hold"),
  508.                             5 : self.__tr("Printing"),
  509.                             6 : self.__tr("Stopped"),
  510.                             7 : self.__tr("Canceled"),
  511.                             8 : self.__tr("Aborted"),
  512.                             9 : self.__tr("Completed"),
  513.                            }
  514.  
  515.         self.email_alerts = utils.to_bool(user_cfg.alerts.email_alerts) or False
  516.         self.email_to_addresses = user_cfg.alerts.email_to_addresses
  517.         self.email_from_address = user_cfg.alerts.email_from_address
  518.         self.auto_refresh = utils.to_bool(user_cfg.refresh.enable) or False
  519.  
  520.         try:
  521.             self.auto_refresh_rate = int(user_cfg.refresh.rate)
  522.         except ValueError:    
  523.             self.auto_refresh_rate = DEF_AUTO_REFRESH_RATE
  524.             
  525.         try:
  526.             self.auto_refresh_type = int(user_cfg.refresh.type)
  527.         except ValueError:
  528.             self.auto_refresh_type = 0 # refresh 1 (1=refresh all)
  529.  
  530.         cmd_print, cmd_scan, cmd_pcard, \
  531.             cmd_copy, cmd_fax, cmd_fab = utils.deviceDefaultFunctions()
  532.  
  533.         self.cmd_print = user_cfg.commands.prnt or cmd_print
  534.         self.cmd_scan = user_cfg.commands.scan or cmd_scan
  535.         self.cmd_pcard = user_cfg.commands.pcard or cmd_pcard
  536.         self.cmd_copy = user_cfg.commands.cpy or cmd_copy
  537.         self.cmd_fax = user_cfg.commands.fax or cmd_fax
  538.         self.cmd_fab = user_cfg.commands.fab or cmd_fab
  539.  
  540.         log.debug("HPLIP Version: %s" % sys_cfg.hplip.version)
  541.         log.debug("Print command: %s" % self.cmd_print)
  542.         log.debug("PCard command: %s" % self.cmd_pcard)
  543.         log.debug("Fax command: %s" % self.cmd_fax)
  544.         log.debug("FAB command: %s" % self.cmd_fab)
  545.         log.debug("Copy command: %s " % self.cmd_copy)
  546.         log.debug("Scan command: %s" % self.cmd_scan)
  547.         log.debug("Email alerts: %s" % self.email_alerts)
  548.         log.debug("Email to address(es): %s" % self.email_to_addresses)
  549.         log.debug("Email from address: %s" % self.email_from_address)
  550.         log.debug("Auto refresh: %s" % self.auto_refresh)
  551.         log.debug("Auto refresh rate: %s" % self.auto_refresh_rate)
  552.         log.debug("Auto refresh type: %s" % self.auto_refresh_type)
  553.  
  554.         if not self.auto_refresh:
  555.             self.autoRefresh.toggle()
  556.  
  557.         self.cur_device_uri = '' # Device URI
  558.         self.devices = {}    # { Device_URI : device.Device(), ... }
  559.         self.device_vars = {}
  560.         self.num_devices = 0
  561.         self.cur_device = None
  562.         self.rescanning = False
  563.  
  564.         # Add Scrolling Maintenance (Tools)
  565.         self.ToolList = ScrollToolView(self.MaintTab, "ToolView")
  566.         MaintTabLayout = QGridLayout(self.MaintTab,1,1,11,6,"MaintTabLayout")
  567.         MaintTabLayout.addWidget(self.ToolList,0,0)
  568.  
  569.         # Add Scrolling Supplies 
  570.         self.SuppliesList = ScrollSuppliesView(self.SuppliesTab, "SuppliesView")
  571.         SuppliesTabLayout = QGridLayout(self.SuppliesTab,1,1,11,6,"SuppliesTabLayout")
  572.         self.SuppliesList.setHScrollBarMode(QScrollView.AlwaysOff)
  573.         SuppliesTabLayout.addWidget(self.SuppliesList,0,0)
  574.  
  575.         QTimer.singleShot(0, self.InitialUpdate)
  576.  
  577.  
  578.     def InitialUpdate(self):
  579.         self.RescanDevices()
  580.  
  581.         self.refresh_timer = QTimer(self, "RefreshTimer")
  582.         self.connect(self.refresh_timer, SIGNAL('timeout()'), self.TimedRefresh)
  583.  
  584.         if MIN_AUTO_REFRESH_RATE <= self.auto_refresh_rate <= MAX_AUTO_REFRESH_RATE:
  585.             self.refresh_timer.start(self.auto_refresh_rate * 60000)
  586.  
  587.  
  588.     def TimedRefresh(self):
  589.         if self.auto_refresh:
  590.             log.debug("Refresh timer...")
  591.             self.CleanupChildren()
  592.             
  593.             if self.auto_refresh_type == 0:
  594.                 self.UpdateDevice()
  595.             else:
  596.                 self.RescanDevices()
  597.  
  598.     def autoRefresh_toggled(self,a0):
  599.         self.auto_refresh = bool(a0)
  600.         self.SaveConfig()
  601.  
  602.  
  603.     def closeEvent(self, event):
  604.         self.Cleanup()
  605.         event.accept()
  606.  
  607.  
  608.     def RescanDevices(self):
  609.         self.deviceRefreshAll.setEnabled(False)
  610.         self.deviceRescanAction.setEnabled(False)
  611.         self.DeviceListRefresh()
  612.         self.deviceRescanAction.setEnabled(True)
  613.         self.deviceRefreshAll.setEnabled(True)
  614.  
  615.  
  616.     def Cleanup(self):
  617.         self.CleanupChildren()
  618.         if self.cleanup is not None:
  619.             self.cleanup()
  620.  
  621.  
  622.     def CleanupChildren(self):
  623.         log.debug("Cleaning up child processes.")
  624.         try:
  625.             os.waitpid(-1, os.WNOHANG)
  626.         except OSError:
  627.             pass
  628.  
  629.  
  630.     def DeviceList_currentChanged(self,a0):
  631.         self.cur_device_uri = self.DeviceList.currentItem().device_uri
  632.         self.cur_device = self.devices[self.cur_device_uri]
  633.  
  634.         self.UpdateDevice()
  635.  
  636.  
  637.     def DeviceList_rightButtonClicked(self, item, pos):
  638.         popup = QPopupMenu(self)
  639.  
  640.         if item is not None:
  641.             if self.cur_device.error_state not in (ERROR_STATE_BUSY, ERROR_STATE_ERROR):
  642.                 popup.insertItem(self.__tr("Print..."), self.PrintButton_clicked)
  643.  
  644.                 if self.cur_device.scan_type:
  645.                     popup.insertItem(self.__tr("Scan..."), self.ScanButton_clicked)
  646.  
  647.                 if self.cur_device.pcard_type:
  648.                     popup.insertItem(self.__tr("Access Photo Cards..."), self.PCardButton_clicked)
  649.  
  650.                 if self.cur_device.fax_type:
  651.                     popup.insertItem(self.__tr("Send Fax..."), self.SendFaxButton_clicked)
  652.  
  653.                 if self.cur_device.copy_type:
  654.                     popup.insertItem(self.__tr("Make Copies..."), self.MakeCopiesButton_clicked)
  655.  
  656.                 popup.insertSeparator()
  657.  
  658.             if self.cur_device.device_settings_ui is not None:
  659.                 popup.insertItem(self.__tr("Device Settings..."), self.deviceSettingsButton_clicked)
  660.  
  661.             popup.insertItem(self.__tr("Refresh Device"), self.UpdateDevice)
  662.  
  663.         popup.insertItem(self.__tr("Refresh All"), self.deviceRefreshAll_activated)
  664.  
  665.         popup.popup(pos)
  666.  
  667.  
  668.     def UpdateDevice(self, check_state=True):
  669.         log.debug(utils.bold("Update: %s %s %s" % ("*"*20, self.cur_device_uri, "*"*20)))
  670.         self.setCaption("%s - HP Device Manager" % self.cur_device.model_ui)
  671.         if not self.rescanning:
  672.             self.statusBar().message(self.cur_device_uri)
  673.  
  674.         if self.cur_device.supported and check_state and not self.rescanning:
  675.             QApplication.setOverrideCursor(QApplication.waitCursor)
  676.             result_code = ERROR_DEVICE_NOT_FOUND
  677.  
  678.             try:
  679.                 try:
  680.                     self.cur_device.open()
  681.                 except Error, e:
  682.                     log.warn(e.msg)
  683.  
  684.                 if self.cur_device.device_state == DEVICE_STATE_NOT_FOUND:
  685.                     self.cur_device.error_state = ERROR_STATE_ERROR
  686.                 else:
  687.                     try:
  688.                         self.cur_device.queryDevice()
  689.                     except Error, e:
  690.                         log.error("Query device error (%s)." % e.msg)
  691.                         self.cur_device.error_state = ERROR_STATE_ERROR
  692.  
  693.             finally:
  694.                 self.cur_device.close()
  695.                 QApplication.restoreOverrideCursor()
  696.  
  697.             log.debug("Device state = %d" % self.cur_device.device_state)
  698.             log.debug("Status code = %d" % self.cur_device.status_code)
  699.             log.debug("Error state = %d" % self.cur_device.error_state)
  700.  
  701.             icon = self.CreatePixmap()
  702.             self.DeviceList.currentItem().setPixmap(icon)
  703.  
  704.         if not self.rescanning: 
  705.             self.UpdateHistory()
  706.             self.UpdateTabs()
  707.  
  708.  
  709.     def CreatePixmap(self):
  710.         d = self.cur_device
  711.         try:
  712.             pix = QPixmap(os.path.join(prop.image_dir, d.icon))
  713.         except AttributeError:
  714.             pix = QPixmap(os.path.join(prop.image_dir, 'default_printer.png'))
  715.  
  716.         error_state = d.error_state
  717.         icon = QPixmap(pix.width(), pix.height())
  718.         p = QPainter(icon)
  719.         p.eraseRect(0, 0, icon.width(), icon.height())
  720.         p.drawPixmap(0, 0, pix)
  721.  
  722.         try:
  723.             tech_type = d.tech_type
  724.         except AttributeError:
  725.             tech_type = TECH_TYPE_NONE
  726.  
  727.         if error_state != ERROR_STATE_CLEAR:
  728.             if tech_type in (TECH_TYPE_COLOR_INK, TECH_TYPE_MONO_INK):
  729.                 status_icon = self.STATUS_HISTORY_ICONS[error_state][0] # ink
  730.             else:
  731.                 status_icon = self.STATUS_HISTORY_ICONS[error_state][1] # laser
  732.  
  733.             if status_icon is not None:
  734.                 p.drawPixmap(0, 0, status_icon)
  735.  
  736.         p.end()
  737.  
  738.         return icon
  739.  
  740.  
  741.     def DeviceListRefresh(self):
  742.         log.debug("Rescanning device list...")
  743.         QApplication.setOverrideCursor(QApplication.waitCursor)
  744.         if not self.rescanning:
  745.             self.rescanning = True
  746.             self.DeviceList.clear()
  747.             self.devices.clear()
  748.             self.supported_devices = device.getSupportedCUPSDevices()
  749.             log.debug(self.supported_devices)
  750.             self.num_devices = len(self.supported_devices)
  751.             self.devices.clear()
  752.             self.device_num = 0
  753.  
  754.             if self.num_devices > 0:
  755.                 self.pb = QProgressBar(self.statusBar(), 'ProgressBar')
  756.                 self.pb.setTotalSteps(self.num_devices)
  757.                 self.statusBar().addWidget(self.pb)
  758.                 self.pb.show()
  759.  
  760.                 self.scan_timer = QTimer(self, "ScanTimer")
  761.                 self.connect(self.scan_timer, SIGNAL('timeout()'),
  762.                               self.ContinueDeviceListRefresh)
  763.  
  764.                 self.__NextDevice = self.__GetNextDevice()
  765.                 self.scan_timer.start(0)
  766.             else:
  767.                 dlg = NoDevicesForm(self)
  768.                 dlg.exec_loop()
  769.                 self.close()
  770.  
  771.     def __GetNextDevice(self):
  772.         for d in self.supported_devices:
  773.             yield d, self.supported_devices[d]
  774.  
  775.  
  776.     def ContinueDeviceListRefresh(self):
  777.         try:
  778.             self.cur_device_uri, cups_printer_list = \
  779.                 self.__NextDevice.next()
  780.         except StopIteration:
  781.  
  782.             self.scan_timer.stop()
  783.             self.disconnect(self.scan_timer, SIGNAL('timeout()'),
  784.                              self.ContinueDeviceListRefresh)
  785.  
  786.             self.scan_timer = None
  787.             del self.scan_timer
  788.  
  789.             self.pb.hide()
  790.             self.statusBar().removeWidget(self.pb)
  791.  
  792.             self.DeviceList.adjustItems()
  793.             self.DeviceList.updateGeometry()
  794.             self.DeviceList.setCurrentItem(self.DeviceList.firstItem())
  795.             self.rescanning = False
  796.  
  797.             QApplication.restoreOverrideCursor()
  798.  
  799.             if self.num_devices:
  800.                 self.UpdateDevice()
  801.  
  802.             else: # == 0:
  803.                 self.deviceRescanAction.setEnabled(False)
  804.                 dlg = NoDevicesForm(self, "", True)
  805.                 dlg.show()
  806.  
  807.         else:
  808.             self.pb.setProgress(self.device_num)
  809.             self.device_num += 1
  810.  
  811.             log.debug(utils.bold("Refresh: %s %s %s" % \
  812.                 ("*"*20, self.cur_device_uri, "*"*20)))
  813.  
  814.             try:
  815.                 self.cur_device = device.Device(self.cur_device_uri,
  816.                                                 hpiod_sock=self.hpiod_sock,
  817.                                                 hpssd_sock=self.hpssd_sock,
  818.                                                 callback=self.callback)
  819.             except Error:
  820.                 log.error("Unexpected error in Device class.")
  821.                 log.exception()
  822.                 return
  823.  
  824.             result_code = ERROR_DEVICE_NOT_FOUND
  825.  
  826.             try:
  827.                 try:
  828.                     self.cur_device.open()
  829.                     self.cur_device.error_state = ERROR_STATE_CLEAR
  830.                 except Error, e:
  831.                     log.warn(e.msg)
  832.  
  833.                 if self.cur_device.device_state == DEVICE_STATE_NOT_FOUND:
  834.                     self.cur_device.error_state = ERROR_STATE_ERROR
  835.  
  836.             finally:
  837.                 self.cur_device.close()
  838.  
  839.             self.CheckForDeviceSettingsUI()
  840.  
  841.             icon = self.CreatePixmap()
  842.             i = IconViewItem(self.DeviceList, self.cur_device.model_ui,
  843.                               icon, self.cur_device_uri)
  844.  
  845.             self.devices[self.cur_device_uri] = self.cur_device
  846.  
  847.             self.DeviceList.setCurrentItem(i)
  848.  
  849.     def callback(self):
  850.         pass
  851.  
  852.     def CheckForDeviceSettingsUI(self):
  853.         self.cur_device.device_settings_ui = None
  854.         name = '.'.join(['plugins', self.cur_device.model])
  855.         log.debug("Attempting to load plugin: %s" % name)
  856.         try:
  857.             mod = __import__(name, globals(), locals(), [])
  858.         except ImportError:
  859.             log.debug("No plugin found.")
  860.             return
  861.         else:
  862.             components = name.split('.')
  863.             for c in components[1:]:
  864.                 mod = getattr(mod, c)
  865.             log.debug("Loaded: %s" % repr(mod))
  866.             self.cur_device.device_settings_ui = mod.settingsUI
  867.  
  868.  
  869.     def ActivateDevice(self, device_uri):
  870.         log.debug(utils.bold("Activate: %s %s %s" % ("*"*20, device_uri, "*"*20)))
  871.         d = self.DeviceList.firstItem()
  872.         found = False
  873.  
  874.         while d is not None:
  875.  
  876.             if d.device_uri == device_uri:
  877.                 found = True
  878.                 self.DeviceList.setSelected(d, True)
  879.                 self.Tabs.setCurrentPage(0)
  880.                 break
  881.  
  882.             d = d.nextItem()
  883.  
  884.         return found
  885.  
  886.  
  887.     def UpdatePrintJobsTab(self):
  888.         self.PrintJobList.clear()
  889.         num_jobs = 0
  890.  
  891.         if self.cur_device.supported:
  892.             jobs = cups.getJobs()
  893.  
  894.             for j in jobs:
  895.                 if j.dest in self.cur_device.cups_printers:
  896.  
  897.                     JobListViewItem(self.PrintJobList, j.dest, j.id,
  898.                                      self.JOB_STATES[j.state], j.user, j.title)
  899.  
  900.                     num_jobs += 1
  901.  
  902.         self.CancelPrintJobButton.setEnabled(num_jobs > 0)
  903.  
  904.  
  905.     def PrintJobList_currentChanged(self, item):
  906.         pass
  907.  
  908.  
  909.     def PrintJobList_selectionChanged(self, a0):
  910.         pass
  911.  
  912.  
  913.     def CancelPrintJobButton_clicked(self):
  914.         item = self.PrintJobList.currentItem()
  915.         if item is not None:
  916.             self.cur_device.cancelJob(item.job_id)
  917.  
  918.  
  919.     def UpdateTabs(self):
  920.         self.UpdateFunctionsTab()
  921.         self.UpdateStatusTab()
  922.         self.UpdateSuppliesTab()
  923.         self.UpdateMaintTab()
  924.         self.UpdatePrintJobsTab()
  925.         self.UpdatePanelTab()
  926.  
  927.  
  928.     def UpdatePanelTab(self):
  929.         dq = self.cur_device.dq
  930.  
  931.         if dq.get('panel', 0) == 1:
  932.             line1 = dq.get('panel-line1', '')
  933.             line2 = dq.get('panel-line2', '')
  934.         else:
  935.             line1 = self.__tr("Front panel display")
  936.             line2 = self.__tr("not available.")
  937.  
  938.         pm = QPixmap(self.blank_lcd)
  939.  
  940.         p = QPainter()
  941.         p.begin(pm)
  942.         p.setPen(QColor(0, 0, 0))
  943.         p.setFont(self.font())
  944.  
  945.         x, y_line1, y_line2 = 10, 17, 33
  946.  
  947.         # TODO: Scroll long lines
  948.         p.drawText(x, y_line1, line1)
  949.         p.drawText(x, y_line2, line2)
  950.         p.end()
  951.  
  952.         self.Panel.setPixmap(pm)
  953.  
  954.  
  955.     def UpdateFunctionsTab(self):
  956.         self.ToggleFunctionButtons(self.cur_device.device_state in \
  957.             (DEVICE_STATE_FOUND, DEVICE_STATE_JUST_FOUND))
  958.  
  959.  
  960.     def ToggleFunctionButtons(self, toggle):
  961.         if toggle:
  962.             self.PrintButton.setEnabled(True)
  963.             self.ScanButton.setEnabled(self.cur_device.scan_type)
  964.             self.PCardButton.setEnabled(self.cur_device.pcard_type)
  965.             self.SendFaxButton.setEnabled(self.cur_device.fax_type)
  966.             self.MakeCopiesButton.setEnabled(self.cur_device.copy_type)
  967.         else:
  968.             self.PrintButton.setEnabled(False)
  969.             self.ScanButton.setEnabled(False)
  970.             self.PCardButton.setEnabled(False)
  971.             self.SendFaxButton.setEnabled(False)
  972.             self.MakeCopiesButton.setEnabled(False)
  973.  
  974.  
  975.     def UpdateHistory(self):
  976.         try:
  977.             self.cur_device.hist = self.cur_device.queryHistory()
  978.             self.cur_device.hist.reverse()
  979.         except Error:
  980.             log.error("History query failed.")
  981.             self.cur_device.last_event = None
  982.             self.cur_device.error_state = ERROR_STATE_ERROR
  983.             self.cur_device.status_code = STATUS_UNKNOWN
  984.         else:
  985.             try:
  986.                 self.cur_device.last_event = self.cur_device.hist[-1]
  987.             except IndexError:
  988.                 self.cur_device.last_event = None
  989.                 self.cur_device.error_state = ERROR_STATE_ERROR
  990.                 self.cur_device.status_code = STATUS_UNKNOWN
  991.  
  992.  
  993.     def UpdateStatusTab(self):
  994.         self.StatusHistoryList.clear()
  995.         d = self.cur_device
  996.  
  997.         for x in d.hist:
  998.             job_id, code = x[9], x[11]
  999.  
  1000.             if job_id == 0:
  1001.                 i = QListViewItem(self.StatusHistoryList, '',
  1002.                                    time.strftime("%x", x[:9]),
  1003.                                    time.strftime("%H:%M:%S", x[:9]),
  1004.                                    '', '', str(code), x[12])
  1005.  
  1006.             else:
  1007.                 i = QListViewItem(self.StatusHistoryList, '',
  1008.                                time.strftime("%x", x[:9]),
  1009.                                time.strftime("%H:%M:%S", x[:9]),
  1010.                                x[10], str(job_id), str(code), x[12])
  1011.  
  1012.             error_state = STATUS_TO_ERROR_STATE_MAP.get(code, ERROR_STATE_CLEAR)
  1013.  
  1014.             try:
  1015.                 tech_type = d.tech_type
  1016.             except AttributeError:
  1017.                 tech_type = TECH_TYPE_NONE
  1018.  
  1019.             if error_state != ERROR_STATE_CLEAR:
  1020.                 if tech_type in (TECH_TYPE_COLOR_INK, TECH_TYPE_MONO_INK):
  1021.                     status_pix = self.STATUS_HISTORY_ICONS[error_state][0] # ink
  1022.                 else:
  1023.                     status_pix = self.STATUS_HISTORY_ICONS[error_state][1] # laser
  1024.  
  1025.                 if status_pix is not None:
  1026.                     i.setPixmap(0, status_pix)
  1027.  
  1028.         if d.last_event is not None:
  1029.             self.StatusText.setText(d.last_event[12])
  1030.             self.StatusText2.setText(d.last_event[13])
  1031.  
  1032.             error_state = STATUS_TO_ERROR_STATE_MAP.get(d.last_event[11], ERROR_STATE_CLEAR)
  1033.  
  1034.             if error_state != ERROR_STATE_CLEAR:
  1035.                 if tech_type in (TECH_TYPE_COLOR_INK, TECH_TYPE_MONO_INK):
  1036.                     status_icon = self.STATUS_ICONS[error_state][0] # ink
  1037.                 else:
  1038.                     status_icon = self.STATUS_ICONS[error_state][1] # laser
  1039.  
  1040.                 if status_icon is not None:
  1041.                     self.StatusIcon.setPixmap(status_icon)
  1042.                 else:
  1043.                     self.StatusIcon.clear()
  1044.             else:
  1045.                 self.StatusIcon.clear()
  1046.  
  1047.  
  1048.     def UpdateSuppliesTab(self):
  1049.         self.SuppliesList.clear()
  1050.  
  1051.         if self.cur_device.supported and \
  1052.             self.cur_device.status_type != STATUS_TYPE_NONE:
  1053.  
  1054.             a = 1
  1055.             while True:
  1056.  
  1057.                 try:
  1058.                     agent_type = int(self.cur_device.dq['agent%d-type' % a])
  1059.                 except KeyError:
  1060.                     break
  1061.                 else:
  1062.                     agent_kind = int(self.cur_device.dq['agent%d-kind' % a])
  1063.                     agent_health = int(self.cur_device.dq['agent%d-health' % a])
  1064.                     agent_level = int(self.cur_device.dq['agent%d-level' % a])
  1065.                     agent_sku = str(self.cur_device.dq['agent%d-sku' % a])
  1066.                     agent_desc = self.cur_device.dq['agent%d-desc' % a]
  1067.                     agent_health_desc = self.cur_device.dq['agent%d-health-desc' % a]
  1068.  
  1069.                     self.SuppliesList.addItem("agent %d" % a, "<b>"+agent_desc+"</b>",
  1070.                                               agent_sku, agent_health_desc, 
  1071.                                               agent_kind, agent_type, agent_level) 
  1072.  
  1073.                 a += 1
  1074.  
  1075.  
  1076.     def UpdateMaintTab(self):
  1077.         self.ToolList.clear()
  1078.  
  1079.         if self.cur_device.supported and \
  1080.             self.cur_device.device_state in (DEVICE_STATE_FOUND, DEVICE_STATE_JUST_FOUND):
  1081.  
  1082.             self.ToolList.addItem( "cups", self.__tr("<b>Configure Print Settings</b>"), 
  1083.                 QPixmap(os.path.join(prop.image_dir, 'icon_cups.png')), 
  1084.                 self.__tr("Use this interface to configure printer settings such as print quality, print mode, paper size, etc. (Note: This may not work on all operating systems)"), 
  1085.                 self.__tr("Configure..."), 
  1086.                 self.ConfigurePrintSettings_clicked)
  1087.  
  1088.             if self.cur_device.device_settings_ui is not None:
  1089.                 self.ToolList.addItem( "device_settings", self.__tr("<b>Device Settings</b>"), 
  1090.                     QPixmap(os.path.join(prop.image_dir, 'icon_settings.png')), 
  1091.                     self.__tr("Your device has special device settings. You may alter these settings here."), 
  1092.                     self.__tr("Device Settings..."), 
  1093.                     self.deviceSettingsButton_clicked)
  1094.                 self.setupDevice.setEnabled(True)
  1095.             else:
  1096.                 self.setupDevice.setEnabled(False)
  1097.  
  1098.             if self.cur_device.fax_type:
  1099.                 self.ToolList.addItem( "fax_settings", self.__tr("<b>Fax Setup</b>"), 
  1100.                     QPixmap(os.path.join(prop.image_dir, 'icon_fax.png')), 
  1101.                     self.__tr("Fax support must be setup before you can send faxes."), 
  1102.                     self.__tr("Setup Fax..."), 
  1103.                     self.faxSettingsButton_clicked)
  1104.  
  1105.             self.ToolList.addItem( "testpage", self.__tr("<b>Print Test Page</b>"), 
  1106.                 QPixmap(os.path.join(prop.image_dir, 'icon_testpage.png')), 
  1107.                 self.__tr("Print a test page to test the setup of your printer."), 
  1108.                 self.__tr("Print Test Page..."), 
  1109.                 self.PrintTestPageButton_clicked)
  1110.  
  1111.  
  1112.             self.ToolList.addItem( "info", self.__tr("<b>View Device Information</b>"), 
  1113.                 QPixmap(os.path.join(prop.image_dir, 'icon_info.png')), 
  1114.                 self.__tr("This information is primarily useful for debugging and troubleshooting."), 
  1115.                 self.__tr("View Information..."), 
  1116.                 self.viewInformation) 
  1117.  
  1118.             if self.cur_device.pq_diag_type:
  1119.                 self.ToolList.addItem( "pqdiag", self.__tr("<b>Print Quality Diagnostics</b>"), 
  1120.                     QPixmap(os.path.join(prop.image_dir, 'icon_pq_diag.png')),
  1121.                     self.__tr("Your printer can print a test page to help diagnose print quality problems."), 
  1122.                     self.__tr("Print Diagnostic Page..."), 
  1123.                     self.pqDiag)
  1124.  
  1125.             if self.cur_device.clean_type:
  1126.                 self.ToolList.addItem( "clean", self.__tr("<b>Clean Cartridges</b>"), 
  1127.                     QPixmap(os.path.join(prop.image_dir, 'icon_clean.png')), 
  1128.                     self.__tr("You only need to perform this action if you are having problems with poor printout quality due to clogged ink nozzles."), 
  1129.                     self.__tr("Clean Cartridges..."), 
  1130.                     self.CleanPensButton_clicked)
  1131.  
  1132.             if self.cur_device.align_type:
  1133.                 self.ToolList.addItem( "align", self.__tr("<b>Align Cartridges</b>"), 
  1134.                     QPixmap(os.path.join(prop.image_dir, 'icon_align.png')), 
  1135.                     self.__tr("This will improve the quality of output when a new cartridge is installed."), 
  1136.                     self.__tr("Align Cartridges..."), 
  1137.                     self.AlignPensButton_clicked)
  1138.  
  1139.             if self.cur_device.color_cal_type:
  1140.                 self.ToolList.addItem( "colorcal", self.__tr("<b>Perform Color Calibration</b>"), 
  1141.                     QPixmap(os.path.join(prop.image_dir, 'icon_colorcal.png')), 
  1142.                     self.__tr("Use this procedure to optimimize your printer's color output."), 
  1143.                     self.__tr("Color Calibration..."), 
  1144.                     self.ColorCalibrationButton_clicked)
  1145.  
  1146.             if self.cur_device.linefeed_cal_type:
  1147.                 self.ToolList.addItem( "linefeed", self.__tr("<b>Perform Line Feed Calibration</b>"), 
  1148.                     QPixmap(os.path.join(prop.image_dir, 'icon_linefeed_cal.png')),
  1149.                     self.__tr("Use line feed calibration to optimize print quality (to remove gaps in the printed output)."), 
  1150.                     self.__tr("Line Feed Calibration..."), 
  1151.                     self.linefeedCalibration) 
  1152.  
  1153.             if self.cur_device.embedded_server_type and self.cur_device.bus == 'net':
  1154.                 self.ToolList.addItem( "ews", self.__tr("<b>Access Embedded Web Page</b>"), 
  1155.                     QPixmap(os.path.join(prop.image_dir, 'icon_ews.png')), 
  1156.                     self.__tr("You can use your printer's embedded web server to configure, maintain, and monitor the device from a web browser. <i>This feature is only available if the device is connected via the network.</i>"),
  1157.                     self.__tr("Open in Browser..."), 
  1158.                     self.OpenEmbeddedBrowserButton_clicked)
  1159.  
  1160.         self.ToolList.addItem("support",  self.__tr("<b>View Support Information</b>"), 
  1161.             QPixmap(os.path.join(prop.image_dir, 'icon_support2.png')), 
  1162.             self.__tr("View available support resources."), 
  1163.             self.__tr("View Support..."), 
  1164.             self.viewSupport) 
  1165.  
  1166.  
  1167.     def viewSupportAction_activated(self):
  1168.         self.viewSupport()
  1169.  
  1170.     def ConfigurePrintSettings_clicked(self):
  1171.         utils.openURL("http://localhost:631/printers")
  1172.  
  1173.     def viewInformation(self):
  1174.         InformationForm(self.cur_device, self).exec_loop()
  1175.  
  1176.     def viewSupport(self):
  1177.         SupportForm(self).exec_loop()
  1178.  
  1179.     def pqDiag(self):
  1180.         d = self.cur_device
  1181.         ok = False;
  1182.         pq_diag = d.pq_diag_type
  1183.  
  1184.         try:
  1185.             QApplication.setOverrideCursor(QApplication.waitCursor)
  1186.             d.open()
  1187.  
  1188.             if d.isIdleAndNoError():
  1189.                 QApplication.restoreOverrideCursor()
  1190.  
  1191.                 if pq_diag == 1:
  1192.                     maint.printQualityDiagType1(d, self.LoadPaperUI)
  1193.  
  1194.             else:
  1195.                 self.CheckDeviceUI()
  1196.  
  1197.         finally:
  1198.             d.close()
  1199.             QApplication.restoreOverrideCursor()
  1200.  
  1201.  
  1202.  
  1203.     def linefeedCalibration(self):
  1204.         d = self.cur_device
  1205.         ok = False;
  1206.         linefeed_type = d.linefeed_cal_type
  1207.  
  1208.         try:
  1209.             QApplication.setOverrideCursor(QApplication.waitCursor)
  1210.             d.open()
  1211.  
  1212.             if d.isIdleAndNoError():
  1213.                 QApplication.restoreOverrideCursor()
  1214.  
  1215.                 if linefeed_type == 1:
  1216.                     maint.linefeedCalType1(d, self.LoadPaperUI)
  1217.  
  1218.             else:
  1219.                 self.CheckDeviceUI()
  1220.  
  1221.         finally:
  1222.             d.close()
  1223.             QApplication.restoreOverrideCursor()
  1224.  
  1225.  
  1226.  
  1227.     def ConfigurePrintSettings_clicked(self):
  1228.         utils.openURL("http://localhost:631/printers")
  1229.  
  1230.     def viewInformation(self):
  1231.         InformationForm(self.cur_device, self).exec_loop()
  1232.  
  1233.     def viewSupport(self):
  1234.         SupportForm(self).exec_loop()
  1235.  
  1236.     def pqDiag(self):
  1237.         d = self.cur_device
  1238.         ok = False;
  1239.         pq_diag = d.pq_diag_type
  1240.  
  1241.         try:
  1242.             QApplication.setOverrideCursor(QApplication.waitCursor)
  1243.             d.open()
  1244.  
  1245.             if d.isIdleAndNoError():
  1246.                 QApplication.restoreOverrideCursor()
  1247.  
  1248.                 if pq_diag == 1:
  1249.                     maint.printQualityDiagType1(d, self.LoadPaperUI)
  1250.  
  1251.             else:
  1252.                 self.CheckDeviceUI()
  1253.  
  1254.         finally:
  1255.             d.close()
  1256.             QApplication.restoreOverrideCursor()
  1257.  
  1258.  
  1259.  
  1260.     def linefeedCalibration(self):
  1261.         d = self.cur_device
  1262.         ok = False;
  1263.         linefeed_type = d.linefeed_cal_type
  1264.  
  1265.         try:
  1266.             QApplication.setOverrideCursor(QApplication.waitCursor)
  1267.             d.open()
  1268.  
  1269.             if d.isIdleAndNoError():
  1270.                 QApplication.restoreOverrideCursor()
  1271.  
  1272.                 if linefeed_type == 1:
  1273.                     maint.linefeedCalType1(d, self.LoadPaperUI)
  1274.  
  1275.             else:
  1276.                 self.CheckDeviceUI()
  1277.  
  1278.         finally:
  1279.             d.close()
  1280.             QApplication.restoreOverrideCursor()
  1281.  
  1282.  
  1283.     def EventUI(self, event_code, event_type,
  1284.                  error_string_short, error_string_long,
  1285.                  retry_timeout, job_id, device_uri):
  1286.  
  1287.         log.debug("Event: code=%d type=%s string=%s timeout=%d id=%d uri=%s" %
  1288.                  (event_code, event_type,  error_string_short, retry_timeout, job_id, device_uri))
  1289.  
  1290.  
  1291.         if self.ActivateDevice(device_uri):
  1292.             self.cur_device.status_code = event_code
  1293.             self.UpdateDevice(False)
  1294.             self.Tabs.setCurrentPage(1)
  1295.  
  1296.  
  1297.     def settingsConfigure_activated(self, tab_to_show=0):
  1298.         dlg = SettingsDialog(self.hpssd_sock, self)
  1299.  
  1300.         dlg.autoRefreshCheckBox.setChecked(self.auto_refresh)
  1301.         dlg.AutoRefreshRate.setValue(self.auto_refresh_rate) # min
  1302.         dlg.refreshScopeButtonGroup.setButton(self.auto_refresh_type)
  1303.         dlg.auto_refresh_type = self.auto_refresh_type
  1304.  
  1305.         dlg.EmailCheckBox.setChecked(self.email_alerts)
  1306.         dlg.EmailAddress.setText(self.email_to_addresses)
  1307.         dlg.senderLineEdit.setText(self.email_from_address)
  1308.  
  1309.         dlg.PrintCommand.setText(self.cmd_print)
  1310.         dlg.ScanCommand.setText(self.cmd_scan)
  1311.         dlg.AccessPCardCommand.setText(self.cmd_pcard)
  1312.         dlg.SendFaxCommand.setText(self.cmd_fax)
  1313.         dlg.MakeCopiesCommand.setText(self.cmd_copy)
  1314.  
  1315.  
  1316.         dlg.TabWidget.setCurrentPage(tab_to_show)
  1317.  
  1318.         if dlg.exec_loop() == QDialog.Accepted:
  1319.  
  1320.             self.cmd_print = str(dlg.PrintCommand.text())
  1321.             self.cmd_scan = str(dlg.ScanCommand.text())
  1322.             self.cmd_pcard = str(dlg.AccessPCardCommand.text())
  1323.             self.cmd_fax   = str(dlg.SendFaxCommand.text())
  1324.             self.cmd_copy  = str(dlg.MakeCopiesCommand.text())
  1325.  
  1326.  
  1327.             self.email_alerts = bool(dlg.EmailCheckBox.isChecked())
  1328.             self.email_to_addresses = str(dlg.EmailAddress.text())
  1329.             self.email_from_address = str(dlg.senderLineEdit.text())
  1330.  
  1331.             old_auto_refresh = self.auto_refresh
  1332.             self.auto_refresh = bool(dlg.autoRefreshCheckBox.isChecked())
  1333.             new_refresh_value = int(dlg.AutoRefreshRate.value())
  1334.             self.auto_refresh_type = dlg.auto_refresh_type
  1335.  
  1336.             if self.auto_refresh and new_refresh_value != self.auto_refresh_rate:
  1337.                     self.auto_refresh_rate = new_refresh_value
  1338.                     self.refresh_timer.changeInterval(self.auto_refresh_rate * 60000)
  1339.  
  1340.             if old_auto_refresh != self.auto_refresh:
  1341.                 self.autoRefresh.toggle()
  1342.  
  1343.             self.SetAlerts()
  1344.             self.SaveConfig()
  1345.             
  1346.  
  1347.     def SetAlerts(self):
  1348.         service.setAlerts(self.hpssd_sock,
  1349.                           self.email_alerts,
  1350.                           self.email_to_addresses,
  1351.                           self.email_from_address)
  1352.  
  1353.  
  1354.     def SaveConfig(self):
  1355.         user_cfg.commands.prnt = self.cmd_print
  1356.         user_cfg.commands.pcard = self.cmd_pcard
  1357.         user_cfg.commands.fax = self.cmd_fax
  1358.         user_cfg.commands.scan = self.cmd_scan
  1359.         user_cfg.commands.cpy = self.cmd_copy
  1360.         user_cfg.alerts.email_to_addresses = self.email_to_addresses
  1361.         user_cfg.alerts.email_from_address = self.email_from_address
  1362.         user_cfg.alerts.email_alerts = self.email_alerts
  1363.         user_cfg.refresh.enable = self.auto_refresh
  1364.         user_cfg.refresh.rate = self.auto_refresh_rate
  1365.         user_cfg.refresh.type = self.auto_refresh_type
  1366.  
  1367.  
  1368.     def SuccessUI(self):
  1369.         QMessageBox.information(self,
  1370.                              self.caption(),
  1371.                              self.__tr("<p><b>The operation completed successfully.</b>"),
  1372.                               QMessageBox.Ok,
  1373.                               QMessageBox.NoButton,
  1374.                               QMessageBox.NoButton)
  1375.  
  1376.     def FailureUI(self, error_text):
  1377.         QMessageBox.critical(self,
  1378.                              self.caption(),
  1379.                              error_text,
  1380.                               QMessageBox.Ok,
  1381.                               QMessageBox.NoButton,
  1382.                               QMessageBox.NoButton)
  1383.  
  1384.     def WarningUI(self, msg):
  1385.         QMessageBox.warning(self,
  1386.                              self.caption(),
  1387.                              msg,
  1388.                               QMessageBox.Ok,
  1389.                               QMessageBox.NoButton,
  1390.                               QMessageBox.NoButton)
  1391.  
  1392.     def CheckDeviceUI(self):
  1393.         self.FailureUI(self.__tr("<b>Device is busy or in an error state.</b><p>Please check device and try again."))
  1394.  
  1395.     def LoadPaperUI(self):
  1396.         if LoadPaperForm(self).exec_loop() == QDialog.Accepted:
  1397.             return True
  1398.         return False
  1399.  
  1400.     def AlignmentNumberUI(self, letter, hortvert, colors, line_count, choice_count):
  1401.         dlg = AlignForm(self, letter, hortvert, colors, line_count, choice_count)
  1402.         if dlg.exec_loop() == QDialog.Accepted:
  1403.             return True, dlg.value
  1404.         else:
  1405.             return False, 0
  1406.  
  1407.     def PaperEdgeUI(self, maximum):
  1408.         dlg = PaperEdgeAlignForm(self)
  1409.         if dlg.exec_loop() == QDialog.Accepted:
  1410.             return True, dlg.value
  1411.         else:
  1412.             return False, 0
  1413.  
  1414.     def BothPensRequiredUI(self):
  1415.         self.WarningUI(self.__tr("<p><b>Both cartridges are required for alignment.</b><p>Please install both cartridges and try again."))
  1416.  
  1417.     def InvalidPenUI(self):
  1418.         self.WarningUI(self.__tr("<p><b>One or more cartiridges are missing from the printer.</b><p>Please install cartridge(s) and try again."))
  1419.  
  1420.     def PhotoPenRequiredUI(self):
  1421.         self.WarningUI(self.__tr("<p><b>Both the photo and color cartridges must be inserted into the printer to perform color calibration.</b><p>If you are planning on printing with the photo cartridge, please insert it and try again."))
  1422.  
  1423.     def PhotoPenRequiredUI2(self):
  1424.         self.WarningUI(self.__tr("<p><b>Both the photo (regular photo or photo blue) and color cartridges must be inserted into the printer to perform color calibration.</b><p>If you are planning on printing with the photo or photo blue cartridge, please insert it and try again."))
  1425.  
  1426.  
  1427.     def AioUI1(self):
  1428.         dlg = AlignType6Form1(self)
  1429.         return dlg.exec_loop() == QDialog.Accepted
  1430.  
  1431.  
  1432.     def AioUI2(self):
  1433.         AlignType6Form2(self).exec_loop()
  1434.  
  1435.     def Align10UI(self, pattern):
  1436.         dlg = Align10Form(pattern, self)
  1437.         dlg.exec_loop()
  1438.         return dlg.getValues()
  1439.  
  1440.     def AlignPensButton_clicked(self):
  1441.         d = self.cur_device
  1442.         ok = False;
  1443.         align_type = d.align_type
  1444.  
  1445.         log.debug(utils.bold("Align: %s %s (type=%d) %s" % ("*"*20, self.cur_device_uri, align_type, "*"*20)))
  1446.  
  1447.         try:
  1448.             QApplication.setOverrideCursor(QApplication.waitCursor)
  1449.             d.open()
  1450.  
  1451.             if d.isIdleAndNoError():
  1452.                 QApplication.restoreOverrideCursor()
  1453.  
  1454.                 if align_type == ALIGN_TYPE_AUTO:
  1455.                     ok = maint.AlignType1(d, self.LoadPaperUI)
  1456.  
  1457.                 elif align_type == ALIGN_TYPE_8XX:
  1458.                     ok = maint.AlignType2(d, self.LoadPaperUI, self.AlignmentNumberUI,
  1459.                                            self.BothPensRequiredUI)
  1460.  
  1461.                 elif align_type in (ALIGN_TYPE_9XX,ALIGN_TYPE_9XX_NO_EDGE_ALIGN):
  1462.                     ok = maint.AlignType3(d, self.LoadPaperUI, self.AlignmentNumberUI,
  1463.                                            self.PaperEdgeUI, align_type)
  1464.  
  1465.                 elif align_type in (ALIGN_TYPE_LIDIL_0_3_8, ALIGN_TYPE_LIDIL_0_4_3, ALIGN_TYPE_LIDIL_VIP):
  1466.                     ok = maint.AlignxBow(d, align_type, self.LoadPaperUI, self.AlignmentNumberUI,
  1467.                                           self.PaperEdgeUI, self.InvalidPenUI, self.ColorAdjUI)
  1468.  
  1469.                 elif align_type == ALIGN_TYPE_LIDIL_AIO:
  1470.                     ok = maint.AlignType6(d, self.AioUI1, self.AioUI2, self.LoadPaperUI)
  1471.  
  1472.                 elif align_type == ALIGN_TYPE_DESKJET_450:
  1473.                     ok = maint.AlignType8(d, self.LoadPaperUI, self.AlignmentNumberUI)
  1474.  
  1475.                 elif align_type == ALIGN_TYPE_LBOW:
  1476.                     ok = maint.AlignType10(d, self.LoadPaperUI, self.Align10UI) 
  1477.             else:
  1478.                 self.CheckDeviceUI()
  1479.  
  1480.         finally:
  1481.             d.close()
  1482.             QApplication.restoreOverrideCursor()
  1483.  
  1484.  
  1485.  
  1486.     def ColorAdjUI(self, line, maximum=0):
  1487.         dlg = ColorAdjForm(self, line)
  1488.         if dlg.exec_loop() == QDialog.Accepted:
  1489.             return True, dlg.value
  1490.         else:
  1491.             return False, 0
  1492.  
  1493.     def ColorCalUI(self):
  1494.         dlg = ColorCalForm(self)
  1495.         if dlg.exec_loop() == QDialog.Accepted:
  1496.             return True, dlg.value
  1497.         else:
  1498.             return False, 0
  1499.  
  1500.     def ColorCalUI2(self):
  1501.         dlg = ColorCalForm2(self)
  1502.         if dlg.exec_loop() == QDialog.Accepted:
  1503.             return True, dlg.value
  1504.         else:
  1505.             return False, 0
  1506.  
  1507.  
  1508.     def ColorCalUI4(self):
  1509.         dlg = ColorCal4Form(self)
  1510.         if dlg.exec_loop() == QDialog.Accepted:
  1511.             #print dlg.values
  1512.             return True, dlg.values
  1513.         else:
  1514.             return False, None
  1515.  
  1516.  
  1517.     def ColorCalibrationButton_clicked(self):
  1518.         d = self.cur_device
  1519.         color_cal_type = d.color_cal_type
  1520.         ok = False
  1521.         log.debug(utils.bold("Color-cal: %s %s (type=%d) %s" % ("*"*20, self.cur_device_uri, color_cal_type, "*"*20)))
  1522.  
  1523.         try:
  1524.             QApplication.setOverrideCursor(QApplication.waitCursor)
  1525.             d.open()
  1526.  
  1527.             if d.isIdleAndNoError():
  1528.                 QApplication.restoreOverrideCursor()
  1529.  
  1530.                 if color_cal_type == COLOR_CAL_TYPE_DESKJET_450:
  1531.                     ok = maint.colorCalType1(d, self.LoadPaperUI, self.ColorCalUI,
  1532.                                          self.PhotoPenRequiredUI)
  1533.  
  1534.                 elif color_cal_type == COLOR_CAL_TYPE_MALIBU_CRICK:
  1535.                     ok = maint.colorCalType2(d, self.LoadPaperUI, self.ColorCalUI2,
  1536.                                                  self.InvalidPenUI)
  1537.  
  1538.                 elif color_cal_type == COLOR_CAL_TYPE_STRINGRAY_LONGBOW_TORNADO:
  1539.                     ok = maint.colorCalType3(d, self.LoadPaperUI, self.ColorAdjUI,
  1540.                                                  self.PhotoPenRequiredUI2)
  1541.  
  1542.                 elif color_cal_type == COLOR_CAL_TYPE_CONNERY:
  1543.                     ok = maint.colorCalType4(d, self.LoadPaperUI, self.ColorCalUI4,
  1544.                                               self.WaitUI)
  1545.  
  1546.                 elif color_cal_type == COLOR_CAL_TYPE_COUSTEAU:
  1547.                     ok = maint.colorCalType5(d, self.LoadPaperUI)
  1548.  
  1549.             else:
  1550.                 self.CheckDeviceUI()
  1551.  
  1552.         finally:
  1553.             d.close()
  1554.             QApplication.restoreOverrideCursor()
  1555.  
  1556.  
  1557.     def PrintTestPageButton_clicked(self):
  1558.         d = self.cur_device
  1559.  
  1560.         printer_name = d.cups_printers[0]
  1561.  
  1562.         if len(d.cups_printers) > 1:
  1563.             from chooseprinterdlg import ChoosePrinterDlg2
  1564.             dlg = ChoosePrinterDlg2(d.cups_printers)
  1565.  
  1566.             if dlg.exec_loop() == QDialog.Accepted:
  1567.                 printer_name = dlg.printer_name
  1568.  
  1569.         try:
  1570.             QApplication.setOverrideCursor(QApplication.waitCursor)
  1571.             d.open()
  1572.  
  1573.             if d.isIdleAndNoError():
  1574.                 QApplication.restoreOverrideCursor()
  1575.                 d.close()
  1576.                 
  1577.                 if self.LoadPaperUI():
  1578.                     d.printTestPage(printer_name)
  1579.  
  1580.                     QMessageBox.information(self,
  1581.                                          self.caption(),
  1582.                                          self.__tr("<p><b>A test page should be printing on your printer.</b><p>If the page fails to print, please visit http://hplip.sourceforge.net for troubleshooting and support."),
  1583.                                           QMessageBox.Ok,
  1584.                                           QMessageBox.NoButton,
  1585.                                           QMessageBox.NoButton)
  1586.  
  1587.             else:
  1588.                 d.close()
  1589.                 self.CheckDeviceUI()
  1590.  
  1591.         finally:
  1592.             QApplication.restoreOverrideCursor()
  1593.  
  1594.  
  1595.     def CleanUI1(self):
  1596.         return CleaningForm(self, 1).exec_loop() == QDialog.Accepted
  1597.  
  1598.  
  1599.     def CleanUI2(self):
  1600.         return CleaningForm(self, 2).exec_loop() == QDialog.Accepted
  1601.  
  1602.  
  1603.     def CleanUI3(self):
  1604.         CleaningForm2(self).exec_loop()
  1605.         return True
  1606.  
  1607.  
  1608.     def WaitUI(self, seconds):
  1609.         WaitForm(seconds, None, self).exec_loop()
  1610.  
  1611.  
  1612.     def CleanPensButton_clicked(self):
  1613.         d = self.cur_device
  1614.         clean_type = d.clean_type
  1615.         log.debug(utils.bold("Clean: %s %s (type=%d) %s" % ("*"*20, self.cur_device_uri, clean_type, "*"*20)))
  1616.  
  1617.         try:
  1618.             QApplication.setOverrideCursor(QApplication.waitCursor)
  1619.             d.open()
  1620.  
  1621.             if d.isIdleAndNoError():
  1622.                 QApplication.restoreOverrideCursor()
  1623.  
  1624.                 if clean_type == CLEAN_TYPE_PCL:
  1625.                     maint.cleaning(d, clean_type, maint.cleanType1, maint.primeType1,
  1626.                                     maint.wipeAndSpitType1, self.LoadPaperUI,
  1627.                                     self.CleanUI1, self.CleanUI2, self.CleanUI3,
  1628.                                     self.WaitUI)
  1629.  
  1630.                 elif clean_type == CLEAN_TYPE_LIDIL:
  1631.                     maint.cleaning(d, clean_type, maint.cleanType2, maint.primeType2,
  1632.                                     maint.wipeAndSpitType2, self.LoadPaperUI,
  1633.                                     self.CleanUI1, self.CleanUI2, self.CleanUI3,
  1634.                                     self.WaitUI)
  1635.  
  1636.                 elif clean_type == CLEAN_TYPE_PCL_WITH_PRINTOUT:
  1637.                     maint.cleaning(d, clean_type, maint.cleanType1, maint.primeType1,
  1638.                                     maint.wipeAndSpitType1, self.LoadPaperUI,
  1639.                                     self.CleanUI1, self.CleanUI2, self.CleanUI3,
  1640.                                     self.WaitUI)
  1641.             else:
  1642.                 self.CheckDeviceUI()
  1643.  
  1644.         finally:
  1645.             d.close()
  1646.             QApplication.restoreOverrideCursor()
  1647.  
  1648.  
  1649.     def deviceRescanAction_activated(self):
  1650.         self.deviceRescanAction.setEnabled(False)
  1651.         self.UpdateDevice()
  1652.         self.deviceRescanAction.setEnabled(True)
  1653.  
  1654.  
  1655.     def deviceRefreshAll_activated(self):
  1656.         self.RescanDevices()
  1657.  
  1658.  
  1659.     def DeviceList_clicked(self,a0):
  1660.         pass
  1661.  
  1662.  
  1663.     def OpenEmbeddedBrowserButton_clicked(self):
  1664.         utils.openURL("http://%s" % self.cur_device.host)
  1665.  
  1666.     def PrintButton_clicked(self):
  1667.         self.RunCommand(self.cmd_print)
  1668.  
  1669.  
  1670.     def ScanButton_clicked(self):
  1671.         self.RunCommand(self.cmd_scan)
  1672.  
  1673.  
  1674.     def PCardButton_clicked(self):
  1675.         if self.cur_device.pcard_type == PCARD_TYPE_MLC:
  1676.             self.RunCommand(self.cmd_pcard)
  1677.         elif self.cur_device.pcard_type == PCARD_TYPE_USB_MASS_STORAGE:
  1678.             self.FailureUI(self.__tr("<p><b>The photocard on your printer are only available by mounting them as drives using USB mass storage.</b>Please refer to your distribution's documentation for setup and usage instructions."))
  1679.  
  1680.     def SendFaxButton_clicked(self):
  1681.         self.RunCommand(self.cmd_fax)
  1682.  
  1683.     def MakeCopiesButton_clicked(self):
  1684.         #self.RunCommand( self.cmd_copy )
  1685.         self.FailureUI(self.__tr("<p><b>Sorry, the make copies feature is currently not implemented.</b>"))
  1686.  
  1687.  
  1688.     def ConfigureFeaturesButton_clicked(self):
  1689.         self.settingsConfigure_activated(2)
  1690.  
  1691.  
  1692.     def RunCommand(self, cmd, macro_char='%'):
  1693.         self.ToggleFunctionButtons(False)
  1694.         if len(cmd) == 0:
  1695.             self.FailureUI(self.__tr("<p><b>Unable to run command. No command specified.</b><p>Use <pre>Configure...</pre> to specify a command to run."))
  1696.             log.error("No command specified. Use settings to configure commands.")
  1697.         else:
  1698.             log.debug(utils.bold("Run: %s %s (%s) %s" % ("*"*20, cmd, self.cur_device_uri, "*"*20)))
  1699.             log.debug(cmd)
  1700.             cmd = ''.join([self.cur_device.device_vars.get(x, x) \
  1701.                              for x in cmd.split(macro_char)])
  1702.             log.debug(cmd)
  1703.  
  1704.             path = cmd.split()[0]
  1705.             args = cmd.split()
  1706.  
  1707.             log.debug(path)
  1708.             log.debug(args)
  1709.  
  1710.             self.CleanupChildren()
  1711.             os.spawnvp(os.P_NOWAIT, path, args)
  1712.  
  1713.  
  1714.         self.ToggleFunctionButtons(True)
  1715.  
  1716.  
  1717.     def helpAbout(self):
  1718.         dlg = AboutDlg(self)
  1719.         dlg.VersionText.setText(prop.version)
  1720.         dlg.exec_loop()
  1721.  
  1722.     def deviceSettingsButton_clicked(self):
  1723.         try:
  1724.             self.cur_device.open()
  1725.             self.cur_device.device_settings_ui(self.cur_device, self)
  1726.         finally:
  1727.             self.cur_device.close()
  1728.  
  1729.     def setupDevice_activated(self):
  1730.         self.cur_device.device_settings_ui(self.cur_device, self)
  1731.  
  1732.     def faxSettingsButton_clicked(self):
  1733.         try:
  1734.             self.cur_device.open()
  1735.  
  1736.             try:
  1737.                 result_code, fax_num = self.cur_device.getPML(pml.OID_FAX_LOCAL_PHONE_NUM)
  1738.             except Error:
  1739.                 log.error("PML failure.")
  1740.                 self.FailureUI(self.__tr("<p><b>Operation failed. Device busy.</b>"))
  1741.                 return
  1742.  
  1743.             fax_num = str(fax_num)
  1744.  
  1745.             try:
  1746.                 result_code, name = self.cur_device.getPML(pml.OID_FAX_STATION_NAME)
  1747.             except Error:
  1748.                 log.error("PML failure.")
  1749.                 self.FailureUI(self.__tr("<p><b>Operation failed. Device busy.</b>"))
  1750.                 return
  1751.  
  1752.             name = str(name)
  1753.  
  1754.             dlg = FaxSettingsForm(self.cur_device, fax_num, name, self)
  1755.             dlg.exec_loop()
  1756.         finally:
  1757.             self.cur_device.close()
  1758.  
  1759.  
  1760.     def addressBookButton_clicked(self):
  1761.         self.RunCommand(self.cmd_fab)
  1762.         
  1763.     def helpContents(self):
  1764.         f = "file://%s" % os.path.join(sys_cfg.dirs.doc, 'index.html')
  1765.         log.debug(f)
  1766.         utils.openURL(f)
  1767.         
  1768.  
  1769.     def __tr(self,s,c = None):
  1770.         return qApp.translate("DevMgr4",s,c)
  1771.