home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_1345 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  2.3 KB  |  50 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. __license__ = 'GPL v3'
  6. __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
  7. __docformat__ = 'restructuredtext en'
  8. import textwrap
  9. from PyQt4.Qt import QComboBox, QStringList, Qt
  10. from calibre.gui2 import config as gui_conf
  11.  
  12. class HistoryBox(QComboBox):
  13.     
  14.     def __init__(self, parent = None):
  15.         QComboBox.__init__(self, parent)
  16.         self.setEditable(True)
  17.  
  18.     
  19.     def initialize(self, opt_name, default, help = None):
  20.         self.opt_name = opt_name
  21.         self.set_value(default)
  22.         if help:
  23.             self.setStatusTip(help)
  24.             help = '\n'.join(textwrap.wrap(help))
  25.             self.setToolTip(help)
  26.             self.setWhatsThis(help)
  27.         
  28.  
  29.     
  30.     def set_value(self, val):
  31.         history = gui_conf[self.opt_name]
  32.         if val not in history:
  33.             history.append(val)
  34.         
  35.         self.clear()
  36.         self.addItems(QStringList(history))
  37.         self.setCurrentIndex(self.findText(val, Qt.MatchFixedString))
  38.  
  39.     
  40.     def save_history(self, opt_name):
  41.         history = [ unicode(self.itemText(i)) for i in range(self.count()) ]
  42.         ct = self.text()
  43.         gui_conf[opt_name] = history[:10]
  44.  
  45.     
  46.     def text(self):
  47.         return unicode(self.currentText()).strip()
  48.  
  49.  
  50.