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 / scrollsupplies.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-04-29  |  8.6 KB  |  255 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. from base.g import *
  5. from base import utils
  6. from prnt import cups
  7. from qt import *
  8. from scrollview import ScrollView
  9. import os.path as os
  10. import os
  11.  
  12. class ScrollSuppliesView(ScrollView):
  13.     
  14.     def __init__(self, parent = None, name = None, fl = 0):
  15.         ScrollView.__init__(self, parent, name, fl)
  16.         self.pix_battery = QPixmap(os.path.join(prop.image_dir, 'icon_battery.png'))
  17.         yellow = '#ffff00'
  18.         light_yellow = '#ffffcc'
  19.         cyan = '#00ffff'
  20.         light_cyan = '#ccffff'
  21.         magenta = '#ff00ff'
  22.         light_magenta = '#ffccff'
  23.         black = '#000000'
  24.         blue = '#0000ff'
  25.         dark_grey = '#808080'
  26.         light_grey = '#c0c0c0'
  27.         self.TYPE_TO_PIX_MAP = {
  28.             AGENT_TYPE_UNSPECIFIED: [
  29.                 black],
  30.             AGENT_TYPE_BLACK: [
  31.                 black],
  32.             AGENT_TYPE_CMY: [
  33.                 cyan,
  34.                 magenta,
  35.                 yellow],
  36.             AGENT_TYPE_KCM: [
  37.                 light_cyan,
  38.                 light_magenta,
  39.                 light_yellow],
  40.             AGENT_TYPE_GGK: [
  41.                 dark_grey],
  42.             AGENT_TYPE_YELLOW: [
  43.                 yellow],
  44.             AGENT_TYPE_MAGENTA: [
  45.                 magenta],
  46.             AGENT_TYPE_CYAN: [
  47.                 cyan],
  48.             AGENT_TYPE_CYAN_LOW: [
  49.                 light_cyan],
  50.             AGENT_TYPE_YELLOW_LOW: [
  51.                 light_yellow],
  52.             AGENT_TYPE_MAGENTA_LOW: [
  53.                 light_magenta],
  54.             AGENT_TYPE_BLUE: [
  55.                 blue],
  56.             AGENT_TYPE_KCMY_CM: [
  57.                 yellow,
  58.                 cyan,
  59.                 magenta],
  60.             AGENT_TYPE_LC_LM: [
  61.                 light_cyan,
  62.                 light_magenta],
  63.             AGENT_TYPE_LG_PK: [
  64.                 light_grey,
  65.                 dark_grey],
  66.             AGENT_TYPE_LG: [
  67.                 light_grey],
  68.             AGENT_TYPE_G: [
  69.                 dark_grey],
  70.             AGENT_TYPE_PG: [
  71.                 light_grey],
  72.             AGENT_TYPE_C_M: [
  73.                 cyan,
  74.                 magenta],
  75.             AGENT_TYPE_K_Y: [
  76.                 black,
  77.                 yellow] }
  78.  
  79.     
  80.     def fillControls(self):
  81.         ScrollView.fillControls(self)
  82.         if self.cur_device is not None and self.cur_device.supported and self.cur_device.status_type != STATUS_TYPE_NONE and self.cur_device.device_state != DEVICE_STATE_NOT_FOUND:
  83.             
  84.             try:
  85.                 self.cur_device.sorted_supplies
  86.             except AttributeError:
  87.                 self.cur_device.sorted_supplies = []
  88.  
  89.             if not self.cur_device.sorted_supplies:
  90.                 a = 1
  91.                 while True:
  92.                     
  93.                     try:
  94.                         agent_type = int(self.cur_device.dq['agent%d-type' % a])
  95.                         agent_kind = int(self.cur_device.dq['agent%d-kind' % a])
  96.                     except KeyError:
  97.                         break
  98.  
  99.                     self.cur_device.sorted_supplies.append((a, agent_kind, agent_type))
  100.                     a += 1
  101.                 self.cur_device.sorted_supplies.sort((lambda x, y: if not cmp(x[2], y[2]):
  102. passcmp(x[1], y[1])))
  103.             
  104.             for x in self.cur_device.sorted_supplies:
  105.                 (a, agent_kind, agent_type) = x
  106.                 agent_level = int(self.cur_device.dq['agent%d-level' % a])
  107.                 agent_sku = str(self.cur_device.dq['agent%d-sku' % a])
  108.                 agent_desc = self.cur_device.dq['agent%d-desc' % a]
  109.                 agent_health_desc = self.cur_device.dq['agent%d-health-desc' % a]
  110.                 self.addItem('agent %d' % a, '<b>' + agent_desc + '</b>', agent_sku, agent_health_desc, agent_kind, agent_type, agent_level)
  111.             
  112.         elif not self.cur_device.supported:
  113.             self.addGroupHeading('not_supported', self._ScrollSuppliesView__tr('ERROR: Device not supported.'))
  114.         elif self.cur_device.status_type == STATUS_TYPE_NONE:
  115.             self.addGroupHeading('not_found', self._ScrollSuppliesView__tr('ERROR: Supplies status is not supported on this device.'))
  116.         else:
  117.             self.addGroupHeading('not_found', self._ScrollSuppliesView__tr('ERROR: Device not found. Please check connection and power-on device.'))
  118.  
  119.     
  120.     def getIcon(self, agent_kind, agent_type):
  121.         if agent_kind in (AGENT_KIND_SUPPLY, AGENT_KIND_HEAD, AGENT_KIND_HEAD_AND_SUPPLY, AGENT_KIND_TONER_CARTRIDGE):
  122.             map = self.TYPE_TO_PIX_MAP[agent_type]
  123.             if isinstance(map, list):
  124.                 map_len = len(map)
  125.                 pix = QPixmap(32, 32)
  126.                 pix.fill(qApp.palette().color(QPalette.Active, QColorGroup.Background))
  127.                 p = QPainter()
  128.                 p.begin(pix)
  129.                 p.setBackgroundMode(Qt.OpaqueMode)
  130.                 if map_len == 1:
  131.                     p.setPen(QColor(map[0]))
  132.                     p.setBrush(QBrush(QColor(map[0]), Qt.SolidPattern))
  133.                     p.drawPie(8, 8, 16, 16, 0, 5760)
  134.                 elif map_len == 2:
  135.                     p.setPen(QColor(map[0]))
  136.                     p.setBrush(QBrush(QColor(map[0]), Qt.SolidPattern))
  137.                     p.drawPie(4, 8, 16, 16, 0, 5760)
  138.                     p.setPen(QColor(map[1]))
  139.                     p.setBrush(QBrush(QColor(map[1]), Qt.SolidPattern))
  140.                     p.drawPie(12, 8, 16, 16, 0, 5760)
  141.                 elif map_len == 3:
  142.                     p.setPen(QColor(map[2]))
  143.                     p.setBrush(QBrush(QColor(map[2]), Qt.SolidPattern))
  144.                     p.drawPie(12, 12, 16, 16, 0, 5760)
  145.                     p.setPen(QColor(map[1]))
  146.                     p.setBrush(QBrush(QColor(map[1]), Qt.SolidPattern))
  147.                     p.drawPie(4, 12, 16, 16, 0, 5760)
  148.                     p.setPen(QColor(map[0]))
  149.                     p.setBrush(QBrush(QColor(map[0]), Qt.SolidPattern))
  150.                     p.drawPie(8, 4, 16, 16, 0, 5760)
  151.                 
  152.                 p.end()
  153.                 return pix
  154.             else:
  155.                 return map
  156.         elif agent_kind == AGENT_KIND_INT_BATTERY:
  157.             return self.pix_battery
  158.         
  159.  
  160.     
  161.     def createBarGraph(self, percent, agent_type, w = 100, h = 18):
  162.         fw = (w / 100) * percent
  163.         px = QPixmap(w, h)
  164.         px.fill(qApp.palette().color(QPalette.Active, QColorGroup.Background))
  165.         pp = QPainter(px)
  166.         pp.setPen(Qt.black)
  167.         pp.setBackgroundColor(qApp.palette().color(QPalette.Active, QColorGroup.Base))
  168.         map = self.TYPE_TO_PIX_MAP[agent_type]
  169.         map_len = len(map)
  170.         if map_len == 1 or map_len > 3:
  171.             pp.fillRect(0, 0, fw, h, QBrush(QColor(map[0])))
  172.         elif map_len == 2:
  173.             h2 = h / 2
  174.             pp.fillRect(0, 0, fw, h2, QBrush(QColor(map[0])))
  175.             pp.fillRect(0, h2, fw, h, QBrush(QColor(map[1])))
  176.         elif map_len == 3:
  177.             h3 = h / 3
  178.             h23 = 2 * h3
  179.             pp.fillRect(0, 0, fw, h3, QBrush(QColor(map[0])))
  180.             pp.fillRect(0, h3, fw, h23, QBrush(QColor(map[1])))
  181.             pp.fillRect(0, h23, fw, h, QBrush(QColor(map[2])))
  182.         
  183.         pp.drawRect(0, 0, w, h)
  184.         if percent > 75 and agent_type in (AGENT_TYPE_BLACK, AGENT_TYPE_UNSPECIFIED, AGENT_TYPE_BLUE):
  185.             pp.setPen(Qt.white)
  186.         
  187.         w1 = 3 * w / 4
  188.         h6 = h / 6
  189.         pp.drawLine(w1, 0, w1, h6)
  190.         pp.drawLine(w1, h, w1, h - h6)
  191.         if percent > 50 and agent_type in (AGENT_TYPE_BLACK, AGENT_TYPE_UNSPECIFIED, AGENT_TYPE_BLUE):
  192.             pp.setPen(Qt.white)
  193.         
  194.         w2 = w / 2
  195.         h4 = h / 4
  196.         pp.drawLine(w2, 0, w2, h4)
  197.         pp.drawLine(w2, h, w2, h - h4)
  198.         if percent > 25 and agent_type in (AGENT_TYPE_BLACK, AGENT_TYPE_UNSPECIFIED, AGENT_TYPE_BLUE):
  199.             pp.setPen(Qt.white)
  200.         
  201.         w4 = w / 4
  202.         pp.drawLine(w4, 0, w4, h6)
  203.         pp.drawLine(w4, h, w4, h - h6)
  204.         return px
  205.  
  206.     
  207.     def addItem(self, name, title_text, part_num_text, status_text, agent_kind, agent_type, percent):
  208.         self.addGroupHeading(title_text, title_text)
  209.         widget = self.getWidget()
  210.         layout1 = QGridLayout(widget, 1, 1, 5, 10, 'layout1')
  211.         spacer1 = QSpacerItem(20, 20, QSizePolicy.Preferred, QSizePolicy.Minimum)
  212.         layout1.addItem(spacer1, 0, 3)
  213.         barGraph = QLabel(widget, 'barGraph')
  214.         barGraph.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed, 0, 0, barGraph.sizePolicy().hasHeightForWidth()))
  215.         barGraph.setMinimumSize(QSize(100, 18))
  216.         barGraph.setMaximumSize(QSize(100, 18))
  217.         barGraph.setScaledContents(1)
  218.         layout1.addMultiCellWidget(barGraph, 0, 0, 4, 5)
  219.         spacer2 = QSpacerItem(20, 20, QSizePolicy.Preferred, QSizePolicy.Minimum)
  220.         layout1.addMultiCell(spacer2, 1, 1, 2, 4)
  221.         statusText = QLabel(widget, 'statusText')
  222.         statusText.setFrameShape(self.frame_shape)
  223.         layout1.addWidget(statusText, 1, 5)
  224.         icon = QLabel(widget, 'icon')
  225.         icon.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed, 0, 0, icon.sizePolicy().hasHeightForWidth()))
  226.         icon.setMinimumSize(QSize(32, 32))
  227.         icon.setMaximumSize(QSize(32, 32))
  228.         icon.setScaledContents(1)
  229.         layout1.addWidget(icon, 0, 0)
  230.         partNumText = QLabel(widget, 'partNumText')
  231.         partNumText.setFrameShape(self.frame_shape)
  232.         partNumText.setSizePolicy(QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred, 0, 0, partNumText.sizePolicy().hasHeightForWidth()))
  233.         partNumText.setAlignment(QLabel.WordBreak | QLabel.AlignVCenter)
  234.         layout1.addWidget(partNumText, 0, 1)
  235.         if part_num_text:
  236.             partNumText.setText(self._ScrollSuppliesView__tr('Part No. %1').arg(part_num_text))
  237.         
  238.         statusText.setText(status_text)
  239.         if agent_kind in (AGENT_KIND_SUPPLY, AGENT_KIND_HEAD_AND_SUPPLY, AGENT_KIND_TONER_CARTRIDGE, AGENT_KIND_MAINT_KIT, AGENT_KIND_ADF_KIT, AGENT_KIND_INT_BATTERY, AGENT_KIND_DRUM_KIT):
  240.             barGraph.setPixmap(self.createBarGraph(percent, agent_type))
  241.         
  242.         if agent_kind in (AGENT_KIND_SUPPLY, AGENT_KIND_HEAD, AGENT_KIND_HEAD_AND_SUPPLY, AGENT_KIND_TONER_CARTRIDGE, AGENT_KIND_INT_BATTERY):
  243.             pix = self.getIcon(agent_kind, agent_type)
  244.             if pix is not None:
  245.                 icon.setPixmap(pix)
  246.             
  247.         
  248.         self.addWidget(widget, name)
  249.  
  250.     
  251.     def __tr(self, s, c = None):
  252.         return qApp.translate('DevMgr4', s, c)
  253.  
  254.  
  255.