home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_1215 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  4.5 KB  |  104 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.     COMMIT_NAME = 'page_setup'
  38.     
  39.     def __init__(self, parent, get_option, get_help, db = None, book_id = None):
  40.         self._PageSetupWidget__connections = []
  41.         Widget.__init__(self, parent, [
  42.             'margin_top',
  43.             'margin_left',
  44.             'margin_right',
  45.             'margin_bottom',
  46.             'input_profile',
  47.             'output_profile'])
  48.         self.db = db
  49.         self.book_id = book_id
  50.         self.input_model = ProfileModel(input_profiles())
  51.         self.output_model = ProfileModel(output_profiles())
  52.         self.opt_input_profile.setModel(self.input_model)
  53.         self.opt_output_profile.setModel(self.output_model)
  54.         for g, slot in self._PageSetupWidget__connections:
  55.             g.selectionModel().currentChanged.connect(slot)
  56.         
  57.         del self._PageSetupWidget__connections
  58.         for x in (self.opt_input_profile, self.opt_output_profile):
  59.             x.setMouseTracking(True)
  60.             self.connect(x, SIGNAL('entered(QModelIndex)'), self.show_desc)
  61.         
  62.         self.initialize_options(get_option, get_help, db, book_id)
  63.         it = unicode(self.opt_input_profile.toolTip())
  64.         self.opt_input_profile.setToolTip('<p>' + it.replace('t.', 't.\n<br>'))
  65.         it = unicode(self.opt_output_profile.toolTip())
  66.         self.opt_output_profile.setToolTip('<p>' + it.replace('t.', 'ce.\n<br>'))
  67.  
  68.     
  69.     def show_desc(self, index):
  70.         desc = index.model().data(index, Qt.StatusTipRole).toString()
  71.         self.profile_description.setText(desc)
  72.  
  73.     
  74.     def connect_gui_obj_handler(self, g, slot):
  75.         if g not in (self.opt_input_profile, self.opt_output_profile):
  76.             raise NotImplementedError()
  77.         g not in (self.opt_input_profile, self.opt_output_profile)
  78.         self._PageSetupWidget__connections.append((g, slot))
  79.  
  80.     
  81.     def set_value_handler(self, g, val):
  82.         if g in (self.opt_input_profile, self.opt_output_profile):
  83.             g.clearSelection()
  84.             for idx, p in enumerate(g.model().profiles):
  85.                 if p.short_name == val:
  86.                     break
  87.                     continue
  88.             
  89.             idx = g.model().index(idx)
  90.             sm = g.selectionModel()
  91.             g.setCurrentIndex(idx)
  92.             sm.select(idx, sm.SelectCurrent)
  93.             return True
  94.         return False
  95.  
  96.     
  97.     def get_value_handler(self, g):
  98.         if g in (self.opt_input_profile, self.opt_output_profile):
  99.             idx = g.currentIndex().row()
  100.             return g.model().profiles[idx].short_name
  101.         return Widget.get_value_handler(self, g)
  102.  
  103.  
  104.