mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-01-04 05:25:05 +01:00
DRYer
This commit is contained in:
parent
03df594e07
commit
1d892d9c0d
2 changed files with 11 additions and 13 deletions
|
|
@ -8,7 +8,6 @@
|
|||
import sys
|
||||
import time
|
||||
import traceback
|
||||
from functools import partial
|
||||
|
||||
import apsw
|
||||
from PyQt5.Qt import QCoreApplication, QIcon, QObject, QTimer
|
||||
|
|
@ -244,18 +243,12 @@ def start_gui(self, db):
|
|||
self.timed_print('splash screen hidden')
|
||||
self.splash_screen = None
|
||||
self.timed_print('Started up in %.2f seconds'%(monotonic() - self.startup_time), 'with', len(db.data), 'books')
|
||||
add_filesystem_book = partial(main.iactions['Add Books'].add_filesystem_book, allow_device=False)
|
||||
main.set_exception_handler()
|
||||
if len(self.args) > 1:
|
||||
files = [os.path.abspath(p) for p in self.args[1:] if not
|
||||
os.path.isdir(p)]
|
||||
if len(files) < len(sys.argv[1:]):
|
||||
prints('Ignoring directories passed as command line arguments')
|
||||
if files:
|
||||
add_filesystem_book(files)
|
||||
main.handle_cli_args(self.args[1:])
|
||||
for event in self.app.file_event_hook.events:
|
||||
add_filesystem_book(event)
|
||||
self.app.file_event_hook = add_filesystem_book
|
||||
main.handle_cli_args(event)
|
||||
self.app.file_event_hook = main.handle_cli_args
|
||||
|
||||
def choose_dir(self, initial_dir):
|
||||
self.hide_splash_screen()
|
||||
|
|
|
|||
|
|
@ -613,6 +613,13 @@ def refresh_all(self):
|
|||
m.research()
|
||||
self.tags_view.recount()
|
||||
|
||||
def handle_cli_args(self, args):
|
||||
if isinstance(args, basestring):
|
||||
args = [args]
|
||||
files = [os.path.abspath(p) for p in args if not os.path.isdir(p) and os.access(p, os.R_OK)]
|
||||
if files:
|
||||
self.iactions['Add Books'].add_filesystem_book(files)
|
||||
|
||||
def another_instance_wants_to_talk(self):
|
||||
try:
|
||||
msg = self.listener.queue.get_nowait()
|
||||
|
|
@ -631,9 +638,7 @@ def another_instance_wants_to_talk(self):
|
|||
det_msg='Invalid msg: %r' % msg, show=True)
|
||||
argv = ()
|
||||
if isinstance(argv, (list, tuple)) and len(argv) > 1:
|
||||
files = [os.path.abspath(p) for p in argv[1:] if not os.path.isdir(p) and os.access(p, os.R_OK)]
|
||||
if files:
|
||||
self.iactions['Add Books'].add_filesystem_book(files)
|
||||
self.handle_cli_args(argv[1:])
|
||||
self.setWindowState(self.windowState() & ~Qt.WindowMinimized|Qt.WindowActive)
|
||||
self.show_windows()
|
||||
self.raise_()
|
||||
|
|
|
|||
Loading…
Reference in a new issue