__main__.py 文件源码

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

项目:SafeEyes 作者: slgobinath 项目源码 文件源码
def main():
    """
    Start the Safe Eyes.
    """
    system_locale = gettext.translation('safeeyes', localedir=Utility.LOCALE_PATH, languages=[Utility.system_locale(), 'en_US'], fallback=True)
    system_locale.install()
    # locale.bindtextdomain is required for Glade files
    # gettext.bindtextdomain(gettext.textdomain(), Utility.LOCALE_PATH)
    locale.bindtextdomain('safeeyes', Utility.LOCALE_PATH)

    parser = argparse.ArgumentParser(prog='safeeyes', description=_('description'))
    group = parser.add_mutually_exclusive_group()
    group.add_argument('-a', '--about', help=_('show the about dialog'), action='store_true')
    group.add_argument('-d', '--disable', help=_('disable the currently running safeeyes instance'), action='store_true')
    group.add_argument('-e', '--enable', help=_('enable the currently running safeeyes instance'), action='store_true')
    group.add_argument('-q', '--quit', help=_('quit the running safeeyes instance and exit'), action='store_true')
    group.add_argument('-s', '--settings', help=_('show the settings dialog'), action='store_true')
    group.add_argument('-t', '--take-break', help=_('Take a break now').lower(), action='store_true')
    parser.add_argument('--debug', help=_('start safeeyes in debug mode'), action='store_true')
    parser.add_argument('--version', action='version', version='%(prog)s ' + SAFE_EYES_VERSION)
    args = parser.parse_args()

    # Initialize the logging
    Utility.intialize_logging(args.debug)
    config = Config()

    if __running():
        logging.info("Safe Eyes is already running")
        rpc_client = RPCClient(config.get('rpc_port'))
        if args.about:
            rpc_client.show_about()
        elif args.disable:
            rpc_client.disable_safeeyes()
        elif args.enable:
            rpc_client.enable_safeeyes()
        elif args.settings:
            rpc_client.show_settings()
        elif args.take_break:
            rpc_client.take_break()
        elif args.quit:
            rpc_client.quit()
        else:
            # Default behavior is opening settings
            rpc_client.show_settings()
        sys.exit(0)
    elif not args.quit:
        logging.info("Starting Safe Eyes")
        safeeyes = SafeEyes(system_locale, config)
        safeeyes.start()
        Timer(1.0, lambda: __evaluate_arguments(args, safeeyes)).start()
        Gtk.main()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号