def __init__(self, window, msg, formats): ''' formats is a list of tuples: [(format, exists, convertible)]. format: Lower case format identifier. E.G. mobi exists: String representing the number of books that exist in the format. convertible: True if the format is a convertible format. formats should be ordered in the device's preferred format ordering. ''' QDialog.__init__(self, window) Ui_ChooseFormatDeviceDialog.__init__(self) self.setupUi(self) self.formats.activated[QModelIndex].connect(self.activated_slot) self.msg.setText(msg) for i, (format, exists, convertible) in enumerate(formats): t_item = QTreeWidgetItem() t_item.setIcon(0, file_icon_provider().icon_from_ext(format.lower())) t_item.setText(0, format.upper()) t_item.setText(1, exists) if convertible: t_item.setIcon(2, QIcon(I('ok.png'))) self.formats.addTopLevelItem(t_item) if i == 0: self.formats.setCurrentItem(t_item) t_item.setSelected(True) self.formats.resizeColumnToContents(2) self.formats.resizeColumnToContents(1) self.formats.resizeColumnToContents(0) self.formats.header().resizeSection( 0, self.formats.header().sectionSize(0) * 2) self._format = None
def process_node(toc, parent): for child in toc: node = QTreeWidgetItem(parent) node.setText(0, child.title or '') node.setData(0, DEST_ROLE, child.dest or '') node.setData(0, FRAG_ROLE, child.frag or '') tt = _('File: {0}\nAnchor: {1}').format( child.dest or '', child.frag or _('Top of file')) node.setData(0, Qt.ItemDataRole.ToolTipRole, tt) process_node(child, node)