def start_gui(self, db): from calibre.gui2.ui import Main self.timed_print('Constructing main UI...') main = self.main = Main(self.opts, gui_debug=self.gui_debug) if self.splash_screen is not None: self.splash_screen.show_message( _('Initializing user interface...')) try: with gprefs: # Only write gui.json after initialization is complete main.initialize(self.library_path, db, self.listener, self.actions) finally: self.timed_print('main UI initialized...') if self.splash_screen is not None: self.timed_print('Hiding splash screen') self.splash_screen.finish(main) 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') main.set_exception_handler() if len(self.args) > 1: main.handle_cli_args(self.args[1:]) for event in self.app.file_event_hook.events: main.handle_cli_args(event) self.app.file_event_hook = main.handle_cli_args
def start_gui(self, db): from calibre.gui2.ui import Main main = self.main = Main(self.opts, gui_debug=self.gui_debug) if self.splash_screen is not None: self.splash_screen.show_message( _('Initializing user interface...')) try: with gprefs: # Only write gui.json after initialization is complete main.initialize(self.library_path, db, self.listener, self.actions) finally: if self.splash_screen is not None: self.splash_screen.finish(main) self.splash_screen = None if DEBUG: prints( 'Started up in %.2f seconds' % (time.time() - 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) for event in self.app.file_event_hook.events: add_filesystem_book(event) self.app.file_event_hook = add_filesystem_book
def init_gui(): from calibre.gui2.ui import Main from calibre.gui2.main import option_parser from calibre.library import db parser = option_parser() opts, args = parser.parse_args([]) actions = tuple(Main.create_application_menubar()) db = db() gui = Main(opts) gui.initialize(db.library_path, db, actions, show_gui=False) return gui