示例#1
0
    def test_conditional_event(self):
        mgr = EventManager()

        self.handled = False

        def handler(event):
            self.handled = True

        binding = mgr.bind(handler, 'basic', condition=1)
        self.assertEqual(
            binding.__class__, Binding,
            'EventManager().bind() returned something other than an instance of Binding'
        )

        mgr.trigger(Event('basic'))
        self.assertFalse(
            self.handled,
            'Conditional event handler called for the wrong event')

        mgr.trigger(Event('basic', [('condition', 0)]))
        self.assertFalse(
            self.handled,
            'Conditional event handler called for the wrong event')

        mgr.trigger(Event('basic', [('condition', 1)]))
        self.assertTrue(self.handled, 'Conditional event handler not called')
示例#2
0
class main:
    def __init__(self):
        self.events = EventManager()
        self.load()
        self.events.trigger(Event('reload'))
    
    def load(self):
        self.reactors = []
        self.reactors.append(example(self.events))
        self.reactors.append(example2(self.events))
        self.events.bind('main app', self.reload, 'reload')
        self.events.trigger(Event('ready'))
    
    def reload(self, event=None, *args):
        self.events.trigger(Event('reloading'))
        self.events.clear_bindings()
        self.reactors = []
        self.load()
        self.events.trigger(Event('reloaded'))
示例#3
0
class main:
    def __init__(self):
        self.events = EventManager()
        self.load()
        self.events.trigger(Event('reload'))

    def load(self):
        self.reactors = []
        self.reactors.append(example(self.events))
        self.reactors.append(example2(self.events))
        self.events.bind('main app', self.reload, 'reload')
        self.events.trigger(Event('ready'))

    def reload(self, event=None, *args):
        self.events.trigger(Event('reloading'))
        self.events.clear_bindings()
        self.reactors = []
        self.load()
        self.events.trigger(Event('reloaded'))
示例#4
0
 def test_basic_event(self):
     mgr = EventManager()
     
     self.handled = False
     
     def handler(event):
         self.handled = True
     
     binding = mgr.bind(handler, 'basic')
     self.assertEqual(binding.__class__, Binding,
         'EventManager().bind() returned something other than an instance of Binding')
     
     mgr.trigger(Event('something'))
     self.assertFalse(self.handled, 'Basic event handler called for the wrong event')
     
     mgr.trigger(Event('basic'))
     self.assertTrue(self.handled, 'Basic event handler not called')
示例#5
0
from reflex.data import Event
from reflex.control import EventManager

events = EventManager()

def handler(event, *args):
    print("Hello, world!")

events.bind(handler, 'example')

events.trigger(Event('example'))
# prints "Hello, world!"
示例#6
0
from reflex.data import Event
from reflex.control import EventManager

events = EventManager()


def handler(event, *args):
    print("Hello, world!")


events.bind(handler, 'example')

events.trigger(Event('example'))
# prints "Hello, world!"