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 / devmgr4.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-04-29  |  36.9 KB  |  1,073 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. from __future__ import generators
  5. import sys
  6. import time
  7. import os
  8. import gzip
  9. from base.g import *
  10. from base import device, utils, service
  11. from prnt import cups
  12. from base.codes import *
  13. from qt import *
  14. from devmgr4_base import DevMgr4_base
  15. from scrollview import ScrollView
  16. from scrollfunc import ScrollFunctionsView
  17. from scrollstatus import ScrollStatusView
  18. from scrollprintsettings import ScrollPrintSettingsView
  19. from scrollprintcontrol import ScrollPrintJobView
  20. from scrolltool import ScrollToolView, ScrollDeviceInfoView, ScrollTestpageView, ScrollPrinterInfoView
  21. from scrollsupplies import ScrollSuppliesView
  22. from scrollprint import ScrollPrintView
  23. from scrollfax import ScrollFaxView
  24. from nodevicesform import NoDevicesForm
  25. from settingsdialog import SettingsDialog
  26. from aboutdlg import AboutDlg
  27. MIN_AUTO_REFRESH_RATE = 5
  28. MAX_AUTO_REFRESH_RATE = 60
  29. DEF_AUTO_REFRESH_RATE = 30
  30.  
  31. class IconViewItem(QIconViewItem):
  32.     
  33.     def __init__(self, parent, text, pixmap, device_uri, is_avail = True):
  34.         QIconViewItem.__init__(self, parent, text, pixmap)
  35.         self.device_uri = device_uri
  36.         self.is_avail = is_avail
  37.  
  38.  
  39.  
  40. class PasswordDialog(QDialog):
  41.     
  42.     def __init__(self, prompt, parent = None, name = None, modal = 0, fl = 0):
  43.         QDialog.__init__(self, parent, name, modal, fl)
  44.         if not name:
  45.             self.setName('PasswordDialog')
  46.         
  47.         passwordDlg_baseLayout = QGridLayout(self, 1, 1, 11, 6, 'passwordDlg_baseLayout')
  48.         self.passwordLineEdit = QLineEdit(self, 'passwordLineEdit')
  49.         self.passwordLineEdit.setEchoMode(QLineEdit.Password)
  50.         passwordDlg_baseLayout.addMultiCellWidget(self.passwordLineEdit, 1, 1, 0, 1)
  51.         self.promptTextLabel = QLabel(self, 'promptTextLabel')
  52.         passwordDlg_baseLayout.addMultiCellWidget(self.promptTextLabel, 0, 0, 0, 1)
  53.         spacer1 = QSpacerItem(20, 61, QSizePolicy.Minimum, QSizePolicy.Expanding)
  54.         passwordDlg_baseLayout.addItem(spacer1, 2, 0)
  55.         spacer2 = QSpacerItem(321, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  56.         passwordDlg_baseLayout.addItem(spacer2, 3, 0)
  57.         self.okPushButton = QPushButton(self, 'okPushButton')
  58.         passwordDlg_baseLayout.addWidget(self.okPushButton, 3, 1)
  59.         self.languageChange()
  60.         self.resize(QSize(420, 163).expandedTo(self.minimumSizeHint()))
  61.         self.clearWState(Qt.WState_Polished)
  62.         self.connect(self.okPushButton, SIGNAL('clicked()'), self.accept)
  63.         self.connect(self.passwordLineEdit, SIGNAL('returnPressed()'), self.accept)
  64.         self.promptTextLabel.setText(prompt)
  65.  
  66.     
  67.     def getPassword(self):
  68.         return str(self.passwordLineEdit.text())
  69.  
  70.     
  71.     def languageChange(self):
  72.         self.setCaption(self._PasswordDialog__tr('HP Device Manager - Enter Password'))
  73.         self.okPushButton.setText(self._PasswordDialog__tr('OK'))
  74.  
  75.     
  76.     def __tr(self, s, c = None):
  77.         return qApp.translate('PasswordDialog', s, c)
  78.  
  79.  
  80.  
  81. def PasswordUI(prompt):
  82.     QApplication.restoreOverrideCursor()
  83.     dlg = PasswordDialog(prompt, None)
  84.     if dlg.exec_loop() == QDialog.Accepted:
  85.         return dlg.getPassword()
  86.     
  87.     QApplication.setOverrideCursor(QApplication.waitCursor)
  88.     return ''
  89.  
  90.  
  91. class DevMgr4(DevMgr4_base):
  92.     
  93.     def __init__(self, hpiod_sock, hpssd_sock, cleanup = None, toolbox_version = '0.0', parent = None, name = None, fl = 0):
  94.         DevMgr4_base.__init__(self, parent, name, fl)
  95.         icon = QPixmap(os.path.join(prop.image_dir, 'HPmenu.png'))
  96.         self.setIcon(icon)
  97.         log.debug('Initializing toolbox UI...')
  98.         self.cleanup = cleanup
  99.         self.hpiod_sock = hpiod_sock
  100.         self.hpssd_sock = hpssd_sock
  101.         self.toolbox_version = toolbox_version
  102.         self.cur_device_uri = user_cfg.last_used.device_uri
  103.         self.devices = { }
  104.         self.device_vars = { }
  105.         self.num_devices = 0
  106.         self.cur_device = None
  107.         self.rescanning = False
  108.         self.email_alerts = utils.to_bool(user_cfg.alerts.email_alerts, False)
  109.         self.email_to_addresses = user_cfg.alerts.email_to_addresses
  110.         self.email_from_address = user_cfg.alerts.email_from_address
  111.         self.auto_refresh = utils.to_bool(user_cfg.refresh.enable, False)
  112.         
  113.         try:
  114.             self.auto_refresh_rate = int(user_cfg.refresh.rate)
  115.         except ValueError:
  116.             self.auto_refresh_rate = DEF_AUTO_REFRESH_RATE
  117.  
  118.         
  119.         try:
  120.             self.auto_refresh_type = int(user_cfg.refresh.type)
  121.         except ValueError:
  122.             self.auto_refresh_type = 0
  123.  
  124.         (cmd_print, cmd_scan, cmd_pcard, cmd_copy, cmd_fax, cmd_fab) = utils.deviceDefaultFunctions()
  125.         if not user_cfg.commands.prnt:
  126.             pass
  127.         self.cmd_print = cmd_print
  128.         self.cmd_print_int = utils.to_bool(user_cfg.commands.prnt_int, True)
  129.         if not user_cfg.commands.scan:
  130.             pass
  131.         self.cmd_scan = cmd_scan
  132.         self.cmd_scan_int = utils.to_bool(user_cfg.commands.scan_int, False)
  133.         if not user_cfg.commands.pcard:
  134.             pass
  135.         self.cmd_pcard = cmd_pcard
  136.         self.cmd_pcard_int = utils.to_bool(user_cfg.commands.pcard_int, False)
  137.         if not user_cfg.commands.cpy:
  138.             pass
  139.         self.cmd_copy = cmd_copy
  140.         self.cmd_copy_int = utils.to_bool(user_cfg.commands.cpy_int, False)
  141.         if not user_cfg.commands.fax:
  142.             pass
  143.         self.cmd_fax = cmd_fax
  144.         self.cmd_fax_int = utils.to_bool(user_cfg.commands.fax_int, False)
  145.         if not user_cfg.commands.fab:
  146.             pass
  147.         self.cmd_fab = cmd_fab
  148.         self.cmd_fab_int = utils.to_bool(user_cfg.commands.fab_int, False)
  149.         log.debug('HPLIP Version: %s' % sys_cfg.hplip.version)
  150.         log.debug('Print command: %s' % self.cmd_print)
  151.         log.debug('Use Internal print command: %s' % self.cmd_print_int)
  152.         log.debug('PCard command: %s' % self.cmd_pcard)
  153.         log.debug('Use internal PCard command: %s' % self.cmd_pcard_int)
  154.         log.debug('Fax command: %s' % self.cmd_fax)
  155.         log.debug('Use internal fax command: %s' % self.cmd_fax_int)
  156.         log.debug('FAB command: %s' % self.cmd_fab)
  157.         log.debug('Use internal FAB command: %s' % self.cmd_fab_int)
  158.         log.debug('Copy command: %s ' % self.cmd_copy)
  159.         log.debug('Use internal copy command: %s ' % self.cmd_copy_int)
  160.         log.debug('Scan command: %s' % self.cmd_scan)
  161.         log.debug('Use internal scan command: %s' % self.cmd_scan_int)
  162.         log.debug('Email alerts: %s' % self.email_alerts)
  163.         log.debug('Email to address(es): %s' % self.email_to_addresses)
  164.         log.debug('Email from address: %s' % self.email_from_address)
  165.         log.debug('Auto refresh: %s' % self.auto_refresh)
  166.         log.debug('Auto refresh rate: %s' % self.auto_refresh_rate)
  167.         log.debug('Auto refresh type: %s' % self.auto_refresh_type)
  168.         if not self.auto_refresh:
  169.             self.autoRefresh.toggle()
  170.         
  171.         self.InitDeviceList()
  172.         self.InitFunctionsTab()
  173.         self.InitStatusTab()
  174.         self.InitMaintTab()
  175.         self.InitSuppliesTab()
  176.         self.InitPrintSettingsTab()
  177.         self.InitPrintJobsTab()
  178.         self.TabIndex = {
  179.             self.FunctionsTab: self.FuncList,
  180.             self.StatusTab: self.StatusList,
  181.             self.MaintTab: self.ToolList,
  182.             self.SuppliesTab: self.SuppliesList,
  183.             self.PrintSettingsTab: self.PrintSettingsList,
  184.             self.PrintJobsTab: self.PrintJobsList,
  185.             self.MaintTab: self.ToolList }
  186.         cups.setPasswordCallback(PasswordUI)
  187.         QTimer.singleShot(0, self.InitialUpdate)
  188.  
  189.     
  190.     def InitialUpdate(self):
  191.         self.RescanDevices(init = True)
  192.         self.refresh_timer = QTimer(self, 'RefreshTimer')
  193.         self.connect(self.refresh_timer, SIGNAL('timeout()'), self.TimedRefresh)
  194.         if self.auto_refresh_rate <= self.auto_refresh_rate:
  195.             pass
  196.         elif self.auto_refresh_rate <= MAX_AUTO_REFRESH_RATE:
  197.             self.refresh_timer.start(self.auto_refresh_rate * 1000)
  198.         
  199.  
  200.     
  201.     def InitDeviceList(self):
  202.         self.DeviceList.setAutoArrange(False)
  203.         self.splitter2.setSizes([
  204.             120,
  205.             700])
  206.  
  207.     
  208.     def InitFunctionsTab(self):
  209.         self.FuncList = ScrollFunctionsView(self.cmd_print, self.cmd_print_int, self.cmd_scan, self.cmd_scan_int, self.cmd_pcard, self.cmd_pcard_int, self.cmd_fax, self.cmd_fax_int, self.cmd_copy, self.cmd_copy_int, self.FunctionsTab, self, 'FuncView')
  210.         self.FuncTabLayout = QGridLayout(self.FunctionsTab, 1, 1, 11, 6, 'FuncTabLayout')
  211.         self.FuncTabLayout.addWidget(self.FuncList, 0, 0)
  212.  
  213.     
  214.     def SwitchFunctionsTab(self, page = 'funcs'):
  215.         self.FuncTabLayout.remove(self.FuncList)
  216.         self.FuncList.hide()
  217.         if page == 'funcs':
  218.             self.Tabs.changeTab(self.FunctionsTab, self._DevMgr4__tr('Functions'))
  219.             self.FuncList = ScrollFunctionsView(self.cmd_print, self.cmd_print_int, self.cmd_scan, self.cmd_scan_int, self.cmd_pcard, self.cmd_pcard_int, self.cmd_fax, self.cmd_fax_int, self.cmd_copy, self.cmd_copy_int, self.FunctionsTab, self, 'FuncView')
  220.         elif page == 'print':
  221.             self.Tabs.changeTab(self.FunctionsTab, self._DevMgr4__tr('Functions > Print'))
  222.             self.FuncList = ScrollPrintView(True, self.FunctionsTab, self, 'PrintView')
  223.         elif page == 'scan':
  224.             pass
  225.         elif page == 'copy':
  226.             pass
  227.         elif page == 'fax':
  228.             self.Tabs.changeTab(self.FunctionsTab, self._DevMgr4__tr('Functions > Fax'))
  229.             self.FuncList = ScrollFaxView(True, self.FunctionsTab, self, 'FaxView')
  230.         elif page == 'pcard':
  231.             pass
  232.         
  233.         self.FuncTabLayout.addWidget(self.FuncList, 0, 0)
  234.         self.FuncList.show()
  235.         self.TabIndex[self.FunctionsTab] = self.FuncList
  236.         self.FuncList.onDeviceChange(self.cur_device)
  237.  
  238.     
  239.     def InitStatusTab(self):
  240.         StatusTabLayout = QGridLayout(self.StatusTab, 1, 1, 11, 6, 'StatusTabLayout')
  241.         self.Panel_2 = QLabel(self.StatusTab, 'Panel_2')
  242.         self.Panel_2.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed, 0, 0, self.Panel_2.sizePolicy().hasHeightForWidth()))
  243.         self.Panel_2.setMinimumSize(QSize(254, 40))
  244.         self.Panel_2.setMaximumSize(QSize(254, 40))
  245.         self.Panel_2.setScaledContents(1)
  246.         StatusTabLayout.addWidget(self.Panel_2, 0, 1)
  247.         spacer21 = QSpacerItem(151, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  248.         StatusTabLayout.addItem(spacer21, 0, 2)
  249.         spacer22 = QSpacerItem(101, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  250.         StatusTabLayout.addItem(spacer22, 0, 0)
  251.         self.StatusList = ScrollStatusView(self.StatusTab, 'statuslist')
  252.         StatusTabLayout.addMultiCellWidget(self.StatusList, 1, 1, 0, 2)
  253.         self.warning_pix_small = QPixmap(os.path.join(prop.image_dir, 'warning_small.png'))
  254.         self.error_pix_small = QPixmap(os.path.join(prop.image_dir, 'error_small.png'))
  255.         self.ok_pix_small = QPixmap(os.path.join(prop.image_dir, 'ok_small.png'))
  256.         self.lowink_pix_small = QPixmap(os.path.join(prop.image_dir, 'inkdrop_small.png'))
  257.         self.lowtoner_pix_small = QPixmap(os.path.join(prop.image_dir, 'toner_small.png'))
  258.         self.busy_pix_small = QPixmap(os.path.join(prop.image_dir, 'busy_small.png'))
  259.         self.lowpaper_pix_small = QPixmap(os.path.join(prop.image_dir, 'paper_small.png'))
  260.         self.SMALL_ICONS = {
  261.             ERROR_STATE_CLEAR: (None, None),
  262.             ERROR_STATE_BUSY: (self.busy_pix_small, self.busy_pix_small),
  263.             ERROR_STATE_ERROR: (self.error_pix_small, self.error_pix_small),
  264.             ERROR_STATE_LOW_SUPPLIES: (self.lowink_pix_small, self.lowtoner_pix_small),
  265.             ERROR_STATE_OK: (self.ok_pix_small, self.ok_pix_small),
  266.             ERROR_STATE_WARNING: (self.warning_pix_small, self.warning_pix_small),
  267.             ERROR_STATE_LOW_PAPER: (self.lowpaper_pix_small, self.lowpaper_pix_small),
  268.             ERROR_STATE_PRINTING: (self.busy_pix_small, self.busy_pix_small),
  269.             ERROR_STATE_SCANNING: (self.busy_pix_small, self.busy_pix_small),
  270.             ERROR_STATE_PHOTOCARD: (self.busy_pix_small, self.busy_pix_small),
  271.             ERROR_STATE_FAXING: (self.busy_pix_small, self.busy_pix_small),
  272.             ERROR_STATE_COPYING: (self.busy_pix_small, self.busy_pix_small) }
  273.         self.blank_lcd = os.path.join(prop.image_dir, 'panel_lcd.xpm')
  274.         self.Panel_2.setPixmap(QPixmap(self.blank_lcd))
  275.  
  276.     
  277.     def InitMaintTab(self):
  278.         self.ToolList = ScrollToolView(True, self.MaintTab, self, 'ToolView')
  279.         self.MaintTabLayout = QGridLayout(self.MaintTab, 1, 1, 11, 6, 'MaintTabLayout')
  280.         self.MaintTabLayout.addWidget(self.ToolList, 0, 0)
  281.  
  282.     
  283.     def SwitchMaintTab(self, page = 'tools'):
  284.         self.MaintTabLayout.remove(self.ToolList)
  285.         self.ToolList.hide()
  286.         if page == 'tools':
  287.             self.Tabs.changeTab(self.MaintTab, self._DevMgr4__tr('Tools'))
  288.             self.ToolList = ScrollToolView(True, self.MaintTab, self, 'ToolView')
  289.         elif page == 'device_info':
  290.             self.Tabs.changeTab(self.MaintTab, self._DevMgr4__tr('Tools > Device Information'))
  291.             self.ToolList = ScrollDeviceInfoView(True, self.MaintTab, self, 'DeviceInfoView')
  292.         elif page == 'printer_info':
  293.             self.Tabs.changeTab(self.MaintTab, self._DevMgr4__tr('Tools > Printer Information'))
  294.             self.ToolList = ScrollPrinterInfoView(True, self.MaintTab, self, 'PrinterInfoView')
  295.         elif page == 'testpage':
  296.             self.Tabs.changeTab(self.MaintTab, self._DevMgr4__tr('Tools > Print Test Page'))
  297.             self.ToolList = ScrollTestpageView(True, self.MaintTab, self, 'ScrollTestpageView')
  298.         
  299.         self.MaintTabLayout.addWidget(self.ToolList, 0, 0)
  300.         self.ToolList.show()
  301.         self.TabIndex[self.MaintTab] = self.ToolList
  302.         self.ToolList.onDeviceChange(self.cur_device)
  303.  
  304.     
  305.     def InitSuppliesTab(self):
  306.         self.SuppliesList = ScrollSuppliesView(self.SuppliesTab, 'SuppliesView')
  307.         SuppliesTabLayout = QGridLayout(self.SuppliesTab, 1, 1, 11, 6, 'SuppliesTabLayout')
  308.         self.SuppliesList.setHScrollBarMode(QScrollView.AlwaysOff)
  309.         SuppliesTabLayout.addWidget(self.SuppliesList, 0, 0)
  310.  
  311.     
  312.     def InitPrintSettingsTab(self):
  313.         PrintJobsTabLayout = QGridLayout(self.PrintSettingsTab, 1, 1, 11, 6, 'PrintJobsTabLayout')
  314.         self.PrintSettingsList = ScrollPrintSettingsView(self.PrintSettingsTab, 'PrintSettingsView')
  315.         PrintJobsTabLayout.addMultiCellWidget(self.PrintSettingsList, 1, 1, 0, 5)
  316.         self.PrintSettingsPrinterCombo = QComboBox(0, self.PrintSettingsTab, 'comboBox5')
  317.         self.PrintSettingsPrinterCombo.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed, 0, 0, self.PrintSettingsPrinterCombo.sizePolicy().hasHeightForWidth()))
  318.         PrintJobsTabLayout.addMultiCellWidget(self.PrintSettingsPrinterCombo, 0, 0, 2, 3)
  319.         textLabel12 = QLabel(self.PrintSettingsTab, 'textLabel12')
  320.         PrintJobsTabLayout.addWidget(textLabel12, 0, 1)
  321.         textLabel12.setText(self._DevMgr4__tr('Printer Name:'))
  322.         spacer34 = QSpacerItem(171, 20, QSizePolicy.Preferred, QSizePolicy.Minimum)
  323.         PrintJobsTabLayout.addMultiCell(spacer34, 0, 0, 4, 5)
  324.         spacer35 = QSpacerItem(71, 20, QSizePolicy.Preferred, QSizePolicy.Minimum)
  325.         PrintJobsTabLayout.addItem(spacer35, 0, 0)
  326.         self.connect(self.PrintSettingsPrinterCombo, SIGNAL('activated(const QString&)'), self.SettingsPrinterCombo_activated)
  327.  
  328.     
  329.     def InitPrintJobsTab(self):
  330.         PrintJobsTabLayout = QGridLayout(self.PrintJobsTab, 1, 1, 11, 6, 'PrintJobsTabLayout')
  331.         self.PrintJobsList = ScrollPrintJobView(self.PrintJobsTab, 'PrintJobsView')
  332.         PrintJobsTabLayout.addMultiCellWidget(self.PrintJobsList, 1, 1, 0, 5)
  333.         self.PrintJobPrinterCombo = QComboBox(0, self.PrintJobsTab, 'comboBox5')
  334.         self.PrintJobPrinterCombo.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed, 0, 0, self.PrintJobPrinterCombo.sizePolicy().hasHeightForWidth()))
  335.         PrintJobsTabLayout.addMultiCellWidget(self.PrintJobPrinterCombo, 0, 0, 2, 3)
  336.         textLabel12 = QLabel(self.PrintJobsTab, 'textLabel12')
  337.         PrintJobsTabLayout.addWidget(textLabel12, 0, 1)
  338.         textLabel12.setText(self._DevMgr4__tr('Printer Name:'))
  339.         spacer34 = QSpacerItem(171, 20, QSizePolicy.Preferred, QSizePolicy.Minimum)
  340.         PrintJobsTabLayout.addMultiCell(spacer34, 0, 0, 4, 5)
  341.         spacer35 = QSpacerItem(71, 20, QSizePolicy.Preferred, QSizePolicy.Minimum)
  342.         PrintJobsTabLayout.addItem(spacer35, 0, 0)
  343.         self.connect(self.PrintJobPrinterCombo, SIGNAL('activated(const QString&)'), self.JobsPrinterCombo_activated)
  344.  
  345.     
  346.     def TimedRefresh(self):
  347.         if self.auto_refresh:
  348.             log.debug('Refresh timer...')
  349.             self.CleanupChildren()
  350.             if self.auto_refresh_type == 0:
  351.                 self.UpdateDevice()
  352.             else:
  353.                 self.RescanDevices()
  354.         
  355.  
  356.     
  357.     def autoRefresh_toggled(self, a0):
  358.         self.auto_refresh = bool(a0)
  359.         self.SaveConfig()
  360.  
  361.     
  362.     def closeEvent(self, event):
  363.         self.Cleanup()
  364.         event.accept()
  365.  
  366.     
  367.     def RescanDevices(self, init = False):
  368.         if not self.rescanning:
  369.             self.deviceRefreshAll.setEnabled(False)
  370.             self.DeviceListRefresh()
  371.             self.deviceRefreshAll.setEnabled(True)
  372.             if not init:
  373.                 self.UpdateDevice()
  374.             
  375.         
  376.  
  377.     
  378.     def ActivateDevice(self, device_uri):
  379.         log.debug(utils.bold('Activate: %s %s %s' % ('********************', device_uri, '********************')))
  380.         d = self.DeviceList.firstItem()
  381.         found = False
  382.         while d is not None:
  383.             if d.device_uri == device_uri:
  384.                 found = True
  385.                 self.DeviceList.setSelected(d, True)
  386.                 break
  387.             
  388.             d = d.nextItem()
  389.         return found
  390.  
  391.     
  392.     def Cleanup(self):
  393.         self.CleanupChildren()
  394.         if self.cleanup is not None:
  395.             self.cleanup()
  396.         
  397.  
  398.     
  399.     def CleanupChildren(self):
  400.         log.debug('Cleaning up child processes.')
  401.         
  402.         try:
  403.             os.waitpid(-1, os.WNOHANG)
  404.         except OSError:
  405.             pass
  406.  
  407.  
  408.     
  409.     def DeviceList_currentChanged(self, a0):
  410.         if not self.rescanning:
  411.             
  412.             try:
  413.                 self.cur_device_uri = self.DeviceList.currentItem().device_uri
  414.                 self.cur_device = self.devices[self.cur_device_uri]
  415.                 user_cfg.last_used.device_uri = self.cur_device_uri
  416.             except AttributeError:
  417.                 pass
  418.  
  419.             self.UpdateDevice()
  420.         
  421.  
  422.     
  423.     def DeviceList_rightButtonClicked(self, item, pos):
  424.         popup = QPopupMenu(self)
  425.         if item is not None:
  426.             if self.cur_device.error_state != ERROR_STATE_ERROR:
  427.                 if self.cmd_print_int:
  428.                     popup.insertItem(self._DevMgr4__tr('Print >>'), self.PrintButton_clicked)
  429.                 else:
  430.                     popup.insertItem(self._DevMgr4__tr('Print...'), self.PrintButton_clicked)
  431.                 if self.cur_device.scan_type:
  432.                     if self.cmd_scan_int:
  433.                         popup.insertItem(self._DevMgr4__tr('Scan >>'), self.ScanButton_clicked)
  434.                     else:
  435.                         popup.insertItem(self._DevMgr4__tr('Scan...'), self.ScanButton_clicked)
  436.                 
  437.                 if self.cur_device.pcard_type:
  438.                     if self.cmd_pcard_int:
  439.                         popup.insertItem(self._DevMgr4__tr('Access Photo Cards >>'), self.PCardButton_clicked)
  440.                     else:
  441.                         popup.insertItem(self._DevMgr4__tr('Access Photo Cards...'), self.PCardButton_clicked)
  442.                 
  443.                 if self.cur_device.fax_type:
  444.                     if self.cmd_fax_int:
  445.                         popup.insertItem(self._DevMgr4__tr('Send Fax >>'), self.SendFaxButton_clicked)
  446.                     else:
  447.                         popup.insertItem(self._DevMgr4__tr('Send Fax...'), self.SendFaxButton_clicked)
  448.                 
  449.                 if self.cur_device.copy_type:
  450.                     if self.cmd_copy_int:
  451.                         popup.insertItem(self._DevMgr4__tr('Make Copies >>'), self.MakeCopiesButton_clicked)
  452.                     else:
  453.                         popup.insertItem(self._DevMgr4__tr('Make Copies...'), self.MakeCopiesButton_clicked)
  454.                 
  455.                 popup.insertSeparator()
  456.             
  457.             if self.cur_device.device_settings_ui is not None:
  458.                 popup.insertItem(self._DevMgr4__tr('Device Settings...'), self.deviceSettingsButton_clicked)
  459.             
  460.             popup.insertItem(self._DevMgr4__tr('Refresh Device'), self.UpdateDevice)
  461.         
  462.         popup.insertItem(self._DevMgr4__tr('Refresh All'), self.deviceRefreshAll_activated)
  463.         popup.popup(pos)
  464.  
  465.     
  466.     def UpdateDevice(self, check_state = True):
  467.         if self.cur_device is not None:
  468.             log.debug(utils.bold('Update: %s %s %s' % ('********************', self.cur_device_uri, '********************')))
  469.             self.setCaption(self._DevMgr4__tr('HP Device Manager - %1').arg(self.cur_device.model_ui))
  470.             if not self.rescanning:
  471.                 self.statusBar().message(self.cur_device_uri)
  472.             
  473.             if not self.rescanning:
  474.                 self.UpdateHistory()
  475.                 self.Tabs_currentChanged(self.Tabs.currentPage())
  476.                 self.UpdatePrinterCombos()
  477.                 self.UpdatePanel()
  478.                 self.setupDevice.setEnabled(self.cur_device.device_settings_ui is not None)
  479.             
  480.         
  481.  
  482.     
  483.     def UpdatePrinterCombos(self):
  484.         if self.cur_device is not None and self.cur_device.supported:
  485.             self.PrintSettingsPrinterCombo.clear()
  486.             self.PrintJobPrinterCombo.clear()
  487.             printers = cups.getPrinters()
  488.             self.cur_device.cups_printers = []
  489.             cur_device_uri_tail = self.cur_device_uri.split(':')[1]
  490.             for p in printers:
  491.                 p_tail = p.device_uri.split(':')[1]
  492.                 if p_tail == cur_device_uri_tail:
  493.                     self.cur_device.cups_printers.append(p.name)
  494.                     continue
  495.             
  496.             for c in self.cur_device.cups_printers:
  497.                 self.PrintSettingsPrinterCombo.insertItem(c)
  498.                 self.PrintJobPrinterCombo.insertItem(c)
  499.             
  500.             self.current_printer = str(self.PrintSettingsPrinterCombo.currentText())
  501.         
  502.  
  503.     
  504.     def SettingsPrinterCombo_activated(self, s):
  505.         self.current_printer = str(s)
  506.         self.PrintJobPrinterCombo.setCurrentText(self.current_printer)
  507.         return self.PrinterCombo_activated(self.current_printer)
  508.  
  509.     
  510.     def JobsPrinterCombo_activated(self, s):
  511.         self.current_printer = str(s)
  512.         self.PrintSettingsPrinterCombo.setCurrentText(s)
  513.         return self.PrinterCombo_activated(self.current_printer)
  514.  
  515.     
  516.     def PrinterCombo_activated(self, printer):
  517.         self.PrintJobsList.onPrinterChange(printer)
  518.         self.PrintSettingsList.onPrinterChange(printer)
  519.         self.FuncList.onPrinterChange(printer)
  520.  
  521.     
  522.     def Tabs_currentChanged(self, tab):
  523.         
  524.         try:
  525.             self.TabIndex[tab].onDeviceChange(self.cur_device)
  526.         except AttributeError:
  527.             self.TabIndex[tab]()
  528.  
  529.  
  530.     
  531.     def CreatePixmap(self, dev = None):
  532.         if dev is None:
  533.             dev = self.cur_device
  534.         
  535.         
  536.         try:
  537.             pix = QPixmap(os.path.join(prop.image_dir, dev.icon))
  538.         except AttributeError:
  539.             pix = QPixmap(os.path.join(prop.image_dir, 'default_printer.png'))
  540.  
  541.         error_state = dev.error_state
  542.         icon = QPixmap(pix.width(), pix.height())
  543.         p = QPainter(icon)
  544.         p.eraseRect(0, 0, icon.width(), icon.height())
  545.         p.drawPixmap(0, 0, pix)
  546.         
  547.         try:
  548.             tech_type = dev.tech_type
  549.         except AttributeError:
  550.             tech_type = TECH_TYPE_NONE
  551.  
  552.         if error_state != ERROR_STATE_CLEAR:
  553.             if tech_type in (TECH_TYPE_COLOR_INK, TECH_TYPE_MONO_INK):
  554.                 status_icon = self.SMALL_ICONS[error_state][0]
  555.             else:
  556.                 status_icon = self.SMALL_ICONS[error_state][1]
  557.             if status_icon is not None:
  558.                 p.drawPixmap(0, 0, status_icon)
  559.             
  560.         
  561.         p.end()
  562.         return icon
  563.  
  564.     
  565.     def DeviceListRefresh(self):
  566.         log.debug('Rescanning device list...')
  567.         if not self.rescanning:
  568.             self.setCaption(self._DevMgr4__tr('Refreshing Device List - HP Device Manager'))
  569.             self.statusBar().message(self._DevMgr4__tr('Refreshing device list...'))
  570.             self.rescanning = True
  571.             total_changes = 0
  572.             total_steps = 0
  573.             self.cups_devices = device.getSupportedCUPSDevices()
  574.             QApplication.setOverrideCursor(QApplication.waitCursor)
  575.             for d in self.cups_devices:
  576.                 if d not in self.devices:
  577.                     total_steps += 1
  578.                     total_changes += 1
  579.                     continue
  580.             
  581.             updates = []
  582.             for d in self.devices:
  583.                 if d not in self.cups_devices:
  584.                     total_steps += 1
  585.                     total_changes += 1
  586.                     continue
  587.                 if self.cur_device is not None and self.cur_device_uri != d:
  588.                     updates.append(d)
  589.                     total_steps += 1
  590.                     continue
  591.             
  592.             log.debug('total changes = %d' % total_changes)
  593.             step_num = 0
  594.             pb = None
  595.             if total_steps:
  596.                 pb = QProgressBar(self.statusBar(), 'ProgressBar')
  597.                 pb.setTotalSteps(total_changes + total_steps)
  598.                 self.statusBar().addWidget(pb)
  599.                 pb.show()
  600.             
  601.             if total_changes:
  602.                 for d in self.cups_devices:
  603.                     if d not in self.devices:
  604.                         qApp.processEvents()
  605.                         log.debug('adding: %s' % d)
  606.                         pb.setProgress(step_num)
  607.                         step_num += 1
  608.                         qApp.processEvents()
  609.                         log.debug(utils.bold('Refresh: %s %s %s' % ('********************', d, '********************')))
  610.                         
  611.                         try:
  612.                             dev = device.Device(d, hpiod_sock = self.hpiod_sock, hpssd_sock = self.hpssd_sock, callback = self.callback)
  613.                         except Error:
  614.                             log.error('Unexpected error in Device class.')
  615.                             log.exception()
  616.                             return None
  617.  
  618.                         
  619.                         try:
  620.                             dev.open()
  621.                         except Error:
  622.                             e = None
  623.                             log.warn(e.msg)
  624.                         
  625.  
  626.                         if dev.device_state == DEVICE_STATE_NOT_FOUND:
  627.                             dev.error_state = ERROR_STATE_ERROR
  628.                         else:
  629.                             dev.queryDevice(quick = True)
  630.                         dev.close()
  631.                         self.CheckForDeviceSettingsUI(dev)
  632.                         icon = self.CreatePixmap(dev)
  633.                         IconViewItem(self.DeviceList, dev.model_ui, icon, d)
  634.                         self.devices[d] = dev
  635.                         continue
  636.                 
  637.                 for d in self.devices.keys():
  638.                     if d not in self.cups_devices:
  639.                         qApp.processEvents()
  640.                         item = self.DeviceList.firstItem()
  641.                         log.debug('removing: %s' % d)
  642.                         pb.setProgress(step_num)
  643.                         step_num += 1
  644.                         qApp.processEvents()
  645.                         while item is not None:
  646.                             if item.device_uri == d:
  647.                                 self.DeviceList.takeItem(item)
  648.                                 del self.devices[d]
  649.                                 break
  650.                             
  651.                             item = item.nextItem()
  652.                         continue
  653.                 
  654.             
  655.             for d in updates:
  656.                 log.debug('updating: %s' % d)
  657.                 qApp.processEvents()
  658.                 dev = self.devices[d]
  659.                 pb.setProgress(step_num)
  660.                 step_num += 1
  661.                 qApp.processEvents()
  662.                 prev_error_state = dev.error_state
  663.                 
  664.                 try:
  665.                     dev.open()
  666.                 except Error:
  667.                     e = None
  668.                     log.warn(e.msg)
  669.                 
  670.  
  671.                 if dev.device_state == DEVICE_STATE_NOT_FOUND:
  672.                     dev.error_state = ERROR_STATE_ERROR
  673.                 else:
  674.                     dev.queryDevice(quick = True)
  675.                 dev.close()
  676.                 if dev.error_state != prev_error_state:
  677.                     item = self.DeviceList.firstItem()
  678.                     while item is not None:
  679.                         item = item.nextItem()
  680.                         continue
  681.                         None if item.device_uri == d else dev.device_state == DEVICE_STATE_NOT_FOUND
  682.                     continue
  683.             
  684.             if pb is not None:
  685.                 pb.hide()
  686.                 self.statusBar().removeWidget(pb)
  687.                 pb = None
  688.             
  689.             if not len(self.cups_devices):
  690.                 QApplication.restoreOverrideCursor()
  691.                 self.cur_device = None
  692.                 self.deviceRescanAction.setEnabled(False)
  693.                 self.deviceRemoveAction.setEnabled(False)
  694.                 self.rescanning = False
  695.                 self.statusBar().message(self._DevMgr4__tr('Press F6 to refresh.'))
  696.                 dlg = NoDevicesForm(self, '', True)
  697.                 dlg.show()
  698.                 return None
  699.             
  700.             self.rescanning = False
  701.             if self.cur_device_uri:
  702.                 item = self.DeviceList.firstItem()
  703.                 while item is not None:
  704.                     qApp.processEvents()
  705.                     if item.device_uri == self.cur_device_uri:
  706.                         self.DeviceList.setCurrentItem(item)
  707.                         self.DeviceList.setSelected(item, True)
  708.                         break
  709.                     
  710.                     item = item.nextItem()
  711.                 self.cur_device = None
  712.                 self.cur_device_uri = ''
  713.             
  714.             if not self.cur_device_uri:
  715.                 self.cur_device_uri = self.DeviceList.firstItem().device_uri
  716.                 self.cur_device = self.devices[self.cur_device_uri]
  717.                 self.DeviceList.setCurrentItem(self.DeviceList.firstItem())
  718.             
  719.             user_cfg.last_used.device_uri = self.cur_device_uri
  720.             self.DeviceList.adjustItems()
  721.             self.DeviceList.updateGeometry()
  722.             self.deviceRescanAction.setEnabled(True)
  723.             self.deviceRemoveAction.setEnabled(True)
  724.             QApplication.restoreOverrideCursor()
  725.         
  726.  
  727.     
  728.     def callback(self):
  729.         pass
  730.  
  731.     
  732.     def CheckForDeviceSettingsUI(self, dev):
  733.         dev.device_settings_ui = None
  734.         name = '.'.join([
  735.             'plugins',
  736.             dev.model])
  737.         log.debug('Attempting to load plugin: %s' % name)
  738.         
  739.         try:
  740.             mod = __import__(name, globals(), locals(), [])
  741.         except ImportError:
  742.             log.debug('No plugin found.')
  743.             return None
  744.  
  745.         components = name.split('.')
  746.         for c in components[1:]:
  747.             mod = getattr(mod, c)
  748.         
  749.         log.debug('Loaded: %s' % repr(mod))
  750.         dev.device_settings_ui = mod.settingsUI
  751.  
  752.     
  753.     def UpdateHistory(self):
  754.         
  755.         try:
  756.             self.cur_device.hist = self.cur_device.queryHistory()
  757.         except Error:
  758.             log.error('History query failed.')
  759.             self.cur_device.last_event = None
  760.             self.cur_device.error_state = ERROR_STATE_ERROR
  761.             self.cur_device.status_code = STATUS_UNKNOWN
  762.  
  763.         
  764.         try:
  765.             self.cur_device.last_event = self.cur_device.hist[-1]
  766.         except IndexError:
  767.             self.cur_device.last_event = None
  768.             self.cur_device.error_state = ERROR_STATE_ERROR
  769.             self.cur_device.status_code = STATUS_UNKNOWN
  770.  
  771.  
  772.     
  773.     def UpdatePanel(self):
  774.         if self.cur_device is not None and self.cur_device.supported:
  775.             dq = self.cur_device.dq
  776.             if dq.get('panel', 0) == 1:
  777.                 line1 = dq.get('panel-line1', '')
  778.                 line2 = dq.get('panel-line2', '')
  779.             else:
  780.                 
  781.                 try:
  782.                     line1 = self.cur_device.hist[0][12]
  783.                 except IndexError:
  784.                     line1 = ''
  785.  
  786.                 line2 = ''
  787.             pm = QPixmap(self.blank_lcd)
  788.             p = QPainter()
  789.             p.begin(pm)
  790.             p.setPen(QColor(0, 0, 0))
  791.             p.setFont(self.font())
  792.             (x, y_line1, y_line2) = (10, 17, 33)
  793.             p.drawText(x, y_line1, line1)
  794.             p.drawText(x, y_line2, line2)
  795.             p.end()
  796.             self.Panel_2.setPixmap(pm)
  797.         else:
  798.             self.Panel_2.setPixmap(QPixmap(self.blank_lcd))
  799.  
  800.     
  801.     def settingsConfigure_activated(self, tab_to_show = 0):
  802.         dlg = SettingsDialog(self.hpssd_sock, self)
  803.         dlg.autoRefreshCheckBox.setChecked(self.auto_refresh)
  804.         dlg.AutoRefreshRate.setValue(self.auto_refresh_rate)
  805.         dlg.refreshScopeButtonGroup.setButton(self.auto_refresh_type)
  806.         dlg.auto_refresh_type = self.auto_refresh_type
  807.         dlg.EmailCheckBox.setChecked(self.email_alerts)
  808.         dlg.EmailAddress.setText(self.email_to_addresses)
  809.         dlg.senderLineEdit.setText(self.email_from_address)
  810.         dlg.PrintCommand.setText(self.cmd_print)
  811.         dlg.PrintCommand.setEnabled(not (self.cmd_print_int))
  812.         if self.cmd_print_int:
  813.             dlg.printButtonGroup.setButton(0)
  814.         else:
  815.             dlg.printButtonGroup.setButton(1)
  816.         dlg.ScanCommand.setText(self.cmd_scan)
  817.         dlg.ScanCommand.setEnabled(not (self.cmd_scan_int))
  818.         if self.cmd_scan_int:
  819.             dlg.scanButtonGroup.setButton(0)
  820.         else:
  821.             dlg.scanButtonGroup.setButton(1)
  822.         dlg.AccessPCardCommand.setText(self.cmd_pcard)
  823.         dlg.AccessPCardCommand.setEnabled(not (self.cmd_pcard_int))
  824.         if self.cmd_pcard_int:
  825.             dlg.pcardButtonGroup.setButton(0)
  826.         else:
  827.             dlg.pcardButtonGroup.setButton(1)
  828.         dlg.SendFaxCommand.setText(self.cmd_fax)
  829.         dlg.SendFaxCommand.setEnabled(not (self.cmd_fax_int))
  830.         if self.cmd_fax_int:
  831.             dlg.faxButtonGroup.setButton(0)
  832.         else:
  833.             dlg.faxButtonGroup.setButton(1)
  834.         dlg.MakeCopiesCommand.setText(self.cmd_copy)
  835.         dlg.MakeCopiesCommand.setEnabled(not (self.cmd_copy_int))
  836.         if self.cmd_copy_int:
  837.             dlg.copyButtonGroup.setButton(0)
  838.         else:
  839.             dlg.copyButtonGroup.setButton(1)
  840.         dlg.TabWidget.setCurrentPage(tab_to_show)
  841.         if dlg.exec_loop() == QDialog.Accepted:
  842.             self.cmd_print = str(dlg.PrintCommand.text())
  843.             self.cmd_print_int = dlg.printButtonGroup.selectedId() == 0
  844.             self.cmd_scan = str(dlg.ScanCommand.text())
  845.             self.cmd_scan_int = dlg.scanButtonGroup.selectedId() == 0
  846.             self.cmd_pcard = str(dlg.AccessPCardCommand.text())
  847.             self.cmd_pcard_int = dlg.pcardButtonGroup.selectedId() == 0
  848.             self.cmd_fax = str(dlg.SendFaxCommand.text())
  849.             self.cmd_fax_int = dlg.faxButtonGroup.selectedId() == 0
  850.             self.cmd_copy = str(dlg.MakeCopiesCommand.text())
  851.             self.cmd_copy_int = dlg.copyButtonGroup.selectedId() == 0
  852.             self.email_alerts = bool(dlg.EmailCheckBox.isChecked())
  853.             self.email_to_addresses = str(dlg.EmailAddress.text())
  854.             self.email_from_address = str(dlg.senderLineEdit.text())
  855.             old_auto_refresh = self.auto_refresh
  856.             self.auto_refresh = bool(dlg.autoRefreshCheckBox.isChecked())
  857.             new_refresh_value = int(dlg.AutoRefreshRate.value())
  858.             self.auto_refresh_type = dlg.auto_refresh_type
  859.             if self.auto_refresh and new_refresh_value != self.auto_refresh_rate:
  860.                 self.auto_refresh_rate = new_refresh_value
  861.                 self.refresh_timer.changeInterval(self.auto_refresh_rate * 1000)
  862.             
  863.             if old_auto_refresh != self.auto_refresh:
  864.                 self.autoRefresh.toggle()
  865.             
  866.             self.SetAlerts()
  867.             self.SaveConfig()
  868.         
  869.         self.SwitchFunctionsTab('funcs')
  870.  
  871.     
  872.     def SetAlerts(self):
  873.         service.setAlerts(self.hpssd_sock, self.email_alerts, self.email_to_addresses, self.email_from_address)
  874.  
  875.     
  876.     def SaveConfig(self):
  877.         user_cfg.commands.prnt = self.cmd_print
  878.         user_cfg.commands.prnt_int = self.cmd_print_int
  879.         user_cfg.commands.pcard = self.cmd_pcard
  880.         user_cfg.commands.pcard_int = self.cmd_pcard_int
  881.         user_cfg.commands.fax = self.cmd_fax
  882.         user_cfg.commands.fax_int = self.cmd_fax_int
  883.         user_cfg.commands.scan = self.cmd_scan
  884.         user_cfg.commands.scan_int = self.cmd_scan_int
  885.         user_cfg.commands.cpy = self.cmd_copy
  886.         user_cfg.commands.cpy_int = self.cmd_copy_int
  887.         user_cfg.alerts.email_to_addresses = self.email_to_addresses
  888.         user_cfg.alerts.email_from_address = self.email_from_address
  889.         user_cfg.alerts.email_alerts = self.email_alerts
  890.         user_cfg.refresh.enable = self.auto_refresh
  891.         user_cfg.refresh.rate = self.auto_refresh_rate
  892.         user_cfg.refresh.type = self.auto_refresh_type
  893.  
  894.     
  895.     def deviceRescanAction_activated(self):
  896.         self.deviceRescanAction.setEnabled(False)
  897.         self.UpdateDevice()
  898.         self.deviceRescanAction.setEnabled(True)
  899.  
  900.     
  901.     def deviceRefreshAll_activated(self):
  902.         self.RescanDevices()
  903.  
  904.     
  905.     def DeviceList_clicked(self, a0):
  906.         pass
  907.  
  908.     
  909.     def PrintButton_clicked(self):
  910.         if self.cmd_print_int:
  911.             self.Tabs.setCurrentPage(0)
  912.             self.SwitchFunctionsTab('print')
  913.         else:
  914.             self.RunCommand(self.cmd_print)
  915.  
  916.     
  917.     def ScanButton_clicked(self):
  918.         if self.cmd_scan_int:
  919.             self.Tabs.setCurrentPage(0)
  920.             self.SwitchFunctionsTab('scan')
  921.         else:
  922.             self.RunCommand(self.cmd_scan)
  923.  
  924.     
  925.     def PCardButton_clicked(self):
  926.         if self.cur_device.pcard_type == PCARD_TYPE_MLC:
  927.             if self.cmd_pcard_int:
  928.                 self.Tabs.setCurrentPage(0)
  929.                 self.SwitchFunctionsTab('pcard')
  930.             else:
  931.                 self.RunCommand(self.cmd_pcard)
  932.         elif self.cur_device.pcard_type == PCARD_TYPE_USB_MASS_STORAGE:
  933.             self.FailureUI(self._DevMgr4__tr("<p><b>Photocards on your printer are only available by mounting them as drives using USB mass storage.</b><p>Please refer to your distribution's documentation for setup and usage instructions."))
  934.         
  935.  
  936.     
  937.     def SendFaxButton_clicked(self):
  938.         if self.cmd_fax_int:
  939.             self.Tabs.setCurrentPage(0)
  940.             self.SwitchFunctionsTab('fax')
  941.         else:
  942.             self.RunCommand(self.cmd_fax)
  943.  
  944.     
  945.     def MakeCopiesButton_clicked(self):
  946.         if self.cmd_copy_int:
  947.             self.Tabs.setCurrentPage(0)
  948.             self.SwitchFunctionsTab('copy')
  949.         else:
  950.             self.RunCommand(self.cmd_copy)
  951.  
  952.     
  953.     def ConfigureFeaturesButton_clicked(self):
  954.         self.settingsConfigure_activated(2)
  955.  
  956.     
  957.     def RunCommand(self, cmd, macro_char = '%'):
  958.         QApplication.setOverrideCursor(QApplication.waitCursor)
  959.         
  960.         try:
  961.             if len(cmd) == 0:
  962.                 self.FailureUI(self._DevMgr4__tr('<p><b>Unable to run command. No command specified.</b><p>Use <pre>Configure...</pre> to specify a command to run.'))
  963.                 log.error('No command specified. Use settings to configure commands.')
  964.             else:
  965.                 log.debug(utils.bold('Run: %s %s (%s) %s' % ('********************', cmd, self.cur_device_uri, '********************')))
  966.                 log.debug(cmd)
  967.                 cmd = []([ self.cur_device.device_vars.get(x, x) for x in cmd.split(macro_char) ])
  968.                 log.debug(cmd)
  969.                 path = cmd.split()[0]
  970.                 args = cmd.split()
  971.                 log.debug(path)
  972.                 log.debug(args)
  973.                 self.CleanupChildren()
  974.                 os.spawnvp(os.P_NOWAIT, path, args)
  975.         finally:
  976.             QApplication.restoreOverrideCursor()
  977.  
  978.  
  979.     
  980.     def helpAbout(self):
  981.         dlg = AboutDlg(self)
  982.         dlg.VersionText.setText(prop.version)
  983.         dlg.ToolboxVersionText.setText(self.toolbox_version)
  984.         dlg.exec_loop()
  985.  
  986.     
  987.     def deviceSettingsButton_clicked(self):
  988.         
  989.         try:
  990.             self.cur_device.open()
  991.             self.cur_device.device_settings_ui(self.cur_device, self)
  992.         finally:
  993.             self.cur_device.close()
  994.  
  995.  
  996.     
  997.     def setupDevice_activated(self):
  998.         
  999.         try:
  1000.             self.cur_device.open()
  1001.             self.cur_device.device_settings_ui(self.cur_device, self)
  1002.         finally:
  1003.             self.cur_device.close()
  1004.  
  1005.  
  1006.     
  1007.     def helpContents(self):
  1008.         f = 'file://%s' % os.path.join(sys_cfg.dirs.doc, 'index.html')
  1009.         log.debug(f)
  1010.         utils.openURL(f)
  1011.  
  1012.     
  1013.     def deviceInstallAction_activated(self):
  1014.         su_sudo = None
  1015.         if utils.which('kdesu'):
  1016.             su_sudo = 'kdesu -- "%s"'
  1017.         elif utils.which('gksu'):
  1018.             su_sudo = 'gksu "%s"'
  1019.         
  1020.         if su_sudo is None:
  1021.             QMessageBox.critical(self, self.caption(), self._DevMgr4__tr('<b>Unable to find an appropriate su/sudo utility to run hp-setup.</b>'), QMessageBox.Ok, QMessageBox.NoButton, QMessageBox.NoButton)
  1022.         elif utils.which('hp-setup'):
  1023.             c = 'hp-setup -u --username=%s' % prop.username
  1024.             cmd = su_sudo % c
  1025.         else:
  1026.             c = 'python ./setup.py -u --username=%s' % prop.username
  1027.             cmd = su_sudo % c
  1028.         log.debug(cmd)
  1029.         os.system(cmd)
  1030.         self.RescanDevices()
  1031.  
  1032.     
  1033.     def deviceRemoveAction_activated(self):
  1034.         if self.cur_device is not None:
  1035.             x = QMessageBox.critical(self, self.caption(), '<b>Annoying Confirmation: Are you sure you want to remove this device?</b>', QMessageBox.Yes, QMessageBox.No | QMessageBox.Default, QMessageBox.NoButton)
  1036.             if x == QMessageBox.Yes:
  1037.                 QApplication.setOverrideCursor(QApplication.waitCursor)
  1038.                 print_uri = self.cur_device.device_uri
  1039.                 fax_uri = print_uri.replace('hp:', 'hpfax:')
  1040.                 log.debug(print_uri)
  1041.                 log.debug(fax_uri)
  1042.                 self.cups_devices = device.getSupportedCUPSDevices([
  1043.                     'hp',
  1044.                     'hpfax'])
  1045.                 for d in self.cups_devices:
  1046.                     if d in (print_uri, fax_uri):
  1047.                         for p in self.cups_devices[d]:
  1048.                             log.debug('Removing %s' % p)
  1049.                             cups.delPrinter(p)
  1050.                         
  1051.                 
  1052.                 self.cur_device = None
  1053.                 self.cur_device_uri = ''
  1054.                 user_cfg.last_used.device_uri = ''
  1055.                 QApplication.restoreOverrideCursor()
  1056.                 self.RescanDevices()
  1057.             
  1058.         
  1059.  
  1060.     
  1061.     def FailureUI(self, error_text):
  1062.         QMessageBox.critical(self, self.caption(), error_text, QMessageBox.Ok, QMessageBox.NoButton, QMessageBox.NoButton)
  1063.  
  1064.     
  1065.     def WarningUI(self, msg):
  1066.         QMessageBox.warning(self, self.caption(), msg, QMessageBox.Ok, QMessageBox.NoButton, QMessageBox.NoButton)
  1067.  
  1068.     
  1069.     def __tr(self, s, c = None):
  1070.         return qApp.translate('DevMgr4', s, c)
  1071.  
  1072.  
  1073.