home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / hplip / ui / scrolltool.py < prev    next >
Encoding:
Python Source  |  2007-04-04  |  34.0 KB  |  928 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2001-2007 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. # Author: Don Welch
  20. #
  21.  
  22. # Local
  23. from base.g import *
  24. from base import utils, pml, maint
  25. from prnt import cups
  26. from base.codes import *
  27.  
  28. # Qt
  29. from qt import *
  30. from scrollview import ScrollView, PixmapLabelButton
  31.  
  32. # Std Lib
  33. import sys, os.path, os
  34.  
  35. # Alignment and ColorCal forms
  36. from alignform import AlignForm
  37. from aligntype6form1 import AlignType6Form1
  38. from aligntype6form2 import AlignType6Form2
  39. from paperedgealignform import PaperEdgeAlignForm
  40. from colorcalform import ColorCalForm # Type 1 color cal
  41. from coloradjform import ColorAdjForm  # Type 5 and 6 color adj
  42. from colorcalform2 import ColorCalForm2 # Type 2 color cal
  43. from colorcal4form import ColorCal4Form # Type 4 color cal
  44. from align10form import Align10Form # Type 10 and 11 alignment
  45.  
  46. # Misc forms
  47. from loadpaperform import LoadPaperForm
  48. from settingsdialog import SettingsDialog
  49. from aboutdlg import AboutDlg
  50. from cleaningform import CleaningForm
  51. from cleaningform2 import CleaningForm2
  52. from waitform import WaitForm
  53. from faxsettingsform import FaxSettingsForm
  54. #from informationform import InformationForm
  55.  
  56.  
  57.  
  58. class ScrollToolView(ScrollView):
  59.     def __init__(self, toolbox_hosted=True, parent = None,form=None, name = None,fl = 0):
  60.         ScrollView.__init__(self,parent,name,fl)
  61.  
  62.         self.form = form
  63.         self.toolbox_hosted = toolbox_hosted
  64.  
  65.         cmd_print, cmd_scan, cmd_pcard, \
  66.             cmd_copy, cmd_fax, cmd_fab = utils.deviceDefaultFunctions()
  67.  
  68.         self.cmd_print = user_cfg.commands.prnt or cmd_print
  69.         self.cmd_scan = user_cfg.commands.scan or cmd_scan
  70.         self.cmd_pcard = user_cfg.commands.pcard or cmd_pcard
  71.         self.cmd_copy = user_cfg.commands.cpy or cmd_copy
  72.         self.cmd_fax = user_cfg.commands.fax or cmd_fax
  73.         self.cmd_fab = user_cfg.commands.fab or cmd_fab
  74.  
  75.  
  76.     def fillControls(self):
  77.         ScrollView.fillControls(self)
  78.  
  79.         if self.cur_device is not None and \
  80.             self.cur_device.supported and \
  81.             self.cur_device.device_state != DEVICE_STATE_NOT_FOUND:
  82.  
  83.             if self.cur_device.device_settings_ui is not None:
  84.                 self.addItem( "device_settings", self.__tr("<b>Device Settings</b>"), 
  85.                     QPixmap(os.path.join(prop.image_dir, 'icon_settings.png')), 
  86.                     self.__tr("Your device has special device settings. You may alter these settings here."), 
  87.                     self.__tr("Device Settings..."), 
  88.                     self.deviceSettingsButton_clicked)
  89.  
  90.             if self.cur_device.fax_type:
  91.                 self.addItem( "fax_settings", self.__tr("<b>Fax Setup</b>"), 
  92.                     QPixmap(os.path.join(prop.image_dir, 'icon_fax.png')), 
  93.                     self.__tr("Fax support must be setup before you can send faxes."), 
  94.                     self.__tr("Setup Fax..."), 
  95.                     self.faxSettingsButton_clicked)
  96.  
  97.                 self.addItem( "fax_address_book", self.__tr("<b>Fax Address Book</b>"), 
  98.                     QPixmap(os.path.join(prop.image_dir, 'icon_fax.png')), 
  99.                     self.__tr("Setup fax phone numbers to use when sending faxes from the PC."), 
  100.                     self.__tr("Fax Address Book..."), 
  101.                     self.faxAddressBookButton_clicked)
  102.  
  103.  
  104.             self.addItem( "testpage", self.__tr("<b>Print Test Page</b>"), 
  105.                 QPixmap(os.path.join(prop.image_dir, 'icon_testpage.png')), 
  106.                 self.__tr("Print a test page to test the setup of your printer."), 
  107.                 self.__tr("Print Test Page >>"), 
  108.                 self.PrintTestPageButton_clicked)
  109.  
  110.             self.addItem( "printer_info", self.__tr("<b>View Printer (Queue) Information</b>"), 
  111.                 QPixmap(os.path.join(prop.image_dir, 'icon_cups.png')), 
  112.                 self.__tr("View the printers (queues) installed in CUPS."), 
  113.                 self.__tr("View Printer Information >>"), 
  114.                 self.viewPrinterInformation) 
  115.  
  116.             self.addItem( "device_info", self.__tr("<b>View Device Information</b>"), 
  117.                 QPixmap(os.path.join(prop.image_dir, 'icon_info.png')), 
  118.                 self.__tr("This information is primarily useful for debugging and troubleshooting (advanced)."), 
  119.                 self.__tr("View Device Information >>"), 
  120.                 self.viewInformation) 
  121.  
  122.             if self.cur_device.pq_diag_type:
  123.                 self.addItem( "pqdiag", self.__tr("<b>Print Quality Diagnostics</b>"), 
  124.                     QPixmap(os.path.join(prop.image_dir, 'icon_pq_diag.png')),
  125.                     self.__tr("Your printer can print a test page to help diagnose print quality problems."), 
  126.                     self.__tr("Print Diagnostic Page..."), 
  127.                     self.pqDiag)
  128.  
  129.             if self.cur_device.fw_download:
  130.                 self.addItem( "fwdownload", self.__tr("<b>Download Firmware</b>"), 
  131.                     QPixmap(os.path.join(prop.image_dir, 'download.png')),
  132.                     self.__tr("Download firmware to your printer (required on some devices after each power-up)."), 
  133.                     self.__tr("Download Firmware..."), 
  134.                     self.downloadFirmware)
  135.  
  136.             if self.cur_device.clean_type:
  137.                 self.addItem( "clean", self.__tr("<b>Clean Cartridges</b>"), 
  138.                     QPixmap(os.path.join(prop.image_dir, 'icon_clean.png')), 
  139.                     self.__tr("You only need to perform this action if you are having problems with poor printout quality due to clogged ink nozzles."), 
  140.                     self.__tr("Clean Cartridges..."), 
  141.                     self.CleanPensButton_clicked)
  142.  
  143.             if self.cur_device.align_type:
  144.                 self.addItem( "align", self.__tr("<b>Align Cartridges</b>"), 
  145.                     QPixmap(os.path.join(prop.image_dir, 'icon_align.png')), 
  146.                     self.__tr("This will improve the quality of output when a new cartridge is installed."), 
  147.                     self.__tr("Align Cartridges..."), 
  148.                     self.AlignPensButton_clicked)
  149.  
  150.             if self.cur_device.color_cal_type:
  151.                 self.addItem( "colorcal", self.__tr("<b>Perform Color Calibration</b>"), 
  152.                     QPixmap(os.path.join(prop.image_dir, 'icon_colorcal.png')), 
  153.                     self.__tr("Use this procedure to optimimize your printer's color output."), 
  154.                     self.__tr("Color Calibration..."), 
  155.                     self.ColorCalibrationButton_clicked)
  156.  
  157.             if self.cur_device.linefeed_cal_type:
  158.                 self.addItem( "linefeed", self.__tr("<b>Perform Line Feed Calibration</b>"), 
  159.                     QPixmap(os.path.join(prop.image_dir, 'icon_linefeed_cal.png')),
  160.                     self.__tr("Use line feed calibration to optimize print quality (to remove gaps in the printed output)."), 
  161.                     self.__tr("Line Feed Calibration..."), 
  162.                     self.linefeedCalibration) 
  163.  
  164.             if self.cur_device.embedded_server_type and self.cur_device.bus == 'net':
  165.                 self.addItem( "ews", self.__tr("<b>Access Embedded Web Page</b>"), 
  166.                     QPixmap(os.path.join(prop.image_dir, 'icon_ews.png')), 
  167.                     self.__tr("You can use your printer's embedded web server to configure, maintain, and monitor the device from a web browser."),
  168.                     self.__tr("Open in Browser..."), 
  169.                     self.OpenEmbeddedBrowserButton_clicked)
  170.  
  171.         self.addItem("support",  self.__tr("<b>View Documentation</b>"), 
  172.             QPixmap(os.path.join(prop.image_dir, 'icon_support2.png')), 
  173.             self.__tr("View documentation installed on your system."), 
  174.             self.__tr("View Documentation..."), 
  175.             self.viewSupport) 
  176.  
  177.  
  178.     def addItem(self, name, title, pix, text, button_text, button_func):
  179.         self.addGroupHeading(title, title)
  180.  
  181.         widget = self.getWidget()
  182.  
  183.         layout1 = QGridLayout(widget, 1, 3, 5, 10,"layout1")
  184.  
  185.         layout1.setColStretch(0, 1)
  186.         layout1.setColStretch(1, 10)
  187.         layout1.setColStretch(2, 2)
  188.  
  189.         pushButton = QPushButton(widget, "pushButton")
  190.         pushButton.setSizePolicy(QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed, 0, 0,
  191.             pushButton.sizePolicy().hasHeightForWidth()))
  192.  
  193.         layout1.addWidget(pushButton, 0, 3)
  194.  
  195.         icon = QLabel(widget, "icon")
  196.         icon.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed, 0, 0,
  197.             icon.sizePolicy().hasHeightForWidth()))
  198.  
  199.         icon.setMinimumSize(QSize(32, 32))
  200.         icon.setMaximumSize(QSize(32, 32))
  201.         icon.setScaledContents(1)
  202.         layout1.addWidget(icon, 0, 0)
  203.  
  204.  
  205.         textLabel = QLabel(widget, "textLabel")
  206.         textLabel.setAlignment(QLabel.WordBreak)
  207.         textLabel.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred, 0, 0,
  208.             textLabel.sizePolicy().hasHeightForWidth()))        
  209.         textLabel.setFrameShape(self.frame_shape)
  210.         layout1.addWidget(textLabel, 0, 1)
  211.  
  212.         spacer1 = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  213.         layout1.addItem(spacer1, 0, 2)
  214.  
  215.         textLabel.setText(text)
  216.         pushButton.setText(button_text)
  217.         icon.setPixmap(pix)
  218.  
  219.         self.connect(pushButton, SIGNAL("clicked()"), button_func)
  220.  
  221.         self.addWidget(widget, str(title))
  222.  
  223.     def viewInformation(self):
  224.         self.form.SwitchMaintTab("device_info")
  225.         
  226.     def viewPrinterInformation(self):
  227.         self.form.SwitchMaintTab("printer_info")
  228.  
  229.     def viewSupport(self):
  230.         f = "file://%s" % os.path.join(sys_cfg.dirs.doc, 'index.html')
  231.         log.debug(f)
  232.         utils.openURL(f)
  233.  
  234.     def pqDiag(self):
  235.         d = self.cur_device
  236.         pq_diag = d.pq_diag_type
  237.  
  238.         try:
  239.             QApplication.setOverrideCursor(QApplication.waitCursor)
  240.             
  241.             try:
  242.                 d.open()
  243.             except Error:
  244.                 self.CheckDeviceUI()
  245.             else:
  246.                 if d.isIdleAndNoError():
  247.                     QApplication.restoreOverrideCursor()
  248.     
  249.                     if pq_diag == 1:
  250.                         maint.printQualityDiagType1(d, self.LoadPaperUI)
  251.     
  252.                     elif pq_diag == 2:
  253.                         maint.printQualityDiagType2(d, self.LoadPaperUI)
  254.     
  255.                 else:
  256.                     self.CheckDeviceUI()
  257.  
  258.         finally:
  259.             d.close()
  260.             QApplication.restoreOverrideCursor()
  261.  
  262.  
  263.     def linefeedCalibration(self):
  264.         d = self.cur_device
  265.         linefeed_type = d.linefeed_cal_type
  266.  
  267.         try:    
  268.             QApplication.setOverrideCursor(QApplication.waitCursor)
  269.             
  270.             try:
  271.                 d.open()
  272.             except Error:
  273.                 self.CheckDeviceUI()
  274.             else:
  275.                 if d.isIdleAndNoError():
  276.                     QApplication.restoreOverrideCursor()
  277.     
  278.                     if linefeed_type == 1:
  279.                         maint.linefeedCalType1(d, self.LoadPaperUI)
  280.     
  281.                     elif linefeed_type == 2:
  282.                         maint.linefeedCalType2(d, self.LoadPaperUI)
  283.     
  284.                 else:
  285.                     self.CheckDeviceUI()
  286.  
  287.         finally:
  288.             d.close()
  289.             QApplication.restoreOverrideCursor()
  290.  
  291.     def downloadFirmware(self):
  292.         d = self.cur_device
  293.  
  294.         try:
  295.             QApplication.setOverrideCursor(QApplication.waitCursor)
  296.             d.open()
  297.  
  298.             if d.isIdleAndNoError():
  299.                 d.downloadFirmware()
  300.             else:
  301.                 self.form.FailureUI(self.__tr("<b>An error occured downloading firmware file.</b><p>Please check your printer and try again."))
  302.  
  303.         finally:
  304.             d.close()
  305.             QApplication.restoreOverrideCursor()
  306.  
  307.  
  308.     def CheckDeviceUI(self):
  309.         self.form.FailureUI(self.__tr("<b>Device is busy or in an error state.</b><p>Please check device and try again."))
  310.  
  311.     def LoadPaperUI(self):
  312.         if LoadPaperForm(self).exec_loop() == QDialog.Accepted:
  313.             return True
  314.         return False
  315.  
  316.     def AlignmentNumberUI(self, letter, hortvert, colors, line_count, choice_count):
  317.         dlg = AlignForm(self, letter, hortvert, colors, line_count, choice_count)
  318.         if dlg.exec_loop() == QDialog.Accepted:
  319.             return True, dlg.value
  320.         else:
  321.             return False, 0
  322.  
  323.     def PaperEdgeUI(self, maximum):
  324.         dlg = PaperEdgeAlignForm(self)
  325.         if dlg.exec_loop() == QDialog.Accepted:
  326.             return True, dlg.value
  327.         else:
  328.             return False, 0
  329.  
  330.     def BothPensRequiredUI(self):
  331.         self.form.WarningUI(self.__tr("<p><b>Both cartridges are required for alignment.</b><p>Please install both cartridges and try again."))
  332.  
  333.     def InvalidPenUI(self):
  334.         self.form.WarningUI(self.__tr("<p><b>One or more cartiridges are missing from the printer.</b><p>Please install cartridge(s) and try again."))
  335.  
  336.     def PhotoPenRequiredUI(self):
  337.         self.form.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."))
  338.  
  339.     def PhotoPenRequiredUI2(self):
  340.         self.form.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."))
  341.  
  342.     def NotPhotoOnlyRequired(self): # Type 11
  343.         self.form.WarningUI(self.__tr("<p><b>Cannot align with only the photo cartridge installed.</b><p>Please install other cartridges and try again."))
  344.  
  345.     def AioUI1(self):
  346.         dlg = AlignType6Form1(self)
  347.         return dlg.exec_loop() == QDialog.Accepted
  348.  
  349.  
  350.     def AioUI2(self):
  351.         AlignType6Form2(self).exec_loop()
  352.  
  353.     def Align10and11UI(self, pattern, align_type):
  354.         dlg = Align10Form(pattern, align_type, self)
  355.         dlg.exec_loop()
  356.         return dlg.getValues()
  357.  
  358.     def AlignPensButton_clicked(self):
  359.         d = self.cur_device
  360.         align_type = d.align_type
  361.  
  362.         log.debug(utils.bold("Align: %s %s (type=%d) %s" % ("*"*20, self.cur_device.device_uri, align_type, "*"*20)))
  363.  
  364.         try:
  365.             QApplication.setOverrideCursor(QApplication.waitCursor)
  366.             
  367.             try:
  368.                 d.open()
  369.             except Error:
  370.                 self.CheckDeviceUI()
  371.             else:
  372.                 if d.isIdleAndNoError():
  373.                     QApplication.restoreOverrideCursor()
  374.     
  375.                     if align_type == ALIGN_TYPE_AUTO:
  376.                         maint.AlignType1(d, self.LoadPaperUI)
  377.     
  378.                     elif align_type == ALIGN_TYPE_8XX:
  379.                         maint.AlignType2(d, self.LoadPaperUI, self.AlignmentNumberUI,
  380.                                          self.BothPensRequiredUI)
  381.     
  382.                     elif align_type in (ALIGN_TYPE_9XX,ALIGN_TYPE_9XX_NO_EDGE_ALIGN):
  383.                          maint.AlignType3(d, self.LoadPaperUI, self.AlignmentNumberUI,
  384.                                           self.PaperEdgeUI, align_type)
  385.     
  386.                     elif align_type in (ALIGN_TYPE_LIDIL_0_3_8, ALIGN_TYPE_LIDIL_0_4_3, ALIGN_TYPE_LIDIL_VIP):
  387.                         maint.AlignxBow(d, align_type, self.LoadPaperUI, self.AlignmentNumberUI,
  388.                                         self.PaperEdgeUI, self.InvalidPenUI, self.ColorAdjUI)
  389.     
  390.                     elif align_type == ALIGN_TYPE_LIDIL_AIO:
  391.                         maint.AlignType6(d, self.AioUI1, self.AioUI2, self.LoadPaperUI)
  392.     
  393.                     elif align_type == ALIGN_TYPE_DESKJET_450:
  394.                         maint.AlignType8(d, self.LoadPaperUI, self.AlignmentNumberUI)
  395.     
  396.                     elif align_type == ALIGN_TYPE_LBOW:
  397.                         maint.AlignType10(d, self.LoadPaperUI, self.Align10and11UI) 
  398.     
  399.                     elif align_type == ALIGN_TYPE_LIDIL_0_5_4:
  400.                         maint.AlignType11(d, self.LoadPaperUI, self.Align10and11UI, self.NotPhotoOnlyRequired) 
  401.     
  402.                     elif align_type == ALIGN_TYPE_OJ_PRO:
  403.                         maint.AlignType12(d, self.LoadPaperUI)
  404.     
  405.                 else:
  406.                     self.CheckDeviceUI()
  407.  
  408.         finally:
  409.             d.close()
  410.             QApplication.restoreOverrideCursor()
  411.  
  412.     def ColorAdjUI(self, line, maximum=0):
  413.         dlg = ColorAdjForm(self, line)
  414.         if dlg.exec_loop() == QDialog.Accepted:
  415.             return True, dlg.value
  416.         else:
  417.             return False, 0
  418.  
  419.     def ColorCalUI(self):
  420.         dlg = ColorCalForm(self)
  421.         if dlg.exec_loop() == QDialog.Accepted:
  422.             return True, dlg.value
  423.         else:
  424.             return False, 0
  425.  
  426.     def ColorCalUI2(self):
  427.         dlg = ColorCalForm2(self)
  428.         if dlg.exec_loop() == QDialog.Accepted:
  429.             return True, dlg.value
  430.         else:
  431.             return False, 0
  432.  
  433.     def ColorCalUI4(self):
  434.         dlg = ColorCal4Form(self)
  435.         if dlg.exec_loop() == QDialog.Accepted:
  436.             return True, dlg.values
  437.         else:
  438.             return False, None
  439.  
  440.     def ColorCalibrationButton_clicked(self):
  441.         d = self.cur_device
  442.         color_cal_type = d.color_cal_type
  443.         log.debug(utils.bold("Color-cal: %s %s (type=%d) %s" % ("*"*20, self.cur_device.device_uri, color_cal_type, "*"*20)))
  444.  
  445.         try:
  446.             QApplication.setOverrideCursor(QApplication.waitCursor)
  447.             
  448.             try:
  449.                 d.open()
  450.             except Error:
  451.                 self.CheckDeviceUI()
  452.             else:
  453.                 if d.isIdleAndNoError():
  454.                     QApplication.restoreOverrideCursor()
  455.     
  456.                     if color_cal_type == COLOR_CAL_TYPE_DESKJET_450:
  457.                          maint.colorCalType1(d, self.LoadPaperUI, self.ColorCalUI,
  458.                                              self.PhotoPenRequiredUI)
  459.     
  460.                     elif color_cal_type == COLOR_CAL_TYPE_MALIBU_CRICK:
  461.                         maint.colorCalType2(d, self.LoadPaperUI, self.ColorCalUI2,
  462.                                             self.InvalidPenUI)
  463.     
  464.                     elif color_cal_type == COLOR_CAL_TYPE_STRINGRAY_LONGBOW_TORNADO:
  465.                         maint.colorCalType3(d, self.LoadPaperUI, self.ColorAdjUI,
  466.                                             self.PhotoPenRequiredUI2)
  467.     
  468.                     elif color_cal_type == COLOR_CAL_TYPE_CONNERY:
  469.                         maint.colorCalType4(d, self.LoadPaperUI, self.ColorCalUI4,
  470.                                             self.WaitUI)
  471.     
  472.                     elif color_cal_type == COLOR_CAL_TYPE_COUSTEAU:
  473.                         maint.colorCalType5(d, self.LoadPaperUI)
  474.     
  475.                     elif color_cal_type == COLOR_CAL_TYPE_CARRIER:
  476.                         maint.colorCalType6(d, self.LoadPaperUI)
  477.     
  478.                 else:
  479.                     self.CheckDeviceUI()
  480.  
  481.         finally:
  482.             d.close()
  483.             QApplication.restoreOverrideCursor()
  484.  
  485.  
  486.     def PrintTestPageButton_clicked(self):
  487.         self.form.SwitchMaintTab("testpage")
  488.  
  489.         
  490.     def CleanUI1(self):
  491.         return CleaningForm(self, self.cur_device, 1).exec_loop() == QDialog.Accepted
  492.  
  493.  
  494.     def CleanUI2(self):
  495.         return CleaningForm(self, self.cur_device, 2).exec_loop() == QDialog.Accepted
  496.  
  497.  
  498.     def CleanUI3(self):
  499.         CleaningForm2(self).exec_loop()
  500.         return True
  501.  
  502.  
  503.     def WaitUI(self, seconds):
  504.         WaitForm(seconds, None, self).exec_loop()
  505.  
  506.  
  507.     def CleanPensButton_clicked(self):
  508.         d = self.cur_device
  509.         clean_type = d.clean_type
  510.         log.debug(utils.bold("Clean: %s %s (type=%d) %s" % ("*"*20, self.cur_device.device_uri, clean_type, "*"*20)))
  511.  
  512.         try:
  513.             QApplication.setOverrideCursor(QApplication.waitCursor)
  514.             
  515.             try:
  516.                 d.open()
  517.             except Error:
  518.                 self.CheckDeviceUI()
  519.             else:
  520.                 if d.isIdleAndNoError():
  521.                     QApplication.restoreOverrideCursor()
  522.     
  523.                     if clean_type == CLEAN_TYPE_PCL:
  524.                         maint.cleaning(d, clean_type, maint.cleanType1, maint.primeType1,
  525.                                         maint.wipeAndSpitType1, self.LoadPaperUI,
  526.                                         self.CleanUI1, self.CleanUI2, self.CleanUI3,
  527.                                         self.WaitUI)
  528.     
  529.                     elif clean_type == CLEAN_TYPE_LIDIL:
  530.                         maint.cleaning(d, clean_type, maint.cleanType2, maint.primeType2,
  531.                                         maint.wipeAndSpitType2, self.LoadPaperUI,
  532.                                         self.CleanUI1, self.CleanUI2, self.CleanUI3,
  533.                                         self.WaitUI)
  534.     
  535.                     elif clean_type == CLEAN_TYPE_PCL_WITH_PRINTOUT:
  536.                         maint.cleaning(d, clean_type, maint.cleanType1, maint.primeType1,
  537.                                         maint.wipeAndSpitType1, self.LoadPaperUI,
  538.                                         self.CleanUI1, self.CleanUI2, self.CleanUI3,
  539.                                         self.WaitUI)
  540.                 else:
  541.                     self.CheckDeviceUI()
  542.  
  543.         finally:
  544.             d.close()
  545.             QApplication.restoreOverrideCursor()
  546.  
  547.     def OpenEmbeddedBrowserButton_clicked(self):
  548.         utils.openURL("http://%s" % self.cur_device.host)
  549.  
  550.     def faxAddressBookButton_clicked(self):
  551.         self.RunCommand(self.cmd_fab)
  552.  
  553.     def faxSettingsButton_clicked(self):
  554.         try:
  555.             try:
  556.                 self.cur_device.open()
  557.             except Error:
  558.                 self.CheckDeviceUI()
  559.             else:
  560.                 try:
  561.                     result_code, fax_num = self.cur_device.getPML(pml.OID_FAX_LOCAL_PHONE_NUM)
  562.                 except Error:
  563.                     log.error("PML failure.")
  564.                     self.form.FailureUI(self.__tr("<p><b>Operation failed. Device busy.</b>"))
  565.                     return
  566.     
  567.                 fax_num = str(fax_num)
  568.     
  569.                 try:
  570.                     result_code, name = self.cur_device.getPML(pml.OID_FAX_STATION_NAME)
  571.                 except Error:
  572.                     log.error("PML failure.")
  573.                     self.form.FailureUI(self.__tr("<p><b>Operation failed. Device busy.</b>"))
  574.                     return
  575.     
  576.                 name = str(name)
  577.     
  578.                 dlg = FaxSettingsForm(self.cur_device, fax_num, name, self)
  579.                 dlg.exec_loop()
  580.         
  581.         finally:
  582.             self.cur_device.close()
  583.  
  584.  
  585.     def addressBookButton_clicked(self):
  586.         self.RunCommand(self.cmd_fab)
  587.  
  588.     def deviceSettingsButton_clicked(self):
  589.         try:
  590.             self.cur_device.open()
  591.             self.cur_device.device_settings_ui(self.cur_device, self)
  592.         finally:
  593.             self.cur_device.close()
  594.  
  595.  
  596.     def RunCommand(self, cmd, macro_char='%'):
  597.         QApplication.setOverrideCursor(QApplication.waitCursor)
  598.  
  599.         try:
  600.             if len(cmd) == 0:
  601.                 self.form.FailureUI(self.__tr("<p><b>Unable to run command. No command specified.</b><p>Use <pre>Configure...</pre> to specify a command to run."))
  602.                 log.error("No command specified. Use settings to configure commands.")
  603.             else:
  604.                 log.debug(utils.bold("Run: %s %s (%s) %s" % ("*"*20, cmd, self.cur_device.device_uri, "*"*20)))
  605.                 log.debug(cmd)
  606.                 cmd = ''.join([self.cur_device.device_vars.get(x, x) \
  607.                                  for x in cmd.split(macro_char)])
  608.                 log.debug(cmd)
  609.  
  610.                 path = cmd.split()[0]
  611.                 args = cmd.split()
  612.  
  613.                 log.debug(path)
  614.                 log.debug(args)
  615.  
  616.                 self.CleanupChildren()
  617.                 os.spawnvp(os.P_NOWAIT, path, args)
  618.  
  619.         finally:
  620.             QApplication.restoreOverrideCursor()
  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 FailureUI(self, error_text):
  631.         QMessageBox.critical(self,
  632.                              self.caption(),
  633.                              error_text,
  634.                               QMessageBox.Ok,
  635.                               QMessageBox.NoButton,
  636.                               QMessageBox.NoButton)
  637.  
  638.     def __tr(self,s,c = None):
  639.         return qApp.translate("ScrollToolView",s,c)
  640.  
  641.  
  642. #
  643. #
  644. # ScrollDeviceInfoView (View Device Information)
  645. #
  646. #
  647.  
  648. class ScrollDeviceInfoView(ScrollView):
  649.     def __init__(self, toolbox_hosted=True, parent = None, form=None, name = None,fl = 0):
  650.         ScrollView.__init__(self,parent,name,fl)
  651.  
  652.         self.form = form
  653.         self.toolbox_hosted = toolbox_hosted
  654.  
  655.     def fillControls(self):
  656.         ScrollView.fillControls(self)
  657.  
  658.         self.addDeviceInfo()
  659.  
  660.         if self.toolbox_hosted:
  661.             self.navButton = self.addActionButton("bottom_nav", "", 
  662.                                     None, self.__tr("<< Tools"), self.navButton_clicked)
  663.         else:
  664.             self.navButton = self.addActionButton("bottom_nav", self.__tr("Close"), 
  665.                                     self.navButton_clicked, "", None)
  666.  
  667.         self.maximizeControl()
  668.  
  669.     def addDeviceInfo(self):
  670.         self.addGroupHeading("info_title", self.__tr("Device Information"))
  671.  
  672.         widget = self.getWidget()
  673.  
  674.         layout37 = QGridLayout(widget,1,1,5,10,"layout37")
  675.  
  676.         self.infoListView = QListView(widget,"fileListView")
  677.         self.infoListView.addColumn(self.__tr("Static/Dynamic"))
  678.         self.infoListView.addColumn(self.__tr("Key"))
  679.         self.infoListView.addColumn(self.__tr("Value"))
  680.         self.infoListView.setAllColumnsShowFocus(1)
  681.         self.infoListView.setShowSortIndicator(1)
  682.         self.infoListView.setColumnWidth(0, 50)
  683.         self.infoListView.setColumnWidth(1, 150)
  684.         self.infoListView.setColumnWidth(2, 300)
  685.         self.infoListView.setItemMargin(2)
  686.         self.infoListView.setSorting(-1)
  687.  
  688.         layout37.addMultiCellWidget(self.infoListView,1,1,0,3)
  689.  
  690.         mq_keys = self.cur_device.mq.keys()
  691.         mq_keys.sort()
  692.         mq_keys.reverse()
  693.         for key,i in zip(mq_keys, range(len(mq_keys))):
  694.             QListViewItem(self.infoListView, self.__tr("Static"), key, str(self.cur_device.mq[key]))
  695.  
  696.         dq_keys = self.cur_device.dq.keys()
  697.         dq_keys.sort()
  698.         dq_keys.reverse()
  699.         for key,i in zip(dq_keys, range(len(dq_keys))):
  700.             QListViewItem(self.infoListView, self.__tr("Dynamic"), key, str(self.cur_device.dq[key]))
  701.  
  702.         self.addWidget(widget, "file_list", maximize=True)
  703.  
  704.     def navButton_clicked(self):
  705.         if self.toolbox_hosted:
  706.             self.form.SwitchMaintTab("tools")
  707.         else:
  708.             self.form.close()
  709.  
  710.     def __tr(self,s,c = None):
  711.         return qApp.translate("ScrollDeviceInfoView",s,c)
  712.  
  713.  
  714.         
  715. #
  716. #
  717. # ScrollTestpageView (Print Test Page)
  718. #
  719. #
  720.         
  721. class ScrollTestpageView(ScrollView):
  722.     def __init__(self, toolbox_hosted=True, parent = None, form=None, name = None,fl = 0):
  723.         ScrollView.__init__(self,parent,name,fl)
  724.  
  725.         self.form = form
  726.         self.toolbox_hosted = toolbox_hosted
  727.  
  728.     def fillControls(self):
  729.         ScrollView.fillControls(self)
  730.  
  731.         self.addPrinterFaxList()
  732.         
  733.         self.addTestpageType()
  734.         
  735.         self.addLoadPaper()
  736.         
  737.         if self.toolbox_hosted:
  738.             s = self.__tr("<< Tools")
  739.         else:
  740.             s = self.__tr("Close")
  741.             
  742.         self.printButton = self.addActionButton("bottom_nav", self.__tr("Print Test Page"), 
  743.                                 self.printButton_clicked, s, self.navButton_clicked)
  744.                                 
  745.  
  746.     def addTestpageType(self):
  747.         self.addGroupHeading("testpage_type", self.__tr("Test Page Type"))
  748.         widget = self.getWidget()
  749.         
  750.         Form4Layout = QGridLayout(widget,1,1,5,10,"Form4Layout")
  751.  
  752.         self.buttonGroup3 = QButtonGroup(widget,"buttonGroup3")
  753.         self.buttonGroup3.setLineWidth(0)
  754.         self.buttonGroup3.setColumnLayout(0,Qt.Vertical)
  755.         self.buttonGroup3.layout().setSpacing(5)
  756.         self.buttonGroup3.layout().setMargin(10)
  757.         
  758.         buttonGroup3Layout = QGridLayout(self.buttonGroup3.layout())
  759.         buttonGroup3Layout.setAlignment(Qt.AlignTop)
  760.  
  761.         self.radioButton6 = QRadioButton(self.buttonGroup3,"radioButton6")
  762.         self.radioButton6.setEnabled(False)
  763.         buttonGroup3Layout.addWidget(self.radioButton6,1,0)
  764.  
  765.         self.radioButton5 = QRadioButton(self.buttonGroup3,"radioButton5")
  766.         self.radioButton5.setChecked(1)
  767.         buttonGroup3Layout.addWidget(self.radioButton5,0,0)
  768.  
  769.         Form4Layout.addWidget(self.buttonGroup3,0,0)
  770.         
  771.         self.radioButton6.setText(self.__tr("Printer diagnostic page (does not test print driver)"))
  772.         self.radioButton5.setText(self.__tr("HPLIP test page (tests print driver)"))
  773.         
  774.                                 
  775.         self.addWidget(widget, "page_type")
  776.                                 
  777.                                 
  778.     def navButton_clicked(self):
  779.         if self.toolbox_hosted:
  780.             self.form.SwitchMaintTab("tools")
  781.         else:
  782.             self.form.close()
  783.             
  784.     def printButton_clicked(self):
  785.         d = self.cur_device
  786.         printer_name = self.cur_printer
  787.         printed = False
  788.         
  789.         try:
  790.             QApplication.setOverrideCursor(QApplication.waitCursor)
  791.             
  792.             try:
  793.                 d.open()
  794.             except Error:
  795.                 self.CheckDeviceUI()
  796.             else:
  797.                 if d.isIdleAndNoError():
  798.                     QApplication.restoreOverrideCursor()
  799.                     d.close()
  800.     
  801.                     d.printTestPage(printer_name)
  802.                     printed = True
  803.     
  804.                 else:
  805.                     d.close()
  806.                     self.CheckDeviceUI()
  807.  
  808.         finally:
  809.             QApplication.restoreOverrideCursor()
  810.  
  811.         if printed:
  812.                 QMessageBox.information(self,
  813.                                      self.caption(),
  814.                                      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."),
  815.                                       QMessageBox.Ok,
  816.                                       QMessageBox.NoButton,
  817.                                       QMessageBox.NoButton)
  818.         
  819.         
  820.         if self.toolbox_hosted:
  821.             self.form.SwitchMaintTab("tools")
  822.         else:
  823.             self.form.close()
  824.     
  825.  
  826.     def __tr(self,s,c = None):
  827.         return qApp.translate("ScrollTestpageView",s,c)
  828.         
  829.         
  830.         
  831.         
  832.         
  833.  
  834.  
  835. #
  836. #
  837. # ScrollPrinterInfoView (View Device Information)
  838. #
  839. #
  840.  
  841. class ScrollPrinterInfoView(ScrollView):
  842.     def __init__(self, toolbox_hosted=True, parent = None, form=None, name = None,fl = 0):
  843.         ScrollView.__init__(self,parent,name,fl)
  844.  
  845.         self.form = form
  846.         self.toolbox_hosted = toolbox_hosted
  847.  
  848.     def fillControls(self):
  849.         ScrollView.fillControls(self)
  850.  
  851.         printers = []
  852.         for p in self.printers:
  853.             if p.device_uri == self.cur_device.device_uri or \
  854.                 p.device_uri.replace("hpfax:", "hp:") == self.cur_device.device_uri:
  855.                 
  856.                 printers.append(p)
  857.                 
  858.         if not printers:
  859.             self.addGroupHeading("error_title", self.__tr("No printers found for this device."))
  860.         else:
  861.             for p in printers:
  862.                 self.addPrinterInfo(p)
  863.                 
  864.         if self.toolbox_hosted:
  865.             self.navButton = self.addActionButton("bottom_nav", "", 
  866.                                     None, self.__tr("<< Tools"), self.navButton_clicked)
  867.         else:
  868.             self.navButton = self.addActionButton("bottom_nav", self.__tr("Close"), 
  869.                                     self.navButton_clicked, "", None)
  870.  
  871.         self.maximizeControl()
  872.  
  873.     def addPrinterInfo(self, p):
  874.         self.addGroupHeading(p.name, p.name)
  875.         widget = self.getWidget()
  876.  
  877.         layout1 = QVBoxLayout(widget,5,10,"layout1")
  878.  
  879.         textLabel2 = QLabel(widget,"textLabel2")
  880.         
  881.         if p.device_uri.startswith("hpfax:"):
  882.             s = self.__tr("Fax")
  883.         else:
  884.             s = self.__tr("Printer")
  885.         textLabel2.setText(self.__tr("Type: %1").arg(s))
  886.         layout1.addWidget(textLabel2)
  887.  
  888.         textLabel3 = QLabel(widget,"textLabel3")
  889.         textLabel3.setText(self.__tr("Location: %1").arg(p.location))
  890.         layout1.addWidget(textLabel3)
  891.  
  892.         textLabel4 = QLabel(widget,"textLabel4")
  893.         textLabel4.setText(self.__tr("Description/Info: %1").arg(p.info))
  894.         layout1.addWidget(textLabel4)
  895.  
  896.         textLabel5 = QLabel(widget,"textLabel5")
  897.         
  898.         if p.state == cups.IPP_PRINTER_STATE_IDLE:
  899.             s = self.__tr("Idle")
  900.         elif p.state == cups.IPP_PRINTER_STATE_PROCESSING:
  901.             s = self.__tr("Processing")
  902.         elif p.state == cups.IPP_PRINTER_STATE_STOPPED:
  903.             s = self.__tr("Stopped")
  904.         else:
  905.             s = self.__tr("Unknown")
  906.         
  907.         textLabel5.setText(self.__tr("State: %1").arg(s))
  908.         layout1.addWidget(textLabel5)
  909.  
  910.         textLabel6 = QLabel(widget,"textLabel6")
  911.         textLabel6.setText(self.__tr("PPD/Driver: %1").arg(p.makemodel))
  912.         layout1.addWidget(textLabel6)
  913.  
  914.         textLabel7 = QLabel(widget,"textLabel7")
  915.         textLabel7.setText(self.__tr("CUPS/IPP Printer URI: %1").arg(p.printer_uri))
  916.         layout1.addWidget(textLabel7)
  917.  
  918.         self.addWidget(widget, p.name)
  919.  
  920.     def navButton_clicked(self):
  921.         if self.toolbox_hosted:
  922.             self.form.SwitchMaintTab("tools")
  923.         else:
  924.             self.form.close()
  925.  
  926.     def __tr(self,s,c = None):
  927.         return qApp.translate("ScrollPrinterInfoView",s,c)
  928.