当前位置: 首页>>代码示例>>Python>>正文


Python Application.schedule方法代码示例

本文整理汇总了Python中application.Application.schedule方法的典型用法代码示例。如果您正苦于以下问题:Python Application.schedule方法的具体用法?Python Application.schedule怎么用?Python Application.schedule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在application.Application的用法示例。


在下文中一共展示了Application.schedule方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: QuizClient

# 需要导入模块: from application import Application [as 别名]
# 或者: from application.Application import schedule [as 别名]

#.........这里部分代码省略.........
        self._disc = umundo.Discovery(umundo.Discovery.MDNS)
        self._disc.add(self._node)

    def _cleanup(self):
        self._disc = None
        self._node = None
        self._subscriber = None
        self._publisher = None
        self._greeter = None
        self._receiver = None

    def _onBtnPress(self, pressedBtn):
        if self._answerLocked:
            return

        mapping = {
            Application.BTN_A: 0,
            Application.BTN_B: 1,
            Application.BTN_C: 2,
            Application.BTN_D: 3,
        }
        answer = Answer(self.ui, self.activeQuestion, mapping[pressedBtn])
        correctBtn = next(k for k,v in mapping.items() if v == int(self.activeQuestion.getCorrectAnswer()))

        self.ui.highlightBtn(correctBtn, None if pressedBtn == correctBtn else pressedBtn)
        self._answerLocked = True
        self.send(answer.toDict(), True)

    def _toMsg(self, kvMap):
        msg = umundo.Message()

        for k in kvMap:
            msg.putMeta(str(k), str(kvMap[k]))

        return msg

    def send(self, kvMap, dispatchToSelf=False):
        """
        Expects a dictonary which is then serialized and published as umundo message.

        kvMap -- The dictonary key-value pairs. Only string keys and string
            values are allowed. Each pair is attached as meta data to the message.
        dispatchToSelf -- Whether to simulate the receiving of the sent message.
        """
        # print("Send message " + kvMap["type"])
        message = self._toMsg(kvMap)
        self._publisher.send(message)

        if dispatchToSelf:
            self.dispatch(message)

    def hasSubscribers(self):
        """Whether there are any subscribers (players) besides ourselves."""
        return self._publisher.waitForSubscribers(0) > 0

    def onSubscriber(self, pub, subStub):
        """
        Gets called whenever a new player is participating.
        We respond via a welcome message to announce him our username.
        """
        self.send({
            "type": config.Message.WELCOME,
            "username": self.ui.username,
        })

    def onSubscriberLeave(self, pub, subStub):
        pass

    def onQuestion(self, msg):
        """
        Gets called when a new question is received.
        The received question is then displayed in the GUI.
        """
        self._answerLocked = False
        self.activeQuestion = Question.fromMsg(msg)
        self.ui.updateQuestion(self.activeQuestion)

    def dispatch(self, msg):
        """Delegate incoming messages to the appropriate handler functions"""
        # print ("Dispatch " + msg.getMeta("type"))

        mapping = {
            config.Message.HEARTBEAT: self._leader.dispatchHeartbeat,
            config.Message.PRIORITY: self._leader.dispatchPriority,
            config.Message.ANSWER: self._leader.dispatchAnswer,
            config.Message.WELCOME: self._scoreboard.dispatchWelcome,
            config.Message.SCORES: self._scoreboard.dispatchScores,
            config.Message.QUESTION: self.onQuestion,
        }

        msgType = msg.getMeta("type")
        if msgType in mapping:
            mapping[msgType](msg)
        else:
            print("Unknown message type: ", msgType)

    def start(self):
        """Starts the eventloop of the GUI"""
        self.ui.schedule(500, self._leader.tick)
        self.ui.run()
开发者ID:tarekauel,项目名称:umundo-java,代码行数:104,代码来源:main.py


注:本文中的application.Application.schedule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。