update_checker.py 文件源码

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

项目:gui_tool 作者: UAVCAN 项目源码 文件源码
def begin_async_check(parent):
    if not _should_continue():
        logger.info('Update check skipped')
        return

    update_reference = None

    def check_from_gui_thread():
        if background_thread.is_alive():
            logger.info('Update checker is still running...')
        else:
            gui_timer.stop()
            logger.info('Update checker stopped')

        if update_reference is None:
            return

        mbox = QMessageBox(parent)
        mbox.setWindowTitle('Update Available')
        mbox.setText('New version is available.<br><br>%s' % update_reference)
        mbox.setIcon(QMessageBox.Information)
        mbox.setStandardButtons(QMessageBox.Ok)
        mbox.exec()

    def do_background_check():
        nonlocal update_reference
        # noinspection PyBroadException
        try:
            if RUNNING_ON_WINDOWS:
                update_reference = _do_windows_check()
            else:
                update_reference = _do_pip_check()

            logger.info('Update reference: %r', update_reference)
        except Exception:
            logger.error('Update checker failed', exc_info=True)

    background_thread = threading.Thread(target=do_background_check, name='update_checker', daemon=True)
    background_thread.start()

    gui_timer = QTimer(parent)
    gui_timer.setSingleShot(False)
    gui_timer.timeout.connect(check_from_gui_thread)
    gui_timer.start(2000)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号