def setup_row(self, field_metadata, row, col, oldkey=None): flags = Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsSelectable item = QTableWidgetItem(col) item.setFlags(flags) self.opt_columns.setItem(row, 1, item) if col.startswith('#'): fm = self.custcols[oldkey if oldkey is not None else col] else: fm = field_metadata[col] if col == 'title': coltype = _('Text') elif col == 'ondevice': coltype = _('Yes/No with text') else: dt = fm['datatype'] if fm['is_multiple']: if col == 'authors' or fm.get('display', {}).get( 'is_names', False): coltype = _( 'Ampersand separated text, shown in the Tag browser') else: coltype = self.column_desc['*' + dt] else: coltype = self.column_desc[dt] coltype_info = (coltype if oldkey is None else ' ' + _('(lookup name was {}) {}'.format(oldkey, coltype))) item = QTableWidgetItem(coltype_info) item.setFlags(flags) self.opt_columns.setItem(row, 2, item) desc = fm['display'].get('description', "") item = QTableWidgetItem(desc) item.setFlags(flags) self.opt_columns.setItem(row, 3, item) item = QTableWidgetItem(fm['name']) item.setData(Qt.ItemDataRole.UserRole, (col)) item.setFlags(flags) self.opt_columns.setItem(row, 0, item) if col.startswith('#'): item.setData(Qt.ItemDataRole.DecorationRole, (QIcon(I('column.png')))) if col != 'ondevice': flags |= Qt.ItemFlag.ItemIsUserCheckable item.setFlags(flags) if col != 'ondevice': item.setCheckState(Qt.CheckState.Unchecked if col in self.hidden_cols else Qt.CheckState.Checked)
def __init__(self, parent, items): QDialog.__init__(self, parent) Ui_DeleteMatchingFromDeviceDialog.__init__(self) self.setupUi(self) self.explanation.setText('<p>' + _('All checked books will be ' '<b>permanently deleted</b> from your ' 'device. Please verify the list.') + '</p>') self.buttonBox.accepted.connect(self.accepted) self.buttonBox.rejected.connect(self.rejected) self.table.cellClicked.connect(self.cell_clicked) self.table.setSelectionMode( QAbstractItemView.SelectionMode.NoSelection) self.table.setColumnCount(7) self.table.setHorizontalHeaderLabels([ '', _('Location'), _('Title'), _('Author'), _('Date'), _('Format'), _('Path') ]) rows = 0 for card in items: rows += len(items[card][1]) self.table.setRowCount(rows) row = 0 for card in items: (model, books) = items[card] for (id, book) in books: item = QTableWidgetItem() item.setFlags(Qt.ItemFlag.ItemIsUserCheckable | Qt.ItemFlag.ItemIsEnabled) item.setCheckState(Qt.CheckState.Checked) item.setData(Qt.ItemDataRole.UserRole, (model, id, book.path)) self.table.setItem(row, 0, item) self.table.setItem(row, 1, tableItem(card)) self.table.setItem(row, 2, titleTableItem(book.title)) self.table.setItem(row, 3, authorTableItem(book)) self.table.setItem(row, 4, dateTableItem(book.datetime)) self.table.setItem( row, 5, centeredTableItem(book.path.rpartition('.')[2])) self.table.setItem(row, 6, tableItem(book.path)) row += 1 self.table.setCurrentCell(0, 1) self.table.resizeColumnsToContents() self.table.setSortingEnabled(True) self.table.sortByColumn(2, Qt.SortOrder.AscendingOrder) self.table.setCurrentCell(0, 1)
def __init__(self, parent, get_option, get_help, db=None, book_id=None): # Dummy attributes to fool the Widget() option handler code. We handle # everything in our *handler methods. for i in range(1, 4): x = 'sr%d_' % i for y in ('search', 'replace'): z = x + y setattr(self, 'opt_' + z, z) self.opt_search_replace = 'search_replace' Widget.__init__(self, parent, OPTIONS['pipe']['search_and_replace']) self.db, self.book_id = db, book_id self.sr_search.set_msg(_('&Search regular expression:')) self.sr_search.set_book_id(book_id) self.sr_search.set_db(db) self.sr_search.doc_update.connect(self.update_doc) proto = QTableWidgetItem() proto.setFlags( Qt.ItemFlags(Qt.ItemFlag.ItemIsSelectable + Qt.ItemFlag.ItemIsEnabled)) self.search_replace.setItemPrototype(proto) self.search_replace.setColumnCount(2) self.search_replace.setColumnWidth(0, 320) self.search_replace.setColumnWidth(1, 320) self.search_replace.setHorizontalHeaderLabels( [_('Search regular expression'), _('Replacement text')]) self.sr_add.clicked.connect(self.sr_add_clicked) self.sr_change.clicked.connect(self.sr_change_clicked) self.sr_remove.clicked.connect(self.sr_remove_clicked) self.sr_load.clicked.connect(self.sr_load_clicked) self.sr_save.clicked.connect(self.sr_save_clicked) self.sr_up.clicked.connect(self.sr_up_clicked) self.sr_down.clicked.connect(self.sr_down_clicked) self.search_replace.currentCellChanged.connect( self.sr_currentCellChanged) self.initialize_options(get_option, get_help, db, book_id) try: self.rh_label.setText( self.rh_label.text() % localize_user_manual_link( 'https://manual.calibre-ebook.com/regexp.html')) except TypeError: pass # link already localized