def send_message_to_viewer_instance(args, open_at): if len(args) > 1: msg = json.dumps((os.path.abspath(args[1]), open_at)) try: send_message_in_process(msg, address=viewer_socket_address()) except Exception as err: error_dialog(None, _('Connecting to E-book viewer failed'), _( 'Unable to connect to existing E-book viewer window, try restarting the viewer.'), det_msg=str(err), show=True) raise SystemExit(1) print('Opened book in existing viewer instance')
def send_message(msg): try: send_message_in_process(msg) except Exception as err: print(_('Failed to contact running instance of calibre'), file=sys.stderr, flush=True) print(err, file=sys.stderr, flush=True) error_dialog(None, _('Contacting calibre failed'), _( 'Failed to contact running instance of calibre, try restarting calibre'), det_msg=str(err), show=True) return False return True
def download_finished(self, download_id): self.central.download_progress.remove_item(download_id) download_item = self.download_data.pop(download_id) path = download_item.path() fname = os.path.basename(path) if download_item.state() == QWebEngineDownloadItem.DownloadState.DownloadInterrupted: error_dialog(self, _('Download failed'), _( 'Download of {0} failed with error: {1}').format(fname, download_item.interruptReasonString()), show=True) return ext = fname.rpartition('.')[-1].lower() if ext not in BOOK_EXTENSIONS: if ext == 'acsm': if not confirm('<p>' + _( 'This e-book is a DRMed EPUB file. ' 'You will be prompted to save this file to your ' 'computer. Once it is saved, open it with ' '<a href="https://www.adobe.com/solutions/ebook/digital-editions.html">' 'Adobe Digital Editions</a> (ADE).<p>ADE, in turn ' 'will download the actual e-book, which will be a ' '.epub file. You can add this book to calibre ' 'using "Add Books" and selecting the file from ' 'the ADE library folder.'), 'acsm_download', self): return name = choose_save_file(self, 'web-store-download-unknown', _( 'File is not a supported e-book type. Save to disk?'), initial_filename=fname) if name: shutil.copyfile(path, name) os.remove(path) return tags = self.data['tags'] if isinstance(tags, string_or_bytes): tags = list(filter(None, [x.strip() for x in tags.split(',')])) data = json.dumps({'path': path, 'tags': tags}) if not isinstance(data, bytes): data = data.encode('utf-8') try: send_message_in_process(b'web-store:' + data) except Exception as err: error_dialog(self, _('Could not contact calibre'), _( 'No running calibre instance found. Please start calibre before trying to' ' download books.'), det_msg=str(err), show=True) return info_dialog(self, _('Download completed'), _( 'Download of {0} has been completed, the book was added to' ' your calibre library').format(fname), show=True)
def send_message(msg): try: send_message_in_process(msg) except Exception: time.sleep(2) try: send_message_in_process(msg) except Exception as err: print(_('Failed to contact running instance of calibre'), file=sys.stderr, flush=True) print(err, file=sys.stderr, flush=True) if Application.instance(): error_dialog(None, _('Contacting calibre failed'), _( 'Failed to contact running instance of calibre, try restarting calibre'), det_msg=str(err) + '\n\n' + repr(msg), show=True) return False return True
def send_message(msg=''): if msg: from calibre.gui2.listener import send_message_in_process send_message_in_process('bookedited:' + msg)