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 __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 create_folder(self, item): text, ok = QInputDialog.getText(self, _('Folder name'), _('Enter a name for the new folder')) if ok and unicode(text): c = QTreeWidgetItem(item, (unicode(text),)) c.setIcon(0, QIcon(I('mimetypes/dir.png'))) for item in self.folders.selectedItems(): item.setSelected(False) c.setSelected(True) self.folders.setCurrentItem(c)
def create_folder(self, item): text, ok = QInputDialog.getText(self, _('Folder name'), _('Enter a name for the new folder')) if ok and unicode(text): c = QTreeWidgetItem(item, (unicode(text), )) c.setIcon(0, QIcon(I('mimetypes/dir.png'))) for item in self.folders.selectedItems(): item.setSelected(False) c.setSelected(True) self.folders.setCurrentItem(c)
def setOpen(self, o): if o: self.setIcon(0, folderOpenIcon) else: self.setIcon(0, folderClosedIcon) if o and not self.childCount(): s = self.fullName() thisDir = QDir(s) if not thisDir.isReadable(): self.readable = 0 return files = thisDir.entryInfoList() if files: for f in files: # f is a QFileInfo # f.fileName is '.' or '..' or 'bearings' or... fileName = str(f.fileName()) if fileName == '.' or fileName == '..': continue elif f.isSymLink(): d = QTreeWidgetItem(self, fileName) #, 'Symbolic Link') d.setIcon(0, fileIcon) elif f.isDir(): if fileName == 'CVS': #bruce 060319 skip CVS directories, so developers see same set of directories as end-users # (implements NFR I recently reported) # WARNING: this is only legitimate for some applications of this module. # For now that's ok (we only use it in MMKit). Later this feature should be turned on # by an optional argument to __init__, and generalized to a list of files to not show # or to a filter function. continue d = Directory(self, fileName) else: if f.isFile(): s = 'File' else: s = 'Special' if not fileName[-3:] in self.filterList: continue d = FileItem(self, f.absFilePath(), fileName) d.setIcon(0, fileIcon) qt4todo('QTreeWidgetItem.setOpen(self, o)')
def setOpen(self, o): if o: self.setIcon(0, folderOpenIcon) else: self.setIcon(0, folderClosedIcon) if o and not self.childCount(): s = self.fullName() thisDir = QDir(s) if not thisDir.isReadable(): self.readable = 0 return files = thisDir.entryInfoList() if files: for f in files: # f is a QFileInfo # f.fileName is '.' or '..' or 'bearings' or... fileName = str(f.fileName()) if fileName == '.' or fileName == '..': continue elif f.isSymLink(): d = QTreeWidgetItem(self, fileName)#, 'Symbolic Link') d.setIcon(0, fileIcon) elif f.isDir(): if fileName == 'CVS': #bruce 060319 skip CVS directories, so developers see same set of directories as end-users # (implements NFR I recently reported) # WARNING: this is only legitimate for some applications of this module. # For now that's ok (we only use it in MMKit). Later this feature should be turned on # by an optional argument to __init__, and generalized to a list of files to not show # or to a filter function. continue d = Directory(self, fileName) else: if f.isFile(): s = 'File' else: s = 'Special' if not fileName[-3:] in self.filterList: continue d = FileItem(self, f.absFilePath(), fileName) d.setIcon(0, fileIcon) qt4todo('QTreeWidgetItem.setOpen(self, o)')
def build(self, container): self.clear() self.root = self.invisibleRootItem() self.root.setFlags(Qt.ItemIsDragEnabled) self.categories = {} for category, text, icon in ( ('text', _('Text'), 'keyboard-prefs.png'), ('styles', _('Styles'), 'lookfeel.png'), ('images', _('Images'), 'view-image.png'), ('fonts', _('Fonts'), 'font.png'), ('misc', _('Miscellaneous'), 'mimetypes/dir.png'), ): self.categories[category] = i = QTreeWidgetItem(self.root, 0) i.setText(0, text) i.setIcon(0, QIcon(I(icon))) f = i.font(0) f.setBold(True) i.setFont(0, f) i.setData(0, NAME_ROLE, category) flags = Qt.ItemIsEnabled if category == 'text': flags |= Qt.ItemIsDropEnabled i.setFlags(flags) processed, seen = set(), {} def get_display_name(name, item): parts = name.split('/') text = parts[-1] while text in seen and parts: text = parts.pop() + '/' + text seen[text] = item return text for name, linear in container.spine_names: processed.add(name) i = QTreeWidgetItem(self.categories['text'], 1) prefix = '' if linear else '[nl] ' if not linear: i.setIcon(self.non_linear_icon) i.setText(0, prefix + get_display_name(name, i)) i.setStatusTip(0, _('Full path: ') + name) i.setFlags(Qt.ItemIsEnabled | Qt.ItemIsDragEnabled | Qt.ItemIsSelectable) i.setData(0, NAME_ROLE, name) font_types = {guess_type('a.'+x)[0] for x in ('ttf', 'otf', 'woff')} def get_category(mt): category = 'misc' if mt.startswith('image/'): category = 'images' elif mt in font_types: category = 'fonts' elif mt in OEB_STYLES: category = 'styles' return category all_files = list(container.manifest_type_map.iteritems()) all_files.append((guess_type('a.opf')[0], [container.opf_name])) for name in container.name_path_map: if name in processed: continue processed.add(name) imt = container.mime_map.get(name, guess_type(name)[0]) icat = get_category(imt) i = QTreeWidgetItem(self.categories[icat], 1) i.setText(0, get_display_name(name, i)) i.setStatusTip(0, _('Full path: ') + name) i.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) i.setData(0, NAME_ROLE, name) for c in self.categories.itervalues(): self.expandItem(c)