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


Python Manager.send方法代码示例

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


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

示例1: ComponentRunner

# 需要导入模块: from circuits import Manager [as 别名]
# 或者: from circuits.Manager import send [as 别名]
class ComponentRunner(Component):
    instance = None

    def __init__(self):
        # instanciated from the c++ side, as modulemanager there
        # assert self.instance is None
        Component.__init__(self)
        ComponentRunner.instance = self  # is used as a singleton now

        self.mouseinfo = MouseInfo(0, 0, 0, 0)
        # m.start() #instead we tick() & flush() in update

        self.firstrun = True
        self.eventhandled = False
        r.restart = False
        self.start()
        r.manager = self

    def start(self):
        # Create a new circuits Manager
        # ignevents = [Update, MouseMove]
        ignchannames = [
            "update",
            "on_mousemove",
            "on_mousedrag",
            "on_keydown",
            "on_input",
            "on_mouseclick",
            "on_entityupdated",
            "on_exit",
            "on_keyup",
            "on_login",
            "on_inboundnetwork",
            "on_genericmessage",
            "on_scene",
            "on_entity_visuals_modified",
            "on_logout",
        ]
        ignchannels = [("*", n) for n in ignchannames]

        # Note: instantiating Manager with debugger causes severe lag when running as a true windowed app (no console), so instantiate without debugger
        # Fix attempt: give the circuits Debugger a logger which uses Naali logging system, instead of the default which writes to sys.stderr
        # Todo: if the default stdout is hidden, the py stdout should be changed
        # to something that shows e.g. in console, so prints from scripts show
        # (people commonly use those for debugging so they should show somewhere)
        d = Debugger(IgnoreChannels=ignchannels, logger=NaaliLogger())  # IgnoreEvents = ignored)
        self.m = Manager() + d
        # self.m = Manager()

        # or __all__ in pymodules __init__ ? (i.e. import pymodules would do that)
        if self.firstrun:
            import autoload

            self.firstrun = False
        else:  # reload may cause something strange sometimes, so better not do it always in production use, is just a dev tool.
            # print "reloading autoload"
            import autoload

            autoload = reload(autoload)
        # print "Autoload module:", autoload
        autoload.load(self.m)

    def run(self, deltatime=0.1):
        # print ".",
        m = self.m
        m.send(Update(deltatime), "update")  # XXX should this be using the __tick__ mechanism of circuits, and how?
        m.tick()
        m.flush()
        # XXX NOTE: now that we tick & flush, circuits works normally, and we could change from send() to push() for the events

    def RexNetMsgChatFromSimulator(self, frm, message):
        self.m.send(Chat(frm, message), "on_chat")

    def callback(self, value):
        self.eventhandled = value

    def INPUT_EVENT(self, evid):
        """Note: the PygameDriver for circuits has a different design:
        there the event data is Key, and the channel either "keydown" or "keyup",
        and mouse and clicks are different events and channels.
        Here we have no way to differentiate presses/releases,
        'cause the c++ internals don't do that apart from the constant name.
        """
        # print "circuits_manager ComponentRunner got input event:", evid
        self.eventhandled = False
        self.m.send(Input(evid, self.callback), "on_input")
        return self.eventhandled

    def KEY_INPUT_EVENT(self, evid, keycode, keymod):
        """Handles key inputs, creates a Circuits Key event with the data provided
        WIP, since on_keydown call doesn't work for now, resorted in using Input(keycode)
        instead, works similarly but still not the way it should
        """

        # print "CircuitManager received KEY_INPUT (event:", evid, "key:", keycode, "mods:", keymod, ")",
        self.eventhandled = False
        if evid == r.KeyPressed:
            self.m.send(Key(keycode, keymod, self.callback), "on_keydown")
        elif evid == r.KeyReleased:
            self.m.send(Key(keycode, keymod, self.callback), "on_keyup")
#.........这里部分代码省略.........
开发者ID:jonnenauha,项目名称:naali,代码行数:103,代码来源:circuits_manager.py

示例2: main

# 需要导入模块: from circuits import Manager [as 别名]
# 或者: from circuits.Manager import send [as 别名]

#.........这里部分代码省略.........
            else:
                address, port = opts.bind, 8000

        bridge = Bridge(bind=(address, port), nodes=nodes)
        manager += bridge
        bridge.start()

    if opts.mode.lower() == "speed":
        if opts.verbose:
            print "Setting up Speed Test..."
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager += SpeedTest(opts, channel=c)
        else:
            manager += SpeedTest(opts)
        monitor.sTime = time.time()
    elif opts.mode.lower() == "latency":
        if opts.verbose:
            print "Setting up Latency Test..."
        manager += LatencyTest(opts)
        monitor.sTime = time.time()
    elif opts.listen:
        if opts.verbose:
            print "Setting up Receiver..."
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager += Receiver(opts, channel=c)
        else:
            manager += Receiver(opts)
    elif args:
        if opts.verbose:
            print "Setting up Sender..."
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager += Sender(opts, channel=c)
        else:
            manager += Sender(opts)
    else:
        if opts.verbose:
            print "Setting up Sender..."
            print "Setting up Receiver..."
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager += Sender(channel=c)
                manager += Receiver(opts, channel=c)
        else:
            manager += Sender(opts)
            manager += Receiver(opts)
        monitor.sTime = time.time()

    if opts.profile:
        if hotshot:
            profiler = hotshot.Profile("bench.prof")
            profiler.start()

    if not opts.wait:
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager.push(Hello("hello"), "hello", c)
        else:
            manager.push(Hello("hello"), "hello")

    while not state.done:
        try:
            manager.flush()

            for i in xrange(opts.fill):
                manager.push(Foo(), "foo")

            if opts.events > 0 and monitor.events > opts.events:
                manager.send(Stop(), "stop")
            if opts.time > 0 and (time.time() - monitor.sTime) > opts.time:
                manager.send(Stop(), "stop")

        except KeyboardInterrupt:
            manager.send(Stop(), "stop")

    if opts.verbose:
        print

    eTime = time.time()

    tTime = eTime - monitor.sTime

    events = monitor.events
    speed = int(math.ceil(float(monitor.events) / tTime))

    if opts.output:
        print opts.output % (events, speed, tTime)
    else:
        print "Total Events: %d (%d/s after %0.2fs)" % (events, speed, tTime)

    if opts.profile and hotshot:
        profiler.stop()
        profiler.close()

        stats = hotshot.stats.load("bench.prof")
        stats.strip_dirs()
        stats.sort_stats("time", "calls")
        stats.print_stats(20)
开发者ID:Belsepubi,项目名称:naali,代码行数:104,代码来源:bench.py

示例3: Foo

# 需要导入模块: from circuits import Manager [as 别名]
# 或者: from circuits.Manager import send [as 别名]
# To Start the Manager in ProcessMode
#m.start(process=True)

# Create a new instance of the Component Foo
foo = Foo()
#noncompfoo = NonComponentFoo()

# Register foo with the Manager
m += foo # Equivalent to: foo.register(m)
#m += noncompfoo
#m._add(a_handler, "a")
"""the plain function doesn't have attribute 'priority' (etc. i guess) 
so a no-go i figure"""

# Push an Event to a Channel called "a"
m.push(Event(), "a")

# Send an Event to a Channel called "b"
x = m.send(Event(), "b")
print x # x contains: "Foo's Event Handler for 'b'"

while 1:
    pass

# Unregister foo
foo.unregister() # Or: m -= foo

# Stop the Manager
m.stop()
开发者ID:A-K,项目名称:naali,代码行数:31,代码来源:circuits_test.py


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