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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
  5. __docformat__ = 'restructuredtext en'
  6. __license__ = 'GPL v3'
  7. from PyQt4.Qt import Qt, QDialog, QTableWidgetItem, QAbstractItemView
  8. from calibre.ebooks.metadata import author_to_author_sort
  9. from calibre.gui2.dialogs.edit_authors_dialog_ui import Ui_EditAuthorsDialog
  10.  
  11. class tableItem(QTableWidgetItem):
  12.     
  13.     def __ge__(self, other):
  14.         return unicode(self.text()).lower() >= unicode(other.text()).lower()
  15.  
  16.     
  17.     def __lt__(self, other):
  18.         return unicode(self.text()).lower() < unicode(other.text()).lower()
  19.  
  20.  
  21.  
  22. class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog):
  23.     
  24.     def __init__(self, parent, db, id_to_select):
  25.         QDialog.__init__(self, parent)
  26.         Ui_EditAuthorsDialog.__init__(self)
  27.         self.setupUi(self)
  28.         icon = self.windowIcon()
  29.         self.setWindowFlags(self.windowFlags() & ~(Qt.WindowContextHelpButtonHint))
  30.         self.setWindowIcon(icon)
  31.         self.buttonBox.accepted.connect(self.accepted)
  32.         self.table.setSelectionMode(QAbstractItemView.SingleSelection)
  33.         self.table.setColumnCount(2)
  34.         self.table.setHorizontalHeaderLabels([
  35.             _('Author'),
  36.             _('Author sort')])
  37.         self.authors = { }
  38.         auts = db.get_authors_with_ids()
  39.         self.table.setRowCount(len(auts))
  40.         select_item = None
  41.         for id, author, sort in enumerate(auts):
  42.             author = author.replace('|', ',')
  43.             self.authors[id] = (author, sort)
  44.             aut = tableItem(author)
  45.             aut.setData(Qt.UserRole, id)
  46.             sort = tableItem(sort)
  47.             self.table.setItem(row, 0, aut)
  48.             self.table.setItem(row, 1, sort)
  49.             if id == id_to_select:
  50.                 select_item = sort
  51.                 continue
  52.         
  53.         self.table.resizeColumnsToContents()
  54.         self.table.cellChanged.connect(self.cell_changed)
  55.         self.table.setSortingEnabled(True)
  56.         self.table.sortByColumn(1, Qt.AscendingOrder)
  57.         if select_item is not None:
  58.             self.table.setCurrentItem(select_item)
  59.             self.table.editItem(select_item)
  60.         else:
  61.             self.table.setCurrentCell(0, 0)
  62.  
  63.     
  64.     def accepted(self):
  65.         self.result = []
  66.         for row in range(0, self.table.rowCount()):
  67.             id = self.table.item(row, 0).data(Qt.UserRole).toInt()[0]
  68.             aut = unicode(self.table.item(row, 0).text()).strip()
  69.             sort = unicode(self.table.item(row, 1).text()).strip()
  70.             (orig_aut, orig_sort) = self.authors[id]
  71.             if orig_aut != aut or orig_sort != sort:
  72.                 self.result.append((id, orig_aut, aut, sort))
  73.                 continue
  74.         
  75.  
  76.     
  77.     def cell_changed(self, row, col):
  78.         if col == 0:
  79.             item = self.table.item(row, 0)
  80.             aut = unicode(item.text()).strip()
  81.             c = self.table.item(row, 1)
  82.             c.setText(author_to_author_sort(aut))
  83.             item = c
  84.         else:
  85.             item = self.table.item(row, 1)
  86.         self.table.setCurrentItem(item)
  87.         self.table.setSortingEnabled(False)
  88.         self.table.setSortingEnabled(True)
  89.         self.table.scrollToItem(item)
  90.  
  91.  
  92.