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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. from base.g import *
  5. from prnt import cups
  6. from qt import *
  7.  
  8. class Widget(QWidget):
  9.     
  10.     def __init__(self, parent = None, name = None, fl = 0):
  11.         QWidget.__init__(self, parent, name, fl)
  12.         self.control = None
  13.  
  14.     
  15.     def setControl(self, control):
  16.         self.control = control
  17.  
  18.  
  19.  
  20. class ScrollView(QScrollView):
  21.     
  22.     def __init__(self, parent = None, name = None, fl = 0):
  23.         QScrollView.__init__(self, parent, name, fl)
  24.         self.items = { }
  25.         self.enableClipper(True)
  26.         self.viewport().setPaletteBackgroundColor(qApp.palette().color(QPalette.Active, QColorGroup.Background))
  27.         self.cur_device = None
  28.         self.cur_printer = None
  29.         self.item_margin = 2
  30.         self.y = 0
  31.         self.printers = []
  32.         self.maximize = None
  33.         self.orig_height = 0
  34.         if log.get_level() == log.LOG_LEVEL_DEBUG:
  35.             self.heading_color = qApp.palette().color(QPalette.Active, QColorGroup.Base)
  36.             self.frame_shape = QFrame.Box
  37.         else:
  38.             self.heading_color = qApp.palette().color(QPalette.Active, QColorGroup.Background)
  39.             self.frame_shape = QFrame.NoFrame
  40.  
  41.     
  42.     def getWidget(self):
  43.         widget = Widget(self.viewport(), 'widget')
  44.         widget.setPaletteBackgroundColor(qApp.palette().color(QPalette.Active, QColorGroup.Background))
  45.         widget.setSizePolicy(QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Maximum))
  46.         widget.resize(self.visibleWidth(), self.size().height())
  47.         widget.setMinimumWidth(self.visibleWidth())
  48.         widget.resize(self.viewport().size().width(), self.size().height())
  49.         return widget
  50.  
  51.     
  52.     def viewportResizeEvent(self, e):
  53.         QScrollView.viewportResizeEvent(self, e)
  54.         total_height = 0
  55.         item_margin = self.item_margin
  56.         width = e.size().width()
  57.         for w in self.items:
  58.             height = self.items[w].size().height()
  59.             self.items[w].resize(width, height)
  60.             self.items[w].setMinimumWidth(width)
  61.             total_height += height + item_margin
  62.         
  63.         if self.maximize is not None:
  64.             self.maximizeControl(total_height)
  65.         
  66.         self.resizeContents(e.size().width(), total_height)
  67.  
  68.     
  69.     def maximizeControl(self, total_height = 0):
  70.         if self.maximize is not None:
  71.             if total_height == 0:
  72.                 item_margin = self.item_margin
  73.                 for w in self.items:
  74.                     total_height += self.items[w].size().height() + item_margin
  75.                 
  76.             
  77.             width = self.items[self.maximize].size().width()
  78.             old_height = self.items[self.maximize].size().height()
  79.             new_height = max(self.visibleHeight() - total_height - old_height, self.orig_height)
  80.             delta = new_height - old_height
  81.             if delta:
  82.                 self.items[self.maximize].resize(width, new_height)
  83.                 self.resizeContents(width, self.contentsHeight() + delta)
  84.                 m_y = self.childY(self.items[self.maximize])
  85.                 for w in self.items:
  86.                     w_y = self.childY(self.items[w])
  87.                     if w_y > m_y:
  88.                         self.moveChild(self.items[w], 0, w_y + delta)
  89.                         continue
  90.                 
  91.             
  92.         
  93.  
  94.     
  95.     def isFax(self):
  96.         self.is_fax = False
  97.         self.printers = cups.getPrinters()
  98.         for p in self.printers:
  99.             if p.name == self.cur_printer:
  100.                 if p.device_uri.startswith('hpfax:'):
  101.                     self.is_fax = True
  102.                 
  103.                 break
  104.                 continue
  105.         
  106.  
  107.     
  108.     def onDeviceChange(self, cur_device = None):
  109.         if cur_device is not None:
  110.             log.debug('onDeviceChange(%s)' % cur_device.device_uri)
  111.         else:
  112.             log.debug('onDeviceChange(None)')
  113.         if cur_device is not None:
  114.             self.cur_device = cur_device
  115.         
  116.         if self.cur_device is not None and self.cur_device.supported:
  117.             
  118.             try:
  119.                 self.cur_printer = self.cur_device.cups_printers[0]
  120.             except IndexError:
  121.                 log.error('Printer list empty')
  122.  
  123.             self.isFax()
  124.             QApplication.setOverrideCursor(QApplication.waitCursor)
  125.             
  126.             try:
  127.                 self.fillControls()
  128.             except Exception:
  129.                 e = None
  130.                 log.exception()
  131.             finally:
  132.                 QApplication.restoreOverrideCursor()
  133.  
  134.         else:
  135.             log.debug('Unsupported device')
  136.             self.y = 0
  137.             self.clear()
  138.  
  139.     
  140.     def fillControls(self):
  141.         log.debug('fillControls(%s)' % str(self.name()))
  142.         self.y = 0
  143.         self.clear()
  144.  
  145.     
  146.     def onPrinterChange(self, printer_name):
  147.         if printer_name == self.cur_printer:
  148.             return None
  149.         
  150.         self.cur_printer = str(printer_name)
  151.         if self.cur_device is not None and self.cur_device.supported:
  152.             self.isFax()
  153.             QApplication.setOverrideCursor(QApplication.waitCursor)
  154.             
  155.             try:
  156.                 self.fillControls()
  157.             except Exception:
  158.                 e = None
  159.                 log.exception()
  160.             finally:
  161.                 QApplication.restoreOverrideCursor()
  162.  
  163.             
  164.             try:
  165.                 self.printerComboBox.setCurrentText(self.cur_printer)
  166.             except AttributeError:
  167.                 pass
  168.             except:
  169.                 None<EXCEPTION MATCH>AttributeError
  170.             
  171.  
  172.         None<EXCEPTION MATCH>AttributeError
  173.         self.y = 0
  174.         self.clear()
  175.  
  176.     
  177.     def addWidget(self, widget, key, control = None, maximize = False):
  178.         
  179.         try:
  180.             self.items[key]
  181.         except KeyError:
  182.             if maximize:
  183.                 self.maximize = key
  184.                 widget.resize(widget.size().width(), 150)
  185.                 self.orig_height = widget.size().height()
  186.             
  187.             widget.setControl(control)
  188.             self.items[key] = widget
  189.             widget.setMinimumWidth(self.visibleWidth())
  190.             widget.adjustSize()
  191.             self.addChild(widget, 0, self.y)
  192.             self.y += widget.size().height() + self.item_margin
  193.             self.resizeContents(self.visibleWidth(), self.y)
  194.             widget.show()
  195.         except:
  196.             self
  197.  
  198.         log.debug('ERROR: Duplicate control name: %s' % key)
  199.  
  200.     
  201.     def clear(self):
  202.         if len(self.items):
  203.             for x in self.items:
  204.                 self.removeChild(self.items[x])
  205.                 self.items[x].hide()
  206.             
  207.             self.items.clear()
  208.         
  209.  
  210.     
  211.     def addGroupHeading(self, group, heading, read_only = False):
  212.         widget = self.getWidget()
  213.         widget.setMinimumHeight(30)
  214.         widget.setMaximumHeight(30)
  215.         if heading:
  216.             widget.setPaletteBackgroundColor(self.heading_color)
  217.         
  218.         layout = QGridLayout(widget, 1, 1, 5, 10, 'layout')
  219.         textLabel2 = QLabel(widget, 'textLabel2')
  220.         if heading:
  221.             textLabel2.setFrameShape(QFrame.TabWidgetPanel)
  222.         
  223.         textLabel2.setSizePolicy(QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum, 0, 0, textLabel2.sizePolicy().hasHeightForWidth()))
  224.         textLabel2.setAlignment(QLabel.AlignLeft | QLabel.AlignVCenter)
  225.         layout.addWidget(textLabel2, 0, 0)
  226.         if read_only:
  227.             textLabel2.setText(self._ScrollView__tr('<b>%1 (read only)</b>').arg(heading))
  228.         else:
  229.             textLabel2.setText(QString('<b>%1</b>').arg(heading))
  230.         self.addWidget(widget, 'g:' + str(group))
  231.  
  232.     
  233.     def addActionButton(self, name, action_text, action_func, nav_text = '', nav_func = None):
  234.         widget = self.getWidget()
  235.         widget.setPaletteBackgroundColor(qApp.palette().color(QPalette.Active, QColorGroup.Highlight))
  236.         self.actionPushButton = None
  237.         self.navPushButton = None
  238.         layout36 = QHBoxLayout(widget, 5, 10, 'layout36')
  239.         if nav_func is not None:
  240.             self.navPushButton = QPushButton(widget, 'navPushButton')
  241.             navPushButton_font = QFont(self.navPushButton.font())
  242.             navPushButton_font.setBold(1)
  243.             self.navPushButton.setFont(navPushButton_font)
  244.             self.navPushButton.setText(nav_text)
  245.             layout36.addWidget(self.navPushButton)
  246.             self.connect(self.navPushButton, SIGNAL('clicked()'), nav_func)
  247.         
  248.         spacer35 = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  249.         layout36.addItem(spacer35)
  250.         if action_func is not None:
  251.             self.actionPushButton = QPushButton(widget, 'actionPushButton')
  252.             actionPushButton_font = QFont(self.actionPushButton.font())
  253.             actionPushButton_font.setBold(1)
  254.             self.actionPushButton.setFont(actionPushButton_font)
  255.             layout36.addWidget(self.actionPushButton)
  256.             self.actionPushButton.setText(action_text)
  257.             self.connect(self.actionPushButton, SIGNAL('clicked()'), action_func)
  258.         
  259.         self.addWidget(widget, name)
  260.         if self.actionPushButton is not None:
  261.             return self.actionPushButton
  262.         elif self.navPushButton is not None:
  263.             return self.navPushButton
  264.         else:
  265.             return None
  266.  
  267.     
  268.     def printerComboBox_activated(self, p):
  269.         self.cur_printer = str(p)
  270.  
  271.     
  272.     def addPrinterFaxList(self, printers = True, faxes = False):
  273.         widget = self.getWidget()
  274.         layout = QGridLayout(widget, 1, 1, 5, 10, 'layout')
  275.         self.printernameTextLabel = QLabel(widget, 'printernameTextLabel')
  276.         layout.addWidget(self.printernameTextLabel, 0, 0)
  277.         self.printerComboBox = QComboBox(0, widget, 'printerComboBox')
  278.         layout.addWidget(self.printerComboBox, 0, 1)
  279.         if printers and faxes:
  280.             self.addGroupHeading('printer_list_heading', self._ScrollView__tr('Printer/Fax'))
  281.             self.printernameTextLabel.setText(self._ScrollView__tr('Printer/Fax Name:'))
  282.         elif printers:
  283.             self.addGroupHeading('printer_list_heading', self._ScrollView__tr('Printer'))
  284.             self.printernameTextLabel.setText(self._ScrollView__tr('Printer Name:'))
  285.         else:
  286.             self.addGroupHeading('printer_list_heading', self._ScrollView__tr('Fax'))
  287.             self.printernameTextLabel.setText(self._ScrollView__tr('Fax Name:'))
  288.         for p in self.printers:
  289.             if p.device_uri == self.cur_device.device_uri or p.device_uri == self.cur_device.device_uri.replace('hp:', 'hpfax:'):
  290.                 if (p.device_uri.startswith('hpfax:') or faxes or p.device_uri.startswith('hp:')) and printers:
  291.                     self.printerComboBox.insertItem(p.name)
  292.                 
  293.             printers
  294.         
  295.         self.connect(self.printerComboBox, SIGNAL('activated(const QString&)'), self.printerComboBox_activated)
  296.         self.addWidget(widget, 'printer_list')
  297.  
  298.     
  299.     def addLoadPaper(self):
  300.         self.addGroupHeading('load_paper', self._ScrollView__tr('Load Paper'))
  301.         widget = self.getWidget()
  302.         layout1 = QGridLayout(widget, 1, 2, 5, 10, 'layout1')
  303.         layout1.setColStretch(0, 1)
  304.         layout1.setColStretch(1, 10)
  305.         icon = QLabel(widget, 'icon')
  306.         icon.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed, 0, 0, icon.sizePolicy().hasHeightForWidth()))
  307.         icon.setScaledContents(1)
  308.         layout1.addWidget(icon, 0, 0)
  309.         textLabel = QLabel(widget, 'textLabel')
  310.         textLabel.setAlignment(QLabel.WordBreak)
  311.         textLabel.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred, 0, 0, textLabel.sizePolicy().hasHeightForWidth()))
  312.         textLabel.setFrameShape(self.frame_shape)
  313.         layout1.addWidget(textLabel, 0, 1)
  314.         spacer1 = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  315.         layout1.addItem(spacer1, 0, 2)
  316.         textLabel.setText(self._ScrollView__tr('A page will be printed. Please load <b>plain paper</b> into the printer.'))
  317.         icon.setPixmap(QPixmap(os.path.join(prop.image_dir, 'load_paper.png')))
  318.         self.addWidget(widget, 'load_paper')
  319.  
  320.     
  321.     def __tr(self, s, c = None):
  322.         return qApp.translate('DevMgr4', s, c)
  323.  
  324.  
  325.  
  326. class PixmapLabelButton(QPushButton):
  327.     
  328.     def __init__(self, parent = None, pixmap = None, disabled_pixmap = None, name = ''):
  329.         QPushButton.__init__(self, parent, name)
  330.         if type(pixmap) == type(''):
  331.             self.pixmap = QPixmap(os.path.join(prop.image_dir, pixmap))
  332.         else:
  333.             self.pixmap = pixmap
  334.         if type(disabled_pixmap) == type(''):
  335.             self.disabled_pixmap = QPixmap(os.path.join(prop.image_dir, disabled_pixmap))
  336.         else:
  337.             self.disabled_pixmap = disabled_pixmap
  338.         self.pixmap_width = self.pixmap.width()
  339.         self.pixmap_height = self.pixmap.height()
  340.         self.width_set = None
  341.  
  342.     
  343.     def drawButtonLabel(self, painter):
  344.         button_width = self.width()
  345.         button_height = self.height()
  346.         adj = 0
  347.         if self.isDown():
  348.             adj = 1
  349.         
  350.         if self.isEnabled():
  351.             painter.setPen(Qt.black)
  352.         else:
  353.             painter.setPen(Qt.gray)
  354.         text_rect = painter.boundingRect(0, 0, 1000, 1000, Qt.AlignLeft, self.text())
  355.         text_width = text_rect.right() - text_rect.left()
  356.         text_height = text_rect.bottom() - text_rect.top()
  357.         button_width_center = button_width / 2
  358.         button_height_center = button_height / 2
  359.         combined_width_center = (self.pixmap_width + text_width + 10) / 2
  360.         if self.isEnabled():
  361.             painter.drawPixmap((button_width_center - combined_width_center) + adj, (button_height_center - self.pixmap_height / 2) + adj, self.pixmap)
  362.         else:
  363.             painter.drawPixmap((button_width_center - combined_width_center) + adj, (button_height_center - self.pixmap_height / 2) + adj, self.disabled_pixmap)
  364.         if self.width_set is None:
  365.             self.setMinimumWidth(self.pixmap_width + text_width + 20)
  366.             self.width_set = 0
  367.         
  368.         painter.drawText((button_width_center - combined_width_center) + self.pixmap_width + 5 + adj, (button_height_center - text_height / 2) + adj, 1000, 1000, Qt.AlignLeft, self.text())
  369.  
  370.  
  371.