Catalog dialog: Only show options tab for currently selected output format

This commit is contained in:
Kovid Goyal 2010-01-21 18:54:30 -07:00
parent dea55f5f09
commit 57a59d2798
3 changed files with 24 additions and 13 deletions

View File

@ -16,6 +16,7 @@ class PluginWidget(QWidget, Ui_Form):
TITLE = _('CSV/XML Output')
HELP = _('Options specific to')+' CSV/XML '+_('output')
sync_enabled = False
formats = set(['csv', 'xml'])
def __init__(self, parent=None):
QWidget.__init__(self, parent)

View File

@ -100,8 +100,6 @@ class Catalog(QDialog, Ui_Dialog):
info("No dynamic tab resources found for %s" % name)
self.widgets = sorted(self.widgets, cmp=lambda x,y:cmp(x.TITLE, y.TITLE))
for pw in self.widgets:
self.tabs.addTab(pw, pw.TITLE)
# Generate a sorted list of installed catalog formats/sync_enabled pairs
fmts = sorted([x[0] for x in self.fmts])
@ -125,6 +123,19 @@ class Catalog(QDialog, Ui_Dialog):
if self.sync.isEnabled():
self.sync.setChecked(dynamic.get('catalog_sync_to_device', True))
self.format.currentIndexChanged.connect(self.format_changed)
self.show_plugin_tab(None)
def show_plugin_tab(self, idx):
cf = unicode(self.format.currentText()).lower()
while self.tabs.count() > 1:
self.tabs.remove(1)
for pw in self.widgets:
if cf in pw.formats:
self.tabs.addTab(pw, pw.TITLE)
break
def format_changed(self, idx):
cf = unicode(self.format.currentText())
if cf in self.sync_enabled_formats:
@ -133,6 +144,14 @@ class Catalog(QDialog, Ui_Dialog):
self.sync.setDisabled(True)
self.sync.setChecked(False)
@property
def fmt_options(self):
ans = {}
if self.tabs.count() > 1:
w = self.tabs.widget(1)
ans = w.options()
return ans
def accept(self):
self.catalog_format = unicode(self.format.currentText())
dynamic.set('catalog_preferred_format', self.catalog_format)

View File

@ -248,22 +248,13 @@ def generate_catalog(parent, dbspec, ids):
# Create the output file
out = PersistentTemporaryFile(suffix='_catalog_out.'+d.catalog_format.lower())
# Retrieve plugin options
fmt_options = {}
for x in range(d.tabs.count()):
if str(d.tabs.tabText(x)).find(str(d.catalog_format)) > -1:
for fmt in d.fmts:
if fmt[0] == d.catalog_format:
fmt_options = fmt[2].options()
# print "gui2.tools:generate_catalog(): options for %s: %s" % (fmt[0], fmt_options)
args = [
d.catalog_format,
d.catalog_title,
dbspec,
ids,
out.name,
fmt_options
d.fmt_options
]
out.close()