mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer
This commit is contained in:
parent
03df594e07
commit
1d892d9c0d
@ -8,7 +8,6 @@ import socket
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from functools import partial
|
|
||||||
|
|
||||||
import apsw
|
import apsw
|
||||||
from PyQt5.Qt import QCoreApplication, QIcon, QObject, QTimer
|
from PyQt5.Qt import QCoreApplication, QIcon, QObject, QTimer
|
||||||
@ -244,18 +243,12 @@ class GuiRunner(QObject):
|
|||||||
self.timed_print('splash screen hidden')
|
self.timed_print('splash screen hidden')
|
||||||
self.splash_screen = None
|
self.splash_screen = None
|
||||||
self.timed_print('Started up in %.2f seconds'%(monotonic() - self.startup_time), 'with', len(db.data), 'books')
|
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()
|
main.set_exception_handler()
|
||||||
if len(self.args) > 1:
|
if len(self.args) > 1:
|
||||||
files = [os.path.abspath(p) for p in self.args[1:] if not
|
main.handle_cli_args(self.args[1:])
|
||||||
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)
|
|
||||||
for event in self.app.file_event_hook.events:
|
for event in self.app.file_event_hook.events:
|
||||||
add_filesystem_book(event)
|
main.handle_cli_args(event)
|
||||||
self.app.file_event_hook = add_filesystem_book
|
self.app.file_event_hook = main.handle_cli_args
|
||||||
|
|
||||||
def choose_dir(self, initial_dir):
|
def choose_dir(self, initial_dir):
|
||||||
self.hide_splash_screen()
|
self.hide_splash_screen()
|
||||||
|
@ -613,6 +613,13 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
|||||||
m.research()
|
m.research()
|
||||||
self.tags_view.recount()
|
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):
|
def another_instance_wants_to_talk(self):
|
||||||
try:
|
try:
|
||||||
msg = self.listener.queue.get_nowait()
|
msg = self.listener.queue.get_nowait()
|
||||||
@ -631,9 +638,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
|||||||
det_msg='Invalid msg: %r' % msg, show=True)
|
det_msg='Invalid msg: %r' % msg, show=True)
|
||||||
argv = ()
|
argv = ()
|
||||||
if isinstance(argv, (list, tuple)) and len(argv) > 1:
|
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)]
|
self.handle_cli_args(argv[1:])
|
||||||
if files:
|
|
||||||
self.iactions['Add Books'].add_filesystem_book(files)
|
|
||||||
self.setWindowState(self.windowState() & ~Qt.WindowMinimized|Qt.WindowActive)
|
self.setWindowState(self.windowState() & ~Qt.WindowMinimized|Qt.WindowActive)
|
||||||
self.show_windows()
|
self.show_windows()
|
||||||
self.raise_()
|
self.raise_()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user