spe2fitsGUI.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:spe2fits 作者: jerryjiahaha 项目源码 文件源码
def workaroundForGUI():
    """ redirect I/O when in GUI
    ref:  http://stackoverflow.com/questions/2883205/how-can-i-freeze-a-dual-mode-gui-and-console-application-using-cx-freeze
    ref:  https://mail.gnome.org/archives/commits-list/2012-November/msg04489.html
    ref:  http://stackoverflow.com/questions/23505835/cx-freeze-ignores-custom-variables-module
    """
    try:
        sys.stdout.write("\n")
        sys.stdout.flush()
    except Exception as e:
        class GuiLogger:
            logfile = os.path.realpath(os.path.realpath(sys.argv[0]))
            logfile = os.path.splitext(logfile)[0] + '.log'
            logObj = open(logfile, "w")
            def __init__(self):
                self.logObj = GuiLogger.logObj
            def write(self, data):
                self.logObj.write(data)
            def flush(self):
                self.logObj.flush()
            def close(self):
                self.flush()
            def read(self, data):
                pass
        sys.stdout = sys.stderr = sys.stdin = sys.__stdout__ = sys.__stdin__ = sys.__stderr__ = GuiLogger()


# ref: http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号