mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make the selection of db fields to add to the CSV/xML catalog in the GUI more intuitive
This commit is contained in:
parent
223e115f42
commit
dea55f5f09
@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
from calibre.gui2 import gprefs
|
from calibre.gui2 import gprefs
|
||||||
from calibre.gui2.catalog.catalog_csv_xml_ui import Ui_Form
|
from calibre.gui2.catalog.catalog_csv_xml_ui import Ui_Form
|
||||||
from PyQt4.Qt import QWidget
|
from PyQt4.Qt import QWidget, QListWidgetItem
|
||||||
|
|
||||||
class PluginWidget(QWidget, Ui_Form):
|
class PluginWidget(QWidget, Ui_Form):
|
||||||
|
|
||||||
@ -20,23 +20,32 @@ class PluginWidget(QWidget, Ui_Form):
|
|||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
QWidget.__init__(self, parent)
|
QWidget.__init__(self, parent)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
from calibre.library.catalog import FIELDS
|
||||||
|
self.all_fields = []
|
||||||
|
for x in FIELDS:
|
||||||
|
if x != 'all':
|
||||||
|
self.all_fields.append(x)
|
||||||
|
QListWidgetItem(x, self.db_fields)
|
||||||
|
|
||||||
def initialize(self, name):
|
def initialize(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
fields = gprefs.get(name+'_db_fields', self.all_fields)
|
||||||
# Restore the activated fields from last use
|
# Restore the activated fields from last use
|
||||||
for x in range(self.db_fields.count()):
|
for x in range(self.db_fields.count()):
|
||||||
pref = '%s_db_fields_%s' % (self.name, self.db_fields.item(x).text())
|
item = self.db_fields.item(x)
|
||||||
activated = gprefs[pref] if pref in gprefs else False
|
item.setSelected(unicode(item.text()) in fields)
|
||||||
self.db_fields.item(x).setSelected(activated)
|
|
||||||
|
|
||||||
def options(self):
|
def options(self):
|
||||||
# Save the currently activated fields
|
# Save the currently activated fields
|
||||||
|
fields = []
|
||||||
for x in range(self.db_fields.count()):
|
for x in range(self.db_fields.count()):
|
||||||
pref = '%s_db_fields_%s' % (self.name, self.db_fields.item(x).text())
|
item = self.db_fields.item(x)
|
||||||
gprefs[pref] = self.db_fields.item(x).isSelected()
|
if item.isSelected():
|
||||||
|
fields.append(unicode(item.text()))
|
||||||
|
gprefs.set(self.name+'_db_fields', fields)
|
||||||
|
|
||||||
# Return a dictionary with current options for this widget
|
# Return a dictionary with current options for this widget
|
||||||
if len(self.db_fields.selectedItems()):
|
if len(self.db_fields.selectedItems()):
|
||||||
return {'fields':[str(item.text()) for item in self.db_fields.selectedItems()]}
|
return {'fields':[unicode(item.text()) for item in self.db_fields.selectedItems()]}
|
||||||
else:
|
else:
|
||||||
return {'fields':['all']}
|
return {'fields':['all']}
|
||||||
|
@ -34,91 +34,6 @@
|
|||||||
<property name="selectionMode">
|
<property name="selectionMode">
|
||||||
<enum>QAbstractItemView::MultiSelection</enum>
|
<enum>QAbstractItemView::MultiSelection</enum>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>author_sort</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>authors</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>comments</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>cover</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>formats</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>id</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>isbn</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>pubdate</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>publisher</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>rating</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>series_index</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>series</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>size</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>tags</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>timestamp</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>title</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>uuid</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QLabel" name="label_6">
|
<widget class="QLabel" name="label_6">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
|
@ -17,6 +17,7 @@ from calibre.customize.ui import catalog_plugins
|
|||||||
|
|
||||||
class Catalog(QDialog, Ui_Dialog):
|
class Catalog(QDialog, Ui_Dialog):
|
||||||
''' Catalog Dialog builder'''
|
''' Catalog Dialog builder'''
|
||||||
|
widgets = []
|
||||||
|
|
||||||
def __init__(self, parent, dbspec, ids):
|
def __init__(self, parent, dbspec, ids):
|
||||||
import re, cStringIO
|
import re, cStringIO
|
||||||
|
@ -2,6 +2,11 @@ import os
|
|||||||
|
|
||||||
from calibre.customize import CatalogPlugin
|
from calibre.customize import CatalogPlugin
|
||||||
|
|
||||||
|
FIELDS = ['all', 'author_sort', 'authors', 'comments',
|
||||||
|
'cover', 'formats', 'id', 'isbn', 'pubdate', 'publisher', 'rating',
|
||||||
|
'series_index', 'series', 'size', 'tags', 'timestamp', 'title',
|
||||||
|
'uuid']
|
||||||
|
|
||||||
class CSV_XML(CatalogPlugin):
|
class CSV_XML(CatalogPlugin):
|
||||||
'CSV/XML catalog generator'
|
'CSV/XML catalog generator'
|
||||||
|
|
||||||
@ -22,11 +27,9 @@ class CSV_XML(CatalogPlugin):
|
|||||||
dest = 'fields',
|
dest = 'fields',
|
||||||
help = _('The fields to output when cataloging books in the '
|
help = _('The fields to output when cataloging books in the '
|
||||||
'database. Should be a comma-separated list of fields.\n'
|
'database. Should be a comma-separated list of fields.\n'
|
||||||
'Available fields: all, author_sort, authors, comments, '
|
'Available fields: %s.\n'
|
||||||
'cover, formats, id, isbn, pubdate, publisher, rating, '
|
"Default: '%%default'\n"
|
||||||
'series_index, series, size, tags, timestamp, title, uuid.\n'
|
"Applies to: CSV, XML output formats")%', '.join(FIELDS)),
|
||||||
"Default: '%default'\n"
|
|
||||||
"Applies to: CSV, XML output formats")),
|
|
||||||
|
|
||||||
Option('--sort-by',
|
Option('--sort-by',
|
||||||
default = 'id',
|
default = 'id',
|
||||||
|
@ -673,7 +673,7 @@ def command_catalog(args, dbpath):
|
|||||||
if opts.verbose:
|
if opts.verbose:
|
||||||
log("library.cli:command_catalog dispatching to plugin %s" % plugin.name)
|
log("library.cli:command_catalog dispatching to plugin %s" % plugin.name)
|
||||||
if opts.ids:
|
if opts.ids:
|
||||||
opts.ids = [int(id) for id in opts.ids.split(',')]
|
opts.ids = [int(id) for id in opts.ids.split(',')]
|
||||||
|
|
||||||
with plugin:
|
with plugin:
|
||||||
plugin.run(args[1], opts, get_db(dbpath, opts))
|
plugin.run(args[1], opts, get_db(dbpath, opts))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user