def start_gui(self, db): from calibre.gui2.ui import Main main = Main(self.opts, gui_debug=self.gui_debug) if self.splash_screen is not None: self.splash_screen.showMessage(_('Initializing user interface...')) with gprefs: # Only write gui.json after initialization is complete main.initialize(self.library_path, db, self.listener, self.actions) if self.splash_screen is not None: self.splash_screen.finish(main) 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) sys.excepthook = main.unhandled_exception 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 self.main = main
def start_gui(self, db): from calibre.gui2.ui import Main main = Main(self.opts, gui_debug=self.gui_debug) if self.splash_screen is not None: self.splash_screen.showMessage(_('Initializing user interface...')) with gprefs: # Only write gui.json after initialization is complete main.initialize(self.library_path, db, self.listener, self.actions) if self.splash_screen is not None: self.splash_screen.finish(main) 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) sys.excepthook = main.unhandled_exception 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 self.main = main
def run_gui(opts, args, listener, app, gui_debug=None): initialize_file_icon_provider() app.load_builtin_fonts(scan_for_fonts=True) if not dynamic.get('welcome_wizard_was_run', False): from calibre.gui2.wizard import wizard wizard().exec_() dynamic.set('welcome_wizard_was_run', True) from calibre.gui2.ui import Main if isosx: actions = tuple(Main.create_application_menubar()) else: actions = tuple(Main.get_menubar_actions()) runner = GuiRunner(opts, args, actions, listener, app, gui_debug=gui_debug) ret = app.exec_() if getattr(runner.main, 'run_wizard_b4_shutdown', False): from calibre.gui2.wizard import wizard wizard().exec_() if getattr(runner.main, 'restart_after_quit', False): e = sys.executable if getattr(sys, 'frozen', False) else sys.argv[0] if getattr(runner.main, 'debug_on_restart', False) or gui_debug is not None: run_in_debug_mode() else: import subprocess if hasattr(sys, 'frameworks_dir'): app = os.path.dirname( os.path.dirname(os.path.realpath(sys.frameworks_dir))) prints('Restarting with:', app) subprocess.Popen('sleep 3s; open ' + shellquote(app), shell=True) else: if iswindows and hasattr(winutil, 'prepare_for_restart'): winutil.prepare_for_restart() args = ['-g' ] if os.path.splitext(e)[0].endswith('-debug') else [] prints('Restarting with:', ' '.join([e] + args)) subprocess.Popen([e] + args) else: if iswindows: try: runner.main.system_tray_icon.hide() except: pass if getattr(runner.main, 'gui_debug', None) is not None: e = sys.executable if getattr(sys, 'frozen', False) else sys.argv[0] debugfile = runner.main.gui_debug from calibre.gui2 import open_local_file if iswindows: with open(debugfile, 'r+b') as f: raw = f.read() raw = re.sub(b'(?<!\r)\n', b'\r\n', raw) f.seek(0) f.truncate() f.write(raw) open_local_file(debugfile) return ret
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
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, None, actions, show_gui=False) return gui
def run_gui(opts, args, listener, app, gui_debug=None): initialize_file_icon_provider() app.load_builtin_fonts(scan_for_fonts=True) if not dynamic.get('welcome_wizard_was_run', False): from calibre.gui2.wizard import wizard wizard().exec_() dynamic.set('welcome_wizard_was_run', True) from calibre.gui2.ui import Main if isosx: actions = tuple(Main.create_application_menubar()) else: actions = tuple(Main.get_menubar_actions()) runner = GuiRunner(opts, args, actions, listener, app, gui_debug=gui_debug) ret = app.exec_() if getattr(runner.main, 'run_wizard_b4_shutdown', False): from calibre.gui2.wizard import wizard wizard().exec_() if getattr(runner.main, 'restart_after_quit', False): e = sys.executable if getattr(sys, 'frozen', False) else sys.argv[0] if getattr(runner.main, 'debug_on_restart', False) or gui_debug is not None: run_in_debug_mode() else: import subprocess if hasattr(sys, 'frameworks_dir'): app = os.path.dirname(os.path.dirname(os.path.realpath(sys.frameworks_dir))) prints('Restarting with:', app) subprocess.Popen('sleep 3s; open ' + shellquote(app), shell=True) else: if iswindows and hasattr(winutil, 'prepare_for_restart'): winutil.prepare_for_restart() args = ['-g'] if os.path.splitext(e)[0].endswith('-debug') else [] prints('Restarting with:', ' '.join([e] + args)) subprocess.Popen([e] + args) else: if iswindows: try: runner.main.system_tray_icon.hide() except: pass if getattr(runner.main, 'gui_debug', None) is not None: e = sys.executable if getattr(sys, 'frozen', False) else sys.argv[0] debugfile = runner.main.gui_debug from calibre.gui2 import open_local_file if iswindows: with open(debugfile, 'r+b') as f: raw = f.read() raw = re.sub(b'(?<!\r)\n', b'\r\n', raw) f.seek(0) f.truncate() f.write(raw) open_local_file(debugfile) return ret
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 run_gui(opts, args, listener, app, gui_debug=None): initialize_file_icon_provider() app.load_builtin_fonts(scan_for_fonts=True) if not dynamic.get("welcome_wizard_was_run", False): from calibre.gui2.wizard import wizard wizard().exec_() dynamic.set("welcome_wizard_was_run", True) from calibre.gui2.ui import Main actions = tuple(Main.create_application_menubar()) runner = GuiRunner(opts, args, actions, listener, app, gui_debug=gui_debug) ret = app.exec_() if getattr(runner.main, "run_wizard_b4_shutdown", False): from calibre.gui2.wizard import wizard wizard().exec_() if getattr(runner.main, "restart_after_quit", False): e = sys.executable if getattr(sys, "frozen", False) else sys.argv[0] if getattr(runner.main, "debug_on_restart", False): run_in_debug_mode() else: import subprocess print "Restarting with:", e, sys.argv if hasattr(sys, "frameworks_dir"): app = os.path.dirname(os.path.dirname(sys.frameworks_dir)) subprocess.Popen("sleep 3s; open " + app, shell=True) else: if iswindows and hasattr(winutil, "prepare_for_restart"): winutil.prepare_for_restart() subprocess.Popen([e] + sys.argv[1:]) else: if iswindows: try: runner.main.system_tray_icon.hide() except: pass if getattr(runner.main, "gui_debug", None) is not None: e = sys.executable if getattr(sys, "frozen", False) else sys.argv[0] import subprocess creationflags = 0 if iswindows: import win32process creationflags = win32process.CREATE_NO_WINDOW subprocess.Popen( [e, "--show-gui-debug", runner.main.gui_debug], creationflags=creationflags, stdout=open(os.devnull, "w"), stderr=subprocess.PIPE, stdin=open(os.devnull, "r"), ) return ret
def run_gui_(opts, args, app, gui_debug=None): initialize_file_icon_provider() app.load_builtin_fonts(scan_for_fonts=True) if not dynamic.get('welcome_wizard_was_run', False): from calibre.gui2.wizard import wizard wizard().exec_() dynamic.set('welcome_wizard_was_run', True) from calibre.gui2.ui import Main if ismacos: actions = tuple(Main.create_application_menubar()) else: actions = tuple(Main.get_menubar_actions()) runner = GuiRunner(opts, args, actions, app, gui_debug=gui_debug) ret = app.exec_() if getattr(runner.main, 'run_wizard_b4_shutdown', False): from calibre.gui2.wizard import wizard wizard().exec_() if getattr(runner.main, 'restart_after_quit', False): after_quit_actions['restart_after_quit'] = True after_quit_actions['debug_on_restart'] = getattr( runner.main, 'debug_on_restart', False) or gui_debug is not None after_quit_actions['no_plugins_on_restart'] = getattr( runner.main, 'no_plugins_on_restart', False) else: if iswindows: try: runner.main.system_tray_icon.hide() except: pass if getattr(runner.main, 'gui_debug', None) is not None: debugfile = runner.main.gui_debug from calibre.gui2 import open_local_file if iswindows: with open(debugfile, 'r+b') as f: raw = f.read() raw = re.sub(b'(?<!\r)\n', b'\r\n', raw) f.seek(0) f.truncate() f.write(raw) open_local_file(debugfile) return ret
def run_gui(opts, args, listener, app, gui_debug=None): initialize_file_icon_provider() app.load_builtin_fonts(scan_for_fonts=True) if not dynamic.get("welcome_wizard_was_run", False): from calibre.gui2.wizard import wizard wizard().exec_() dynamic.set("welcome_wizard_was_run", True) from calibre.gui2.ui import Main actions = tuple(Main.create_application_menubar()) runner = GuiRunner(opts, args, actions, listener, app, gui_debug=gui_debug) ret = app.exec_() if getattr(runner.main, "run_wizard_b4_shutdown", False): from calibre.gui2.wizard import wizard wizard().exec_() if getattr(runner.main, "restart_after_quit", False): e = sys.executable if getattr(sys, "frozen", False) else sys.argv[0] if getattr(runner.main, "debug_on_restart", False): run_in_debug_mode() else: import subprocess print "Restarting with:", e, sys.argv if hasattr(sys, "frameworks_dir"): app = os.path.dirname(os.path.dirname(os.path.realpath(sys.frameworks_dir))) subprocess.Popen("sleep 3s; open " + shellquote(app), shell=True) else: if iswindows and hasattr(winutil, "prepare_for_restart"): winutil.prepare_for_restart() subprocess.Popen([e] + sys.argv[1:]) else: if iswindows: try: runner.main.system_tray_icon.hide() except: pass if getattr(runner.main, "gui_debug", None) is not None: e = sys.executable if getattr(sys, "frozen", False) else sys.argv[0] debugfile = runner.main.gui_debug from calibre.gui2 import open_local_file if iswindows: with open(debugfile, "r+b") as f: raw = f.read() raw = re.sub(b"(?<!\r)\n", b"\r\n", raw) f.seek(0) f.truncate() f.write(raw) open_local_file(debugfile) return ret
def run_gui(opts, args, listener, app, gui_debug=None): initialize_file_icon_provider() app.load_builtin_fonts(scan_for_fonts=True) if not dynamic.get('welcome_wizard_was_run', False): from calibre.gui2.wizard import wizard wizard().exec_() dynamic.set('welcome_wizard_was_run', True) from calibre.gui2.ui import Main actions = tuple(Main.create_application_menubar()) runner = GuiRunner(opts, args, actions, listener, app, gui_debug=gui_debug) ret = app.exec_() if getattr(runner.main, 'run_wizard_b4_shutdown', False): from calibre.gui2.wizard import wizard wizard().exec_() if getattr(runner.main, 'restart_after_quit', False): e = sys.executable if getattr(sys, 'frozen', False) else sys.argv[0] if getattr(runner.main, 'debug_on_restart', False): run_in_debug_mode() else: import subprocess print 'Restarting with:', e, sys.argv if hasattr(sys, 'frameworks_dir'): app = os.path.dirname(os.path.dirname(sys.frameworks_dir)) subprocess.Popen('sleep 3s; open ' + app, shell=True) else: if iswindows and hasattr(winutil, 'prepare_for_restart'): winutil.prepare_for_restart() subprocess.Popen([e] + sys.argv[1:]) else: if iswindows: try: runner.main.system_tray_icon.hide() except: pass if getattr(runner.main, 'gui_debug', None) is not None: e = sys.executable if getattr(sys, 'frozen', False) else sys.argv[0] import subprocess creationflags = 0 if iswindows: import win32process creationflags = win32process.CREATE_NO_WINDOW subprocess.Popen([e, '--show-gui-debug', runner.main.gui_debug], creationflags=creationflags, stdout=open(os.devnull, 'w'), stderr=subprocess.PIPE, stdin=open(os.devnull, 'r')) return ret
def init_qt(args): from calibre.gui2.ui import Main parser = option_parser() opts, args = parser.parse_args(args) if opts.with_library is not None: if not os.path.exists(opts.with_library): os.makedirs(opts.with_library) if os.path.isdir(opts.with_library): prefs.set('library_path', os.path.abspath(opts.with_library)) prints('Using library at', prefs['library_path']) QCoreApplication.setOrganizationName(ORG_NAME) QCoreApplication.setApplicationName(APP_UID) override = 'calibre-gui' if islinux else None app = Application(args, override_program_name=override) actions = tuple(Main.create_application_menubar()) app.setWindowIcon(QIcon(I('lt.png'))) return app, opts, args, actions
def start_gui(self, db): from calibre.gui2.ui import Main from calibre.gui2 import Application 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) print('aca mate todo') 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') 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_qt(args): from calibre.gui2.ui import Main parser = option_parser() opts, args = parser.parse_args(args) find_portable_library() if opts.with_library is not None: libpath = os.path.expanduser(opts.with_library) if not os.path.exists(libpath): os.makedirs(libpath) if os.path.isdir(libpath): prefs.set('library_path', os.path.abspath(libpath)) prints('Using library at', prefs['library_path']) QCoreApplication.setOrganizationName(ORG_NAME) QCoreApplication.setApplicationName(APP_UID) override = 'calibre-gui' if islinux else None app = Application(args, override_program_name=override) app.file_event_hook = EventAccumulator() actions = tuple(Main.create_application_menubar()) app.setWindowIcon(QIcon(I('lt.png'))) return app, opts, args, actions
def run_gui(opts, args, listener, app, gui_debug=None): si = singleinstance('db') if not si: ext = '.exe' if iswindows else '' error_dialog(None, _('Cannot start calibre'), _( 'Another calibre program that can modify calibre libraries, such as,' ' {} or {} is already running. You must first shut it down, before' ' starting the main calibre program. If you are sure no such' ' program is running, try restarting your computer.').format( 'calibre-server' + ext, 'calibredb' + ext), show=True) return 1 initialize_file_icon_provider() app.load_builtin_fonts(scan_for_fonts=True) if not dynamic.get('welcome_wizard_was_run', False): from calibre.gui2.wizard import wizard wizard().exec_() dynamic.set('welcome_wizard_was_run', True) from calibre.gui2.ui import Main if isosx: actions = tuple(Main.create_application_menubar()) else: actions = tuple(Main.get_menubar_actions()) runner = GuiRunner(opts, args, actions, listener, app, gui_debug=gui_debug) ret = app.exec_() if getattr(runner.main, 'run_wizard_b4_shutdown', False): from calibre.gui2.wizard import wizard wizard().exec_() if getattr(runner.main, 'restart_after_quit', False): e = sys.executable if getattr(sys, 'frozen', False) else sys.argv[0] if getattr(runner.main, 'debug_on_restart', False) or gui_debug is not None: run_in_debug_mode() else: import subprocess if hasattr(sys, 'frameworks_dir'): app = os.path.dirname(os.path.dirname(os.path.realpath(sys.frameworks_dir))) prints('Restarting with:', app) subprocess.Popen('sleep 3s; open ' + shellquote(app), shell=True) else: os.environ[b'CALIBRE_RESTARTING_FROM_GUI'] = b'1' if iswindows and hasattr(winutil, 'prepare_for_restart'): winutil.prepare_for_restart() args = ['-g'] if os.path.splitext(e)[0].endswith('-debug') else [] prints('Restarting with:', ' '.join([e] + args)) subprocess.Popen([e] + args) else: if iswindows: try: runner.main.system_tray_icon.hide() except: pass if getattr(runner.main, 'gui_debug', None) is not None: e = sys.executable if getattr(sys, 'frozen', False) else sys.argv[0] debugfile = runner.main.gui_debug from calibre.gui2 import open_local_file if iswindows: with open(debugfile, 'r+b') as f: raw = f.read() raw = re.sub(b'(?<!\r)\n', b'\r\n', raw) f.seek(0) f.truncate() f.write(raw) open_local_file(debugfile) return ret
def run_gui(opts, args, listener, app, gui_debug=None): si = singleinstance('db') if not si: ext = '.exe' if iswindows else '' error_dialog( None, _('Cannot start calibre'), _('Another calibre program that can modify calibre libraries, such as,' ' {} or {} is already running. You must first shut it down, before' ' starting the main calibre program. If you are sure no such' ' program is running, try restarting your computer.').format( 'calibre-server' + ext, 'calibredb' + ext), show=True) return 1 initialize_file_icon_provider() app.load_builtin_fonts(scan_for_fonts=True) if not dynamic.get('welcome_wizard_was_run', False): from calibre.gui2.wizard import wizard wizard().exec_() dynamic.set('welcome_wizard_was_run', True) from calibre.gui2.ui import Main if isosx: actions = tuple(Main.create_application_menubar()) else: actions = tuple(Main.get_menubar_actions()) runner = GuiRunner(opts, args, actions, listener, app, gui_debug=gui_debug) ret = app.exec_() if getattr(runner.main, 'run_wizard_b4_shutdown', False): from calibre.gui2.wizard import wizard wizard().exec_() if getattr(runner.main, 'restart_after_quit', False): e = sys.executable if getattr(sys, 'frozen', False) else sys.argv[0] if getattr(runner.main, 'debug_on_restart', False) or gui_debug is not None: run_in_debug_mode() else: if hasattr(sys, 'frameworks_dir'): app = os.path.dirname( os.path.dirname(os.path.realpath(sys.frameworks_dir))) from calibre.debug import run_calibre_debug prints('Restarting with:', app) run_calibre_debug( '-c', 'import sys, os, time; time.sleep(3); os.execlp("open", "open", sys.argv[-1])', app) else: import subprocess os.environ['CALIBRE_RESTARTING_FROM_GUI'] = environ_item('1') if iswindows and hasattr(winutil, 'prepare_for_restart'): winutil.prepare_for_restart() if hasattr(sys, 'run_local'): cmd = [sys.run_local] if DEBUG: cmd += ['calibre-debug', '-g'] else: cmd.append('calibre') else: args = [ '-g' ] if os.path.splitext(e)[0].endswith('-debug') else [] cmd = [e] + args prints('Restarting with:', ' '.join(cmd)) subprocess.Popen(cmd) else: if iswindows: try: runner.main.system_tray_icon.hide() except: pass if getattr(runner.main, 'gui_debug', None) is not None: e = sys.executable if getattr(sys, 'frozen', False) else sys.argv[0] debugfile = runner.main.gui_debug from calibre.gui2 import open_local_file if iswindows: with open(debugfile, 'r+b') as f: raw = f.read() raw = re.sub(b'(?<!\r)\n', b'\r\n', raw) f.seek(0) f.truncate() f.write(raw) open_local_file(debugfile) return ret