def show_context_menu(self, point): item = self.itemAt(point) if item is None or item in set(self.categories.itervalues()): return m = QMenu(self) sel = self.selectedItems() num = len(sel) if num > 0: m.addAction(QIcon(I('trash.png')), _('&Delete selected files'), self.request_delete) ci = self.currentItem() if ci is not None: cn = unicode(ci.data(0, NAME_ROLE).toString()) mt = unicode(ci.data(0, MIME_ROLE).toString()) cat = unicode(ci.data(0, CATEGORY_ROLE).toString()) m.addAction(QIcon(I('modified.png')), _('&Rename %s') % (elided_text(self.font(), cn)), self.edit_current_item) if is_raster_image(mt): m.addAction( QIcon(I('default_cover.png')), _('Mark %s as cover image') % elided_text(self.font(), cn), partial(self.mark_as_cover, cn)) elif current_container( ).SUPPORTS_TITLEPAGES and mt in OEB_DOCS and cat == 'text': m.addAction( QIcon(I('default_cover.png')), _('Mark %s as title/cover page') % elided_text(self.font(), cn), partial(self.mark_as_titlepage, cn)) selected_map = defaultdict(list) for item in sel: selected_map[unicode(item.data( 0, CATEGORY_ROLE).toString())].append( unicode(item.data(0, NAME_ROLE).toString())) for items in selected_map.itervalues(): items.sort(key=self.index_of_name) if len(selected_map['text']) > 1: m.addAction( QIcon(I('merge.png')), _('&Merge selected text files'), partial(self.start_merge, 'text', selected_map['text'])) if len(selected_map['styles']) > 1: m.addAction( QIcon(I('merge.png')), _('&Merge selected style files'), partial(self.start_merge, 'styles', selected_map['styles'])) if len(list(m.actions())) > 0: m.popup(self.mapToGlobal(point))
def show_context_menu(self, point): item = self.itemAt(point) if item is None or item in set(self.categories.itervalues()): return m = QMenu(self) sel = self.selectedItems() num = len(sel) if num > 0: m.addAction(QIcon(I('trash.png')), _('&Delete selected files'), self.request_delete) ci = self.currentItem() if ci is not None: cn = unicode(ci.data(0, NAME_ROLE).toString()) mt = unicode(ci.data(0, MIME_ROLE).toString()) cat = unicode(ci.data(0, CATEGORY_ROLE).toString()) m.addAction(QIcon(I('modified.png')), _('&Rename %s') % (elided_text(self.font(), cn)), self.edit_current_item) if is_raster_image(mt): m.addAction(QIcon(I('default_cover.png')), _('Mark %s as cover image') % elided_text(self.font(), cn), partial(self.mark_as_cover, cn)) elif current_container().SUPPORTS_TITLEPAGES and mt in OEB_DOCS and cat == 'text': m.addAction(QIcon(I('default_cover.png')), _('Mark %s as title/cover page') % elided_text(self.font(), cn), partial(self.mark_as_titlepage, cn)) selected_map = defaultdict(list) for item in sel: selected_map[unicode(item.data(0, CATEGORY_ROLE).toString())].append(unicode(item.data(0, NAME_ROLE).toString())) for items in selected_map.itervalues(): items.sort(key=self.index_of_name) if len(selected_map['text']) > 1: m.addAction(QIcon(I('merge.png')), _('&Merge selected text files'), partial(self.start_merge, 'text', selected_map['text'])) if len(selected_map['styles']) > 1: m.addAction(QIcon(I('merge.png')), _('&Merge selected style files'), partial(self.start_merge, 'styles', selected_map['styles'])) if len(list(m.actions())) > 0: m.popup(self.mapToGlobal(point))
def mark_as_titlepage(self, name): first = unicode(self.categories['text'].child(0).data(0, NAME_ROLE).toString()) == name move_to_start = False if not first: move_to_start = question_dialog(self, _('Not first item'), _( '%s is not the first text item. You should only mark the' ' first text item as cover. Do you want to make it the' ' first item?') % elided_text(self.font(), name)) self.mark_requested.emit(name, 'titlepage:%r' % move_to_start)
def mark_as_titlepage(self, name): first = unicode(self.categories['text'].child(0).data( 0, NAME_ROLE).toString()) == name move_to_start = False if not first: move_to_start = question_dialog( self, _('Not first item'), _('%s is not the first text item. You should only mark the' ' first text item as cover. Do you want to make it the' ' first item?') % elided_text(self.font(), name)) self.mark_requested.emit(name, 'titlepage:%r' % move_to_start)
def show_context_menu(self, point): item = self.itemAt(point) if item is None or item in set(self.categories.itervalues()): return m = QMenu(self) sel = self.selectedItems() num = len(sel) if num > 0: m.addAction(QIcon(I("trash.png")), _("&Delete selected files"), self.request_delete) ci = self.currentItem() if ci is not None: cn = unicode(ci.data(0, NAME_ROLE).toString()) m.addAction( QIcon(I("modified.png")), _("&Rename %s") % (elided_text(self.font(), cn)), self.edit_current_item ) selected_map = defaultdict(list) for item in sel: selected_map[unicode(item.data(0, CATEGORY_ROLE).toString())].append( unicode(item.data(0, NAME_ROLE).toString()) ) for items in selected_map.itervalues(): items.sort(key=self.index_of_name) if len(selected_map["text"]) > 1: m.addAction( QIcon(I("merge.png")), _("&Merge selected text files"), partial(self.start_merge, "text", selected_map["text"]), ) if len(selected_map["styles"]) > 1: m.addAction( QIcon(I("merge.png")), _("&Merge selected style files"), partial(self.start_merge, "styles", selected_map["styles"]), ) if len(list(m.actions())) > 0: m.popup(self.mapToGlobal(point))
def elided_text(self, text, width=200, mode=Qt.ElideMiddle): return elided_text(self.font(), text, width=width, mode=mode)