home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1277 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.8 KB  |  84 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. from PyQt4.Qt import QVBoxLayout, QDialog, QLabel, QDialogButtonBox, Qt, QAbstractListModel, QVariant, QListView, QSize
  9. from calibre.gui2 import NONE, file_icon_provider
  10.  
  11. class Formats(QAbstractListModel):
  12.     
  13.     def __init__(self, fmts):
  14.         QAbstractListModel.__init__(self)
  15.         self.fmts = sorted(fmts)
  16.         self.fi = file_icon_provider()
  17.  
  18.     
  19.     def rowCount(self, parent):
  20.         return len(self.fmts)
  21.  
  22.     
  23.     def data(self, index, role):
  24.         row = index.row()
  25.         if role == Qt.DisplayRole:
  26.             return QVariant(self.fmts[row].upper())
  27.         if role == Qt.DecorationRole:
  28.             return QVariant(self.fi.icon_from_ext(self.fmts[row].lower()))
  29.         return NONE
  30.  
  31.     
  32.     def flags(self, index):
  33.         return Qt.ItemIsSelectable | Qt.ItemIsEnabled
  34.  
  35.     
  36.     def fmt(self, idx):
  37.         return self.fmts[idx.row()]
  38.  
  39.  
  40.  
  41. class SelectFormats(QDialog):
  42.     
  43.     def __init__(self, fmt_list, msg, single = False, parent = None):
  44.         QDialog.__init__(self, parent)
  45.         self._l = QVBoxLayout(self)
  46.         self.setLayout(self._l)
  47.         self.setWindowTitle(_('Choose formats'))
  48.         self._m = QLabel(msg)
  49.         self._m.setWordWrap = True
  50.         self._l.addWidget(self._m)
  51.         self.formats = Formats(fmt_list)
  52.         self.fview = QListView(self)
  53.         self._l.addWidget(self.fview)
  54.         self.fview.setModel(self.formats)
  55.         None(self.fview.setSelectionMode if single else self.fview.MultiSelection)
  56.         self.bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self)
  57.         self._l.addWidget(self.bbox)
  58.         self.bbox.accepted.connect(self.accept)
  59.         self.bbox.rejected.connect(self.reject)
  60.         self.fview.setIconSize(QSize(48, 48))
  61.         self.fview.setSpacing(2)
  62.         self.resize(350, 500)
  63.         self.selected_formats = set([])
  64.  
  65.     
  66.     def accept(self, *args):
  67.         for idx in self.fview.selectedIndexes():
  68.             self.selected_formats.add(self.formats.fmt(idx))
  69.         
  70.         QDialog.accept(self, *args)
  71.  
  72.  
  73. if __name__ == '__main__':
  74.     from PyQt4.Qt import QApplication
  75.     app = QApplication([])
  76.     d = SelectFormats([
  77.         'epub',
  78.         'lrf',
  79.         'lit',
  80.         'mobi'], 'Choose a format')
  81.     d.exec_()
  82.     print d.selected_formats
  83.  
  84.