Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
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
Exemple #4
0
def run_gui(opts, args, actions, 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)
    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:
                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
Exemple #5
0
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
Exemple #6
0
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
Exemple #7
0
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