diff --git a/src/calibre/gui2/book_details.py b/src/calibre/gui2/book_details.py index 26deab2866..b57397a47f 100644 --- a/src/calibre/gui2/book_details.py +++ b/src/calibre/gui2/book_details.py @@ -744,16 +744,16 @@ def details_context_menu_event(view, ev, book_info, add_popup_action=False, edit # }}} -def create_open_cover_with_menu(self, parent_menu): +def create_open_cover_with_menu(self, parent_menu, text=''): from calibre.gui2.open_with import edit_programs, populate_menu - m = QMenu(_('Open cover with...')) + m = QMenu(text or _('Open cover with...')) def connect_action(ac, entry): connect_lambda(ac.triggered, self, lambda self: self.open_with(entry)) populate_menu(m, connect_action, 'cover_image') if len(m.actions()) == 0: - parent_menu.addAction(_('Open cover with...'), self.choose_open_with) + parent_menu.addAction(text or _('Open cover with...'), self.choose_open_with) else: m.addSeparator() m.addAction(_('Add another application to open cover with...'), self.choose_open_with) diff --git a/src/calibre/gui2/metadata/basic_widgets.py b/src/calibre/gui2/metadata/basic_widgets.py index 5b415af265..003b2566ea 100644 --- a/src/calibre/gui2/metadata/basic_widgets.py +++ b/src/calibre/gui2/metadata/basic_widgets.py @@ -1232,6 +1232,8 @@ class Cover(ImageView): # {{{ m = super().build_context_menu() m.addSeparator() m.addAction(QIcon.ic('view-image'), _('View image in popup window'), self.view_image) + from calibre.gui2.book_details import create_open_cover_with_menu + create_open_cover_with_menu(self, m, _('Edit cover with...')) return m def mouseDoubleClickEvent(self, event): @@ -1249,6 +1251,32 @@ class Cover(ImageView): # {{{ from calibre.utils.img import image_to_data self.current_val = image_to_data(d.current_img.toImage(), fmt='png') + def open_with(self, entry): + from calibre.gui2 import info_dialog + from calibre.gui2.open_with import run_program + from calibre.utils.img import image_from_data, save_image + cdata = self.current_val + img = image_from_data(cdata) + pt = PersistentTemporaryFile(suffix='.png') + pt.close() + try: + save_image(img, pt.name) + run_program(entry, pt.name, self) + info_dialog(self, _('Cover opened in {}').format(entry.get('name') or _('external editor')), _( + 'Close this popup when you are done making changes to the cover'), show=True, show_copy_button=False) + finally: + with open(pt.name, 'rb') as f: + ncdata = f.read() + os.remove(pt.name) + if ncdata and ncdata != cdata: + self.current_val = ncdata + + def choose_open_with(self): + from calibre.gui2.open_with import choose_program + entry = choose_program('cover_image', self) + if entry is not None: + self.open_with(entry) + def undo_trim(self): if self.cdata_before_trim: self.current_val = self.cdata_before_trim