From 58f49ebeb5fe3e798f861c17d9a95dc1441e033d Mon Sep 17 00:00:00 2001 From: John Schember Date: Thu, 7 May 2009 18:06:29 -0400 Subject: [PATCH] GUI convert: PDB output widget to select format. --- src/calibre/gui2/convert/gui_conversion.py | 2 - src/calibre/gui2/convert/pdb_output.py | 28 ++++++++++++++ src/calibre/gui2/convert/pdb_output.ui | 44 ++++++++++++++++++++++ src/calibre/gui2/widgets.py | 25 ++++++++++++ 4 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 src/calibre/gui2/convert/pdb_output.py create mode 100644 src/calibre/gui2/convert/pdb_output.ui diff --git a/src/calibre/gui2/convert/gui_conversion.py b/src/calibre/gui2/convert/gui_conversion.py index 1d41b4ec29..8f25acb7be 100644 --- a/src/calibre/gui2/convert/gui_conversion.py +++ b/src/calibre/gui2/convert/gui_conversion.py @@ -4,8 +4,6 @@ __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' -import logging - from calibre.ebooks.conversion.plumber import Plumber from calibre.utils.logging import Log diff --git a/src/calibre/gui2/convert/pdb_output.py b/src/calibre/gui2/convert/pdb_output.py new file mode 100644 index 0000000000..db52db8f46 --- /dev/null +++ b/src/calibre/gui2/convert/pdb_output.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- + +__license__ = 'GPL 3' +__copyright__ = '2009, John Schember ' +__docformat__ = 'restructuredtext en' + +from calibre.gui2.convert.pdb_output_ui import Ui_Form +from calibre.gui2.convert import Widget +from calibre.ebooks.pdb import FORMAT_WRITERS +from calibre.gui2.widgets import BasicComboModel + +format_model = None + +class PluginWidget(Widget, Ui_Form): + + TITLE = _('PDB Output') + + def __init__(self, parent, get_option, get_help, db=None, book_id=None): + Widget.__init__(self, parent, 'pdb_output', ['format']) + self.db, self.book_id = db, book_id + self.initialize_options(get_option, get_help, db, book_id) + + global format_model + if format_model is None: + format_model = BasicComboModel(FORMAT_WRITERS.keys()) + self.format_model = format_model + self.opt_format.setModel(self.format_model) + diff --git a/src/calibre/gui2/convert/pdb_output.ui b/src/calibre/gui2/convert/pdb_output.ui new file mode 100644 index 0000000000..5f21031233 --- /dev/null +++ b/src/calibre/gui2/convert/pdb_output.ui @@ -0,0 +1,44 @@ + + + Form + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Format: + + + + + + + + + + Qt::Vertical + + + + 148 + 246 + + + + + + + + + diff --git a/src/calibre/gui2/widgets.py b/src/calibre/gui2/widgets.py index 7f3487f035..c8d8ed79bd 100644 --- a/src/calibre/gui2/widgets.py +++ b/src/calibre/gui2/widgets.py @@ -305,6 +305,31 @@ class FontFamilyModel(QAbstractListModel): def index_of(self, family): return self.families.index(family.strip()) +class BasicComboModel(QAbstractListModel): + + def __init__(self, items, *args): + QAbstractListModel.__init__(self, *args) + self.items = [i for i in items] + self.items.sort() + + def rowCount(self, *args): + return len(self.items) + + def data(self, index, role): + try: + item = self.items[index.row()] + except: + traceback.print_exc() + return NONE + if role == Qt.DisplayRole: + return QVariant(item) + if role == Qt.FontRole: + return QVariant(QFont(item)) + return NONE + + def index_of(self, item): + return self.items.index(item.strip()) + class BasicListItem(QListWidgetItem):