diff --git a/src/calibre/gui2/viewer2/main.py b/src/calibre/gui2/viewer2/main.py index efb2fe8d66..98117c6c18 100644 --- a/src/calibre/gui2/viewer2/main.py +++ b/src/calibre/gui2/viewer2/main.py @@ -158,11 +158,13 @@ def main(args=sys.argv): app.setWindowIcon(QIcon(I('viewer.png'))) main = EbookViewer() main.set_exception_handler() + if args: + acc.events.append(args[-1]) acc.got_file.connect(main.handle_commandline_arg) main.show() main.msg_from_anotherinstance.connect(main.another_instance_wants_to_talk, type=Qt.QueuedConnection) if listener is not None: - t = Thread(name='ListenSI', target=listen, args=(listener, main.msg_from_anotherinstance)) + t = Thread(name='ConnListener', target=listen, args=(listener, main.msg_from_anotherinstance)) t.daemon = True t.start() QTimer.singleShot(0, acc.flush) diff --git a/src/calibre/gui2/viewer2/ui.py b/src/calibre/gui2/viewer2/ui.py new file mode 100644 index 0000000000..b995f65a01 --- /dev/null +++ b/src/calibre/gui2/viewer2/ui.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python2 +# vim:fileencoding=utf-8 +# License: GPL v3 Copyright: 2018, Kovid Goyal + +from __future__ import absolute_import, division, print_function, unicode_literals + +import os + +from PyQt5.Qt import pyqtSignal + +from calibre.gui2.main_window import MainWindow + + +class EbookViewer(MainWindow): + + msg_from_anotherinstance = pyqtSignal(object) + + def __init__(self): + MainWindow.__init__(self) + + def handle_commandline_arg(self, arg): + if arg and os.path.isfile(arg) and os.access(arg, os.R_OK): + self.load_ebook(arg) + + def another_instance_wants_to_talk(self, msg): + try: + path, open_at = msg + except Exception: + return + self.load_ebook(path, open_at=open_at) + self.raise_()