mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
IGN:Remove uneccessary dependency on Qt mainloop when messaging the GUI from a commandline app
This commit is contained in:
parent
9f1daa37d6
commit
103f8d91d9
@ -11,7 +11,10 @@ import sys, os
|
||||
from textwrap import TextWrapper
|
||||
|
||||
from calibre import OptionParser, Settings, terminal_controller, preferred_encoding
|
||||
from calibre.gui2 import SingleApplication
|
||||
try:
|
||||
from calibre.utils.single_qt_application import send_message
|
||||
except:
|
||||
send_message = None
|
||||
from calibre.ebooks.metadata.meta import get_metadata
|
||||
from calibre.ebooks.metadata.opf import OPFCreator, OPFReader
|
||||
from calibre.library.database import LibraryDatabase, text_to_tokens
|
||||
@ -181,10 +184,9 @@ def do_add(db, paths, one_book_per_directory, recurse, add_duplicates):
|
||||
title = title.encode(preferred_encoding)
|
||||
print '\t', title+':'
|
||||
print '\t\t ', path
|
||||
|
||||
if SingleApplication is not None:
|
||||
sa = SingleApplication('calibre GUI')
|
||||
sa.send_message('refreshdb:')
|
||||
|
||||
if send_message is not None:
|
||||
send_message('refreshdb:', 'calibre GUI')
|
||||
finally:
|
||||
sys.stdout = sys.__stdout__
|
||||
|
||||
@ -222,10 +224,10 @@ def do_remove(db, ids):
|
||||
for y in x:
|
||||
db.delete_book(y)
|
||||
|
||||
if SingleApplication is not None:
|
||||
sa = SingleApplication('calibre GUI')
|
||||
sa.send_message('refreshdb:')
|
||||
|
||||
if send_message is not None:
|
||||
send_message('refreshdb:', 'calibre GUI')
|
||||
|
||||
|
||||
def command_remove(args, dbpath):
|
||||
parser = get_parser(_(
|
||||
'''\
|
||||
@ -337,10 +339,9 @@ def do_set_metadata(db, id, stream):
|
||||
mi = OPFReader(stream)
|
||||
db.set_metadata(id, mi)
|
||||
do_show_metadata(db, id, False)
|
||||
if SingleApplication is not None:
|
||||
sa = SingleApplication('calibre GUI')
|
||||
sa.send_message('refreshdb:')
|
||||
|
||||
if send_message is not None:
|
||||
send_message('refreshdb:', 'calibre GUI')
|
||||
|
||||
def command_set_metadata(args, dbpath):
|
||||
parser = get_parser(_(
|
||||
'''
|
||||
|
@ -104,7 +104,12 @@ class LocalServer(QLocalServer):
|
||||
return True
|
||||
|
||||
|
||||
|
||||
def send_message(msg, name, server_name='calibre_server', timeout=5000):
|
||||
socket = QLocalSocket()
|
||||
socket.connectToServer(server_name)
|
||||
if socket.waitForConnected(timeout_connect):
|
||||
if read_message(socket) == name:
|
||||
write_message(socket, name+':'+msg, timeout)
|
||||
|
||||
class SingleApplication(QObject):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user