More work on the new viewer

This commit is contained in:
Kovid Goyal 2018-08-01 15:40:54 +05:30
parent 200d38d2f5
commit 2c669bf853
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 34 additions and 1 deletions

View File

@ -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)

View File

@ -0,0 +1,31 @@
#!/usr/bin/env python2
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
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_()