コード例 #1
0
ファイル: example.py プロジェクト: xmonader/Kuai
    def __init__(self, model):
        self.activities = ["queryModel", "mutateModel"]
        self.data = model
        self.t = threading.Thread(target=self.run)
        self.t.daemon = True
        self.t.start()

        # ~&% Kuài %&~
        Kuai.on('jobs-done', self.jobsDone, priority=1)
コード例 #2
0
 def __init__(self, screen_res):
     pygame.init()
     self.screen = pygame.display.set_mode(screen_res)
     self.background = pygame.Surface(self.screen.get_size())
     Kuai.on('square', self.draw_square)
     Kuai.on('line', self.draw_line)
     Kuai.on('circle', self.draw_circle)
     Kuai.on('point', self.draw_point)
     Kuai.on('update-view', self.update)
     Kuai.emit('view-loaded')
コード例 #3
0
def test_priority_backend():
    set_backend('priority')

    def increment():
        global x
        x += 1

    Kuai.on('test', increment)
    Kuai.emit('test')
    assert x == 1

    Kuai.emit('test')
    assert x == 2
コード例 #4
0
def test_kuai_events():
    set_backend('threaded')

    def increment():
        global x
        x += 1

    Kuai.on('test', increment)
    Kuai.emit('test')
    sleep(0.01)
    assert x == 1

    Kuai.emit('test')
    sleep(0.01)
    assert x == 2
コード例 #5
0
ファイル: example.py プロジェクト: xmonader/Kuai
    def __init__(self):
        self.ego = Ego(1)

        # ~&% Kuài %&~
        Kuai.on("model-changed", self.onModelChanged)
        Kuai.on("model-accessed", self.onModelAccessed)
        Kuai.on("jobs-done", self.onJobsDone)
        Kuai.on("stroked", self.onStroked)
コード例 #6
0
def draw_speck(x, y):
    print("Draw speck!")
    Kuai.emit('point', red, x, y)


def confirm_exit(msg=None):
    if msg:
        print("Select y or n..")
    conf = input("Sure you want to exit?  n [y] $ ").lower() or 'y'
    if conf not in ['y', 'n']:
        confirm_exit(msg=True)
    else:
        if conf == 'y':
            Kuai.emit('display-is-done')


def greeting():
    print(f"Welcome to the demo! Pygame is ready to go~")


if __name__ == '__main__':
    Kuai.on('key-up', draw_squid)
    Kuai.on('key-down', draw_worm)
    Kuai.on('key-left', draw_turtle)
    Kuai.on('key-right', draw_speck)
    Kuai.on('key-escape', confirm_exit)
    Kuai.on('display-is-done', controller.stop)
    Kuai.on('view-loaded', greeting)
    controller.run()
コード例 #7
0
from kuai import Kuai, set_backend
set_backend('signal')


def hello(name):
    print(f"Hello, {name}")


signal = Kuai.on('signal', hello)
signal("cymrow")
コード例 #8
0
from kuai import Kuai


def hello(world):
    print("Hello, {world}!".format(world=world))


Kuai.on('hello-world', hello)

Kuai.emit('hello-world', 'Kuài')