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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
  6. __docformat__ = 'restructuredtext en'
  7. import re
  8. from PyQt4.Qt import Qt, QVariant, QListWidgetItem
  9. from calibre.gui2.preferences import ConfigWidgetBase, test_widget, CommaSeparatedList
  10. from calibre.gui2.preferences.behavior_ui import Ui_Form
  11. from calibre.gui2 import config, info_dialog, dynamic
  12. from calibre.utils.config import prefs
  13. from calibre.customize.ui import available_output_formats, all_input_formats
  14. from calibre.utils.search_query_parser import saved_searches
  15. from calibre.ebooks import BOOK_EXTENSIONS
  16. from calibre.ebooks.oeb.iterator import is_supported
  17. from calibre.constants import iswindows
  18.  
  19. class ConfigWidget(ConfigWidgetBase, Ui_Form):
  20.     
  21.     def genesis(self, gui):
  22.         self.gui = gui
  23.         db = gui.library_view.model().db
  24.         r = self.register
  25.         r('worker_process_priority', prefs, choices = [
  26.             (_('Low'), 'low'),
  27.             (_('Normal'), 'normal'),
  28.             (_('High'), 'high')])
  29.         r('network_timeout', prefs)
  30.         r('overwrite_author_title_metadata', config)
  31.         r('get_social_metadata', config)
  32.         r('new_version_notification', config)
  33.         r('upload_news_to_device', config)
  34.         r('delete_news_from_library_on_upload', config)
  35.         output_formats = list(sorted(available_output_formats()))
  36.         output_formats.remove('oeb')
  37.         choices = [ (x.upper(), x) for x in output_formats ]
  38.         r('output_format', prefs, choices = choices)
  39.         restrictions = sorted(saved_searches().names(), cmp = (lambda x, y: cmp(x.lower(), y.lower())))
  40.         choices = [] + [ (x, x) for x in restrictions ]
  41.         r('gui_restriction', db.prefs, choices = choices)
  42.         r('new_book_tags', prefs, setting = CommaSeparatedList)
  43.         self.reset_confirmation_button.clicked.connect(self.reset_confirmation_dialogs)
  44.         self.input_up_button.clicked.connect(self.up_input)
  45.         self.input_down_button.clicked.connect(self.down_input)
  46.         for signal in ('Activated', 'Changed', 'DoubleClicked', 'Clicked'):
  47.             signal = getattr(self.opt_internally_viewed_formats, 'item' + signal)
  48.             signal.connect(self.internally_viewed_formats_changed)
  49.         
  50.         self.settings['worker_process_priority'].gui_obj.setVisible(iswindows)
  51.         self.priority_label.setVisible(iswindows)
  52.  
  53.     
  54.     def initialize(self):
  55.         ConfigWidgetBase.initialize(self)
  56.         self.init_input_order()
  57.         self.init_internally_viewed_formats()
  58.  
  59.     
  60.     def restore_defaults(self):
  61.         ConfigWidgetBase.restore_defaults(self)
  62.         self.init_input_order(defaults = True)
  63.         self.init_internally_viewed_formats(defaults = True)
  64.         self.changed_signal.emit()
  65.  
  66.     
  67.     def commit(self):
  68.         input_map = prefs['input_format_order']
  69.         input_cols = [ unicode(self.opt_input_order.item(i).data(Qt.UserRole).toString()) for i in range(self.opt_input_order.count()) ]
  70.         fmts = self.current_internally_viewed_formats
  71.         old = config['internally_viewed_formats']
  72.         if fmts != old:
  73.             config['internally_viewed_formats'] = fmts
  74.         
  75.         return ConfigWidgetBase.commit(self)
  76.  
  77.     
  78.     def internally_viewed_formats_changed(self, *args):
  79.         fmts = self.current_internally_viewed_formats
  80.         old = config['internally_viewed_formats']
  81.         if fmts != old:
  82.             self.changed_signal.emit()
  83.         
  84.  
  85.     
  86.     def init_internally_viewed_formats(self, defaults = False):
  87.         if defaults:
  88.             fmts = config.defaults['internally_viewed_formats']
  89.         else:
  90.             fmts = config['internally_viewed_formats']
  91.         viewer = self.opt_internally_viewed_formats
  92.         viewer.blockSignals(True)
  93.         exts = set([])
  94.         for ext in BOOK_EXTENSIONS:
  95.             ext = ext.lower()
  96.             ext = re.sub('(x{0,1})htm(l{0,1})', 'html', ext)
  97.             if ext == 'lrf' or is_supported('book.' + ext):
  98.                 exts.add(ext)
  99.                 continue
  100.         
  101.         viewer.clear()
  102.         for ext in sorted(exts):
  103.             viewer.addItem(ext.upper())
  104.             item = viewer.item(viewer.count() - 1)
  105.             item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
  106.             None(item.setCheckState if ext.upper() in fmts else Qt.Unchecked)
  107.         
  108.         viewer.blockSignals(False)
  109.  
  110.     
  111.     def current_internally_viewed_formats(self):
  112.         fmts = []
  113.         viewer = self.opt_internally_viewed_formats
  114.         for i in range(viewer.count()):
  115.             if viewer.item(i).checkState() == Qt.Checked:
  116.                 fmts.append(unicode(viewer.item(i).text()))
  117.                 continue
  118.         
  119.         return fmts
  120.  
  121.     current_internally_viewed_formats = property(current_internally_viewed_formats)
  122.     
  123.     def init_input_order(self, defaults = False):
  124.         if defaults:
  125.             input_map = prefs.defaults['input_format_order']
  126.         else:
  127.             input_map = prefs['input_format_order']
  128.         all_formats = set()
  129.         self.opt_input_order.clear()
  130.         for fmt in all_input_formats().union(set([
  131.             'ZIP',
  132.             'RAR'])):
  133.             all_formats.add(fmt.upper())
  134.         
  135.         for format in input_map + list(all_formats.difference(input_map)):
  136.             item = QListWidgetItem(format, self.opt_input_order)
  137.             item.setData(Qt.UserRole, QVariant(format))
  138.             item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
  139.         
  140.  
  141.     
  142.     def up_input(self, *args):
  143.         idx = self.opt_input_order.currentRow()
  144.         if idx > 0:
  145.             self.opt_input_order.insertItem(idx - 1, self.opt_input_order.takeItem(idx))
  146.             self.opt_input_order.setCurrentRow(idx - 1)
  147.             self.changed_signal.emit()
  148.         
  149.  
  150.     
  151.     def down_input(self, *args):
  152.         idx = self.opt_input_order.currentRow()
  153.         if idx < self.opt_input_order.count() - 1:
  154.             self.opt_input_order.insertItem(idx + 1, self.opt_input_order.takeItem(idx))
  155.             self.opt_input_order.setCurrentRow(idx + 1)
  156.             self.changed_signal.emit()
  157.         
  158.  
  159.     
  160.     def reset_confirmation_dialogs(self, *args):
  161.         for key in dynamic.keys():
  162.             if key.endswith('_again') and dynamic[key] is False:
  163.                 dynamic[key] = True
  164.                 continue
  165.         
  166.         info_dialog(self, _('Done'), _('Confirmation dialogs have all been reset'), show = True)
  167.  
  168.  
  169. if __name__ == '__main__':
  170.     from PyQt4.Qt import QApplication
  171.     app = QApplication([])
  172.     test_widget('Interface', 'Behavior')
  173.  
  174.