Esempio n. 1
0
def main():
    from xpra.gtk_common.quit import gtk_main_quit_on_fatal_exceptions_enable
    gtk_main_quit_on_fatal_exceptions_enable()

    from xpra.platform import init as platform_init
    from xpra.platform.gui import ready as gui_ready
    platform_init("Xpra-Launcher", "Xpra Connection Launcher")
    gui_init()

    #logging init:
    from xpra.scripts.main import parse_cmdline, fixup_debug_option
    options, args = parse_cmdline(sys.argv)
    debug = fixup_debug_option(options.debug)
    if debug:
        for x in debug.split(","):
            enable_debug_for(x)

    app = ApplicationWindow()
    def app_signal(signum, frame):
        print("")
        log("got signal %s" % SIGNAMES.get(signum, signum))
        def show_signal():
            app.show()
            app.client.cleanup()
            gobject.timeout_add(1000, app.set_info_text, "got signal %s" % SIGNAMES.get(signum, signum))
            gobject.timeout_add(1000, app.set_info_color, True)
        #call from UI thread:
        gobject.idle_add(show_signal)
    signal.signal(signal.SIGINT, app_signal)
    signal.signal(signal.SIGTERM, app_signal)
    has_file = len(args) == 1
    if has_file:
        app.update_options_from_file(args[0])
    debug = fixup_debug_option(app.config.debug)
    if debug:
        for x in debug.split(","):
            enable_debug_for(x)
   #suspend tray workaround for our window widgets:
    try:
        set_use_tray_workaround(False)
        app.create_window()
    finally:
        set_use_tray_workaround(True)
    try:
        app.update_gui_from_config()
        if app.config.autoconnect:
            #file says we should connect,
            #do that only (not showing UI unless something goes wrong):
            gobject.idle_add(app.do_connect)
        if not has_file:
            app.reset_errors()
        gui_ready()
        if not app.config.autoconnect or app.config.debug:
            app.show()
        app.run()
    except KeyboardInterrupt:
        pass
    return 0
Esempio n. 2
0
def do_main():
    from xpra.os_util import SIGNAMES
    from xpra.scripts.main import InitExit, InitInfo
    from xpra.gtk_common.quit import gtk_main_quit_on_fatal_exceptions_enable
    gtk_main_quit_on_fatal_exceptions_enable()

    from xpra.platform.gui import ready as gui_ready
    gui_init()
    try:
        from xpra.scripts.main import parse_cmdline, fixup_debug_option
        options, args = parse_cmdline(sys.argv)
        debug = fixup_debug_option(options.debug)
        if debug:
            for x in debug.split(","):
                enable_debug_for(x)
    except InitInfo as e:
        print(str(e))
        return 0
    except InitExit as e:
        return e.status
    except Exception:
        exception_dialog("Error parsing command line")
        return 1

    #allow config to be debugged:
    from xpra.scripts import config
    config.debug = log.debug

    try:
        app = ApplicationWindow()
        def app_signal(signum, _frame):
            print("")
            log("got signal %s" % SIGNAMES.get(signum, signum))
            def show_signal():
                app.show()
                app.client.cleanup()
                glib.timeout_add(1000, app.set_info_text, "got signal %s" % SIGNAMES.get(signum, signum))
                glib.timeout_add(1000, app.set_info_color, True)
            #call from UI thread:
            glib.idle_add(show_signal)
        if sys.version_info[0]<3:
            #breaks GTK3..
            signal.signal(signal.SIGINT, app_signal)
        signal.signal(signal.SIGTERM, app_signal)
        has_file = len(args) == 1
        if has_file:
            app.update_options_from_file(args[0])
            #the compressors and packet encoders cannot be changed from the UI
            #so apply them now:
            configure_network(app.config)
        debug = fixup_debug_option(app.config.debug)
        if debug:
            for x in debug.split(","):
                enable_debug_for(x)
        #suspend tray workaround for our window widgets:
        try:
            set_use_tray_workaround(False)
            app.create_window()
        finally:
            set_use_tray_workaround(True)
        app.update_gui_from_config()
    except Exception:
        exception_dialog("Error creating launcher form")
        return 1
    try:
        if app.config.autoconnect:
            #file says we should connect,
            #do that only (not showing UI unless something goes wrong):
            glib.idle_add(app.do_connect)
        if not has_file:
            app.reset_errors()
        gui_ready()
        if not app.config.autoconnect or app.config.debug:
            #FIXME: this is ugly as hell
            #We have to wait for the main loop to be running
            #to get the NSApplicationOpneFile signal,
            #so we end up duplicating some of the logic from just above
            #maybe we should always run this code from the main loop instead
            if OSX:
                def force_show():
                    from xpra.platform.darwin.gui import enable_focus_workaround, disable_focus_workaround
                    enable_focus_workaround()
                    app.show()
                    glib.timeout_add(500, disable_focus_workaround)
                #wait a little bit for the "openFile" signal
                app.__osx_open_signal = False
                def do_open_file(filename):
                    log.info("do_open_file(%s)", filename)
                    app.update_options_from_file(filename)
                    #the compressors and packet encoders cannot be changed from the UI
                    #so apply them now:
                    configure_network(app.config)
                    app.update_gui_from_config()
                    if app.config.autoconnect:
                        app.__osx_open_signal = True
                        glib.idle_add(app.do_connect)
                    else:
                        force_show()
                def open_file(_, filename):
                    log.info("open_file(%s)", filename)
                    glib.idle_add(do_open_file, filename)
                def do_open_URL(url):
                    log.info("do_open_URL(%s)", url)
                    app.__osx_open_signal = True
                    app.update_options_from_URL(url)
                    #the compressors and packet encoders cannot be changed from the UI
                    #so apply them now:
                    configure_network(app.config)
                    app.update_gui_from_config()
                    glib.idle_add(app.do_connect)
                def open_URL(url):
                    log.info("open_URL(%s)", url)
                    glib.idle_add(do_open_URL, url)
                from xpra.platform.darwin.gui import get_OSXApplication, register_URL_handler
                register_URL_handler(open_URL)
                try:
                    get_OSXApplication().connect("NSApplicationOpenFile", open_file)
                except Exception as e:
                    log.error("Error: cannot handle file associations:")
                    log.error(" %s", e)
                def may_show():
                    log("may_show() osx open signal=%s", app.__osx_open_signal)
                    if not app.__osx_open_signal:
                        force_show()
                glib.timeout_add(500, may_show)
            else:
                app.show()
        app.run()
    except KeyboardInterrupt:
        pass
    return 0
Esempio n. 3
0
def main():
    from xpra.os_util import SIGNAMES
    from xpra.gtk_common.quit import gtk_main_quit_on_fatal_exceptions_enable
    gtk_main_quit_on_fatal_exceptions_enable()

    from xpra.platform import program_context
    from xpra.platform.gui import ready as gui_ready
    from xpra.log import enable_color
    with program_context("Xpra-Launcher", "Xpra Connection Launcher"):
        enable_color()
        gui_init()
        try:
            from xpra.scripts.main import parse_cmdline, fixup_debug_option
            options, args = parse_cmdline(sys.argv)
            debug = fixup_debug_option(options.debug)
            if debug:
                for x in debug.split(","):
                    enable_debug_for(x)
        except Exception:
            exception_dialog("Error parsing command line")
            return 1

        try:
            app = ApplicationWindow()
            def app_signal(signum, frame):
                print("")
                log("got signal %s" % SIGNAMES.get(signum, signum))
                def show_signal():
                    app.show()
                    app.client.cleanup()
                    glib.timeout_add(1000, app.set_info_text, "got signal %s" % SIGNAMES.get(signum, signum))
                    glib.timeout_add(1000, app.set_info_color, True)
                #call from UI thread:
                glib.idle_add(show_signal)
            if sys.version_info[0]<3:
                #breaks GTK3..
                signal.signal(signal.SIGINT, app_signal)
            signal.signal(signal.SIGTERM, app_signal)
            has_file = len(args) == 1
            if has_file:
                app.update_options_from_file(args[0])
                #the compressors and packet encoders cannot be changed from the UI
                #so apply them now:
                configure_network(app.config)
            debug = fixup_debug_option(app.config.debug)
            if debug:
                for x in debug.split(","):
                    enable_debug_for(x)
            #suspend tray workaround for our window widgets:
            try:
                set_use_tray_workaround(False)
                app.create_window()
            finally:
                set_use_tray_workaround(True)
            app.update_gui_from_config()
        except Exception:
            exception_dialog("Error creating launcher form")
            return 1
        try:
            if app.config.autoconnect:
                #file says we should connect,
                #do that only (not showing UI unless something goes wrong):
                glib.idle_add(app.do_connect)
            if not has_file:
                app.reset_errors()
            gui_ready()
            if not app.config.autoconnect or app.config.debug:
                #FIXME: this is ugly as hell
                #We have to wait for the main loop to be running
                #to get the NSApplicationOpneFile signal,
                #so we end up duplicating some of the logic from just above
                #maybe we should always run this code from the main loop instead
                if sys.platform.startswith("darwin"):
                    #wait a little bit for the "openFile" signal
                    app.__osx_open_file = False
                    def do_open_file(filename):
                        app.__osx_open_file = True
                        app.update_options_from_file(filename)
                        #the compressors and packet encoders cannot be changed from the UI
                        #so apply them now:
                        configure_network(app.config)
                        app.update_gui_from_config()
                        if app.config.autoconnect:
                            glib.idle_add(app.do_connect)
                    def open_file(_, filename):
                        log("open_file(%s)", filename)
                        glib.idle_add(do_open_file, filename)
                    from xpra.platform.darwin.gui import get_OSXApplication
                    get_OSXApplication().connect("NSApplicationOpenFile", open_file)
                    def may_show():
                        log("may_show() osx open file=%s", app.__osx_open_file)
                        if not app.__osx_open_file:
                            app.show()
                    glib.timeout_add(500, may_show)
                else:
                    app.show()
            app.run()
        except KeyboardInterrupt:
            pass
        return 0
Esempio n. 4
0
def main():
    from xpra.os_util import SIGNAMES
    from xpra.gtk_common.quit import gtk_main_quit_on_fatal_exceptions_enable
    gtk_main_quit_on_fatal_exceptions_enable()

    from xpra.platform import init as platform_init, clean as platform_clean
    from xpra.platform.gui import ready as gui_ready
    from xpra.log import enable_color
    try:
        platform_init("Xpra-Launcher", "Xpra Connection Launcher")
        enable_color()
        gui_init()
        try:
            from xpra.scripts.main import parse_cmdline, fixup_debug_option
            options, args = parse_cmdline(sys.argv)
            debug = fixup_debug_option(options.debug)
            if debug:
                for x in debug.split(","):
                    enable_debug_for(x)
        except Exception:
            exception_dialog("Error parsing command line")
            return 1

        try:
            app = ApplicationWindow()
            def app_signal(signum, frame):
                print("")
                log("got signal %s" % SIGNAMES.get(signum, signum))
                def show_signal():
                    app.show()
                    app.client.cleanup()
                    glib.timeout_add(1000, app.set_info_text, "got signal %s" % SIGNAMES.get(signum, signum))
                    glib.timeout_add(1000, app.set_info_color, True)
                #call from UI thread:
                glib.idle_add(show_signal)
            if sys.version_info[0]<3:
                #breaks GTK3..
                signal.signal(signal.SIGINT, app_signal)
            signal.signal(signal.SIGTERM, app_signal)
            has_file = len(args) == 1
            if has_file:
                app.update_options_from_file(args[0])
                #the compressors and packet encoders cannot be changed from the UI
                #so apply them now:
                configure_network(app.config)
            debug = fixup_debug_option(app.config.debug)
            if debug:
                for x in debug.split(","):
                    enable_debug_for(x)
            #suspend tray workaround for our window widgets:
            try:
                set_use_tray_workaround(False)
                app.create_window()
            finally:
                set_use_tray_workaround(True)
            app.update_gui_from_config()
        except Exception:
            exception_dialog("Error creating launcher form")
            return 1
        try:
            if app.config.autoconnect:
                #file says we should connect,
                #do that only (not showing UI unless something goes wrong):
                glib.idle_add(app.do_connect)
            if not has_file:
                app.reset_errors()
            gui_ready()
            if not app.config.autoconnect or app.config.debug:
                app.show()
            app.run()
        except KeyboardInterrupt:
            pass
        return 0
    finally:
        platform_clean()