Example #1
0
def gui():
    global gui_root
    sys.path.append("/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk")
    sys.path.append("/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/")

    # Wait for ui_server startup
    while not (sys.modules.get("main") and "ui_server" in dir(sys.modules["main"]) and getattr(sys.modules["main"].ui_server, "server", None)):
        time.sleep(0.1)

    def click():
        import webbrowser
        webbrowser.open("http://127.0.0.1:43110")

    def quit():
        sys.exit(0)

    try:
        from Tkinter import Tk
        gui_root = Tk()
        gui_root.iconify()
        gui_root.createcommand('tk::mac::ReopenApplication', click)
        gui_root.createcommand('tk::mac::Quit', quit)
        if not os.environ.get("SECURITYSESSIONID"):  # Not started by auto-run
            click()
        gui_root.mainloop()
    except ExitCommand:
        print "Stopping..."
    except Exception, err:
        print "Gui error: %s" % err
        while 1:
            time.sleep(1000)