home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1189 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  4.1 KB  |  91 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 Qt, QAbstractListModel, QVariant, SIGNAL
  9. from calibre.gui2.convert.page_setup_ui import Ui_Form
  10. from calibre.gui2.convert import Widget
  11. from calibre.gui2 import NONE
  12. from calibre.customize.ui import input_profiles, output_profiles
  13.  
  14. class ProfileModel(QAbstractListModel):
  15.     
  16.     def __init__(self, profiles):
  17.         QAbstractListModel.__init__(self)
  18.         self.profiles = list(profiles)
  19.  
  20.     
  21.     def rowCount(self, *args):
  22.         return len(self.profiles)
  23.  
  24.     
  25.     def data(self, index, role):
  26.         profile = self.profiles[index.row()]
  27.         if role == Qt.DisplayRole:
  28.             return QVariant(profile.name)
  29.         if role in (Qt.ToolTipRole, Qt.StatusTipRole, Qt.WhatsThisRole):
  30.             return QVariant(profile.description)
  31.         return NONE
  32.  
  33.  
  34.  
  35. class PageSetupWidget(Widget, Ui_Form):
  36.     TITLE = _('Page Setup')
  37.     
  38.     def __init__(self, parent, get_option, get_help, db = None, book_id = None):
  39.         Widget.__init__(self, parent, 'page_setup', [
  40.             'margin_top',
  41.             'margin_left',
  42.             'margin_right',
  43.             'margin_bottom',
  44.             'input_profile',
  45.             'output_profile'])
  46.         self.db = db
  47.         self.book_id = book_id
  48.         self.input_model = ProfileModel(input_profiles())
  49.         self.output_model = ProfileModel(output_profiles())
  50.         self.opt_input_profile.setModel(self.input_model)
  51.         self.opt_output_profile.setModel(self.output_model)
  52.         for x in (self.opt_input_profile, self.opt_output_profile):
  53.             x.setMouseTracking(True)
  54.             self.connect(x, SIGNAL('entered(QModelIndex)'), self.show_desc)
  55.         
  56.         self.initialize_options(get_option, get_help, db, book_id)
  57.         it = unicode(self.opt_input_profile.toolTip())
  58.         self.opt_input_profile.setToolTip('<p>' + it.replace('t.', 't.\n<br>'))
  59.         it = unicode(self.opt_output_profile.toolTip())
  60.         self.opt_output_profile.setToolTip('<p>' + it.replace('t.', 'ce.\n<br>'))
  61.  
  62.     
  63.     def show_desc(self, index):
  64.         desc = index.model().data(index, Qt.StatusTipRole).toString()
  65.         self.profile_description.setText(desc)
  66.  
  67.     
  68.     def set_value_handler(self, g, val):
  69.         if g in (self.opt_input_profile, self.opt_output_profile):
  70.             g.clearSelection()
  71.             for idx, p in enumerate(g.model().profiles):
  72.                 if p.short_name == val:
  73.                     break
  74.                     continue
  75.             
  76.             idx = g.model().index(idx)
  77.             sm = g.selectionModel()
  78.             g.setCurrentIndex(idx)
  79.             sm.select(idx, sm.SelectCurrent)
  80.             return True
  81.         return False
  82.  
  83.     
  84.     def get_value_handler(self, g):
  85.         if g in (self.opt_input_profile, self.opt_output_profile):
  86.             idx = g.currentIndex().row()
  87.             return g.model().profiles[idx].short_name
  88.         return Widget.get_value_handler(self, g)
  89.  
  90.  
  91.