Exemplo n.º 1
0
  def test_set_callback(self):
    xs = []
    b = Button(callback=(lambda: xs.append(1)))
    b.handle_event({'type': CLICK, 'id': b.id})
    self.assertEqual([1], xs)

    xs = []
    b.set_callback(lambda: xs.append(2))
    b.handle_event({'type': CLICK, 'id': b.id})
    self.assertEqual([2], xs)
Exemplo n.º 2
0
  def test_callbacks_produce_commands(self):
    button_with_predefined_callback = Button(callback=(lambda: None))
    button_with_later_callback = Button()
    gui = GUI(button_with_predefined_callback, button_with_later_callback)
    stream = gui.command_stream()

    self.assertIn(button_with_predefined_callback.id, stream.get(block=False))
    self.assertTrue(stream.empty())

    button_with_later_callback.set_callback(lambda: None)
    self.assertIn(button_with_later_callback.id, stream.get(block=False))
    self.assertTrue(stream.empty())
Exemplo n.º 3
0
  def test_event_dispatch(self):
    decoy1 = Button()
    button = Button()
    decoy2 = Button()

    xs = []
    button.set_callback(lambda: xs.append(1))

    gui = GUI(decoy1, button, decoy2)

    event = {'type': CLICK, 'id': button.id}
    gui.dispatch_event({'type': CLICK, 'id': button.id})
    self.assertEqual([1], xs)