mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Simplify more GUI widgets.
This commit is contained in:
parent
68587e8679
commit
d271747cff
@ -6,8 +6,6 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
from calibre.gui2.convert.pdb_output_ui import Ui_Form
|
from calibre.gui2.convert.pdb_output_ui import Ui_Form
|
||||||
from calibre.gui2.convert import Widget
|
from calibre.gui2.convert import Widget
|
||||||
from calibre.ebooks.pdb import FORMAT_WRITERS
|
|
||||||
from calibre.gui2.widgets import BasicComboModel
|
|
||||||
|
|
||||||
format_model = None
|
format_model = None
|
||||||
|
|
||||||
@ -21,17 +19,8 @@ class PluginWidget(Widget, Ui_Form):
|
|||||||
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
||||||
Widget.__init__(self, parent, ['format', 'inline_toc', 'pdb_output_encoding'])
|
Widget.__init__(self, parent, ['format', 'inline_toc', 'pdb_output_encoding'])
|
||||||
self.db, self.book_id = db, book_id
|
self.db, self.book_id = db, book_id
|
||||||
|
|
||||||
|
for x in get_option('format').option.choices:
|
||||||
|
self.opt_format.addItem(x)
|
||||||
|
|
||||||
self.initialize_options(get_option, get_help, db, book_id)
|
self.initialize_options(get_option, get_help, db, book_id)
|
||||||
|
|
||||||
default = self.opt_format.currentText()
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
default_index = self.opt_format.findText(default)
|
|
||||||
format_index = self.opt_format.findText('doc')
|
|
||||||
self.opt_format.setCurrentIndex(default_index if default_index != -1 else format_index if format_index != -1 else 0)
|
|
||||||
|
|
||||||
|
@ -6,8 +6,6 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
from calibre.gui2.convert.pdf_output_ui import Ui_Form
|
from calibre.gui2.convert.pdf_output_ui import Ui_Form
|
||||||
from calibre.gui2.convert import Widget
|
from calibre.gui2.convert import Widget
|
||||||
from calibre.ebooks.pdf.pageoptions import PAPER_SIZES, ORIENTATIONS
|
|
||||||
from calibre.gui2.widgets import BasicComboModel
|
|
||||||
|
|
||||||
paper_size_model = None
|
paper_size_model = None
|
||||||
orientation_model = None
|
orientation_model = None
|
||||||
@ -23,28 +21,11 @@ class PluginWidget(Widget, Ui_Form):
|
|||||||
Widget.__init__(self, parent, ['paper_size',
|
Widget.__init__(self, parent, ['paper_size',
|
||||||
'orientation', 'preserve_cover_aspect_ratio'])
|
'orientation', 'preserve_cover_aspect_ratio'])
|
||||||
self.db, self.book_id = db, book_id
|
self.db, self.book_id = db, book_id
|
||||||
|
|
||||||
|
for x in get_option('paper_size').option.choices:
|
||||||
|
self.opt_paper_size.addItem(x)
|
||||||
|
for x in get_option('orientation').option.choices:
|
||||||
|
self.opt_orientation.addItem(x)
|
||||||
|
|
||||||
self.initialize_options(get_option, get_help, db, book_id)
|
self.initialize_options(get_option, get_help, db, book_id)
|
||||||
|
|
||||||
default_paper_size = self.opt_paper_size.currentText()
|
|
||||||
default_orientation = self.opt_orientation.currentText()
|
|
||||||
|
|
||||||
global paper_size_model
|
|
||||||
if paper_size_model is None:
|
|
||||||
paper_size_model = BasicComboModel(PAPER_SIZES.keys())
|
|
||||||
self.paper_size_model = paper_size_model
|
|
||||||
self.opt_paper_size.setModel(self.paper_size_model)
|
|
||||||
|
|
||||||
default_paper_size_index = self.opt_paper_size.findText(default_paper_size)
|
|
||||||
letter_index = self.opt_paper_size.findText('letter')
|
|
||||||
self.opt_paper_size.setCurrentIndex(default_paper_size_index if default_paper_size_index != -1 else letter_index if letter_index != -1 else 0)
|
|
||||||
|
|
||||||
global orientation_model
|
|
||||||
if orientation_model is None:
|
|
||||||
orientation_model = BasicComboModel(ORIENTATIONS.keys())
|
|
||||||
self.orientation_model = orientation_model
|
|
||||||
self.opt_orientation.setModel(self.orientation_model)
|
|
||||||
|
|
||||||
default_orientation_index = self.opt_orientation.findText(default_orientation)
|
|
||||||
orientation_index = self.opt_orientation.findText('portrait')
|
|
||||||
self.opt_orientation.setCurrentIndex(default_orientation_index if default_orientation_index != -1 else orientation_index if orientation_index != -1 else 0)
|
|
||||||
|
|
@ -6,8 +6,6 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
from calibre.gui2.convert.txt_output_ui import Ui_Form
|
from calibre.gui2.convert.txt_output_ui import Ui_Form
|
||||||
from calibre.gui2.convert import Widget
|
from calibre.gui2.convert import Widget
|
||||||
from calibre.ebooks.txt.newlines import TxtNewlines
|
|
||||||
from calibre.gui2.widgets import BasicComboModel
|
|
||||||
|
|
||||||
newline_model = None
|
newline_model = None
|
||||||
|
|
||||||
@ -24,16 +22,8 @@ class PluginWidget(Widget, Ui_Form):
|
|||||||
'inline_toc', 'markdown_format', 'keep_links', 'keep_image_references',
|
'inline_toc', 'markdown_format', 'keep_links', 'keep_image_references',
|
||||||
'txt_output_encoding'])
|
'txt_output_encoding'])
|
||||||
self.db, self.book_id = db, book_id
|
self.db, self.book_id = db, book_id
|
||||||
|
|
||||||
|
for x in get_option('newline').option.choices:
|
||||||
|
self.opt_newline.addItem(x)
|
||||||
|
|
||||||
self.initialize_options(get_option, get_help, db, book_id)
|
self.initialize_options(get_option, get_help, db, book_id)
|
||||||
|
|
||||||
default = self.opt_newline.currentText()
|
|
||||||
|
|
||||||
global newline_model
|
|
||||||
if newline_model is None:
|
|
||||||
newline_model = BasicComboModel(TxtNewlines.NEWLINE_TYPES.keys())
|
|
||||||
self.newline_model = newline_model
|
|
||||||
self.opt_newline.setModel(self.newline_model)
|
|
||||||
|
|
||||||
default_index = self.opt_newline.findText(default)
|
|
||||||
system_index = self.opt_newline.findText('system')
|
|
||||||
self.opt_newline.setCurrentIndex(default_index if default_index != -1 else system_index if system_index != -1 else 0)
|
|
||||||
|
@ -311,32 +311,6 @@ class FontFamilyModel(QAbstractListModel):
|
|||||||
def index_of(self, family):
|
def index_of(self, family):
|
||||||
return self.families.index(family.strip())
|
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):
|
class BasicListItem(QListWidgetItem):
|
||||||
|
|
||||||
def __init__(self, text, user_data=None):
|
def __init__(self, text, user_data=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user