home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- from __future__ import with_statement
- __license__ = 'GPL v3'
- __copyright__ = '2009, John Schember <john@nachtimwald.com>'
- import cPickle
- import os
- from PyQt4.Qt import Qt, QDialog, QAbstractTableModel, QVariant, SIGNAL, QModelIndex, QInputDialog, QLineEdit, QFileDialog
- from calibre.gui2.viewer.bookmarkmanager_ui import Ui_BookmarkManager
- from calibre.gui2 import NONE
-
- class BookmarkManager(QDialog, Ui_BookmarkManager):
-
- def __init__(self, parent, bookmarks):
- QDialog.__init__(self, parent)
- self.setupUi(self)
- self.bookmarks = bookmarks[:]
- self.set_bookmarks()
- self.connect(self.button_revert, SIGNAL('clicked()'), self.set_bookmarks)
- self.connect(self.button_delete, SIGNAL('clicked()'), self.delete_bookmark)
- self.connect(self.button_edit, SIGNAL('clicked()'), self.edit_bookmark)
- self.connect(self.button_export, SIGNAL('clicked()'), self.export_bookmarks)
- self.connect(self.button_import, SIGNAL('clicked()'), self.import_bookmarks)
-
-
- def set_bookmarks(self, bookmarks = None):
- if bookmarks == None:
- bookmarks = self.bookmarks[:]
-
- self._model = BookmarkTableModel(self, bookmarks)
- self.bookmarks_table.setModel(self._model)
-
-
- def delete_bookmark(self):
- indexes = self.bookmarks_table.selectionModel().selectedIndexes()
- if indexes != []:
- self._model.remove_row(indexes[0].row())
-
-
-
- def edit_bookmark(self):
- indexes = self.bookmarks_table.selectionModel().selectedIndexes()
- if indexes != []:
- (title, ok) = QInputDialog.getText(self, _('Edit bookmark'), _('New title for bookmark:'), QLineEdit.Normal, self._model.data(indexes[0], Qt.DisplayRole).toString())
- title = QVariant(unicode(title).strip())
- if ok and title:
- self._model.setData(indexes[0], title, Qt.EditRole)
-
-
-
-
- def get_bookmarks(self):
- return self._model.bookmarks
-
-
- def export_bookmarks(self):
- filename = QFileDialog.getSaveFileName(self, _('Export Bookmarks'), '%s%suntitled.pickle' % (os.getcwdu(), os.sep), _('Saved Bookmarks (*.pickle)'))
- if filename == '':
- return None
-
- try:
- fileobj = _[1]
- cPickle.dump(self._model.bookmarks, fileobj)
- finally:
- pass
-
-
-
- def import_bookmarks(self):
- filename = QFileDialog.getOpenFileName(self, _('Import Bookmarks'), '%s' % os.getcwdu(), _('Pickled Bookmarks (*.pickle)'))
- if filename == '':
- return None
- imported = None
-
- try:
- fileobj = _[1]
- imported = cPickle.load(fileobj)
- finally:
- pass
-
-
-
-
- class BookmarkTableModel(QAbstractTableModel):
- headers = [
- _('Name')]
-
- def __init__(self, parent, bookmarks):
- QAbstractTableModel.__init__(self, parent)
- self.bookmarks = bookmarks[:]
-
-
- def rowCount(self, parent):
- if parent and parent.isValid():
- return 0
- return len(self.bookmarks)
-
-
- def columnCount(self, parent):
- if parent and parent.isValid():
- return 0
- return len(self.headers)
-
-
- def data(self, index, role):
- if role in (Qt.DisplayRole, Qt.EditRole):
- ans = self.bookmarks[index.row()][0]
- if ans is None:
- return NONE
- return QVariant(ans)
- return NONE
-
-
- def setData(self, index, value, role):
- if role == Qt.EditRole:
- self.bookmarks[index.row()] = (unicode(value.toString()).strip(), self.bookmarks[index.row()][1])
- self.emit(SIGNAL('dataChanged(QModelIndex, QModelIndex)'), index, index)
- return True
- return False
-
-
- def flags(self, index):
- flags = QAbstractTableModel.flags(self, index)
- flags |= Qt.ItemIsEditable
- return flags
-
-
- def headerData(self, section, orientation, role):
- if role != Qt.DisplayRole:
- return NONE
- if orientation == Qt.Horizontal:
- return QVariant(self.headers[section])
- return QVariant(section + 1)
-
-
- def remove_row(self, row):
- self.beginRemoveRows(QModelIndex(), row, row)
- del self.bookmarks[row]
- self.endRemoveRows()
-
-
-