mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Make timed_print() re-useable
This commit is contained in:
parent
88320477ad
commit
ef70a1eefb
@ -1667,3 +1667,12 @@ def make_view_use_window_background(view):
|
||||
p.setColor(QPalette.ColorRole.AlternateBase, p.color(QPalette.ColorRole.Window))
|
||||
view.setPalette(p)
|
||||
return view
|
||||
|
||||
|
||||
def timed_print(*a, **kw):
|
||||
if not DEBUG:
|
||||
return
|
||||
from time import monotonic
|
||||
if not hasattr(timed_print, 'startup_time'):
|
||||
timed_print.startup_time = monotonic()
|
||||
print(f'[{monotonic() - timed_print.startup_time:.2f}]', *a, **kw)
|
||||
|
@ -17,7 +17,7 @@ from calibre.constants import (
|
||||
)
|
||||
from calibre.gui2 import (
|
||||
Application, choose_dir, error_dialog, gprefs, initialize_file_icon_provider,
|
||||
question_dialog, setup_gui_option_parser,
|
||||
question_dialog, setup_gui_option_parser, timed_print,
|
||||
)
|
||||
from calibre.gui2.listener import send_message_in_process
|
||||
from calibre.gui2.main_window import option_parser as _option_parser
|
||||
@ -235,7 +235,7 @@ class GuiRunner(QObject):
|
||||
|
||||
def __init__(self, opts, args, actions, app, gui_debug=None):
|
||||
self.startup_time = monotonic()
|
||||
self.timed_print('Starting up...')
|
||||
timed_print('Starting up...')
|
||||
self.opts, self.args, self.app = opts, args, app
|
||||
self.gui_debug = gui_debug
|
||||
self.actions = actions
|
||||
@ -244,13 +244,9 @@ class GuiRunner(QObject):
|
||||
self.splash_screen = None
|
||||
self.timer = QTimer.singleShot(1, self.initialize)
|
||||
|
||||
def timed_print(self, *a, **kw):
|
||||
if DEBUG:
|
||||
prints(f'[{monotonic() - self.startup_time:.2f}]', *a, **kw)
|
||||
|
||||
def start_gui(self, db):
|
||||
from calibre.gui2.ui import Main
|
||||
self.timed_print('Constructing main UI...')
|
||||
timed_print('Constructing main UI...')
|
||||
if self.splash_screen is not None:
|
||||
self.splash_screen.show_message(_('Initializing user interface...'))
|
||||
main = self.main = Main(self.opts, gui_debug=self.gui_debug)
|
||||
@ -258,13 +254,13 @@ class GuiRunner(QObject):
|
||||
with gprefs: # Only write gui.json after initialization is complete
|
||||
main.initialize(self.library_path, db, self.actions)
|
||||
finally:
|
||||
self.timed_print('main UI initialized...')
|
||||
timed_print('main UI initialized...')
|
||||
if self.splash_screen is not None:
|
||||
self.timed_print('Hiding splash screen')
|
||||
timed_print('Hiding splash screen')
|
||||
self.splash_screen.finish(main)
|
||||
self.timed_print('splash screen hidden')
|
||||
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')
|
||||
timed_print('Started up in %.2f seconds'%(monotonic() - self.startup_time), 'with', len(db.data), 'books')
|
||||
main.set_exception_handler()
|
||||
if len(self.args) > 1:
|
||||
main.handle_cli_args(self.args[1:])
|
||||
@ -311,7 +307,7 @@ class GuiRunner(QObject):
|
||||
det_msg=traceback.format_exc())
|
||||
self.initialization_failed()
|
||||
|
||||
self.timed_print('db initialized')
|
||||
timed_print('db initialized')
|
||||
try:
|
||||
self.start_gui(db)
|
||||
except Exception:
|
||||
@ -326,7 +322,7 @@ class GuiRunner(QObject):
|
||||
def initialize_db(self):
|
||||
from calibre.db.legacy import LibraryDatabase
|
||||
db = None
|
||||
self.timed_print('Initializing db...')
|
||||
timed_print('Initializing db...')
|
||||
try:
|
||||
db = LibraryDatabase(self.library_path)
|
||||
except apsw.Error:
|
||||
@ -359,11 +355,11 @@ class GuiRunner(QObject):
|
||||
self.initialize_db_stage2(db, None)
|
||||
|
||||
def show_splash_screen(self):
|
||||
self.timed_print('Showing splash screen...')
|
||||
timed_print('Showing splash screen...')
|
||||
self.splash_screen = SplashScreen()
|
||||
self.splash_screen.show()
|
||||
self.splash_screen.show_message(_('Starting %s: Loading books...') % __appname__)
|
||||
self.timed_print('splash screen shown')
|
||||
timed_print('splash screen shown')
|
||||
|
||||
def hide_splash_screen(self):
|
||||
if self.splash_screen is not None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user