class DownloadStatus(QScrollArea): def __init__(self, parent=None): QScrollArea.__init__(self, parent) self.setWidgetResizable(True) self.w = QWidget(self) self.l = QGridLayout(self.w) self.setWidget(self.w) def __call__(self, resources): self.url_map = {} self.labels = [] for url in resources: p = self.url_map[url] = QProgressBar(self.w) p.setRange(0, 0) self.l.addWidget(p, self.l.rowCount(), 0) la = QLabel('\xa0' + url) self.labels.append(la) self.l.addWidget(la, self.l.rowCount() - 1, 1) self.l.addWidget(QLabel('')) self.l.setRowStretch(self.l.rowCount() - 1, 10) def progress(self, url, done, total): p = self.url_map.get(url) if p is not None: if total > 0: p.setRange(0, total) p.setValue(done) else: p.setRange(0, 0)
def setup_store_checks(self): first_run = self.config.get('first_run', True) # Add check boxes for each store so the user # can disable searching specific stores on a # per search basis. existing = {} for n in self.store_checks: existing[n] = self.store_checks[n].isChecked() self.store_checks = {} stores_check_widget = QWidget() store_list_layout = QGridLayout() stores_check_widget.setLayout(store_list_layout) icon = QIcon(I('donate.png')) for i, x in enumerate( sorted(self.gui.istores.keys(), key=lambda x: x.lower())): cbox = QCheckBox(x) cbox.setChecked(existing.get(x, first_run)) store_list_layout.addWidget(cbox, i, 0, 1, 1) if self.gui.istores[x].base_plugin.affiliate: iw = QLabel(self) iw.setToolTip('<p>' + _( 'Buying from this store supports the calibre developer: %s</p>' ) % self.gui.istores[x].base_plugin.author + '</p>') iw.setPixmap(icon.pixmap(16, 16)) store_list_layout.addWidget(iw, i, 1, 1, 1) self.store_checks[x] = cbox store_list_layout.setRowStretch(store_list_layout.rowCount(), 10) self.store_list.setWidget(stores_check_widget) self.config['first_run'] = False
class ConfigWidget(QWidget): def __init__(self, plugin): QWidget.__init__(self) self.plugin = plugin self.overl = l = QVBoxLayout(self) self.gb = QGroupBox(_('Metadata fields to download'), self) if plugin.config_help_message: self.pchm = QLabel(plugin.config_help_message) self.pchm.setWordWrap(True) self.pchm.setOpenExternalLinks(True) l.addWidget(self.pchm, 10) l.addWidget(self.gb) self.gb.l = g = QVBoxLayout(self.gb) g.setContentsMargins(0, 0, 0, 0) self.fields_view = v = FieldsList(self) g.addWidget(v) v.setFlow(QListView.Flow.LeftToRight) v.setWrapping(True) v.setResizeMode(QListView.ResizeMode.Adjust) self.fields_model = FieldsModel(self.plugin) self.fields_model.initialize() v.setModel(self.fields_model) self.memory = [] self.widgets = [] self.l = QGridLayout() self.l.setContentsMargins(0, 0, 0, 0) l.addLayout(self.l, 100) for opt in plugin.options: self.create_widgets(opt) def create_widgets(self, opt): val = self.plugin.prefs[opt.name] if opt.type == 'number': c = QSpinBox if isinstance(opt.default, numbers.Integral) else QDoubleSpinBox widget = c(self) widget.setValue(val) elif opt.type == 'string': widget = QLineEdit(self) widget.setText(val if val else '') elif opt.type == 'bool': widget = QCheckBox(opt.label, self) widget.setChecked(bool(val)) elif opt.type == 'choices': widget = QComboBox(self) items = list(iteritems(opt.choices)) items.sort(key=lambda k_v: sort_key(k_v[1])) for key, label in items: widget.addItem(label, (key)) idx = widget.findData(val) widget.setCurrentIndex(idx) widget.opt = opt widget.setToolTip(textwrap.fill(opt.desc)) self.widgets.append(widget) r = self.l.rowCount() if opt.type == 'bool': self.l.addWidget(widget, r, 0, 1, self.l.columnCount()) else: l = QLabel(opt.label) l.setToolTip(widget.toolTip()) self.memory.append(l) l.setBuddy(widget) self.l.addWidget(l, r, 0, 1, 1) self.l.addWidget(widget, r, 1, 1, 1) def commit(self): self.fields_model.commit() for w in self.widgets: if isinstance(w, (QSpinBox, QDoubleSpinBox)): val = w.value() elif isinstance(w, QLineEdit): val = str(w.text()) elif isinstance(w, QCheckBox): val = w.isChecked() elif isinstance(w, QComboBox): idx = w.currentIndex() val = str(w.itemData(idx) or '') self.plugin.prefs[w.opt.name] = val