home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1262 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  7.7 KB  |  164 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
  6. from PyQt4.QtCore import SIGNAL, QObject
  7. from PyQt4.QtGui import QDialog, QGridLayout
  8. from calibre.gui2.dialogs.metadata_bulk_ui import Ui_MetadataBulkDialog
  9. from calibre.gui2.dialogs.tag_editor import TagEditor
  10. from calibre.ebooks.metadata import string_to_authors, authors_to_string
  11. from calibre.gui2.custom_column_widgets import populate_metadata_page
  12.  
  13. class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
  14.     
  15.     def __init__(self, window, rows, db):
  16.         QDialog.__init__(self, window)
  17.         Ui_MetadataBulkDialog.__init__(self)
  18.         self.setupUi(self)
  19.         self.db = db
  20.         self.ids = [ db.id(r) for r in rows ]
  21.         self.box_title.setText('<p>' + _('Editing meta information for <b>%d books</b>') % len(rows))
  22.         self.write_series = False
  23.         self.changed = False
  24.         QObject.connect(self.button_box, SIGNAL('accepted()'), self.sync)
  25.         self.tags.update_tags_cache(self.db.all_tags())
  26.         self.remove_tags.update_tags_cache(self.db.all_tags())
  27.         self.initialize_combos()
  28.         for f in self.db.all_formats():
  29.             self.remove_format.addItem(f)
  30.         
  31.         self.remove_format.setCurrentIndex(-1)
  32.         QObject.connect(self.series, SIGNAL('currentIndexChanged(int)'), self.series_changed)
  33.         QObject.connect(self.series, SIGNAL('editTextChanged(QString)'), self.series_changed)
  34.         QObject.connect(self.tag_editor_button, SIGNAL('clicked()'), self.tag_editor)
  35.         self.exec_()
  36.  
  37.     
  38.     def create_custom_column_editors(self):
  39.         w = self.central_widget.widget(1)
  40.         layout = QGridLayout()
  41.         (self.custom_column_widgets, self._MetadataBulkDialog__cc_spacers) = populate_metadata_page(layout, self.db, self.ids, parent = w, two_column = False, bulk = True)
  42.         w.setLayout(layout)
  43.         self._MetadataBulkDialog__custom_col_layouts = [
  44.             layout]
  45.         ans = self.custom_column_widgets
  46.         for i in range(len(ans) - 1):
  47.             w.setTabOrder(ans[i].widgets[-1], ans[i + 1].widgets[1])
  48.             for c in range(2, len(ans[i].widgets), 2):
  49.                 w.setTabOrder(ans[i].widgets[c - 1], ans[i].widgets[c + 1])
  50.             
  51.         
  52.  
  53.     
  54.     def initialize_combos(self):
  55.         self.initalize_authors()
  56.         self.initialize_series()
  57.         self.initialize_publisher()
  58.  
  59.     
  60.     def initalize_authors(self):
  61.         all_authors = self.db.all_authors()
  62.         all_authors.sort(cmp = (lambda x, y: cmp(x[1], y[1])))
  63.         for i in all_authors:
  64.             (id, name) = i
  65.             name = []([ name.strip().replace('|', ',') for n in name.split(',') ])
  66.             self.authors.addItem(name)
  67.         
  68.         self.authors.setEditText('')
  69.  
  70.     
  71.     def initialize_series(self):
  72.         all_series = self.db.all_series()
  73.         all_series.sort(cmp = (lambda x, y: cmp(x[1], y[1])))
  74.         for i in all_series:
  75.             (id, name) = i
  76.             self.series.addItem(name)
  77.         
  78.         self.series.setEditText('')
  79.  
  80.     
  81.     def initialize_publisher(self):
  82.         all_publishers = self.db.all_publishers()
  83.         all_publishers.sort(cmp = (lambda x, y: cmp(x[1], y[1])))
  84.         for i in all_publishers:
  85.             (id, name) = i
  86.             self.publisher.addItem(name)
  87.         
  88.         self.publisher.setEditText('')
  89.  
  90.     
  91.     def tag_editor(self):
  92.         d = TagEditor(self, self.db, None)
  93.         d.exec_()
  94.         if d.result() == QDialog.Accepted:
  95.             tag_string = ', '.join(d.tags)
  96.             self.tags.setText(tag_string)
  97.             self.tags.update_tags_cache(self.db.all_tags())
  98.             self.remove_tags.update_tags_cache(self.db.all_tags())
  99.         
  100.  
  101.     
  102.     def sync(self):
  103.         for id in self.ids:
  104.             au = unicode(self.authors.text())
  105.             if au:
  106.                 au = string_to_authors(au)
  107.                 self.db.set_authors(id, au, notify = False)
  108.             
  109.             if self.auto_author_sort.isChecked():
  110.                 x = self.db.author_sort_from_book(id, index_is_id = True)
  111.                 if x:
  112.                     self.db.set_author_sort(id, x, notify = False)
  113.                 
  114.             
  115.             aus = unicode(self.author_sort.text())
  116.             if aus and self.author_sort.isEnabled():
  117.                 self.db.set_author_sort(id, aus, notify = False)
  118.             
  119.             if self.rating.value() != -1:
  120.                 self.db.set_rating(id, 2 * self.rating.value(), notify = False)
  121.             
  122.             pub = unicode(self.publisher.text())
  123.             if pub:
  124.                 self.db.set_publisher(id, pub, notify = False)
  125.             
  126.             remove_tags = unicode(self.remove_tags.text()).strip()
  127.             tags = unicode(self.tags.text()).strip()
  128.             if tags:
  129.                 tags = map((lambda x: x.strip()), tags.split(','))
  130.                 self.db.set_tags(id, tags, append = True, notify = False)
  131.             
  132.             if self.write_series:
  133.                 series = unicode(self.series.currentText()).strip()
  134.                 next = self.db.get_next_series_num_for(series)
  135.                 self.db.set_series(id, series, notify = False)
  136.                 num = None if self.autonumber_series.isChecked() and series else 1
  137.                 self.db.set_series_index(id, num, notify = False)
  138.             
  139.             if self.remove_format.currentIndex() > -1:
  140.                 self.db.remove_format(id, unicode(self.remove_format.currentText()), index_is_id = True, notify = False)
  141.             
  142.             if self.swap_title_and_author.isChecked():
  143.                 title = self.db.title(id, index_is_id = True)
  144.                 aum = self.db.authors(id, index_is_id = True)
  145.                 if title:
  146.                     new_authors = string_to_authors(title)
  147.                     self.db.set_authors(id, new_authors, notify = False)
  148.                 
  149.             
  150.             if self.remove_conversion_settings.isChecked():
  151.                 self.db.delete_conversion_options(id, 'PIPE')
  152.             
  153.             self.changed = True
  154.         
  155.         for w in getattr(self, 'custom_column_widgets', []):
  156.             w.commit(self.ids)
  157.         
  158.  
  159.     
  160.     def series_changed(self):
  161.         self.write_series = True
  162.  
  163.  
  164.