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


Python circuits.Event类代码示例

本文整理汇总了Python中circuits.Event的典型用法代码示例。如果您正苦于以下问题:Python Event类的具体用法?Python Event怎么用?Python Event使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: started

  def started(self, component):
    self.fetcher = pymetar.ReportFetcher('CYZP')
    self.parser  = pymetar.ReportParser()

    self.fire(Event.create("fetch"))

    Timer(60*30, Event.create("fetch"), persist=True).register(self)
    Timer(60, Event.create("report"), persist=True).register(self)
开发者ID:rfb,项目名称:rasp-clock,代码行数:8,代码来源:clock.py

示例2: generate_events

    def generate_events(self, event):
        if not self._ready or self._done:
            return

        if self._counter < 10:
            self.fire(Event.create("hello"))
        else:
            self.fire(Event.create("done"))
        event.reduce_time_left(0)
开发者ID:ke4roh,项目名称:circuits,代码行数:9,代码来源:test_generate_events.py

示例3: started

    def started(self, component):
        """started Event handler

        Setup 3 timers at 5, 1 and 3 seconds.
        The 2nd two timers are persitent meaning that
        they are fired repeatedly every 1 and 3 seconds
        respectively.
        """

        # Timer(seconds, event, persist=False)
        Timer(5, Event.create("hello")).register(self)
        Timer(1, Event.create("foo"), persist=True).register(self)
        Timer(3, Event.create("bar"), persist=True).register(self)
开发者ID:ke4roh,项目名称:circuits,代码行数:13,代码来源:timers.py

示例4: test_values

def test_values():
    event = Event()
    event.test_meta = 1

    value = Value(event=event)
    value.value = 'foo'
    value.errors = False
    value.node_call_id = 1

    x, id, errors, meta = load_value(dump_value(value))

    assert value.value == x
    assert id == 1
    assert not errors
    assert meta['test_meta'] == event.test_meta
开发者ID:carriercomm,项目名称:circuits,代码行数:15,代码来源:test_utils.py

示例5: __init__

    def __init__(self, maxcams=16, *args):
        super(CameraManager, self).__init__("CAM", *args)

        self._cameras = {}
        self._subscribers = {}
        self._filming = True
        self._framecount = 0
        self._frames = {}

        if opencv is not None:
            self.log("Checking opencv for cameras.", lvl=debug)

            for cam in range(maxcams):
                video = opencv.VideoCapture(cam)
                if video.isOpened():
                    camera = {"uuid": str(uuid4()), "name": "Camera" + str(cam), "cam": video}
                    self._cameras[cam] = camera
                    self.log("Found camera [", cam, "]: ", camera)

            self.log("Starting timer")
            self.timer = Timer(0.05, Event.create("rec"), persist=True).register(self)

            self.log("Found cameras: ", self._cameras, lvl=debug)
        else:
            self.log("No opencv, no cameras.")

        AuthorizedEvents["camera"] = camerarequest

        self.log("Started")
开发者ID:ri0t,项目名称:hfos,代码行数:29,代码来源:manager.py

示例6: decode

    def decode(self, data):
        obj = json.loads(data)

        name = bytes_to_str(obj["name"].encode("utf-8"))

        args = []
        for arg in obj["args"]:
            if isinstance(arg, text_type):
                arg = arg.encode("utf-8")
            args.append(arg)

        kwargs = {}
        for k, v in obj["kwargs"].items():
            if isinstance(v, text_type):
                v = v.encode("utf-8")
            kwargs[str(k)] = v

        e = Event.create(name, *args, **kwargs)

        e.success = bool(obj["success"])
        e.failure = bool(obj["failure"])
        e.notify = bool(obj["notify"])
        e.channels = tuple(obj["channels"])

        return e
开发者ID:apnarm,项目名称:autodock,代码行数:25,代码来源:codecs.py

示例7: on_message

def on_message(client, userdata, msg):
    try:
        parsed_json = json.loads(msg.payload)
        if (parsed_json["power_off"] == "Y"):
            # do_power_off()
            log.log(45, "POWEROFF BYTES\t" + str(get_tx_bytes()))
            CircuitsApp.timer.persist = False
            log.info("Received Control: PAUSE EXECUTION")

        if (parsed_json["power_off"] == "R"):
            # do_power_off()
            log.info("Received Control: RESET TIMER")
            CircuitsApp.timer.reset(int(parsed_json["sampling_rate"]))
            log.log(45, "RESET\t" + str(get_tx_bytes()))
            CircuitsApp.timer = Timer(SENSE_INTERVAL, Event.create("sense_event"), persist=True).register(CircuitsApp)

        if (parsed_json["camera"] == "Y"):
            print("Taking picture")
            newstr = "image" + str(get_timestamp()) + ".jpg"
            try:                
                cam.take_picture(newstr)
                log.info("Successfully captured picture\t" + str(newstr))
            except:
                log.error("Error in taking picture.")

        if (parsed_json["sampling_rate"] != SENSE_INTERVAL):
            CircuitsApp.timer.reset(int(parsed_json["sampling_rate"]))
            log.info("Timer Reset. New sampling rate is\t" + str(parsed_json["sampling_rate"]))
            print("Timer resetted")
        log.info("Received external control command.")
        print("Received a control string")
        print(parsed_json)
    except:
        print("From topic: " + msg.topic + " INVALID DATA")
开发者ID:amatur,项目名称:EnviroSCALE_pi,代码行数:34,代码来源:Dispatcher.py

示例8: __init__

    def __init__(self, maxcams=16, *args):
        super(CameraManager, self).__init__(*args)

        self._cameras = {}
        self._subscribers = {}
        self._filming = True
        self._framecount = 0
        self._frames = {}

        hfoslog("[CAM] Checking opencv for cameras.", lvl=debug)
        for cam in range(maxcams):
            video = opencv.VideoCapture(cam)
            if video.isOpened():
                camera = {'uuid': str(uuid4()),
                          'name': 'Camera' + str(cam),
                          'cam': video
                          }
                self._cameras[cam] = camera
                hfoslog("[CAM] Found camera [", cam, "]: ", camera)

        hfoslog("[CAM] Starting timer")
        self.timer = Timer(0.05, Event.create("rec"), persist=True).register(self)

        hfoslog("[CAM] Found cameras: ", self._cameras, lvl=debug)
        hfoslog("[CAM] Started")
开发者ID:addy2342,项目名称:hfos,代码行数:25,代码来源:camera.py

示例9: started

    def started(self, component):
        """started Event handler

        Setup a simple timer to fire every second.
        """

        # Timer(seconds, event, persist=False)
        Timer(1, Event.create("timerevent"),persist=True).register(self)
开发者ID:clixx-io,项目名称:clixx.io,代码行数:8,代码来源:simple_timer.py

示例10: started

    def started(self, component):
        """started Event handler

        """

        self.serial_ports = self.read_serial_ports()

        # Timer(seconds, event, persist=False)
        Timer(self.timer_interval, Event.create("timer"), persist=True).register(self)
开发者ID:clixx-io,项目名称:clixx.io,代码行数:9,代码来源:serialports-monitor.py

示例11: test_return_value

def test_return_value(app, watcher):
    event = Event.create('foo')
    event.notify = True

    remote_event = remote(event, 'child')
    remote_event.notify = True

    value = app.fire(remote_event)
    assert watcher.wait('remote_value_changed')
    assert value.value == 'Hello World!'
开发者ID:ke4roh,项目名称:circuits,代码行数:10,代码来源:test_node.py

示例12: started

    def started(self, component):
        while True:
    	    try:
	        actuatorClient = mqttc.Client()
                actuatorClient.on_connect = on_connect
                actuatorClient.on_message = on_message
                actuatorClient.connect(MQTT_BROKER_HOSTNAME, 1883, 60)
                actuatorClient.loop_start()
                print(time_of_now(), "Started => Running")
                print(get_tx_bytes())
                log.log(45, "START_BYTES\t" + str(get_tx_bytes()))
                self.fire(Event.create("sense_event"))
                self.timer = Timer(SENSE_INTERVAL, Event.create("sense_event"), persist=True).register(self)
                Timer(RUNTIME, Event.create("exit_event"), persist=False).register(self)
		break
	    except gaierror:
                log.error("Failure connecting to MQTT controller")
	        print("FAILED")
		#reconnect(TX_MEDIUM)
	    time.sleep(10)
开发者ID:amatur,项目名称:EnviroSCALE_pi,代码行数:20,代码来源:Dispatcher.py

示例13: init

    def init(self, **kwargs):
        # Default Settings
        prop_defaults = {
            "nick": "pancakesbot",
            "network": "irc.slashnet.org",
            "port": 6667,
            "channels": ["#bots"],
            "plugins": ["admin"],
            "plugins_path": "plugins",
            "command_prefix": "~",
            "storage_path": "storage",
        }
        self.__dict__.update(prop_defaults)
        # Overwrite defaults with kwargs
        if kwargs:
            self.__dict__.update(kwargs)

        self.terminate = False
        self.storage_path = os.path.abspath(self.storage_path)

        # Add a logger
        self.logger = logging.getLogger(__name__)

        # Message Queue used by plugins, as to avoid kicks for flooding.
        self.msg_queue = []
        # Global mesasge queue timer, only activated when there are messages
        # to process.
        self.queue_timer = None

        # Add TCPClient and IRC to the system.
        TCPClient(channel=self.channel).register(self)
        IRC(channel=self.channel).register(self)

        # Creates an instance of UserManager
        self.logger.debug("Initializing user manager.")
        user_db_file = os.path.join(self.storage_path, "users-{}.db".format(self.network))
        if not os.path.exists(self.storage_path):
            os.makedirs(self.storage_path)
        self.user_mngr = UserManager(self, user_db_file)
        self.user_mngr.register(self)

        # Add plugins directory to path
        self.logger.debug("Initializing plugin manager.")
        self.plugins_path = os.path.abspath(self.plugins_path)
        if not os.path.exists(self.plugins_path):
            os.makedirs(self.plugins_path)
        sys.path.append(self.plugins_path)
        # Keeps track of plugins and commands
        self.plugin_mngr = PluginManager(self, self.command_prefix, os.path.basename(self.plugins_path)).register(self)
        for plugin in self.plugins:
            self.plugin_mngr.load(plugin)

        # Send Keepalive PING every 5 minutes
        Timer(300.0, Event.create("keepalive"), persist=True).register(self)
开发者ID:NickPancakes,项目名称:PancakesBot,代码行数:54,代码来源:pancakesbot.py

示例14: init

    def init(self, logfilename, delay=5000):
        hfoslog("[NMEA] Playback component started")

        with open(logfilename, 'r') as logfile:
            self.logdata = logfile.readlines()

        hfoslog("[NMEA] Logfile contains ", len(self.logdata), " items.")

        self.delay = delay
        self.position = 0

        Timer(self.delay, Event.create('nmeaplayback'), self.channel, persist=True).register(self)
开发者ID:addy2342,项目名称:hfos,代码行数:12,代码来源:nmea.py

示例15: started

    def started(self, c):
        if hasattr(os, 'cpu_count'): # python 3.4 min
            self.max_avg = os.cpu_count()

        else:
            import subprocess
            process_cmd = ['grep', '-c', '^processor', '/proc/cpuinfo']
            cpu_count = subprocess.check_output(process_cmd)
            self.max_avg = int(cpu_count)

        load_avg_evt = Event.create('get_load_avg')
        Timer(self.delay, load_avg_evt, self.channel, persist=True).register(self)
开发者ID:treemo,项目名称:MoLA-load_watcher-module,代码行数:12,代码来源:Module.py


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