Esempio n. 1
0
    def _stroke(self, pressure):
        if pressure is 'hard':
            self.total += 10
        else:
            self.total += 1

        # ~&% Kuài %&~
        Kuai.emit('stroked')
Esempio n. 2
0
 def get(self, item):
     try:
         rv = self._innerData[item]
     except KeyError:
         return None
     else:
         # ~&% Kuài %&~
         Kuai.emit("model-accessed", item)
         return rv
Esempio n. 3
0
    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)
Esempio n. 4
0
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')
Esempio n. 5
0
    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)
Esempio n. 6
0
 def run(self):
     while not self.is_done:
         time.sleep(0.01)
         x, y = pygame.mouse.get_pos()
         events = pygame.event.get()
         for event in events:
             if event.type == pygame.KEYDOWN:
                 if event.key == pygame.K_UP:
                     Kuai.emit('key-up', x, y)
                 if event.key == pygame.K_DOWN:
                     Kuai.emit('key-down', x, y)
                 if event.key == pygame.K_LEFT:
                     Kuai.emit('key-left', x, y)
                 if event.key == pygame.K_RIGHT:
                     Kuai.emit('key-right', x, y)
                 if event.key == pygame.K_ESCAPE:
                     Kuai.emit('key-escape')
                 pass
Esempio n. 7
0
    def run(self):
        while True:
            job = random.choice(self.activities)
            if job == "queryModel":
                choice = random.choice("first second third".split(' '))
                print(
                    green(
                        "Me: Better do some research on this {} one..".format(
                            choice)))
                self.data.get(choice)
                print(
                    green("Me: Okay so {} choice is the one then..".format(
                        choice)))
            if job == "mutateModel":
                data = random.choice("first second third".split(' '))
                this = random.randint(1, 100)
                print(
                    green("Me: Hmm.. Think i'll change {} to {}..".format(
                        data, this)))
                self.data.set(data, this)
            time.sleep(random.randint(3, 9))

            # ~&% Kuài %&~
            Kuai.emit("jobs-done", "Hm, a job well done I'd say!")
Esempio n. 8
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
Esempio n. 9
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
Esempio n. 10
0
def draw_squid(x, y):
    print("Draw squid!")
    Kuai.emit('circle', white, x, y, random.randrange(5, 15))
Esempio n. 11
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()
Esempio n. 12
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')
Esempio n. 13
0
 def draw_point(self, color, x, y):
     pygame.draw.rect(self.screen, color, (x, y, 1, 1))
     Kuai.emit('update-view')
Esempio n. 14
0
 def draw_square(self, color, x, y, height, border=0):
     height = 20
     pygame.draw.rect(self.screen, color, (x, y, height, height), border)
     Kuai.emit('update-view')
Esempio n. 15
0
 def draw_line(self, color, start_pos, end_pos, width=1):
     pygame.draw.line(self.screen, color, start_pos, end_pos, width)
     Kuai.emit('update-view')
Esempio n. 16
0
 def draw_circle(self, color, x, y, radius, width=0):
     pygame.draw.circle(self.screen, color, (x, y), radius, width)
     Kuai.emit('update-view')
Esempio n. 17
0
    def set(self, item, value):
        self._innerData[item] = value

        # ~&% Kuài %&~
        Kuai.emit("model-changed", data=(item, value))
Esempio n. 18
0
def draw_speck(x, y):
    print("Draw speck!")
    Kuai.emit('point', red, x, y)
Esempio n. 19
0
def draw_worm(x, y):
    print("Draw worm!")
    Kuai.emit('line', white, (x, y),
              (random.randrange(0, 799), random.randrange(0, 599)), 1)
Esempio n. 20
0
def draw_turtle(x, y):
    print("Draw turtle!")
    Kuai.emit('square', red, x, y, random.randrange(5, 20))
Esempio n. 21
0
def test_kuai_singleton():
    a = Kuai()
    b = Kuai()
    c = Kuai()
    assert (a == b == c)
Esempio n. 22
0
from kuai import Kuai, set_backend
set_backend('signal')


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


signal = Kuai.on('signal', hello)
signal("cymrow")
Esempio n. 23
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')