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 textwrap import TextWrapper
|
||||||
|
|
||||||
from calibre import OptionParser, Settings, terminal_controller, preferred_encoding
|
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.meta import get_metadata
|
||||||
from calibre.ebooks.metadata.opf import OPFCreator, OPFReader
|
from calibre.ebooks.metadata.opf import OPFCreator, OPFReader
|
||||||
from calibre.library.database import LibraryDatabase, text_to_tokens
|
from calibre.library.database import LibraryDatabase, text_to_tokens
|
||||||
@ -182,9 +185,8 @@ def do_add(db, paths, one_book_per_directory, recurse, add_duplicates):
|
|||||||
print '\t', title+':'
|
print '\t', title+':'
|
||||||
print '\t\t ', path
|
print '\t\t ', path
|
||||||
|
|
||||||
if SingleApplication is not None:
|
if send_message is not None:
|
||||||
sa = SingleApplication('calibre GUI')
|
send_message('refreshdb:', 'calibre GUI')
|
||||||
sa.send_message('refreshdb:')
|
|
||||||
finally:
|
finally:
|
||||||
sys.stdout = sys.__stdout__
|
sys.stdout = sys.__stdout__
|
||||||
|
|
||||||
@ -222,9 +224,9 @@ def do_remove(db, ids):
|
|||||||
for y in x:
|
for y in x:
|
||||||
db.delete_book(y)
|
db.delete_book(y)
|
||||||
|
|
||||||
if SingleApplication is not None:
|
if send_message is not None:
|
||||||
sa = SingleApplication('calibre GUI')
|
send_message('refreshdb:', 'calibre GUI')
|
||||||
sa.send_message('refreshdb:')
|
|
||||||
|
|
||||||
def command_remove(args, dbpath):
|
def command_remove(args, dbpath):
|
||||||
parser = get_parser(_(
|
parser = get_parser(_(
|
||||||
@ -337,9 +339,8 @@ def do_set_metadata(db, id, stream):
|
|||||||
mi = OPFReader(stream)
|
mi = OPFReader(stream)
|
||||||
db.set_metadata(id, mi)
|
db.set_metadata(id, mi)
|
||||||
do_show_metadata(db, id, False)
|
do_show_metadata(db, id, False)
|
||||||
if SingleApplication is not None:
|
if send_message is not None:
|
||||||
sa = SingleApplication('calibre GUI')
|
send_message('refreshdb:', 'calibre GUI')
|
||||||
sa.send_message('refreshdb:')
|
|
||||||
|
|
||||||
def command_set_metadata(args, dbpath):
|
def command_set_metadata(args, dbpath):
|
||||||
parser = get_parser(_(
|
parser = get_parser(_(
|
||||||
|
@ -104,7 +104,12 @@ class LocalServer(QLocalServer):
|
|||||||
return True
|
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):
|
class SingleApplication(QObject):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user